Search in sources :

Example 86 with Timer

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

the class VCardPanel method buildUI.

private void buildUI(final VCard vcard) {
    avatarImage.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent mouseEvent) {
            if (mouseEvent.getClickCount() == 2) {
                SparkManager.getVCardManager().viewProfile(vcard.getJabberId(), avatarImage);
            }
        }

        final Timer timer = new Timer(500, actionEvent -> showAvatarBig(true, vcard));

        @Override
        public void mouseEntered(MouseEvent e) {
            super.mouseEntered(e);
            timer.start();
        }

        @Override
        public void mouseExited(MouseEvent e) {
            super.mouseExited(e);
            timer.stop();
        }
    });
    String firstName = vcard.getFirstName();
    if (firstName == null) {
        firstName = "";
    }
    String lastName = vcard.getLastName();
    if (lastName == null) {
        lastName = "";
    }
    final JLabel usernameLabel = new JLabel();
    usernameLabel.setHorizontalTextPosition(JLabel.LEFT);
    usernameLabel.setFont(new Font("Dialog", Font.BOLD, 15));
    usernameLabel.setForeground(Color.GRAY);
    if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
        usernameLabel.setText(firstName + " " + lastName);
    } else {
        String nickname = SparkManager.getUserManager().getUserNicknameFromJID(jid);
        usernameLabel.setText(UserManager.unescapeJID(nickname));
    }
    final Icon icon = SparkManager.getChatManager().getIconForContactHandler(vcard.getJabberId());
    if (icon != null) {
        usernameLabel.setIcon(icon);
    }
    add(usernameLabel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 0));
    String title = vcard.getField("TITLE");
    if (ModelUtil.hasLength(title)) {
        final JLabel titleLabel = new JLabel(title);
        titleLabel.setFont(new Font("Dialog", Font.PLAIN, 11));
        add(titleLabel, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 7, 0, 0), 0, 0));
    }
    if (ModelUtil.hasLength(vcard.getEmailHome())) {
        emailAddress = vcard.getEmailHome();
    }
    final Color linkColor = new Color(49, 89, 151);
    final String unselectedText = "<html><body><font color=" + GraphicUtils.toHTMLColor(linkColor) + "><u>" + emailAddress + "</u></font></body></html>";
    final String hoverText = "<html><body><font color=red><u>" + emailAddress + "</u></font></body></html>";
    final JLabel emailTime = new JLabel(unselectedText);
    emailTime.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            startEmailClient(emailAddress);
        }

        public void mouseEntered(MouseEvent e) {
            emailTime.setText(hoverText);
            setCursor(LINK_CURSOR);
        }

        public void mouseExited(MouseEvent e) {
            emailTime.setText(unselectedText);
            setCursor(DEFAULT_CURSOR);
        }
    });
    add(emailTime, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 7, 5, 0), 0, 0));
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) MouseEvent(java.awt.event.MouseEvent) Insets(java.awt.Insets) Timer(javax.swing.Timer) Color(java.awt.Color) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) ImageIcon(javax.swing.ImageIcon) Icon(javax.swing.Icon) Font(java.awt.Font)

Example 87 with Timer

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

the class ShakeWindow method startShake.

public void startShake() {
    if (window instanceof JFrame) {
        JFrame f = (JFrame) window;
        f.setState(Frame.NORMAL);
        f.setVisible(true);
    }
    SparkManager.getNativeManager().flashWindow(window);
    naturalLocation = window.getLocation();
    startTime = System.currentTimeMillis();
    shakeTimer = new Timer(SHAKE_UPDATE, e -> {
        // calculate elapsed time
        long elapsed = System.currentTimeMillis() - startTime;
        // use sin to calculate an x-offset
        double waveOffset = (elapsed % SHAKE_CYCLE) / SHAKE_CYCLE;
        double angle = waveOffset * TWO_PI;
        // offset the x-location by an amount
        // proportional to the sine, up to
        // shake_distance
        int shakenX = (int) ((Math.sin(angle) * SHAKE_DISTANCE) + naturalLocation.x);
        int shakenY;
        if (added) {
            shakenY = naturalLocation.y - 10;
            added = false;
        } else {
            shakenY = naturalLocation.y + 10;
            added = true;
        }
        window.setLocation(shakenX, shakenY);
        window.repaint();
        // should we stop timer?
        if (elapsed >= SHAKE_DURATION)
            stopShake();
    });
    shakeTimer.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)

