Example usage for javax.swing Timer Timer

List of usage examples for javax.swing Timer Timer

Introduction

In this page you can find the example usage for javax.swing Timer Timer.

Prototype

public Timer(int delay, ActionListener listener) 

Source Link

Document

Creates a Timer and initializes both the initial delay and between-event delay to delay milliseconds.

Usage

From source file:net.sf.jabref.gui.MainTableSelectionListener.java

private void updatePreview(final BibtexEntry toShow, final boolean changedPreview, int repeats) {
    if (workingOnPreview) {
        if (repeats > 0) {
            return; // We've already waited once. Give up on this selection.
        }/*w w w .  ja  v a 2  s  .  c o  m*/
        Timer t = new Timer(50, actionEvent -> updatePreview(toShow, changedPreview, 1));
        t.setRepeats(false);
        t.start();
        return;
    }
    EventList<BibtexEntry> list = table.getSelected();
    // Check if the entry to preview is still selected:
    if ((list.size() != 1) || (list.get(0) != toShow)) {
        return;
    }
    final int mode = panel.getMode();
    workingOnPreview = true;
    SwingUtilities.invokeLater(() -> {
        preview.setEntry(toShow);

        // If nothing was already shown, set the preview and move the separator:
        if (changedPreview || (mode == BasePanel.SHOWING_NOTHING)) {
            panel.showPreview(preview);
            panel.adjustSplitter();
        }
        workingOnPreview = false;
    });
}

From source file:eu.europeana.sip.gui.SipCreatorGUI.java

private Component createFilterPanel() {
    JPanel p = new JPanel(new BorderLayout());
    p.setBorder(BorderFactory.createTitledBorder("Filter"));
    filterTimer = new Timer(300, new ActionListener() {
        @Override//  w  w w .j a va2 s  .  co  m
        public void actionPerformed(ActionEvent actionEvent) {
            dataSetList.clearSelection();
            dataSetListModel.setPattern(filter.getText());
        }
    });
    filterTimer.setRepeats(false);
    filter.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent documentEvent) {
            filterTimer.restart();
        }

        @Override
        public void removeUpdate(DocumentEvent documentEvent) {
            filterTimer.restart();
        }

        @Override
        public void changedUpdate(DocumentEvent documentEvent) {
            filterTimer.restart();
        }
    });
    p.add(filter, BorderLayout.CENTER);
    return p;
}

From source file:net.sf.jabref.gui.maintable.MainTableSelectionListener.java

private void updatePreview(final BibEntry toShow, final boolean changedPreview, int repeats) {
    if (workingOnPreview) {
        if (repeats > 0) {
            return; // We've already waited once. Give up on this selection.
        }/* w  w w  . j av  a2s .c om*/
        Timer t = new Timer(50, actionEvent -> updatePreview(toShow, changedPreview, 1));
        t.setRepeats(false);
        t.start();
        return;
    }
    EventList<BibEntry> list = table.getSelected();
    // Check if the entry to preview is still selected:
    if ((list.size() != 1) || (list.get(0) != toShow)) {
        return;
    }
    final BasePanelMode mode = panel.getMode();
    workingOnPreview = true;
    SwingUtilities.invokeLater(() -> {
        preview.setEntry(toShow);

        // If nothing was already shown, set the preview and move the separator:
        if (changedPreview || (mode == BasePanelMode.SHOWING_NOTHING)) {
            panel.showPreview(preview);
            panel.adjustSplitter();
        }
        workingOnPreview = false;
    });
}

From source file:edu.mit.fss.examples.visual.gui.WorldWindVisualization.java

/**
 * Instantiates a new world wind visualization.
 *
 * @throws OrekitException the orekit exception
 *//*from www .j a v  a  2s. co  m*/
