| 1 7 8 package javax.swing.plaf.basic; 9 10 import java.awt.Font ; 11 import java.awt.Color ; 12 import java.awt.SystemColor ; 13 import java.awt.event.*; 14 import java.awt.Insets ; 15 import java.awt.Component ; 16 import java.awt.Container ; 17 import java.awt.FocusTraversalPolicy ; 18 import java.awt.AWTEvent ; 19 import java.awt.Toolkit ; 20 import java.awt.Point ; 21 import java.net.URL ; 22 import java.io.*; 23 import java.awt.Dimension ; 24 import java.awt.KeyboardFocusManager ; 25 import java.security.AccessController ; 26 import java.security.PrivilegedAction ; 27 import java.util.*; 28 import java.lang.reflect.*; 29 import javax.sound.sampled.*; 30 31 import sun.awt.AppContext; 32 33 import sun.swing.SwingLazyValue; 34 import com.sun.java.swing.SwingUtilities2; 35 36 import javax.swing.LookAndFeel ; 37 import javax.swing.AbstractAction ; 38 import javax.swing.Action ; 39 import javax.swing.ActionMap ; 40 import javax.swing.BorderFactory ; 41 import javax.swing.JComponent ; 42 import javax.swing.ImageIcon ; 43 import javax.swing.UIDefaults ; 44 import javax.swing.UIManager ; 45 import javax.swing.KeyStroke ; 46 import javax.swing.JTextField ; 47 import javax.swing.DefaultListCellRenderer ; 48 import javax.swing.FocusManager ; 49 import javax.swing.LayoutFocusTraversalPolicy ; 50 import javax.swing.SwingUtilities ; 51 import javax.swing.MenuSelectionManager ; 52 import javax.swing.MenuElement ; 53 import javax.swing.border.*; 54 import javax.swing.plaf.*; 55 import javax.swing.text.JTextComponent ; 56 import javax.swing.text.DefaultEditorKit ; 57 import java.beans.PropertyChangeListener ; 58 import java.beans.PropertyChangeEvent ; 59 60 61 79 public abstract class BasicLookAndFeel extends LookAndFeel implements Serializable 80 { 81 84 static boolean hasPopups; 85 86 89 private Object audioLock = new Object (); 90 93 private Clip clipPlaying; 94 95 PopupInvocationHelper invocator = null; 96 97 100 private PropertyChangeListener disposer = null; 101 102 public UIDefaults getDefaults() { 103 UIDefaults table = new UIDefaults (); 104 105 initClassDefaults(table); 106 initSystemColorDefaults(table); 107 initComponentDefaults(table); 108 109 return table; 110 } 111 112 116 public void initialize() { 117 if (hasPopups) { 118 createdPopup(); 119 } 120 } 121 122 126 public void uninitialize() { 127 Toolkit tk = Toolkit.getDefaultToolkit(); 128 if(invocator != null) { 129 AccessController.doPrivileged(invocator); 130 invocator = null; 131 } 132 133 if (disposer != null) { 134 AppContext.getAppContext().removePropertyChangeListener( 139 AppContext.GUI_DISPOSED, 140 disposer); 141 disposer = null; 142 } 143 } 144 145 154 protected void initClassDefaults(UIDefaults table) 155 { 156 final String basicPackageName = "javax.swing.plaf.basic."; 157 Object [] uiDefaults = { 158 "ButtonUI", basicPackageName + "BasicButtonUI", 159 "CheckBoxUI", basicPackageName + "BasicCheckBoxUI", 160 "ColorChooserUI", basicPackageName + "BasicColorChooserUI", 161 "FormattedTextFieldUI", basicPackageName + "BasicFormattedTextFieldUI", 162 "MenuBarUI", basicPackageName + "BasicMenuBarUI", 163 "MenuUI", basicPackageName + "BasicMenuUI", 164 "MenuItemUI", basicPackageName + "BasicMenuItemUI", 165 "CheckBoxMenuItemUI", basicPackageName + "BasicCheckBoxMenuItemUI", 166 "RadioButtonMenuItemUI", basicPackageName + "BasicRadioButtonMenuItemUI", 167 "RadioButtonUI", basicPackageName + "BasicRadioButtonUI", 168 "ToggleButtonUI", basicPackageName + "BasicToggleButtonUI", 169 "PopupMenuUI", basicPackageName + "BasicPopupMenuUI", 170 "ProgressBarUI", basicPackageName + "BasicProgressBarUI", 171 "ScrollBarUI", basicPackageName + "BasicScrollBarUI", 172 "ScrollPaneUI", basicPackageName + "BasicScrollPaneUI", 173 "SplitPaneUI", basicPackageName + "BasicSplitPaneUI", 174 "SliderUI", basicPackageName + "BasicSliderUI", 175 "SeparatorUI", basicPackageName + "BasicSeparatorUI", 176 "SpinnerUI", basicPackageName + "BasicSpinnerUI", 177 "ToolBarSeparatorUI", basicPackageName + "BasicToolBarSeparatorUI", 178 "PopupMenuSeparatorUI", basicPackageName + "BasicPopupMenuSeparatorUI", 179 "TabbedPaneUI", basicPackageName + "BasicTabbedPaneUI", 180 "TextAreaUI", basicPackageName + "BasicTextAreaUI", 181 "TextFieldUI", basicPackageName + "BasicTextFieldUI", 182 "PasswordFieldUI", basicPackageName + "BasicPasswordFieldUI", 183 "TextPaneUI", basicPackageName + "BasicTextPaneUI", 184 "EditorPaneUI", basicPackageName + "BasicEditorPaneUI", 185 "TreeUI", basicPackageName + "BasicTreeUI", 186 "LabelUI", basicPackageName + "BasicLabelUI", 187 "ListUI", basicPackageName + "BasicListUI", 188 "ToolBarUI", basicPackageName + "BasicToolBarUI", 189 "ToolTipUI", basicPackageName + "BasicToolTipUI", 190 "ComboBoxUI", basicPackageName + "BasicComboBoxUI", 191 "TableUI", basicPackageName + "BasicTableUI", 192 "TableHeaderUI", basicPackageName + "BasicTableHeaderUI", 193 "InternalFrameUI", basicPackageName + "BasicInternalFrameUI", 194 "DesktopPaneUI", basicPackageName + "BasicDesktopPaneUI", 195 "DesktopIconUI", basicPackageName + "BasicDesktopIconUI", 196 "OptionPaneUI", basicPackageName + "BasicOptionPaneUI", 197 "PanelUI", basicPackageName + "BasicPanelUI", 198 "ViewportUI", basicPackageName + "BasicViewportUI", 199 "RootPaneUI", basicPackageName + "BasicRootPaneUI", 200 }; 201 202 table.putDefaults(uiDefaults); 203 } 204 205 213 protected void initSystemColorDefaults(UIDefaults table) 214 { 215 String [] defaultSystemColors = { 216 "desktop", "#005C5C", 217 "activeCaption", "#000080", 218 "activeCaptionText", "#FFFFFF", 219 "activeCaptionBorder", "#C0C0C0", 220 "inactiveCaption", "#808080", 221 "inactiveCaptionText", "#C0C0C0", 222 "inactiveCaptionBorder", "#C0C0C0", 223 "window", "#FFFFFF", 224 "windowBorder", "#000000", 225 "windowText", "#000000", 226 "menu", "#C0C0C0", 227 "menuText", "#000000", 228 "text", "#C0C0C0", 229 "textText", "#000000", 230 "textHighlight", "#000080", 231 "textHighlightText", "#FFFFFF", 232 "textInactiveText", "#808080", 233 "control", "#C0C0C0", 234 "controlText", "#000000", 235 "controlHighlight", "#C0C0C0", 236 "controlLtHighlight", "#FFFFFF", 237 "controlShadow", "#808080", 238 "controlDkShadow", "#000000", 239 "scrollbar", "#E0E0E0", 240 "info", "#FFFFE1", 241 "infoText", "#000000" 242 }; 243 244 loadSystemColors(table, defaultSystemColors, isNativeLookAndFeel()); 245 } 246 247 248 254 protected void loadSystemColors(UIDefaults table, String [] systemColors, boolean useNative) 255 { 256 260 if (useNative) { 261 for(int i = 0; i < systemColors.length; i += 2) { 262 Color color = Color.black; 263 try { 264 String name = systemColors[i]; 265 color = (Color )(SystemColor .class.getField(name).get(null)); 266 } catch (Exception e) { 267 } 268 table.put(systemColors[i], new ColorUIResource(color)); 269 } 270 } else { 271 for(int i = 0; i < systemColors.length; i += 2) { 272 Color color = Color.black; 273 try { 274 color = Color.decode(systemColors[i + 1]); 275 } 276 catch(NumberFormatException e) { 277 e.printStackTrace(); 278 } 279 table.put(systemColors[i], new ColorUIResource(color)); 280 } 281 } 282 } 283 290 private void initResourceBundle(UIDefaults table) { 291 table.setDefaultLocale( Locale.getDefault() ); 292 table.addResourceBundle( "com.sun.swing.internal.plaf.basic.resources.basic" ); 293 } 294 295 protected void initComponentDefaults(UIDefaults table) 296 { 297 298 initResourceBundle(table); 299 300 Integer fiveHundred = new Integer (500); 302 303 Long oneThousand = new Long (1000); 305 306 Integer twelve = new Integer (12); 308 Integer fontPlain = new Integer (Font.PLAIN); 309 Integer fontBold = new Integer (Font.BOLD); 310 Object dialogPlain12 = new SwingLazyValue( 311 "javax.swing.plaf.FontUIResource", 312 null, 313 new Object [] {"Dialog", fontPlain, twelve}); 314 Object serifPlain12 = new SwingLazyValue( 315 "javax.swing.plaf.FontUIResource", 316 null, 317 new Object [] {"Serif", fontPlain, twelve}); 318 Object sansSerifPlain12 = new SwingLazyValue( 319 "javax.swing.plaf.FontUIResource", 320 null, 321 new Object [] {"SansSerif", fontPlain, twelve}); 322 Object monospacedPlain12 = new SwingLazyValue( 323 "javax.swing.plaf.FontUIResource", 324 null, 325 new Object [] {"MonoSpaced", fontPlain, twelve}); 326 Object dialogBold12 = new SwingLazyValue( 327 "javax.swing.plaf.FontUIResource", 328 null, 329 new Object [] {"Dialog", fontBold, twelve}); 330 331 332 ColorUIResource red = new ColorUIResource(Color.red); 334 ColorUIResource black = new ColorUIResource(Color.black); 335 ColorUIResource white = new ColorUIResource(Color.white); 336 ColorUIResource yellow = new ColorUIResource(Color.yellow); 337 ColorUIResource gray = new ColorUIResource(Color.gray); 338 ColorUIResource lightGray = new ColorUIResource(Color.lightGray); 339 ColorUIResource darkGray = new ColorUIResource(Color.darkGray); 340 ColorUIResource scrollBarTrack = new ColorUIResource(224, 224, 224); 341 342 Color control = table.getColor("control"); 343 Color controlDkShadow = table.getColor("controlDkShadow"); 344 Color controlHighlight = table.getColor("controlHighlight"); 345 Color controlLtHighlight = table.getColor("controlLtHighlight"); 346 Color controlShadow = table.getColor("controlShadow"); 347 Color controlText = table.getColor("controlText"); 348 Color menu = table.getColor("menu"); 349 Color menuText = table.getColor("menuText"); 350 Color textHighlight = table.getColor("textHighlight"); 351 Color textHighlightText = table.getColor("textHighlightText"); 352 Color textInactiveText = table.getColor("textInactiveText"); 353 Color textText = table.getColor("textText"); 354 Color window = table.getColor("window"); 355 356 InsetsUIResource zeroInsets = new InsetsUIResource(0,0,0,0); 358 InsetsUIResource twoInsets = new InsetsUIResource(2, 2, 2, 2); 359 360 Object marginBorder = new SwingLazyValue( 362 "javax.swing.plaf.basic.BasicBorders$MarginBorder"); 363 Object etchedBorder = new SwingLazyValue( 364 "javax.swing.plaf.BorderUIResource", 365 "getEtchedBorderUIResource"); 366 Object loweredBevelBorder = new SwingLazyValue( 367 "javax.swing.plaf.BorderUIResource", 368 "getLoweredBevelBorderUIResource"); 369 370 Object popupMenuBorder = new SwingLazyValue( 371 "javax.swing.plaf.basic.BasicBorders", 372 "getInternalFrameBorder"); 373 374 Object blackLineBorder = new SwingLazyValue( 375 "javax.swing.plaf.BorderUIResource", 376 "getBlackLineBorderUIResource"); 377 Object focusCellHighlightBorder = new SwingLazyValue( 378 "javax.swing.plaf.BorderUIResource$LineBorderUIResource", 379 null, 380 new Object [] {yellow}); 381 382 383 Object tableHeaderBorder = new SwingLazyValue( 384 "javax.swing.plaf.BorderUIResource$BevelBorderUIResource", 385 null, 386 new Object [] { new Integer (BevelBorder.RAISED), 387 controlLtHighlight, 388 control, 389 controlDkShadow, 390 controlShadow }); 391 392 393 395 Object buttonBorder = 396 new SwingLazyValue( 397 "javax.swing.plaf.basic.BasicBorders", 398 "getButtonBorder"); 399 400 Object buttonToggleBorder = 401 new SwingLazyValue( 402 "javax.swing.plaf.basic.BasicBorders", 403 "getToggleButtonBorder"); 404 405 Object radioButtonBorder = 406 new SwingLazyValue( 407 "javax.swing.plaf.basic.BasicBorders", 408 "getRadioButtonBorder"); 409 410 412 Object newFolderIcon = SwingUtilities2.makeIcon(getClass(), 413 BasicLookAndFeel .class, 414 "icons/NewFolder.gif"); 415 Object upFolderIcon = SwingUtilities2.makeIcon(getClass(), 416 BasicLookAndFeel .class, 417 "icons/UpFolder.gif"); 418 Object homeFolderIcon = SwingUtilities2.makeIcon(getClass(), 419 BasicLookAndFeel .class, 420 "icons/HomeFolder.gif"); 421 Object detailsViewIcon = SwingUtilities2.makeIcon(getClass(), 422 BasicLookAndFeel .class, 423 "icons/DetailsView.gif"); 424 Object listViewIcon = SwingUtilities2.makeIcon(getClass(), 425 BasicLookAndFeel .class, 426 "icons/ListView.gif"); 427 Object directoryIcon = SwingUtilities2.makeIcon(getClass(), 428 BasicLookAndFeel .class, 429 "icons/Directory.gif"); 430 Object fileIcon = SwingUtilities2.makeIcon(getClass(), 431 BasicLookAndFeel .class, 432 "icons/File.gif"); 433 Object computerIcon = SwingUtilities2.makeIcon(getClass(), 434 BasicLookAndFeel .class, 435 "icons/Computer.gif"); 436 Object hardDriveIcon = SwingUtilities2.makeIcon(getClass(), 437 BasicLookAndFeel .class, 438 "icons/HardDrive.gif"); 439 Object floppyDriveIcon = SwingUtilities2.makeIcon(getClass(), 440 BasicLookAndFeel .class, 441 "icons/FloppyDrive.gif"); 442 443 444 446 Object internalFrameBorder = new SwingLazyValue( 447 "javax.swing.plaf.basic.BasicBorders", 448 "getInternalFrameBorder"); 449 450 452 Object listCellRendererActiveValue = new UIDefaults.ActiveValue () { 453 public Object createValue(UIDefaults table) { 454 return new DefaultListCellRenderer.UIResource (); 455 } 456 }; 457 458 459 461 Object menuBarBorder = 462 new SwingLazyValue( 463 "javax.swing.plaf.basic.BasicBorders", 464 "getMenuBarBorder"); 465 466 Object menuItemCheckIcon = 467 new SwingLazyValue( 468 "javax.swing.plaf.basic.BasicIconFactory", 469 "getMenuItemCheckIcon"); 470 471 Object menuItemArrowIcon = 472 new SwingLazyValue( 473 "javax.swing.plaf.basic.BasicIconFactory", 474 "getMenuItemArrowIcon"); 475 476 477 Object menuArrowIcon = 478 new SwingLazyValue( 479 "javax.swing.plaf.basic.BasicIconFactory", 480 "getMenuArrowIcon"); 481 482 Object checkBoxIcon = 483 new SwingLazyValue( 484 "javax.swing.plaf.basic.BasicIconFactory", 485 "getCheckBoxIcon"); 486 487 Object radioButtonIcon = 488 new SwingLazyValue( 489 "javax.swing.plaf.basic.BasicIconFactory", 490 "getRadioButtonIcon"); 491 492 Object checkBoxMenuItemIcon = 493 new SwingLazyValue( 494 "javax.swing.plaf.basic.BasicIconFactory", 495 "getCheckBoxMenuItemIcon"); 496 497 Object radioButtonMenuItemIcon = 498 new SwingLazyValue( 499 "javax.swing.plaf.basic.BasicIconFactory", 500 "getRadioButtonMenuItemIcon"); 501 502 Object menuItemAcceleratorDelimiter = new String ("+"); 503 504 506 Object optionPaneMinimumSize = new DimensionUIResource(262, 90); 507 508 Integer zero = new Integer (0); 509 Object zeroBorder = new SwingLazyValue( 510 "javax.swing.plaf.BorderUIResource$EmptyBorderUIResource", 511 new Object [] {zero, zero, zero, zero}); 512 513 Integer ten = new Integer (10); 514 Object optionPaneBorder = new SwingLazyValue( 515 "javax.swing.plaf.BorderUIResource$EmptyBorderUIResource", 516 new Object [] {ten, ten, twelve, ten}); 517 518 Object optionPaneButtonAreaBorder = new SwingLazyValue( 519 "javax.swing.plaf.BorderUIResource$EmptyBorderUIResource", 520 new Object [] {new Integer (6), zero, zero, zero}); 521 522 523 525 Object progressBarBorder = 526 new SwingLazyValue( 527 "javax.swing.plaf.basic.BasicBorders", 528 "getProgressBarBorder"); 529 530 532 Object minimumThumbSize = new DimensionUIResource(8,8); 533 Object maximumThumbSize = new DimensionUIResource(4096,4096); 534 535 537 Object sliderFocusInsets = twoInsets; 538 539 Object toolBarSeparatorSize = new DimensionUIResource( 10, 10 ); 540 541 542 544 Object splitPaneBorder = 545 new SwingLazyValue( 546 "javax.swing.plaf.basic.BasicBorders", 547 "getSplitPaneBorder"); 548 Object splitPaneDividerBorder = 549 new SwingLazyValue( 550 "javax.swing.plaf.basic.BasicBorders", 551 "getSplitPaneDividerBorder"); 552 553 555 Object tabbedPaneTabInsets = new InsetsUIResource(0, 4, 1, 4); 556 557 Object tabbedPaneTabPadInsets = new InsetsUIResource(2, 2, 2, 1); 558 559 Object tabbedPaneTabAreaInsets = new InsetsUIResource(3, 2, 0, 2); 560 561 Object tabbedPaneContentBorderInsets = new InsetsUIResource(2, 2, 3, 3); 562 563 564 566 Object textFieldBorder = 567 new SwingLazyValue( 568 "javax.swing.plaf.basic.BasicBorders", 569 "getTextFieldBorder"); 570 571 Object editorMargin = new InsetsUIResource(3,3,3,3); 572 573 Object caretBlinkRate = fiveHundred; 574 Integer four = new Integer (4); 575 576 Object [] allAuditoryCues = new Object [] { 577 "CheckBoxMenuItem.commandSound", 578 "InternalFrame.closeSound", 579 "InternalFrame.maximizeSound", 580 "InternalFrame.minimizeSound", 581 "InternalFrame.restoreDownSound", 582 "InternalFrame.restoreUpSound", 583 "MenuItem.commandSound", 584 "OptionPane.errorSound", 585 "OptionPane.informationSound", 586 "OptionPane.questionSound", 587 "OptionPane.warningSound", 588 "PopupMenu.popupSound", 589 "RadioButtonMenuItem.commandSound"}; 590 591 Object [] noAuditoryCues = new Object [] {"mute"}; 592 593 595 Object [] defaults = { 596 "AuditoryCues.cueList", allAuditoryCues, 598 "AuditoryCues.allAuditoryCues", allAuditoryCues, 599 "AuditoryCues.noAuditoryCues", noAuditoryCues, 600 "AuditoryCues.playList", null, 603 604 "Button.defaultButtonFollowsFocus", Boolean.TRUE, 606 "Button.font", dialogPlain12, 607 "Button.background", control, 608 "Button.foreground", controlText, 609 "Button.shadow", controlShadow, 610 "Button.darkShadow", controlDkShadow, 611 "Button.light", controlHighlight, 612 "Button.highlight", controlLtHighlight, 613 "Button.border", buttonBorder, 614 "Button.margin", new InsetsUIResource(2, 14, 2, 14), 615 "Button.textIconGap", four, 616 "Button.textShiftOffset", zero, 617 "Button.focusInputMap", new UIDefaults.LazyInputMap (new Object [] { 618 "SPACE", "pressed", 619 "released SPACE", "released", 620 "ENTER", "pressed", 621 "released ENTER", "released" 622 }), 623 624 "ToggleButton.font", dialogPlain12, 625 "ToggleButton.background", control, 626 "ToggleButton.foreground", controlText, 627 "ToggleButton.shadow", controlShadow, 628 "ToggleButton.darkShadow", controlDkShadow, 629 "ToggleButton.light", controlHighlight, 630 "ToggleButton.highlight", controlLtHighlight, 631 "ToggleButton.border", buttonToggleBorder, 632 "ToggleButton.margin", new InsetsUIResource(2, 14, 2, 14), 633 "ToggleButton.textIconGap", four, 634 "ToggleButton.textShiftOffset", zero, 635 "ToggleButton.focusInputMap", 636 new UIDefaults.LazyInputMap (new Object [] { 637 "SPACE", "pressed", 638 "released SPACE", "released" 639 }), 640 641 "RadioButton.font", dialogPlain12, 642 "RadioButton.background", control, 643 "RadioButton.foreground", controlText, 644 "RadioButton.shadow", controlShadow, 645 "RadioButton.darkShadow", controlDkShadow, 646 "RadioButton.light", controlHighlight, 647 "RadioButton.highlight", controlLtHighlight, 648 "RadioButton.border", radioButtonBorder, 649 "RadioButton.margin", twoInsets, 650 "RadioButton.textIconGap", four, 651 "RadioButton.textShiftOffset", zero, 652 "RadioButton.icon", radioButtonIcon, 653 "RadioButton.focusInputMap", 654 new UIDefaults.LazyInputMap (new Object [] { 655 "SPACE", "pressed", 656 |