1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
/* TemporaryInternetFilesPanel.java -- Display and sets cache settings.
Copyright (C) 2010 Red Hat
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package net.sourceforge.jnlp.controlpanel;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import net.sourceforge.jnlp.config.DeploymentConfiguration;
import net.sourceforge.jnlp.runtime.Translator;
/**
* The actual panel that contains the fields that the user can edit accordingly.
* This is provided as a pane for inside the Panel itself, can also be used to
* display as a dialog.
* TODO: Add functionality:
*
* @author Andrew Su (asu@redhat.com, andrew.su@utoronto.ca)
*
*/
@SuppressWarnings("serial")
public class TemporaryInternetFilesPanel extends NamedBorderPanel implements ChangeListener {
private DeploymentConfiguration config;
private int minSize = -1;
private int maxSize = 1000;
/** List of properties used by this panel */
public static String[] properties = { "deployment.javapi.cache.enabled", // false == enabled
"deployment.user.cachedir",
"deployment.cache.max.size", // Specified in MB
"deployment.cache.jarcompression", // Allows values 0-9
};
private JComponent defaultFocusComponent = null;
JSpinner spCacheSize;
JSlider slCacheSize;
public TemporaryInternetFilesPanel(DeploymentConfiguration config) {
super(Translator.R("CPHeadTempInternetFiles"));
this.config = config;
setLayout(new BorderLayout());
addComponents();
}
/**
* Add components to panel.
*/
private void addComponents() {
JPanel topPanel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
JLabel description = new JLabel("<html>" + Translator.R("CPTempInternetFilesDescription") + "<hr /></html>");
JCheckBox enableCaching = new JCheckBox(Translator.R("TIFPEnableCache"), !Boolean.parseBoolean(this.config.getProperty(properties[0])));
enableCaching.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
config.setProperty(properties[0], String.valueOf(!(e.getStateChange() == ItemEvent.SELECTED)));
}
});
// This displays the option for changing location of cache
// User can NOT edit the text field must do it through dialog.
JPanel locationPanel = new NamedBorderPanel(Translator.R("TIFPLocation"), new GridBagLayout());
JLabel locationDescription = new JLabel(Translator.R("TIFPLocationLabel") + ":");
final JTextField location = new JTextField(this.config.getProperty(properties[1]));
location.setEditable(false); // Can not c&p into the location field.
JButton bLocation = new JButton(Translator.R("TIFPChange") + "...");
bLocation.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
String result = fileChooser.getSelectedFile().getAbsolutePath();
location.setText(result);
config.setProperty(properties[1], result);
}
}
});
c.weightx = 1;
c.gridwidth = GridBagConstraints.REMAINDER;
c.gridx = 0;
c.gridy = 0;
locationPanel.add(locationDescription, c);
c.gridwidth = 1;
c.gridy = 1;
locationPanel.add(location, c);
c.gridx = 1;
c.weightx = 0;
locationPanel.add(bLocation, c);
// This section deals with how to use the disk space.
JPanel diskSpacePanel = new NamedBorderPanel(Translator.R("TIFPDiskSpace"), new GridBagLayout());
JLabel lCompression = new JLabel(Translator.R("TIFPCompressionLevel")); // Sets compression level for jar files.
ComboItem[] compressionOptions = { new ComboItem(Translator.R("TIFPNone"), "0"),
new ComboItem("1", "1"),
new ComboItem("2", "2"),
new ComboItem("3", "3"),
new ComboItem("4", "4"),
new ComboItem("5", "5"),
new ComboItem("6", "6"),
new ComboItem("7", "7"),
new ComboItem("8", "8"),
new ComboItem(Translator.R("TIFPMax"), "9"), };
JComboBox cbCompression = new JComboBox(compressionOptions);
cbCompression.setSelectedIndex(Integer.parseInt(this.config.getProperty(properties[3])));
cbCompression.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
config.setProperty(properties[3], ((ComboItem) e.getItem()).getValue());
}
});
// This is to work with how much space is available for caching.
JLabel lCacheSize = new JLabel(Translator.R("TIFPCacheSize") + ":");
slCacheSize = new JSlider(minSize, maxSize, Integer.parseInt(this.config.getProperty(properties[2])));
slCacheSize.setMinorTickSpacing(50);
slCacheSize.setPaintTicks(true);
SpinnerNumberModel snmCacheSize = new SpinnerNumberModel(Integer.parseInt(this.config.getProperty(properties[2])), minSize, maxSize, 1);
spCacheSize = new JSpinner(snmCacheSize);
slCacheSize.addChangeListener(this);
spCacheSize.addChangeListener(this);
c.gridy = 0;
c.gridx = 0;
c.weightx = 1;
diskSpacePanel.add(lCompression, c);
c.gridx = 1;
c.weightx = 0;
diskSpacePanel.add(cbCompression, c);
c.gridy = 1;
c.gridx = 0;
c.gridwidth = GridBagConstraints.REMAINDER;
c.weightx = 1;
diskSpacePanel.add(lCacheSize, c);
c.gridwidth = 1;
c.gridy = 2;
diskSpacePanel.add(slCacheSize, c);
c.gridx = 1;
diskSpacePanel.add(spCacheSize, c);
JPanel buttonDeleteRestore = new JPanel(new FlowLayout(FlowLayout.TRAILING));
JButton bViewFiles = new JButton(Translator.R("TIFPViewFiles"));
bViewFiles.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CacheViewer.showCacheDialog(config);
}
});
buttonDeleteRestore.add(bViewFiles);
c.weighty = 0;
c.gridx = 0;
c.gridy = 0;
topPanel.add(enableCaching, c);
c.gridy = 1;
topPanel.add(locationPanel, c);
c.gridy = 2;
topPanel.add(diskSpacePanel, c);
c.weighty = 1;
c.gridy = 3;
topPanel.add(buttonDeleteRestore, c);
add(description, BorderLayout.NORTH);
add(topPanel, BorderLayout.CENTER);
}
/**
* Give focus to the default button.
*/
public void focusOnDefaultButton() {
if (defaultFocusComponent != null) {
defaultFocusComponent.requestFocusInWindow();
}
}
@Override
public void stateChanged(ChangeEvent e) {
Object o = e.getSource();
if (o instanceof JSlider)
spCacheSize.setValue(((JSlider) o).getValue());
else if (o instanceof JSpinner)
slCacheSize.setValue((Integer) ((JSpinner) o).getValue());
config.setProperty(properties[2], spCacheSize.getValue().toString());
}
}
|