1 36 37 40 41 import java.awt.*; 42 import java.io.*; 43 import java.awt.event.*; 44 import java.beans.*; 45 import javax.swing.*; 46 import javax.swing.border.*; 47 48 import javax.swing.plaf.metal.*; 49 50 51 57 public class MetalworksFrame extends JFrame { 58 59 JMenuBar menuBar; 60 JDesktopPane desktop; 61 JInternalFrame toolPalette; 62 JCheckBoxMenuItem showToolPaletteMenuItem; 63 64 static final Integer DOCLAYER = new Integer (5); 65 static final Integer TOOLLAYER = new Integer (6); 66 static final Integer HELPLAYER = new Integer (7); 67 68 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"; 69 70 71 public MetalworksFrame() { 72 super("Metalworks"); 73 final int inset = 50; 74 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 75 setBounds ( inset, inset, screenSize.width - inset*2, screenSize.height - inset*2 ); 76 buildContent(); 77 buildMenus(); 78 this.addWindowListener(new WindowAdapter() { 79 public void windowClosing(WindowEvent e) { 80 quit(); 81 }}); 82 UIManager.addPropertyChangeListener(new UISwitchListener((JComponent)getRootPane())); 83 } 84 85 protected void buildMenus() { 86 menuBar = new JMenuBar(); 87 menuBar.setOpaque(true); 88 JMenu file = buildFileMenu(); 89 JMenu edit = buildEditMenu(); 90 JMenu views = buildViewsMenu(); 91 JMenu speed = buildSpeedMenu(); 92 JMenu help = buildHelpMenu(); 93 94 MetalTheme myTheme = null; 96 try { 97 InputStream istream = getClass().getResourceAsStream("/resources/MyTheme.theme"); 98 myTheme = new PropertiesMetalTheme(istream); 99 } catch (NullPointerException e) {System.out.println(e);} 100 101 MetalTheme[] themes = { new OceanTheme(), 103 new DefaultMetalTheme(), 104 new GreenMetalTheme(), 105 new AquaMetalTheme(), 106 new KhakiMetalTheme(), 107 new DemoMetalTheme(), 108 new ContrastMetalTheme(), 109 new BigContrastMetalTheme(), 110 myTheme }; 111 112 JMenu themeMenu = new MetalThemeMenu("Theme", themes); 114 115 menuBar.add(file); 116 menuBar.add(edit); 117 menuBar.add(views); 118 menuBar.add(themeMenu); 119 menuBar.add(speed); 120 menuBar.add(help); 121 setJMenuBar(menuBar); 122 } 123 124 protected JMenu buildFileMenu() { 125 JMenu file = new JMenu("File"); 126 JMenuItem newWin = new JMenuItem("New"); 127 JMenuItem open = new JMenuItem("Open"); 128 JMenuItem quit = new JMenuItem("Quit"); 129 130 newWin.addActionListener(new ActionListener() { 131 public void actionPerformed(ActionEvent e) { 132 newDocument(); 133 }}); 134 135 open.addActionListener(new ActionListener() { 136 public void actionPerformed(ActionEvent e) { 137 openDocument(); 138 }}); 139 140 quit.addActionListener(new ActionListener() { 141 public void actionPerformed(ActionEvent e) { 142 quit(); 143 }}); 144 145 file.add(newWin); 146 file.add(open); 147 file.addSeparator(); 148 file.add(quit); 149 return file; 150 } 151 152 protected JMenu buildEditMenu() { 153 JMenu edit = new JMenu("Edit"); 154 JMenuItem undo = new JMenuItem("Undo"); 155 JMenuItem copy = new JMenuItem("Copy"); 156 JMenuItem cut = new JMenuItem("Cut"); 157 JMenuItem paste = new JMenuItem("Paste"); 158 JMenuItem prefs = new JMenuItem("Preferences..."); 159 160 undo.setEnabled(false); 161 copy.setEnabled(false); 162 cut.setEnabled(false); 163 paste.setEnabled(false); 164 165 prefs.addActionListener(new ActionListener() { 166 public void actionPerformed(ActionEvent e) { 167 openPrefsWindow(); 168 }}); 169 170 edit.add(undo); 171 edit.addSeparator(); 172 edit.add(cut); 173 edit.add(copy); 174 edit.add(paste); 175 edit.addSeparator(); 176 edit.add(prefs); 177 return edit; 178 } 179 180 protected JMenu buildViewsMenu() { 181 JMenu views = new JMenu("Views"); 182 183 JMenuItem inBox = new JMenuItem("Open In-Box"); 184 JMenuItem outBox = new JMenuItem("Open Out-Box"); 185 outBox.setEnabled(false); 186 187 inBox.addActionListener(new ActionListener() { 188 public void actionPerformed(ActionEvent e) { 189 openInBox(); 190 }}); 191 192 views.add(inBox); 193 views.add(outBox); 194 return views; 195 } 196 197 protected JMenu buildSpeedMenu() { 198 JMenu speed = new JMenu("Drag"); 199 200 JRadioButtonMenuItem live = new JRadioButtonMenuItem("Live"); 201 JRadioButtonMenuItem outline = new JRadioButtonMenuItem("Outline"); 202 203 JRadioButtonMenuItem slow = new JRadioButtonMenuItem("Old and Slow"); 204 205 ButtonGroup group = new ButtonGroup(); 206 207 group.add(live); 208 group.add(outline); 209 group.add(slow); 210 211 live.setSelected(true); 212 213 slow.addActionListener(new ActionListener(){ 214 public void actionPerformed(ActionEvent e){ 215 desktop.setDragMode(-1);}}); 220 221 live.addActionListener(new ActionListener(){ 222 public void actionPerformed(ActionEvent e){ 223 desktop.setDragMode(JDesktopPane.LIVE_DRAG_MODE);}}); 224 225 outline.addActionListener(new ActionListener(){ 226 public void actionPerformed(ActionEvent e){ 227 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);}}); 228 229 230 speed.add(live); 231 speed.add(outline); 232 speed.add(slow); 233 return speed; 234 } 235 236 protected JMenu buildHelpMenu() { 237 JMenu help = new JMenu("Help"); 238 JMenuItem about = new JMenuItem("About Metalworks..."); 239 JMenuItem openHelp = new JMenuItem("Open Help Window"); 240 241 about.addActionListener(new ActionListener() { 242 public void actionPerformed(ActionEvent e) { 243 showAboutBox(); 244 } 245 }); 246 247 openHelp.addActionListener(new ActionListener() { 248 public void actionPerformed(ActionEvent e) { 249 openHelpWindow(); 250 }}); 251 252 help.add(about); 253 help.add(openHelp); 254 255 return help; 256 } 257 258 protected void buildContent() { 259 desktop = new JDesktopPane(); 260 getContentPane().add(desktop); 261 } 262 263 public void quit() { 264 System.exit(0); 265 } 266 267 public void newDocument() { 268 JInternalFrame doc = new MetalworksDocumentFrame(); 269 desktop.add(doc, DOCLAYER); 270 try { 271 doc.setVisible(true); 272 doc.setSelected(true); 273 } catch (java.beans.PropertyVetoException e2) {} 274 } 275 276 public void openDocument() { 277 JFileChooser chooser = new JFileChooser(); 278 chooser.showOpenDialog(this); 279 } 280 281 public void openHelpWindow() { 282 JInternalFrame help = new MetalworksHelp(); 283 desktop.add(help, HELPLAYER); 284 try { 285 help.setVisible(true); 286 help.setSelected(true); 287 } catch (java.beans.PropertyVetoException e2) {} 288 } 289 290 public void showAboutBox() { 291 JOptionPane.showMessageDialog(this, ABOUTMSG); 292 } 293 294 public void openPrefsWindow() { 295 MetalworksPrefs dialog = new MetalworksPrefs(this); 296 dialog.show(); 297 298 } 299 300 public void openInBox() { 301 JInternalFrame doc = new MetalworksInBox(); 302 desktop.add(doc, DOCLAYER); 303 try { 304 doc.setVisible(true); 305 doc.setSelected(true); 306 } catch (java.beans.PropertyVetoException e2) {} 307 } 308 } 309 310 311
| Popular Tags
|