Java Code Examples for javax.swing.Timer#start()

The following examples show how to use javax.swing.Timer#start() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RotatingIcon.java    From btdex with GNU General Public License v3.0 6 votes vote down vote up
public RotatingIcon(Icon icon) {
	delegateIcon = icon;
	
	rotatingTimer = new Timer( 200, new ActionListener() {
		@Override
		public void actionPerformed( ActionEvent e ) {
			angleInDegrees = angleInDegrees + 40;
			if ( angleInDegrees == 360 ){
				angleInDegrees = 0;
			}
			
			for(DefaultTableModel model : cells.keySet()) {
				for(Point c : cells.get(model))
					model.fireTableCellUpdated(c.x, c.y);					
			}
		}
	} );
	rotatingTimer.setRepeats( false );
	rotatingTimer.start();
}
 
Example 2
Source File: FadingPanel.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * Animate this panel. This fades from its current state to the state after
 * the argument runnable has been performed.
 * <P>
 * This method should be called from the event dispatch thread.
 * 
 * @param r
 *            the changes to make to this panel.
 * @param duration
 *            the duration the fade should last, in milliseconds. Usually
 *            250 is a reasonable number.
 */
public void animateStates(Runnable r, final long duration) {
	captureStates(r);
	setProgress(0);
	final long start = System.currentTimeMillis();
	ActionListener actionListener = new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			long current = System.currentTimeMillis() - start;
			float f = ((float) current) / ((float) duration);
			if (f > 1)
				f = 1;
			setProgress(f);
			if (f == 1) {
				((Timer) e.getSource()).stop();
			}
		}
	};
	Timer timer = new Timer(40, actionListener);
	timer.start();
}
 
Example 3
Source File: TumbleItem.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void init() {
    loadAppletParameters();

    // Execute a job on the event-dispatching thread:
    // creating this applet's GUI.
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                createGUI();
            }
        });
    } catch (Exception e) {
        System.err.println("createGUI didn't successfully complete");
    }

    // Set up timer to drive animation events.
    timer = new Timer(speed, this);
    timer.setInitialDelay(pause);
    timer.start();

    // Start loading the images in the background.
    worker.execute();
}
 
Example 4
Source File: frmAbout.java    From Course_Generator with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates new form DialogAbout
 */
public frmAbout(java.awt.Frame parent, boolean modal, boolean autoclose, String version) {
	super(parent, modal);

	bundle = java.util.ResourceBundle.getBundle("course_generator/Bundle");
	initComponents();

	lbVersion.setText("V" + version);

	if (autoclose) {
		Timer timer = new Timer(2000, new MyTimerActionListener());
		timer.start();
	}
}
 
Example 5
Source File: QOptionPane.java    From pumpernickel with MIT License 5 votes vote down vote up
private JComponent createDebugPanel() {
	BufferedImage img = (BufferedImage) getClientProperty("debug.ghost.image");

	if (img == null)
		return this;

	final CardLayout cardLayout = new CardLayout();
	final JPanel panel = new JPanel(cardLayout);

	JPanel imagePanel = new JPanel();
	imagePanel.setUI(new PanelImageUI(img));

	JPanel paneWrapper = new JPanel(new GridBagLayout());
	GridBagConstraints c = new GridBagConstraints();
	c.fill = GridBagConstraints.NONE;
	c.gridx = 0;
	c.gridy = 0;
	c.weightx = 1;
	c.weighty = 1;
	paneWrapper.add(this, c);

	panel.add(paneWrapper, "real");
	panel.add(imagePanel, "debug");

	Timer timer = new Timer(2000, new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			String mode = (System.currentTimeMillis() % 4000) > 2000 ? "real"
					: "debug";
			cardLayout.show(panel, mode);
		}
	});
	timer.start();

	return panel;
}
 
Example 6
Source File: SessionBean.java    From tn5250j with GNU General Public License v2.0 5 votes vote down vote up
private void doVisibility()
{
  if (!isVisible() && (visibilityInterval > 0))
  {
    Timer t = new Timer(visibilityInterval, new DoVisible());
    t.setRepeats(false);
    t.start();
  }
  else if (!isVisible())
  {
    new DoVisible().run();
  }
}
 
