home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / JBuilder8.iso / Solaris / resource / jre / demo / plugin / jfc / Metalworks / src / MetalworksPrefs.java < prev    next >
Encoding:
Java Source  |  2002-09-06  |  7.3 KB  |  240 lines

  1. /*
  2.  * Copyright (c) 2002 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.  * -Redistribution in binary form must reproduct the above copyright
  12.  *  notice, this list of conditions and the following disclaimer in
  13.  *  the documentation and/or other materials provided with the distribution.
  14.  * 
  15.  * Neither the name of Sun Microsystems, Inc. or the names of contributors
  16.  * may be used to endorse or promote products derived from this software
  17.  * without specific prior written permission.
  18.  * 
  19.  * This software is provided "AS IS," without a warranty of any kind. ALL
  20.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
  21.  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
  22.  * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT
  23.  * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
  24.  * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
  25.  * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
  26.  * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
  27.  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
  28.  * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
  29.  * IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  30.  * 
  31.  * You acknowledge that Software is not designed, licensed or intended for
  32.  * use in the design, construction, operation or maintenance of any nuclear
  33.  * facility.
  34.  */
  35.  
  36. /*
  37.  * @(#)MetalworksPrefs.java    1.8 02/06/13
  38.  */
  39.  
  40. import java.awt.*;
  41. import java.awt.event.*;
  42. import java.beans.*;
  43. import javax.swing.*;
  44. import javax.swing.border.*;
  45. import javax.swing.plaf.metal.*;
  46.  
  47.  
  48. /**
  49.   * This is dialog which allows users to choose preferences
  50.   *
  51.  * @version 1.8 06/13/02
  52.   * @author Steve Wilson
  53.   */
  54. public class MetalworksPrefs extends JDialog {
  55.  
  56.     public MetalworksPrefs(JFrame f) {
  57.         super(f, "Preferences", true);
  58.     JPanel container = new JPanel();
  59.     container.setLayout( new BorderLayout() );
  60.  
  61.      JTabbedPane tabs = new JTabbedPane();
  62.     JPanel filters = buildFilterPanel();
  63.     JPanel conn = buildConnectingPanel();
  64.     tabs.addTab( "Filters", null, filters );
  65.     tabs.addTab( "Connecting", null, conn );
  66.  
  67.  
  68.     JPanel buttonPanel = new JPanel();
  69.     buttonPanel.setLayout ( new FlowLayout(FlowLayout.RIGHT) );
  70.     JButton cancel = new JButton("Cancel");
  71.     cancel.addActionListener(new ActionListener() {
  72.                            public void actionPerformed(ActionEvent e) {
  73.                    CancelPressed();
  74.                    }});
  75.     buttonPanel.add( cancel );
  76.     JButton ok = new JButton("OK");
  77.     ok.addActionListener(new ActionListener() {
  78.                            public void actionPerformed(ActionEvent e) {
  79.                    OKPressed();
  80.                    }});
  81.     buttonPanel.add( ok );
  82.     getRootPane().setDefaultButton(ok);
  83.  
  84.     container.add(tabs, BorderLayout.CENTER);
  85.     container.add(buttonPanel, BorderLayout.SOUTH);
  86.     getContentPane().add(container);
  87.     pack();
  88.     centerDialog();
  89.     UIManager.addPropertyChangeListener(new UISwitchListener(container));
  90.     }
  91.  
  92.     public JPanel buildFilterPanel() {
  93.     JPanel filters = new JPanel();
  94.     filters.setLayout( new GridLayout(1, 0) );
  95.  
  96.     JPanel spamPanel = new JPanel();
  97.  
  98.     spamPanel.setLayout(new ColumnLayout());
  99.     spamPanel.setBorder( new TitledBorder("Spam") );
  100.     ButtonGroup spamGroup = new ButtonGroup();
  101.     JRadioButton file = new JRadioButton("File in Spam Folder");
  102.     JRadioButton delete = new JRadioButton("Auto Delete");
  103.     JRadioButton bomb = new JRadioButton("Reverse Mail-Bomb");
  104.     spamGroup.add(file);
  105.     spamGroup.add(delete);
  106.     spamGroup.add(bomb);   
  107.     spamPanel.add(file);
  108.     spamPanel.add(delete);
  109.     spamPanel.add(bomb);  
  110.     file.setSelected(true);
  111.     filters.add(spamPanel);
  112.     
  113.     JPanel autoRespond = new JPanel();
  114.     autoRespond.setLayout(new ColumnLayout());
  115.     autoRespond.setBorder( new TitledBorder("Auto Response") );
  116.  
  117.     ButtonGroup respondGroup = new ButtonGroup();
  118.     JRadioButton none = new JRadioButton("None");
  119.     JRadioButton vaca = new JRadioButton("Send Vacation Message");
  120.     JRadioButton thx = new JRadioButton("Send Thank You Message");
  121.  
  122.     respondGroup.add(none);
  123.     respondGroup.add(vaca);
  124.     respondGroup.add(thx);
  125.  
  126.     autoRespond.add(none);
  127.     autoRespond.add(vaca);
  128.     autoRespond.add(thx);
  129.  
  130.     none.setSelected(true);
  131.     filters.add(autoRespond);
  132.  
  133.     return filters;
  134.     }
  135.  
  136.     public JPanel buildConnectingPanel() {
  137.     JPanel connectPanel = new JPanel();
  138.     connectPanel.setLayout( new ColumnLayout() );
  139.  
  140.     JPanel protoPanel = new JPanel();
  141.     JLabel protoLabel = new JLabel ("Protocol");
  142.     JComboBox protocol = new JComboBox();
  143.     protocol.addItem("SMTP");
  144.     protocol.addItem("IMAP");
  145.     protocol.addItem("Other...");
  146.     protoPanel.add(protoLabel);
  147.     protoPanel.add(protocol);
  148.  
  149.     JPanel attachmentPanel = new JPanel();
  150.     JLabel attachmentLabel = new JLabel ("Attachments");
  151.     JComboBox attach = new JComboBox();
  152.     attach.addItem("Download Always");
  153.     attach.addItem("Ask size > 1 Meg");
  154.     attach.addItem("Ask size > 5 Meg");
  155.     attach.addItem("Ask Always");
  156.     attachmentPanel.add(attachmentLabel);
  157.     attachmentPanel.add(attach);
  158.  
  159.     JCheckBox autoConn = new JCheckBox("Auto Connect");
  160.     JCheckBox compress = new JCheckBox("Use Compression");
  161.     autoConn.setSelected( true );
  162.  
  163.     connectPanel.add(protoPanel);
  164.     connectPanel.add(attachmentPanel);
  165.     connectPanel.add(autoConn);
  166.     connectPanel.add(compress);
  167.     return connectPanel;
  168.     }
  169.  
  170.  
  171.  
  172.     protected void centerDialog() {
  173.         Dimension screenSize = this.getToolkit().getScreenSize();
  174.     Dimension size = this.getSize();
  175.     screenSize.height = screenSize.height/2;
  176.     screenSize.width = screenSize.width/2;
  177.     size.height = size.height/2;
  178.     size.width = size.width/2;
  179.     int y = screenSize.height - size.height;
  180.     int x = screenSize.width - size.width;
  181.     this.setLocation(x,y);
  182.     }
  183.  
  184.     public void CancelPressed() {
  185.         this.setVisible(false);
  186.     }
  187.  
  188.     public void OKPressed() {
  189.         this.setVisible(false);
  190.     }
  191.   
  192. }
  193.  
  194. class ColumnLayout implements LayoutManager {
  195.  
  196.   int xInset = 5;
  197.   int yInset = 5;
  198.   int yGap = 2;
  199.  
  200.   public void addLayoutComponent(String s, Component c) {}
  201.  
  202.   public void layoutContainer(Container c) {
  203.       Insets insets = c.getInsets();
  204.       int height = yInset + insets.top;
  205.       
  206.       Component[] children = c.getComponents();
  207.       Dimension compSize = null;
  208.       for (int i = 0; i < children.length; i++) {
  209.       compSize = children[i].getPreferredSize();
  210.       children[i].setSize(compSize.width, compSize.height);
  211.       children[i].setLocation( xInset + insets.left, height);
  212.       height += compSize.height + yGap;
  213.       }
  214.  
  215.   }
  216.  
  217.   public Dimension minimumLayoutSize(Container c) {
  218.       Insets insets = c.getInsets();
  219.       int height = yInset + insets.top;
  220.       int width = 0 + insets.left + insets.right;
  221.       
  222.       Component[] children = c.getComponents();
  223.       Dimension compSize = null;
  224.       for (int i = 0; i < children.length; i++) {
  225.       compSize = children[i].getPreferredSize();
  226.       height += compSize.height + yGap;
  227.       width = Math.max(width, compSize.width + insets.left + insets.right + xInset*2);
  228.       }
  229.       height += insets.bottom;
  230.       return new Dimension( width, height);
  231.   }
  232.   
  233.   public Dimension preferredLayoutSize(Container c) {
  234.       return minimumLayoutSize(c);
  235.   }
  236.    
  237.   public void removeLayoutComponent(Component c) {}
  238.  
  239. }
  240.