6660049: Synth Region.uiToRegionMap/lowerCaseNameMap are mutable statics

Reviewed-by: hawtin
This commit is contained in:
Sergey Malenkov 2009-06-18 14:08:07 +04:00
parent d214e051c9
commit 0681d1454c
2 changed files with 287 additions and 124 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2002-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,8 +24,13 @@
*/ */
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import javax.swing.*; import sun.awt.AppContext;
import java.util.*;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.swing.JComponent;
import javax.swing.UIDefaults;
/** /**
* A distinct rendering area of a Swing component. A component may * A distinct rendering area of a Swing component. A component may
@ -67,8 +72,8 @@ import java.util.*;
* @author Scott Violet * @author Scott Violet
*/ */
public class Region { public class Region {
private static final Map<String, Region> uiToRegionMap = new HashMap<String, Region>(); private static final Object UI_TO_REGION_MAP_KEY = new Object();
private static final Map<Region, String> lowerCaseNameMap = new HashMap<Region, String>(); private static final Object LOWER_CASE_NAME_MAP_KEY = new Object();
/** /**
* ArrowButton's are special types of buttons that also render a * ArrowButton's are special types of buttons that also render a
@ -77,396 +82,433 @@ public class Region {
* To bind a style to this <code>Region</code> use the name * To bind a style to this <code>Region</code> use the name
* <code>ArrowButton</code>. * <code>ArrowButton</code>.
*/ */
public static final Region ARROW_BUTTON = new Region("ArrowButton", public static final Region ARROW_BUTTON = new Region("ArrowButton", false);
"ArrowButtonUI");
/** /**
* Button region. To bind a style to this <code>Region</code> use the name * Button region. To bind a style to this <code>Region</code> use the name
* <code>Button</code>. * <code>Button</code>.
*/ */
public static final Region BUTTON = new Region("Button", public static final Region BUTTON = new Region("Button", false);
"ButtonUI");
/** /**
* CheckBox region. To bind a style to this <code>Region</code> use the name * CheckBox region. To bind a style to this <code>Region</code> use the name
* <code>CheckBox</code>. * <code>CheckBox</code>.
*/ */
public static final Region CHECK_BOX = new Region("CheckBox", public static final Region CHECK_BOX = new Region("CheckBox", false);
"CheckBoxUI");
/** /**
* CheckBoxMenuItem region. To bind a style to this <code>Region</code> use * CheckBoxMenuItem region. To bind a style to this <code>Region</code> use
* the name <code>CheckBoxMenuItem</code>. * the name <code>CheckBoxMenuItem</code>.
*/ */
public static final Region CHECK_BOX_MENU_ITEM = new Region( public static final Region CHECK_BOX_MENU_ITEM = new Region("CheckBoxMenuItem", false);
"CheckBoxMenuItem", "CheckBoxMenuItemUI");
/** /**
* ColorChooser region. To bind a style to this <code>Region</code> use * ColorChooser region. To bind a style to this <code>Region</code> use
* the name <code>ColorChooser</code>. * the name <code>ColorChooser</code>.
*/ */
public static final Region COLOR_CHOOSER = new Region( public static final Region COLOR_CHOOSER = new Region("ColorChooser", false);
"ColorChooser", "ColorChooserUI");
/** /**
* ComboBox region. To bind a style to this <code>Region</code> use * ComboBox region. To bind a style to this <code>Region</code> use
* the name <code>ComboBox</code>. * the name <code>ComboBox</code>.
*/ */
public static final Region COMBO_BOX = new Region( public static final Region COMBO_BOX = new Region("ComboBox", false);
"ComboBox", "ComboBoxUI");
/** /**
* DesktopPane region. To bind a style to this <code>Region</code> use * DesktopPane region. To bind a style to this <code>Region</code> use
* the name <code>DesktopPane</code>. * the name <code>DesktopPane</code>.
*/ */
public static final Region DESKTOP_PANE = new Region("DesktopPane", public static final Region DESKTOP_PANE = new Region("DesktopPane", false);
"DesktopPaneUI");
/** /**
* DesktopIcon region. To bind a style to this <code>Region</code> use * DesktopIcon region. To bind a style to this <code>Region</code> use
* the name <code>DesktopIcon</code>. * the name <code>DesktopIcon</code>.
*/ */
public static final Region DESKTOP_ICON = new Region("DesktopIcon", public static final Region DESKTOP_ICON = new Region("DesktopIcon", false);
"DesktopIconUI");
/** /**
* EditorPane region. To bind a style to this <code>Region</code> use * EditorPane region. To bind a style to this <code>Region</code> use
* the name <code>EditorPane</code>. * the name <code>EditorPane</code>.
*/ */
public static final Region EDITOR_PANE = new Region("EditorPane", public static final Region EDITOR_PANE = new Region("EditorPane", false);
"EditorPaneUI");
/** /**
* FileChooser region. To bind a style to this <code>Region</code> use * FileChooser region. To bind a style to this <code>Region</code> use
* the name <code>FileChooser</code>. * the name <code>FileChooser</code>.
*/ */
public static final Region FILE_CHOOSER = new Region("FileChooser", public static final Region FILE_CHOOSER = new Region("FileChooser", false);
"FileChooserUI");
/** /**
* FormattedTextField region. To bind a style to this <code>Region</code> use * FormattedTextField region. To bind a style to this <code>Region</code> use
* the name <code>FormattedTextField</code>. * the name <code>FormattedTextField</code>.
*/ */
public static final Region FORMATTED_TEXT_FIELD = new Region( public static final Region FORMATTED_TEXT_FIELD = new Region("FormattedTextField", false);
"FormattedTextField", "FormattedTextFieldUI");
/** /**
* InternalFrame region. To bind a style to this <code>Region</code> use * InternalFrame region. To bind a style to this <code>Region</code> use
* the name <code>InternalFrame</code>. * the name <code>InternalFrame</code>.
*/ */
public static final Region INTERNAL_FRAME = new Region("InternalFrame", public static final Region INTERNAL_FRAME = new Region("InternalFrame", false);
"InternalFrameUI");
/** /**
* TitlePane of an InternalFrame. The TitlePane typically * TitlePane of an InternalFrame. The TitlePane typically
* shows a menu, title, widgets to manipulate the internal frame. * shows a menu, title, widgets to manipulate the internal frame.
* To bind a style to this <code>Region</code> use the name * To bind a style to this <code>Region</code> use the name
* <code>InternalFrameTitlePane</code>. * <code>InternalFrameTitlePane</code>.
*/ */
public static final Region INTERNAL_FRAME_TITLE_PANE = public static final Region INTERNAL_FRAME_TITLE_PANE = new Region("InternalFrameTitlePane", false);
new Region("InternalFrameTitlePane",
"InternalFrameTitlePaneUI");
/** /**
* Label region. To bind a style to this <code>Region</code> use the name * Label region. To bind a style to this <code>Region</code> use the name
* <code>Label</code>. * <code>Label</code>.
*/ */
public static final Region LABEL = new Region("Label", "LabelUI"); public static final Region LABEL = new Region("Label", false);
/** /**
* List region. To bind a style to this <code>Region</code> use the name * List region. To bind a style to this <code>Region</code> use the name
* <code>List</code>. * <code>List</code>.
*/ */
public static final Region LIST = new Region("List", "ListUI"); public static final Region LIST = new Region("List", false);
/** /**
* Menu region. To bind a style to this <code>Region</code> use the name * Menu region. To bind a style to this <code>Region</code> use the name
* <code>Menu</code>. * <code>Menu</code>.
*/ */
public static final Region MENU = new Region("Menu", "MenuUI"); public static final Region MENU = new Region("Menu", false);
/** /**
* MenuBar region. To bind a style to this <code>Region</code> use the name * MenuBar region. To bind a style to this <code>Region</code> use the name
* <code>MenuBar</code>. * <code>MenuBar</code>.
*/ */
public static final Region MENU_BAR = new Region("MenuBar", "MenuBarUI"); public static final Region MENU_BAR = new Region("MenuBar", false);
/** /**
* MenuItem region. To bind a style to this <code>Region</code> use the name * MenuItem region. To bind a style to this <code>Region</code> use the name
* <code>MenuItem</code>. * <code>MenuItem</code>.
*/ */
public static final Region MENU_ITEM = new Region("MenuItem","MenuItemUI"); public static final Region MENU_ITEM = new Region("MenuItem", false);
/** /**
* Accelerator region of a MenuItem. To bind a style to this * Accelerator region of a MenuItem. To bind a style to this
* <code>Region</code> use the name <code>MenuItemAccelerator</code>. * <code>Region</code> use the name <code>MenuItemAccelerator</code>.
*/ */
public static final Region MENU_ITEM_ACCELERATOR = new Region( public static final Region MENU_ITEM_ACCELERATOR = new Region("MenuItemAccelerator", true);
"MenuItemAccelerator");
/** /**
* OptionPane region. To bind a style to this <code>Region</code> use * OptionPane region. To bind a style to this <code>Region</code> use
* the name <code>OptionPane</code>. * the name <code>OptionPane</code>.
*/ */
public static final Region OPTION_PANE = new Region("OptionPane", public static final Region OPTION_PANE = new Region("OptionPane", false);
"OptionPaneUI");
/** /**
* Panel region. To bind a style to this <code>Region</code> use the name * Panel region. To bind a style to this <code>Region</code> use the name
* <code>Panel</code>. * <code>Panel</code>.
*/ */
public static final Region PANEL = new Region("Panel", "PanelUI"); public static final Region PANEL = new Region("Panel", false);
/** /**
* PasswordField region. To bind a style to this <code>Region</code> use * PasswordField region. To bind a style to this <code>Region</code> use
* the name <code>PasswordField</code>. * the name <code>PasswordField</code>.
*/ */
public static final Region PASSWORD_FIELD = new Region("PasswordField", public static final Region PASSWORD_FIELD = new Region("PasswordField", false);
"PasswordFieldUI");
/** /**
* PopupMenu region. To bind a style to this <code>Region</code> use * PopupMenu region. To bind a style to this <code>Region</code> use
* the name <code>PopupMenu</code>. * the name <code>PopupMenu</code>.
*/ */
public static final Region POPUP_MENU = new Region("PopupMenu", public static final Region POPUP_MENU = new Region("PopupMenu", false);
"PopupMenuUI");
/** /**
* PopupMenuSeparator region. To bind a style to this <code>Region</code> * PopupMenuSeparator region. To bind a style to this <code>Region</code>
* use the name <code>PopupMenuSeparator</code>. * use the name <code>PopupMenuSeparator</code>.
*/ */
public static final Region POPUP_MENU_SEPARATOR = new Region( public static final Region POPUP_MENU_SEPARATOR = new Region("PopupMenuSeparator", false);
"PopupMenuSeparator", "PopupMenuSeparatorUI");
/** /**
* ProgressBar region. To bind a style to this <code>Region</code> * ProgressBar region. To bind a style to this <code>Region</code>
* use the name <code>ProgressBar</code>. * use the name <code>ProgressBar</code>.
*/ */
public static final Region PROGRESS_BAR = new Region("ProgressBar", public static final Region PROGRESS_BAR = new Region("ProgressBar", false);
"ProgressBarUI");
/** /**
* RadioButton region. To bind a style to this <code>Region</code> * RadioButton region. To bind a style to this <code>Region</code>
* use the name <code>RadioButton</code>. * use the name <code>RadioButton</code>.
*/ */
public static final Region RADIO_BUTTON = new Region( public static final Region RADIO_BUTTON = new Region("RadioButton", false);
"RadioButton", "RadioButtonUI");
/** /**
* RegionButtonMenuItem region. To bind a style to this <code>Region</code> * RegionButtonMenuItem region. To bind a style to this <code>Region</code>
* use the name <code>RadioButtonMenuItem</code>. * use the name <code>RadioButtonMenuItem</code>.
*/ */
public static final Region RADIO_BUTTON_MENU_ITEM = new Region( public static final Region RADIO_BUTTON_MENU_ITEM = new Region("RadioButtonMenuItem", false);
"RadioButtonMenuItem", "RadioButtonMenuItemUI");
/** /**
* RootPane region. To bind a style to this <code>Region</code> use * RootPane region. To bind a style to this <code>Region</code> use
* the name <code>RootPane</code>. * the name <code>RootPane</code>.
*/ */
public static final Region ROOT_PANE = new Region("RootPane", public static final Region ROOT_PANE = new Region("RootPane", false);
"RootPaneUI");
/** /**
* ScrollBar region. To bind a style to this <code>Region</code> use * ScrollBar region. To bind a style to this <code>Region</code> use
* the name <code>ScrollBar</code>. * the name <code>ScrollBar</code>.
*/ */
public static final Region SCROLL_BAR = new Region("ScrollBar", public static final Region SCROLL_BAR = new Region("ScrollBar", false);
"ScrollBarUI");
/** /**
* Track of the ScrollBar. To bind a style to this <code>Region</code> use * Track of the ScrollBar. To bind a style to this <code>Region</code> use
* the name <code>ScrollBarTrack</code>. * the name <code>ScrollBarTrack</code>.
*/ */
public static final Region SCROLL_BAR_TRACK = new Region("ScrollBarTrack"); public static final Region SCROLL_BAR_TRACK = new Region("ScrollBarTrack", true);
/** /**
* Thumb of the ScrollBar. The thumb is the region of the ScrollBar * Thumb of the ScrollBar. The thumb is the region of the ScrollBar
* that gives a graphical depiction of what percentage of the View is * that gives a graphical depiction of what percentage of the View is
* currently visible. To bind a style to this <code>Region</code> use * currently visible. To bind a style to this <code>Region</code> use
* the name <code>ScrollBarThumb</code>. * the name <code>ScrollBarThumb</code>.
*/ */
public static final Region SCROLL_BAR_THUMB = new Region("ScrollBarThumb"); public static final Region SCROLL_BAR_THUMB = new Region("ScrollBarThumb", true);
/** /**
* ScrollPane region. To bind a style to this <code>Region</code> use * ScrollPane region. To bind a style to this <code>Region</code> use
* the name <code>ScrollPane</code>. * the name <code>ScrollPane</code>.
*/ */
public static final Region SCROLL_PANE = new Region("ScrollPane", public static final Region SCROLL_PANE = new Region("ScrollPane", false);
"ScrollPaneUI");
/** /**
* Separator region. To bind a style to this <code>Region</code> use * Separator region. To bind a style to this <code>Region</code> use
* the name <code>Separator</code>. * the name <code>Separator</code>.
*/ */
public static final Region SEPARATOR = new Region("Separator", public static final Region SEPARATOR = new Region("Separator", false);
"SeparatorUI");
/** /**
* Slider region. To bind a style to this <code>Region</code> use * Slider region. To bind a style to this <code>Region</code> use
* the name <code>Slider</code>. * the name <code>Slider</code>.
*/ */
public static final Region SLIDER = new Region("Slider", "SliderUI"); public static final Region SLIDER = new Region("Slider", false);
/** /**
* Track of the Slider. To bind a style to this <code>Region</code> use * Track of the Slider. To bind a style to this <code>Region</code> use
* the name <code>SliderTrack</code>. * the name <code>SliderTrack</code>.
*/ */
public static final Region SLIDER_TRACK = new Region("SliderTrack"); public static final Region SLIDER_TRACK = new Region("SliderTrack", true);
/** /**
* Thumb of the Slider. The thumb of the Slider identifies the current * Thumb of the Slider. The thumb of the Slider identifies the current
* value. To bind a style to this <code>Region</code> use the name * value. To bind a style to this <code>Region</code> use the name
* <code>SliderThumb</code>. * <code>SliderThumb</code>.
*/ */
public static final Region SLIDER_THUMB = new Region("SliderThumb"); public static final Region SLIDER_THUMB = new Region("SliderThumb", true);
/** /**
* Spinner region. To bind a style to this <code>Region</code> use the name * Spinner region. To bind a style to this <code>Region</code> use the name
* <code>Spinner</code>. * <code>Spinner</code>.
*/ */
public static final Region SPINNER = new Region("Spinner", "SpinnerUI"); public static final Region SPINNER = new Region("Spinner", false);
/** /**
* SplitPane region. To bind a style to this <code>Region</code> use the name * SplitPane region. To bind a style to this <code>Region</code> use the name
* <code>SplitPane</code>. * <code>SplitPane</code>.
*/ */
public static final Region SPLIT_PANE = new Region("SplitPane", public static final Region SPLIT_PANE = new Region("SplitPane", false);
"SplitPaneUI");
/** /**
* Divider of the SplitPane. To bind a style to this <code>Region</code> * Divider of the SplitPane. To bind a style to this <code>Region</code>
* use the name <code>SplitPaneDivider</code>. * use the name <code>SplitPaneDivider</code>.
*/ */
public static final Region SPLIT_PANE_DIVIDER = new Region( public static final Region SPLIT_PANE_DIVIDER = new Region("SplitPaneDivider", true);
"SplitPaneDivider");
/** /**
* TabbedPane region. To bind a style to this <code>Region</code> use * TabbedPane region. To bind a style to this <code>Region</code> use
* the name <code>TabbedPane</code>. * the name <code>TabbedPane</code>.
*/ */
public static final Region TABBED_PANE = new Region("TabbedPane", public static final Region TABBED_PANE = new Region("TabbedPane", false);
"TabbedPaneUI");
/** /**
* Region of a TabbedPane for one tab. To bind a style to this * Region of a TabbedPane for one tab. To bind a style to this
* <code>Region</code> use the name <code>TabbedPaneTab</code>. * <code>Region</code> use the name <code>TabbedPaneTab</code>.
*/ */
public static final Region TABBED_PANE_TAB = new Region("TabbedPaneTab"); public static final Region TABBED_PANE_TAB = new Region("TabbedPaneTab", true);
/** /**
* Region of a TabbedPane containing the tabs. To bind a style to this * Region of a TabbedPane containing the tabs. To bind a style to this
* <code>Region</code> use the name <code>TabbedPaneTabArea</code>. * <code>Region</code> use the name <code>TabbedPaneTabArea</code>.
*/ */
public static final Region TABBED_PANE_TAB_AREA = public static final Region TABBED_PANE_TAB_AREA = new Region("TabbedPaneTabArea", true);
new Region("TabbedPaneTabArea");
/** /**
* Region of a TabbedPane containing the content. To bind a style to this * Region of a TabbedPane containing the content. To bind a style to this
* <code>Region</code> use the name <code>TabbedPaneContent</code>. * <code>Region</code> use the name <code>TabbedPaneContent</code>.
*/ */
public static final Region TABBED_PANE_CONTENT = public static final Region TABBED_PANE_CONTENT = new Region("TabbedPaneContent", true);
new Region("TabbedPaneContent");
/** /**
* Table region. To bind a style to this <code>Region</code> use * Table region. To bind a style to this <code>Region</code> use
* the name <code>Table</code>. * the name <code>Table</code>.
*/ */
public static final Region TABLE = new Region("Table", "TableUI"); public static final Region TABLE = new Region("Table", false);
/** /**
* TableHeader region. To bind a style to this <code>Region</code> use * TableHeader region. To bind a style to this <code>Region</code> use
* the name <code>TableHeader</code>. * the name <code>TableHeader</code>.
*/ */
public static final Region TABLE_HEADER = new Region("TableHeader", public static final Region TABLE_HEADER = new Region("TableHeader", false);
"TableHeaderUI");
/** /**
* TextArea region. To bind a style to this <code>Region</code> use * TextArea region. To bind a style to this <code>Region</code> use
* the name <code>TextArea</code>. * the name <code>TextArea</code>.
*/ */
public static final Region TEXT_AREA = new Region("TextArea", public static final Region TEXT_AREA = new Region("TextArea", false);
"TextAreaUI");
/** /**
* TextField region. To bind a style to this <code>Region</code> use * TextField region. To bind a style to this <code>Region</code> use
* the name <code>TextField</code>. * the name <code>TextField</code>.
*/ */
public static final Region TEXT_FIELD = new Region("TextField", public static final Region TEXT_FIELD = new Region("TextField", false);
"TextFieldUI");
/** /**
* TextPane region. To bind a style to this <code>Region</code> use * TextPane region. To bind a style to this <code>Region</code> use
* the name <code>TextPane</code>. * the name <code>TextPane</code>.
*/ */
public static final Region TEXT_PANE = new Region("TextPane", public static final Region TEXT_PANE = new Region("TextPane", false);
"TextPaneUI");
/** /**
* ToggleButton region. To bind a style to this <code>Region</code> use * ToggleButton region. To bind a style to this <code>Region</code> use
* the name <code>ToggleButton</code>. * the name <code>ToggleButton</code>.
*/ */
public static final Region TOGGLE_BUTTON = new Region("ToggleButton", public static final Region TOGGLE_BUTTON = new Region("ToggleButton", false);
"ToggleButtonUI");
/** /**
* ToolBar region. To bind a style to this <code>Region</code> use * ToolBar region. To bind a style to this <code>Region</code> use
* the name <code>ToolBar</code>. * the name <code>ToolBar</code>.
*/ */
public static final Region TOOL_BAR = new Region("ToolBar", "ToolBarUI"); public static final Region TOOL_BAR = new Region("ToolBar", false);
/** /**
* Region of the ToolBar containing the content. To bind a style to this * Region of the ToolBar containing the content. To bind a style to this
* <code>Region</code> use the name <code>ToolBarContent</code>. * <code>Region</code> use the name <code>ToolBarContent</code>.
*/ */
public static final Region TOOL_BAR_CONTENT = new Region("ToolBarContent"); public static final Region TOOL_BAR_CONTENT = new Region("ToolBarContent", true);
/** /**
* Region for the Window containing the ToolBar. To bind a style to this * Region for the Window containing the ToolBar. To bind a style to this
* <code>Region</code> use the name <code>ToolBarDragWindow</code>. * <code>Region</code> use the name <code>ToolBarDragWindow</code>.
*/ */
public static final Region TOOL_BAR_DRAG_WINDOW = new Region( public static final Region TOOL_BAR_DRAG_WINDOW = new Region("ToolBarDragWindow", false);
"ToolBarDragWindow", null, false);
/** /**
* ToolTip region. To bind a style to this <code>Region</code> use * ToolTip region. To bind a style to this <code>Region</code> use
* the name <code>ToolTip</code>. * the name <code>ToolTip</code>.
*/ */
public static final Region TOOL_TIP = new Region("ToolTip", "ToolTipUI"); public static final Region TOOL_TIP = new Region("ToolTip", false);
/** /**
* ToolBar separator region. To bind a style to this <code>Region</code> use * ToolBar separator region. To bind a style to this <code>Region</code> use
* the name <code>ToolBarSeparator</code>. * the name <code>ToolBarSeparator</code>.
*/ */
public static final Region TOOL_BAR_SEPARATOR = new Region( public static final Region TOOL_BAR_SEPARATOR = new Region("ToolBarSeparator", false);
"ToolBarSeparator", "ToolBarSeparatorUI");
/** /**
* Tree region. To bind a style to this <code>Region</code> use the name * Tree region. To bind a style to this <code>Region</code> use the name
* <code>Tree</code>. * <code>Tree</code>.
*/ */
public static final Region TREE = new Region("Tree", "TreeUI"); public static final Region TREE = new Region("Tree", false);
/** /**
* Region of the Tree for one cell. To bind a style to this * Region of the Tree for one cell. To bind a style to this
* <code>Region</code> use the name <code>TreeCell</code>. * <code>Region</code> use the name <code>TreeCell</code>.
*/ */
public static final Region TREE_CELL = new Region("TreeCell"); public static final Region TREE_CELL = new Region("TreeCell", true);
/** /**
* Viewport region. To bind a style to this <code>Region</code> use * Viewport region. To bind a style to this <code>Region</code> use
* the name <code>Viewport</code>. * the name <code>Viewport</code>.
*/ */
public static final Region VIEWPORT = new Region("Viewport", "ViewportUI"); public static final Region VIEWPORT = new Region("Viewport", false);
private static Map<String, Region> getUItoRegionMap() {
AppContext context = AppContext.getAppContext();
Map<String, Region> map = (Map<String, Region>) context.get(UI_TO_REGION_MAP_KEY);
if (map == null) {
map = new HashMap<String, Region>();
map.put("ArrowButtonUI", ARROW_BUTTON);
map.put("ButtonUI", BUTTON);
map.put("CheckBoxUI", CHECK_BOX);
map.put("CheckBoxMenuItemUI", CHECK_BOX_MENU_ITEM);
map.put("ColorChooserUI", COLOR_CHOOSER);
map.put("ComboBoxUI", COMBO_BOX);
map.put("DesktopPaneUI", DESKTOP_PANE);
map.put("DesktopIconUI", DESKTOP_ICON);
map.put("EditorPaneUI", EDITOR_PANE);
map.put("FileChooserUI", FILE_CHOOSER);
map.put("FormattedTextFieldUI", FORMATTED_TEXT_FIELD);
map.put("InternalFrameUI", INTERNAL_FRAME);
map.put("InternalFrameTitlePaneUI", INTERNAL_FRAME_TITLE_PANE);
map.put("LabelUI", LABEL);
map.put("ListUI", LIST);
map.put("MenuUI", MENU);
map.put("MenuBarUI", MENU_BAR);
map.put("MenuItemUI", MENU_ITEM);
map.put("OptionPaneUI", OPTION_PANE);
map.put("PanelUI", PANEL);
map.put("PasswordFieldUI", PASSWORD_FIELD);
map.put("PopupMenuUI", POPUP_MENU);
map.put("PopupMenuSeparatorUI", POPUP_MENU_SEPARATOR);
map.put("ProgressBarUI", PROGRESS_BAR);
map.put("RadioButtonUI", RADIO_BUTTON);
map.put("RadioButtonMenuItemUI", RADIO_BUTTON_MENU_ITEM);
map.put("RootPaneUI", ROOT_PANE);
map.put("ScrollBarUI", SCROLL_BAR);
map.put("ScrollPaneUI", SCROLL_PANE);
map.put("SeparatorUI", SEPARATOR);
map.put("SliderUI", SLIDER);
map.put("SpinnerUI", SPINNER);
map.put("SplitPaneUI", SPLIT_PANE);
map.put("TabbedPaneUI", TABBED_PANE);
map.put("TableUI", TABLE);
map.put("TableHeaderUI", TABLE_HEADER);
map.put("TextAreaUI", TEXT_AREA);
map.put("TextFieldUI", TEXT_FIELD);
map.put("TextPaneUI", TEXT_PANE);
map.put("ToggleButtonUI", TOGGLE_BUTTON);
map.put("ToolBarUI", TOOL_BAR);
map.put("ToolTipUI", TOOL_TIP);
map.put("ToolBarSeparatorUI", TOOL_BAR_SEPARATOR);
map.put("TreeUI", TREE);
map.put("ViewportUI", VIEWPORT);
context.put(UI_TO_REGION_MAP_KEY, map);
}
return map;
}
private String name; private static Map<Region, String> getLowerCaseNameMap() {
private boolean subregion; AppContext context = AppContext.getAppContext();
Map<Region, String> map = (Map<Region, String>) context.get(LOWER_CASE_NAME_MAP_KEY);
if (map == null) {
map = new HashMap<Region, String>();
context.put(LOWER_CASE_NAME_MAP_KEY, map);
}
return map;
}
static Region getRegion(JComponent c) { static Region getRegion(JComponent c) {
return uiToRegionMap.get(c.getUIClassID()); return getUItoRegionMap().get(c.getUIClassID());
} }
static void registerUIs(UIDefaults table) { static void registerUIs(UIDefaults table) {
for (String key : uiToRegionMap.keySet()) { for (Object key : getUItoRegionMap().keySet()) {
table.put(key, "javax.swing.plaf.synth.SynthLookAndFeel"); table.put(key, "javax.swing.plaf.synth.SynthLookAndFeel");
} }
} }
private final String name;
private final boolean subregion;
Region(String name) { private Region(String name, boolean subregion) {
this(name, null, true); if (name == null) {
} throw new NullPointerException("You must specify a non-null name");
}
Region(String name, String ui) { this.name = name;
this(name, ui, false); this.subregion = subregion;
} }
/** /**
@ -481,14 +523,10 @@ public class Region {
* @param subregion Whether or not this is a subregion. * @param subregion Whether or not this is a subregion.
*/ */
protected Region(String name, String ui, boolean subregion) { protected Region(String name, String ui, boolean subregion) {
if (name == null) { this(name, subregion);
throw new NullPointerException("You must specify a non-null name");
}
this.name = name;
if (ui != null) { if (ui != null) {
uiToRegionMap.put(ui, this); getUItoRegionMap().put(ui, this);
} }
this.subregion = subregion;
} }
/** /**
@ -514,16 +552,17 @@ public class Region {
/** /**
* Returns the name, in lowercase. * Returns the name, in lowercase.
*
* @return lower case representation of the name of the Region
*/ */
String getLowerCaseName() { String getLowerCaseName() {
synchronized(lowerCaseNameMap) { Map<Region, String> lowerCaseNameMap = getLowerCaseNameMap();
String lowerCaseName = lowerCaseNameMap.get(this); String lowerCaseName = lowerCaseNameMap.get(this);
if (lowerCaseName == null) { if (lowerCaseName == null) {
lowerCaseName = getName().toLowerCase(); lowerCaseName = name.toLowerCase(Locale.ENGLISH);
lowerCaseNameMap.put(this, lowerCaseName); lowerCaseNameMap.put(this, lowerCaseName);
}
return lowerCaseName;
} }
return lowerCaseName;
} }
/** /**
@ -531,6 +570,7 @@ public class Region {
* *
* @return name of the Region. * @return name of the Region.
*/ */
@Override
public String toString() { public String toString() {
return name; return name;
} }

View File

@ -0,0 +1,123 @@
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6660049 6849518
* @summary Tests the Region initialization
* @author Sergey Malenkov
*/
import sun.awt.SunToolkit;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import javax.swing.plaf.synth.Region;
import javax.swing.plaf.synth.SynthLookAndFeel;
public class Test6660049 implements Runnable {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Test6660049(
javax.swing.JButton.class,
javax.swing.JCheckBox.class,
javax.swing.JCheckBoxMenuItem.class,
javax.swing.JColorChooser.class,
javax.swing.JComboBox.class,
javax.swing.JDesktopPane.class,
javax.swing.JEditorPane.class,
javax.swing.JFileChooser.class,
javax.swing.JFormattedTextField.class,
javax.swing.JInternalFrame.class,
javax.swing.JLabel.class,
javax.swing.JList.class,
javax.swing.JMenu.class,
javax.swing.JMenuBar.class,
javax.swing.JMenuItem.class,
javax.swing.JOptionPane.class,
javax.swing.JPanel.class,
javax.swing.JPasswordField.class,
javax.swing.JPopupMenu.class,
javax.swing.JProgressBar.class,
javax.swing.JRadioButton.class,
javax.swing.JRadioButtonMenuItem.class,
javax.swing.JRootPane.class,
javax.swing.JScrollBar.class,
javax.swing.JScrollPane.class,
javax.swing.JSeparator.class,
javax.swing.JSlider.class,
javax.swing.JSpinner.class,
javax.swing.JSplitPane.class,
javax.swing.JTabbedPane.class,
javax.swing.JTable.class,
javax.swing.JTextArea.class,
javax.swing.JTextField.class,
javax.swing.JTextPane.class,
javax.swing.JToggleButton.class,
javax.swing.JToolBar.class,
javax.swing.JToolTip.class,
javax.swing.JTree.class,
javax.swing.JViewport.class,
javax.swing.table.JTableHeader.class));
}
private final Class<? extends JComponent>[] types;
private final Region region;
private Test6660049(Class<? extends JComponent>... types) {
this.types = types;
run();
this.region = new Region("Button", "ButtonUI", true) {
@Override
public String getName() {
throw new Error("6660049: exploit is available");
}
};
}
public void run() {
if (this.region != null) {
SunToolkit.createNewAppContext();
}
for (Class<? extends JComponent> type : this.types) {
Region region = getRegion(type);
if (region == null) {
throw new Error("6849518: region is not initialized");
}
}
getRegion(JButton.class).getName();
}
private static Region getRegion(Class<? extends JComponent> type) {
try {
return SynthLookAndFeel.getRegion(type.newInstance());
}
catch (IllegalAccessException exception) {
throw new Error("unexpected exception", exception);
}
catch (InstantiationException exception) {
throw new Error("unexpected exception", exception);
}
}
}