gtkstyle.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,779 行 · 第 1/5 页
JAVA
1,779 行
return defaultValue; } /** * Convenience method to get a class specific Boolean value. * * @param context SynthContext indentifying requestor * @param key Key identifying class specific value * @param defaultValue Returned if there is no value for the specified * type * @return Value, or defaultValue if <code>key</code> is not defined */ public boolean getClassSpecificBoolValue(SynthContext context, String key, boolean defaultValue) { Object value = getClassSpecificValue(context, key); if (value instanceof Boolean) { return ((Boolean)value).booleanValue(); } return defaultValue; } public Object getDefaultValue(SynthContext context, Object key) { // See if this is a class specific value. Object classKey = CLASS_SPECIFIC_MAP.get(key); Object value = null; if (classKey != null) { value = getClassSpecificValue(context, (String)classKey); if (value != null) { return value; } } if (key == "ScrollPane.viewportBorderInsets") { return GTKPainter.INSTANCE.getScrollPaneInsets(context, new Insets(0,0,0,0)); } else if (key == "Slider.tickColor") { return getColor(context.getComponent(), context.getRegion(), context.getComponentState(), ColorType.FOREGROUND); } synchronized (DATA) { value = DATA.get(key); } if (value instanceof StyleSpecificValue) { put(key, ((StyleSpecificValue)value).getValue(context)); } if (value == null && key != "engine") { // For backward compatability we'll fallback to the UIManager. // We don't go to the UIManager for engine as the engine is GTK // specific. value = UIManager.get(key); if (key == "Table.rowHeight") { int focusLineWidth = getClassSpecificIntValue( context, "focus-line-width", 0); if (value == null && focusLineWidth > 0) { value = new Integer(16 + 2 * focusLineWidth); } } } // Don't call super, we don't want to pick up defaults from // SynthStyle. return value; } /** * Returns the font for the specified state. This should NOT callback * to the JComponent. * * @param c JComponent the style is associated with * @param id Region identifier * @param state State of the region. * @return Font to render with */ protected Font getFontForState(JComponent c, Region id, int state) { state = GTKLookAndFeel.synthStateToGTKState(id, state); Font f = super.getFontForState(c, id, state); if (f == null) { return DEFAULT_FONT; } return f; } Color getGTKColor(int state, ColorType type) { return getGTKColor(null, null, state, type); } /** * This method is to be used from within GTK when do NOT want * the component state to be mapped. It will NOT remap the state as * the other various getters do. * * @param c JComponent the style is associated with * @param id Region identifier * @param state State of the region. * @param type Type of color being requested. * @return Color to render with */ public Color getGTKColor(JComponent c, Region id, int state, ColorType type) { // NOTE: c and id are only ever null when this is called from // GTKLookAndFeel.loadSystemColorDefaults. if (c != null && id != null) { if (!id.isSubregion() && (state & SynthConstants.ENABLED) == SynthConstants.ENABLED) { if (type == ColorType.BACKGROUND) { Color bg = c.getBackground(); if (!(bg instanceof UIResource)) { return bg; } } else if (type == ColorType.FOREGROUND) { Color fg = c.getForeground(); if (!(fg instanceof UIResource)) { return fg; } } else if (type == ColorType.TEXT_FOREGROUND) { Color fg = c.getForeground(); if (!(fg instanceof UIResource)) { return fg; } } else if (type == ColorType.TEXT_BACKGROUND) { Color bg = c.getBackground(); if (!(bg instanceof UIResource)) { return bg; } } } } Color color = super.getColorForState(c, id, state, type); if (color != null) { return color; } return getDefaultColor(c, id, state, type); } /** * getColor is overriden to map the state from a Synth state to the * GTK state, this should be not used when you have already mapped the * state. Additionally this will map TEXT_FOREGROUND to the * <code>c.getForeground()</code> if it is non-null and not a UIResource. * * @param c JComponent the style is associated with * @param id Region identifier * @param state State of the region. * @param type Type of color being requested. * @return Color to render with */ public Color getColor(JComponent c, Region id, int state, ColorType type) { if (id == Region.LABEL && type == ColorType.TEXT_FOREGROUND) { type = ColorType.FOREGROUND; } state = GTKLookAndFeel.synthStateToGTKState(id, state); if (!id.isSubregion() && (state & SynthConstants.ENABLED) == SynthConstants.ENABLED) { if (type == ColorType.BACKGROUND) { return c.getBackground(); } else if (type == ColorType.FOREGROUND) { return c.getForeground(); } else if (type == ColorType.TEXT_FOREGROUND) { Color fg = c.getForeground(); if (fg != null && !(fg instanceof UIResource)) { // Only use the fg for text if specified. return fg; } } } return getColorForState(c, id, state, type); } /** * Returns the color for the specified state. This redirects to the * JComponent <code>c</code> as necessary. If this does not redirect * to the JComponent <code>getColorForState</code> is invoked. * * @param c JComponent the style is associated with * @param id Region identifier * @param state State of the region. * @param type Type of color being requested. * @return Color to render with */ protected Color getColorForState(JComponent c, Region id, int state, ColorType type) { Color color = super.getColorForState(c, id, state, type); if (color != null) { return color; } if (type == ColorType.FOCUS) { return BLACK_COLOR; } else if (type == GTKColorType.BLACK) { return BLACK_COLOR; } else if (type == GTKColorType.WHITE) { return WHITE_COLOR; } if (type == ColorType.TEXT_FOREGROUND && (GTKStyleFactory. isLabelBearing(id) || id == Region.MENU_ITEM_ACCELERATOR || id == Region.TABBED_PANE_TAB)) { type = ColorType.FOREGROUND; } else if (id == Region.TABLE || id == Region.LIST || id == Region.TREE || id == Region.TREE_CELL){ if (type == ColorType.FOREGROUND) { type = ColorType.TEXT_FOREGROUND; if (state == SynthConstants.PRESSED) { state = SynthConstants.SELECTED; } } else if (type == ColorType.BACKGROUND) { type = ColorType.TEXT_BACKGROUND; if (state == SynthConstants.PRESSED) { state = SynthConstants.SELECTED; } } } return getDefaultColor(c, id, state, type); } /** * Returns the Color to use if the GTKStyle does not specify a color. * * @param c JComponent the style is associated with * @param id Region identifier * @param state State of the region. * @param type Type of color being requested. * @return Color to render with */ Color getDefaultColor(JComponent c, Region id, int state, ColorType type) { if (type == ColorType.FOCUS) { return BLACK_COLOR; } else if (type == GTKColorType.BLACK) { return BLACK_COLOR; } else if (type == GTKColorType.WHITE) { return WHITE_COLOR; } for (int counter = DEFAULT_COLOR_MAP.length - 1; counter >= 0; counter--) { if ((DEFAULT_COLOR_MAP[counter] & state) != 0) { if (type.getID() < DEFAULT_COLORS[counter].length) { return DEFAULT_COLORS[counter][type.getID()]; } } } if (type.getID() < DEFAULT_COLORS[2].length) { return DEFAULT_COLORS[2][type.getID()]; } return null; } /** * Returns the value to initialize the opacity property of the Component * to. A Style should NOT assume the opacity will remain this value, the * developer may reset it or override it. * * @param context SynthContext indentifying requestor * @return opaque Whether or not the JComponent is opaque. */ public boolean isOpaque(SynthContext context) { Region region = context.getRegion(); if (region == Region.COMBO_BOX || region == Region.DESKTOP_PANE || region == Region.DESKTOP_ICON || region == Region.EDITOR_PANE || region == Region.FORMATTED_TEXT_FIELD || region == Region.INTERNAL_FRAME || region == Region.LIST || region == Region.MENU_BAR || region == Region.PASSWORD_FIELD || region == Region.POPUP_MENU || region == Region.PROGRESS_BAR || region == Region.ROOT_PANE || region == Region.SCROLL_PANE || region == Region.SPINNER || region == Region.TABLE || region == Region.TEXT_AREA || region == Region.TEXT_FIELD || region == Region.TEXT_PANE || region == Region.TOOL_BAR_DRAG_WINDOW || region == Region.TOOL_TIP || region == Region.TREE || region == Region.VIEWPORT) { return true; } Component c = context.getComponent(); String name = c.getName(); if (name == "ComboBox.renderer" || name == "ComboBox.listRenderer") { return true; } return false; } /** * Returns the X thickness to use for this GTKStyle. * * @return x thickness. */ public int getXThickness() { return xThickness; } /** * Returns the Y thickness to use for this GTKStyle. * * @return x thickness. */ public int getYThickness() { return yThickness; } private Icon getStockIcon(SynthContext context, String key, int type) { Icon icon = null; GTKStockIconInfo iconInfo = null; GTKIconSource bestSource = null; int direction = LTR; if (context != null) { ComponentOrientation co = context.getComponent(). getComponentOrientation(); if (co == null || co.isLeftToRight()) { direction = LTR; } else { direction = RTL; } } // See if the style defines an icon if (icons != null) { for (int i = 0; i < icons.length; i++) { // find the first one that matches our key if (icons[i].getKey() == key) { iconInfo = icons[i]; break; } } if (iconInfo != null) { // PENDING(shannonh) - pass in actual state bestSource = iconInfo.getBestIconSource(direction, SynthConstants.ENABLED, type); } if (bestSource != null) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?