home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 September / PCO_0998.ISO / filesbbs / frei / vnc-java.arj / VNC-JAVA.ZIP / optionsFrame.java < prev    next >
Encoding:
Java Source  |  1998-05-08  |  6.2 KB  |  241 lines

  1. //
  2. //  Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory
  3. //
  4. //  This is free software; you can redistribute it and/or modify
  5. //  it under the terms of the GNU General Public License as published by
  6. //  the Free Software Foundation; either version 2 of the License, or
  7. //  (at your option) any later version.
  8. //
  9. //  This software is distributed in the hope that it will be useful,
  10. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //  GNU General Public License for more details.
  13. //
  14. //  You should have received a copy of the GNU General Public License
  15. //  along with this software; if not, write to the Free Software
  16. //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  17. //  USA.
  18. //
  19.  
  20. //
  21. // Options frame.
  22. //
  23. // This deals with all the options the user can play with.
  24. // It sets the encodings array and some booleans.
  25. //
  26.  
  27. import java.awt.*;
  28.  
  29. class optionsFrame extends Frame {
  30.  
  31.   static String[] names = {
  32.     "Encoding",
  33.     "Use CopyRect",
  34.     "Mouse buttons 2 and 3",
  35.     "Raw pixel drawing",
  36.     "CopyRect",
  37.     "Share desktop",
  38.   };
  39.  
  40.   static String[][] values = {
  41.     { "Raw", "RRE", "CoRRE", "Hextile" },
  42.     { "Yes", "No" },
  43.     { "Normal", "Reversed" },
  44.     { "Fast", "Reliable" },
  45.     { "Fast", "Reliable" },
  46.     { "Yes", "No" },
  47.   };
  48.  
  49.   final int encodingIndex = 0, useCopyRectIndex = 1, mouseButtonIndex = 2,
  50.     rawPixelDrawingIndex = 3, copyRectFastIndex = 4, shareDesktopIndex = 5;
  51.  
  52.   Label[] labels = new Label[names.length];
  53.   Choice[] choices = new Choice[names.length];
  54.   Button dismiss;
  55.   vncviewer v;
  56.  
  57.  
  58.   //
  59.   // The actual data which other classes look at:
  60.   //
  61.  
  62.   int[] encodings = new int[10];
  63.   int nEncodings;
  64.  
  65.   boolean reverseMouseButtons2And3;
  66.  
  67.   boolean drawEachPixelForRawRects;
  68.  
  69.   boolean copyRectFast;
  70.  
  71.   boolean shareDesktop;
  72.  
  73.  
  74.   //
  75.   // Constructor.  Set up the labels and choices from the names and values
  76.   // arrays.
  77.   //
  78.  
  79.   optionsFrame(vncviewer v1) {
  80.     super("VNC Options");
  81.  
  82.     v = v1;
  83.  
  84.     GridBagLayout gridbag = new GridBagLayout();
  85.     setLayout(gridbag);
  86.  
  87.     GridBagConstraints gbc = new GridBagConstraints();
  88.     gbc.fill = GridBagConstraints.BOTH;
  89.  
  90.     for (int i = 0; i < names.length; i++) {
  91.       labels[i] = new Label(names[i]);
  92.       gbc.gridwidth = 1;
  93.       gridbag.setConstraints(labels[i],gbc);
  94.       add(labels[i]);
  95.  
  96.       choices[i] = new Choice();
  97.       gbc.gridwidth = GridBagConstraints.REMAINDER;
  98.       gridbag.setConstraints(choices[i],gbc);
  99.       add(choices[i]);
  100.  
  101.       for (int j = 0; j < values[i].length; j++) {
  102.     choices[i].addItem(values[i][j]);
  103.       }
  104.     }
  105.  
  106.     dismiss = new Button("Dismiss");
  107.     gbc.gridwidth = GridBagConstraints.REMAINDER;
  108.     gridbag.setConstraints(dismiss,gbc);
  109.     add(dismiss);
  110.  
  111.     pack();
  112.  
  113.     // Set up defaults
  114.  
  115.     choices[encodingIndex].select("Hextile");
  116.     choices[useCopyRectIndex].select("Yes");
  117.     choices[mouseButtonIndex].select("Normal");
  118.     choices[rawPixelDrawingIndex].select("Reliable");
  119.     choices[copyRectFastIndex].select("Fast");
  120.     choices[shareDesktopIndex].select("No");
  121.  
  122.     // But let them be overridden by parameters
  123.  
  124.     for (int i = 0; i < names.length; i++) {
  125.       String s = v.readParameter(names[i], false);
  126.       if (s != null) {
  127.     for (int j = 0; j < values[i].length; j++) {
  128.       if (s.equalsIgnoreCase(values[i][j])) {
  129.         choices[i].select(j);
  130.       }
  131.     }
  132.       }
  133.     }
  134.  
  135.     // Make the booleans and encodings array correspond to the state of the GUI
  136.  
  137.     setEncodings();
  138.     setOtherOptions();
  139.   }
  140.  
  141.  
  142.   //
  143.   // Disable shareDesktop option
  144.   //
  145.  
  146.   void disableShareDesktop() {
  147.     labels[shareDesktopIndex].disable();
  148.     choices[shareDesktopIndex].disable();
  149.   }
  150.  
  151.   //
  152.   // setEncodings looks at the encoding and copyRect choices and sets the
  153.   // encodings array appropriately.  It also calls the vncviewer's
  154.   // setEncodings method to send a message to the RFB server if necessary.
  155.   //
  156.  
  157.   void setEncodings() {
  158.     nEncodings = 0;
  159.     if (choices[useCopyRectIndex].getSelectedItem().equals("Yes")) {
  160.       encodings[nEncodings++] = rfbProto.EncodingCopyRect;
  161.     }
  162.  
  163.     int preferredEncoding = rfbProto.EncodingRaw;
  164.  
  165.     if (choices[encodingIndex].getSelectedItem().equals("RRE")) {
  166.       preferredEncoding = rfbProto.EncodingRRE;
  167.     } else if (choices[encodingIndex].getSelectedItem().equals("CoRRE")) {
  168.       preferredEncoding = rfbProto.EncodingCoRRE;
  169.     } else if (choices[encodingIndex].getSelectedItem().equals("Hextile")) {
  170.       preferredEncoding = rfbProto.EncodingHextile;
  171.     }
  172.  
  173.     if (preferredEncoding == rfbProto.EncodingRaw) {
  174.       choices[rawPixelDrawingIndex].select("Fast");
  175.       drawEachPixelForRawRects = false;
  176.     }
  177.  
  178.     encodings[nEncodings++] = preferredEncoding;
  179.     if (preferredEncoding != rfbProto.EncodingRRE) {
  180.       encodings[nEncodings++] = rfbProto.EncodingRRE;
  181.     }
  182.     if (preferredEncoding != rfbProto.EncodingCoRRE) {
  183.       encodings[nEncodings++] = rfbProto.EncodingCoRRE;
  184.     }
  185.     if (preferredEncoding != rfbProto.EncodingHextile) {
  186.       encodings[nEncodings++] = rfbProto.EncodingHextile;
  187.     }
  188.  
  189.     v.setEncodings();
  190.   }
  191.  
  192.   //
  193.   // setOtherOptions looks at the "other" choices (ones which don't set the
  194.   // encoding) and sets the boolean flags appropriately.
  195.   //
  196.  
  197.   void setOtherOptions() {
  198.  
  199.     reverseMouseButtons2And3
  200.       = choices[mouseButtonIndex].getSelectedItem().equals("Reversed");
  201.  
  202.     drawEachPixelForRawRects
  203.       = choices[rawPixelDrawingIndex].getSelectedItem().equals("Reliable");
  204.  
  205.     copyRectFast
  206.       = (choices[copyRectFastIndex].getSelectedItem().equals("Fast"));
  207.  
  208.     shareDesktop
  209.       = (choices[shareDesktopIndex].getSelectedItem().equals("Yes"));
  210.   }
  211.  
  212.  
  213.  
  214.   //
  215.   // Respond to an action i.e. choice or button press
  216.   //
  217.  
  218.   public boolean action(Event evt, Object arg) {
  219.  
  220.     if (evt.target == dismiss) {
  221.       hide();
  222.       return true;
  223.  
  224.     } else if ((evt.target == choices[encodingIndex]) ||
  225.            (evt.target == choices[useCopyRectIndex])) {
  226.  
  227.       setEncodings();
  228.       return true;
  229.  
  230.     } else if ((evt.target == choices[mouseButtonIndex]) ||
  231.            (evt.target == choices[rawPixelDrawingIndex]) ||
  232.            (evt.target == choices[copyRectFastIndex]) ||
  233.            (evt.target == choices[shareDesktopIndex])) {
  234.  
  235.       setOtherOptions();
  236.       return true;
  237.     }
  238.     return false;
  239.   }
  240. }
  241.