2
|
1 |
/*
|
|
2 |
* Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
*
|
|
4 |
* Redistribution and use in source and binary forms, with or without
|
|
5 |
* modification, are permitted provided that the following conditions
|
|
6 |
* are met:
|
|
7 |
*
|
|
8 |
* - Redistributions of source code must retain the above copyright
|
|
9 |
* notice, this list of conditions and the following disclaimer.
|
|
10 |
*
|
|
11 |
* - Redistributions in binary form must reproduce the above copyright
|
|
12 |
* notice, this list of conditions and the following disclaimer in the
|
|
13 |
* documentation and/or other materials provided with the distribution.
|
|
14 |
*
|
|
15 |
* - Neither the name of Sun Microsystems nor the names of its
|
|
16 |
* contributors may be used to endorse or promote products derived
|
|
17 |
* from this software without specific prior written permission.
|
|
18 |
*
|
|
19 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
20 |
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
21 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
22 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
23 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
24 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
25 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
26 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
27 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
28 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
29 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
30 |
*/
|
|
31 |
|
|
32 |
/*
|
|
33 |
*/
|
|
34 |
|
|
35 |
import java.awt.*;
|
|
36 |
import java.io.*;
|
|
37 |
import java.awt.event.*;
|
|
38 |
import java.beans.*;
|
|
39 |
import javax.swing.*;
|
|
40 |
import javax.swing.border.*;
|
|
41 |
|
|
42 |
import javax.swing.plaf.metal.*;
|
|
43 |
|
|
44 |
|
|
45 |
/**
|
|
46 |
* This is the main container frame for the Metalworks demo app
|
|
47 |
*
|
|
48 |
* @author Steve Wilson
|
|
49 |
*/
|
|
50 |
public class MetalworksFrame extends JFrame {
|
|
51 |
|
|
52 |
JMenuBar menuBar;
|
|
53 |
JDesktopPane desktop;
|
|
54 |
JInternalFrame toolPalette;
|
|
55 |
JCheckBoxMenuItem showToolPaletteMenuItem;
|
|
56 |
|
|
57 |
static final Integer DOCLAYER = new Integer(5);
|
|
58 |
static final Integer TOOLLAYER = new Integer(6);
|
|
59 |
static final Integer HELPLAYER = new Integer(7);
|
|
60 |
|
|
61 |
static final String ABOUTMSG = "Metalworks \n \nAn application written to show off the Java Look & Feel. \n \nWritten by the JavaSoft Look & Feel Team \n Michael Albers\n Tom Santos\n Jeff Shapiro\n Steve Wilson";
|
|
62 |
|
|
63 |
|
|
64 |
public MetalworksFrame() {
|
|
65 |
super("Metalworks");
|
|
66 |
final int inset = 50;
|
|
67 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
|
68 |
setBounds ( inset, inset, screenSize.width - inset*2, screenSize.height - inset*2 );
|
|
69 |
buildContent();
|
|
70 |
buildMenus();
|
|
71 |
this.addWindowListener(new WindowAdapter() {
|
|
72 |
public void windowClosing(WindowEvent e) {
|
|
73 |
quit();
|
|
74 |
}});
|
|
75 |
UIManager.addPropertyChangeListener(new UISwitchListener((JComponent)getRootPane()));
|
|
76 |
}
|
|
77 |
|
|
78 |
protected void buildMenus() {
|
|
79 |
menuBar = new JMenuBar();
|
|
80 |
menuBar.setOpaque(true);
|
|
81 |
JMenu file = buildFileMenu();
|
|
82 |
JMenu edit = buildEditMenu();
|
|
83 |
JMenu views = buildViewsMenu();
|
|
84 |
JMenu speed = buildSpeedMenu();
|
|
85 |
JMenu help = buildHelpMenu();
|
|
86 |
|
|
87 |
// load a theme from a text file
|
|
88 |
MetalTheme myTheme = null;
|
|
89 |
try {
|
|
90 |
InputStream istream = getClass().getResourceAsStream("/resources/MyTheme.theme");
|
|
91 |
myTheme = new PropertiesMetalTheme(istream);
|
|
92 |
} catch (NullPointerException e) {System.out.println(e);}
|
|
93 |
|
|
94 |
// build an array of themes
|
|
95 |
MetalTheme[] themes = { new OceanTheme(),
|
|
96 |
new DefaultMetalTheme(),
|
|
97 |
new GreenMetalTheme(),
|
|
98 |
new AquaMetalTheme(),
|
|
99 |
new KhakiMetalTheme(),
|
|
100 |
new DemoMetalTheme(),
|
|
101 |
new ContrastMetalTheme(),
|
|
102 |
new BigContrastMetalTheme(),
|
|
103 |
myTheme };
|
|
104 |
|
|
105 |
// put the themes in a menu
|
|
106 |
JMenu themeMenu = new MetalThemeMenu("Theme", themes);
|
|
107 |
|
|
108 |
menuBar.add(file);
|
|
109 |
menuBar.add(edit);
|
|
110 |
menuBar.add(views);
|
|
111 |
menuBar.add(themeMenu);
|
|
112 |
menuBar.add(speed);
|
|
113 |
menuBar.add(help);
|
|
114 |
setJMenuBar(menuBar);
|
|
115 |
}
|
|
116 |
|
|
117 |
protected JMenu buildFileMenu() {
|
|
118 |
JMenu file = new JMenu("File");
|
|
119 |
JMenuItem newWin = new JMenuItem("New");
|
|
120 |
JMenuItem open = new JMenuItem("Open");
|
|
121 |
JMenuItem quit = new JMenuItem("Quit");
|
|
122 |
|
|
123 |
newWin.addActionListener(new ActionListener() {
|
|
124 |
public void actionPerformed(ActionEvent e) {
|
|
125 |
newDocument();
|
|
126 |
}});
|
|
127 |
|
|
128 |
open.addActionListener(new ActionListener() {
|
|
129 |
public void actionPerformed(ActionEvent e) {
|
|
130 |
openDocument();
|
|
131 |
}});
|
|
132 |
|
|
133 |
quit.addActionListener(new ActionListener() {
|
|
134 |
public void actionPerformed(ActionEvent e) {
|
|
135 |
quit();
|
|
136 |
}});
|
|
137 |
|
|
138 |
file.add(newWin);
|
|
139 |
file.add(open);
|
|
140 |
file.addSeparator();
|
|
141 |
file.add(quit);
|
|
142 |
return file;
|
|
143 |
}
|
|
144 |
|
|
145 |
protected JMenu buildEditMenu() {
|
|
146 |
JMenu edit = new JMenu("Edit");
|
|
147 |
JMenuItem undo = new JMenuItem("Undo");
|
|
148 |
JMenuItem copy = new JMenuItem("Copy");
|
|
149 |
JMenuItem cut = new JMenuItem("Cut");
|
|
150 |
JMenuItem paste = new JMenuItem("Paste");
|
|
151 |
JMenuItem prefs = new JMenuItem("Preferences...");
|
|
152 |
|
|
153 |
undo.setEnabled(false);
|
|
154 |
copy.setEnabled(false);
|
|
155 |
cut.setEnabled(false);
|
|
156 |
paste.setEnabled(false);
|
|
157 |
|
|
158 |
prefs.addActionListener(new ActionListener() {
|
|
159 |
public void actionPerformed(ActionEvent e) {
|
|
160 |
openPrefsWindow();
|
|
161 |
}});
|
|
162 |
|
|
163 |
edit.add(undo);
|
|
164 |
edit.addSeparator();
|
|
165 |
edit.add(cut);
|
|
166 |
edit.add(copy);
|
|
167 |
edit.add(paste);
|
|
168 |
edit.addSeparator();
|
|
169 |
edit.add(prefs);
|
|
170 |
return edit;
|
|
171 |
}
|
|
172 |
|
|
173 |
protected JMenu buildViewsMenu() {
|
|
174 |
JMenu views = new JMenu("Views");
|
|
175 |
|
|
176 |
JMenuItem inBox = new JMenuItem("Open In-Box");
|
|
177 |
JMenuItem outBox = new JMenuItem("Open Out-Box");
|
|
178 |
outBox.setEnabled(false);
|
|
179 |
|
|
180 |
inBox.addActionListener(new ActionListener() {
|
|
181 |
public void actionPerformed(ActionEvent e) {
|
|
182 |
openInBox();
|
|
183 |
}});
|
|
184 |
|
|
185 |
views.add(inBox);
|
|
186 |
views.add(outBox);
|
|
187 |
return views;
|
|
188 |
}
|
|
189 |
|
|
190 |
protected JMenu buildSpeedMenu() {
|
|
191 |
JMenu speed = new JMenu("Drag");
|
|
192 |
|
|
193 |
JRadioButtonMenuItem live = new JRadioButtonMenuItem("Live");
|
|
194 |
JRadioButtonMenuItem outline = new JRadioButtonMenuItem("Outline");
|
|
195 |
|
|
196 |
JRadioButtonMenuItem slow = new JRadioButtonMenuItem("Old and Slow");
|
|
197 |
|
|
198 |
ButtonGroup group = new ButtonGroup();
|
|
199 |
|
|
200 |
group.add(live);
|
|
201 |
group.add(outline);
|
|
202 |
group.add(slow);
|
|
203 |
|
|
204 |
live.setSelected(true);
|
|
205 |
|
|
206 |
slow.addActionListener(new ActionListener(){
|
|
207 |
public void actionPerformed(ActionEvent e){
|
|
208 |
// for right now I'm saying if you set the mode
|
|
209 |
// to something other than a specified mode
|
|
210 |
// it will revert to the old way
|
|
211 |
// This is mostly for comparison's sake
|
|
212 |
desktop.setDragMode(-1);}});
|
|
213 |
|
|
214 |
live.addActionListener(new ActionListener(){
|
|
215 |
public void actionPerformed(ActionEvent e){
|
|
216 |
desktop.setDragMode(JDesktopPane.LIVE_DRAG_MODE);}});
|
|
217 |
|
|
218 |
outline.addActionListener(new ActionListener(){
|
|
219 |
public void actionPerformed(ActionEvent e){
|
|
220 |
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);}});
|
|
221 |
|
|
222 |
|
|
223 |
speed.add(live);
|
|
224 |
speed.add(outline);
|
|
225 |
speed.add(slow);
|
|
226 |
return speed;
|
|
227 |
}
|
|
228 |
|
|
229 |
protected JMenu buildHelpMenu() {
|
|
230 |
JMenu help = new JMenu("Help");
|
|
231 |
JMenuItem about = new JMenuItem("About Metalworks...");
|
|
232 |
JMenuItem openHelp = new JMenuItem("Open Help Window");
|
|
233 |
|
|
234 |
about.addActionListener(new ActionListener() {
|
|
235 |
public void actionPerformed(ActionEvent e) {
|
|
236 |
showAboutBox();
|
|
237 |
}
|
|
238 |
});
|
|
239 |
|
|
240 |
openHelp.addActionListener(new ActionListener() {
|
|
241 |
public void actionPerformed(ActionEvent e) {
|
|
242 |
openHelpWindow();
|
|
243 |
}});
|
|
244 |
|
|
245 |
help.add(about);
|
|
246 |
help.add(openHelp);
|
|
247 |
|
|
248 |
return help;
|
|
249 |
}
|
|
250 |
|
|
251 |
protected void buildContent() {
|
|
252 |
desktop = new JDesktopPane();
|
|
253 |
getContentPane().add(desktop);
|
|
254 |
}
|
|
255 |
|
|
256 |
public void quit() {
|
|
257 |
System.exit(0);
|
|
258 |
}
|
|
259 |
|
|
260 |
public void newDocument() {
|
|
261 |
JInternalFrame doc = new MetalworksDocumentFrame();
|
|
262 |
desktop.add(doc, DOCLAYER);
|
|
263 |
try {
|
|
264 |
doc.setVisible(true);
|
|
265 |
doc.setSelected(true);
|
|
266 |
} catch (java.beans.PropertyVetoException e2) {}
|
|
267 |
}
|
|
268 |
|
|
269 |
public void openDocument() {
|
|
270 |
JFileChooser chooser = new JFileChooser();
|
|
271 |
chooser.showOpenDialog(this);
|
|
272 |
}
|
|
273 |
|
|
274 |
public void openHelpWindow() {
|
|
275 |
JInternalFrame help = new MetalworksHelp();
|
|
276 |
desktop.add(help, HELPLAYER);
|
|
277 |
try {
|
|
278 |
help.setVisible(true);
|
|
279 |
help.setSelected(true);
|
|
280 |
} catch (java.beans.PropertyVetoException e2) {}
|
|
281 |
}
|
|
282 |
|
|
283 |
public void showAboutBox() {
|
|
284 |
JOptionPane.showMessageDialog(this, ABOUTMSG);
|
|
285 |
}
|
|
286 |
|
|
287 |
public void openPrefsWindow() {
|
|
288 |
MetalworksPrefs dialog = new MetalworksPrefs(this);
|
|
289 |
dialog.show();
|
|
290 |
|
|
291 |
}
|
|
292 |
|
|
293 |
public void openInBox() {
|
|
294 |
JInternalFrame doc = new MetalworksInBox();
|
|
295 |
desktop.add(doc, DOCLAYER);
|
|
296 |
try {
|
|
297 |
doc.setVisible(true);
|
|
298 |
doc.setSelected(true);
|
|
299 |
} catch (java.beans.PropertyVetoException e2) {}
|
|
300 |
}
|
|
301 |
}
|