gtkstyle.java
来自「Mobile 应用程序使用 Java Micro Edition (Java M」· Java 代码 · 共 1,138 行 · 第 1/3 页
JAVA
1,138 行
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 troughBorder = getClassSpecificIntValue(context, "trough-border", 1); insets.left = insets.right = insets.top = insets.bottom = troughBorder; JComponent c = context.getComponent(); if (c.getParent() instanceof JScrollPane) { // This scrollbar is part of a scrollpane; use only the // "scrollbar-spacing" style property to determine the padding // between the scrollbar and its parent scrollpane. int spacing = getClassSpecificIntValue(WidgetType.SCROLL_PANE, "scrollbar-spacing", 3); if (((JScrollBar)c).getOrientation() == JScrollBar.HORIZONTAL) { insets.top += spacing; } else { if (c.getComponentOrientation().isLeftToRight()) { insets.left += spacing; } else { insets.right += spacing; } } } else { // This is a standalone scrollbar; leave enough room for the // focus line in addition to the trough border. if (c.isFocusable()) { int focusSize = getClassSpecificIntValue(context, "focus-line-width", 1); int focusPad = getClassSpecificIntValue(context, "focus-padding", 1); int totalFocus = focusSize + focusPad; insets.left += totalFocus; insets.right += totalFocus; insets.top += totalFocus; insets.bottom += totalFocus; } } return insets; } /** * Returns the value for a class specific property for a particular * WidgetType. 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 insets for a * SCROLL_BAR, but certain values can only be extracted from a * SCROLL_PANE region). * * @param wt WidgetType for which to fetch the value * @param key Key identifying class specific value * @return Value, or null if one has not been defined */ Object getClassSpecificValue(WidgetType wt, String key) { return null; } /** * Convenience method to get a class specific integer value for * a particular WidgetType. * * @param wt WidgetType 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 */ int getClassSpecificIntValue(WidgetType wt, String key, int defaultValue) { Object value = getClassSpecificValue(wt, 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 = getClassSpecificIntValue(WidgetType.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; } else if (key == "ScrollBar.minimumThumbSize") { int len = getClassSpecificIntValue(context, "min-slider-length", 21); JScrollBar sb = (JScrollBar)context.getComponent(); if (sb.getOrientation() == JScrollBar.HORIZONTAL) { return new DimensionUIResource(len, 0); } else { return new DimensionUIResource(0, len); } } else if (key == "ScrollBar.buttonSize") { JScrollBar sb = (JScrollBar)context.getComponent().getParent(); boolean horiz = (sb.getOrientation() == JScrollBar.HORIZONTAL); WidgetType wt = horiz ? WidgetType.HSCROLL_BAR : WidgetType.VSCROLL_BAR; int sliderWidth = getClassSpecificIntValue(wt, "slider-width", 14); int stepperSize = getClassSpecificIntValue(wt, "stepper-size", 14); return horiz ? new DimensionUIResource(stepperSize, sliderWidth) : new DimensionUIResource(sliderWidth, stepperSize); } else if (key == "ArrowButton.size") { String name = context.getComponent().getName(); if (name != null && name.startsWith("Spinner")) { // Believe it or not, the size of a spinner arrow button is // dependent upon the size of the spinner's font. These // calculations come from gtkspinbutton.c (version 2.8.20),
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?