public WorldWindVisualization() throws OrekitException {
    logger.trace("Creating Orekit reference frames.");
    eme = ReferenceFrame.EME2000.getOrekitFrame();
    itrf = ReferenceFrame.ITRF2008.getOrekitFrame();
    // world wind frame is a fixed rotation from Earth inertial frame
    wwj = new Frame(itrf, new Transform(date, new Rotation(RotationOrder.ZXZ, 0, -Math.PI / 2, -Math.PI / 2)),
            "World Wind");

    logger.trace("Creating World Window GL canvas and adding to panel.");
    wwd = new WorldWindowGLCanvas();
    wwd.setModel(new BasicModel());
    wwd.setPreferredSize(new Dimension(800, 600));
    setLayout(new BorderLayout());
    add(wwd, BorderLayout.CENTER);

    logger.trace("Creating and adding a renderable layer.");
    displayLayer = new RenderableLayer();
    wwd.getModel().getLayers().add(displayLayer);

    logger.trace("Creating and adding a marker layer.");
    markerLayer = new MarkerLayer();
    // allow markers above/below surface
    markerLayer.setOverrideMarkerElevation(false);
    wwd.getModel().getLayers().add(markerLayer);

    logger.trace("Creating and adding a sun renderable.");
    Vector3D position = sun.getPVCoordinates(date, wwj).getPosition();
    sunShape = new Ellipsoid(wwd.getModel().getGlobe().computePositionFromPoint(convert(position)), 696000000.,
            696000000., 696000000.);
    ShapeAttributes sunAttributes = new BasicShapeAttributes();
    sunAttributes.setInteriorMaterial(Material.YELLOW);
    sunAttributes.setInteriorOpacity(1.0);
    sunShape.setAttributes(sunAttributes);
    displayLayer.addRenderable(sunShape);

    logger.trace("Creating and adding a terminator.");
    LatLon antiSun = LatLon.fromRadians(-sunShape.getCenterPosition().getLatitude().radians,
            FastMath.PI + sunShape.getCenterPosition().getLongitude().radians);
    // set radius to a quarter Earth chord at the anti-sun position less
    // a small amount (100 m) to avoid graphics problems
    terminatorShape = new SurfaceCircle(antiSun,
            wwd.getModel().getGlobe().getRadiusAt(antiSun) * FastMath.PI / 2 - 100);
    ShapeAttributes nightAttributes = new BasicShapeAttributes();
    nightAttributes.setInteriorMaterial(Material.BLACK);
    nightAttributes.setInteriorOpacity(0.5);
    terminatorShape.setAttributes(nightAttributes);
    displayLayer.addRenderable(terminatorShape);

    logger.trace("Creating and adding a panel for buttons.");
    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    buttonPanel.add(new JCheckBox(new AbstractAction("Inertial Frame") {
        private static final long serialVersionUID = 2287109397693524964L;

        @Override
        public void actionPerformed(ActionEvent e) {
            setInertialFrame(((JCheckBox) e.getSource()).isSelected());
        }
    }));
    buttonPanel.add(new JButton(editOptionsAction));
    add(buttonPanel, BorderLayout.SOUTH);

    logger.trace(
            "Creating a timer to rotate the sun renderable, " + "terminator surface circle, and stars layer.");
    Timer rotationTimer = new Timer(15, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            wwd.redraw();
            try {
                BasicOrbitView wwdView;
                if (wwd.getView() instanceof BasicOrbitView) {
                    wwdView = (BasicOrbitView) wwd.getView();
                } else {
                    return;
                }

                // rotate camera to simulate inertial frame
                if (wwd.getView().isAnimating() || !inertialFrame.get()) {
                    // update eme datum
                    rotationDatum = wwj.getTransformTo(eme, date)
                            .transformPosition(convert(wwdView.getCenterPoint()));
                } else if (inertialFrame.get()) {
                    Position newCenter = wwd.getModel().getGlobe().computePositionFromPoint(
                            convert(eme.getTransformTo(wwj, date).transformPosition(rotationDatum)));
                    // move to eme datum
                    wwdView.setCenterPosition(newCenter);
                }

                // rotate stars layer
                for (Layer layer : wwd.getModel().getLayers()) {
                    if (layer instanceof StarsLayer) {
                        StarsLayer stars = (StarsLayer) layer;
                        // find the EME coordinates of (0,0)
                        Vector3D emeDatum = wwj.getTransformTo(eme, date).transformPosition(convert(
                                wwd.getModel().getGlobe().computePointFromLocation(LatLon.fromDegrees(0, 0))));
                        // find the WWJ coordinates the equivalent point in ITRF
                        Vector3D wwjDatum = itrf.getTransformTo(wwj, date).transformPosition(emeDatum);
                        // set the longitude offset to the opposite of 
                        // the difference in longitude (i.e. from 0)
                        stars.setLongitudeOffset(wwd.getModel().getGlobe()
                                .computePositionFromPoint(convert(wwjDatum)).getLongitude().multiply(-1));
                    }
                }
            } catch (OrekitException ex) {
                logger.error(ex);
            }
        }
    });
    // set initial 2-second delay for initialization
    rotationTimer.setInitialDelay(2000);
    rotationTimer.start();
}

