001: /*
002: * (c) Copyright 2000 wingS development team.
003: *
004: * This file is part of the wingS demo (http://j-wings.org).
005: *
006: * The wingS demo is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013:
014: package desktop;
015:
016: import org.wings.*;
017: import org.wings.border.SEmptyBorder;
018: import org.wings.event.SContainerEvent;
019: import org.wings.event.SContainerListener;
020: import org.wings.header.Link;
021: import org.wings.resource.DefaultURLResource;
022: import org.wings.style.CSSProperty;
023: import org.wings.util.ComponentVisitor;
024:
025: import java.awt.*;
026: import java.awt.event.ActionEvent;
027: import java.awt.event.ActionListener;
028: import java.util.*;
029: import java.util.List;
030: import java.util.prefs.BackingStoreException;
031: import java.util.prefs.Preferences;
032:
033: /**
034: * @author Holger Engels
035: */
036: public class Desktop implements SConstants {
037: SFrame frame;
038: Map<String, DesktopPane> panes = new HashMap<String, DesktopPane>();
039: SMenu windowMenu;
040: SMenuBar menuBar;
041: int editorNumber = 0;
042: int xPos = 0;
043: Preferences prefRoot;
044:
045: public Desktop() {
046:
047: frame = new SFrame("Desktop");
048: frame.setAttribute(CSSProperty.MARGIN, "4px");
049: frame.setVisible(true);
050: prefRoot = Preferences.userRoot();
051: try {
052: if (prefRoot.nodeExists("desktoppanes"))
053: Desktop.this .loadExisting(frame.getContentPane());
054: else
055: Desktop.this .createNew(frame.getContentPane());
056: } catch (BackingStoreException ex) {
057: System.out
058: .println("BackingStoreException. Falling back to default settings");
059: Desktop.this .createNew(frame.getContentPane());
060: }
061:
062: frame.addHeader(new Link("stylesheet", null, "text/css", null,
063: new DefaultURLResource("../desktop.css")));
064: flushPreferences();
065: frame.show();
066: }
067:
068: private void createNew(SContainer contentPane) {
069:
070: //first clear all old stuf..
071: try {
072: for (String name : Preferences.userRoot().childrenNames()) {
073: Preferences.userRoot().node(name).removeNode();
074: }
075:
076: } catch (Exception ex) {
077: ex.printStackTrace();
078: }
079: contentPane.removeAll();
080: EditorPanel.resetEditorNo();
081:
082: menuBar = createMenu();
083:
084: final DesktopPane desktop = new DesktopPane();
085:
086: // add the frames to the window-menu ..
087: desktop.addContainerListener(new DesktopFrameListener(desktop));
088:
089: final DesktopPane feeds = new DesktopPane();
090:
091: feeds.addContainerListener(new DesktopFrameListener(feeds));
092:
093: contentPane.setLayout(new SGridBagLayout());
094:
095: GridBagConstraints c1 = new GridBagConstraints();
096: GridBagConstraints c2 = new GridBagConstraints();
097: GridBagConstraints c3 = new GridBagConstraints();
098: c1.gridwidth = GridBagConstraints.REMAINDER;
099: c1.weightx = 1.0;
100: contentPane.add(menuBar, c1);
101: c2.gridx = xPos;
102: xPos++;
103: c2.gridy = 1;
104: c2.weightx = 0.7;
105: contentPane.add(desktop, c2);
106: panes.put(desktop.getName(), desktop);
107: prefRoot.node("desktoppanes").node(desktop.getName())
108: .putDouble(DesktopPane.WEIGHTX, c2.weightx);
109:
110: c3.gridx = xPos;
111: xPos++;
112: c3.gridy = 1;
113: c3.weightx = 0.3;
114: contentPane.add(feeds, c3);
115: prefRoot.node("desktoppanes").node(feeds.getName()).putDouble(
116: DesktopPane.WEIGHTX, c3.weightx);
117: panes.put(feeds.getName(), feeds);
118:
119: DesktopItem ed = new EditorItem();
120: ed.putValue(EditorItem.TEXT, getStory());
121: desktop.addDesktopItem(ed);
122:
123: DesktopItem feed = new NewsFeedItem();
124: feed.putValue(DesktopItem.NAME, "heise news ticker");
125: feed.putValue(NewsFeedItem.FEED,
126: "http://www.heise.de/english/newsticker/news.rdf");
127: feeds.addDesktopItem(feed);
128:
129: DesktopItem feed2 = new NewsFeedItem();
130: feed2.putValue(DesktopItem.NAME, "the server side");
131: feed2
132: .putValue(NewsFeedItem.FEED,
133: "http://www.theserverside.com/rss/theserverside-rss2.xml");
134: feeds.addDesktopItem(feed2);
135: }
136:
137: private void loadExisting(SContainer contentPane) {
138: contentPane.setLayout(new SGridBagLayout());
139: menuBar = createMenu();
140: GridBagConstraints c1 = new GridBagConstraints();
141: c1.gridwidth = GridBagConstraints.REMAINDER;
142: c1.weightx = 1.0;
143: c1.gridy = 0;
144: contentPane.add(menuBar, c1);
145:
146: int firstFreePane = 0;
147: int firstFreeItem = 0;
148:
149: try {
150: for (String paneName : prefRoot.node("desktoppanes")
151: .childrenNames()) {
152: Preferences paneNode = prefRoot.node("desktoppanes")
153: .node(paneName);
154: DesktopPane p = new DesktopPane(paneName);
155: p.addContainerListener(new DesktopFrameListener(p));
156: firstFreePane = Math.max(firstFreePane, paneNode
157: .getInt(DesktopPane.FIRST_FREE_INDEX, 0));
158: GridBagConstraints c = new GridBagConstraints();
159: c.gridx = xPos;
160: c.gridy = 1;
161: xPos++;
162: c.weightx = paneNode
163: .getDouble(DesktopPane.WEIGHTX, 0.2);
164: contentPane.add(p, c);
165: panes.put(p.getName(), p);
166: List<DesktopItem> items = new ArrayList<DesktopItem>();
167:
168: for (String itemName : prefRoot.node("desktopitems")
169: .childrenNames()) {
170:
171: Preferences itemNode = prefRoot
172: .node("desktopitems").node(itemName);
173:
174: if (!paneName.equals(itemNode.get(
175: DesktopItem.DESKTOPPANE, "nix")))
176: continue;
177:
178: firstFreeItem = Math.max(firstFreeItem, itemNode
179: .getInt(DesktopItem.FIRST_FREE_INDEX, 0));
180: DesktopItem item = ToolRegistry.getToolRegistry()
181: .getRegisteredTools().get(
182: itemNode.get(DesktopItem.TOOL,
183: "EditorTool"))
184: .getExistingItem(itemName);
185:
186: String[] keys = itemNode.keys();
187:
188: for (String key : keys) {
189:
190: if (!key.equals(DesktopItem.DESKTOPPANE)
191: && !key
192: .equals(DesktopItem.FIRST_FREE_INDEX)
193: && !key.equals(DesktopItem.TOOL)) {
194: if (key.equals(DesktopItem.KEY))
195: item.putValue(key, itemNode
196: .get(key, ""));
197: else if (key
198: .equals(DesktopItem.POSITION_ON_PANE))
199: item.putValue(key, itemNode.getInt(key,
200: -100));
201: else if (key.equals(DesktopItem.TEXT))
202: item.putValue(key, itemNode
203: .get(key, ""));
204: else if (isIntValue(itemNode, key))
205: item
206: .putValue(
207: key,
208: (Integer) itemNode
209: .getInt(
210: key,
211: Integer.MIN_VALUE));
212: else if (isBooleanValue(itemNode, key))
213: item.putValue(key, itemNode.getBoolean(
214: key, true));
215: else if (isFloatValue(itemNode, key))
216: item.putValue(key, itemNode.getFloat(
217: key, Float.NaN));
218: else if (isDoubleValue(itemNode, key))
219: item.putValue(key, Double.NaN);
220: else if (isLongValue(itemNode, key))
221: item.putValue(key, itemNode.getLong(
222: key, Long.MIN_VALUE));
223: else {
224: item.putValue(key, itemNode
225: .get(key, ""));
226: }
227:
228: }
229: }
230:
231: boolean putToEnd = true;
232:
233: for (int i = 0; i < items.size(); i++) {
234: int itemValue = ((Integer) item
235: .getValue(DesktopItem.POSITION_ON_PANE))
236: .intValue();
237: int listValue = ((Integer) items.get(i)
238: .getValue(DesktopItem.POSITION_ON_PANE))
239: .intValue();
240:
241: if (itemValue < listValue) {
242: items.add(i, item);
243: putToEnd = false;
244: break;
245: }
246: }
247:
248: if (putToEnd)
249: items.add(item);
250: }
251: for (DesktopItem item : items) {
252: p.addExistingDesktopItem(item);
253: }
254: }
255:
256: } catch (Exception e) {
257: e.printStackTrace();
258: }
259:
260: DesktopPane.paneNo.set(firstFreePane);
261: AbstractDesktopItem.itemNo.set(firstFreeItem);
262: }
263:
264: private boolean isBooleanValue(Preferences node, String key) {
265: boolean b1 = node.getBoolean(DesktopItem.ICON, true);
266: boolean b2 = node.getBoolean(DesktopItem.ICON, false);
267: return b1 == b2;
268: }
269:
270: private boolean isFloatValue(Preferences node, String key) {
271: Float f = node.getFloat(key, Float.NaN);
272: return !f.equals(Float.NaN);
273: }
274:
275: private boolean isDoubleValue(Preferences node, String key) {
276: Double d = node.getDouble(key, Double.NaN);
277: return !d.equals(Double.NaN);
278: }
279:
280: private boolean isLongValue(Preferences node, String key) {
281: Long l = node.getLong(key, Long.MIN_VALUE);
282: return !l.equals(Long.MIN_VALUE);
283: }
284:
285: private boolean isIntValue(Preferences node, String key) {
286: int i = node.getInt(key, -3245);
287: return i != -3245;
288: }
289:
290: private boolean isByteArrayValue(Preferences node, String key) {
291: byte[] ba = node.getByteArray(key, new byte[0]);
292:
293: return ba.length != 0;
294: }
295:
296: protected String getStory() {
297: return "Ein Philosoph ist jemand, der in einem absolut dunklen Raum "
298: + "mit verbundenen Augen nach einer schwarzen Katze sucht, die gar nicht "
299: + "da ist. Ein Theologe ist jemand der genau das gleiche macht und ruft: "
300: + "\"ich hab sie!\"";
301: }
302:
303: protected SMenuBar createMenu() {
304:
305: SMenu fileMenu = new SMenu("File");
306: SMenuItem fileMenuItem;
307:
308: for (final DesktopTool tool : ToolRegistry.getToolRegistry()
309: .getRegisteredTools().values()) {
310: fileMenuItem = new SMenuItem(tool.getText());
311: fileMenuItem.addActionListener(new ActionListener() {
312: public void actionPerformed(ActionEvent evt) {
313: DesktopPane paneToAddTo = null;
314: for (DesktopPane pane : panes.values()) {
315: if (pane.getParentFrame() != null) {
316: paneToAddTo = pane;
317: break;
318: }
319: }
320: if (paneToAddTo == null)
321: paneToAddTo = new DesktopPane();
322:
323: paneToAddTo.addDesktopItem(tool.getItem());
324: }
325: });
326: fileMenu.add(fileMenuItem);
327: }
328:
329: windowMenu = new SMenu("Window");
330:
331: SMenuItem newPaneItem = new SMenuItem("new Column");
332: newPaneItem.addActionListener(new ActionListener() {
333: public void actionPerformed(ActionEvent evt) {
334: SContainer contentPane = frame.getContentPane();
335: int paneCount = contentPane.getComponentCount() - 1;
336:
337: int ct = 0;
338: if (contentPane.getComponentCount() >= 3) {
339: for (int i = 0; i < contentPane.getComponentCount(); i++) {
340: if (ct > 1)
341: break;
342:
343: if (contentPane.getComponent(i) instanceof DesktopPane) {
344: if (((GridBagConstraints) contentPane
345: .getConstraintAt(i)).weightx >= 0.2) {
346: ((GridBagConstraints) contentPane
347: .getConstraintAt(i)).weightx -= 0.1;
348: prefRoot
349: .node("desktoppanes")
350: .node(
351: contentPane
352: .getComponent(i)
353: .getName())
354: .putDouble(
355: DesktopPane.WEIGHTX,
356: ((GridBagConstraints) contentPane
357: .getConstraintAt(i)).weightx);
358: ct++;
359: }
360:
361: }
362: }
363: } else {
364: for (int i = 0; i < contentPane.getComponentCount(); i++) {
365: if (contentPane.getComponent(i) instanceof DesktopPane) {
366: ((GridBagConstraints) contentPane
367: .getConstraintAt(i)).weightx -= 0.2;
368: prefRoot
369: .node("desktoppanes")
370: .node(
371: contentPane.getComponent(i)
372: .getName())
373: .putDouble(
374: DesktopPane.WEIGHTX,
375: ((GridBagConstraints) contentPane
376: .getConstraintAt(i)).weightx);
377: break;
378: }
379: }
380: }
381:
382: final DesktopPane newPane = new DesktopPane();
383: GridBagConstraints c = new GridBagConstraints();
384: c.gridx = xPos;
385: xPos++;
386: c.gridy = 1;
387: c.weightx = 0.2;
388:
389: newPane.addContainerListener(new DesktopFrameListener(
390: newPane));
391:
392: panes.put(newPane.getName(), newPane);
393: contentPane.add(newPane, c);
394: prefRoot.node("desktoppanes").node(newPane.getName())
395: .putDouble(DesktopPane.WEIGHTX, c.weightx);
396: flushPreferences();
397:
398: }
399: });
400:
401: SMenuItem editPanesItem = new SMenuItem("edit Columns");
402: editPanesItem.addActionListener(new ActionListener() {
403:
404: class EditOptionPane extends SOptionPane {
405: public void updateOkButtonEnabledState() {
406: if (freeSpace < 0)
407: this .optionOK.setEnabled(false);
408: else
409: this .optionOK.setEnabled(true);
410: }
411: }
412:
413: int freeSpace = 100;
414: List<String> backups = new ArrayList<String>();
415: final SPanel inputPanel = new SPanel();
416: EditOptionPane optionPane = new EditOptionPane();
417: List<DesktopPane> toBeRemoved = new ArrayList<DesktopPane>();
418:
419: private double roundTo1Digit(double toRound) {
420: if (toRound > 0)
421: return (int) (toRound * 100 + 0.5) / 100.0;
422: else
423: return (int) (toRound * 100 - 0.5) / 100.0;
424: }
425:
426: public void actionPerformed(ActionEvent evt) {
427: final STextField freeSpaceField = new STextField(String
428: .valueOf(freeSpace));
429: inputPanel.removeAll();
430: inputPanel.setLayout(new SGridLayout(frame
431: .getContentPane().getComponentCount(), 6));
432: inputPanel.setBorder(new SEmptyBorder(10, 10, 10, 10));
433: freeSpace = 100;
434: backups.clear();
435: toBeRemoved.clear();
436: for (int i = 0; i < frame.getContentPane()
437: .getComponentCount(); i++) {
438: backups.add(String
439: .valueOf(((GridBagConstraints) frame
440: .getContentPane()
441: .getConstraintAt(i)).weightx));
442: }
443:
444: for (int i = 0; i < frame.getContentPane()
445: .getComponentCount(); i++) {
446: if (frame.getContentPane().getComponent(i) instanceof DesktopPane) {
447: final DesktopPane pane = (DesktopPane) frame
448: .getContentPane().getComponent(i);
449: final SLabel nameLabel = new SLabel(pane
450: .getName()
451: + " ");
452: inputPanel.add(nameLabel);
453: final GridBagConstraints c = (GridBagConstraints) frame
454: .getContentPane().getConstraintAt(i);
455:
456: freeSpace -= Math.round(100 * c.weightx);
457:
458: final STextField tf = new STextField(String
459: .valueOf(Math.round(100 * c.weightx)));
460: tf.addActionListener(new ActionListener() {
461: public void actionPerformed(ActionEvent e) {
462: try {
463: int input = Integer.parseInt(e
464: .getActionCommand());
465: if (input >= 0 && input <= 100) {
466:
467: freeSpace -= (input - Math
468: .round(100 * c.weightx));
469: freeSpaceField.setText(String
470: .valueOf(freeSpace));
471: c.weightx = input * 0.01;
472: prefRoot
473: .node("desktoppanes")
474: .node(pane.getName())
475: .putDouble(
476: DesktopPane.WEIGHTX,
477: c.weightx);
478:
479: optionPane
480: .updateOkButtonEnabledState();
481: } else
482: tf
483: .setText(String
484: .valueOf(Math
485: .round(100 * c.weightx)));
486: } catch (java.lang.NumberFormatException ex) {
487: tf.setText(String.valueOf(Math
488: .round(100 * c.weightx)));
489: }
490:
491: }
492: });
493:
494: inputPanel.add(tf);
495: final SLabel percentLabel = new SLabel(" % ");
496: inputPanel.add(percentLabel);
497:
498: final SButton plusButton = new SButton("+");
499: plusButton
500: .addActionListener(new ActionListener() {
501: public void actionPerformed(
502: ActionEvent e) {
503: c.weightx = roundTo1Digit(c.weightx + 0.1);
504: prefRoot
505: .node("desktoppanes")
506: .node(pane.getName())
507: .putDouble(
508: DesktopPane.WEIGHTX,
509: c.weightx);
510: freeSpace -= 10;
511: tf
512: .setText(String
513: .valueOf(Math
514: .round(100 * c.weightx)));
515: freeSpaceField.setText(String
516: .valueOf(freeSpace));
517:
518: optionPane
519: .updateOkButtonEnabledState();
520:
521: }
522: });
523:
524: final SButton minusButton = new SButton("-");
525: minusButton
526: .addActionListener(new ActionListener() {
527: public void actionPerformed(
528: ActionEvent e) {
529: if (Double.parseDouble(tf
530: .getText()) >= 10) {
531: c.weightx = roundTo1Digit(c.weightx - 0.1);
532: prefRoot
533: .node(
534: "desktoppanes")
535: .node(
536: pane
537: .getName())
538: .putDouble(
539: DesktopPane.WEIGHTX,
540: c.weightx);
541: freeSpace += 10;
542: tf
543: .setText(String
544: .valueOf(Math
545: .round(100.0 * c.weightx)));
546: freeSpaceField
547: .setText(String
548: .valueOf(freeSpace));
549:
550: optionPane
551: .updateOkButtonEnabledState();
552: }
553: }
554: });
555:
556: final SButton removeButton = new SButton(
557: "remove");
558: removeButton
559: .addActionListener(new ActionListener() {
560: public void actionPerformed(
561: ActionEvent e) {
562: toBeRemoved.add(pane);
563: freeSpace += (int) Math
564: .round(100 * c.weightx);
565: freeSpaceField.setText(String
566: .valueOf(freeSpace));
567:
568: //remove column from dialog
569: inputPanel.remove(nameLabel);
570: inputPanel.remove(tf);
571: inputPanel.remove(percentLabel);
572: inputPanel.remove(plusButton);
573: inputPanel.remove(minusButton);
574: inputPanel.remove(removeButton);
575:
576: optionPane
577: .updateOkButtonEnabledState();
578:
579: }
580: });
581:
582: inputPanel.add(plusButton);
583: inputPanel.add(minusButton);
584: inputPanel.add(removeButton);
585: }
586: }
587: inputPanel.add(new SLabel("Free Space"));
588: freeSpaceField.setText(String.valueOf(freeSpace));
589:
590: inputPanel.add(freeSpaceField);
591: inputPanel.add(new SLabel(" % "));
592:
593: optionPane = new EditOptionPane();
594: optionPane.addActionListener(new ActionListener() {
595: public void actionPerformed(ActionEvent e) {
596: if (e.getActionCommand() == SOptionPane.OK_ACTION) {
597:
598: for (int i = 0; i < frame.getContentPane()
599: .getComponentCount(); i++) {
600: if (frame.getContentPane()
601: .getComponent(i) instanceof DesktopPane) {
602: DesktopPane dp = (DesktopPane) frame
603: .getContentPane()
604: .getComponent(i);
605: if (toBeRemoved.contains(dp)) {
606: dp.removeAll();
607: frame.getContentPane().remove(
608: dp);
609: try {
610: prefRoot.node(
611: "desktoppanes")
612: .node(dp.getName())
613: .removeNode();
614: } catch (BackingStoreException ex) {
615:
616: }
617:
618: i--;
619: }
620: }
621: }
622:
623: frame.getContentPane().setLayout(
624: ((SGridBagLayout) frame
625: .getContentPane()
626: .getLayout()));
627:
628: }
629:
630: else {
631: //put backup back in
632: for (int i = 0; i < frame.getContentPane()
633: .getComponentCount(); i++) {
634: //ignore the menu
635: if (frame.getContentPane()
636: .getComponent(i) instanceof SMenuBar)
637: continue;
638:
639: GridBagConstraints c = (GridBagConstraints) frame
640: .getContentPane()
641: .getConstraintAt(i);
642: c.weightx = java.lang.Double
643: .parseDouble(backups.get(i));
644: prefRoot
645: .node("desktoppanes")
646: .node(
647: frame
648: .getContentPane()
649: .getComponent(i)
650: .getName())
651: .putDouble(
652: DesktopPane.WEIGHTX,
653: ((GridBagConstraints) frame
654: .getContentPane()
655: .getConstraintAt(
656: i)).weightx);
657: }
658: }
659: }
660: });
661:
662: optionPane.showInput(frame, "Resize Desktop Panes",
663: inputPanel, "Resize Desktop Panes");
664: flushPreferences();
665: }
666: });
667:
668: SMenuItem resetItem = new SMenuItem("Reset Desktop");
669: resetItem.addActionListener(new ActionListener() {
670: public void actionPerformed(ActionEvent evt) {
671: Desktop.this .createNew(frame.getContentPane());
672: }
673: });
674:
675: SMenu desktopMenu = new SMenu("Desktop");
676: desktopMenu.add(newPaneItem);
677: desktopMenu.add(editPanesItem);
678: desktopMenu.add(resetItem);
679:
680: SMenuBar menuBar = new SMenuBar();
681: menuBar.add(fileMenu);
682: menuBar.add(desktopMenu);
683: menuBar.add(windowMenu);
684:
685: return menuBar;
686: }
687:
688: /**
689: * Servletinfo
690: */
691: public String getServletInfo() {
692: return "Desktop ($Revision: 3824 $)";
693: }
694:
695: private void flushPreferences() {
696: try {
697: prefRoot.flush();
698: } catch (Exception ex) {
699: ex.printStackTrace();
700: }
701: }
702:
703: /**
704: * A menu item, that handles the position of an internal frame within
705: * the desktop - whenever it is clicked, the frame is put on top. This
706: * MenuItem is added in some component listener, that gets activated
707: * whenever a window is added or removed from the desktop.
708: */
709: private static class WindowMenuItem extends SMenuItem {
710:
711: @Override
712: public void setText(String t) {
713:
714: SMenu menu = (SMenu) this .getParentMenu();
715: if (menu != null) {
716: SMenu bar = (SMenu) menu.getParentMenu();
717: bar.remove(menu);
718: menu.remove(this );
719: super .setText(t);
720: menu.add(this );
721: bar.add(menu);
722: } else
723: super .setText(t);
724:
725: }
726:
727: private final SInternalFrame frame;
728:
729: public WindowMenuItem(SInternalFrame f) {
730: frame = f;
731: this .setText(f.getTitle());
732: this .setIcon(f.getIcon());
733: }
734:
735: public WindowMenuItem(final SDesktopPane d,
736: final SInternalFrame f) {
737: frame = f;
738: this .setText(f.getTitle());
739: this .setIcon(f.getIcon());
740: /*
741: * when clicked, put that frame on top. If some other frame was
742: * maximized at that point, then maximize _our_ frame instead.
743: */
744: addActionListener(new ActionListener() {
745: public void actionPerformed(ActionEvent evt) {
746: d.setPosition(f, 0);
747: if (f.isIconified()) {
748: f.setIconified(false);
749: }
750: /*
751: * if some other frame is maximized, then we want
752: * to toggle this maximization..
753: */
754: try {
755: d.invite(new ComponentVisitor() {
756: public void visit(SComponent c) { /*ign*/
757: }
758:
759: public void visit(SContainer c) {
760: if (!(c instanceof SInternalFrame))
761: return;
762: SInternalFrame ff = (SInternalFrame) c;
763: if (ff != frame && ff.isMaximized()) {
764: ff.setMaximized(false);
765: // set _our_ frame maximized, then.
766: frame.setMaximized(true);
767: }
768: }
769: });
770: } catch (Exception e) {
771: System.err.println(e);
772: }
773: }
774: });
775: }
776:
777: /**
778: * returns the title of the frame.
779: */
780: public String getText() {
781: String title = frame.getTitle();
782: return (title == null || title.length() == 0) ? "[noname]"
783: : title;
784: }
785:
786: /**
787: * remove menu item by frame ..
788: */
789: public boolean equals(Object o) {
790: if (o instanceof WindowMenuItem) {
791: WindowMenuItem wme = (WindowMenuItem) o;
792: return (frame != null && wme.frame == frame);
793: }
794: return false;
795: }
796:
797: public void updateItem(WindowMenuItem updatedItem) {
798:
799: }
800: }
801:
802: private class DesktopFrameListener implements SContainerListener {
803:
804: private DesktopPane pane;
805:
806: public DesktopFrameListener(DesktopPane pane) {
807: this .pane = pane;
808: }
809:
810: public void componentAdded(SContainerEvent e) {
811: SInternalFrame frame = (SInternalFrame) e.getChild();
812: SMenuItem windowItem = new WindowMenuItem(pane, frame);
813: windowMenu.add(windowItem);
814: }
815:
816: public void componentRemoved(SContainerEvent e) {
817: SInternalFrame frame = (SInternalFrame) e.getChild();
818: SMenuItem windowItem = new WindowMenuItem(frame);
819: windowMenu.remove(windowItem);
820: }
821: }
822:
823: }
|