add src files decompiled via jad
[rsa2client.git] / src / mcsClient / Options.java
diff --git a/src/mcsClient/Options.java b/src/mcsClient/Options.java
new file mode 100644 (file)
index 0000000..54b9d8a
--- /dev/null
@@ -0,0 +1,355 @@
+// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
+// Jad home page: http://www.kpdus.com/jad.html
+// Decompiler options: packimports(3) fieldsfirst nonlb space 
+
+package mcsClient;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.io.*;
+import java.util.ArrayList;
+import javax.swing.*;
+
+// Referenced classes of package mcsClient:
+//            DefaultKeyArray, SavedSettings, Row, ComboKeyArray, 
+//            KeyData, McsKeyAdapter, McsToolBar, DatagramReader
+
+public final class Options extends JFrame
+    implements KeyListener, ActionListener {
+
+    public static final int MAX_BUTTONS = 12;
+    public static final int MAX_KEYS = 4;
+    public static final int EXPECTED_PREFS_VER = 1;
+    public static final int EXPECTED_COMBO_KEYS_VER = 1;
+    protected static final String EMPTY = "";
+    protected static final String CLEAR = "Clear";
+    private static final String KEY_FILE_NAME = "keys.dat";
+    private static final String PREFS_FILE_NAME = "prefs.dat";
+    private static final String RESTORE = "Restore Defaults";
+    private static final String CANCEL = "Cancel Changes";
+    private static final String SAVE = "Save Buttons";
+    private final DefaultKeyArray defaultKeys = new DefaultKeyArray();
+    private Row row[];
+    private JButton restore;
+    private JButton cancel;
+    private JButton save;
+    private String hostName;
+    private McsKeyAdapter keyAdapter;
+    private McsToolBar toolBar;
+    private McsToolBar countryKeyBar;
+    private JComboBox kbSelector;
+    private static final String KEYBOARDS[] = {
+        "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"
+    };
+    private JComboBox mouseSyncKey;
+    private static final String SYNC_KEYS[] = {
+        "None", "Escape", "Alt", "Right Mouse Button"
+    };
+    public static final String NO_KEY_SET = SYNC_KEYS[0];
+    public static final String RIGHT_MOUSE = SYNC_KEYS[3];
+    private SavedSettings savedSettings;
+
+    public Options(String s, McsKeyAdapter mcskeyadapter, DatagramReader datagramreader, McsToolBar mcstoolbar, McsToolBar mcstoolbar1) {
+        restore = new JButton("Restore Defaults");
+        cancel = new JButton("Cancel Changes");
+        save = new JButton("Save Buttons");
+        hostName = s;
+        keyAdapter = mcskeyadapter;
+        toolBar = mcstoolbar;
+        countryKeyBar = mcstoolbar1;
+        restore.addActionListener(this);
+        restore.addKeyListener(this);
+        cancel.addActionListener(this);
+        cancel.addKeyListener(this);
+        save.addActionListener(this);
+        save.addKeyListener(this);
+        restore.setToolTipText("Restore buttons to factory default settings.");
+        cancel.setToolTipText("Cancel changes made to button settings.");
+        save.setToolTipText("Save changes made to button settings.");
+        setTitle("Remote Console Preferences");
+        setDefaultCloseOperation(1);
+        setResizable(false);
+        try {
+            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+        }
+        catch (Exception exception) { }
+        try {
+            savedSettings = (SavedSettings)getSerializedObject("prefs.dat");
+        }
+        catch (Exception exception1) {
+            savedSettings = new SavedSettings();
+        }
+        JPanel jpanel = new JPanel();
+        jpanel.setLayout(new GridBagLayout());
+        jpanel.setBackground(getBackground());
+        GridBagConstraints gridbagconstraints = new GridBagConstraints();
+        gridbagconstraints.fill = 0;
+        gridbagconstraints.anchor = 10;
+        gridbagconstraints.weightx = 1.0D;
+        gridbagconstraints.weighty = 1.0D;
+        gridbagconstraints.insets = new Insets(20, 20, 20, 20);
+        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.");
+        jtextarea.setBackground(getBackground());
+        jtextarea.setEditable(false);
+        jtextarea.setFont(new Font("Sans Serif", 0, 12));
+        add(jtextarea, jpanel, gridbagconstraints, 0, 0, 10, 4);
+        gridbagconstraints.insets = new Insets(0, 0, 0, 0);
+        JPanel jpanel1 = new JPanel();
+        row = new Row[12];
+        for (int i = 0; i < 12; i++) {
+            row[i] = new Row(i + 1, this);
+            jpanel1.add(row[i]);
+        }
+
+        jpanel1.setPreferredSize(new Dimension((int)row[1].getPreferredSize().getWidth(), 12 * ((int)row[1].getPreferredSize().getHeight() + 10)));
+        JScrollPane jscrollpane = new JScrollPane(jpanel1);
+        jscrollpane.setPreferredSize(new Dimension((int)row[1].getPreferredSize().getWidth() + 30, 300));
+        add(jscrollpane, jpanel, gridbagconstraints, 0, 10, 10, 1);
+        jscrollpane.validate();
+        jpanel1.validate();
+        gridbagconstraints.anchor = 17;
+        gridbagconstraints.insets = new Insets(14, 20, 8, 0);
+        add(restore, jpanel, gridbagconstraints, 0, 22, 1, 1);
+        gridbagconstraints.anchor = 10;
+        gridbagconstraints.insets = new Insets(14, 0, 8, 0);
+        add(cancel, jpanel, gridbagconstraints, 4, 22, 1, 1);
+        gridbagconstraints.anchor = 13;
+        gridbagconstraints.insets = new Insets(14, 0, 8, 20);
+        add(save, jpanel, gridbagconstraints, 8, 22, 1, 1);
+        try {
+            ComboKeyArray combokeyarray = (ComboKeyArray)getSerializedObject("keys.dat");
+            if (combokeyarray.getVersion() != 1)
+                throw new IOException("Old version of ComboKeyArray found.");
+            loadButtonArray(combokeyarray);
+        }
+        catch (ClassNotFoundException classnotfoundexception) {
+            System.out.println(classnotfoundexception);
+        }
+        catch (IOException ioexception) {
+            loadButtonArray(defaultKeys);
+        }
+        saveButtonClicked();
+        JTabbedPane jtabbedpane = new JTabbedPane();
+        jtabbedpane.setBackground(getBackground());
+        getContentPane().setLayout(new FlowLayout(0, 1, 5));
+        getContentPane().add(jtabbedpane);
+        jtabbedpane.addTab("Key Buttons", jpanel);
+        gridbagconstraints.insets = new Insets(20, 20, 0, 20);
+        gridbagconstraints.anchor = 11;
+        JPanel jpanel2 = new JPanel();
+        jpanel2.setLayout(new GridBagLayout());
+        jpanel2.setBackground(getBackground());
+        JTextArea jtextarea1 = new JTextArea("The keyboard selector enables you to select the keyboard type that will be emulated.");
+        jtextarea1.setBackground(getBackground());
+        jtextarea1.setEditable(false);
+        jtextarea1.setFont(new Font("Sans Serif", 0, 12));
+        add(jtextarea1, jpanel2, gridbagconstraints, 0, 0, 20, 8);
+        kbSelector = new JComboBox(KEYBOARDS);
+        kbSelector.setToolTipText("Keyboard type selector");
+        kbSelector.addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent actionevent) {
+                String s1 = (String)kbSelector.getSelectedItem();
+                for (int j = 0; j < Options.KEYBOARDS.length; j++) {
+                    if (!s1.equals(Options.KEYBOARDS[j]))
+                        continue;
+                    countryKeyBar.populateCountryKeyBar(j);
+                    keyAdapter.setKeyboardType(j);
+                    System.out.println("Keyboard selected: " + j);
+                    try {
+                        savedSettings.setKeyboardNum(j);
+                        saveSerializedObject("prefs.dat", savedSettings);
+                    }
+                    catch (IOException ioexception1) {
+                        System.out.println("Could not save keyboard number.");
+                    }
+                    break;
+                }
+
+            }
+
+        }
+);
+        JPanel jpanel3 = new JPanel();
+        javax.swing.border.TitledBorder titledborder = BorderFactory.createTitledBorder("Keyboard Type");
+        jpanel3.setBorder(titledborder);
+        jpanel3.setBackground(getBackground());
+        jpanel3.add(kbSelector);
+        add(jpanel3, jpanel2, gridbagconstraints, 10, 8, 1, 1);
+        jtabbedpane.addTab("Keyboard Type", jpanel2);
+        JPanel jpanel4 = new JPanel();
+        jpanel4.setLayout(new GridBagLayout());
+        jpanel4.setBackground(getBackground());
+        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.");
+        jtextarea2.setBackground(getBackground());
+        jtextarea2.setEditable(false);
+        jtextarea2.setFont(new Font("Sans Serif", 0, 12));
+        add(jtextarea2, jpanel4, gridbagconstraints, 0, 0, 20, 8);
+        keyAdapter.setMouseSyncKey(SYNC_KEYS[0]);
+        mouseSyncKey = new JComboBox(SYNC_KEYS);
+        mouseSyncKey.setToolTipText("Mouse synchronization key or button");
+        mouseSyncKey.addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent actionevent) {
+                keyAdapter.setMouseSyncKey((String)mouseSyncKey.getSelectedItem());
+                try {
+                    savedSettings.setMouseSyncKeyNum(mouseSyncKey.getSelectedIndex());
+                    saveSerializedObject("prefs.dat", savedSettings);
+                }
+                catch (IOException ioexception1) {
+                    System.out.println("Could not save mouse sync key number.");
+                }
+            }
+
+        }
+);
+        JPanel jpanel5 = new JPanel();
+        javax.swing.border.TitledBorder titledborder1 = BorderFactory.createTitledBorder("Mouse Sync");
+        jpanel5.setBorder(titledborder1);
+        jpanel5.setBackground(getBackground());
+        jpanel5.add(mouseSyncKey);
+        add(jpanel5, jpanel4, gridbagconstraints, 10, 8, 1, 1);
+        jtabbedpane.addTab("Mouse Sync", jpanel4);
+        if (savedSettings.getVersion() == 1) {
+            kbSelector.setSelectedIndex(savedSettings.getKeyboardNum());
+            mouseSyncKey.setSelectedIndex(savedSettings.getMouseSyncKeyNum());
+        }
+        pack();
+    }
+
+    public void actionPerformed(ActionEvent actionevent) {
+        if (actionevent.getSource() == restore)
+            loadButtonArray(defaultKeys);
+        else
+        if (actionevent.getSource() == cancel)
+            try {
+                loadButtonArray((ComboKeyArray)getSerializedObject("keys.dat"));
+            }
+            catch (ClassNotFoundException classnotfoundexception) {
+                System.out.println(classnotfoundexception);
+            }
+            catch (IOException ioexception) {
+                loadButtonArray(defaultKeys);
+            }
+        else
+        if (actionevent.getSource() == save)
+            saveButtonClicked();
+    }
+
+    public void keyPressed(KeyEvent keyevent) {
+        if (keyevent.getKeyCode() != 10)
+            return;
+        if (keyevent.getSource() == restore)
+            loadButtonArray(defaultKeys);
+        else
+        if (keyevent.getSource() == cancel)
+            try {
+                loadButtonArray((ComboKeyArray)getSerializedObject("keys.dat"));
+            }
+            catch (ClassNotFoundException classnotfoundexception) {
+                System.out.println(classnotfoundexception);
+            }
+            catch (IOException ioexception) {
+                loadButtonArray(defaultKeys);
+            }
+        else
+        if (keyevent.getSource() == save)
+            saveButtonClicked();
+    }
+
+    public void keyTyped(KeyEvent keyevent) {
+        keyevent.consume();
+    }
+
+    public void keyReleased(KeyEvent keyevent) {
+    }
+
+    protected void getFocusOnSaveButton() {
+        save.requestFocus();
+    }
+
+    private void add(Component component, JPanel jpanel, GridBagConstraints gridbagconstraints, int i, int j, int k, int l) {
+        gridbagconstraints.gridx = i;
+        gridbagconstraints.gridy = j;
+        gridbagconstraints.gridwidth = k;
+        gridbagconstraints.gridheight = l;
+        jpanel.add(component, gridbagconstraints);
+    }
+
+    private void saveButtonClicked() {
+        ComboKeyArray combokeyarray = new ComboKeyArray();
+        for (int i = 0; i < 12; i++)
+            if (row[i].isValid()) {
+                ArrayList arraylist = new ArrayList();
+                for (int j = 0; j < 4; j++) {
+                    String s = row[i].keyField[j].getText();
+                    if (!s.equals("")) {
+                        KeyData keydata = new KeyData(s, row[i].usageCode[j]);
+                        arraylist.add(keydata);
+                    }
+                }
+
+                combokeyarray.setKeysForButton(i, arraylist);
+            }
+
+        try {
+            saveSerializedObject("keys.dat", combokeyarray);
+        }
+        catch (IOException ioexception) {
+            System.out.println(ioexception);
+        }
+        toolBar.buildCustomizedButtonBar(combokeyarray);
+    }
+
+    private void loadButtonArray(ComboKeyArray combokeyarray) {
+        for (int i = 0; i < 12; i++) {
+            row[i].setValid(false);
+            ArrayList arraylist = combokeyarray.getKeysForButton(i);
+            for (int j = 0; j < 4; j++) {
+                KeyData keydata;
+                if (arraylist != null && j < arraylist.size()) {
+                    keydata = (KeyData)arraylist.get(j);
+                    row[i].setValid(true);
+                } else {
+                    keydata = new KeyData("", 0);
+                }
+                row[i].keyField[j].setText(keydata.getKeyName());
+                row[i].usageCode[j] = keydata.getUsageCode();
+            }
+
+        }
+
+    }
+
+    private Object getSerializedObject(String s) throws ClassNotFoundException, IOException {
+        File file = new File(System.getProperty("user.home"), "IBM");
+        File file1 = new File(file, hostName);
+        File file2 = new File(file1, s);
+        FileInputStream fileinputstream = new FileInputStream(file2);
+        ObjectInputStream objectinputstream = new ObjectInputStream(fileinputstream);
+        Object obj = objectinputstream.readObject();
+        objectinputstream.close();
+        return obj;
+    }
+
+    private void saveSerializedObject(String s, Object obj) throws IOException {
+        File file = new File(System.getProperty("user.home"), "IBM");
+        file.mkdir();
+        File file1 = new File(file, hostName);
+        file1.mkdir();
+        File file2 = new File(file1, s);
+        FileOutputStream fileoutputstream = new FileOutputStream(file2);
+        ObjectOutputStream objectoutputstream = new ObjectOutputStream(fileoutputstream);
+        objectoutputstream.writeObject(obj);
+        objectoutputstream.flush();
+        objectoutputstream.close();
+    }
+
+
+
+
+
+
+
+
+}