123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- import java.awt.*;
- import java.awt.event.*;
- class OptionsFrame extends Frame
- implements WindowListener, ActionListener, ItemListener {
- static String[] names = {
- "Encoding",
- "Compression level",
- "JPEG image quality",
- "Cursor shape updates",
- "Use CopyRect",
- "Restricted colors",
- "Mouse buttons 2 and 3",
- "View only",
- "Share desktop",
- };
- static String[][] values = {
- { "Raw", "RRE", "CoRRE", "Hextile", "Zlib", "Tight" },
- { "Default", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
- { "JPEG off", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
- { "Enable", "Ignore", "Disable" },
- { "Yes", "No" },
- { "Full", "256", "64", "8", "4 (Grey)", "2 (B&W)" },
- { "Normal", "Reversed" },
- { "Yes", "No" },
- { "Yes", "No" },
- };
-
- final int
- encodingIndex = 0,
- compressLevelIndex = 1,
- jpegQualityIndex = 2,
- cursorUpdatesIndex = 3,
- useCopyRectIndex = 4,
- eightBitColorsIndex = 5,
- mouseButtonIndex = 6,
- viewOnlyIndex = 7,
- shareDesktopIndex = 8;
- Label[] labels = new Label[names.length];
- Choice[] choices = new Choice[names.length];
- Button closeButton;
- VncViewer viewer;
-
-
-
- int[] encodings = new int[20];
- int nEncodings;
- int compressLevel;
- int jpegQuality;
- int eightBitColors;
- int oldEightBitColors;
- boolean requestCursorUpdates;
- boolean ignoreCursorUpdates;
- boolean reverseMouseButtons2And3;
- boolean shareDesktop;
- boolean viewOnly;
-
-
-
-
- OptionsFrame(VncViewer v) {
- super("Ultr@VNC Options");
- viewer = v;
- GridBagLayout gridbag = new GridBagLayout();
- setLayout(gridbag);
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.fill = GridBagConstraints.BOTH;
- for (int i = 0; i < names.length; i++) {
- labels[i] = new Label(names[i]);
- gbc.gridwidth = 1;
- gridbag.setConstraints(labels[i],gbc);
- add(labels[i]);
- choices[i] = new Choice();
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gridbag.setConstraints(choices[i],gbc);
- add(choices[i]);
- choices[i].addItemListener(this);
- for (int j = 0; j < values[i].length; j++) {
- choices[i].addItem(values[i][j]);
- }
- }
- closeButton = new Button("Close");
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gridbag.setConstraints(closeButton, gbc);
- add(closeButton);
- closeButton.addActionListener(this);
- pack();
- addWindowListener(this);
-
- choices[encodingIndex].select("Tight");
- choices[compressLevelIndex].select("Default");
- choices[jpegQualityIndex].select("6");
- choices[cursorUpdatesIndex].select("Enable");
- choices[useCopyRectIndex].select("Yes");
- choices[eightBitColorsIndex].select("256");
- choices[mouseButtonIndex].select("Normal");
- choices[viewOnlyIndex].select("No");
- choices[shareDesktopIndex].select("Yes");
-
- for (int i = 0; i < names.length; i++) {
- String s = viewer.readParameter(names[i], false);
- if (s != null) {
- for (int j = 0; j < values[i].length; j++) {
- if (s.equalsIgnoreCase(values[i][j])) {
- choices[i].select(j);
- }
- }
- }
- }
-
- setEncodings();
- setColorFormat();
- setOtherOptions();
- }
-
-
-
- void disableShareDesktop() {
- labels[shareDesktopIndex].setEnabled(false);
- choices[shareDesktopIndex].setEnabled(false);
- }
-
-
-
-
-
-
-
- void setEncodings() {
- nEncodings = 0;
- if (choices[useCopyRectIndex].getSelectedItem().equals("Yes")) {
- encodings[nEncodings++] = RfbProto.EncodingCopyRect;
- }
- int preferredEncoding = RfbProto.EncodingRaw;
- boolean enableCompressLevel = false;
- if (choices[encodingIndex].getSelectedItem().equals("RRE")) {
- preferredEncoding = RfbProto.EncodingRRE;
- } else if (choices[encodingIndex].getSelectedItem().equals("CoRRE")) {
- preferredEncoding = RfbProto.EncodingCoRRE;
- } else if (choices[encodingIndex].getSelectedItem().equals("Hextile")) {
- preferredEncoding = RfbProto.EncodingHextile;
- } else if (choices[encodingIndex].getSelectedItem().equals("Zlib")) {
- preferredEncoding = RfbProto.EncodingZlib;
- enableCompressLevel = true;
- } else if (choices[encodingIndex].getSelectedItem().equals("Tight")) {
- preferredEncoding = RfbProto.EncodingTight;
- enableCompressLevel = true;
- }
- encodings[nEncodings++] = preferredEncoding;
- if (preferredEncoding != RfbProto.EncodingHextile) {
- encodings[nEncodings++] = RfbProto.EncodingHextile;
- }
- if (preferredEncoding != RfbProto.EncodingTight) {
- encodings[nEncodings++] = RfbProto.EncodingTight;
- }
- if (preferredEncoding != RfbProto.EncodingZlib) {
- encodings[nEncodings++] = RfbProto.EncodingZlib;
- }
- if (preferredEncoding != RfbProto.EncodingCoRRE) {
- encodings[nEncodings++] = RfbProto.EncodingCoRRE;
- }
- if (preferredEncoding != RfbProto.EncodingRRE) {
- encodings[nEncodings++] = RfbProto.EncodingRRE;
- }
-
- if (enableCompressLevel) {
- labels[compressLevelIndex].setEnabled(true);
- choices[compressLevelIndex].setEnabled(true);
- try {
- compressLevel =
- Integer.parseInt(choices[compressLevelIndex].getSelectedItem());
- }
- catch (NumberFormatException e) {
- compressLevel = -1;
- }
- if (compressLevel >= 1 && compressLevel <= 9) {
- encodings[nEncodings++] =
- RfbProto.EncodingCompressLevel0 + compressLevel;
- } else {
- compressLevel = -1;
- }
- } else {
- labels[compressLevelIndex].setEnabled(false);
- choices[compressLevelIndex].setEnabled(false);
- }
-
- if (preferredEncoding == RfbProto.EncodingTight && (eightBitColors == 0)) {
- labels[jpegQualityIndex].setEnabled(true);
- choices[jpegQualityIndex].setEnabled(true);
- try {
- jpegQuality =
- Integer.parseInt(choices[jpegQualityIndex].getSelectedItem());
- }
- catch (NumberFormatException e) {
- jpegQuality = -1;
- }
- if (jpegQuality >= 0 && jpegQuality <= 9) {
- encodings[nEncodings++] =
- RfbProto.EncodingQualityLevel0 + jpegQuality;
- } else {
- jpegQuality = -1;
- }
- } else {
- labels[jpegQualityIndex].setEnabled(false);
- choices[jpegQualityIndex].setEnabled(false);
- }
-
- requestCursorUpdates =
- !choices[cursorUpdatesIndex].getSelectedItem().equals("Disable");
- if (requestCursorUpdates) {
- encodings[nEncodings++] = RfbProto.EncodingXCursor;
- encodings[nEncodings++] = RfbProto.EncodingRichCursor;
- ignoreCursorUpdates =
- choices[cursorUpdatesIndex].getSelectedItem().equals("Ignore");
-
- if (!ignoreCursorUpdates) {
- encodings[nEncodings++] = RfbProto.EncodingPointerPos;
- }
- }
- encodings[nEncodings++] = RfbProto.EncodingLastRect;
- encodings[nEncodings++] = RfbProto.EncodingNewFBSize;
- viewer.setEncodings();
- }
-
-
-
-
-
- void setColorFormat() {
-
- if (choices[eightBitColorsIndex].getSelectedItem().equals("Full"))
- eightBitColors = 0;
- else if (choices[eightBitColorsIndex].getSelectedItem().equals("256"))
- eightBitColors = 1;
- else if (choices[eightBitColorsIndex].getSelectedItem().equals("64"))
- eightBitColors = 2;
- else if (choices[eightBitColorsIndex].getSelectedItem().equals("8"))
- eightBitColors = 3;
- else if (choices[eightBitColorsIndex].getSelectedItem().equals("4 (Grey)"))
- eightBitColors = 4;
- else if (choices[eightBitColorsIndex].getSelectedItem().equals("2 (B&W)"))
- eightBitColors = 5;
-
- boolean enableJPEG = (eightBitColors == 0) &&
- choices[encodingIndex].getSelectedItem().equals("Tight");
- labels[jpegQualityIndex].setEnabled(enableJPEG);
- choices[jpegQualityIndex].setEnabled(enableJPEG);
- }
-
-
-
-
- void setOtherOptions() {
- reverseMouseButtons2And3
- = choices[mouseButtonIndex].getSelectedItem().equals("Reversed");
- viewOnly
- = choices[viewOnlyIndex].getSelectedItem().equals("Yes");
- if (viewer.vc != null)
- viewer.vc.enableInput(!viewOnly);
- shareDesktop
- = choices[shareDesktopIndex].getSelectedItem().equals("Yes");
- }
-
-
-
- public void itemStateChanged(ItemEvent evt) {
- Object source = evt.getSource();
- if (source == choices[encodingIndex] ||
- source == choices[compressLevelIndex] ||
- source == choices[jpegQualityIndex] ||
- source == choices[cursorUpdatesIndex] ||
- source == choices[useCopyRectIndex]) {
- setEncodings();
- } else if (source == choices[eightBitColorsIndex]) {
- setColorFormat();
- } else if (source == choices[mouseButtonIndex] ||
- source == choices[shareDesktopIndex] ||
- source == choices[viewOnlyIndex]) {
- setOtherOptions();
- }
- }
-
-
-
- public void actionPerformed(ActionEvent evt) {
- if (evt.getSource() == closeButton)
- setVisible(false);
- }
-
-
-
- public void windowClosing(WindowEvent evt) {
- setVisible(false);
- }
- public void windowActivated(WindowEvent evt) {}
- public void windowDeactivated(WindowEvent evt) {}
- public void windowOpened(WindowEvent evt) {}
- public void windowClosed(WindowEvent evt) {}
- public void windowIconified(WindowEvent evt) {}
- public void windowDeiconified(WindowEvent evt) {}
- }
|