1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package us.paulevans.basicxslt; |
17 | |
|
18 | |
import java.awt.BorderLayout; |
19 | |
import java.awt.Color; |
20 | |
import java.awt.Cursor; |
21 | |
import java.awt.FlowLayout; |
22 | |
import java.awt.Font; |
23 | |
import java.awt.GridBagConstraints; |
24 | |
import java.awt.GridBagLayout; |
25 | |
import java.awt.event.ActionEvent; |
26 | |
import java.awt.event.ActionListener; |
27 | |
import java.awt.event.WindowAdapter; |
28 | |
import java.awt.event.WindowEvent; |
29 | |
|
30 | |
import javax.swing.JButton; |
31 | |
import javax.swing.JCheckBox; |
32 | |
import javax.swing.JComboBox; |
33 | |
import javax.swing.JFrame; |
34 | |
import javax.swing.JLabel; |
35 | |
import javax.swing.JPanel; |
36 | |
import javax.swing.JScrollPane; |
37 | |
import javax.swing.JSeparator; |
38 | |
|
39 | |
import net.blueslate.commons.gui.GUIUtils; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public class LoadConfigurationFrame extends JFrame implements ActionListener { |
47 | |
|
48 | |
|
49 | |
private static final int FRAME_WIDTH = 485; |
50 | |
private static final int FRAME_HEIGHT = 185; |
51 | |
|
52 | |
|
53 | 0 | private static final LabelStringFactory stringFactory = |
54 | |
LabelStringFactory.getInstance(); |
55 | |
|
56 | |
private JButton cancelBtn, okayBtn; |
57 | |
private UserPreferences userPrefs; |
58 | |
private BasicXSLTFrame parent; |
59 | |
private JComboBox configurations; |
60 | |
private JCheckBox makeDefault; |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
public LoadConfigurationFrame(BasicXSLTFrame aParent, |
69 | 0 | String aCurrentConfiguration, String aAllConfigurations[]) { |
70 | |
|
71 | |
JPanel southPanel, mainPanel; |
72 | |
|
73 | 0 | parent = aParent; |
74 | 0 | userPrefs = Utils.getUserPrefs(); |
75 | 0 | addWindowListener(new WindowAdapter() { |
76 | 0 | public void windowClosing(WindowEvent aEvt) { |
77 | 0 | dispose(); |
78 | 0 | } |
79 | |
}); |
80 | 0 | mainPanel = new JPanel(new BorderLayout()); |
81 | 0 | mainPanel.add(buildMainPanel(aAllConfigurations), BorderLayout.CENTER); |
82 | 0 | southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); |
83 | 0 | southPanel.add(okayBtn = new JButton(stringFactory.getString( |
84 | |
LabelStringFactory.OK_BUTTON))); |
85 | 0 | southPanel.add(cancelBtn = new JButton(stringFactory.getString( |
86 | |
LabelStringFactory.CANCEL_BUTTON))); |
87 | 0 | okayBtn.addActionListener(this); |
88 | 0 | cancelBtn.addActionListener(this); |
89 | 0 | getContentPane().setLayout(new BorderLayout()); |
90 | 0 | getContentPane().add(buildNorthPanel(), BorderLayout.NORTH); |
91 | 0 | getContentPane().add(southPanel, BorderLayout.SOUTH); |
92 | 0 | getContentPane().add(new JScrollPane(mainPanel), BorderLayout.CENTER); |
93 | 0 | setTitle(stringFactory.getString( |
94 | |
LabelStringFactory.LOADCONFIG_FRAME_LOAD_CONFIGURATION)); |
95 | 0 | setSize(FRAME_WIDTH, FRAME_HEIGHT); |
96 | 0 | GUIUtils.center(this, aParent); |
97 | 0 | setVisible(true); |
98 | 0 | } |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
private JPanel buildNorthPanel() { |
105 | |
|
106 | |
GridBagLayout layout; |
107 | |
GridBagConstraints constraints; |
108 | |
JPanel panel; |
109 | |
int row, col; |
110 | |
JLabel headerLabel; |
111 | |
|
112 | 0 | layout = new GridBagLayout(); |
113 | 0 | constraints = new GridBagConstraints(); |
114 | 0 | panel = new JPanel(layout); |
115 | 0 | row = 0; |
116 | 0 | col = 0; |
117 | 0 | headerLabel = new JLabel(stringFactory.getString( |
118 | |
LabelStringFactory.LOADCONFIG_FRAME_LOAD_CONFIGURATION)); |
119 | 0 | headerLabel.setFont(new Font("arial", Font.PLAIN, 18)); |
120 | 0 | GUIUtils.add(panel, headerLabel, layout, constraints, row++, col, |
121 | |
1, 1, 1, 1, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH, |
122 | |
GUIUtils.MED_LARGE_INSETS); |
123 | 0 | return panel; |
124 | |
} |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
private JPanel buildMainPanel(String aAllConfigurations[]) { |
132 | |
|
133 | |
int row; |
134 | |
JLabel label; |
135 | |
GridBagLayout layout; |
136 | |
GridBagConstraints constraints; |
137 | |
JPanel main; |
138 | |
|
139 | 0 | layout = new GridBagLayout(); |
140 | 0 | constraints = new GridBagConstraints(); |
141 | 0 | main = new JPanel(layout); |
142 | 0 | row = 0; |
143 | 0 | GUIUtils.add(main, new JLabel(stringFactory.getString( |
144 | |
LabelStringFactory.LOADCONFIG_FRAME_LOAD_CONFIGURATION)), |
145 | |
layout, constraints, row, 0, 1, 1, GridBagConstraints.EAST, |
146 | |
GridBagConstraints.NONE, GUIUtils.MED_INSETS); |
147 | 0 | GUIUtils.add(main, label = new JLabel(userPrefs.getConfiguration()), |
148 | |
layout, constraints, row++, 1, 1, 1, GridBagConstraints.WEST, |
149 | |
GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); |
150 | 0 | label.setForeground(Color.BLUE); |
151 | 0 | GUIUtils.add(main, new JSeparator(), layout, constraints, row++, 0, 1, |
152 | |
2, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, |
153 | |
GUIUtils.MED_INSETS); |
154 | 0 | GUIUtils.add(main, new JLabel(stringFactory.getString( |
155 | |
LabelStringFactory.LOADCONFIG_FRAME_CONFIGURATION)), layout, |
156 | |
constraints, row, 0, 1, 1, GridBagConstraints.EAST, |
157 | |
GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); |
158 | 0 | GUIUtils.add(main, configurations = new JComboBox(aAllConfigurations), |
159 | |
layout, constraints, row++, 1, 1, 1, GridBagConstraints.WEST, |
160 | |
GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); |
161 | 0 | GUIUtils.add(main, new JLabel(stringFactory.getString( |
162 | |
LabelStringFactory.LOADCONFIG_FRAME_MAKE_DEFAULT)), layout, |
163 | |
constraints, row, 0, 1, 1, GridBagConstraints.EAST, |
164 | |
GridBagConstraints.NONE, GUIUtils.MED_INSETS); |
165 | 0 | GUIUtils.add(main, makeDefault = new JCheckBox(), layout, constraints, |
166 | |
row++, 1, 1, 1, GridBagConstraints.WEST, |
167 | |
GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); |
168 | 0 | return main; |
169 | |
} |
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
public void actionPerformed(ActionEvent aEvent) { |
175 | |
|
176 | |
Object eventSource; |
177 | |
|
178 | 0 | eventSource = aEvent.getSource(); |
179 | 0 | setCursor(new Cursor(Cursor.WAIT_CURSOR)); |
180 | 0 | if (eventSource == cancelBtn) { |
181 | 0 | dispose(); |
182 | 0 | } else if (eventSource == okayBtn) { |
183 | 0 | userPrefs.setConfiguration((String)configurations.getSelectedItem(), |
184 | |
makeDefault.isSelected()); |
185 | 0 | parent.refreshApplication(); |
186 | 0 | dispose(); |
187 | |
} |
188 | 0 | setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
189 | 0 | } |
190 | |
} |
191 | |
|