📄 gtkselection.java
字号:
text = null; textDelivered = false; } requestLock.notifyAll(); } } return result; } /** * Callback that sets the available text on the clipboard. Note that * this should not call any code that could need the main gdk lock. */ private void textAvailable(String text) { synchronized (requestLock) { this.text = text; textDelivered = true; requestLock.notifyAll(); } } /** * Helper method that tests whether we already have an image for the * current gtk+ selection on the clipboard and if not requests it * and waits till it is available. */ private Image getImage() { Image result; synchronized (requestLock) { // Did we request already and cache the result? if (imageDelivered) result = image; else { // Wait till there are no pending requests. while (requestInProgress) { try { requestLock.wait(); } catch (InterruptedException ie) { // ignored } } // If nobody else beat us we try ourselves to get and // caching the result. if (! imageDelivered) { requestInProgress = true; requestImage(clipboard); while (! imageDelivered) { try { requestLock.wait(); } catch (InterruptedException ie) { // ignored } } requestInProgress = false; } if (imagePointer != null) image = new GtkImage(imagePointer); imagePointer = null; result = image; if (! GtkClipboard.canCache) { image = null; imageDelivered = false; } requestLock.notifyAll(); } } return result; } /** * Callback that sets the available image on the clipboard. Note * that this should not call any code that could need the main gdk * lock. Note that we get a Pointer to a GdkPixbuf which we cannot * turn into a real GtkImage at this point. That will be done on the * "user thread" in getImage(). */ private void imageAvailable(Pointer pointer) { synchronized (requestLock) { this.imagePointer = pointer; imageDelivered = true; requestLock.notifyAll(); } } /** * Helper method that test whether we already have a list of * URIs/Files and if not requests them and waits till they are * available. */ private List getURIs() { List result; synchronized (requestLock) { // Did we request already and cache the result? if (urisDelivered) result = uris; else { // Wait till there are no pending requests. while (requestInProgress) { try { requestLock.wait(); } catch (InterruptedException ie) { // ignored } } // If nobody else beat us we try ourselves to get and // caching the result. if (! urisDelivered) { requestInProgress = true; requestURIs(clipboard); while (! urisDelivered) { try { requestLock.wait(); } catch (InterruptedException ie) { // ignored } } requestInProgress = false; } result = uris; if (! GtkClipboard.canCache) { uris = null; urisDelivered = false; } requestLock.notifyAll(); } } return result; } /** * Callback that sets the available File list. Note that this should * not call any code that could need the main gdk lock. */ private void urisAvailable(String[] uris) { synchronized (requestLock) { if (uris != null && uris.length != 0) { ArrayList list = new ArrayList(uris.length); for (int i = 0; i < uris.length; i++) { try { URI uri = new URI(uris[i]); if (uri.getScheme().equals("file")) list.add(new File(uri)); } catch (URISyntaxException use) { } } this.uris = list; } urisDelivered = true; requestLock.notifyAll(); } } /** * Helper method that requests a byte[] for the given target * mime-type flavor and waits till it is available. Note that unlike * the other get methods this one doesn't cache the result since * there are possibly many targets. */ private byte[] getBytes(String target) { byte[] result; synchronized (requestLock) { // Wait till there are no pending requests. while (requestInProgress) { try { requestLock.wait(); } catch (InterruptedException ie) { // ignored } } // Request bytes and wait till they are available. requestInProgress = true; requestBytes(clipboard, target); while (! bytesDelivered) { try { requestLock.wait(); } catch (InterruptedException ie) { // ignored } } result = bytes; bytes = null; bytesDelivered = false; requestInProgress = false; requestLock.notifyAll(); } return result; } /** * Callback that sets the available byte array on the * clipboard. Note that this should not call any code that could * need the main gdk lock. */ private void bytesAvailable(byte[] bytes) { synchronized (requestLock) { this.bytes = bytes; bytesDelivered = true; requestLock.notifyAll(); } } public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { // Note the fall throughs for the "magic targets" if they fail we // try one more time through getBytes(). if (flavor.equals(DataFlavor.stringFlavor)) { String text = getText(); if (text != null) return text; } if (flavor.equals(DataFlavor.plainTextFlavor)) { String text = getText(); if (text != null) return new StringBufferInputStream(text); } if (flavor.equals(DataFlavor.imageFlavor)) { Image image = getImage(); if (image != null) return image; } if (flavor.equals(DataFlavor.javaFileListFlavor)) { List uris = getURIs(); if (uris != null) return uris; } byte[] bytes = getBytes(flavor.getMimeType()); if (bytes == null) throw new UnsupportedFlavorException(flavor); if (flavor.isMimeTypeSerializedObject()) { try { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais); return ois.readObject(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (ClassNotFoundException cnfe) { cnfe.printStackTrace(); } } if (flavor.isRepresentationClassInputStream()) return new ByteArrayInputStream(bytes); // XXX, need some more conversions? throw new UnsupportedFlavorException(flavor); } /* * Requests text, Image or an byte[] for a particular target from the * other application. These methods return immediately. When the * content is available the contentLock will be notified through * textAvailable, imageAvailable, urisAvailable or bytesAvailable and the * appropriate field is set. * The clipboard argument is true if we want the Clipboard, and false * if we want the (primary) selection. */ private native void requestText(boolean clipboard); private native void requestImage(boolean clipboard); private native void requestURIs(boolean clipboard); private native void requestBytes(boolean clipboard, String target); /* Similar to the above but for requesting the supported targets. */ private native void requestMimeTypes(boolean clipboard);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -