Search in sources :

Example 21 with Timer

use of javax.swing.Timer in project cytoscape-impl by cytoscape.

the class NetworkViewMediator method updateView.

private void updateView(final CyNetworkView view, final VisualStyle style) {
    if (view == null)
        return;
    if (getNetworkViewMainPanel().isGridVisible() || view.equals(getNetworkViewMainPanel().getCurrentNetworkView())) {
        Timer timer = null;
        synchronized (lock) {
            timer = viewUpdateTimers.get(view);
        }
        if (timer == null) {
            timer = new Timer(0, evt -> {
                VisualStyle vs = style != null ? style : serviceRegistrar.getService(VisualMappingManager.class).getVisualStyle(view);
                vs.apply(view);
                view.updateView();
            });
            timer.setRepeats(false);
            timer.setCoalesce(true);
            synchronized (lock) {
                viewUpdateTimers.put(view, timer);
            }
        } else {
            timer.stop();
        }
        timer.setInitialDelay(120);
        timer.start();
    } else {
        viewUpdateRequired.add(view);
    }
}
Also used : VisualStyleSetListener(org.cytoscape.view.vizmap.events.VisualStyleSetListener) LoggerFactory(org.slf4j.LoggerFactory) UpdateNetworkPresentationListener(org.cytoscape.view.model.events.UpdateNetworkPresentationListener) View(org.cytoscape.view.model.View) SetCurrentVisualStyleListener(org.cytoscape.view.vizmap.events.SetCurrentVisualStyleListener) SessionAboutToBeLoadedListener(org.cytoscape.session.events.SessionAboutToBeLoadedListener) VisualStyleSetEvent(org.cytoscape.view.vizmap.events.VisualStyleSetEvent) CyNetwork(org.cytoscape.model.CyNetwork) Map(java.util.Map) MouseAdapter(java.awt.event.MouseAdapter) SetCurrentNetworkViewEvent(org.cytoscape.application.events.SetCurrentNetworkViewEvent) CyProperty(org.cytoscape.property.CyProperty) ViewChangedEvent(org.cytoscape.view.model.events.ViewChangedEvent) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) ColumnNameChangedEvent(org.cytoscape.model.events.ColumnNameChangedEvent) MouseListener(java.awt.event.MouseListener) Timer(javax.swing.Timer) VisualStyleChangedEvent(org.cytoscape.view.vizmap.events.VisualStyleChangedEvent) RenderingEngineFactory(org.cytoscape.view.presentation.RenderingEngineFactory) ViewChangedListener(org.cytoscape.view.model.events.ViewChangedListener) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) NetworkViewAboutToBeDestroyedListener(org.cytoscape.view.model.events.NetworkViewAboutToBeDestroyedListener) ViewChangeRecord(org.cytoscape.view.model.events.ViewChangeRecord) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) VisualStyleChangedListener(org.cytoscape.view.vizmap.events.VisualStyleChangedListener) ColumnDeletedEvent(org.cytoscape.model.events.ColumnDeletedEvent) Collection(java.util.Collection) SetCurrentNetworkViewListener(org.cytoscape.application.events.SetCurrentNetworkViewListener) Set(java.util.Set) VisualLexicon(org.cytoscape.view.model.VisualLexicon) CyNetworkManager(org.cytoscape.model.CyNetworkManager) Component(java.awt.Component) SessionLoadedListener(org.cytoscape.session.events.SessionLoadedListener) RowsSetEvent(org.cytoscape.model.events.RowsSetEvent) RowsSetListener(org.cytoscape.model.events.RowsSetListener) List(java.util.List) CyApplicationManager(org.cytoscape.application.CyApplicationManager) ThumbnailPanel(org.cytoscape.internal.view.NetworkViewGrid.ThumbnailPanel) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) SessionLoadedEvent(org.cytoscape.session.events.SessionLoadedEvent) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer) ActionListener(java.awt.event.ActionListener) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) Mode(org.cytoscape.internal.view.GridViewToggleModel.Mode) ExportNetworkViewTaskFactory(org.cytoscape.task.write.ExportNetworkViewTaskFactory) NetworkViewAboutToBeDestroyedEvent(org.cytoscape.view.model.events.NetworkViewAboutToBeDestroyedEvent) HashMap(java.util.HashMap) RowSetRecord(org.cytoscape.model.events.RowSetRecord) HashSet(java.util.HashSet) DestroyNetworkViewTaskFactory(org.cytoscape.task.destroy.DestroyNetworkViewTaskFactory) ExportNetworkImageTaskFactory(org.cytoscape.task.write.ExportNetworkImageTaskFactory) JMenuItem(javax.swing.JMenuItem) NetworkViewAddedListener(org.cytoscape.view.model.events.NetworkViewAddedListener) CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) SetCurrentVisualStyleEvent(org.cytoscape.view.vizmap.events.SetCurrentVisualStyleEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) LinkedHashSet(java.util.LinkedHashSet) WeakHashMap(java.util.WeakHashMap) CyTable(org.cytoscape.model.CyTable) VisualProperty(org.cytoscape.view.model.VisualProperty) UpdateNetworkPresentationEvent(org.cytoscape.view.model.events.UpdateNetworkPresentationEvent) NetworkViewAddedEvent(org.cytoscape.view.model.events.NetworkViewAddedEvent) SessionAboutToBeLoadedEvent(org.cytoscape.session.events.SessionAboutToBeLoadedEvent) Properties(java.util.Properties) Logger(org.slf4j.Logger) JPopupMenu(javax.swing.JPopupMenu) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) MappableVisualPropertyValue(org.cytoscape.view.presentation.property.values.MappableVisualPropertyValue) ViewUtil(org.cytoscape.internal.util.ViewUtil) ActionEvent(java.awt.event.ActionEvent) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) MouseEvent(java.awt.event.MouseEvent) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) ColumnDeletedListener(org.cytoscape.model.events.ColumnDeletedListener) ColumnNameChangedListener(org.cytoscape.model.events.ColumnNameChangedListener) CyNetworkView(org.cytoscape.view.model.CyNetworkView) RenderingEngine(org.cytoscape.view.presentation.RenderingEngine) CyColumnIdentifierFactory(org.cytoscape.view.presentation.property.values.CyColumnIdentifierFactory) ViewUtil.invokeOnEDT(org.cytoscape.internal.util.ViewUtil.invokeOnEDT) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) Collections(java.util.Collections) Timer(javax.swing.Timer) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager)