Example 7
Source File: Test6559154.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void run() {
    Timer timer = new Timer(1000, this);
    timer.setRepeats(false);
    timer.start();

    JColorChooser chooser = new JColorChooser();
    setEnabledRecursive(chooser, false);

    this.dialog = new JDialog();
    this.dialog.add(chooser);
    this.dialog.setVisible(true);
}
 
Example 8
Source File: ExportZipDialog.java    From tracker with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Offers to open a newly saved zip file.
 *
 * @param path the path to the zip file
 */
private void openZip(final String path) {
  Runnable runner1 = new Runnable() {
  	public void run() {
    	int response = javax.swing.JOptionPane.showConfirmDialog(
    			frame,	    			
    			TrackerRes.getString("ZipResourceDialog.Complete.Message1") //$NON-NLS-1$ 
    			+" \""+XML.getName(path)+"\".\n" //$NON-NLS-1$ //$NON-NLS-2$
    			+TrackerRes.getString("ZipResourceDialog.Complete.Message2"), //$NON-NLS-1$ 
    			TrackerRes.getString("ZipResourceDialog.Complete.Title"), //$NON-NLS-1$ 
    			javax.swing.JOptionPane.YES_NO_OPTION, 
    			javax.swing.JOptionPane.QUESTION_MESSAGE);
    	if (response == javax.swing.JOptionPane.YES_OPTION) {
    		frame.loadedFiles.remove(path);
        Runnable runner = new Runnable() {
        	public void run() {
        		// open the TRZ in a Tracker tab
        		TrackerIO.open(new File(path), frame);
        		// open the TRZ in the Library Browser
  	      	frame.getLibraryBrowser().open(path);
  	      	frame.getLibraryBrowser().setVisible(true);
  	        Timer timer = new Timer(1000, new ActionListener() {
  	          public void actionPerformed(ActionEvent e) {
  	          	LibraryTreePanel treePanel = frame.getLibraryBrowser().getSelectedTreePanel();
  	          	if (treePanel!=null) {
  		    				treePanel.refreshSelectedNode();
  	          	}
  	          }
  	        });
  	        timer.setRepeats(false);
  	        timer.start();
        	}
        };
        SwingUtilities.invokeLater(runner);
    	}
  	}
  };
  SwingUtilities.invokeLater(runner1);  	
}
 
Example 9
Source File: HistoryWindow.java    From jitsi with Apache License 2.0 5 votes vote down vote up
/**
 * Handles the ProgressEvent triggered from the history when processing
 * a query.
 * @param evt the <tt>ProgressEvent</tt> that notified us
 */
public void progressChanged(ProgressEvent evt)
{
    int progress = evt.getProgress();

    if((lastProgress != progress)
            && evt.getStartDate() == null
            || evt.getStartDate() != ignoreProgressDate)
    {
        this.progressBar.setValue(progress);

        if(progressBar.getPercentComplete() == 1.0)
        {
            // Wait 1 sec and remove the progress bar from the main panel.
            Timer progressBarTimer = new Timer(1 * 1000, null);

            progressBarTimer.setRepeats(false);
            progressBarTimer.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e)
                {
                    mainPanel.remove(progressBar);
                    mainPanel.add(readyLabel, BorderLayout.SOUTH);
                    mainPanel.revalidate();
                    mainPanel.repaint();
                    progressBar.setValue(0);
                }
            });
            progressBarTimer.start();
        }

        lastProgress = progress;
    }
}
 
Example 10
Source File: JPanelsSliding.java    From Java-MP3-player with MIT License 5 votes vote down vote up
public void nextSlidPanel(int SpeedPanel, int TimeSpeed,Component ShowPanel, direct DirectionMove) { 
    if (!ShowPanel.getName().equals(getCurrentComponentShow(this))) { 
        Component currentComp = getCurrentComponent(this);           
        ShowPanel.setVisible(true);                     
        JPanelSlidingListener sl = new JPanelSlidingListener(SpeedPanel, currentComp, ShowPanel, DirectionMove);
        Timer t = new Timer(TimeSpeed, sl);            
        sl.timer = t;           
        t.start();           
    }   
    refresh();
}
 
