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