Example 22 with Timer

use of javax.swing.Timer in project cytoscape-impl by cytoscape.

the class CreditScreen method showCredits.

@SuppressWarnings("serial")
public void showCredits() {
    dialog = new JDialog(parent, true);
    dialog.setUndecorated(true);
    final ScrollingLinesPanel panel = new ScrollingLinesPanel(image, lines);
    panel.setBorder(BorderFactory.createLineBorder(UIManager.getColor("Separator.foreground")));
    dialog.add(panel);
    dialog.pack();
    dialog.validate();
    dialog.setPreferredSize(panel.getPreferredSize());
    centerDialogLocation(dialog);
    Action scrollText = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            panel.incrementYPos();
            dialog.repaint();
        }
    };
    timer = new Timer(100, scrollText);
    dialog.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            hideCredits();
        }
    });
    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            hideCredits();
        }
    };
    LookAndFeelUtil.setDefaultOkCancelKeyStrokes(dialog.getRootPane(), null, cancelAction);
    timer.start();
    dialog.setVisible(true);
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) MouseEvent(java.awt.event.MouseEvent) Timer(javax.swing.Timer) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 23 with Timer

use of javax.swing.Timer in project Spark by igniterealtime.

the class ShakeWindow method startRandomMovement.

/**
 * punishes the User by moving the Chatwindow around for 10 seconds
 */