Example 11
Source File: HostOverviewView.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
protected DataViewComponent createComponent() {
    GlobalPreferences preferences = GlobalPreferences.sharedInstance();
    int chartCache = preferences.getMonitoredHostCache() * 60 /
                     preferences.getMonitoredHostPoll();

    DataViewComponent dvc = new DataViewComponent(
            new MasterViewSupport((Host)getDataSource()).getMasterView(),
            new DataViewComponent.MasterViewConfiguration(false));

    boolean cpuSupported = hostOverview.getSystemLoadAverage() >= 0;
    final CpuLoadViewSupport cpuLoadViewSupport = new CpuLoadViewSupport(hostOverview, cpuSupported, chartCache);
    dvc.configureDetailsArea(new DataViewComponent.DetailsAreaConfiguration(NbBundle.getMessage(HostOverviewView.class, "LBL_CPU"), true), DataViewComponent.TOP_LEFT); // NOI18N
    dvc.addDetailsView(cpuLoadViewSupport.getDetailsView(), DataViewComponent.TOP_LEFT);
    if (!cpuSupported) dvc.hideDetailsArea(DataViewComponent.TOP_LEFT);

    final PhysicalMemoryViewSupport physicalMemoryViewSupport = new PhysicalMemoryViewSupport(chartCache);
    dvc.configureDetailsArea(new DataViewComponent.DetailsAreaConfiguration(NbBundle.getMessage(HostOverviewView.class, "LBL_Memory"), true), DataViewComponent.TOP_RIGHT); // NOI18N
    dvc.addDetailsView(physicalMemoryViewSupport.getDetailsView(), DataViewComponent.TOP_RIGHT);

    final SwapMemoryViewSupport swapMemoryViewSupport = new SwapMemoryViewSupport(chartCache);
    dvc.addDetailsView(swapMemoryViewSupport.getDetailsView(), DataViewComponent.TOP_RIGHT);

    timer = new Timer(2000, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            final long time = System.currentTimeMillis();
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    cpuLoadViewSupport.refresh(hostOverview, time);
                    physicalMemoryViewSupport.refresh(hostOverview, time);
                    swapMemoryViewSupport.refresh(hostOverview, time);
                }
            });
        }
    });
    timer.setInitialDelay(800);
    timer.start();
    ((Host)getDataSource()).notifyWhenRemoved(this);
    
    return dvc;
}
 
Example 12
Source File: Test6559154.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void run() {
    Timer timer = new Timer(1000, this);
    timer.setRepeats(false);
    timer.start();

    JColorChooser chooser = new JColorChooser();
    setEnabledRecursive(chooser, false);

    this.dialog = new JDialog();
    this.dialog.add(chooser);
    this.dialog.setVisible(true);
}
 
Example 13
Source File: Login.java    From dctb-utfpr-2018-1 with Apache License 2.0 5 votes vote down vote up
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    jButton1.setVisible(false);
    jProgressBar1.setVisible(true);
    
    tempo = new Timer(100, new progresso(jProgressBar1, tempo));
    tempo.start();
}
 
Example 14
Source File: TaskExecutor.java    From chipster with MIT License 5 votes vote down vote up
private void setupTimeoutTimer(Task task, int timeout) {
	// setup timeout checker if needed
	if (timeout != -1) {
		// we'll have to timeout this task
		Timer timer = new Timer(timeout, new TimeoutListener(task));
		timer.setRepeats(false);
		timer.start();
	}
}
 
Example 15
Source File: FadeInFadeOutHelper.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
public FadeInFadeOutHelper() {
    componentToHighlightTimer = new Timer(50, e -> {

        if (componentToHighlightFadeOut) {
            if (componentToHighlightPosition > 0) {
                componentToHighlightPosition -= 40;
            } else {
                componentToHighlightFadeOut = false;
                componentToHighlight = componentToHighlightNext;
            }
        } else {
            if (componentToHighlightNext != null) {
                componentToHighlight = componentToHighlightNext;
                componentToHighlightNext = null;
            }
            if (componentToHighlight != null) {
                Dimension theSize = componentToHighlight.getSize();
                if (componentToHighlightPosition < theSize.width + 10) {
                    int theStep = theSize.width + 10 - componentToHighlightPosition;
                    if (theStep > 40) {
                        theStep = 40;
                    }
                    componentToHighlightPosition += theStep;
                } else {
                    componentToHighlightTimer.stop();
                }
            } else {
                componentToHighlightTimer.stop();
            }
        }

        doRepaint();
    });
    componentToHighlightWaitTimer = new Timer(1000, e -> componentToHighlightTimer.start());
    componentToHighlightWaitTimer.setRepeats(false);
}
 
