1253 * In addition to any and all formats specified in the flavormap.properties 1254 * file, or other file specified by the <code>AWT.DnD.flavorMapFileURL 1255 * </code> Toolkit property, text returned by the system Clipboard's <code> 1256 * getTransferData()</code> method is available in the following flavors: 1257 * <ul> 1258 * <li>DataFlavor.stringFlavor</li> 1259 * <li>DataFlavor.plainTextFlavor (<b>deprecated</b>)</li> 1260 * </ul> 1261 * As with <code>java.awt.datatransfer.StringSelection</code>, if the 1262 * requested flavor is <code>DataFlavor.plainTextFlavor</code>, or an 1263 * equivalent flavor, a Reader is returned. <b>Note:</b> The behavior of 1264 * the system Clipboard's <code>getTransferData()</code> method for <code> 1265 * DataFlavor.plainTextFlavor</code>, and equivalent DataFlavors, is 1266 * inconsistent with the definition of <code>DataFlavor.plainTextFlavor 1267 * </code>. Because of this, support for <code> 1268 * DataFlavor.plainTextFlavor</code>, and equivalent flavors, is 1269 * <b>deprecated</b>. 1270 * <p> 1271 * Each actual implementation of this method should first check if there 1272 * is a security manager installed. If there is, the method should call 1273 * the security manager's <code>checkSystemClipboardAccess</code> method 1274 * to ensure it's ok to to access the system clipboard. If the default 1275 * implementation of <code>checkSystemClipboardAccess</code> is used (that 1276 * is, that method is not overriden), then this results in a call to the 1277 * security manager's <code>checkPermission</code> method with an <code> 1278 * AWTPermission("accessClipboard")</code> permission. 1279 * 1280 * @return the system Clipboard 1281 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 1282 * returns true 1283 * @see java.awt.GraphicsEnvironment#isHeadless 1284 * @see java.awt.datatransfer.Clipboard 1285 * @see java.awt.datatransfer.StringSelection 1286 * @see java.awt.datatransfer.DataFlavor#stringFlavor 1287 * @see java.awt.datatransfer.DataFlavor#plainTextFlavor 1288 * @see java.io.Reader 1289 * @see java.awt.AWTPermission 1290 * @since JDK1.1 1291 */ 1292 public abstract Clipboard getSystemClipboard() 1293 throws HeadlessException; 1294 1295 /** 1296 * Gets the singleton instance of the system selection as a 1297 * <code>Clipboard</code> object. This allows an application to read and 1298 * modify the current, system-wide selection. 1301 * the user selects text, using either the mouse or the keyboard. 1302 * Typically, this is implemented by installing a 1303 * <code>FocusListener</code> on all <code>Component</code>s which support 1304 * text selection, and, between <code>FOCUS_GAINED</code> and 1305 * <code>FOCUS_LOST</code> events delivered to that <code>Component</code>, 1306 * updating the system selection <code>Clipboard</code> when the selection 1307 * changes inside the <code>Component</code>. Properly updating the system 1308 * selection ensures that a Java application will interact correctly with 1309 * native applications and other Java applications running simultaneously 1310 * on the system. Note that <code>java.awt.TextComponent</code> and 1311 * <code>javax.swing.text.JTextComponent</code> already adhere to this 1312 * policy. When using these classes, and their subclasses, developers need 1313 * not write any additional code. 1314 * <p> 1315 * Some platforms do not support a system selection <code>Clipboard</code>. 1316 * On those platforms, this method will return <code>null</code>. In such a 1317 * case, an application is absolved from its responsibility to update the 1318 * system selection <code>Clipboard</code> as described above. 1319 * <p> 1320 * Each actual implementation of this method should first check if there 1321 * is a <code>SecurityManager</code> installed. If there is, the method 1322 * should call the <code>SecurityManager</code>'s 1323 * <code>checkSystemClipboardAccess</code> method to ensure that client 1324 * code has access the system selection. If the default implementation of 1325 * <code>checkSystemClipboardAccess</code> is used (that is, if the method 1326 * is not overridden), then this results in a call to the 1327 * <code>SecurityManager</code>'s <code>checkPermission</code> method with 1328 * an <code>AWTPermission("accessClipboard")</code> permission. 1329 * 1330 * @return the system selection as a <code>Clipboard</code>, or 1331 * <code>null</code> if the native platform does not support a 1332 * system selection <code>Clipboard</code> 1333 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 1334 * returns true 1335 * 1336 * @see java.awt.datatransfer.Clipboard 1337 * @see java.awt.event.FocusListener 1338 * @see java.awt.event.FocusEvent#FOCUS_GAINED 1339 * @see java.awt.event.FocusEvent#FOCUS_LOST 1340 * @see TextComponent 1341 * @see javax.swing.text.JTextComponent 1342 * @see AWTPermission 1343 * @see GraphicsEnvironment#isHeadless 1344 * @since 1.4 1345 */ 1346 public Clipboard getSystemSelection() throws HeadlessException { 1347 GraphicsEnvironment.checkHeadless(); 1348 1682 * This method returns defaultValue if the property is not found. 1683 */ 1684 public static String getProperty(String key, String defaultValue) { 1685 if (resources != null) { 1686 try { 1687 return resources.getString(key); 1688 } 1689 catch (MissingResourceException e) {} 1690 } 1691 1692 return defaultValue; 1693 } 1694 1695 /** 1696 * Get the application's or applet's EventQueue instance. 1697 * Depending on the Toolkit implementation, different EventQueues 1698 * may be returned for different applets. Applets should 1699 * therefore not assume that the EventQueue instance returned 1700 * by this method will be shared by other applets or the system. 1701 * 1702 * <p>First, if there is a security manager, its 1703 * <code>checkAwtEventQueueAccess</code> 1704 * method is called. 1705 * If the default implementation of <code>checkAwtEventQueueAccess</code> 1706 * is used (that is, that method is not overriden), then this results in 1707 * a call to the security manager's <code>checkPermission</code> method 1708 * with an <code>AWTPermission("accessEventQueue")</code> permission. 1709 * 1710 * @return the <code>EventQueue</code> object 1711 * @throws SecurityException 1712 * if a security manager exists and its <code>{@link 1713 * java.lang.SecurityManager#checkAwtEventQueueAccess}</code> 1714 * method denies access to the <code>EventQueue</code> 1715 * @see java.awt.AWTPermission 1716 */ 1717 public final EventQueue getSystemEventQueue() { 1718 SecurityManager security = System.getSecurityManager(); 1719 if (security != null) { 1720 security.checkAwtEventQueueAccess(); 1721 } 1722 return getSystemEventQueueImpl(); 1723 } 1724 1725 /** 1726 * Gets the application's or applet's <code>EventQueue</code> 1727 * instance, without checking access. For security reasons, 1728 * this can only be called from a <code>Toolkit</code> subclass. 1729 * @return the <code>EventQueue</code> object 1730 */ 1731 protected abstract EventQueue getSystemEventQueueImpl(); 1732 1733 /* Accessor method for use by AWT package routines. */ 1734 static EventQueue getEventQueue() { 1735 return getDefaultToolkit().getSystemEventQueueImpl(); 1736 } 1737 1738 /** 1739 * Creates the peer for a DragSourceContext. 1740 * Always throws InvalidDndOperationException if | 1253 * In addition to any and all formats specified in the flavormap.properties 1254 * file, or other file specified by the <code>AWT.DnD.flavorMapFileURL 1255 * </code> Toolkit property, text returned by the system Clipboard's <code> 1256 * getTransferData()</code> method is available in the following flavors: 1257 * <ul> 1258 * <li>DataFlavor.stringFlavor</li> 1259 * <li>DataFlavor.plainTextFlavor (<b>deprecated</b>)</li> 1260 * </ul> 1261 * As with <code>java.awt.datatransfer.StringSelection</code>, if the 1262 * requested flavor is <code>DataFlavor.plainTextFlavor</code>, or an 1263 * equivalent flavor, a Reader is returned. <b>Note:</b> The behavior of 1264 * the system Clipboard's <code>getTransferData()</code> method for <code> 1265 * DataFlavor.plainTextFlavor</code>, and equivalent DataFlavors, is 1266 * inconsistent with the definition of <code>DataFlavor.plainTextFlavor 1267 * </code>. Because of this, support for <code> 1268 * DataFlavor.plainTextFlavor</code>, and equivalent flavors, is 1269 * <b>deprecated</b>. 1270 * <p> 1271 * Each actual implementation of this method should first check if there 1272 * is a security manager installed. If there is, the method should call 1273 * the security manager's {@link SecurityManager#checkPermission 1274 * checkPermission} method to check {@code AWTPermission("accessClipboard")}. 1275 * 1276 * @return the system Clipboard 1277 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 1278 * returns true 1279 * @see java.awt.GraphicsEnvironment#isHeadless 1280 * @see java.awt.datatransfer.Clipboard 1281 * @see java.awt.datatransfer.StringSelection 1282 * @see java.awt.datatransfer.DataFlavor#stringFlavor 1283 * @see java.awt.datatransfer.DataFlavor#plainTextFlavor 1284 * @see java.io.Reader 1285 * @see java.awt.AWTPermission 1286 * @since JDK1.1 1287 */ 1288 public abstract Clipboard getSystemClipboard() 1289 throws HeadlessException; 1290 1291 /** 1292 * Gets the singleton instance of the system selection as a 1293 * <code>Clipboard</code> object. This allows an application to read and 1294 * modify the current, system-wide selection. 1297 * the user selects text, using either the mouse or the keyboard. 1298 * Typically, this is implemented by installing a 1299 * <code>FocusListener</code> on all <code>Component</code>s which support 1300 * text selection, and, between <code>FOCUS_GAINED</code> and 1301 * <code>FOCUS_LOST</code> events delivered to that <code>Component</code>, 1302 * updating the system selection <code>Clipboard</code> when the selection 1303 * changes inside the <code>Component</code>. Properly updating the system 1304 * selection ensures that a Java application will interact correctly with 1305 * native applications and other Java applications running simultaneously 1306 * on the system. Note that <code>java.awt.TextComponent</code> and 1307 * <code>javax.swing.text.JTextComponent</code> already adhere to this 1308 * policy. When using these classes, and their subclasses, developers need 1309 * not write any additional code. 1310 * <p> 1311 * Some platforms do not support a system selection <code>Clipboard</code>. 1312 * On those platforms, this method will return <code>null</code>. In such a 1313 * case, an application is absolved from its responsibility to update the 1314 * system selection <code>Clipboard</code> as described above. 1315 * <p> 1316 * Each actual implementation of this method should first check if there 1317 * is a security manager installed. If there is, the method should call 1318 * the security manager's {@link SecurityManager#checkPermission 1319 * checkPermission} method to check {@code AWTPermission("accessClipboard")}. 1320 * 1321 * @return the system selection as a <code>Clipboard</code>, or 1322 * <code>null</code> if the native platform does not support a 1323 * system selection <code>Clipboard</code> 1324 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 1325 * returns true 1326 * 1327 * @see java.awt.datatransfer.Clipboard 1328 * @see java.awt.event.FocusListener 1329 * @see java.awt.event.FocusEvent#FOCUS_GAINED 1330 * @see java.awt.event.FocusEvent#FOCUS_LOST 1331 * @see TextComponent 1332 * @see javax.swing.text.JTextComponent 1333 * @see AWTPermission 1334 * @see GraphicsEnvironment#isHeadless 1335 * @since 1.4 1336 */ 1337 public Clipboard getSystemSelection() throws HeadlessException { 1338 GraphicsEnvironment.checkHeadless(); 1339 1673 * This method returns defaultValue if the property is not found. 1674 */ 1675 public static String getProperty(String key, String defaultValue) { 1676 if (resources != null) { 1677 try { 1678 return resources.getString(key); 1679 } 1680 catch (MissingResourceException e) {} 1681 } 1682 1683 return defaultValue; 1684 } 1685 1686 /** 1687 * Get the application's or applet's EventQueue instance. 1688 * Depending on the Toolkit implementation, different EventQueues 1689 * may be returned for different applets. Applets should 1690 * therefore not assume that the EventQueue instance returned 1691 * by this method will be shared by other applets or the system. 1692 * 1693 * <p> If there is a security manager then its 1694 * {@link SecurityManager#checkPermission checkPermission} method 1695 * is called to check {@code AWTPermission("accessEventQueue")}. 1696 * 1697 * @return the <code>EventQueue</code> object 1698 * @throws SecurityException 1699 * if a security manager is set and it denies access to 1700 * the {@code EventQueue} 1701 * @see java.awt.AWTPermission 1702 */ 1703 public final EventQueue getSystemEventQueue() { 1704 SecurityManager security = System.getSecurityManager(); 1705 if (security != null) { 1706 security.checkPermission(SecurityConstants.AWT.CHECK_AWT_EVENTQUEUE_PERMISSION); 1707 } 1708 return getSystemEventQueueImpl(); 1709 } 1710 1711 /** 1712 * Gets the application's or applet's <code>EventQueue</code> 1713 * instance, without checking access. For security reasons, 1714 * this can only be called from a <code>Toolkit</code> subclass. 1715 * @return the <code>EventQueue</code> object 1716 */ 1717 protected abstract EventQueue getSystemEventQueueImpl(); 1718 1719 /* Accessor method for use by AWT package routines. */ 1720 static EventQueue getEventQueue() { 1721 return getDefaultToolkit().getSystemEventQueueImpl(); 1722 } 1723 1724 /** 1725 * Creates the peer for a DragSourceContext. 1726 * Always throws InvalidDndOperationException if |