List of usage examples for javax.swing Timer Timer
public Timer(int delay, ActionListener listener)
From source file:ca.sqlpower.swingui.object.VariablesPanel.java
@SuppressWarnings("unchecked") private void showVarsPicker() { final MultiValueMap namespaces = this.variableHelper.getNamespaces(); List<String> sortedNames = new ArrayList<String>(namespaces.keySet().size()); sortedNames.addAll(namespaces.keySet()); Collections.sort(sortedNames, new Comparator<String>() { public int compare(String o1, String o2) { if (o1 == null) { return -1; }//from w ww .j a v a 2 s .c om if (o2 == null) { return 1; } return o1.compareTo(o2); }; }); final JPopupMenu menu = new JPopupMenu(); for (final String name : sortedNames) { final JMenu subMenu = new JMenu(name); menu.add(subMenu); subMenu.addMenuListener(new MenuListener() { private Timer timer; public void menuSelected(MenuEvent e) { subMenu.removeAll(); subMenu.add(new PleaseWaitAction()); ActionListener menuPopulator = new ActionListener() { public void actionPerformed(ActionEvent e) { if (subMenu.isPopupMenuVisible()) { subMenu.removeAll(); for (Object namespaceO : namespaces.getCollection(name)) { String namespace = (String) namespaceO; logger.debug("Resolving variables for namespace ".concat(namespace)); int nbItems = 0; for (String key : variableHelper.keySet(namespace)) { subMenu.add(new InsertVariableAction(SPVariableHelper.getKey((String) key), (String) key)); nbItems++; } if (nbItems == 0) { subMenu.add(new DummyAction()); logger.debug("No variables found."); } } subMenu.revalidate(); subMenu.getPopupMenu().pack(); } } }; timer = new Timer(700, menuPopulator); timer.setRepeats(false); timer.start(); } public void menuDeselected(MenuEvent e) { timer.stop(); } public void menuCanceled(MenuEvent e) { timer.stop(); } }); } menu.show(varNameText, 0, varNameText.getHeight()); }
From source file:neembuu.uploader.NeembuuUploader.java
/** * Creates new form NeembuuUploader//from w w w . j ava 2 s.c om */ private NeembuuUploader() { //An error message will be printed. //Saying //java.lang.ClassNotFoundException: neembuu.release1.ui.mc.EmotionIconProviderImpl //please ignore it. mainComponent = new MainComponentImpl(this); //mainComponent = new NonUIMainComponent(); << When running in command line mode NULogger.getLogger().log(Level.INFO, "{0}: Starting up..", getClass().getName()); //Display the splashscreen until the NeembuuUploader is initialized //NeembuuUploaderSplashScreen.getInstance().setVisible(true); //Setup NeembuuUploaderProperties.. Create the file if it doesn't exist. NeembuuUploaderProperties.setUp(); //Initialize components initComponents(); initSorting(); initNotification(); setUpTrayIcon(); setUpFileChooser(); setUpHttpClient(); setupTabs(); //map each checkbox to its class in the hashmap variable //NULogger.getLogger().info("Setting checkbox operations"); //checkBoxOperations(); //Load previously saved state //loadSavedState(); //This 3rd party code is to enable Drag n Drop of files FileDrop fileDrop = new FileDrop(this, new FileDrop.Listener() { @Override public void filesDropped(java.io.File[] filesSelected) { //Ignore directories for (File file : filesSelected) { if (file.isFile()) { files.add(file); } } if (files.isEmpty()) { return; } //If one file is dropped, display its name.. If more than one dropped, display the number of files selected if (files.size() == 1) { inputFileTextField.setText(files.get(0) + ""); } else { inputFileTextField.setText(files.size() + " " + Translation.T().nfilesselected()); } NULogger.getLogger().info("Files Dropped"); } }); //Timer is used to periodically refresh the table so that the progress will appear smoothly. SwingUtilities.invokeLater(new Runnable() { @Override public void run() { //Update every 1s Timer autoUpdate = new Timer(1000, new ActionListener() { //Check if the queue is locked. If not, repaint. @Override public void actionPerformed(ActionEvent e) { if (!QueueManager.getInstance().isQueueLocked()) { //Should not call firetablerowsupdated as it'll lose the selection of rows. // //So repaint is called. neembuuUploaderTable.repaint(); } } }); //Unnecessary.. but waits for 3 seconds within which other threads will get more juice and initialize faster.. //reduced from 10 to 3 as I moved to faster pc autoUpdate.setInitialDelay(3000); //Start the timer. autoUpdate.start(); NULogger.getLogger().info("Timer started.."); } }); //By now everything is loaded, so no need of splashscreen anymore,, dispose it. :) //NeembuuUploaderSplashScreen.getInstance().dispose(); NULogger.getLogger().info("Splash screen disposed.."); //Make the NeembuuUploader appear in center of screen. setLocationRelativeTo(null); selectFileButton.requestFocus(); setVisible(true); ThemeCheck.apply(this); selectFileButton.setBorder(BorderFactory.createEmptyBorder()); selectFileButton.setContentAreaFilled(false); selectFileButton.setToolTipText(Translation.T().selectFileButton()); selectFileButton.setFocusPainted(false); selectFolderButton.setBorder(BorderFactory.createEmptyBorder()); selectFolderButton.setContentAreaFilled(false); selectFolderButton.setToolTipText("Select Folder"); selectFolderButton.setFocusPainted(false); getLogButton.setBorder(BorderFactory.createEmptyBorder()); getLogButton.setContentAreaFilled(false); getLogButton.setToolTipText("Copy \"nu.log\" to the clipboard"); getLogButton.setFocusPainted(false); checkifLKSOn(); // starting a thread from a constructor is a bad way to do it // however, we dont have enough options here. }
From source file:lu.fisch.unimozer.Diagram.java
public Diagram() { super();/*from w w w. j a va2 s. c o m*/ setDoubleBuffered(true); /*this.setFocusable(true); this.addKeyListener(new KeyListener() { public void keyTyped(KeyEvent e) { SwingUtilities.processKeyBindings(e); } public void keyPressed(KeyEvent e) { System.err.println("Pressed: "+e.getKeyText(e.getKeyCode())); SwingUtilities.processKeyBindings(e); } public void keyReleased(KeyEvent e) { SwingUtilities.processKeyBindings(e); } });/**/ this.setLayout(new BorderLayout()); this.addMouseListener(this); this.addMouseMotionListener(this); this.addMouseListener(new PopupListener()); this.add(popup); // set the filedropper for the diagram FileDrop fileDrop = new FileDrop(this, new FileDrop.Listener() { @Override public void filesDropped(java.io.File[] files) { boolean found = false; for (int i = 0; i < files.length; i++) { String filename = files[i].toString(); File f = new File(filename); if (filename.substring(filename.length() - 5, filename.length()).toLowerCase() .equals(".java")) { try { //MyClass mc = new MyClass(new FileInputStream(filename)); MyClass mc = new MyClass(filename, Unimozer.FILE_ENCODING); mc.setPosition(new Point(0, 0)); addClass(mc); setChanged(true); diagram.setChanged(true); } catch (Exception ex) { MyError.display(ex); } } else if (f.isDirectory()) { if (((PackageFile.exists(f) == true) || (BlueJPackageFile.exists(f) == true) || (NetBeansPackageFile.exists(f) == true)) && (f.isDirectory())) { final String fim = filename; (new Thread(new Runnable() { @Override public void run() { if (askToSave() == true) { //Console.disconnectAll(); //System.out.println("Opening: "+fim); diagram.open(fim); } } })).start(); } else { addDir(f); } } } diagram.repaint(); frame.setTitleNew(); } }); // start the auto-save timer (after 10 minutes) saveTimer = new Timer(AUTOSAVE_TIMEOUT, autoSave); //saveTimer.start(); // => it is started upon the first change! }
From source file:com.github.benchdoos.weblocopener.updater.gui.UpdateDialog.java
public void showMessage(String message, int messageValue) { errorPanel.setBackground(MessagePushable.getMessageColor(messageValue)); boolean wasVisible = errorPanel.isVisible(); errorPanel.setVisible(true);/*from w w w . j av a 2 s. co m*/ errorTextPane.setText(message); if (!wasVisible) { updateSize(UpdateSizeMode.BEFORE_HIDE); } if (messageTimer != null) { messageTimer.stop(); } messageTimer = new Timer(MessagePushable.DEFAULT_TIMER_DELAY, e -> { errorTextPane.setText(""); errorPanel.setVisible(false); updateSize(UpdateSizeMode.AFTER_HIDE); }); messageTimer.setRepeats(false); messageTimer.start(); }
From source file:replicatorg.app.ui.panels.ControlPanel.java
private void startMovementTimer(MovDir whereTo) { ActionListener listener;//from w w w .j a v a 2 s. co m if (canMove == false) { Base.writeLog("*** Can't move at the moment ***", this.getClass()); return; } setPollDataTrue.stop(); movButtonHoldDown = new Timer(movCommandInterval, null); movButtonHoldDown.setRepeats(true); canPollData = false; switch (whereTo) { case Z_PLUS: listener = (ActionEvent e) -> { double val; driver.dispatchCommand("G0 F1000 Z" + movCommandStep, COM.NO_RESPONSE); val = Double.parseDouble(zTextFieldValue.getText()) + movCommandStep; zTextFieldValue.setText(String.format(Locale.US, "%3.3f", val)); }; movButtonHoldDown.addActionListener(listener); movButtonHoldDown.start(); break; case Z_MINUS: listener = (ActionEvent e) -> { double val; driver.dispatchCommand("G0 F1000 Z-" + movCommandStep, COM.NO_RESPONSE); val = Double.parseDouble(zTextFieldValue.getText()) - movCommandStep; zTextFieldValue.setText(String.format(Locale.US, "%3.3f", val)); }; movButtonHoldDown.addActionListener(listener); movButtonHoldDown.start(); break; case Y_PLUS: listener = (ActionEvent e) -> { double val; driver.dispatchCommand("G0 F1000 Y" + movCommandStep, COM.NO_RESPONSE); val = Double.parseDouble(yTextFieldValue.getText()) + movCommandStep; yTextFieldValue.setText(String.format(Locale.US, "%3.3f", val)); }; movButtonHoldDown.addActionListener(listener); movButtonHoldDown.start(); break; case Y_MINUS: listener = (ActionEvent e) -> { double val; driver.dispatchCommand("G0 F1000 Y-" + movCommandStep, COM.NO_RESPONSE); val = Double.parseDouble(yTextFieldValue.getText()) - movCommandStep; yTextFieldValue.setText(String.format(Locale.US, "%3.3f", val)); }; movButtonHoldDown.addActionListener(listener); movButtonHoldDown.start(); break; case X_PLUS: listener = (ActionEvent e) -> { double val; driver.dispatchCommand("G0 F1000 X" + movCommandStep, COM.NO_RESPONSE); val = Double.parseDouble(xTextFieldValue.getText()) + movCommandStep; xTextFieldValue.setText(String.format(Locale.US, "%3.3f", val)); }; movButtonHoldDown.addActionListener(listener); movButtonHoldDown.start(); break; case X_MINUS: listener = (ActionEvent e) -> { double val; driver.dispatchCommand("G0 F1000 X-" + movCommandStep, COM.NO_RESPONSE); val = Double.parseDouble(xTextFieldValue.getText()) - movCommandStep; xTextFieldValue.setText(String.format(Locale.US, "%3.3f", val)); }; movButtonHoldDown.addActionListener(listener); movButtonHoldDown.start(); break; default: break; } }
From source file:com.josescalia.tumblr.app.MainFrame.java
private void createTimer() { timer = new Timer(1000, new ActionListener() { @Override/*from w ww . j a v a 2 s . co m*/ public void actionPerformed(ActionEvent arg0) { setCurrentTime("Time : " + new SimpleDateFormat("hh:mm:ss a").format(new Date())); } }); }
From source file:com.joey.software.regionSelectionToolkit.controlers.ImageProfileTool.java
public JPanel getControls() { if (controls == null) { controls = new JPanel(new BorderLayout()); JPanel dirButton = new JPanel(new GridLayout(1, 2)); dirButton.add(moveUpData);/* w w w . j a v a2 s. c o m*/ dirButton.add(moveDownData); JPanel buttonPanel = new JPanel(new GridLayout(1, 3)); buttonPanel.add(showFlattenedButton); buttonPanel.add(showAScanButton); buttonPanel.add(estimageSurface); JPanel pointsPanel = new JPanel(new BorderLayout()); pointsPanel.add(saveData, BorderLayout.SOUTH); pointsPanel.add(axisToggle, BorderLayout.WEST); pointsPanel.add(numPoints, BorderLayout.CENTER); pointsPanel.add(updatePoints, BorderLayout.EAST); pointsPanel.add(buttonPanel, BorderLayout.NORTH); JPanel offsetPane = new JPanel(new BorderLayout()); offsetPane.add(showOffset, BorderLayout.WEST); offsetPane.add(offset, BorderLayout.CENTER); JPanel temp = new JPanel(new BorderLayout()); temp.add(offsetPane, BorderLayout.SOUTH); temp.add(transparance, BorderLayout.NORTH); JPanel toolPanel = new JPanel(new BorderLayout()); toolPanel.add(temp, BorderLayout.NORTH); toolPanel.add(pointsPanel, BorderLayout.CENTER); toolPanel.add(dirButton, BorderLayout.SOUTH); controls.add(toolPanel, BorderLayout.NORTH); estimageSurface.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { estimateSurface(); } }); showAScanButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { showAScanPanel(); } }); axisToggle.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (axis == AXIS_X) { setAxis(AXIS_Y); axisToggle.setText("Y Axis"); } else { setAxis(AXIS_X); axisToggle.setText("X Axis"); } panel.repaint(); } }); transparance.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { panel.repaint(); } }); showOffset.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { panel.repaint(); } }); offset.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { panel.shapeChanged(); panel.repaint(); updatePlotPanel(); } }); showFlattenedButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { showFlattenedImage(); } }); updatePoints.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setDataPoints((Integer) numPoints.getValue()); } }); moveUPTimer = new Timer(delay, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addValue(1.0f / view.getImage().getHeight()); } }); moveDownTimer = new Timer(delay, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addValue(-1.0f / view.getImage().getHeight()); } }); moveUpData.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JButton btn2 = (JButton) e.getSource(); ButtonModel model = btn2.getModel(); if (model.isPressed() && !moveUPTimer.isRunning()) { moveUPTimer.start(); } else if (!model.isPressed() && moveUPTimer.isRunning()) { moveUPTimer.stop(); } } }); moveDownData.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JButton btn2 = (JButton) e.getSource(); ButtonModel model = btn2.getModel(); if (model.isPressed() && !moveDownTimer.isRunning()) { moveDownTimer.start(); } else if (!model.isPressed() && moveDownTimer.isRunning()) { moveDownTimer.stop(); } } }); moveUpData.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addValue(1.0f / view.getImage().getHeight()); } }); moveDownData.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addValue(-1.0f / view.getImage().getHeight()); } }); saveData.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { saveData(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); } return controls; }
From source file:edu.ku.brc.af.prefs.PreferencesDlg.java
/** * Start animation where painting will occur for the given rectangle * @param window the window to start it in * @param comp the component//from w ww . ja va 2 s . c om * @param delta the delta each time * @param fullStep the step */ public void startAnimation(final Window window, final Component comp, final int delta, final boolean fullStep) { new Timer(10, new SlideInOutAnimation(window, comp, delta, fullStep)).start(); }
From source file:com.josue.tileset.editor.Editor.java
private void jSpinner1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner1StateChanged long value = (long) jSpinner1.getValue(); selectedTile.getAnimation().setAnimationInterval(value); animatedPerformer.stop();/*w w w . j av a2 s .c o m*/ //restart the performer animatedPerformer = new Timer((int) (selectedTile.getAnimation().getAnimationInterval()), new TileAnimator(selectedTile, previewLabel, loadedTiles)); animatedPerformer.start(); }
From source file:com.massabot.codesender.GrblController.java
/** * Create a timer which will execute GRBL's position polling mechanism. *//*from w w w . j av a 2s .com*/ private Timer createPositionPollTimer() { // Action Listener for GRBL's polling mechanism. ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { try { if (outstandingPolls == 0) { outstandingPolls++; comm.sendByteImmediately(GrblUtils.GRBL_STATUS_COMMAND); } else { // If a poll is somehow lost after 20 intervals, // reset for sending another. outstandingPolls++; if (outstandingPolls >= 20) { outstandingPolls = 0; } } } catch (Exception ex) { messageForConsole(Localization.getString("controller.exception.sendingstatus") + ": " + ex.getMessage() + "\n"); ex.printStackTrace(); } } }); } }; return new Timer(this.getStatusUpdateRate(), actionListener); }