Example 16
Source File: TextualDocumentView.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void initGUI() {
  // textView = new JEditorPane();
  // textView.setContentType("text/plain");
  // textView.setEditorKit(new RawEditorKit());

  textView = new JTextArea();
  textView.setAutoscrolls(false);
  textView.setLineWrap(true);
  textView.setWrapStyleWord(true);
  // the selection is hidden when the focus is lost for some system
  // like Linux, so we make sure it stays
  // it is needed when doing a selection in the search textfield
  textView.setCaret(new PermanentSelectionCaret());
  scroller = new JScrollPane(textView);

  textView.setText(document.getContent().toString());
  textView.getDocument().addDocumentListener(swingDocListener);
  // display and put the caret at the beginning of the file
  SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
      try {
        if(textView.modelToView(0) != null) {
          textView.scrollRectToVisible(textView.modelToView(0));
        }
        textView.select(0, 0);
        textView.requestFocus();
      } catch(BadLocationException e) {
        e.printStackTrace();
      }
    }
  });
  // contentPane = new JPanel(new BorderLayout());
  // contentPane.add(scroller, BorderLayout.CENTER);

  // //get a pointer to the annotation list view used to display
  // //the highlighted annotations
  // Iterator horizViewsIter = owner.getHorizontalViews().iterator();
  // while(annotationListView == null && horizViewsIter.hasNext()){
  // DocumentView aView = (DocumentView)horizViewsIter.next();
  // if(aView instanceof AnnotationListView)
  // annotationListView = (AnnotationListView)aView;
  // }
  highlightsMinder = new Timer(BLINK_DELAY, new UpdateHighlightsAction());
  highlightsMinder.setInitialDelay(HIGHLIGHT_DELAY);
  highlightsMinder.setDelay(BLINK_DELAY);
  highlightsMinder.setRepeats(true);
  highlightsMinder.setCoalesce(true);
  highlightsMinder.start();

  // blinker = new Timer(this.getClass().getCanonicalName() +
  // "_blink_timer",
  // true);
  // final BlinkAction blinkAction = new BlinkAction();
  // blinker.scheduleAtFixedRate(new TimerTask(){
  // public void run() {
  // blinkAction.actionPerformed(null);
  // }
  // }, 0, BLINK_DELAY);
  initListeners();
}
 
Example 17
Source File: WrongPaperPrintingTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void createAndShowTestDialog() {
    String description =
        " To run this test it is required to have a virtual PDF\r\n" +
        " printer or any other printer supporting A5 paper size.\r\n" +
        "\r\n" +
        " 1. Verify that NOT A5 paper size is set as default for the\r\n" +
        " printer to be used.\r\n" +
        " 2. Click on \"Start Test\" button.\r\n" +
        " 3. In the shown print dialog select the printer and click\r\n" +
        " on \"Print\" button.\r\n" +
        " 4. Verify that a page with a drawn rectangle is printed on\r\n" +
        " a paper of A5 size which is (5.8 x 8.3 in) or\r\n" +
        " (148 x 210 mm).\r\n" +
        "\r\n" +
        " If the printed page size is correct, click on \"PASS\"\r\n" +
        " button, otherwise click on \"FAIL\" button.";

    final JDialog dialog = new JDialog();
    dialog.setTitle("WrongPaperPrintingTest");
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            dialog.dispose();
            fail("Main dialog was closed.");
        }
    });

    final JLabel testTimeoutLabel = new JLabel(String.format(
        "Test timeout: %s", convertMillisToTimeStr(testTimeout)));
    final long startTime = System.currentTimeMillis();
    final Timer timer = new Timer(0, null);
    timer.setDelay(1000);
    timer.addActionListener((e) -> {
        int leftTime = testTimeout - (int)(System.currentTimeMillis() - startTime);
        if ((leftTime < 0) || testFinished) {
            timer.stop();
            dialog.dispose();
        }
        testTimeoutLabel.setText(String.format(
            "Test timeout: %s", convertMillisToTimeStr(leftTime)));
    });
    timer.start();

    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);

    final JButton testButton = new JButton("Start Test");
    final JButton passButton = new JButton("PASS");
    final JButton failButton = new JButton("FAIL");
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        new Thread(() -> {
            try {
                doTest();

                SwingUtilities.invokeLater(() -> {
                    passButton.setEnabled(true);
                    failButton.setEnabled(true);
                });
            } catch (Throwable t) {
                t.printStackTrace();
                dialog.dispose();
                fail("Exception occurred in a thread executing the test.");
            }
        }).start();
    });
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        dialog.dispose();
        pass();
    });
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        dialog.dispose();
        fail("Size of a printed page is wrong.");
    });

    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel labelPanel = new JPanel(new FlowLayout());
    labelPanel.add(testTimeoutLabel);
    mainPanel.add(labelPanel, BorderLayout.NORTH);
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);

    dialog.pack();
    dialog.setVisible(true);
}
 