From source file:com.microsoft.alm.plugin.idea.git.ui.vcsimport.ImportForm.java

private void createUIComponents() {
    userAccountPanel = new UserAccountPanel();

    // Create timer for filtering the list
    timer = new Timer(400, null);
    timer.setInitialDelay(400);/*  w  w  w  .j a va2  s.c om*/
    timer.setActionCommand(CMD_PROJECT_FILTER_CHANGED);
    timer.setRepeats(false);
}

From source file:es.emergya.ui.gis.popups.GPSDialog.java

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(i18n.getString("window.gps.button.actualizar"))) {
        last_bandejaSalida = send();/*from   w  w  w  .ja  va 2  s  .c o  m*/
        log.info("bandeja de salida: " + last_bandejaSalida);

        if (last_bandejaSalida == null) {
            return;
        }

        final JButton request = ((JButton) e.getSource());

        request.setEnabled(false);
        progressIcon.setIcon(iconEnviando);
        notification.setForeground(Color.WHITE);

        SolicitudGPSActionListener listener = new SolicitudGPSActionListener(last_bandejaSalida);
        Timer t = new Timer(1000, listener);

        listener.setTimer(t);
        t.start();
    }

    if (e.getActionCommand().equals(i18n.getString("Buttons.cancel"))) {
        if (last_bandejaSalida != null) {
            MessageGenerator.remove(last_bandejaSalida.getId());
        }

        last_bandejaSalida = null;
        dispose();
    }
}

From source file:com.willwinder.ugs.nbp.core.windows.StateTopComponent.java

private Timer createTimer() {
    return new Timer((int) REFRESH_RATE.toMillis(), (ae) -> {
        java.awt.EventQueue.invokeLater(() -> {
            GcodeState state = backend.getGcodeState();
            if (state == null)
                return;

            try {
                loading = true;/*from  w  ww. j ava  2  s .  c  o  m*/

                motionBox.setSelectedItem(state.currentMotionMode.toString());
                unitBox.setSelectedItem(get(state.units));
                feedModeBox.setSelectedItem(get(state.feedMode));
                distanceModeBox.setSelectedItem(get(state.distanceMode));
                workOffsetBox.setSelectedItem(get(state.offset));
                planeBox.setSelectedItem(get(state.plane.code));

                this.setFeedAndSpeed(state.speed, state.spindleSpeed);
            } finally {
                loading = false;
            }
        });
    });
}

From source file:replicatorg.app.ui.panels.ControlPanel.java

private void evaluateInitialConditions() {
    getPosition();//from   ww  w.  ja  v  a2s . co m

    disposeThread.start();
    inputValidationThread.start();
    getInitialValuesThread.start();

    // set to relative positioning
    driver.dispatchCommand("G91");

    // enable debug mode
    driver.dispatchCommand("M1110 S1");

    setPollDataTrue = new Timer(0, (ActionEvent e) -> {
        if (movButtonHoldDown.isRunning() == false) {
            canPollData = true;
        }
    });
    setPollDataTrue.setInitialDelay(200);
    setPollDataTrue.setRepeats(false);

    showBeepLabel = new Timer(0, (ActionEvent e) -> {
        labelBeepValidation.setVisible(false);
    });
    showBeepLabel.setInitialDelay(2000);
    showBeepLabel.setRepeats(false);

    categories2 = fullFillComboDuration();
    comboModel2 = new DefaultComboBoxModel(categories2);

    extrudeCombo.setModel(comboModel2);
    extrudeCombo.setSelectedIndex(0);

}

From source file:com.microsoft.alm.plugin.idea.common.ui.common.tabs.TabFormImpl.java

/**
 * Create the search filter for the toolbar
 *//*from   w w w.  j av  a  2 s  .  c o  m*/
protected void createFilterToolbar() {
    // Create timer for filtering the list
    timer = new Timer(400, null);
    timer.setInitialDelay(400);
    timer.setActionCommand(CMD_FILTER_CHANGED);
    timer.setRepeats(false);

    searchFilter = new SearchFilter();
    //initialize to empty string
    searchFilter.setFilterText(StringUtils.EMPTY);
}

From source file:uk.co.petertribble.jangle.SnmpChart.java

/**
 * Start the timer, so the display will continually update.
 *//* w  ww .j av a  2 s  . co m*/
public void startLoop() {
    if (timer == null) {
        timer = new Timer(interval * 1000, this);
    }
    timer.start();
}