20 package net.sf.gridarta.gui.dialog.prefs;
22 import java.awt.Component;
23 import java.awt.GridBagLayout;
24 import java.awt.event.ItemEvent;
25 import java.awt.event.ItemListener;
26 import java.net.InetSocketAddress;
27 import java.net.Proxy;
28 import java.util.EnumSet;
29 import java.util.prefs.Preferences;
30 import javax.swing.Box;
31 import javax.swing.JComboBox;
32 import javax.swing.JComponent;
33 import javax.swing.JPanel;
34 import javax.swing.JSpinner;
35 import javax.swing.JTextField;
36 import javax.swing.SpinnerNumberModel;
37 import javax.swing.border.Border;
38 import javax.swing.border.CompoundBorder;
39 import javax.swing.border.TitledBorder;
40 import javax.swing.text.JTextComponent;
44 import net.
sf.japi.swing.action.ActionBuilder;
45 import net.
sf.japi.swing.action.ActionBuilderFactory;
46 import net.
sf.japi.swing.prefs.AbstractPrefs;
47 import org.jetbrains.annotations.NotNull;
83 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
101 private final JTextComponent
proxyHost =
new JTextField(PREFERENCES.get(NET_PREFERENCES_KEY_HOST,
""));
107 private final JSpinner
proxyPort =
new JSpinner(
new SpinnerNumberModel(PREFERENCES.getInt(NET_PREFERENCES_KEY_PORT, 3128), 1, 65535, 1));
114 setListLabelIcon(ACTION_BUILDER.getIcon(
"prefsNet.icon"));
118 add(Box.createVerticalGlue());
134 return !(
proxyType.getSelectedItem() == Proxy.Type.valueOf(PREFERENCES.get(NET_PREFERENCES_KEY_TYPE,
"DIRECT")) && PREFERENCES.get(NET_PREFERENCES_KEY_HOST,
"").equals(proxyHost.getText()) && PREFERENCES.getInt(NET_PREFERENCES_KEY_PORT, 3128) == (Integer) proxyPort.getValue());
140 PREFERENCES.remove(NET_PREFERENCES_KEY_TYPE);
141 PREFERENCES.remove(NET_PREFERENCES_KEY_HOST);
142 PREFERENCES.remove(NET_PREFERENCES_KEY_PORT);
149 final Proxy.Type keyType = Proxy.Type.valueOf(PREFERENCES.get(NET_PREFERENCES_KEY_TYPE,
"DIRECT"));
150 proxyType.setSelectedIndex(keyType.ordinal());
151 final boolean enableProxy = keyType != Proxy.Type.DIRECT;
152 proxyHost.setEnabled(enableProxy);
153 proxyPort.setEnabled(enableProxy);
154 proxyHost.setText(PREFERENCES.get(NET_PREFERENCES_KEY_HOST,
""));
155 proxyPort.setValue(PREFERENCES.getInt(NET_PREFERENCES_KEY_PORT, 3128));
161 @SuppressWarnings(
"unchecked")
final Enum<Proxy.Type> typeEnum = (Enum<Proxy.Type>)
proxyType.getSelectedItem();
162 PREFERENCES.put(NET_PREFERENCES_KEY_TYPE, typeEnum.name());
163 PREFERENCES.put(NET_PREFERENCES_KEY_HOST, proxyHost.getText());
164 PREFERENCES.putInt(NET_PREFERENCES_KEY_PORT, (Integer) proxyPort.getValue());
173 final JComponent panel =
new JPanel(
new GridBagLayout());
189 return new JComboBox<>(EnumSet.allOf(Proxy.Type.class).toArray(
new Proxy.Type[0]));
198 final Proxy.Type
proxyType = Proxy.Type.valueOf(PREFERENCES.get(NET_PREFERENCES_KEY_TYPE,
"DIRECT"));
200 return Proxy.NO_PROXY;
202 return new Proxy(
proxyType,
new InetSocketAddress(PREFERENCES.get(NET_PREFERENCES_KEY_HOST,
"proxy"), PREFERENCES.getInt(NET_PREFERENCES_KEY_PORT, 3128)));
207 final Proxy.Type proxyTypeSelection = (Proxy.Type)
proxyType.getSelectedItem();
208 final boolean enableProxy = proxyTypeSelection != Proxy.Type.DIRECT;
209 proxyHost.setEnabled(enableProxy);
210 proxyPort.setEnabled(enableProxy);
static final long serialVersionUID
The serial version UID.
static Proxy getProxy()
Returns the currently preferred proxy.
Graphical User Interface of Gridarta.
static final ActionBuilder ACTION_BUILDER
Action Builder.
static JComboBox< Proxy.Type > createProxyType()
Creates the JComboBox for selecting the proxy type.
static final String NET_PREFERENCES_KEY_HOST
The preferences key for the type.
void itemStateChanged(@NotNull final ItemEvent e)
void addComponent(@NotNull final Component component)
Adds a component to the container.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Base package of all Gridarta classes.
Interface used as preferences location.
Preferences Module for networking preferences.
NetPreferences()
Creates a new instance.
Helper class for preference panes.
Utility class for ActionBuilder related functions.
static final Preferences PREFERENCES
Preferences.
Component createNetPanel()
Creates the sub-panel with the external applications.
Border DIALOG_BORDER
The Border object to be used when creating dialogs.
static final String NET_PREFERENCES_KEY_PORT
The preferences key for the type.
static final String NET_PREFERENCES_KEY_TYPE
The preferences key for the type.
static Border createTitledBorder(@NotNull final String titleKey)
Creates a titled border.
final JComboBox< Proxy.Type > proxyType
JComboBox for selecting the proxy type.
final JTextComponent proxyHost
TextField for server executable.
final JSpinner proxyPort
TextField for client executable.
Defines common UI constants used in different dialogs.