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));
}
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();
}
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();
}
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();
}
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();
}
Aggregations