public void startRandomMovement(final int seconds) {
    if (window instanceof JFrame) {
        JFrame f = (JFrame) window;
        f.setState(Frame.NORMAL);
        f.setVisible(true);
    }
    SparkManager.getNativeManager().flashWindow(window);
    final long startTime = System.currentTimeMillis() / 1000L;
    moveTimer = new Timer(5, e -> {
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        double x = Math.random() * 10000 % d.getWidth();
        double y = Math.random() * 10000 % d.getHeight();
        int xx = Math.round(Math.round(x));
        int yy = Math.round(Math.round(y));
        window.setLocation(xx, yy);
        window.repaint();
        long now = System.currentTimeMillis() / 1000L;
        long diff = now - startTime;
        System.out.println(diff);
        if (diff > seconds) {
            moveTimer.stop();
        }
    });
    moveTimer.start();
}
Also used : Dimension(java.awt.Dimension) Frame(java.awt.Frame) SparkManager(org.jivesoftware.spark.SparkManager) Window(java.awt.Window) Point(java.awt.Point) JFrame(javax.swing.JFrame) Timer(javax.swing.Timer) Toolkit(java.awt.Toolkit) Timer(javax.swing.Timer) JFrame(javax.swing.JFrame) Dimension(java.awt.Dimension)

Example 24 with Timer

use of javax.swing.Timer in project grafikon by jub77.

the class WaitDialog method propertyChange.

@Override
public void propertyChange(PropertyChangeEvent evt) {
    log.trace("Event received: {}, {}", evt.getPropertyName(), evt.getNewValue());
    if ("state".equals(evt.getPropertyName())) {
        if (evt.getNewValue() == ActionContext.WaitDialogState.HIDE) {
            this.setVisible(false);
        } else if (evt.getNewValue() == ActionContext.WaitDialogState.SHOW) {
            final ActionContext context = (ActionContext) evt.getSource();
            Timer timer = new Timer(context.getDelay(), new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    progressBar.setValue(context.getProgress());
                    progressBar.setVisible(context.isShowProgress());
                    pack();
                    if (context.getLocationComponent() != null) {
                        setLocationRelativeTo(context.getLocationComponent());
                    }
                    setVisible(true);
                }
            });
            timer.setRepeats(false);
            timer.start();
        }
    } else if ("description".equals(evt.getPropertyName())) {
        String newValue = (String) evt.getNewValue();
        if (newValue != null) {
            messageLabel.setText(newValue);
        }
    } else if ("progress".equals(evt.getPropertyName())) {
        progressBar.setValue((Integer) evt.getNewValue());
    } else if ("progressDescription".equals(evt.getPropertyName())) {
        String newValue = (String) evt.getNewValue();
        progressBar.setString(newValue);
    }
}
Also used : Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ActionContext(net.parostroj.timetable.gui.actions.execution.ActionContext)

Example 25 with Timer

use of javax.swing.Timer in project code-sample by SprintBean.

the class LambdaTest method methodReferenceTest.

@Test
public void methodReferenceTest() {
    Timer timer = new Timer(1000, (ActionEvent event) -> System.out.println(event));
    // //可以写成方法引用的形式
    // 等价于x->System.out.println(x)
    timer = new Timer(1000, (x) -> {
        System.out.println(x);
    });
    // 
    Arrays.sort(new String[] { "abc", "soa", "pod" }, (x, y) -> {
        return x.compareToIgnoreCase(y);
    });
}
Also used : Slf4j(lombok.extern.slf4j.Slf4j) java.util(java.util) Stream(java.util.stream.Stream) Person(com.huangjunlin.learning.model.Person) BiFunction(java.util.function.BiFunction) IntConsumer(java.util.function.IntConsumer) Test(org.junit.Test) ActionEvent(java.awt.event.ActionEvent) Timer(javax.swing.Timer) Timer(javax.swing.Timer) ActionEvent(java.awt.event.ActionEvent) Test(org.junit.Test)

Aggregations

Timer (javax.swing.Timer)130 ActionEvent (java.awt.event.ActionEvent)66 ActionListener (java.awt.event.ActionListener)62 IOException (java.io.IOException)12 JPanel (javax.swing.JPanel)12 JLabel (javax.swing.JLabel)11 BorderLayout (java.awt.BorderLayout)9 Dimension (java.awt.Dimension)9 Point (java.awt.Point)9 Color (java.awt.Color)8 JCheckBox (javax.swing.JCheckBox)8 MouseEvent (java.awt.event.MouseEvent)7 JFrame (javax.swing.JFrame)7 MouseAdapter (java.awt.event.MouseAdapter)6 Window (java.awt.Window)5 JButton (javax.swing.JButton)5 JDialog (javax.swing.JDialog)5 JScrollPane (javax.swing.JScrollPane)5 File (java.io.File)4 Date (java.util.Date)4