1 7 8 package javax.swing; 9 10 import java.awt.*; 11 import java.awt.event.*; 12 13 import java.beans.PropertyVetoException ; 14 import java.beans.PropertyChangeEvent ; 15 import java.util.EventListener ; 16 17 import javax.swing.border.Border ; 18 import javax.swing.event.InternalFrameEvent ; 19 import javax.swing.event.InternalFrameListener ; 20 import javax.swing.plaf.*; 21 22 import javax.accessibility.*; 23 24 import java.io.ObjectOutputStream ; 25 import java.io.ObjectInputStream ; 26 import java.io.IOException ; 27 28 29 90 public class JInternalFrame extends JComponent implements 91 Accessible, WindowConstants , 92 RootPaneContainer 93 { 94 98 private static final String uiClassID = "InternalFrameUI"; 99 100 109 protected JRootPane rootPane; 110 111 121 protected boolean rootPaneCheckingEnabled = false; 122 123 124 protected boolean closable; 125 126 protected boolean isClosed; 127 128 protected boolean maximizable; 129 133 protected boolean isMaximum; 134 140 protected boolean iconable; 141 145 protected boolean isIcon; 146 147 protected boolean resizable; 148 149 protected boolean isSelected; 150 151 protected Icon frameIcon; 152 153 protected String title; 154 158 protected JDesktopIcon desktopIcon; 159 160 private boolean opened; 161 162 private Rectangle normalBounds = null; 163 164 private int defaultCloseOperation = DISPOSE_ON_CLOSE; 165 166 172 private Component lastFocusOwner; 173 174 175 public final static String CONTENT_PANE_PROPERTY = "contentPane"; 176 177 public final static String MENU_BAR_PROPERTY = "JMenuBar"; 178 179 public final static String TITLE_PROPERTY = "title"; 180 181 public final static String LAYERED_PANE_PROPERTY = "layeredPane"; 182 183 public final static String ROOT_PANE_PROPERTY = "rootPane"; 184 185 public final static String GLASS_PANE_PROPERTY = "glassPane"; 186 187 public final static String FRAME_ICON_PROPERTY = "frameIcon"; 188 189 193 public final static String IS_SELECTED_PROPERTY = "selected"; 194 195 public final static String IS_CLOSED_PROPERTY = "closed"; 196 197 public final static String IS_MAXIMUM_PROPERTY = "maximum"; 198 199 public final static String IS_ICON_PROPERTY = "icon"; 200 201 202 206 public JInternalFrame() { 207 this("", false, false, false, false); 208 } 209 210 219 public JInternalFrame(String title) { 220 this(title, false, false, false, false); 221 } 222 223 231 public JInternalFrame(String title, boolean resizable) { 232 this(title, resizable, false, false, false); 233 } 234 235 244 public JInternalFrame(String title, boolean resizable, boolean closable) { 245 this(title, resizable, closable, false, false); 246 } 247 248 258 public JInternalFrame(String title, boolean resizable, boolean closable, 259 boolean maximizable) { 260 this(title, resizable, closable, maximizable, false); 261 } 262 263 274 public JInternalFrame(String title, boolean resizable, boolean closable, 275 boolean maximizable, boolean iconifiable) { 276 277 setRootPane(createRootPane()); 278 getGlassPane().setVisible(true); 279 setLayout(new BorderLayout()); 280 this.title = title; 281 this.resizable = resizable; 282 this.closable = closable; 283 this.maximizable = maximizable; 284 isMaximum = false; 285 this.iconable = iconifiable; 286 isIcon = false; 287 setVisible(false); 288 setRootPaneCheckingEnabled(true); 289 desktopIcon = new JDesktopIcon(this); 290 updateUI(); 291 sun.awt.SunToolkit.checkAndSetPolicy(this, true); 292 } 293 294 299 protected JRootPane createRootPane() { 300 return new JRootPane (); 301 } 302 303 309 public InternalFrameUI getUI() { 310 return (InternalFrameUI)ui; 311 } 312 313 322 public void setUI(InternalFrameUI ui) { 323 boolean checkingEnabled = isRootPaneCheckingEnabled(); 324 try { 325 setRootPaneCheckingEnabled(false); 326 super.setUI(ui); 327 } 328 finally { 329 setRootPaneCheckingEnabled(checkingEnabled); 330 } 331 } 332 333 341 public void updateUI() { 342 setUI((InternalFrameUI)UIManager.getUI(this)); 343 invalidate(); 344 if (desktopIcon != null) { 345 desktopIcon.updateUIWhenHidden(); 346 } 347 } 348 349 353 void updateUIWhenHidden() { 354 setUI((InternalFrameUI)UIManager.getUI(this)); 355 invalidate(); 356 Component[] children = getComponents(); 357 if (children != null) { 358 for(int i = 0; i < children.length; i++) { 359 SwingUtilities.updateComponentTreeUI(children[i]); 360 } 361 } 362 } 363 364 365 377 public String getUIClassID() { 378 return uiClassID; 379 } 380 381 393 protected boolean isRootPaneCheckingEnabled() { 394 return rootPaneCheckingEnabled; 395 } 396 397 413 protected void setRootPaneCheckingEnabled(boolean enabled) { 414 rootPaneCheckingEnabled = enabled; 415 } 416 417 436 protected void addImpl(Component comp, Object constraints, int index) { 437 if(isRootPaneCheckingEnabled()) { 438 getContentPane().add(comp, constraints, index); 439 } 440 else { 441 super.addImpl(comp, constraints, index); 442 } 443 } 444 445 455 public void remove(Component comp) { 456 int oldCount = getComponentCount(); 457 super.remove(comp); 458 if (oldCount == getComponentCount()) { 459 getContentPane().remove(comp); 460 } 461 } 462 463 464 474 public void setLayout(LayoutManager manager) { 475 if(isRootPaneCheckingEnabled()) { 476 getContentPane().setLayout(manager); 477 } 478 else { 479 super.setLayout(manager); 480 } 481 } 482 483 484 488 497 @Deprecated 498 public JMenuBar getMenuBar() { 499 return getRootPane().getMenuBar(); 500 } 501 502 510 public JMenuBar getJMenuBar() { 511 return getRootPane().getJMenuBar(); 512 } 513 514 522 @Deprecated 523 public void setMenuBar(JMenuBar m) { 524 JMenuBar oldValue = getMenuBar(); 525 getRootPane().setJMenuBar(m); 526 firePropertyChange(MENU_BAR_PROPERTY, oldValue, m); 527 } 528 529 540 public void setJMenuBar(JMenuBar m){ 541 JMenuBar oldValue = getMenuBar(); 542 getRootPane().setJMenuBar(m); 543 firePropertyChange(MENU_BAR_PROPERTY, oldValue, m); 544 } 545 546 551 public Container getContentPane() { 552 return getRootPane().getContentPane(); 553 } 554 555 556 571 public void setContentPane(Container c) { 572 Container oldValue = getContentPane(); 573 getRootPane().setContentPane(c); 574 firePropertyChange(CONTENT_PANE_PROPERTY, oldValue, c); 575 } 576 577 584 public JLayeredPane getLayeredPane() { 585 return getRootPane().getLayeredPane(); 586 } 587 588 602 public void setLayeredPane(JLayeredPane layered) { 603 JLayeredPane oldValue = getLayeredPane(); 604 getRootPane().setLayeredPane(layered); 605 firePropertyChange(LAYERED_PANE_PROPERTY, oldValue, layered); 606 } 607 608 614 public Component getGlassPane() { 615 return getRootPane().getGlassPane(); 616 } 617 618 629 public void setGlassPane(Component glass) { 630 Component oldValue = getGlassPane(); 631 getRootPane().setGlassPane(glass); 632 firePropertyChange(GLASS_PANE_PROPERTY, oldValue, glass); 633 } 634 635 641 public JRootPane getRootPane() { 642 return rootPane; 643 } 644 645 646 657 protected void setRootPane(JRootPane root) { 658 if(rootPane != null) { 659 remove(rootPane); 660 } 661 JRootPane oldValue = getRootPane(); 662 rootPane = root; 663 if(rootPane != null) { 664 boolean checkingEnabled = isRootPaneCheckingEnabled(); 665 try { 666 setRootPaneCheckingEnabled(false); 667 add(rootPane, BorderLayout.CENTER); 668 } 669 finally { 670 setRootPaneCheckingEnabled(checkingEnabled); 671 } 672 } 673 firePropertyChange(ROOT_PANE_PROPERTY, oldValue, root); 674 } 675 676 685 public void setClosable(boolean b) { 686 Boolean oldValue = closable ? Boolean.TRUE : Boolean.FALSE; 687 Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; 688 closable = b; 689 firePropertyChange("closable", oldValue, newValue); 690 } 691 692 697 public boolean isClosable() { 698 return closable; 699 } 700 701 705 public boolean isClosed() { 706 return isClosed; 707 } 708 709 752 public void setClosed(boolean b) throws PropertyVetoException { 753 if (isClosed == b) { 754 return; 755 } 756 757 Boolean oldValue = isClosed ? Boolean.TRUE : Boolean.FALSE; 758 Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; 759 if (b) { 760 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING); 761 } 762 fireVetoableChange(IS_CLOSED_PROPERTY, oldValue, newValue); 763 isClosed = b; 764 firePropertyChange(IS_CLOSED_PROPERTY, oldValue, newValue); 765 if (isClosed) { 766 dispose(); 767 } else if (!opened) { 768 770 } 773 } 774 775 786 public void setResizable(boolean b) { 787 Boolean oldValue = resizable ? Boolean.TRUE : Boolean.FALSE; 788 Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; 789 resizable = b; 790 firePropertyChange("resizable", oldValue, newValue); 791 } 792 793 799 public boolean isResizable() { 800 return isMaximum ? false : resizable; 802 } 803 804 818 public void setIconifiable(boolean b) { 819 Boolean oldValue = iconable ? Boolean.TRUE : Boolean.FALSE; 820 Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; 821 iconable = b; 822 firePropertyChange("iconable", oldValue, newValue); 823 } 824 825 833 public boolean isIconifiable() { 834 return iconable; 835 } 836 837 842 public boolean isIcon() { 843 return isIcon; 844 } 845 846 867 public void setIcon(boolean b) throws PropertyVetoException { 868 if (isIcon == b) { 869 return; 870 } 871 872 878 firePropertyChange("ancestor", null, getParent()); 879 880 Boolean oldValue = isIcon ? Boolean.TRUE : Boolean.FALSE; 881 Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; 882 fireVetoableChange(IS_ICON_PROPERTY, oldValue, newValue); 883 isIcon = b; 884 firePropertyChange(IS_ICON_PROPERTY, oldValue, newValue); 885 if (b) 886 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ICONIFIED); 887 else 888 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED); 889 } 890 891 905 public void setMaximizable(boolean b) { 906 Boolean oldValue = maximizable ? Boolean.TRUE : Boolean.FALSE; 907 Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; 908 maximizable = b; 909 firePropertyChange("maximizable", oldValue, newValue); 910 } 911 912 918 public boolean isMaximizable() { 919 return maximizable; 920 } 921 922 927 public boolean isMaximum() { 928 return isMaximum; 929 } 930 931 947 public void setMaximum(boolean b) throws PropertyVetoException { 948 if (isMaximum == b) { 949 return; 950 } 951 952 Boolean oldValue = isMaximum ? Boolean.TRUE : Boolean.FALSE; 953 Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; 954 fireVetoableChange(IS_MAXIMUM_PROPERTY, oldValue, newValue); 955 958 isMaximum = b; 959 firePropertyChange(IS_MAXIMUM_PROPERTY, oldValue, newValue); 960 } 961 962 968 public String getTitle() { 969 return title; 970 } 971 972 983 public void setTitle(String title) { 984 String oldValue = this.title; 985 this.title = title; 986 firePropertyChange(TITLE_PROPERTY, oldValue, title); 987 } 988 989 1019 public void setSelected(boolean selected) throws PropertyVetoException { 1020 if ((isSelected == selected) || (selected && 1023 (isIcon ? !desktopIcon.isShowing() : !isShowing()))) { 1024 return; 1025 } 1026 1027 Boolean oldValue = isSelected ? Boolean.TRUE : Boolean.FALSE; 1028 Boolean newValue = selected ? Boolean.TRUE : Boolean.FALSE; 1029 fireVetoableChange(IS_SELECTED_PROPERTY, oldValue, newValue); 1030 1031 1041 1042 lastFocusOwner = null; 1043 if (selected) { 1044 restoreSubcomponentFocus(); 1045 } else { 1046 getRootPane().setMostRecentFocusOwner(getFocusOwner()); 1047 } 1048 1049 isSelected = selected; 1050 firePropertyChange(IS_SELECTED_PROPERTY, oldValue, newValue); 1051 if (isSelected) 1052 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED); 1053 else 1054 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED); 1055 lastFocusOwner = null; 1056 repaint(); 1057 } 1058 1059 1066 public boolean isSelected() { 1067 return isSelected; 1068 } 1069 1070 1089 public void setFrameIcon(Icon icon) { 1090 Icon oldIcon = frameIcon; 1091 frameIcon = icon; 1092 firePropertyChange(FRAME_ICON_PROPERTY, oldIcon, icon); 1093 } 1094 1095 1102 public Icon getFrameIcon() { 1103 return frameIcon; 1104 } 1105 1106 1110 public void moveToFront() { 1111 if(getParent() != null && getParent() instanceof JLayeredPane ) { 1112 JLayeredPane l = (JLayeredPane )getParent(); 1113 Component focusOwner = (lastFocusOwner != null) ? lastFocusOwner : 1121 KeyboardFocusManager.getCurrentKeyboardFocusManager(). 1122 getFocusOwner(); 1123 1124 if (focusOwner != null && 1125 !SwingUtilities.isDescendingFrom(focusOwner, this)) { 1126 focusOwner = null; 1127 } 1128 l.moveToFront(this); 1129 if (focusOwner != null) { 1130 focusOwner.requestFocus(); 1131 } 1132 } 1133 } 1134 1135 1139 public void moveToBack() { 1140 if(getParent() != null && getParent() instanceof JLayeredPane ) { 1141 JLayeredPane l = (JLayeredPane )getParent(); 1142 l.moveToBack(this); 1143 } 1144 } 1145 1146 1156 public void setLayer(Integer layer) { 1157 if(getParent() != null && getParent() instanceof JLayeredPane ) { 1158 JLayeredPane p = (JLayeredPane )getParent(); 1161 p.setLayer(this, layer.intValue(), p.getPosition(this)); 1162 } else { 1163 JLayeredPane.putLayer(this, layer.intValue()); 1165 if(getParent() != null) 1166 getParent().repaint(getX(), getY(), getWidth(), getHeight()); 1167 } 1168 } 1169 1170 1187 public void setLayer(int layer) { 1188 this.setLayer(new Integer (layer)); 1189 } 1190 1191 1198 public int getLayer() { 1199 return JLayeredPane.getLayer(this); 1200 } 1201 1202 1210 public JDesktopPane getDesktopPane() { 1211 Container p; 1212 1213 p = getParent(); 1215 while(p != null && !(p instanceof JDesktopPane )) 1216 p = p.getParent(); 1217 1218 if(p == null) { 1219 p = getDesktopIcon().getParent(); 1221 while(p != null && !(p instanceof JDesktopPane )) 1222 p = p.getParent(); 1223 } 1224 1225 return (JDesktopPane )p; 1226 } 1227 1228 1238 public void setDesktopIcon(JDesktopIcon d) { 1239 JDesktopIcon oldValue = getDesktopIcon(); 1240 desktopIcon = d; 1241 firePropertyChange("desktopIcon", oldValue, d); 1242 } 1243 1244 1251 public JDesktopIcon getDesktopIcon() { 1252 return desktopIcon; 1253 } 1254 1255 1264 public Rectangle getNormalBounds() { 1265 1266 1271 1272 if (normalBounds != null) { 1273 return normalBounds; 1274 } else { 1275 return getBounds(); 1276 } 1277 } 1278 1279 1287 public void setNormalBounds(Rectangle r) { 1288 normalBounds = r; 1289 } 1290 1291 1299 public Component getFocusOwner() { 1300 if (isSelected()) { 1301 Component focusOwner = KeyboardFocusManager. 1302 getCurrentKeyboardFocusManager().getFocusOwner(); 1303 1304 if (focusOwner != null && !SwingUtilities. 1305 isDescendingFrom(focusOwner, this)) { 1306 focusOwner = null; 1308 } 1309 return focusOwner; 1310 } 1311 return null; 1312 } 1313 1314 1335 public Component getMostRecentFocusOwner() { 1336 if (isSelected()) { 1337 return getFocusOwner(); 1338 } 1339 1340 Component mostRecentFocusOwner = 1341 getRootPane().getMostRecentFocusOwner(); 1342 if (mostRecentFocusOwner != null) { 1343 return mostRecentFocusOwner; 1344 } 1345 1346 FocusTraversalPolicy policy = getFocusTraversalPolicy(); 1347 if (policy instanceof InternalFrameFocusTraversalPolicy ) { 1348 return ((InternalFrameFocusTraversalPolicy )policy). 1349 getInitialComponent(this); 1350 } 1351 1352 return policy.getDefaultComponent(this); 1353 } 1354 1355 1363 public void restoreSubcomponentFocus() { 1364 lastFocusOwner = getMostRecentFocusOwner(); 1365 if (lastFocusOwner == null) { 1366 lastFocusOwner = getContentPane(); 1370 } 1371 lastFocusOwner.requestFocus(); 1372 } 1373 1374 1386 public void reshape(int x, int y, int width, int height) { 1387 super.reshape(x, y, width, height); 1388 validate(); 1389 repaint(); 1390 } 1391 1392 1396 1402 public void addInternalFrameListener(InternalFrameListener l) { listenerList.add(InternalFrameListener .class, l); 1404 enableEvents(0); } 1407 1408 1414 public void removeInternalFrameListener(InternalFrameListener l) { listenerList.remove(InternalFrameListener .class, l); 1416 } 1417 1418 1429 public InternalFrameListener [] getInternalFrameListeners() { 1430 return (InternalFrameListener [])listenerList.getListeners( 1431 InternalFrameListener .class); 1432 } 1433 1434 1450 protected void fireInternalFrameEvent(int id){ 1451 Object [] listeners = listenerList.getListenerList(); 1452 InternalFrameEvent e = null; 1453 for (int i = listeners.length -2; i >=0; i -= 2){ 1454 if (listeners[i] == InternalFrameListener .class){ 1455 if (e == null){ 1456 e = new InternalFrameEvent (this, id); 1457 } 1459 switch(e.getID()) { 1460 case InternalFrameEvent.INTERNAL_FRAME_OPENED: 1461 ((InternalFrameListener )listeners[i+1]).internalFrameOpened(e); 1462 break; 1463 case InternalFrameEvent.INTERNAL_FRAME_CLOSING: 1464 ((InternalFrameListener )listeners[i+1]).internalFrameClosing(e); 1465 break; 1466 case InternalFrameEvent.INTERNAL_FRAME_CLOSED: 1467 ((InternalFrameListener )listeners[i+1]).internalFrameClosed(e); 1468 break; 1469 case InternalFrameEvent.INTERNAL_FRAME_ICONIFIED: 1470 ((InternalFrameListener )listeners[i+1]).internalFrameIconified(e); 1471 break; 1472 case InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED: 1473 ((InternalFrameListener )listeners[i+1]).internalFrameDeiconified(e); 1474 break; 1475 case InternalFrameEvent.INTERNAL_FRAME_ACTIVATED: 1476 ((InternalFrameListener )listeners[i+1]).internalFrameActivated(e); 1477 break; 1478 case InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED: 1479 ((InternalFrameListener )listeners[i+1]).internalFrameDeactivated(e); 1480 break; 1481 default: 1482 break; 1483 } 1484 } 1485 } 1486 1488 } 1492 1493 1506 public void doDefaultCloseAction() { 1507 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING); 1508 switch(defaultCloseOperation) { 1509 case DO_NOTHING_ON_CLOSE: 1510 break; 1511 case HIDE_ON_CLOSE: 1512 setVisible(false); 1513 if (isSelected()) 1514 try { 1515 setSelected(false); 1516 } catch (PropertyVetoException pve) {} 1517 1518 1520 break; 1521 case DISPOSE_ON_CLOSE: 1522 try { 1523 fireVetoableChange(IS_CLOSED_PROPERTY, Boolean.FALSE, 1524 Boolean.TRUE); 1525 isClosed = true; 1526 firePropertyChange(IS_CLOSED_PROPERTY, Boolean.FALSE, 1527 Boolean.TRUE); 1528 dispose(); 1529 } catch (PropertyVetoException pve) {} 1530 break; 1531 default: 1532 break; 1533 } 1534 } 1535 1536 1572 public void setDefaultCloseOperation(int operation) { 1573 this.defaultCloseOperation = operation; 1574 } 1575 1576 1583 public int getDefaultCloseOperation() { 1584 return defaultCloseOperation; 1585 } 1586 1587 1596 public void pack() { 1597 try { 1598 if (isIcon()) { 1599 setIcon(false); 1600 } else if (isMaximum()) { 1601 setMaximum(false); 1602 } 1603 } catch(PropertyVetoException e) { 1604 return; 1605 } 1606 setSize(getPreferredSize()); 1607 validate(); 1608 } 1609 1610 1627 public void show() { 1628 if (isVisible()) { 1630 return; 1632 } 1633 1634 if (!opened) { 1636 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_OPENED); 1637 opened = true; 1638 } 1639 1640 1642 getDesktopIcon().setVisible(true); 1643 1644 toFront(); 1645 super.show(); 1646 1647 if (isIcon) { 1648 return; 1649 } 1650 1651 if (!isSelected()) { 1652 try { 1653 setSelected(true); 1654 } catch (PropertyVetoException pve) {} 1655 } 1656 } 1657 1658 public void hide() { 1659 if (isIcon()) { 1660 getDesktopIcon().setVisible(false); 1661 } 1662 super.hide(); 1663 } 1664 1665 1682 public void dispose() { 1683 if (isVisible()) { 1684 setVisible(false); 1685 } 1686 if (isSelected()) { 1687 try { 1688 setSelected(false); 1689 } catch (PropertyVetoException pve) {} 1690 } 1691 if (!isClosed) { 1692 firePropertyChange(IS_CLOSED_PROPERTY, Boolean.FALSE, Boolean.TRUE); 1693 isClosed = true; 1694 } 1695 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED); 1696 } 1697 1698 1707 public void toFront() { 1708 moveToFront(); 1709 } 1710 1711 1720 public void toBack() { 1721 moveToBack(); 1722 } 1723 1724 1734 public final void setFocusCycleRoot(boolean focusCycleRoot) { 1735 } 1736 1737 1747 public final boolean isFocusCycleRoot() { 1748 return true; 1749 } 1750 1751 1760 public final Container getFocusCycleRootAncestor() { 1761 return null; 1762 } 1763 1764 1772 public final String getWarningString() { 1773 return null; 1774 } 1775 1776 1781 private void writeObject(ObjectOutputStream s) throws IOException { 1782 s.defaultWriteObject(); 1783 if (getUIClassID().equals(uiClassID)) { 1784 byte count = JComponent.getWriteObjCounter(this); 1785 JComponent.setWriteObjCounter(this, --count); 1786 if (count == 0 && ui != null) { 1787 boolean old = isRootPaneCheckingEnabled(); 1788 try { 1789 setRootPaneCheckingEnabled(false); 1790 ui.installUI(this); 1791 } finally { 1792 setRootPaneCheckingEnabled(old); 1793 } 1794 } 1795 } 1796 } 1797 1798 1801 void compWriteObjectNotify() { 1802 boolean old = isRootPaneCheckingEnabled(); 1804 try { 1805 setRootPaneCheckingEnabled(false); 1806 super.compWriteObjectNotify(); 1807 } 1808 finally { 1809 setRootPaneCheckingEnabled(old); 1810 } 1811 } 1812 1813 1823 protected String paramString() { 1824 String rootPaneString = (rootPane != null ? 1825 rootPane.toString() : ""); 1826 String rootPaneCheckingEnabledString = (rootPaneCheckingEnabled ? 1827 "true" : "false"); 1828 String closableString = (closable ? "true" : "false"); 1829 String isClosedString = (isClosed ? "true" : "false"); 1830 String maximizableString = (maximizable ? "true" : "false"); 1831 String isMaximumString = (isMaximum ? "true" : "false"); 1832 String iconableString = (iconable ? "true" : "false"); 1833 String isIconString = (isIcon ? "true" : "false"); 1834 String resizableString = (resizable ? "true" : "false"); 1835 String isSelectedString = (isSelected ? "true" : "false"); 1836 String frameIconString = (frameIcon != null ? 1837 frameIcon.toString() : ""); 1838 String titleString = (title != null ? 1839 title : ""); 1840 String desktopIconString = (desktopIcon != null ? 1841 desktopIcon.toString() : ""); 1842 String openedString = (opened ? "true" : "false"); 1843 String defaultCloseOperationString; 1844 if (defaultCloseOperation == HIDE_ON_CLOSE) { 1845 defaultCloseOperationString = "HIDE_ON_CLOSE"; 1846 } else if (defaultCloseOperation == DISPOSE_ON_CLOSE) { 1847 defaultCloseOperationString = "DISPOSE_ON_CLOSE"; 1848 } else if (defaultCloseOperation == DO_NOTHING_ON_CLOSE) { 1849 defaultCloseOperationString = "DO_NOTHING_ON_CLOSE"; 1850 } else defaultCloseOperationString = ""; 1851 1852 return super.paramString() + 1853 ",closable=" + closableString + 1854 ",defaultCloseOperation=" + defaultCloseOperationString + 1855 ",desktopIcon=" + desktopIconString + 1856 ",frameIcon=" + frameIconString + 1857 ",iconable=" + iconableString + 1858 ",isClosed=" + isClosedString + 1859 ",isIcon=" + isIconString + 1860 ",isMaximum=" + isMaximumString + 1861 ",isSelected=" + isSelectedString + 1862 ",maximizable=" + maximizableString + 1863 ",opened=" + openedString + 1864 ",resizable=" + resizableString + 1865 ",rootPane=" + rootPaneString + 1866 ",rootPaneCheckingEnabled=" + rootPaneCheckingEnabledString + 1867 ",title=" + titleString; 1868 } 1869 1870 1872 boolean isDragging = false; 1873 boolean danger = false; 1874 1875 1879 protected void paintComponent(Graphics g) { 1880 if (isDragging) { 1881 danger = true; 1883 } 1884 1885 super.paintComponent(g); 1886 } 1887 1888 1890 1894 1907 public AccessibleContext getAccessibleContext() { 1908 if (accessibleContext == null) { 1909 accessibleContext = new AccessibleJInternalFrame(); 1910 } 1911 return accessibleContext; 1912 } 1913 1914 1929 protected class AccessibleJInternalFrame extends AccessibleJComponent 1930 implements AccessibleValue { 1931 1932 1939 public String getAccessibleName() { 1940 if (accessibleName != null) { 1941 return accessibleName; 1942 } else { 1943 return getTitle(); 1944 } 1945 } 1946 1947 1954 public AccessibleRole getAccessibleRole() { 1955 return AccessibleRole.INTERNAL_FRAME; 1956 } 1957 1958 1966 public AccessibleValue getAccessibleValue() { 1967 return this; 1968 } 1969 1970 1971 1975 1981 public Number getCurrentAccessibleValue() { 1982 return new Integer (getLayer()); 1983 } 1984 1985 1990 public boolean setCurrentAccessibleValue(Number n) { 1991 if (n == null) { 1993 return false; 1994 } 1995 setLayer(new Integer (n.intValue())); 1996 return true; 1997 } 1998 1999 2005 public Number getMinimumAccessibleValue() { 2006 return new Integer (Integer.MIN_VALUE); 2007 } 2008 2009 2015 public Number getMaximumAccessibleValue() { 2016 return new Integer (Integer.MAX_VALUE); 2017 } 2018 2019 } 2021 2042 static public class JDesktopIcon extends JComponent implements Accessible 2043 { 2044 JInternalFrame internalFrame; 2045 2046 2052 public JDesktopIcon(JInternalFrame f) { 2053 setVisible(false); 2054 setInternalFrame(f); 2055 updateUI(); 2056 } 2057 2058 2064 public DesktopIconUI getUI() { 2065 return (DesktopIconUI)ui; 2066 } 2067 2068 2074 public void setUI(DesktopIconUI ui) { 2075 super.setUI(ui); 2076 } 2077 2078 2085 public JInternalFrame getInternalFrame() { 2086 return internalFrame; 2087 } 2088 2089 2096 public void setInternalFrame(JInternalFrame f) { 2097 internalFrame = f; 2098 } 2099 2100 2107 public JDesktopPane getDesktopPane() { 2108 if(getInternalFrame() != null) 2109 return getInternalFrame().getDesktopPane(); 2110 return null; 2111 } 2112 2113 2121 public void updateUI() { 2122 boolean hadUI = (ui != null); 2123 setUI((DesktopIconUI)UIManager.getUI(this)); 2124 invalidate(); 2125 2126 Dimension r = getPreferredSize(); 2127 setSize(r.width, r.height); 2128 2129 2130 if (internalFrame != null && internalFrame.getUI() != null) { SwingUtilities.updateComponentTreeUI(internalFrame); 2132 } 2133 } 2134 2135 2138 void updateUIWhenHidden() { 2139 2140 setUI((DesktopIconUI)UIManager.getUI(this)); 2141 2142 Dimension r = getPreferredSize(); 2143 setSize(r.width, r.height); 2144 2145 invalidate(); 2146 Component[] children = getComponents(); 2147 if (children != null) { 2148 for(int i = 0; i < children.length; i++) { 2149 SwingUtilities.updateComponentTreeUI(children[i]); 2150 } 2151 } 2152 } 2153 2154 2162 public String getUIClassID() { 2163 return "DesktopIconUI"; 2164 } 2165 private void writeObject(ObjectOutputStream s) throws IOException { 2169 s.defaultWriteObject(); 2170 if (getUIClassID().equals("DesktopIconUI")) { 2171 byte count = JComponent.getWriteObjCounter(this); 2172 JComponent.setWriteObjCounter(this, --count); 2173 if (count == 0 && ui != null) { 2174 ui.installUI(this); 2175 } 2176 } 2177 } 2178 2179 2183 2192 public AccessibleContext getAccessibleContext() { 2193 if (accessibleContext == null) { 2194 accessibleContext = new AccessibleJDesktopIcon(); 2195 } 2196 return accessibleContext; 2197 } 2198 2199 2214 protected class AccessibleJDesktopIcon extends AccessibleJComponent 2215 implements AccessibleValue { 2216 2217 2224 public AccessibleRole getAccessibleRole() { 2225 return AccessibleRole.DESKTOP_ICON; 2226 } 2227 2228 2236 public AccessibleValue getAccessibleValue() { 2237 return this; 2238 } 2239 2240 2244 2250 public Number getCurrentAccessibleValue() { 2251 AccessibleContext a = JDesktopIcon.this.getInternalFrame().getAccessibleContext(); 2252 AccessibleValue v = a.getAccessibleValue(); 2253 if (v != null) { 2254 return v.getCurrentAccessibleValue(); 2255 } else { 2256 return null; 2257 } 2258 } 2259 2260 2265 public boolean setCurrentAccessibleValue(Number n) { 2266 if (n == null) { 2268 return false; 2269 } 2270 AccessibleContext a = JDesktopIcon.this.getInternalFrame().getAccessibleContext(); 2271 AccessibleValue v = a.getAccessibleValue(); 2272 if (v != null) { 2273 return v.setCurrentAccessibleValue(n); 2274 } else { 2275 return false; 2276 } 2277 } 2278 2279 2285 public Number getMinimumAccessibleValue() { 2286 AccessibleContext a = JDesktopIcon.this.getInternalFrame().getAccessibleContext(); 2287 if (a instanceof AccessibleValue) { 2288 return ((AccessibleValue)a).getMinimumAccessibleValue(); 2289 } else { 2290 return null; 2291 } 2292 } 2293 2294 2300 public Number getMaximumAccessibleValue() { 2301 AccessibleContext a = JDesktopIcon.this.getInternalFrame().getAccessibleContext(); 2302 if (a instanceof AccessibleValue) { 2303 return ((AccessibleValue)a).getMaximumAccessibleValue(); 2304 } else { 2305 return null; 2306 } 2307 } 2308 2309 } } 2311} 2312 | Popular Tags |