| 1 7 8 22 23 package com.sun.java.swing.plaf.windows; 24 25 import java.awt.*; 26 import javax.swing.plaf.*; 27 import javax.swing.*; 28 import javax.swing.plaf.basic.*; 29 import javax.swing.border.*; 30 import javax.swing.text.JTextComponent ; 31 import javax.swing.text.DefaultEditorKit ; 32 33 import java.awt.Font ; 34 import java.awt.Color ; 35 import java.awt.SystemColor ; 36 import java.awt.event.KeyEvent ; 37 import java.awt.event.InputEvent ; 38 import java.awt.event.ActionEvent ; 39 40 import java.beans.PropertyChangeListener ; 41 import java.beans.PropertyChangeEvent ; 42 43 import java.net.URL ; 44 import java.io.Serializable ; 45 import java.security.AccessController ; 46 import java.util.*; 47 48 import sun.awt.shell.ShellFolder; 49 import sun.font.FontManager; 50 import sun.security.action.GetPropertyAction; 51 52 import sun.swing.SwingLazyValue; 53 import sun.swing.BorderProvider; 54 import com.sun.java.swing.SwingUtilities2; 55 56 import com.sun.java.swing.plaf.windows.TMSchema.*; 57 import com.sun.java.swing.plaf.windows.XPStyle.Skin; 58 59 import com.sun.java.swing.plaf.windows.WindowsIconFactory 60 .VistaMenuItemCheckIconFactory; 61 62 77 public class WindowsLookAndFeel extends BasicLookAndFeel 78 { 79 private Toolkit toolkit; 80 private boolean updatePending = false; 81 82 private boolean useSystemFontSettings = true; 83 private boolean useSystemFontSizeSettings; 84 85 private DesktopProperty themeActive, dllName, colorName, sizeName; 88 89 public String getName() { 90 return "Windows"; 91 } 92 93 public String getDescription() { 94 return "The Microsoft Windows Look and Feel"; 95 } 96 97 public String getID() { 98 return "Windows"; 99 } 100 101 public boolean isNativeLookAndFeel() { 102 String osName = System.getProperty("os.name"); 103 return (osName != null) && (osName.indexOf("Windows") != -1); 104 } 105 106 public boolean isSupportedLookAndFeel() { 107 return isNativeLookAndFeel(); 108 } 109 110 public void initialize() { 111 super.initialize(); 112 toolkit = Toolkit.getDefaultToolkit(); 113 114 String osVersion = System.getProperty("os.version"); 118 if (osVersion != null) { 119 Float version = Float.valueOf(osVersion); 120 if (version.floatValue() <= 4.0) { 121 isClassicWindows = true; 122 } else { 123 isClassicWindows = false; 124 XPStyle.invalidateStyle(); 125 } 126 } 127 128 String systemFonts = (String ) java.security.AccessController.doPrivileged( 133 new GetPropertyAction("swing.useSystemFontSettings")); 134 useSystemFontSettings = (systemFonts == null || 135 Boolean.valueOf(systemFonts).booleanValue()); 136 137 if (useSystemFontSettings) { 138 Object value = UIManager.get("Application.useSystemFontSettings"); 139 140 useSystemFontSettings = (value == null || 141 Boolean.TRUE.equals(value)); 142 } 143 KeyboardFocusManager.getCurrentKeyboardFocusManager(). 144 addKeyEventPostProcessor(WindowsRootPaneUI.altProcessor); 145 146 } 147 148 157 protected void initClassDefaults(UIDefaults table) 158 { 159 super.initClassDefaults(table); 160 161 final String windowsPackageName = "com.sun.java.swing.plaf.windows."; 162 163 Object [] uiDefaults = { 164 "ButtonUI", windowsPackageName + "WindowsButtonUI", 165 "CheckBoxUI", windowsPackageName + "WindowsCheckBoxUI", 166 "CheckBoxMenuItemUI", windowsPackageName + "WindowsCheckBoxMenuItemUI", 167 "LabelUI", windowsPackageName + "WindowsLabelUI", 168 "RadioButtonUI", windowsPackageName + "WindowsRadioButtonUI", 169 "RadioButtonMenuItemUI", windowsPackageName + "WindowsRadioButtonMenuItemUI", 170 "ToggleButtonUI", windowsPackageName + "WindowsToggleButtonUI", 171 "ProgressBarUI", windowsPackageName + "WindowsProgressBarUI", 172 "SliderUI", windowsPackageName + "WindowsSliderUI", 173 "SeparatorUI", windowsPackageName + "WindowsSeparatorUI", 174 "SplitPaneUI", windowsPackageName + "WindowsSplitPaneUI", 175 "SpinnerUI", windowsPackageName + "WindowsSpinnerUI", 176 "TabbedPaneUI", windowsPackageName + "WindowsTabbedPaneUI", 177 "TextAreaUI", windowsPackageName + "WindowsTextAreaUI", 178 "TextFieldUI", windowsPackageName + "WindowsTextFieldUI", 179 "PasswordFieldUI", windowsPackageName + "WindowsPasswordFieldUI", 180 "TextPaneUI", windowsPackageName + "WindowsTextPaneUI", 181 "EditorPaneUI", windowsPackageName + "WindowsEditorPaneUI", 182 "TreeUI", windowsPackageName + "WindowsTreeUI", 183 "ToolBarUI", windowsPackageName + "WindowsToolBarUI", 184 "ToolBarSeparatorUI", windowsPackageName + "WindowsToolBarSeparatorUI", 185 "ComboBoxUI", windowsPackageName + "WindowsComboBoxUI", 186 "TableHeaderUI", windowsPackageName + "WindowsTableHeaderUI", 187 "InternalFrameUI", windowsPackageName + "WindowsInternalFrameUI", 188 "DesktopPaneUI", windowsPackageName + "WindowsDesktopPaneUI", 189 "DesktopIconUI", windowsPackageName + "WindowsDesktopIconUI", 190 "FileChooserUI", windowsPackageName + "WindowsFileChooserUI", 191 "MenuUI", windowsPackageName + "WindowsMenuUI", 192 "MenuItemUI", windowsPackageName + "WindowsMenuItemUI", 193 "MenuBarUI", windowsPackageName + "WindowsMenuBarUI", 194 "PopupMenuUI", windowsPackageName + "WindowsPopupMenuUI", 195 "PopupMenuSeparatorUI", windowsPackageName + "WindowsPopupMenuSeparatorUI", 196 "ScrollBarUI", windowsPackageName + "WindowsScrollBarUI", 197 "RootPaneUI", windowsPackageName + "WindowsRootPaneUI" 198 }; 199 200 table.putDefaults(uiDefaults); 201 } 202 203 211 protected void initSystemColorDefaults(UIDefaults table) 212 { 213 String [] defaultSystemColors = { 214 "desktop", "#005C5C", 215 "activeCaption", "#000080", 216 "activeCaptionText", "#FFFFFF", 217 "activeCaptionBorder", "#C0C0C0", 218 "inactiveCaption", "#808080", 219 "inactiveCaptionText", "#C0C0C0", 220 "inactiveCaptionBorder", "#C0C0C0", 221 "window", "#FFFFFF", 222 "windowBorder", "#000000", 223 "windowText", "#000000", 224 "menu", "#C0C0C0", 225 "menuPressedItemB", "#000080", 226 "menuPressedItemF", "#FFFFFF", 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 237 238 "controlLtHighlight", "#FFFFFF", 239 "controlShadow", "#808080", 240 "controlDkShadow", "#000000", 241 "scrollbar", "#E0E0E0", 242 "info", "#FFFFE1", 243 "infoText", "#000000" 244 }; 245 246 loadSystemColors(table, defaultSystemColors, isNativeLookAndFeel()); 247 } 248 249 253 private void initResourceBundle(UIDefaults table) { 254 table.addResourceBundle( "com.sun.java.swing.plaf.windows.resources.windows" ); 255 } 256 257 protected void initComponentDefaults(UIDefaults table) 260 { 261 super.initComponentDefaults( table ); 262 263 initResourceBundle(table); 264 265 Integer twelve = new Integer (12); 267 Integer eight = new Integer (8); 268 Integer ten = new Integer (10); 269 Integer fontPlain = new Integer (Font.PLAIN); 270 Integer fontBold = new Integer (Font.BOLD); 271 272 Object dialogPlain12 = new SwingLazyValue( 273 "javax.swing.plaf.FontUIResource", 274 null, 275 new Object [] {"Dialog", fontPlain, twelve}); 276 277 Object sansSerifPlain12 = new SwingLazyValue( 278 "javax.swing.plaf.FontUIResource", 279 null, 280 new Object [] {"SansSerif", fontPlain, twelve}); 281 Object monospacedPlain12 = new SwingLazyValue( 282 "javax.swing.plaf.FontUIResource", 283 null, 284 new Object [] {"MonoSpaced", fontPlain, twelve}); 285 Object dialogBold12 = new SwingLazyValue( 286 "javax.swing.plaf.FontUIResource", 287 null, 288 new Object [] {"Dialog", fontBold, twelve}); 289 290 ColorUIResource red = new ColorUIResource(Color.red); 293 ColorUIResource black = new ColorUIResource(Color.black); 294 ColorUIResource white = new ColorUIResource(Color.white); 295 ColorUIResource yellow = new ColorUIResource(Color.yellow); 296 ColorUIResource gray = new ColorUIResource(Color.gray); 297 ColorUIResource lightGray = new ColorUIResource(Color.lightGray); 298 ColorUIResource darkGray = new ColorUIResource(Color.darkGray); 299 ColorUIResource scrollBarTrack = lightGray; 300 ColorUIResource scrollBarTrackHighlight = darkGray; 301 302 String osVersion = System.getProperty("os.version"); 306 if (osVersion != null) { 307 try { 308 Float version = Float.valueOf(osVersion); 309 if (version.floatValue() <= 4.0) { 310 isClassicWindows = true; 311 } else { 312 isClassicWindows = false; 313 } 314 } catch (NumberFormatException ex) { 315 isClassicWindows = false; 316 } 317 } 318 319 ColorUIResource treeSelection = new ColorUIResource(0, 0, 128); 321 Object treeExpandedIcon = WindowsTreeUI.ExpandedIcon.createExpandedIcon(); 322 323 Object treeCollapsedIcon = WindowsTreeUI.CollapsedIcon.createCollapsedIcon(); 324 325 326 Object fieldInputMap = new UIDefaults.LazyInputMap(new Object [] { 328 "control C", DefaultEditorKit.copyAction, 329 "control V", DefaultEditorKit.pasteAction, 330 "control X", DefaultEditorKit.cutAction, 331 "COPY", DefaultEditorKit.copyAction, 332 "PASTE", DefaultEditorKit.pasteAction, 333 "CUT", DefaultEditorKit.cutAction, 334 "control INSERT", DefaultEditorKit.copyAction, 335 "shift INSERT", DefaultEditorKit.pasteAction, 336 "shift DELETE", DefaultEditorKit.cutAction, 337 "control A", DefaultEditorKit.selectAllAction, 338 "control BACK_SLASH", "unselect", 339 "shift LEFT", DefaultEditorKit.selectionBackwardAction, 340 "shift RIGHT", DefaultEditorKit.selectionForwardAction, 341 "control LEFT", DefaultEditorKit.previousWordAction, 342 "control RIGHT", DefaultEditorKit.nextWordAction, 343 "control shift LEFT", DefaultEditorKit.selectionPreviousWordAction, 344 "control shift RIGHT", DefaultEditorKit.selectionNextWordAction, 345 "HOME", DefaultEditorKit.beginLineAction, 346 "END", DefaultEditorKit.endLineAction, 347 "shift HOME", DefaultEditorKit.selectionBeginLineAction, 348 "shift END", DefaultEditorKit.selectionEndLineAction, 349 "BACK_SPACE", DefaultEditorKit.deletePrevCharAction, 350 "ctrl H", DefaultEditorKit.deletePrevCharAction, 351 "DELETE", DefaultEditorKit.deleteNextCharAction, 352 "RIGHT", DefaultEditorKit.forwardAction, 353 "LEFT", DefaultEditorKit.backwardAction, 354 "KP_RIGHT", DefaultEditorKit.forwardAction, 355 "KP_LEFT", DefaultEditorKit.backwardAction, 356 "ENTER", JTextField.notifyAction, 357 "control shift O", "toggle-componentOrientation" 358 }); 359 360 Object passwordInputMap = new UIDefaults.LazyInputMap(new Object [] { 361 "control C", DefaultEditorKit.copyAction, 362 "control V", DefaultEditorKit.pasteAction, 363 "control X", DefaultEditorKit.cutAction, 364 "COPY", DefaultEditorKit.copyAction, 365 "PASTE", DefaultEditorKit.pasteAction, 366 "CUT", DefaultEditorKit.cutAction, 367 "control INSERT", DefaultEditorKit.copyAction, 368 "shift INSERT", DefaultEditorKit.pasteAction, 369 "shift DELETE", DefaultEditorKit.cutAction, 370 "control A", DefaultEditorKit.selectAllAction, 371 "control BACK_SLASH", "unselect", 372 "shift LEFT", DefaultEditorKit.selectionBackwardAction, 373 "shift RIGHT", DefaultEditorKit.selectionForwardAction, 374 "control LEFT", DefaultEditorKit.beginLineAction, 375 "control RIGHT", DefaultEditorKit.endLineAction, 376 "control shift LEFT", DefaultEditorKit.selectionBeginLineAction, 377 "control shift RIGHT", DefaultEditorKit.selectionEndLineAction, 378 "HOME", DefaultEditorKit.beginLineAction, 379 "END", DefaultEditorKit.endLineAction, 380 "shift HOME", DefaultEditorKit.selectionBeginLineAction, 381 "shift END", DefaultEditorKit.selectionEndLineAction, 382 "BACK_SPACE", DefaultEditorKit.deletePrevCharAction, 383 "ctrl H", DefaultEditorKit.deletePrevCharAction, 384 "DELETE", DefaultEditorKit.deleteNextCharAction, 385 "RIGHT", DefaultEditorKit.forwardAction, 386 "LEFT", DefaultEditorKit.backwardAction, 387 "KP_RIGHT", DefaultEditorKit.forwardAction, 388 "KP_LEFT", DefaultEditorKit.backwardAction, 389 "ENTER", JTextField.notifyAction, 390 "control shift O", "toggle-componentOrientation" 391 }); 392 393 Object multilineInputMap = new UIDefaults.LazyInputMap(new Object [] { 394 "control C", DefaultEditorKit.copyAction, 395 "control V", DefaultEditorKit.pasteAction, 396 "control X", DefaultEditorKit.cutAction, 397 "COPY", DefaultEditorKit.copyAction, 398 "PASTE", DefaultEditorKit.pasteAction, 399 "CUT", DefaultEditorKit.cutAction, 400 "control INSERT", DefaultEditorKit.copyAction, 401 "shift INSERT", DefaultEditorKit.pasteAction, 402 "shift DELETE", DefaultEditorKit.cutAction, 403 "shift LEFT", DefaultEditorKit.selectionBackwardAction, 404 "shift RIGHT", DefaultEditorKit.selectionForwardAction, 405 "control LEFT", DefaultEditorKit.previousWordAction, 406 "control RIGHT", DefaultEditorKit.nextWordAction, 407 "control shift LEFT", DefaultEditorKit.selectionPreviousWordAction, 408 "control shift RIGHT", DefaultEditorKit.selectionNextWordAction, 409 "control A", DefaultEditorKit.selectAllAction, 410 "control BACK_SLASH", "unselect", 411 "HOME", DefaultEditorKit.beginLineAction, 412 "END", DefaultEditorKit.endLineAction, 413 "shift HOME", DefaultEditorKit.selectionBeginLineAction, 414 "shift END", DefaultEditorKit.selectionEndLineAction, 415 "control HOME", DefaultEditorKit.beginAction, 416 "control END", DefaultEditorKit.endAction, 417 "control shift HOME", DefaultEditorKit.selectionBeginAction, 418 "control shift END", DefaultEditorKit.selectionEndAction, 419 "UP", DefaultEditorKit.upAction, 420 "DOWN", DefaultEditorKit.downAction, 421 "BACK_SPACE", DefaultEditorKit.deletePrevCharAction, 422 "ctrl H", DefaultEditorKit.deletePrevCharAction, 423 "DELETE", DefaultEditorKit.deleteNextCharAction, 424 "RIGHT", DefaultEditorKit.forwardAction, 425 "LEFT", DefaultEditorKit.backwardAction, 426 "KP_RIGHT", DefaultEditorKit.forwardAction, 427 "KP_LEFT", DefaultEditorKit.backwardAction, 428 "PAGE_UP", DefaultEditorKit.pageUpAction, 429 "PAGE_DOWN", DefaultEditorKit.pageDownAction, 430 "shift PAGE_UP", "selection-page-up", 431 "shift PAGE_DOWN", "selection-page-down", 432 "ctrl shift PAGE_UP", "selection-page-left", 433 "ctrl shift PAGE_DOWN", "selection-page-right", 434 "shift UP", DefaultEditorKit.selectionUpAction, 435 "shift DOWN", DefaultEditorKit.selectionDownAction, 436 "ENTER", DefaultEditorKit.insertBreakAction, 437 "TAB", DefaultEditorKit.insertTabAction, 438 "control T", "next-link-action", 439 "control shift T", "previous-link-action", 440 "control SPACE", "activate-link-action", 441 "control shift O", "toggle-componentOrientation" 442 }); 443 444 Object menuItemAcceleratorDelimiter = new String ("+"); 445 446 Object ControlBackgroundColor = new DesktopProperty( 447 "win.3d.backgroundColor", 448 table.get("control"), 449 toolkit); 450 Object ControlLightColor = new DesktopProperty( 451 "win.3d.lightColor", 452 table.get("controlHighlight"), 453 toolkit); 454 Object ControlHighlightColor = new DesktopProperty( 455 "win.3d.highlightColor", 456 table.get("controlLtHighlight"), 457 toolkit); 458 Object ControlShadowColor = new DesktopProperty( 459 "win.3d.shadowColor", 460 table.get("controlShadow"), 461 toolkit); 462 Object ControlDarkShadowColor = new DesktopProperty( 463 "win.3d.darkShadowColor", 464 table.get("controlDkShadow"), 465 toolkit); 466 Object ControlTextColor = new DesktopProperty( 467 "win.button.textColor", 468 table.get("controlText"), 469 toolkit); 470 Object MenuBackgroundColor = new DesktopProperty( 471 "win.menu.backgroundColor", 472 table.get("menu"), 473 toolkit); 474 Object MenuBarBackgroundColor = new DesktopProperty( 475 "win.menubar.backgroundColor", 476 table.get("menu"), 477 toolkit); 478 Object MenuTextColor = new DesktopProperty( 479 "win.menu.textColor", 480 table.get("menuText"), 481 toolkit); 482 Object SelectionBackgroundColor = new DesktopProperty( 483 "win.item.highlightColor", 484 table.get("textHighlight"), 485 toolkit); 486 Object SelectionTextColor = new DesktopProperty( 487 "win.item.highlightTextColor", 488 table.get("textHighlightText"), 489 toolkit); 490 Object WindowBackgroundColor = new DesktopProperty( 491 "win.frame.backgroundColor", 492 table.get("window"), 493 toolkit); 494 Object WindowTextColor = new DesktopProperty( 495 "win.frame.textColor", 496 table.get("windowText"), 497 toolkit); 498 Object WindowBorderWidth = new DesktopProperty( 499 "win.frame.sizingBorderWidth", 500 new Integer (1), 501 toolkit); 502 Object TitlePaneHeight = new DesktopProperty( 503 "win.frame.captionHeight", 504 new Integer (18), 505 toolkit); 506 Object TitleButtonWidth = new DesktopProperty( 507 "win.frame.captionButtonWidth", 508 new Integer (16), 509 toolkit); 510 Object TitleButtonHeight = new DesktopProperty( 511 "win.frame.captionButtonHeight", 512 new Integer (16), 513 toolkit); 514 Object InactiveTextColor = new DesktopProperty( 515 "win.text.grayedTextColor", 516 table.get("textInactiveText"), 517 toolkit); 518 Object ScrollbarBackgroundColor = new DesktopProperty( 519 "win.scrollbar.backgroundColor", 520 table.get("scrollbar"), 521 toolkit); 522 523 Object TextBackground = new XPColorValue( 524 Part.EP_EDIT, null, Prop.FILLCOLOR, 525 WindowBackgroundColor); 526 Object ReadOnlyTextBackground = new XPColorValue( 527 Part.EP_EDITTEXT, State.READONLY, Prop.FILLCOLOR, 528 ControlBackgroundColor); 529 Object DisabledTextBackground = new XPColorValue( 530 Part.EP_EDITTEXT, State.DISABLED, Prop.FILLCOLOR, 531 ControlBackgroundColor); 532 533 Object MenuFont = dialogPlain12; 534 Object FixedControlFont = monospacedPlain12; 535 Object ControlFont = dialogPlain12; 536 Object MessageFont = dialogPlain12; 537 Object WindowFont = dialogBold12; 538 Object ToolTipFont = sansSerifPlain12; 539 Object IconFont = ControlFont; 540 541 Object scrollBarWidth = new DesktopProperty("win.scrollbar.width", 542 new Integer (16), toolkit); 543 544 Object showMnemonics = new DesktopProperty("win.menu.keyboardCuesOn", 545 Boolean.TRUE, toolkit); 546 547 if (useSystemFontSettings) { 548 MenuFont = getDesktopFontValue("win.menu.font", MenuFont, toolkit); 549 FixedControlFont = getDesktopFontValue("win.ansiFixed.font", 550 FixedControlFont, toolkit); 551 ControlFont = getDesktopFontValue("win.defaultGUI.font", 552 ControlFont, toolkit); 553 MessageFont = getDesktopFontValue("win.messagebox.font", 554 MessageFont, toolkit); 555 WindowFont = getDesktopFontValue("win.frame.captionFont", 556 WindowFont, toolkit); 557 IconFont = getDesktopFontValue("win.icon.font", 558 IconFont, toolkit); 559 ToolTipFont = getDesktopFontValue("win.tooltip.font", ToolTipFont, 560 toolkit); 561 } 562 if (useSystemFontSizeSettings) { 563 MenuFont = new WindowsFontSizeProperty("win.menu.font.height", 564 toolkit, "Dialog", Font.PLAIN, 12); 565 FixedControlFont = new WindowsFontSizeProperty( 566 "win.ansiFixed.font.height", toolkit, "MonoSpaced", 567 Font.PLAIN, 12); 568 ControlFont = new WindowsFontSizeProperty( 569 "win.defaultGUI.font.height", toolkit, "Dialog", 570 Font.PLAIN, 12); 571 MessageFont = new WindowsFontSizeProperty( 572 "win.messagebox.font.height", 573 toolkit, "Dialog", Font.PLAIN, 12); 574 WindowFont = new WindowsFontSizeProperty( 575 "win.frame.captionFont.height", toolkit, 576 "Dialog", Font.BOLD, 12); 577 ToolTipFont = new WindowsFontSizeProperty( 578 "win.tooltip.font.height", toolkit, "SansSerif", 579 &nbs
|