Example 18
Source File: DocBookScriptReportEditorView.java    From ramus with GNU General Public License v3.0 4 votes vote down vote up
public DocBookScriptReportEditorView(final GUIFramework framework,
                                     final Element element) {
    super(framework, element);
    timer = new Timer(500, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            boolean save;
            synchronized (lock) {
                if (System.currentTimeMillis() - changeTime < 500)
                    return;
                save = changed;
            }

            if (save) {
                save();
                synchronized (lock) {
                    changed = false;
                }
            }
        }
    });

    timer.start();

    editorView = new ScriptEditorView(framework) {
        /**
         *
         */
        private static final long serialVersionUID = -8884124882782860341L;

        @Override
        protected void changed() {
            synchronized (lock) {
                changed = true;
                changeTime = System.currentTimeMillis();
            }
        }
    };

    editorView.load(framework.getEngine(), element);

    saved = editorView.getText();

    fullRefresh = new com.ramussoft.gui.common.event.ActionListener() {

        @Override
        public void onAction(
                com.ramussoft.gui.common.event.ActionEvent event) {
            editorView.load(framework.getEngine(), element);
        }
    };
    framework.addActionListener(Commands.FULL_REFRESH, fullRefresh);

}
 
Example 19
Source File: AbstractDataMonitorView.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
private void initView() {
    setOpaque(true);
    setBackground(Color.white);
    try {

        this.add(redux_Icon_label);

        rawDataFilePathTextFactory();

        buttonFactory();

        progressBarFactory();

        showMostRecentFractionLabelFactory();

        dataMonitorTimer = new Timer(2500, (ActionEvent e) -> {
            monitorDataFile();
        });

        dataMonitorTimer.start();

    } catch (IOException ex) {
        Logger.getLogger(LAICPMSProjectParametersManager.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 20
Source File: DataToolTab.java    From osp with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Sets the font level.
 *
 * @param level the level
 */
protected void setFontLevel(int level) {
  FontSizer.setFonts(this, level);
  plot.setFontLevel(level);
  
  FontSizer.setFonts(statsTable, level);
  FontSizer.setFonts(propsTable, level);
  
  curveFitter.setFontLevel(level);
  
  double factor = FontSizer.getFactor(level);
  plot.getAxes().resizeFonts(factor, plot);
  FontSizer.setFonts(plot.getPopupMenu(), level);
  if(propsTable.styleDialog!=null) {
    FontSizer.setFonts(propsTable.styleDialog, level);
    propsTable.styleDialog.pack();
  }
  if(dataBuilder!=null) {
    dataBuilder.setFontLevel(level);
  }
  fitterAction.actionPerformed(null);
  propsTable.refreshTable();
  
  // set shift field and label fonts in case they are not currently displayed
  FontSizer.setFonts(shiftXLabel, level);
  FontSizer.setFonts(shiftYLabel, level);
  FontSizer.setFonts(selectedXLabel, level);
  FontSizer.setFonts(selectedYLabel, level);
  FontSizer.setFonts(shiftXField, level);
  FontSizer.setFonts(shiftYField, level);
  FontSizer.setFonts(selectedXField, level);
  FontSizer.setFonts(selectedYField, level);
  shiftXField.refreshPreferredWidth();
  shiftYField.refreshPreferredWidth();
  selectedXField.refreshPreferredWidth();
  selectedYField.refreshPreferredWidth();
  toolbar.revalidate();

refreshStatusBar(null);
// kludge to display tables correctly: do propsAndStatsAction now and again after a millisecond!
  propsAndStatsAction.actionPerformed(null);
  Timer timer = new Timer(1, new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      propsAndStatsAction.actionPerformed(null);
    }
  });
timer.setRepeats(false);
timer.start();
}