SlowdownTest.java
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18: package xeij;
19:
20: import java.awt.event.*;
21: import java.lang.*;
22: import java.util.*;
23: import javax.swing.*;
24: import javax.swing.event.*;
25:
26: public class SlowdownTest {
27:
28: public static long sdtNano;
29: public static TimerTask sdtTask;
30:
31: public static JCheckBoxMenuItem sdtCheckBoxMenuItem;
32: public static SpinnerNumberModel sdtModel;
33: public static JSpinner sdtSpinner;
34: public static Box sdtBox;
35:
36: public static void sdtInit () {
37: sdtNano = 0L;
38: sdtTask = null;
39:
40: sdtCheckBoxMenuItem =
41: Multilingual.mlnText (
42: ComponentFactory.createCheckBoxMenuItem (
43: false,
44: "Slowdown test",
45: new ActionListener () {
46: @Override public void actionPerformed (ActionEvent ae) {
47: if (((JCheckBoxMenuItem) ae.getSource ()).isSelected ()) {
48: sdtStart ();
49: } else {
50: sdtStop ();
51: }
52: }
53: }),
54: "ja", "鈍化テスト");
55: sdtModel = new SpinnerNumberModel (0.0, 0.0, 99.9, 0.1);
56: sdtSpinner = ComponentFactory.createNumberSpinner (sdtModel, 4, new ChangeListener () {
57: @Override public void stateChanged (ChangeEvent ce) {
58: sdtCheckBoxMenuItem.setSelected (true);
59: sdtStart ();
60: }
61: });
62: sdtBox = ComponentFactory.createHorizontalBox (
63: Box.createHorizontalStrut (20),
64: sdtSpinner,
65: ComponentFactory.createLabel ("%"),
66: Box.createHorizontalGlue ()
67: );
68: }
69:
70:
71:
72: public static void sdtStart () {
73: sdtStop ();
74: sdtNano = XEiJ.TMR_INTERVAL * Math.round (10000.0 * sdtModel.getNumber ().doubleValue ());
75: sdtTask = new TimerTask () {
76: @Override public void run () {
77: long limit = System.nanoTime () + sdtNano;
78: while (System.nanoTime () < limit) {
79: }
80: }
81: };
82: XEiJ.tmrTimer.scheduleAtFixedRate (sdtTask, XEiJ.TMR_DELAY, XEiJ.TMR_INTERVAL);
83: }
84:
85:
86:
87: public static void sdtStop () {
88: if (sdtTask != null) {
89: sdtTask.cancel ();
90: sdtTask = null;
91: }
92: }
93:
94: }
95:
96:
97: