001: package tide.editor;
002:
003: import snow.utils.gui.GUIUtils;
004: import javax.swing.event.MenuEvent;
005: import javax.swing.event.MenuListener;
006: import java.util.TimerTask;
007: import java.awt.BorderLayout;
008: import java.awt.FlowLayout;
009: import java.awt.event.*;
010: import java.awt.Insets;
011: import javax.swing.border.EmptyBorder;
012: import java.util.GregorianCalendar;
013: import java.util.Calendar;
014: import java.util.prefs.Preferences;
015: import java.util.Random;
016: import javax.swing.*;
017:
018: /** Has to be.
019: */
020: public final class NonSense {
021: private NonSense() {
022: }
023:
024: public static void create(JMenu menu) {
025: menu.addSeparator();
026: JMenu nsmenu = new JMenu("NonSense");
027: menu.add(nsmenu);
028:
029: Random r = new Random();
030:
031: JMenuItem instanceRandomInt = new JMenuItem(
032: "Random int for this instance: " + r.nextInt());
033: nsmenu.add(instanceRandomInt);
034: JMenuItem instanceRandomBool = new JMenuItem(
035: "Random boolean for this instance: " + r.nextBoolean());
036: nsmenu.add(instanceRandomBool);
037: nsmenu.addSeparator();
038:
039: int nin = r.nextInt();
040: String ni = Preferences.userRoot().get("random_int", null);
041: if (ni == null) {
042: Preferences.userRoot().put("random_int", "" + nin);
043: } else {
044: try {
045: nin = Integer.parseInt(ni);
046: } catch (NumberFormatException ign) {
047: }
048: }
049:
050: JMenuItem userAndJVMRandomInt = new JMenuItem(
051: "Random int for this JVM and this user: " + nin);
052: nsmenu.add(userAndJVMRandomInt);
053:
054: JMenuItem eternalWait = new JMenuItem("Nothing for impatients");
055: nsmenu.addSeparator();
056: nsmenu.add(eternalWait);
057: eternalWait.addActionListener(new ActionListener() {
058: public void actionPerformed(ActionEvent ae) {
059: pleaseWait();
060: }
061: });
062:
063: JMenuItem conf1 = new JMenuItem("Please confirm...");
064: nsmenu.add(conf1);
065: conf1.addActionListener(new ActionListener() {
066: public void actionPerformed(ActionEvent ae) {
067: goodChoice();
068: }
069: });
070: //+stupid questions
071: //+dummy invasion alerts
072: //+dummy blue screen.
073:
074: final JMenu subm = new JMenu("Search an end...");
075: nsmenu.add(subm);
076: infiniteSubmenu(subm, 1);
077:
078: /*
079: JMenuItem tech = new JMenuItem("What tIDE is ...");
080: nsmenu.add(tech);
081: tech.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) {
082: GUIUtils.displayInDialog(MainEditorFrame.instance, "What tIDE is",
083: GUIUtils.createReadOnlyDescriptionArea("<html><body>"
084: +"Whing sang klang mang klue smue"
085:
086: ));
087: } }); */
088: }
089:
090: private static void infiniteSubmenu(final JMenu subm,
091: final int level) {
092: /*int n = (int)(Math.random()*10);
093: for(int i=0*/
094: subm.addMenuListener(new MenuListener() {
095: public void menuCanceled(MenuEvent e) {
096: }
097:
098: public void menuDeselected(MenuEvent e) {
099: }
100:
101: public void menuSelected(MenuEvent e) {
102: String name = "deeper...";
103: JMenu jm = new JMenu(name);
104: subm.add(jm);
105: infiniteSubmenu(jm, level + 1);
106:
107: }
108: });
109: }
110:
111: private static void goodChoice() {
112: final JDialog d = new JDialog((JFrame) null, "Confirmation",
113: true);
114: JLabel lab = new JLabel("Are you sure ?");
115: lab.setBorder(new EmptyBorder(5, 5, 5, 5));
116: d.add(lab, BorderLayout.CENTER);
117: JPanel fp = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 2));
118: d.add(fp, BorderLayout.SOUTH);
119: ActionListener closeAction = new ActionListener() {
120: public void actionPerformed(ActionEvent ae) {
121: d.setVisible(false);
122: }
123: };
124: JButton yes1 = new JButton("Yes");
125: yes1.addActionListener(closeAction);
126: fp.add(yes1);
127: JButton yes2 = new JButton("Yes");
128: yes2.addActionListener(closeAction);
129: fp.add(yes2);
130:
131: d.pack();
132: d.setLocationRelativeTo(null);
133: d.setVisible(true);
134:
135: }
136:
137: private static void pleaseWait() {
138: final JDialog d = new JDialog((JFrame) null, "Please wait...",
139: true);
140: JLabel lab = new JLabel(
141: "Please wait until the sun burns out...");
142: lab.setBorder(new EmptyBorder(5, 5, 5, 5));
143: d.add(lab, BorderLayout.NORTH);
144:
145: JPanel cp = new JPanel(new BorderLayout(5, 5));
146: d.add(cp, BorderLayout.CENTER);
147: // cp.setBorder(new EmptyBorder(5,5,5,5));
148:
149: final JProgressBar pb = new JProgressBar();
150: pb.setStringPainted(true);
151: cp.add(pb, BorderLayout.CENTER);
152: final java.util.Timer timer = new java.util.Timer();
153: final Calendar c = GregorianCalendar.getInstance();
154:
155: timer.scheduleAtFixedRate(new TimerTask() {
156: public void run() {
157: c.setTimeInMillis(System.currentTimeMillis());
158:
159: int ry = 2007 - c.get(Calendar.YEAR) + 999;
160: //int rm = 11 - c.get(Calendar.MONTH);
161: int rd = 366 - c.get(c.DAY_OF_YEAR);
162: int rh = 24 - c.get(Calendar.HOUR_OF_DAY);
163: int rm = 60 - c.get(Calendar.MINUTE);
164: int rs = 60 - c.get(Calendar.SECOND);
165: StringBuilder sb = new StringBuilder(
166: " Remaining: 3'999'999'" + ry + " years, ");
167: sb.append("" + rd + " days, " + rh + " hours, ");
168: sb.append("" + rm + " minutes, " + rs + " seconds ");
169:
170: pb.setString(sb.toString());
171: }
172: }, 0L, 1000L);
173:
174: JPanel fp = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 2));
175: d.add(fp, BorderLayout.SOUTH);
176: ActionListener closeAction = new ActionListener() {
177: public void actionPerformed(ActionEvent ae) {
178: d.setVisible(false);
179: }
180: };
181:
182: JButton yes1 = new JButton("cancel");
183: yes1.setMargin(new Insets(1, 0, 1, 0));
184: yes1.addActionListener(closeAction);
185: fp.add(yes1);
186: yes1.setFocusPainted(false);
187:
188: d.pack();
189: d.setLocationRelativeTo(null);
190: d.setVisible(true);
191:
192: timer.cancel();
193:
194: }
195: }
|