1
36
37
40
41 import javax.swing.*;
42 import javax.swing.event.*;
43 import javax.swing.text.*;
44 import javax.swing.border.*;
45 import javax.swing.colorchooser.*;
46 import javax.swing.filechooser.*;
47 import javax.accessibility.*;
48
49 import java.awt.*;
50 import java.awt.event.*;
51 import java.beans.*;
52 import java.util.*;
53 import java.io.*;
54 import java.applet.*;
55 import java.net.*;
56
57
63 public class DemoModule extends JApplet {
64
65 private int PREFERRED_WIDTH = 680;
67 private int PREFERRED_HEIGHT = 600;
68
69 Border loweredBorder = new CompoundBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED),
70 new EmptyBorder(5,5,5,5));
71
72 public static Dimension HGAP2 = new Dimension(2,1);
74 public static Dimension VGAP2 = new Dimension(1,2);
75
76 public static Dimension HGAP5 = new Dimension(5,1);
77 public static Dimension VGAP5 = new Dimension(1,5);
78
79 public static Dimension HGAP10 = new Dimension(10,1);
80 public static Dimension VGAP10 = new Dimension(1,10);
81
82 public static Dimension HGAP15 = new Dimension(15,1);
83 public static Dimension VGAP15 = new Dimension(1,15);
84
85 public static Dimension HGAP20 = new Dimension(20,1);
86 public static Dimension VGAP20 = new Dimension(1,20);
87
88 public static Dimension HGAP25 = new Dimension(25,1);
89 public static Dimension VGAP25 = new Dimension(1,25);
90
91 public static Dimension HGAP30 = new Dimension(30,1);
92 public static Dimension VGAP30 = new Dimension(1,30);
93
94 private SwingSet2 swingset = null;
95 private JPanel panel = null;
96 private String resourceName = null;
97 private String iconPath = null;
98 private String sourceCode = null;
99
100 private ResourceBundle bundle = null;
102
103 public DemoModule(SwingSet2 swingset) {
104 this(swingset, null, null);
105 }
106
107 public DemoModule(SwingSet2 swingset, String resourceName, String iconPath) {
108 UIManager.put("swing.boldMetal", Boolean.FALSE);
109 panel = new JPanel();
110 panel.setLayout(new BorderLayout());
111
112 this.resourceName = resourceName;
113 this.iconPath = iconPath;
114 this.swingset = swingset;
115
116 loadSourceCode();
117 }
118
119 public String getResourceName() {
120 return resourceName;
121 }
122
123 public JPanel getDemoPanel() {
124 return panel;
125 }
126
127 public SwingSet2 getSwingSet2() {
128 return swingset;
129 }
130
131
132 public String getString(String key) {
133 String value = "nada";
134 if(bundle == null) {
135 if(getSwingSet2() != null) {
136 bundle = getSwingSet2().getResourceBundle();
137 } else {
138 bundle = ResourceBundle.getBundle("resources.swingset");
139 }
140 }
141 try {
142 value = bundle.getString(key);
143 } catch (MissingResourceException e) {
144 System.out.println("java.util.MissingResourceException: Couldn't find value for: " + key);
145 }
146 return value;
147 }
148
149 public char getMnemonic(String key) {
150 return (getString(key)).charAt(0);
151 }
152
153 public ImageIcon createImageIcon(String filename, String description) {
154 if(getSwingSet2() != null) {
155 return getSwingSet2().createImageIcon(filename, description);
156 } else {
157 String path = "/resources/images/" + filename;
158 return new ImageIcon(getClass().getResource(path), description);
159 }
160 }
161
162
163 public String getSourceCode() {
164 return sourceCode;
165 }
166
167 public void loadSourceCode() {
168 if(getResourceName() != null) {
169 String filename = getResourceName() + ".java";
170 sourceCode = new String("<html><body bgcolor=\"#ffffff\"><pre>");
171 InputStream is;
172 InputStreamReader isr;
173 CodeViewer cv = new CodeViewer();
174 URL url;
175
176 try {
177 url = getClass().getResource(filename);
178 is = url.openStream();
179 isr = new InputStreamReader(is);
180 BufferedReader reader = new BufferedReader(isr);
181
182 String line = reader.readLine();
185 while(line != null) {
186 sourceCode += cv.syntaxHighlight(line) + " \n ";
187 line = reader.readLine();
188 }
189 sourceCode += new String("</pre></body></html>");
190 } catch (Exception ex) {
191 sourceCode = "Could not load file: " + filename;
192 }
193 }
194 }
195
196 public String getName() {
197 return getString(getResourceName() + ".name");
198 };
199
200 public Icon getIcon() {
201 return createImageIcon(iconPath, getResourceName() + ".name");
202 };
203
204 public String getToolTip() {
205 return getString(getResourceName() + ".tooltip");
206 };
207
208 public void mainImpl() {
209 JFrame frame = new JFrame(getName());
210 frame.getContentPane().setLayout(new BorderLayout());
211 frame.getContentPane().add(getDemoPanel(), BorderLayout.CENTER);
212 getDemoPanel().setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
213 frame.pack();
214 frame.show();
215 }
216
217 public JPanel createHorizontalPanel(boolean threeD) {
218 JPanel p = new JPanel();
219 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
220 p.setAlignmentY(TOP_ALIGNMENT);
221 p.setAlignmentX(LEFT_ALIGNMENT);
222 if(threeD) {
223 p.setBorder(loweredBorder);
224 }
225 return p;
226 }
227
228 public JPanel createVerticalPanel(boolean threeD) {
229 JPanel p = new JPanel();
230 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
231 p.setAlignmentY(TOP_ALIGNMENT);
232 p.setAlignmentX(LEFT_ALIGNMENT);
233 if(threeD) {
234 p.setBorder(loweredBorder);
235 }
236 return p;
237 }
238
239 public static void main(String[] args) {
240 DemoModule demo = new DemoModule(null);
241 demo.mainImpl();
242 }
243
244 public void init() {
245 getContentPane().setLayout(new BorderLayout());
246 getContentPane().add(getDemoPanel(), BorderLayout.CENTER);
247 }
248
249 void updateDragEnabled(boolean dragEnabled) {}
250 }
251
252