author | mgronlun |
Sun, 22 Sep 2019 15:38:32 +0200 | |
branch | JEP-349-branch |
changeset 58258 | 48aabad45dac |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
8961 | 2 |
* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* - 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. |
|
14 |
* |
|
5506 | 15 |
* - Neither the name of Oracle nor the names of its |
2 | 16 |
* contributors may be used to endorse or promote products derived |
17 |
* from this software without specific prior written permission. |
|
18 |
* |
|
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. |
|
30 |
*/ |
|
31 |
||
10292
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
8961
diff
changeset
|
32 |
/* |
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
8961
diff
changeset
|
33 |
* This source code is provided to illustrate the usage of a given feature |
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
8961
diff
changeset
|
34 |
* or technique and has been deliberately simplified. Additional steps |
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
8961
diff
changeset
|
35 |
* required for a production-quality application, such as security checks, |
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
8961
diff
changeset
|
36 |
* input validation and proper error handling, might not be present in |
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
8961
diff
changeset
|
37 |
* this sample code. |
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
8961
diff
changeset
|
38 |
*/ |
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
8961
diff
changeset
|
39 |
|
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
8961
diff
changeset
|
40 |
|
2 | 41 |
|
8961 | 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; |
|
2 | 64 |
|
65 |
||
66 |
/** |
|
8961 | 67 |
* This is dialog which allows users to choose preferences |
68 |
* |
|
69 |
* @author Steve Wilson |
|
70 |
* @author Alexander Kouznetsov |
|
71 |
*/ |
|
72 |
@SuppressWarnings("serial") |
|
73 |
public final class MetalworksPrefs extends JDialog { |
|
2 | 74 |
|
75 |
public MetalworksPrefs(JFrame f) { |
|
76 |
super(f, "Preferences", true); |
|
77 |
JPanel container = new JPanel(); |
|
8961 | 78 |
container.setLayout(new BorderLayout()); |
2 | 79 |
|
80 |
JTabbedPane tabs = new JTabbedPane(); |
|
81 |
JPanel filters = buildFilterPanel(); |
|
82 |
JPanel conn = buildConnectingPanel(); |
|
8961 | 83 |
tabs.addTab("Filters", null, filters); |
84 |
tabs.addTab("Connecting", null, conn); |
|
2 | 85 |
|
86 |
||
87 |
JPanel buttonPanel = new JPanel(); |
|
8961 | 88 |
buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
2 | 89 |
JButton cancel = new JButton("Cancel"); |
90 |
cancel.addActionListener(new ActionListener() { |
|
8961 | 91 |
|
92 |
public void actionPerformed(ActionEvent e) { |
|
93 |
CancelPressed(); |
|
94 |
} |
|
95 |
}); |
|
96 |
buttonPanel.add(cancel); |
|
2 | 97 |
JButton ok = new JButton("OK"); |
98 |
ok.addActionListener(new ActionListener() { |
|
8961 | 99 |
|
100 |
public void actionPerformed(ActionEvent e) { |
|
101 |
OKPressed(); |
|
102 |
} |
|
103 |
}); |
|
104 |
buttonPanel.add(ok); |
|
2 | 105 |
getRootPane().setDefaultButton(ok); |
106 |
||
107 |
container.add(tabs, BorderLayout.CENTER); |
|
108 |
container.add(buttonPanel, BorderLayout.SOUTH); |
|
109 |
getContentPane().add(container); |
|
110 |
pack(); |
|
111 |
centerDialog(); |
|
112 |
UIManager.addPropertyChangeListener(new UISwitchListener(container)); |
|
113 |
} |
|
114 |
||
115 |
public JPanel buildFilterPanel() { |
|
116 |
JPanel filters = new JPanel(); |
|
8961 | 117 |
filters.setLayout(new GridLayout(1, 0)); |
2 | 118 |
|
119 |
JPanel spamPanel = new JPanel(); |
|
120 |
||
121 |
spamPanel.setLayout(new ColumnLayout()); |
|
8961 | 122 |
spamPanel.setBorder(new TitledBorder("Spam")); |
2 | 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"); |
|
127 |
spamGroup.add(file); |
|
128 |
spamGroup.add(delete); |
|
129 |
spamGroup.add(bomb); |
|
130 |
spamPanel.add(file); |
|
131 |
spamPanel.add(delete); |
|
132 |
spamPanel.add(bomb); |
|
133 |
file.setSelected(true); |
|
134 |
filters.add(spamPanel); |
|
135 |
||
136 |
JPanel autoRespond = new JPanel(); |
|
137 |
autoRespond.setLayout(new ColumnLayout()); |
|
8961 | 138 |
autoRespond.setBorder(new TitledBorder("Auto Response")); |
2 | 139 |
|
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"); |
|
144 |
||
145 |
respondGroup.add(none); |
|
146 |
respondGroup.add(vaca); |
|
147 |
respondGroup.add(thx); |
|
148 |
||
149 |
autoRespond.add(none); |
|
150 |
autoRespond.add(vaca); |
|
151 |
autoRespond.add(thx); |
|
152 |
||
153 |
none.setSelected(true); |
|
154 |
filters.add(autoRespond); |
|
155 |
||
156 |
return filters; |
|
157 |
} |
|
158 |
||
159 |
public JPanel buildConnectingPanel() { |
|
160 |
JPanel connectPanel = new JPanel(); |
|
8961 | 161 |
connectPanel.setLayout(new ColumnLayout()); |
2 | 162 |
|
163 |
JPanel protoPanel = new JPanel(); |
|
8961 | 164 |
JLabel protoLabel = new JLabel("Protocol"); |
2 | 165 |
JComboBox protocol = new JComboBox(); |
166 |
protocol.addItem("SMTP"); |
|
167 |
protocol.addItem("IMAP"); |
|
168 |
protocol.addItem("Other..."); |
|
169 |
protoPanel.add(protoLabel); |
|
170 |
protoPanel.add(protocol); |
|
171 |
||
172 |
JPanel attachmentPanel = new JPanel(); |
|
8961 | 173 |
JLabel attachmentLabel = new JLabel("Attachments"); |
2 | 174 |
JComboBox 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); |
|
181 |
||
182 |
JCheckBox autoConn = new JCheckBox("Auto Connect"); |
|
183 |
JCheckBox compress = new JCheckBox("Use Compression"); |
|
8961 | 184 |
autoConn.setSelected(true); |
2 | 185 |
|
186 |
connectPanel.add(protoPanel); |
|
187 |
connectPanel.add(attachmentPanel); |
|
188 |
connectPanel.add(autoConn); |
|
189 |
connectPanel.add(compress); |
|
190 |
return connectPanel; |
|
191 |
} |
|
192 |
||
193 |
protected void centerDialog() { |
|
194 |
Dimension screenSize = this.getToolkit().getScreenSize(); |
|
195 |
Dimension size = this.getSize(); |
|
8961 | 196 |
screenSize.height = screenSize.height / 2; |
197 |
screenSize.width = screenSize.width / 2; |
|
198 |
size.height = size.height / 2; |
|
199 |
size.width = size.width / 2; |
|
2 | 200 |
int y = screenSize.height - size.height; |
201 |
int x = screenSize.width - size.width; |
|
8961 | 202 |
this.setLocation(x, y); |
2 | 203 |
} |
204 |
||
205 |
public void CancelPressed() { |
|
206 |
this.setVisible(false); |
|
207 |
} |
|
208 |
||
209 |
public void OKPressed() { |
|
210 |
this.setVisible(false); |
|
211 |
} |
|
8961 | 212 |
} |
2 | 213 |
|
214 |
||
215 |
class ColumnLayout implements LayoutManager { |
|
216 |
||
8961 | 217 |
int xInset = 5; |
218 |
int yInset = 5; |
|
219 |
int yGap = 2; |
|
2 | 220 |
|
8961 | 221 |
public void addLayoutComponent(String s, Component c) { |
222 |
} |
|
2 | 223 |
|
8961 | 224 |
public void layoutContainer(Container c) { |
225 |
Insets insets = c.getInsets(); |
|
226 |
int height = yInset + insets.top; |
|
2 | 227 |
|
8961 | 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; |
|
235 |
} |
|
2 | 236 |
|
8961 | 237 |
} |
2 | 238 |
|
8961 | 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; |
|
2 | 243 |
|
8961 | 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 |
|
250 |
* 2); |
|
251 |
} |
|
252 |
height += insets.bottom; |
|
253 |
return new Dimension(width, height); |
|
254 |
} |
|
2 | 255 |
|
8961 | 256 |
public Dimension preferredLayoutSize(Container c) { |
257 |
return minimumLayoutSize(c); |
|
258 |
} |
|
2 | 259 |
|
8961 | 260 |
public void removeLayoutComponent(Component c) { |
261 |
} |
|
2 | 262 |
} |