/[classpath]/classpath/gnu/java/awt/peer/gtk/GtkClipboard.java
ViewVC logotype

Diff of /classpath/gnu/java/awt/peer/gtk/GtkClipboard.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by mkoch, Wed Jul 9 10:25:34 2003 UTC revision 1.6 by mkoch, Wed Sep 22 12:24:21 2004 UTC
# Line 60  public class GtkClipboard extends Clipbo Line 60  public class GtkClipboard extends Clipbo
60    
61    static boolean hasSelection = false;    static boolean hasSelection = false;
62    
63    protected    protected GtkClipboard()
   GtkClipboard ()  
64    {    {
65      super ("System Clipboard");      super("System Clipboard");
66      initNativeState ();      initNativeState();
67    }    }
68    
69    public Transferable    public Transferable getContents(Object requestor)
   getContents (Object requestor)  
70    {    {
71      synchronized (this)      synchronized (this)
72        {        {
# Line 77  public class GtkClipboard extends Clipbo Line 75  public class GtkClipboard extends Clipbo
75        }        }
76    
77      /* Java doesn't own the selection, so we need to ask X11 */      /* Java doesn't own the selection, so we need to ask X11 */
78        // XXX: Does this hold with Swing too ?
79      synchronized (selectionLock)      synchronized (selectionLock)
80        {        {
81          requestStringConversion ();          requestStringConversion();
82            
83          try          try
84            {            {
85              selectionLock.wait (SELECTION_RECEIVED_TIMEOUT);              selectionLock.wait(SELECTION_RECEIVED_TIMEOUT);
86            }            }
87          catch (InterruptedException e)          catch (InterruptedException e)
88            {            {
89              return null;              return null;
90            }            }
91                    
92          return (selection == null) ? null : new StringSelection (selection);          return selection == null ? null : new StringSelection(selection);
93        }        }
94    }    }
95    
96    void    void stringSelectionReceived(String newSelection)
   stringSelectionReceived (String newSelection)  
97    {    {
98      synchronized (selectionLock)      synchronized (selectionLock)
99        {        {
100          selection = newSelection;          selection = newSelection;
101          selectionLock.notify ();          selectionLock.notify();
102        }        }
103    }    }
104    
105    /* convert Java clipboard data into a String suitable for sending    /* convert Java clipboard data into a String suitable for sending
106       to another application */       to another application */
107    synchronized String    synchronized String stringSelectionHandler() throws IOException
   stringSelectionHandler () throws IOException  
108    {    {
109      String selection = null;      String selection = null;
110    
111      try {      try
112        if (contents.isDataFlavorSupported (DataFlavor.stringFlavor))        {
113          selection = (String)contents.getTransferData (DataFlavor.stringFlavor);          if (contents.isDataFlavorSupported(DataFlavor.stringFlavor))
114        else if (contents.isDataFlavorSupported (DataFlavor.plainTextFlavor))            selection = (String)contents.getTransferData(DataFlavor.stringFlavor);
115          {          else if (contents.isDataFlavorSupported(DataFlavor.plainTextFlavor))
116            StringBuffer sbuf = new StringBuffer ();            {
117            InputStreamReader reader;              StringBuffer sbuf = new StringBuffer();
118            char readBuf[] = new char[512];              InputStreamReader reader;
119            int numChars;              char readBuf[] = new char[512];
120                int numChars;
121                        
122            reader = new InputStreamReader              reader = new InputStreamReader
123              ((InputStream)                ((InputStream)
124               contents.getTransferData (DataFlavor.plainTextFlavor), "UNICODE");                 contents.getTransferData(DataFlavor.plainTextFlavor), "UNICODE");
125                        
126            while (true)              while (true)
127              {                {
128                numChars = reader.read (readBuf);                  numChars = reader.read(readBuf);
129                if (numChars == -1)                  if (numChars == -1)
130                  break;                    break;
131                sbuf.append (readBuf, 0, numChars);                  sbuf.append(readBuf, 0, numChars);
132              }                }
133                        
134            selection = new String (sbuf);              selection = new String(sbuf);
135          }            }
136      } catch (Exception e) { }        }
137        catch (Exception e)
138          {
139          }
140            
141      return selection;      return selection;
142    }    }
143    
144    public synchronized void    public synchronized void setContents(Transferable contents,
145    setContents (Transferable contents, ClipboardOwner owner)                                         ClipboardOwner owner)
146    {    {
147      selectionGet ();      selectionGet();
148    
149      this.contents = contents;      this.contents = contents;
150      this.owner = owner;      this.owner = owner;
# Line 150  public class GtkClipboard extends Clipbo Line 152  public class GtkClipboard extends Clipbo
152      hasSelection = true;      hasSelection = true;
153    }    }
154    
155    synchronized    synchronized void selectionClear()
   void selectionClear ()  
156    {    {
157      hasSelection = false;      hasSelection = false;
158    
159      if (owner != null)      if (owner != null)
160        {        {
161          owner.lostOwnership (this, contents);          owner.lostOwnership(this, contents);
162          owner = null;          owner = null;
163          contents = null;          contents = null;
164        }        }
165    }    }
166    
167    native void initNativeState ();    native void initNativeState();
168    native static void requestStringConversion ();    native static void requestStringConversion();
169    native static void selectionGet ();    native static void selectionGet();
170  }  }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26