Search in sources :

Example 26 with Timer

use of javax.swing.Timer in project chatty by chatty.

the class ActivityTracker method startTracking.

/**
 * Start tracking activity (globally currently only mouse activity, inside
 * of the program keypresses and mouse actions).
 */
public static void startTracking() {
    if (timer == null) {
        checkMouseLocation();
        timer = new Timer(DELAY, new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                checkMouseLocation();
            }
        });
        timer.start();
        Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {

            @Override
            public void eventDispatched(AWTEvent event) {
                triggerActivity();
            }
        }, AWTEvent.KEY_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK);
        LOGGER.info("Started tracking user activity..");
    }
}
Also used : Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) AWTEventListener(java.awt.event.AWTEventListener) AWTEvent(java.awt.AWTEvent)

Example 27 with Timer

use of javax.swing.Timer in project sonarlint-intellij by SonarSource.

the class LastAnalysisPanel method setTimer.

private void setTimer() {
    lastAnalysisTimeUpdater = new Timer(5000, e -> {
        if (lastAnalysis != null) {
            setLastAnalysisLabel();
            panel.repaint();
        }
    });
    lastAnalysisTimeUpdater.start();
}
Also used : DateUtils(org.sonarsource.sonarlint.core.client.api.util.DateUtils) CardLayout(java.awt.CardLayout) GridBagConstraints(java.awt.GridBagConstraints) Instant(java.time.Instant) Disposable(com.intellij.openapi.Disposable) Box(javax.swing.Box) JBUI(com.intellij.util.ui.JBUI) JLabel(javax.swing.JLabel) SonarLintIcons(icons.SonarLintIcons) Disposer(com.intellij.openapi.util.Disposer) Project(com.intellij.openapi.project.Project) GridBagLayout(java.awt.GridBagLayout) Nullable(javax.annotation.Nullable) JPanel(javax.swing.JPanel) Timer(javax.swing.Timer) Timer(javax.swing.Timer)

Example 28 with Timer

use of javax.swing.Timer in project clusterMaker2 by RBVI.

the class TreeView method handleEvent.

public void handleEvent(RowsSetEvent e) {
    if (!e.containsColumn(CyNetwork.SELECTED))
        return;
    if (ignoreSelection) {
        return;
    }
    // System.out.println("Got selection event");
    CyTable table = e.getSource();
    CyNetwork net = networkTableManager.getNetworkForTable(table);
    Class<?> type = networkTableManager.getTableType(table);
    if (pendingSelections == null)
        pendingSelections = new HashSet<CyIdentifiable>();
    if (type.equals(CyNode.class)) {
        // if (dataModel.isSymmetrical()) return;
        for (RowSetRecord record : e.getColumnRecords(CyNetwork.SELECTED)) {
            Long nodeSUID = record.getRow().get(CyIdentifiable.SUID, Long.class);
            CyNode node = net.getNode(nodeSUID);
            if ((Boolean) record.getValue()) {
                if (node != null)
                    pendingSelections.add(node);
            } else if (pendingSelections.contains(node)) {
                pendingSelections.remove(node);
            }
        }
    /*
			List<CyNode> selectedNodes = CyTableUtil.getNodesInState(net, CyNetwork.SELECTED, true);
			setNodeSelection(selectedNodes, true);
			*/
    } else if (type.equals(CyEdge.class) && dataModel.isSymmetrical()) {
        // System.out.println("Edge selection");
        for (RowSetRecord record : e.getColumnRecords(CyNetwork.SELECTED)) {
            Long edgeSUID = record.getRow().get(CyIdentifiable.SUID, Long.class);
            CyEdge edge = net.getEdge(edgeSUID);
            if ((Boolean) record.getValue()) {
                if (edge != null)
                    pendingSelections.add(edge);
            } else if (pendingSelections.contains(edge)) {
                pendingSelections.remove(edge);
            }
        }
    // List<CyEdge> selectedEdges = CyTableUtil.getEdgesInState(net, CyNetwork.SELECTED, true);
    // setEdgeSelection(selectedEdges, true);
    }
    if (selectionTimer == null) {
        selectionTimer = new Timer(200, new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                // System.out.println("Selection Timer fired");
                List<CyEdge> edges = new ArrayList<CyEdge>();
                List<CyNode> nodes = new ArrayList<CyNode>();
                for (CyIdentifiable id : pendingSelections) {
                    if (CyEdge.class.isAssignableFrom(id.getClass())) {
                        edges.add((CyEdge) id);
                    } else if (CyNode.class.isAssignableFrom(id.getClass())) {
                        nodes.add((CyNode) id);
                    }
                }
                if (edges.size() > 0) {
                    setEdgeSelection(edges, true);
                // System.out.println("Selecting "+edges.size()+" edges");
                } else {
                    setNodeSelection(nodes, true);
                // System.out.println("Selecting "+nodes.size()+" nodes");
                }
            // pendingSelections.clear();
            }
        });
        selectionTimer.setCoalesce(true);
        selectionTimer.setRepeats(false);
        selectionTimer.start();
    } else if (selectionTimer.isRunning()) {
    // Don't do anything
    } else {
        selectionTimer.restart();
    }
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) CyTable(org.cytoscape.model.CyTable) Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) CyNode(org.cytoscape.model.CyNode) HashSet(java.util.HashSet) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 29 with Timer

use of javax.swing.Timer in project opennars by opennars.

the class PercentLayoutAnimator method start.

public void start() {
    animatorTimer = new Timer(15, this);
    animatorTimer.start();
}
Also used : Timer(javax.swing.Timer)

Example 30 with Timer

use of javax.swing.Timer in project chatty by chatty.

the class Channel method setTextPreferredSizeTemporarily.

/**
 * Setting the preferred size to 0, so the text pane doesn't influence the
 * size of the userlist. Setting it back later so it doesn't flicker when
 * being scrolled up (and possibly other issues). This is an ugly hack, but
 * I don't know enough about this to find a proper solution.
 */
private void setTextPreferredSizeTemporarily() {
    text.setPreferredSize(new Dimension(0, 0));
    Timer t = new Timer(5000, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            text.setPreferredSize(null);
        }
    });
    t.setRepeats(false);
    t.start();
}
Also used : Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Dimension(java.awt.Dimension)

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