KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > util > gui > propedit > DesktopPropertyEditorFactory


1 package net.suberic.util.gui.propedit;
2 import javax.swing.*;
3 import net.suberic.util.*;
4 import net.suberic.util.gui.IconManager;
5 import java.util.*;
6 import java.awt.Container JavaDoc;
7 import java.awt.Component JavaDoc;
8 import javax.help.HelpBroker;
9
10 /**
11  * A factory which can be used to create PropertyEditorUI's.
12  */

13 public class DesktopPropertyEditorFactory extends PropertyEditorFactory {
14   JDesktopPane desktop;
15
16   /**
17    * Creates a PropertyEditorFactory using the given VariableBundle as
18    * a source.
19    */

20   public DesktopPropertyEditorFactory(VariableBundle bundle, JDesktopPane newDesktop, IconManager manager, HelpBroker broker) {
21     super(bundle, manager, broker);
22     desktop = newDesktop;
23   }
24
25   /**
26    * Creates a PropertyEditorFactory using the given VariableBundle as
27    * a source.
28    */

29   public DesktopPropertyEditorFactory(VariableBundle bundle, IconManager manager, HelpBroker broker) {
30     this(bundle, null, manager, broker);
31   }
32
33   /**
34    * Returns the desktop.
35    */

36   public JDesktopPane getDesktop() {
37     return desktop;
38   }
39
40   /**
41    * Sets the desktop.
42    */

43   public void setDesktop(JDesktopPane newDesktop) {
44     desktop = newDesktop;
45   }
46
47   /**
48    * Shows an error message.
49    */

50   public void showError(Object JavaDoc component, String JavaDoc errorMessage) {
51     JOptionPane.showInternalMessageDialog(desktop, errorMessage);
52   }
53
54   /**
55    * Shows an input dialog.
56    */

57   public String JavaDoc showInputDialog(SwingPropertyEditor dpe, String JavaDoc query) {
58     return JOptionPane.showInternalInputDialog(desktop, query);
59   }
60
61   /**
62    * Creates and displays an editor window.
63    */

64   public void showNewEditorWindow(String JavaDoc title, PropertyEditorUI editor, Container JavaDoc window) {
65     JInternalFrame jif = (JInternalFrame) createEditorWindow(title, editor, window);
66
67     //jif.pack();
68
jif.setSize(jif.getPreferredSize());
69     if (window != null && window instanceof JInternalFrame) {
70       jif.setLocation(Math.max(0, ((window.getWidth() - jif.getWidth()) / 2) + window.getX()), Math.max(0, ((window.getHeight() - jif.getHeight()) / 2) + window.getY()));
71     }
72     desktop.add(jif);
73     jif.setVisible(true);
74     try {
75       jif.setSelected(true);
76     } catch (java.beans.PropertyVetoException JavaDoc pve) {
77     }
78   }
79
80   public void showNewEditorWindow(String JavaDoc title, String JavaDoc property, String JavaDoc template, String JavaDoc propertyBase, PropertyEditorManager mgr, Container JavaDoc window) {
81     JInternalFrame jif = (JInternalFrame) createEditorWindow(title, property, template, propertyBase, mgr, window);
82     //jif.pack();
83
jif.setSize(jif.getPreferredSize());
84     if (window != null && window instanceof JInternalFrame) {
85       jif.setLocation(Math.max(0, ((window.getWidth() - jif.getWidth()) / 2) + window.getX()), Math.max(0, ((window.getHeight() - jif.getHeight()) / 2) + window.getY()));
86     }
87     desktop.add(jif);
88     jif.setVisible(true);
89     try {
90       jif.setSelected(true);
91     } catch (java.beans.PropertyVetoException JavaDoc pve) {
92     }
93   }
94
95   /**
96    * This method returns an EditorWindow (a JFrame in this
97    * implementation) which has an editor for each property in the
98    * properties Vector. The title string is the title of the
99    * JInternalFrame.
100    */

101   public Container JavaDoc createEditorWindow(String JavaDoc title, PropertyEditorUI editor, Container JavaDoc window) {
102     JInternalFrame jif = new JInternalFrame(title, true, true);
103     PropertyEditorPane pep = createPropertyEditorPane(editor.getManager(), (SwingPropertyEditor) editor, jif);
104     jif.getContentPane().add(pep);
105     jif.pack();
106     jif.setSize(jif.getPreferredSize());
107     return jif;
108   }
109
110 }
111
Popular Tags