2
* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
8
* - Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
11
* - Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
15
* - Neither the name of Oracle nor the names of its
16
* contributors may be used to endorse or promote products derived
17
* from this software without specific prior written permission.
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
* This source code is provided to illustrate the usage of a given feature
34
* or technique and has been deliberately simplified. Additional steps
35
* required for a production-quality application, such as security checks,
36
* input validation and proper error handling, might not be present in
42
import java.awt.BorderLayout;
43
import java.awt.Component;
44
import java.awt.Container;
45
import java.awt.Dimension;
46
import java.awt.FlowLayout;
47
import java.awt.GridLayout;
48
import java.awt.Insets;
49
import java.awt.LayoutManager;
50
import java.awt.event.ActionEvent;
51
import java.awt.event.ActionListener;
52
import javax.swing.ButtonGroup;
53
import javax.swing.JButton;
54
import javax.swing.JCheckBox;
55
import javax.swing.JComboBox;
56
import javax.swing.JDialog;
57
import javax.swing.JFrame;
58
import javax.swing.JLabel;
59
import javax.swing.JPanel;
60
import javax.swing.JRadioButton;
61
import javax.swing.JTabbedPane;
62
import javax.swing.UIManager;
63
import javax.swing.border.TitledBorder;
67
* This is dialog which allows users to choose preferences
69
* @author Steve Wilson
70
* @author Alexander Kouznetsov
72
@SuppressWarnings("serial")
73
public final class MetalworksPrefs extends JDialog {
75
public MetalworksPrefs(JFrame f) {
76
super(f, "Preferences", true);
77
JPanel container = new JPanel();
78
container.setLayout(new BorderLayout());
80
JTabbedPane tabs = new JTabbedPane();
81
JPanel filters = buildFilterPanel();
82
JPanel conn = buildConnectingPanel();
83
tabs.addTab("Filters", null, filters);
84
tabs.addTab("Connecting", null, conn);
87
JPanel buttonPanel = new JPanel();
88
buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
89
JButton cancel = new JButton("Cancel");
90
cancel.addActionListener(new ActionListener() {
92
public void actionPerformed(ActionEvent e) {
96
buttonPanel.add(cancel);
97
JButton ok = new JButton("OK");
98
ok.addActionListener(new ActionListener() {
100
public void actionPerformed(ActionEvent e) {
105
getRootPane().setDefaultButton(ok);
107
container.add(tabs, BorderLayout.CENTER);
108
container.add(buttonPanel, BorderLayout.SOUTH);
109
getContentPane().add(container);
112
UIManager.addPropertyChangeListener(new UISwitchListener(container));
115
public JPanel buildFilterPanel() {
116
JPanel filters = new JPanel();
117
filters.setLayout(new GridLayout(1, 0));
119
JPanel spamPanel = new JPanel();
121
spamPanel.setLayout(new ColumnLayout());
122
spamPanel.setBorder(new TitledBorder("Spam"));
123
ButtonGroup spamGroup = new ButtonGroup();
124
JRadioButton file = new JRadioButton("File in Spam Folder");
125
JRadioButton delete = new JRadioButton("Auto Delete");
126
JRadioButton bomb = new JRadioButton("Reverse Mail-Bomb");
128
spamGroup.add(delete);
131
spamPanel.add(delete);
133
file.setSelected(true);
134
filters.add(spamPanel);
136
JPanel autoRespond = new JPanel();
137
autoRespond.setLayout(new ColumnLayout());
138
autoRespond.setBorder(new TitledBorder("Auto Response"));
140
ButtonGroup respondGroup = new ButtonGroup();
141
JRadioButton none = new JRadioButton("None");
142
JRadioButton vaca = new JRadioButton("Send Vacation Message");
143
JRadioButton thx = new JRadioButton("Send Thank You Message");
145
respondGroup.add(none);
146
respondGroup.add(vaca);
147
respondGroup.add(thx);
149
autoRespond.add(none);
150
autoRespond.add(vaca);
151
autoRespond.add(thx);
153
none.setSelected(true);
154
filters.add(autoRespond);
159
public JPanel buildConnectingPanel() {
160
JPanel connectPanel = new JPanel();
161
connectPanel.setLayout(new ColumnLayout());
163
JPanel protoPanel = new JPanel();
164
JLabel protoLabel = new JLabel("Protocol");
165
JComboBox<String> protocol = new JComboBox<>();
166
protocol.addItem("SMTP");
167
protocol.addItem("IMAP");
168
protocol.addItem("Other...");
169
protoPanel.add(protoLabel);
170
protoPanel.add(protocol);
172
JPanel attachmentPanel = new JPanel();
173
JLabel attachmentLabel = new JLabel("Attachments");
174
JComboBox<String> attach = new JComboBox<>();
175
attach.addItem("Download Always");
176
attach.addItem("Ask size > 1 Meg");
177
attach.addItem("Ask size > 5 Meg");
178
attach.addItem("Ask Always");
179
attachmentPanel.add(attachmentLabel);
180
attachmentPanel.add(attach);
182
JCheckBox autoConn = new JCheckBox("Auto Connect");
183
JCheckBox compress = new JCheckBox("Use Compression");
184
autoConn.setSelected(true);
186
connectPanel.add(protoPanel);
187
connectPanel.add(attachmentPanel);
188
connectPanel.add(autoConn);
189
connectPanel.add(compress);
193
protected void centerDialog() {
194
Dimension screenSize = this.getToolkit().getScreenSize();
195
Dimension size = this.getSize();
196
screenSize.height = screenSize.height / 2;
197
screenSize.width = screenSize.width / 2;
198
size.height = size.height / 2;
199
size.width = size.width / 2;
200
int y = screenSize.height - size.height;
201
int x = screenSize.width - size.width;
202
this.setLocation(x, y);
205
public void CancelPressed() {
206
this.setVisible(false);
209
public void OKPressed() {
210
this.setVisible(false);
215
class ColumnLayout implements LayoutManager {
221
public void addLayoutComponent(String s, Component c) {
224
public void layoutContainer(Container c) {
225
Insets insets = c.getInsets();
226
int height = yInset + insets.top;
228
Component[] children = c.getComponents();
229
Dimension compSize = null;
230
for (Component child : children) {
231
compSize = child.getPreferredSize();
232
child.setSize(compSize.width, compSize.height);
233
child.setLocation(xInset + insets.left, height);
234
height += compSize.height + yGap;
239
public Dimension minimumLayoutSize(Container c) {
240
Insets insets = c.getInsets();
241
int height = yInset + insets.top;
242
int width = 0 + insets.left + insets.right;
244
Component[] children = c.getComponents();
245
Dimension compSize = null;
246
for (Component child : children) {
247
compSize = child.getPreferredSize();
248
height += compSize.height + yGap;
249
width = Math.max(width, compSize.width + insets.left + insets.right + xInset
252
height += insets.bottom;
253
return new Dimension(width, height);
256
public Dimension preferredLayoutSize(Container c) {
257
return minimumLayoutSize(c);
260
public void removeLayoutComponent(Component c) {