1 35 36 39 package demo.swingset; 40 41 import swingwtx.swing.*; 42 import swingwtx.swing.event.*; 43 import swingwtx.swing.text.*; 44 import swingwtx.swing.border.*; 45 import swingwtx.swing.colorchooser.*; 46 import swingwtx.swing.filechooser.*; 47 import javax.accessibility.*; 48 49 import swingwt.awt.*; 50 import swingwt.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 InternalFrameDemo extends DemoModule { 64 int windowCount = 0; 65 JDesktopPane desktop = null; 66 67 ImageIcon icon1, icon2, icon3, icon4; 68 ImageIcon smIcon1, smIcon2, smIcon3, smIcon4; 69 70 public Integer FIRST_FRAME_LAYER = new Integer (1); 71 public Integer DEMO_FRAME_LAYER = new Integer (2); 72 public Integer PALETTE_LAYER = new Integer (3); 73 74 public int FRAME0_X = 15; 75 public int FRAME0_Y = 280; 76 77 public int FRAME0_WIDTH = 320; 78 public int FRAME0_HEIGHT = 230; 79 80 public int FRAME_WIDTH = 225; 81 public int FRAME_HEIGHT = 150; 82 83 public int PALETTE_X = 375; 84 public int PALETTE_Y = 20; 85 86 public int PALETTE_WIDTH = 260; 87 public int PALETTE_HEIGHT = 230; 88 89 JCheckBox windowResizable = null; 90 JCheckBox windowClosable = null; 91 JCheckBox windowIconifiable = null; 92 JCheckBox windowMaximizable = null; 93 94 JTextField windowTitleField = null; 95 JLabel windowTitleLabel = null; 96 97 98 101 public static void main(String [] args) { 102 InternalFrameDemo demo = new InternalFrameDemo(null); 103 demo.mainImpl(); 104 } 105 106 109 public InternalFrameDemo(SwingSet2 swingset) { 110 super(swingset, "InternalFrameDemo", "toolbar/JDesktop.gif"); 111 112 icon1 = createImageIcon("ImageClub/misc/fish.gif", getString("InternalFrameDemo.fish")); 114 icon2 = createImageIcon("ImageClub/misc/moon.gif", getString("InternalFrameDemo.moon")); 115 icon3 = createImageIcon("ImageClub/misc/sun.gif", getString("InternalFrameDemo.sun")); 116 icon4 = createImageIcon("ImageClub/misc/cab.gif", getString("InternalFrameDemo.cab")); 117 118 smIcon1 = createImageIcon("ImageClub/misc/fish_small.gif", getString("InternalFrameDemo.fish")); 119 smIcon2 = createImageIcon("ImageClub/misc/moon_small.gif", getString("InternalFrameDemo.moon")); 120 smIcon3 = createImageIcon("ImageClub/misc/sun_small.gif", getString("InternalFrameDemo.sun")); 121 smIcon4 = createImageIcon("ImageClub/misc/cab_small.gif", getString("InternalFrameDemo.cab")); 122 123 desktop = new JDesktopPane(); 125 getDemoPanel().add(desktop, BorderLayout.CENTER); 126 127 final JInternalFrame p = createInternalFramePalette(); 129 130 JInternalFrame frame1 = createInternalFrame(icon1, FIRST_FRAME_LAYER, 1, 1); 132 frame1.setBounds(FRAME0_X, FRAME0_Y, FRAME0_WIDTH, FRAME0_HEIGHT); 133 134 createInternalFrame(icon1, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT); 136 createInternalFrame(icon3, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT); 137 createInternalFrame(icon4, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT); 138 createInternalFrame(icon2, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT); 139 140 try { 141 p.setSelected(true); 142 } 143 catch (Exception e) {} 144 145 } 146 147 148 149 152 public JInternalFrame createInternalFrame(ImageIcon icon, Integer layer, int width, int height) { 153 JInternalFrame jif = new JInternalFrame(); 154 155 if(!windowTitleField.getText().equals(getString("InternalFrameDemo.frame_label"))) { 156 jif.setTitle(windowTitleField.getText() + " "); 157 } else { 158 jif = new JInternalFrame(getString("InternalFrameDemo.frame_label") + " " + windowCount + " "); 159 } 160 161 jif.setClosable(windowClosable.isSelected()); 163 jif.setMaximizable(windowMaximizable.isSelected()); 164 jif.setIconifiable(windowIconifiable.isSelected()); 165 jif.setResizable(windowResizable.isSelected()); 166 167 jif.setBounds(20*(windowCount%10), 20*(windowCount%10), width, height); 168 jif.setLayout(new BorderLayout()); 169 jif.getContentPane().add(new ImageScroller(this, icon, 0, windowCount), BorderLayout.CENTER); 170 171 windowCount++; 172 173 desktop.add(jif, layer); 174 175 try { 177 jif.setSelected(true); 178 } 179 catch (PropertyVetoException e) {} 180 181 jif.show(); 182 183 return jif; 184 } 185 186 public JInternalFrame createInternalFramePalette() { 187 JInternalFrame palette = new JInternalFrame( 188 getString("InternalFrameDemo.palette_label") 189 ); 190 palette.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE); 191 palette.getContentPane().setLayout(new BorderLayout()); 192 palette.setBounds(PALETTE_X, PALETTE_Y, PALETTE_WIDTH, PALETTE_HEIGHT); 193 palette.setResizable(true); 194 palette.setIconifiable(true); 195 desktop.add(palette, PALETTE_LAYER); 196 197 JButton b1 = new JButton(smIcon1); 201 JButton b2 = new JButton(smIcon2); 202 JButton b3 = new JButton(smIcon3); 203 JButton b4 = new JButton(smIcon4); 204 205 b1.addActionListener(new ShowFrameAction(this, icon1)); 207 b2.addActionListener(new ShowFrameAction(this, icon2)); 208 b3.addActionListener(new ShowFrameAction(this, icon3)); 209 b4.addActionListener(new ShowFrameAction(this, icon4)); 210 211 JPanel p = new JPanel(); 213 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); 214 215 JPanel buttons1 = new JPanel(); 216 buttons1.setLayout(new BoxLayout(buttons1, BoxLayout.X_AXIS)); 217 218 JPanel buttons2 = new JPanel(); 219 buttons2.setLayout(new BoxLayout(buttons2, BoxLayout.X_AXIS)); 220 221 buttons1.add(b1); 222 buttons1.add(Box.createRigidArea(HGAP15)); 223 buttons1.add(b2); 224 225 buttons2.add(b3); 226 buttons2.add(Box.createRigidArea(HGAP15)); 227 buttons2.add(b4); 228 229 p.add(Box.createRigidArea(VGAP10)); 230 p.add(buttons1); 231 p.add(Box.createRigidArea(VGAP15)); 232 p.add(buttons2); 233 p.add(Box.createRigidArea(VGAP10)); 234 235 palette.getContentPane().add(p, BorderLayout.NORTH); 236 237 p = new JPanel() { 241 Insets insets = new Insets(10,15,10,5); 242 public Insets getInsets() { 243 return insets; 244 } 245 }; 246 p.setLayout(new GridLayout(1,2)); 247 248 249 Box box = new Box(BoxLayout.Y_AXIS); 250 windowResizable = new JCheckBox(getString("InternalFrameDemo.resizable_label"), true); 251 windowIconifiable = new JCheckBox(getString("InternalFrameDemo.iconifiable_label"), true); 252 253 p.add(box); 256 257 box = new Box(BoxLayout.Y_AXIS); 258 windowClosable = new JCheckBox(getString("InternalFrameDemo.closable_label"), true); 259 windowMaximizable = new JCheckBox(getString("InternalFrameDemo.maximizable_label"), true); 260 261 p.add(box); 264 265 palette.getContentPane().add(p, BorderLayout.CENTER); 266 267 268 p = new JPanel() { 272 Insets insets = new Insets(0,0,10,0); 273 public Insets getInsets() { 274 return insets; 275 } 276 }; 277 278 windowTitleField = new JTextField(getString("InternalFrameDemo.frame_label")); 279 windowTitleField.setPreferredSize(new Dimension(200, 25)); 280 windowTitleLabel = new JLabel(getString("InternalFrameDemo.title_text_field_label")); 281 282 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); 283 p.add(Box.createRigidArea(HGAP5)); 284 p.add(windowTitleLabel, BorderLayout.WEST); 285 p.add(Box.createRigidArea(HGAP5)); 286 p.add(windowTitleField, BorderLayout.CENTER); 287 p.add(Box.createRigidArea(HGAP5)); 288 289 palette.getContentPane().add(p, BorderLayout.SOUTH); 290 291 palette.show(); 292 293 return palette; 294 } 295 296 297 class ShowFrameAction extends AbstractAction { 298 InternalFrameDemo demo; 299 ImageIcon icon; 300 301 302 public ShowFrameAction(InternalFrameDemo demo, ImageIcon icon) { 303 this.demo = demo; 304 this.icon = icon; 305 } 306 307 public void actionPerformed(ActionEvent e) { 308 demo.createInternalFrame(icon, 309 getDemoFrameLayer(), 310 getFrameWidth(), 311 getFrameHeight() 312 ); 313 } 314 } 315 316 public int getFrameWidth() { 317 return FRAME_WIDTH; 318 } 319 320 public int getFrameHeight() { 321 return FRAME_HEIGHT; 322 } 323 324 public Integer getDemoFrameLayer() { 325 return DEMO_FRAME_LAYER; 326 } 327 328 class ImageScroller extends JScrollPane { 329 330 public ImageScroller(InternalFrameDemo demo, ImageIcon icon, int layer, int count) { 331 super(); 332 JPanel p = new JPanel(); 333 p.setBackground(Color.white); 334 p.setLayout(new BorderLayout() ); 335 336 p.add(new JLabel(icon), BorderLayout.CENTER); 337 setLayout(new BorderLayout()); 338 add(p); 339 } 340 341 public Dimension getMinimumSize() { 342 return new Dimension(25, 25); 343 } 344 345 } 346 347 348 } 349 | Popular Tags |