gtkstyle.java
来自「JAVA 所有包」· Java 代码 · 共 1,081 行 · 第 1/3 页
JAVA
1,081 行
!(component.getParent() instanceof JToolBar) && ((JButton)component).isDefaultCapable()) { // Include the default border insets, but only for JButtons // that are default capable. Note that // JButton.getDefaultCapable() returns true by default, but // GtkToolButtons are never default capable, so we skip this // step if the button is contained in a toolbar. Insets defaultInsets = getClassSpecificInsetsValue(context, "default-border", BUTTON_DEFAULT_BORDER_INSETS); insets.left += defaultInsets.left; insets.right += defaultInsets.right; insets.top += defaultInsets.top; insets.bottom += defaultInsets.bottom; } return insets; } /* * This is used for both RADIO_BUTTON and CHECK_BOX. */ private Insets getRadioInsets(SynthContext context, Insets insets) { // The following calculations are derived from gtkcheckbutton.c // (GTK+ version 2.8.20), gtk_check_button_size_allocate() method. int focusSize = getClassSpecificIntValue(context, "focus-line-width", 1); int focusPad = getClassSpecificIntValue(context, "focus-padding", 1); int totalFocus = focusSize + focusPad; // Note: GTKIconFactory.DelegateIcon will have already included the // "indicator-spacing" value in the size of the indicator icon, // which explains why we use zero as the left inset (or right inset // in the RTL case); see 6489585 for more details. insets.top = totalFocus; insets.bottom = totalFocus; if (context.getComponent().getComponentOrientation().isLeftToRight()) { insets.left = 0; insets.right = totalFocus; } else { insets.left = totalFocus; insets.right = 0; } return insets; } private Insets getMenuBarInsets(SynthContext context, Insets insets) { // The following calculations are derived from gtkmenubar.c // (GTK+ version 2.8.20), gtk_menu_bar_size_allocate() method. int internalPadding = getClassSpecificIntValue(context, "internal-padding", 1); int xThickness = getXThickness(); int yThickness = getYThickness(); insets.left = insets.right = xThickness + internalPadding; insets.top = insets.bottom = yThickness + internalPadding; return insets; } private Insets getMenuItemInsets(SynthContext context, Insets insets) { // The following calculations are derived from gtkmenuitem.c // (GTK+ version 2.8.20), gtk_menu_item_size_allocate() method. int horizPadding = getClassSpecificIntValue(context, "horizontal-padding", 3); int xThickness = getXThickness(); int yThickness = getYThickness(); insets.left = insets.right = xThickness + horizPadding; insets.top = insets.bottom = yThickness; return insets; } private Insets getThicknessInsets(SynthContext context, Insets insets) { insets.left = insets.right = getXThickness(); insets.top = insets.bottom = getYThickness(); return insets; } private Insets getSeparatorInsets(SynthContext context, Insets insets) { int horizPadding = 0; if (context.getRegion() == Region.POPUP_MENU_SEPARATOR) { horizPadding = getClassSpecificIntValue(context, "horizontal-padding", 3); } insets.right = insets.left = getXThickness() + horizPadding; insets.top = insets.bottom = getYThickness(); return insets; } private Insets getSliderTrackInsets(SynthContext context, Insets insets) { int focusSize = getClassSpecificIntValue(context, "focus-line-width", 1); int focusPad = getClassSpecificIntValue(context, "focus-padding", 1); insets.top = insets.bottom = insets.left = insets.right = focusSize + focusPad; return insets; } private Insets getSimpleInsets(SynthContext context, Insets insets, int n) { insets.top = insets.bottom = insets.right = insets.left = n; return insets; } private Insets getTabbedPaneTabInsets(SynthContext context, Insets insets) { int xThickness = getXThickness(); int yThickness = getYThickness(); int focusSize = getClassSpecificIntValue(context, "focus-line-width",1); int pad = 2; insets.left = insets.right = focusSize + pad + xThickness; insets.top = insets.bottom = focusSize + pad + yThickness; return insets; } // NOTE: this is called for ComboBox, and FormattedTextField. too. private Insets getTextFieldInsets(SynthContext context, Insets insets) { int xThickness = getXThickness(); int yThickness = getYThickness(); boolean interiorFocus = getClassSpecificBoolValue(context, "interior-focus", true); int focusSize = 0; if (!interiorFocus) { focusSize = getClassSpecificIntValue(context, "focus-line-width",1); } insets.left = insets.right = focusSize + xThickness + 2; insets.top = insets.bottom = focusSize + yThickness + 2; return insets; } private Insets getScrollBarInsets(SynthContext context, Insets insets) { int inset = 0; if (context.getComponent().isFocusable()) { int focusSize = getClassSpecificIntValue(context, "focus-line-width",1); int focusPad = getClassSpecificIntValue(context, "focus-padding", 1); inset = focusSize + focusPad; } int troughBorder = getClassSpecificIntValue(context, "trough-border", 1); inset += troughBorder; insets.left = insets.right = insets.top = insets.bottom = inset; return insets; } /** * Returns the value for a class specific property for a particular * region. This method is useful in those cases where we need to fetch * a value for a Region that is not associated with the component * currently in use (e.g. we need to figure out the size of a * SEPARATOR, but certain values can only be extracted from a * TOOL_BAR region). * * REMIND: This method can be safely removed once the fixes for * 6468814 and 6464868 are backported to a JDK 6 update release. * * @param r Region for which to fetch the value * @param key Key identifying class specific value * @return Value, or null if one has not been defined */ private static Object getClassSpecificValueForRegion(Region r, String key) { GTKStyleFactory factory = (GTKStyleFactory) GTKLookAndFeel.getStyleFactory(); GTKStyle style = (GTKStyle)factory.getStyle(null, r); return style.getClassSpecificValue(r, key); } /** * Convenience method to get a class specific integer value for * a particular region. * * REMIND: This method can be safely removed once the fixes for * 6468814 and 6464868 are backported to a JDK 6 update release. * * @param r Region for which to fetch the value * @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 * @see #getClassSpecificValueForRegion */ private static int getClassSpecificIntValueForRegion(Region r, String key, int defaultValue) { Object value = getClassSpecificValueForRegion(r, key); if (value instanceof Number) { return ((Number)value).intValue(); } return defaultValue; } /** * Returns the value for a class specific property. A class specific value * is a value that will be picked up based on class hierarchy. * * @param context SynthContext indentifying requestor * @param key Key identifying class specific value * @return Value, or null if one has not been defined. */ Object getClassSpecificValue(SynthContext context, String key) { return getClassSpecificValue(context.getRegion(), key); } /** * Convenience method to get a class specific integer 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 int getClassSpecificIntValue(SynthContext context, String key, int defaultValue) { Object value = getClassSpecificValue(context, key); if (value instanceof Number) { return ((Number)value).intValue(); } return defaultValue; } /** * Convenience method to get a class specific Insets 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 */ Insets getClassSpecificInsetsValue(SynthContext context, String key, Insets defaultValue) { Object value = getClassSpecificValue(context, key); if (value instanceof Insets) { return (Insets)value; } 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 */ boolean getClassSpecificBoolValue(SynthContext context, String key, boolean defaultValue) { Object value = getClassSpecificValue(context, key); if (value instanceof Boolean) { return ((Boolean)value).booleanValue(); } return defaultValue; } /** * 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.PANEL || 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.SPLIT_PANE_DIVIDER || 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; } public Object get(SynthContext context, Object key) { // See if this is a class specific value. String classKey = CLASS_SPECIFIC_MAP.get(key); if (classKey != null) { Object value = getClassSpecificValue(context, classKey); if (value != null) { return value; } } // Is it a specific value ? if (key == "ScrollPane.viewportBorderInsets") { return getThicknessInsets(context, new Insets(0, 0, 0, 0)); } else if (key == "Slider.tickColor") { return getColorForState(context, ColorType.FOREGROUND); } else if (key == "Separator.thickness") { JSeparator sep = (JSeparator)context.getComponent(); if (sep.getOrientation() == JSeparator.HORIZONTAL) { return getYThickness(); } else { return getXThickness(); } } else if (key == "ToolBar.separatorSize") { int size = getClassSpecificIntValueForRegion(Region.TOOL_BAR, "space-size", 12); return new DimensionUIResource(size, size); } else if ("CheckBox.iconTextGap".equals(key) || "RadioButton.iconTextGap".equals(key)) { // The iconTextGap value needs to include "indicator-spacing" // and it also needs to leave enough space for the focus line, // which falls between the indicator icon and the text. // See getRadioInsets() and 6489585 for more details. int indicatorSpacing = getClassSpecificIntValue(context, "indicator-spacing", 2); int focusSize = getClassSpecificIntValue(context, "focus-line-width", 1); int focusPad = getClassSpecificIntValue(context, "focus-padding", 1); return indicatorSpacing + focusSize + focusPad; } // Is it a stock icon ? GTKStockIcon stockIcon = null; synchronized (ICONS_MAP) { stockIcon = ICONS_MAP.get(key); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?