home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Sample.bin / Metalworks.java < prev    next >
Text File  |  1998-09-30  |  16KB  |  503 lines

  1. /*
  2.         A basic implementation of the JFrame class.
  3. */
  4.  
  5. import java.awt.*;
  6. import java.awt.event.*;
  7. import java.beans.*;
  8. import com.sun.java.swing.*;
  9. import com.sun.java.swing.plaf.metal.*;
  10. import com.sun.java.swing.preview.*;
  11.  
  12. public class Metalworks extends com.sun.java.swing.JFrame
  13. {
  14.     static final Integer DOCLAYER = new Integer(5);
  15.     static final Integer HELPLAYER = new Integer(7);
  16.     static final String  ABOUTMSG = "Based on the oringal Metalworks example written by the Look&Feel team at Sun\nThis version shows how to create an equivilent using Visual Cafe\'s GUI building facilities.";
  17.     
  18.     public JDesktopPane desktop=new JDesktopPane();
  19.     
  20.     ButtonGroup themeGroup = new ButtonGroup();
  21.     
  22.     public Metalworks()
  23.     {
  24.         // This code is automatically generated by Visual Cafe when you add
  25.         // components to the visual environment. It instantiates and initializes
  26.         // the components. To modify the code, only use code syntax that matches
  27.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  28.         // parse your Java file into its visual environment.
  29.         //{{INIT_CONTROLS
  30.         setJMenuBar(JMenuBar1);
  31.         setTitle("Metalworks");
  32.         setDefaultCloseOperation(com.sun.java.swing.JFrame.DISPOSE_ON_CLOSE);
  33.         getContentPane().setLayout(new BorderLayout(0,0));
  34.         setSize(640,480);
  35.         setVisible(false);
  36.         //$$ JMenuBar1.move(24,372);
  37.         fileMenu.setText("File");
  38.         fileMenu.setActionCommand("File");
  39.         fileMenu.setMnemonic((int)'F');
  40.         JMenuBar1.add(fileMenu);
  41.         newMenu.setText("New");
  42.         newMenu.setActionCommand("New");
  43.         newMenu.setMnemonic((int)'N');
  44.         fileMenu.add(newMenu);
  45.         openMenu.setText("Open");
  46.         openMenu.setActionCommand("Open");
  47.         openMenu.setMnemonic((int)'O');
  48.         fileMenu.add(openMenu);
  49.         fileMenu.add(JSeparator1);
  50.         quitMenu.setText("Quit");
  51.         quitMenu.setActionCommand("Quit");
  52.         quitMenu.setMnemonic((int)'Q');
  53.         fileMenu.add(quitMenu);
  54.         editMenu.setText("Edit");
  55.         editMenu.setActionCommand("Edit");
  56.         editMenu.setMnemonic((int)'E');
  57.         JMenuBar1.add(editMenu);
  58.         undoMenu.setEnabled(false);
  59.         undoMenu.setText("Undo");
  60.         undoMenu.setActionCommand("Undo");
  61.         undoMenu.setAccelerator(com.sun.java.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z, Event.CTRL_MASK));
  62.         editMenu.add(undoMenu);
  63.         editMenu.add(JSeparator2);
  64.         cutMenu.setEnabled(false);
  65.         cutMenu.setText("Cut");
  66.         cutMenu.setActionCommand("Cut");
  67.         cutMenu.setAccelerator(com.sun.java.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, Event.CTRL_MASK));
  68.         cutMenu.setMnemonic((int)'U');
  69.         editMenu.add(cutMenu);
  70.         copyMenu.setEnabled(false);
  71.         copyMenu.setText("Copy");
  72.         copyMenu.setActionCommand("Copy");
  73.         copyMenu.setAccelerator(com.sun.java.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, Event.CTRL_MASK));
  74.         copyMenu.setMnemonic((int)'O');
  75.         editMenu.add(copyMenu);
  76.         pasteMenu.setEnabled(false);
  77.         pasteMenu.setText("Paste");
  78.         pasteMenu.setActionCommand("Paste");
  79.         pasteMenu.setAccelerator(com.sun.java.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, Event.CTRL_MASK));
  80.         pasteMenu.setMnemonic((int)'P');
  81.         editMenu.add(pasteMenu);
  82.         editMenu.add(JSeparator3);
  83.         preferencesMenu.setText("Preferences");
  84.         preferencesMenu.setActionCommand("Preferences");
  85.         preferencesMenu.setMnemonic((int)'R');
  86.         editMenu.add(preferencesMenu);
  87.         viewsMenu.setText("Views");
  88.         viewsMenu.setActionCommand("Views");
  89.         viewsMenu.setMnemonic((int)'V');
  90.         JMenuBar1.add(viewsMenu);
  91.         openInboxMenu.setText("Open In-box");
  92.         openInboxMenu.setActionCommand("Open In-box");
  93.         openInboxMenu.setMnemonic((int)'I');
  94.         viewsMenu.add(openInboxMenu);
  95.         openOutboxMenu.setEnabled(false);
  96.         openOutboxMenu.setText("Open Out-Box");
  97.         openOutboxMenu.setActionCommand("Open Out-Box");
  98.         openOutboxMenu.setMnemonic((int)'O');
  99.         viewsMenu.add(openOutboxMenu);
  100.         themesMenu.setText("Theme");
  101.         themesMenu.setActionCommand("Theme");
  102.         themesMenu.setMnemonic((int)'T');
  103.         JMenuBar1.add(themesMenu);
  104.         steelMenu.setText("Steel");
  105.         steelMenu.setActionCommand("Steel");
  106.         steelMenu.setSelected(true);
  107.         themesMenu.add(steelMenu);
  108.         emeraldMenu.setText("Emerald");
  109.         emeraldMenu.setActionCommand("Emerald");
  110.         themesMenu.add(emeraldMenu);
  111.         oxideMenu.setText("Oxide");
  112.         oxideMenu.setActionCommand("Oxide");
  113.         themesMenu.add(oxideMenu);
  114.         sandstoneMenu.setText("Sandstone");
  115.         sandstoneMenu.setActionCommand("Sandstone");
  116.         themesMenu.add(sandstoneMenu);
  117.         presentationMenu.setText("Presentation");
  118.         presentationMenu.setActionCommand("Presentation");
  119.         themesMenu.add(presentationMenu);
  120.         contrastMenu.setText("Contrast");
  121.         contrastMenu.setActionCommand("Contrast");
  122.         themesMenu.add(contrastMenu);
  123.         lowvisionMenu.setText("Low Vision");
  124.         lowvisionMenu.setActionCommand("Low-Vision");
  125.         themesMenu.add(lowvisionMenu);
  126.         charcoalMenu.setText("Charcoal");
  127.         charcoalMenu.setActionCommand("Charcoal");
  128.         themesMenu.add(charcoalMenu);
  129.         helpMenu.setText("Help");
  130.         helpMenu.setActionCommand("Help");
  131.         helpMenu.setMnemonic((int)'H');
  132.         JMenuBar1.add(helpMenu);
  133.         aboutMenu.setText("About");
  134.         aboutMenu.setActionCommand("About");
  135.         aboutMenu.setAccelerator(com.sun.java.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, Event.SHIFT_MASK|Event.CTRL_MASK));
  136.         aboutMenu.setMnemonic((int)'A');
  137.         helpMenu.add(aboutMenu);
  138.         openHelpMenu.setText("Open Help Window");
  139.         openHelpMenu.setActionCommand("Open Help Window");
  140.         helpMenu.add(openHelpMenu);
  141.         //}}
  142.         
  143.         themeGroup.add(steelMenu);
  144.         themeGroup.add(emeraldMenu);
  145.         themeGroup.add(oxideMenu);
  146.         themeGroup.add(sandstoneMenu);
  147.         themeGroup.add(presentationMenu);
  148.         themeGroup.add(contrastMenu);
  149.         themeGroup.add(lowvisionMenu);
  150.         themeGroup.add(charcoalMenu);
  151.         
  152.         getContentPane().add("Center", desktop);
  153.         
  154.         UIManager.addPropertyChangeListener(
  155.             new PropertyChangeListener()
  156.             {
  157.                 public void propertyChange(PropertyChangeEvent pe)
  158.                 {
  159.                     if((pe!=null)&&("lookAndFeel".equals(pe.getPropertyName())))
  160.                     {
  161.                         SwingUtilities.updateComponentTreeUI(Metalworks.this);
  162.                         invalidate();
  163.                         validate();
  164.                         repaint();
  165.                     }
  166.                 }
  167.             }
  168.         );
  169.         
  170.         //{{INIT_MENUS
  171.         //}}
  172.     
  173.         //{{REGISTER_LISTENERS
  174.         SymWindow aSymWindow = new SymWindow();
  175.         this.addWindowListener(aSymWindow);
  176.         SymItem lSymItem = new SymItem();
  177.         emeraldMenu.addItemListener(lSymItem);
  178.         steelMenu.addItemListener(lSymItem);
  179.         oxideMenu.addItemListener(lSymItem);
  180.         sandstoneMenu.addItemListener(lSymItem);
  181.         presentationMenu.addItemListener(lSymItem);
  182.         contrastMenu.addItemListener(lSymItem);
  183.         lowvisionMenu.addItemListener(lSymItem);
  184.         charcoalMenu.addItemListener(lSymItem);
  185.         SymAction lSymAction = new SymAction();
  186.         newMenu.addActionListener(lSymAction);
  187.         openMenu.addActionListener(lSymAction);
  188.         quitMenu.addActionListener(lSymAction);
  189.         preferencesMenu.addActionListener(lSymAction);
  190.         openInboxMenu.addActionListener(lSymAction);
  191.         aboutMenu.addActionListener(lSymAction);
  192.         openHelpMenu.addActionListener(lSymAction);
  193.         //}}
  194.     }
  195.  
  196.     static public void main(String args[])
  197.     {
  198.         try
  199.         {
  200.             MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
  201.             UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
  202.         }
  203.         catch(Exception e)
  204.         {
  205.             System.out.println("Metal Look and Feel error");
  206.             e.printStackTrace();
  207.             System.exit(0);
  208.         }
  209.         
  210.         Metalworks m = new Metalworks();
  211.         m.setLocation(50,50);
  212.         m.setVisible(true);
  213.     }
  214.  
  215.     //{{DECLARE_CONTROLS
  216.     com.sun.java.swing.JMenuBar JMenuBar1 = new com.sun.java.swing.JMenuBar();
  217.     com.sun.java.swing.JMenu fileMenu = new com.sun.java.swing.JMenu();
  218.     com.sun.java.swing.JMenuItem newMenu = new com.sun.java.swing.JMenuItem();
  219.     com.sun.java.swing.JMenuItem openMenu = new com.sun.java.swing.JMenuItem();
  220.     com.sun.java.swing.JSeparator JSeparator1 = new com.sun.java.swing.JSeparator();
  221.     com.sun.java.swing.JMenuItem quitMenu = new com.sun.java.swing.JMenuItem();
  222.     com.sun.java.swing.JMenu editMenu = new com.sun.java.swing.JMenu();
  223.     com.sun.java.swing.JMenuItem undoMenu = new com.sun.java.swing.JMenuItem();
  224.     com.sun.java.swing.JSeparator JSeparator2 = new com.sun.java.swing.JSeparator();
  225.     com.sun.java.swing.JMenuItem cutMenu = new com.sun.java.swing.JMenuItem();
  226.     com.sun.java.swing.JMenuItem copyMenu = new com.sun.java.swing.JMenuItem();
  227.     com.sun.java.swing.JMenuItem pasteMenu = new com.sun.java.swing.JMenuItem();
  228.     com.sun.java.swing.JSeparator JSeparator3 = new com.sun.java.swing.JSeparator();
  229.     com.sun.java.swing.JMenuItem preferencesMenu = new com.sun.java.swing.JMenuItem();
  230.     com.sun.java.swing.JMenu viewsMenu = new com.sun.java.swing.JMenu();
  231.     com.sun.java.swing.JMenuItem openInboxMenu = new com.sun.java.swing.JMenuItem();
  232.     com.sun.java.swing.JMenuItem openOutboxMenu = new com.sun.java.swing.JMenuItem();
  233.     com.sun.java.swing.JMenu themesMenu = new com.sun.java.swing.JMenu();
  234.     com.sun.java.swing.JRadioButtonMenuItem steelMenu = new com.sun.java.swing.JRadioButtonMenuItem();
  235.     com.sun.java.swing.JRadioButtonMenuItem emeraldMenu = new com.sun.java.swing.JRadioButtonMenuItem();
  236.     com.sun.java.swing.JRadioButtonMenuItem oxideMenu = new com.sun.java.swing.JRadioButtonMenuItem();
  237.     com.sun.java.swing.JRadioButtonMenuItem sandstoneMenu = new com.sun.java.swing.JRadioButtonMenuItem();
  238.     com.sun.java.swing.JRadioButtonMenuItem presentationMenu = new com.sun.java.swing.JRadioButtonMenuItem();
  239.     com.sun.java.swing.JRadioButtonMenuItem contrastMenu = new com.sun.java.swing.JRadioButtonMenuItem();
  240.     com.sun.java.swing.JRadioButtonMenuItem lowvisionMenu = new com.sun.java.swing.JRadioButtonMenuItem();
  241.     com.sun.java.swing.JRadioButtonMenuItem charcoalMenu = new com.sun.java.swing.JRadioButtonMenuItem();
  242.     com.sun.java.swing.JMenu helpMenu = new com.sun.java.swing.JMenu();
  243.     com.sun.java.swing.JMenuItem aboutMenu = new com.sun.java.swing.JMenuItem();
  244.     com.sun.java.swing.JMenuItem openHelpMenu = new com.sun.java.swing.JMenuItem();
  245.     //}}
  246.  
  247.     //{{DECLARE_MENUS
  248.     //}}
  249.  
  250.  
  251.     class SymWindow extends java.awt.event.WindowAdapter
  252.     {
  253.         public void windowClosing(java.awt.event.WindowEvent event)
  254.         {
  255.             Object object = event.getSource();
  256.             if (object == Metalworks.this)
  257.                 metalworks_windowClosing(event);
  258.         }
  259.     }
  260.  
  261.     void metalworks_windowClosing(java.awt.event.WindowEvent event)
  262.     {
  263.         System.exit(0);
  264.     }
  265.  
  266.     class SymItem implements java.awt.event.ItemListener
  267.     {
  268.         public void itemStateChanged(java.awt.event.ItemEvent event)
  269.         {
  270.             Object object = event.getSource();
  271.             if (object == emeraldMenu)
  272.                 emeraldMenu_itemStateChanged(event);
  273.             else if (object == steelMenu)
  274.                 steelMenu_itemStateChanged(event);
  275.             else if (object == oxideMenu)
  276.                 oxideMenu_itemStateChanged(event);
  277.             else if (object == sandstoneMenu)
  278.                 sandstoneMenu_itemStateChanged(event);
  279.             else if (object == presentationMenu)
  280.                 presentationMenu_itemStateChanged(event);
  281.             else if (object == contrastMenu)
  282.                 contrastMenu_itemStateChanged(event);
  283.             else if (object == lowvisionMenu)
  284.                 lowvisionMenu_itemStateChanged(event);
  285.             else if (object == charcoalMenu)
  286.                 charcoalMenu_itemStateChanged(event);
  287.         }
  288.     }
  289.  
  290.     void steelMenu_itemStateChanged(java.awt.event.ItemEvent event)
  291.     {
  292.         if(steelMenu.isSelected())
  293.         {
  294.             try
  295.             {
  296.                 MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
  297.                 UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
  298.             }
  299.             catch(Exception e)
  300.             {
  301.                 e.printStackTrace();
  302.             }
  303.         }
  304.     }
  305.  
  306.     void emeraldMenu_itemStateChanged(java.awt.event.ItemEvent event)
  307.     {
  308.         if(emeraldMenu.isSelected())
  309.         {
  310.             try
  311.             {
  312.                 MetalLookAndFeel.setCurrentTheme(new GreenMetalTheme());
  313.                 UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
  314.             }
  315.             catch(Exception e)
  316.             {
  317.                 e.printStackTrace();
  318.             }
  319.         }
  320.     }
  321.  
  322.     void oxideMenu_itemStateChanged(java.awt.event.ItemEvent event)
  323.     {
  324.         if(oxideMenu.isSelected())
  325.         {
  326.             try
  327.             {
  328.                 MetalLookAndFeel.setCurrentTheme(new AquaMetalTheme());
  329.                 UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
  330.             }
  331.             catch(Exception e)
  332.             {
  333.                 e.printStackTrace();
  334.             }
  335.         }
  336.     }
  337.  
  338.     void sandstoneMenu_itemStateChanged(java.awt.event.ItemEvent event)
  339.     {
  340.         if(sandstoneMenu.isSelected())
  341.         {
  342.             try
  343.             {
  344.                 MetalLookAndFeel.setCurrentTheme(new KhakiMetalTheme());
  345.                 UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
  346.             }
  347.             catch(Exception e)
  348.             {
  349.                 e.printStackTrace();
  350.             }
  351.         }
  352.     }
  353.  
  354.     void presentationMenu_itemStateChanged(java.awt.event.ItemEvent event)
  355.     {
  356.         if(presentationMenu.isSelected())
  357.         {
  358.             try
  359.             {
  360.                 MetalLookAndFeel.setCurrentTheme(new DemoMetalTheme());
  361.                 UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
  362.             }
  363.             catch(Exception e)
  364.             {
  365.                 e.printStackTrace();
  366.             }
  367.         }
  368.     }
  369.  
  370.     void contrastMenu_itemStateChanged(java.awt.event.ItemEvent event)
  371.     {
  372.         if(contrastMenu.isSelected())
  373.         {
  374.             try
  375.             {
  376.                 MetalLookAndFeel.setCurrentTheme(new ContrastMetalTheme());
  377.                 UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
  378.             }
  379.             catch(Exception e)
  380.             {
  381.                 e.printStackTrace();
  382.             }
  383.         }
  384.     }
  385.  
  386.     void lowvisionMenu_itemStateChanged(java.awt.event.ItemEvent event)
  387.     {
  388.         if(lowvisionMenu.isSelected())
  389.         {
  390.             try
  391.             {
  392.                 MetalLookAndFeel.setCurrentTheme(new BigContrastMetalTheme());
  393.                 UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
  394.             }
  395.             catch(Exception e)
  396.             {
  397.                 e.printStackTrace();
  398.             }
  399.         }
  400.     }
  401.  
  402.     void charcoalMenu_itemStateChanged(java.awt.event.ItemEvent event)
  403.     {
  404.         if(charcoalMenu.isSelected())
  405.         {
  406.             try
  407.             {
  408.                 MetalLookAndFeel.setCurrentTheme(new PropertiesMetalTheme(new java.io.FileInputStream("MyTheme.theme")));
  409.                 UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
  410.             }
  411.             catch(Exception e)
  412.             {
  413.                 e.printStackTrace();
  414.             }
  415.         }
  416.     }
  417.  
  418.     class SymAction implements java.awt.event.ActionListener
  419.     {
  420.         public void actionPerformed(java.awt.event.ActionEvent event)
  421.         {
  422.             Object object = event.getSource();
  423.             if (object == newMenu)
  424.                 newMenu_actionPerformed(event);
  425.             else if (object == openMenu)
  426.                 openMenu_actionPerformed(event);
  427.             else if (object == quitMenu)
  428.                 quitMenu_actionPerformed(event);
  429.             else if (object == preferencesMenu)
  430.                 preferencesMenu_actionPerformed(event);
  431.             else if (object == openInboxMenu)
  432.                 openInboxMenu_actionPerformed(event);
  433.             else if (object == aboutMenu)
  434.                 aboutMenu_actionPerformed(event);
  435.             else if (object == openHelpMenu)
  436.                 openHelpMenu_actionPerformed(event);
  437.         }
  438.     }
  439.  
  440.     void newMenu_actionPerformed(java.awt.event.ActionEvent event)
  441.     {
  442.         try
  443.         {
  444.             MailDocument m = new MailDocument();
  445.             desktop.add(m, DOCLAYER);
  446.             m.setSelected(true);
  447.         }
  448.         catch(Exception e)
  449.         {
  450.             e.printStackTrace();
  451.         }
  452.     }
  453.  
  454.     void openMenu_actionPerformed(java.awt.event.ActionEvent event)
  455.     {
  456.         JFileChooser jc = new JFileChooser();
  457.         jc.showOpenDialog(desktop);
  458.     }
  459.  
  460.     void quitMenu_actionPerformed(java.awt.event.ActionEvent event)
  461.     {
  462.         System.exit(0);
  463.     }
  464.  
  465.     void preferencesMenu_actionPerformed(java.awt.event.ActionEvent event)
  466.     {
  467.         PrefsDialog dialog = new PrefsDialog(this);
  468.         dialog.setVisible(true);
  469.     }
  470.  
  471.     void openInboxMenu_actionPerformed(java.awt.event.ActionEvent event)
  472.     {
  473.         try
  474.         {
  475.             InboxWindow in = new InboxWindow();
  476.             desktop.add(in, DOCLAYER);
  477.             in.setSelected(true);
  478.         }
  479.         catch (Exception e)
  480.         {
  481.             e.printStackTrace();
  482.         }
  483.     }
  484.  
  485.     void aboutMenu_actionPerformed(java.awt.event.ActionEvent event)
  486.     {
  487.         JOptionPane.showInternalMessageDialog(desktop, ABOUTMSG, "About", JOptionPane.INFORMATION_MESSAGE);
  488.     }
  489.  
  490.     void openHelpMenu_actionPerformed(java.awt.event.ActionEvent event)
  491.     {
  492.         try
  493.         {
  494.             HelpWindow in = new HelpWindow();
  495.             desktop.add(in, HELPLAYER);
  496.             in.setSelected(true);
  497.         }
  498.         catch(Exception e)
  499.         {
  500.             e.printStackTrace();
  501.         }
  502.     }
  503. }