1 36 37 40 41 import java.awt.*; 42 import java.awt.event.*; 43 import java.beans.*; 44 import javax.swing.*; 45 import javax.swing.border.*; 46 import javax.swing.plaf.metal.*; 47 48 49 55 public class MetalworksPrefs extends JDialog { 56 57 public MetalworksPrefs(JFrame f) { 58 super(f, "Preferences", true); 59 JPanel container = new JPanel(); 60 container.setLayout( new BorderLayout() ); 61 62 JTabbedPane tabs = new JTabbedPane(); 63 JPanel filters = buildFilterPanel(); 64 JPanel conn = buildConnectingPanel(); 65 tabs.addTab( "Filters", null, filters ); 66 tabs.addTab( "Connecting", null, conn ); 67 68 69 JPanel buttonPanel = new JPanel(); 70 buttonPanel.setLayout ( new FlowLayout(FlowLayout.RIGHT) ); 71 JButton cancel = new JButton("Cancel"); 72 cancel.addActionListener(new ActionListener() { 73 public void actionPerformed(ActionEvent e) { 74 CancelPressed(); 75 }}); 76 buttonPanel.add( cancel ); 77 JButton ok = new JButton("OK"); 78 ok.addActionListener(new ActionListener() { 79 public void actionPerformed(ActionEvent e) { 80 OKPressed(); 81 }}); 82 buttonPanel.add( ok ); 83 getRootPane().setDefaultButton(ok); 84 85 container.add(tabs, BorderLayout.CENTER); 86 container.add(buttonPanel, BorderLayout.SOUTH); 87 getContentPane().add(container); 88 pack(); 89 centerDialog(); 90 UIManager.addPropertyChangeListener(new UISwitchListener(container)); 91 } 92 93 public JPanel buildFilterPanel() { 94 JPanel filters = new JPanel(); 95 filters.setLayout( new GridLayout(1, 0) ); 96 97 JPanel spamPanel = new JPanel(); 98 99 spamPanel.setLayout(new ColumnLayout()); 100 spamPanel.setBorder( new TitledBorder("Spam") ); 101 ButtonGroup spamGroup = new ButtonGroup(); 102 JRadioButton file = new JRadioButton("File in Spam Folder"); 103 JRadioButton delete = new JRadioButton("Auto Delete"); 104 JRadioButton bomb = new JRadioButton("Reverse Mail-Bomb"); 105 spamGroup.add(file); 106 spamGroup.add(delete); 107 spamGroup.add(bomb); 108 spamPanel.add(file); 109 spamPanel.add(delete); 110 spamPanel.add(bomb); 111 file.setSelected(true); 112 filters.add(spamPanel); 113 114 JPanel autoRespond = new JPanel(); 115 autoRespond.setLayout(new ColumnLayout()); 116 autoRespond.setBorder( new TitledBorder("Auto Response") ); 117 118 ButtonGroup respondGroup = new ButtonGroup(); 119 JRadioButton none = new JRadioButton("None"); 120 JRadioButton vaca = new JRadioButton("Send Vacation Message"); 121 JRadioButton thx = new JRadioButton("Send Thank You Message"); 122 123 respondGroup.add(none); 124 respondGroup.add(vaca); 125 respondGroup.add(thx); 126 127 autoRespond.add(none); 128 autoRespond.add(vaca); 129 autoRespond.add(thx); 130 131 none.setSelected(true); 132 filters.add(autoRespond); 133 134 return filters; 135 } 136 137 public JPanel buildConnectingPanel() { 138 JPanel connectPanel = new JPanel(); 139 connectPanel.setLayout( new ColumnLayout() ); 140 141 JPanel protoPanel = new JPanel(); 142 JLabel protoLabel = new JLabel ("Protocol"); 143 JComboBox protocol = new JComboBox(); 144 protocol.addItem("SMTP"); 145 protocol.addItem("IMAP"); 146 protocol.addItem("Other..."); 147 protoPanel.add(protoLabel); 148 protoPanel.add(protocol); 149 150 JPanel attachmentPanel = new JPanel(); 151 JLabel attachmentLabel = new JLabel ("Attachments"); 152 JComboBox attach = new JComboBox(); 153 attach.addItem("Download Always"); 154 attach.addItem("Ask size > 1 Meg"); 155 attach.addItem("Ask size > 5 Meg"); 156 attach.addItem("Ask Always"); 157 attachmentPanel.add(attachmentLabel); 158 attachmentPanel.add(attach); 159 160 JCheckBox autoConn = new JCheckBox("Auto Connect"); 161 JCheckBox compress = new JCheckBox("Use Compression"); 162 autoConn.setSelected( true ); 163 164 connectPanel.add(protoPanel); 165 connectPanel.add(attachmentPanel); 166 connectPanel.add(autoConn); 167 connectPanel.add(compress); 168 return connectPanel; 169 } 170 171 172 173 protected void centerDialog() { 174 Dimension screenSize = this.getToolkit().getScreenSize(); 175 Dimension size = this.getSize(); 176 screenSize.height = screenSize.height/2; 177 screenSize.width = screenSize.width/2; 178 size.height = size.height/2; 179 size.width = size.width/2; 180 int y = screenSize.height - size.height; 181 int x = screenSize.width - size.width; 182 this.setLocation(x,y); 183 } 184 185 public void CancelPressed() { 186 this.setVisible(false); 187 } 188 189 public void OKPressed() { 190 this.setVisible(false); 191 } 192 193 } 194 195 class ColumnLayout implements LayoutManager { 196 197 int xInset = 5; 198 int yInset = 5; 199 int yGap = 2; 200 201 public void addLayoutComponent(String s, Component c) {} 202 203 public void layoutContainer(Container c) { 204 Insets insets = c.getInsets(); 205 int height = yInset + insets.top; 206 207 Component[] children = c.getComponents(); 208 Dimension compSize = null; 209 for (int i = 0; i < children.length; i++) { 210 compSize = children[i].getPreferredSize(); 211 children[i].setSize(compSize.width, compSize.height); 212 children[i].setLocation( xInset + insets.left, height); 213 height += compSize.height + yGap; 214 } 215 216 } 217 218 public Dimension minimumLayoutSize(Container c) { 219 Insets insets = c.getInsets(); 220 int height = yInset + insets.top; 221 int width = 0 + insets.left + insets.right; 222 223 Component[] children = c.getComponents(); 224 Dimension compSize = null; 225 for (int i = 0; i < children.length; i++) { 226 compSize = children[i].getPreferredSize(); 227 height += compSize.height + yGap; 228 width = Math.max(width, compSize.width + insets.left + insets.right + xInset*2); 229 } 230 height += insets.bottom; 231 return new Dimension( width, height); 232 } 233 234 public Dimension preferredLayoutSize(Container c) { 235 return minimumLayoutSize(c); 236 } 237 238 public void removeLayoutComponent(Component c) {} 239 240 } 241 | Popular Tags |