home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 September / PCO_0998.ISO / filesbbs / frei / vnc-java.arj / VNC-JAVA.ZIP / clipboardFrame.java < prev    next >
Encoding:
Java Source  |  1998-01-15  |  2.4 KB  |  116 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. // Clipboard frame.
  22. //
  23.  
  24. import java.awt.*;
  25.  
  26. class clipboardFrame extends Frame {
  27.  
  28.   TextArea ta;
  29.   Button clear, dismiss;
  30.   String selection;
  31.   vncviewer v;
  32.  
  33.  
  34.   //
  35.   // Constructor.
  36.   //
  37.  
  38.   clipboardFrame(vncviewer v1) {
  39.     super("VNC Clipboard");
  40.  
  41.     v = v1;
  42.  
  43.     GridBagLayout gridbag = new GridBagLayout();
  44.     setLayout(gridbag);
  45.  
  46.     GridBagConstraints gbc = new GridBagConstraints();
  47.     gbc.gridwidth = GridBagConstraints.REMAINDER;
  48.     gbc.fill = GridBagConstraints.BOTH;
  49.     gbc.weighty = 1.0;
  50.  
  51.     ta = new TextArea(5,40);
  52.     gridbag.setConstraints(ta,gbc);
  53.     add(ta);
  54.  
  55.     gbc.fill = GridBagConstraints.HORIZONTAL;
  56.     gbc.weightx = 1.0;
  57.     gbc.weighty = 0.0;
  58.     gbc.gridwidth = 1;
  59.     clear = new Button("Clear");
  60.     gridbag.setConstraints(clear,gbc);
  61.     add(clear);
  62.  
  63.     dismiss = new Button("Dismiss");
  64.     gridbag.setConstraints(dismiss,gbc);
  65.     add(dismiss);
  66.  
  67.     pack();
  68.   }
  69.  
  70.  
  71.   //
  72.   // Set the cut text from the RFB server.
  73.   //
  74.  
  75.   void setCutText(String text) {
  76.     selection = text;
  77.     ta.setText(text);
  78.     if (isVisible()) {
  79.       ta.selectAll();
  80.     }
  81.   }
  82.  
  83.  
  84.   //
  85.   // When the focus leaves the window, see if we have new cut text and if so
  86.   // send it to the RFB server.
  87.   //
  88.  
  89.   public boolean lostFocus(Event evt, Object arg) {
  90.     if ((selection != null) && !selection.equals(ta.getText())) {
  91.       selection = ta.getText();
  92.       v.setCutText(selection);
  93.     }
  94.     return true;
  95.   }
  96.  
  97.  
  98.   //
  99.   // Respond to an action i.e. button press
  100.   //
  101.  
  102.   public boolean action(Event evt, Object arg) {
  103.  
  104.     if (evt.target == dismiss) {
  105.       hide();
  106.       return true;
  107.  
  108.     } else if (evt.target == clear) {
  109.       ta.setText("");
  110.       return true;
  111.     }
  112.  
  113.     return false;
  114.   }
  115. }
  116.