home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 July / CHIP-1999-07.iso / software / jdk / jdk121.exe / disk1 / data1.cab / demos / demo / jfc / SwingSet / InternalWindowPanel.java < prev    next >
Encoding:
Java Source  |  1999-03-27  |  6.2 KB  |  199 lines

  1. /*
  2.  * @(#)InternalWindowPanel.java    1.15 98/08/26
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. import javax.swing.*;
  16. import javax.swing.border.*;
  17. import javax.accessibility.*;
  18.  
  19. import java.awt.Panel;
  20. import java.awt.Color;
  21. import java.awt.BorderLayout;
  22. import java.awt.GridLayout;
  23. import java.awt.Font;
  24. import java.awt.event.ActionListener;
  25. import java.awt.event.ActionEvent;
  26. import java.awt.Dimension;
  27. import java.awt.Graphics;
  28. import java.awt.Color;
  29. import java.awt.Rectangle;
  30. import java.awt.Container;
  31.  
  32. /*
  33.  * 1.15 98/08/26
  34.  * @author Dave Kloba
  35.  * @author Peter Korn (accessibility support)
  36.  */
  37. public class InternalWindowPanel extends JPanel implements ActionListener     {
  38.     // Maker values
  39.     JCheckBox closeBox;
  40.     JCheckBox maxBox;
  41.     JCheckBox iconBox;
  42.     JCheckBox resizeBox;
  43.     JTextField titleField;
  44.     JTextField layerField;
  45.     JButton closeAllButton;
  46.     JButton makeButton;
  47.     JLayeredPane lc;
  48.     int makeCount = 0;
  49.     JInternalFrame maker;
  50.  
  51.     public InternalWindowPanel()    {
  52.         setLayout(new BorderLayout());
  53.         lc = new JDesktopPane();
  54.     lc.setOpaque(false);
  55.         maker = createMakerFrame();
  56.         lc.add(maker, JLayeredPane.PALETTE_LAYER);  
  57.         
  58.         add("Center", lc);
  59.     }
  60.  
  61.     public JInternalFrame createMakerFrame() {
  62.         JInternalFrame w;
  63.         JPanel tp;
  64.     Container contentPane;
  65.         
  66.         w = new JInternalFrame("Frame Creator");
  67.     contentPane = w.getContentPane();
  68.         contentPane.setLayout(new GridLayout(0, 1));
  69.  
  70.         tp = new JPanel();
  71.         tp.setLayout(new GridLayout(2, 2));
  72.         closeBox = new JCheckBox( "is Closable ");
  73.         closeBox.setSelected(true);
  74.         tp.add(closeBox);
  75.         maxBox = new JCheckBox(   "is Maxable  ");
  76.         maxBox.setSelected(true);
  77.         tp.add(maxBox);
  78.         iconBox = new JCheckBox(  "is Iconifiable ");
  79.         iconBox.setSelected(true);
  80.         tp.add(iconBox);
  81.         resizeBox = new JCheckBox("is Resizable");
  82.         resizeBox.setSelected(true);
  83.         tp.add(resizeBox);
  84.         contentPane.add(tp);
  85.         
  86.         tp = new JPanel();
  87.     tp.setBorder(BorderFactory.createTitledBorder("Title"));
  88.         tp.setLayout(new BorderLayout());
  89.         titleField = new JTextField();
  90.         titleField.setText("");
  91.         titleField.setMinimumSize(new Dimension(50, 25));
  92.     titleField.setEditable(true);
  93.     titleField.getAccessibleContext().setAccessibleName("Title for created frame");
  94.         tp.add(titleField, "Center");
  95.         contentPane.add(tp);              
  96.  
  97.         tp = new JPanel();
  98.     tp.setBorder(BorderFactory.createTitledBorder("Layer"));
  99.         tp.setLayout(new BorderLayout());
  100.         layerField = new JTextField();
  101.         layerField.setMinimumSize(new Dimension(50, 25));
  102.     layerField.setEditable(true);
  103.         layerField.setText("5");
  104.     layerField.getAccessibleContext().setAccessibleName("Layer for created frame");
  105.     layerField.getAccessibleContext().setAccessibleDescription("This must be an Integer value, which determines which layer in the stacking order to place the newly created Internal Frame");
  106.         tp.add(layerField, "Center");
  107.         contentPane.add(tp);              
  108.  
  109.         tp = new JPanel();
  110.         tp.setLayout(new GridLayout(1, 2));
  111.         closeAllButton = new JButton("Clear");
  112.         closeAllButton.addActionListener(this);
  113.         tp.add(closeAllButton);
  114.         makeButton = new JButton("Make");
  115.         makeButton.addActionListener(this);
  116.         tp.add(makeButton);     
  117.         contentPane.add(tp);
  118.         
  119.         w.setBounds(360, 10, 270, 250);
  120.         w.setResizable(true);
  121.         return w;
  122.     }
  123.  
  124.     public void actionPerformed(ActionEvent e) {
  125.         if(e.getSource() == closeAllButton) {
  126.             lc.removeAll();
  127.             lc.add(maker);
  128.             lc.repaint();
  129.             makeCount = 0;
  130.         } else if(e.getSource() == makeButton) {
  131.             JInternalFrame w;
  132.         int layer;
  133.             w = new JInternalFrame();
  134.             w.setClosable(closeBox.isSelected());
  135.             w.setMaximizable(maxBox.isSelected());
  136.             w.setIconifiable(iconBox.isSelected());
  137.         String title = titleField.getText();
  138.         if(title.equals("")) {
  139.                 w.setTitle("Internal Frame " + (makeCount+1));
  140.         } else {
  141.                 w.setTitle(title);
  142.         }
  143.             w.setResizable(resizeBox.isSelected());
  144.         try { 
  145.                 layer = Integer.parseInt(layerField.getText()); 
  146.         } catch (NumberFormatException e2) {
  147.             layer = 0;
  148.         }
  149.             makeCount++;
  150.             w.setBounds(20*(makeCount%10), 20*(makeCount%10), 225, 150);
  151.             w.setContentPane(new MyScrollPane(layer, makeCount));
  152.                 
  153.             lc.add(w, new Integer(layer));  
  154.             try { w.setSelected(true); } catch (java.beans.PropertyVetoException e2) {}
  155.         }
  156.     }
  157.  
  158. }
  159.  
  160. class MyScrollPane extends JScrollPane
  161. {
  162.     static ImageIcon[] icon = new ImageIcon[5];
  163.  
  164.     public MyScrollPane(int layer, int count)
  165.     {
  166.     super();
  167.         if(icon[0] == null) {
  168.            icon[0] = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/misc/horn.gif", "Horn");
  169.            icon[1] = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/misc/fish.gif", "Fish");
  170.            icon[2] = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/misc/moon.gif", "Moon");
  171.            icon[3] = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/misc/sun.gif",  "Sun");
  172.            icon[4] = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/misc/cab.gif",  "Yellow Cab");
  173.         }
  174.     JPanel p = new JPanel();
  175.            p.setOpaque(false);
  176.     p.setLayout(new BorderLayout() );
  177.     JLabel layerLabel = new JLabel("Layer "+layer);
  178.     layerLabel.setOpaque(false);
  179.         
  180.     int it = count%5;
  181.         p.add(new JLabel(icon[count%5]), BorderLayout.CENTER);
  182.     p.add(layerLabel, BorderLayout.NORTH);
  183.  
  184.     getViewport().add(p);
  185.  
  186.     }
  187.     
  188.     public Dimension getMinimumSize() {
  189.     return new Dimension(25, 25);
  190.     }
  191.     
  192.     public boolean isOpaque() {
  193.         return true;
  194.     }
  195. }
  196.  
  197.  
  198.  
  199.