Example 88 with Timer

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

the class DelayedMouseListener method mouseClicked.

public void mouseClicked(final MouseEvent me) {
    if (me.getButton() != button) {
        delegate.mouseClicked(me);
        return;
    }
    if (timer != null) {
        timer.stop();
        timer = null;
        clickCounter++;
    } else {
        clickCounter = 1;
    }
    if (clickCounter == maxClickNumber) {
        delegate.mouseClicked(me);
        delegate.mouseReleased(me);
        return;
    }
    timer = new Timer(MAX_TIME_BETWEEN_CLICKS, new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            final MouseEvent newMouseEvent = new MouseEvent(me.getComponent(), me.getID(), e.getWhen(), me.getModifiers(), me.getX(), me.getY(), clickCounter, me.isPopupTrigger(), button);
            delegate.mouseClicked(newMouseEvent);
            timer = null;
        }
    });
    timer.setRepeats(false);
    timer.start();
// me.consume();
}
Also used : MouseEvent(java.awt.event.MouseEvent) Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent)

Example 89 with Timer

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

the class MapViewDockingWindows method focusMapViewLater.

public void focusMapViewLater(final MapView mapView) {
    Timer timer = new Timer(40, new ActionListener() {

        int retryCount = 5;

        public void actionPerformed(final ActionEvent event) {
            final Timer eventTimer = (Timer) event.getSource();
            focusMapLater(mapView, eventTimer);
        }

        private void focusMapLater(final MapView mapView, final Timer eventTimer) {
            if (mapView.isShowing() && Controller.getCurrentController().getMapViewManager().getMapViewComponent() == mapView) {
                final NodeView selected = mapView.getSelected();
                if (selected != null) {
                    final Frame frame = JOptionPane.getFrameForComponent(mapView);
                    if (frame.isFocused())
                        selected.requestFocusInWindow();
                    else
                        frame.addWindowFocusListener(new WindowAdapter() {

                            @Override
                            public void windowGainedFocus(WindowEvent e) {
                                frame.removeWindowFocusListener(this);
                                selected.requestFocusInWindow();
                                retryCount = 2;
                                eventTimer.start();
                            }
                        });
                }
            }
            if (retryCount > 1) {
                retryCount--;
                eventTimer.start();
            }
        }
    });
    timer.setRepeats(false);
    timer.start();
}
Also used : JFrame(javax.swing.JFrame) Frame(java.awt.Frame) Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) WindowEvent(java.awt.event.WindowEvent) MapView(org.freeplane.view.swing.map.MapView) WindowAdapter(java.awt.event.WindowAdapter) DockingWindowAdapter(net.infonode.docking.DockingWindowAdapter) NodeView(org.freeplane.view.swing.map.NodeView)

Example 90 with Timer

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

the class UpdateCheckAction method setTimer.

private void setTimer() {
    if (autorunEnabled == false) {
        return;
    }
    autorunEnabled = ResourceController.getResourceController().getBooleanProperty(CHECK_UPDATES_AUTOMATICALLY);
    if (autorunEnabled == false) {
        return;
    }
    autorunEnabled = false;
    final Date now = new Date();
    final long nextCheckMillis = ResourceController.getResourceController().getLongProperty(LAST_UPDATE_CHECK_TIME, 0) + ONE_DAY;
    final Date nextCheckDate = new Date(nextCheckMillis);
    if (now.before(nextCheckDate)) {
        final FreeplaneVersion knownNewVersion = getKnownNewVersion();
        addUpdateButton(knownNewVersion);
        return;
    }
    autorunTimer = new Timer(CHECK_TIME, this);
    autorunTimer.setRepeats(false);
    autorunTimer.start();
}
Also used : Timer(javax.swing.Timer) FreeplaneVersion(org.freeplane.core.util.FreeplaneVersion) Date(java.util.Date)

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