add src files decompiled via jad
[rsa2client.git] / src / mcsClient / Options.java
1 // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
2 // Jad home page: http://www.kpdus.com/jad.html
3 // Decompiler options: packimports(3) fieldsfirst nonlb space 
4
5 package mcsClient;
6
7 import java.awt.*;
8 import java.awt.event.*;
9 import java.io.*;
10 import java.util.ArrayList;
11 import javax.swing.*;
12
13 // Referenced classes of package mcsClient:
14 //            DefaultKeyArray, SavedSettings, Row, ComboKeyArray, 
15 //            KeyData, McsKeyAdapter, McsToolBar, DatagramReader
16
17 public final class Options extends JFrame
18     implements KeyListener, ActionListener {
19
20     public static final int MAX_BUTTONS = 12;
21     public static final int MAX_KEYS = 4;
22     public static final int EXPECTED_PREFS_VER = 1;
23     public static final int EXPECTED_COMBO_KEYS_VER = 1;
24     protected static final String EMPTY = "";
25     protected static final String CLEAR = "Clear";
26     private static final String KEY_FILE_NAME = "keys.dat";
27     private static final String PREFS_FILE_NAME = "prefs.dat";
28     private static final String RESTORE = "Restore Defaults";
29     private static final String CANCEL = "Cancel Changes";
30     private static final String SAVE = "Save Buttons";
31     private final DefaultKeyArray defaultKeys = new DefaultKeyArray();
32     private Row row[];
33     private JButton restore;
34     private JButton cancel;
35     private JButton save;
36     private String hostName;
37     private McsKeyAdapter keyAdapter;
38     private McsToolBar toolBar;
39     private McsToolBar countryKeyBar;
40     private JComboBox kbSelector;
41     private static final String KEYBOARDS[] = {
42         "US 104-key keyboard", "Belgian 105-key keyboard", "French 105-key keyboard", "German 105-key keyboard", "Italian 105-key keyboard (142)", "Japanese 109-key keyboard", "Spanish 105-key keyboard", "UK 105-key keyboard"
43     };
44     private JComboBox mouseSyncKey;
45     private static final String SYNC_KEYS[] = {
46         "None", "Escape", "Alt", "Right Mouse Button"
47     };
48     public static final String NO_KEY_SET = SYNC_KEYS[0];
49     public static final String RIGHT_MOUSE = SYNC_KEYS[3];
50     private SavedSettings savedSettings;
51
52     public Options(String s, McsKeyAdapter mcskeyadapter, DatagramReader datagramreader, McsToolBar mcstoolbar, McsToolBar mcstoolbar1) {
53         restore = new JButton("Restore Defaults");
54         cancel = new JButton("Cancel Changes");
55         save = new JButton("Save Buttons");
56         hostName = s;
57         keyAdapter = mcskeyadapter;
58         toolBar = mcstoolbar;
59         countryKeyBar = mcstoolbar1;
60         restore.addActionListener(this);
61         restore.addKeyListener(this);
62         cancel.addActionListener(this);
63         cancel.addKeyListener(this);
64         save.addActionListener(this);
65         save.addKeyListener(this);
66         restore.setToolTipText("Restore buttons to factory default settings.");
67         cancel.setToolTipText("Cancel changes made to button settings.");
68         save.setToolTipText("Save changes made to button settings.");
69         setTitle("Remote Console Preferences");
70         setDefaultCloseOperation(1);
71         setResizable(false);
72         try {
73             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
74         }
75         catch (Exception exception) { }
76         try {
77             savedSettings = (SavedSettings)getSerializedObject("prefs.dat");
78         }
79         catch (Exception exception1) {
80             savedSettings = new SavedSettings();
81         }
82         JPanel jpanel = new JPanel();
83         jpanel.setLayout(new GridBagLayout());
84         jpanel.setBackground(getBackground());
85         GridBagConstraints gridbagconstraints = new GridBagConstraints();
86         gridbagconstraints.fill = 0;
87         gridbagconstraints.anchor = 10;
88         gridbagconstraints.weightx = 1.0D;
89         gridbagconstraints.weighty = 1.0D;
90         gridbagconstraints.insets = new Insets(20, 20, 20, 20);
91         JTextArea jtextarea = new JTextArea("You can create key buttons to represent common key combinations or keys that would\nbe trapped by your computer.  Create and customize the remote console key buttons\nby typing a key into each box below.  Click on Save Buttons when you are finished, and \nthe customized buttons will appear on your console control bar.\n\nSimulate the Print Screen key by pressing and holding the 'P' key for 3 seconds.");
92         jtextarea.setBackground(getBackground());
93         jtextarea.setEditable(false);
94         jtextarea.setFont(new Font("Sans Serif", 0, 12));
95         add(jtextarea, jpanel, gridbagconstraints, 0, 0, 10, 4);
96         gridbagconstraints.insets = new Insets(0, 0, 0, 0);
97         JPanel jpanel1 = new JPanel();
98         row = new Row[12];
99         for (int i = 0; i < 12; i++) {
100             row[i] = new Row(i + 1, this);
101             jpanel1.add(row[i]);
102         }
103
104         jpanel1.setPreferredSize(new Dimension((int)row[1].getPreferredSize().getWidth(), 12 * ((int)row[1].getPreferredSize().getHeight() + 10)));
105         JScrollPane jscrollpane = new JScrollPane(jpanel1);
106         jscrollpane.setPreferredSize(new Dimension((int)row[1].getPreferredSize().getWidth() + 30, 300));
107         add(jscrollpane, jpanel, gridbagconstraints, 0, 10, 10, 1);
108         jscrollpane.validate();
109         jpanel1.validate();
110         gridbagconstraints.anchor = 17;
111         gridbagconstraints.insets = new Insets(14, 20, 8, 0);
112         add(restore, jpanel, gridbagconstraints, 0, 22, 1, 1);
113         gridbagconstraints.anchor = 10;
114         gridbagconstraints.insets = new Insets(14, 0, 8, 0);
115         add(cancel, jpanel, gridbagconstraints, 4, 22, 1, 1);
116         gridbagconstraints.anchor = 13;
117         gridbagconstraints.insets = new Insets(14, 0, 8, 20);
118         add(save, jpanel, gridbagconstraints, 8, 22, 1, 1);
119         try {
120             ComboKeyArray combokeyarray = (ComboKeyArray)getSerializedObject("keys.dat");
121             if (combokeyarray.getVersion() != 1)
122                 throw new IOException("Old version of ComboKeyArray found.");
123             loadButtonArray(combokeyarray);
124         }
125         catch (ClassNotFoundException classnotfoundexception) {
126             System.out.println(classnotfoundexception);
127         }
128         catch (IOException ioexception) {
129             loadButtonArray(defaultKeys);
130         }
131         saveButtonClicked();
132         JTabbedPane jtabbedpane = new JTabbedPane();
133         jtabbedpane.setBackground(getBackground());
134         getContentPane().setLayout(new FlowLayout(0, 1, 5));
135         getContentPane().add(jtabbedpane);
136         jtabbedpane.addTab("Key Buttons", jpanel);
137         gridbagconstraints.insets = new Insets(20, 20, 0, 20);
138         gridbagconstraints.anchor = 11;
139         JPanel jpanel2 = new JPanel();
140         jpanel2.setLayout(new GridBagLayout());
141         jpanel2.setBackground(getBackground());
142         JTextArea jtextarea1 = new JTextArea("The keyboard selector enables you to select the keyboard type that will be emulated.");
143         jtextarea1.setBackground(getBackground());
144         jtextarea1.setEditable(false);
145         jtextarea1.setFont(new Font("Sans Serif", 0, 12));
146         add(jtextarea1, jpanel2, gridbagconstraints, 0, 0, 20, 8);
147         kbSelector = new JComboBox(KEYBOARDS);
148         kbSelector.setToolTipText("Keyboard type selector");
149         kbSelector.addActionListener(new ActionListener() {
150
151             public void actionPerformed(ActionEvent actionevent) {
152                 String s1 = (String)kbSelector.getSelectedItem();
153                 for (int j = 0; j < Options.KEYBOARDS.length; j++) {
154                     if (!s1.equals(Options.KEYBOARDS[j]))
155                         continue;
156                     countryKeyBar.populateCountryKeyBar(j);
157                     keyAdapter.setKeyboardType(j);
158                     System.out.println("Keyboard selected: " + j);
159                     try {
160                         savedSettings.setKeyboardNum(j);
161                         saveSerializedObject("prefs.dat", savedSettings);
162                     }
163                     catch (IOException ioexception1) {
164                         System.out.println("Could not save keyboard number.");
165                     }
166                     break;
167                 }
168
169             }
170
171         }
172 );
173         JPanel jpanel3 = new JPanel();
174         javax.swing.border.TitledBorder titledborder = BorderFactory.createTitledBorder("Keyboard Type");
175         jpanel3.setBorder(titledborder);
176         jpanel3.setBackground(getBackground());
177         jpanel3.add(kbSelector);
178         add(jpanel3, jpanel2, gridbagconstraints, 10, 8, 1, 1);
179         jtabbedpane.addTab("Keyboard Type", jpanel2);
180         JPanel jpanel4 = new JPanel();
181         jpanel4.setLayout(new GridBagLayout());
182         jpanel4.setBackground(getBackground());
183         JTextArea jtextarea2 = new JTextArea("The mouse sync selector enables you to designate the key or mouse button to use\nin order to align the client and server mouse cursors with each other.  When you\nneed to synchronize the cursors, hold down the designated key or mouse button and\nmove the client mouse until the cursors are aligned.  The server's mouse cursor\nwill not move while the designated key or button is held down.\n\nNote that using the mouse sync key or button may have the effect of making it\nimpossible to reach regions of the console with your mouse if a large correction is\nrequired.  If necessary, close the Remote Control window and restart to realign the\ncursors.");
184         jtextarea2.setBackground(getBackground());
185         jtextarea2.setEditable(false);
186         jtextarea2.setFont(new Font("Sans Serif", 0, 12));
187         add(jtextarea2, jpanel4, gridbagconstraints, 0, 0, 20, 8);
188         keyAdapter.setMouseSyncKey(SYNC_KEYS[0]);
189         mouseSyncKey = new JComboBox(SYNC_KEYS);
190         mouseSyncKey.setToolTipText("Mouse synchronization key or button");
191         mouseSyncKey.addActionListener(new ActionListener() {
192
193             public void actionPerformed(ActionEvent actionevent) {
194                 keyAdapter.setMouseSyncKey((String)mouseSyncKey.getSelectedItem());
195                 try {
196                     savedSettings.setMouseSyncKeyNum(mouseSyncKey.getSelectedIndex());
197                     saveSerializedObject("prefs.dat", savedSettings);
198                 }
199                 catch (IOException ioexception1) {
200                     System.out.println("Could not save mouse sync key number.");
201                 }
202             }
203
204         }
205 );
206         JPanel jpanel5 = new JPanel();
207         javax.swing.border.TitledBorder titledborder1 = BorderFactory.createTitledBorder("Mouse Sync");
208         jpanel5.setBorder(titledborder1);
209         jpanel5.setBackground(getBackground());
210         jpanel5.add(mouseSyncKey);
211         add(jpanel5, jpanel4, gridbagconstraints, 10, 8, 1, 1);
212         jtabbedpane.addTab("Mouse Sync", jpanel4);
213         if (savedSettings.getVersion() == 1) {
214             kbSelector.setSelectedIndex(savedSettings.getKeyboardNum());
215             mouseSyncKey.setSelectedIndex(savedSettings.getMouseSyncKeyNum());
216         }
217         pack();
218     }
219
220     public void actionPerformed(ActionEvent actionevent) {
221         if (actionevent.getSource() == restore)
222             loadButtonArray(defaultKeys);
223         else
224         if (actionevent.getSource() == cancel)
225             try {
226                 loadButtonArray((ComboKeyArray)getSerializedObject("keys.dat"));
227             }
228             catch (ClassNotFoundException classnotfoundexception) {
229                 System.out.println(classnotfoundexception);
230             }
231             catch (IOException ioexception) {
232                 loadButtonArray(defaultKeys);
233             }
234         else
235         if (actionevent.getSource() == save)
236             saveButtonClicked();
237     }
238
239     public void keyPressed(KeyEvent keyevent) {
240         if (keyevent.getKeyCode() != 10)
241             return;
242         if (keyevent.getSource() == restore)
243             loadButtonArray(defaultKeys);
244         else
245         if (keyevent.getSource() == cancel)
246             try {
247                 loadButtonArray((ComboKeyArray)getSerializedObject("keys.dat"));
248             }
249             catch (ClassNotFoundException classnotfoundexception) {
250                 System.out.println(classnotfoundexception);
251             }
252             catch (IOException ioexception) {
253                 loadButtonArray(defaultKeys);
254             }
255         else
256         if (keyevent.getSource() == save)
257             saveButtonClicked();
258     }
259
260     public void keyTyped(KeyEvent keyevent) {
261         keyevent.consume();
262     }
263
264     public void keyReleased(KeyEvent keyevent) {
265     }
266
267     protected void getFocusOnSaveButton() {
268         save.requestFocus();
269     }
270
271     private void add(Component component, JPanel jpanel, GridBagConstraints gridbagconstraints, int i, int j, int k, int l) {
272         gridbagconstraints.gridx = i;
273         gridbagconstraints.gridy = j;
274         gridbagconstraints.gridwidth = k;
275         gridbagconstraints.gridheight = l;
276         jpanel.add(component, gridbagconstraints);
277     }
278
279     private void saveButtonClicked() {
280         ComboKeyArray combokeyarray = new ComboKeyArray();
281         for (int i = 0; i < 12; i++)
282             if (row[i].isValid()) {
283                 ArrayList arraylist = new ArrayList();
284                 for (int j = 0; j < 4; j++) {
285                     String s = row[i].keyField[j].getText();
286                     if (!s.equals("")) {
287                         KeyData keydata = new KeyData(s, row[i].usageCode[j]);
288                         arraylist.add(keydata);
289                     }
290                 }
291
292                 combokeyarray.setKeysForButton(i, arraylist);
293             }
294
295         try {
296             saveSerializedObject("keys.dat", combokeyarray);
297         }
298         catch (IOException ioexception) {
299             System.out.println(ioexception);
300         }
301         toolBar.buildCustomizedButtonBar(combokeyarray);
302     }
303
304     private void loadButtonArray(ComboKeyArray combokeyarray) {
305         for (int i = 0; i < 12; i++) {
306             row[i].setValid(false);
307             ArrayList arraylist = combokeyarray.getKeysForButton(i);
308             for (int j = 0; j < 4; j++) {
309                 KeyData keydata;
310                 if (arraylist != null && j < arraylist.size()) {
311                     keydata = (KeyData)arraylist.get(j);
312                     row[i].setValid(true);
313                 } else {
314                     keydata = new KeyData("", 0);
315                 }
316                 row[i].keyField[j].setText(keydata.getKeyName());
317                 row[i].usageCode[j] = keydata.getUsageCode();
318             }
319
320         }
321
322     }
323
324     private Object getSerializedObject(String s) throws ClassNotFoundException, IOException {
325         File file = new File(System.getProperty("user.home"), "IBM");
326         File file1 = new File(file, hostName);
327         File file2 = new File(file1, s);
328         FileInputStream fileinputstream = new FileInputStream(file2);
329         ObjectInputStream objectinputstream = new ObjectInputStream(fileinputstream);
330         Object obj = objectinputstream.readObject();
331         objectinputstream.close();
332         return obj;
333     }
334
335     private void saveSerializedObject(String s, Object obj) throws IOException {
336         File file = new File(System.getProperty("user.home"), "IBM");
337         file.mkdir();
338         File file1 = new File(file, hostName);
339         file1.mkdir();
340         File file2 = new File(file1, s);
341         FileOutputStream fileoutputstream = new FileOutputStream(file2);
342         ObjectOutputStream objectoutputstream = new ObjectOutputStream(fileoutputstream);
343         objectoutputstream.writeObject(obj);
344         objectoutputstream.flush();
345         objectoutputstream.close();
346     }
347
348
349
350
351
352
353
354
355 }