gtkstyle.java
来自「JAVA 所有包」· Java 代码 · 共 1,081 行 · 第 1/3 页
JAVA
1,081 行
/* * @(#)GTKStyle.java 1.129 06/12/01 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.java.swing.plaf.gtk;import sun.swing.SwingUtilities2;import java.util.*;import javax.swing.plaf.*;import javax.swing.plaf.synth.*;import java.awt.*;import java.awt.image.BufferedImage;import javax.swing.*;import java.lang.reflect.*;import java.security.*;import sun.awt.AppContext;import sun.swing.plaf.synth.*;/** * * @author Scott Violet */abstract class GTKStyle extends SynthStyle implements GTKConstants { private static final String ICON_PROPERTY_PREFIX = "gtk.icon."; static final Color BLACK_COLOR = new ColorUIResource(Color.BLACK); static final Color WHITE_COLOR = new ColorUIResource(Color.WHITE); static final Font DEFAULT_FONT = new FontUIResource("sansserif", Font.PLAIN, 10 ); static final Insets BUTTON_DEFAULT_BORDER_INSETS = new Insets(1, 1, 1, 1); private static final GTKGraphicsUtils GTK_GRAPHICS = new GTKGraphicsUtils(); /** * Maps from a key that is passed to Style.get to the equivalent class * specific key. */ private static final Map<String,String> CLASS_SPECIFIC_MAP; /** * Backing style properties that are used if the style does not * defined the property. */ private static final Map<String,GTKStockIcon> ICONS_MAP; /** * User specific font. */ private Font font; GTKStyle(Font font) { this.font = font; } Color getGTKColor(int state, ColorType type) { return getGTKColor(null, state, type); } public void installDefaults(SynthContext context) { super.installDefaults(context); if (!context.getRegion().isSubregion()) { context.getComponent().putClientProperty( SwingUtilities2.AA_TEXT_PROPERTY_KEY, GTKLookAndFeel.aaTextInfo); } } public SynthGraphicsUtils getGraphicsUtils(SynthContext context) { return GTK_GRAPHICS; } /** * Returns a <code>SynthPainter</code> that will route the appropriate * calls to a <code>GTKEngine</code>. * * @param state SynthContext indentifying requestor * @return SynthPainter */ public SynthPainter getPainter(SynthContext state) { return GTKPainter.INSTANCE; } protected Color getColorForState(SynthContext context, ColorType type) { if (type == ColorType.FOCUS || type == GTKColorType.BLACK) { return BLACK_COLOR; } else if (type == GTKColorType.WHITE) { return WHITE_COLOR; } Region id = context.getRegion(); int state = context.getComponentState(); state = GTKLookAndFeel.synthStateToGTKState(id, state); if (type == ColorType.TEXT_FOREGROUND && (id == Region.BUTTON || id == Region.CHECK_BOX || id == Region.CHECK_BOX_MENU_ITEM || id == Region.MENU || id == Region.MENU_ITEM || id == Region.RADIO_BUTTON || id == Region.RADIO_BUTTON_MENU_ITEM || id == Region.TABBED_PANE_TAB || id == Region.TOGGLE_BUTTON || id == Region.TOOL_TIP || 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; } } } return getStyleSpecificColor(context, state, type); } /** * Returns color specific for Native or Default style. This method is * invoked when other variants don't fit. * */ abstract Color getStyleSpecificColor(SynthContext context, int state, ColorType type); /** * Returns the color for the specified state. * * @param context SynthContext identifying requester * @param state to get the color for * @param type of the color * @return Color to render with */ Color getGTKColor(SynthContext context, int state, ColorType type) { if (context != null) { JComponent c = context.getComponent(); Region id = context.getRegion(); state = GTKLookAndFeel.synthStateToGTKState(id, state); if (!id.isSubregion() && (state & SynthConstants.ENABLED) != 0) { if (type == ColorType.BACKGROUND || type == ColorType.TEXT_BACKGROUND) { Color bg = c.getBackground(); if (!(bg instanceof UIResource)) { return bg; } } else if (type == ColorType.FOREGROUND || type == ColorType.TEXT_FOREGROUND) { Color fg = c.getForeground(); if (!(fg instanceof UIResource)) { return fg; } } } } return getStyleSpecificColor(context, state, type); } public Color getColor(SynthContext context, ColorType type) { JComponent c = context.getComponent(); Region id = context.getRegion(); int state = context.getComponentState(); if (c.getName() == "Table.cellRenderer") { if (type == ColorType.BACKGROUND) { return c.getBackground(); } if (type == ColorType.FOREGROUND) { return c.getForeground(); } } if (id == Region.LABEL && type == ColorType.TEXT_FOREGROUND) { type = ColorType.FOREGROUND; } // For the enabled state, prefer the widget's colors if (!id.isSubregion() && (state & SynthConstants.ENABLED) != 0) { if (type == ColorType.BACKGROUND) { return c.getBackground(); } else if (type == ColorType.FOREGROUND) { return c.getForeground(); } else if (type == ColorType.TEXT_FOREGROUND) { // If getForeground returns a non-UIResource it means the // developer has explicitly set the foreground, use it over // that of TEXT_FOREGROUND as that is typically the expected // behavior. Color color = c.getForeground(); if (color != null && !(color instanceof UIResource)) { return color; } } } return getColorForState(context, type); } /** * Returns the font for the specified state. * * @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) { return font != null ? font : DEFAULT_FONT; } protected Font getFontForState(SynthContext context) { return getFontForState(context.getComponent(), context.getRegion(), context.getComponentState()); } /** * Returns the X thickness to use for this GTKStyle. * * @return x thickness. */ abstract int getXThickness(); /** * Returns the Y thickness to use for this GTKStyle. * * @return x thickness. */ abstract int getYThickness(); /** * 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. */ abstract Object getClassSpecificValue(Region region, String key); /** * Returns the Insets. If <code>insets</code> is non-null the resulting * insets will be placed in it, otherwise a new Insets object will be * created and returned. * * @param context SynthContext indentifying requestor * @param insets Where to place Insets * @return Insets. */ public Insets getInsets(SynthContext state, Insets insets) { Region id = state.getRegion(); String name = (id.isSubregion()) ? null : state.getComponent().getName(); if (insets == null) { insets = new Insets(0, 0, 0, 0); } else { insets.top = insets.bottom = insets.left = insets.right = 0; } if (id == Region.ARROW_BUTTON || id == Region.BUTTON || id == Region.TOGGLE_BUTTON) { if ("Spinner.previousButton" == name || "Spinner.nextButton" == name) { return getSimpleInsets(state, insets, 1); } else { return getButtonInsets(state, insets); } } else if (id == Region.CHECK_BOX || id == Region.RADIO_BUTTON) { return getRadioInsets(state, insets); } else if (id == Region.MENU_BAR) { return getMenuBarInsets(state, insets); } else if (id == Region.MENU || id == Region.MENU_ITEM || id == Region.CHECK_BOX_MENU_ITEM || id == Region.RADIO_BUTTON_MENU_ITEM) { return getMenuItemInsets(state, insets); } else if (id == Region.FORMATTED_TEXT_FIELD) { return getTextFieldInsets(state, insets); } else if (id == Region.INTERNAL_FRAME) { insets = Metacity.INSTANCE.getBorderInsets(state, insets); } else if (id == Region.LABEL) { if ("TableHeader.renderer" == name) { return getButtonInsets(state, insets); } else if ("ComboBox.renderer" == name || "ComboBox.listRenderer" == name) { return getTextFieldInsets(state, insets); } else if ("Tree.cellRenderer" == name) { return getSimpleInsets(state, insets, 1); } } else if (id == Region.OPTION_PANE) { return getSimpleInsets(state, insets, 6); } else if (id == Region.POPUP_MENU) { return getSimpleInsets(state, insets, 2); } else if (id == Region.PROGRESS_BAR || id == Region.SLIDER || id == Region.TABBED_PANE || id == Region.TABBED_PANE_CONTENT || id == Region.TOOL_BAR || id == Region.TOOL_BAR_DRAG_WINDOW || id == Region.TOOL_TIP) { return getThicknessInsets(state, insets); } else if (id == Region.SCROLL_BAR) { return getScrollBarInsets(state, insets); } else if (id == Region.SLIDER_TRACK) { return getSliderTrackInsets(state, insets); } else if (id == Region.TABBED_PANE_TAB) { return getTabbedPaneTabInsets(state, insets); } else if (id == Region.TEXT_FIELD || id == Region.PASSWORD_FIELD) { if (name == "Tree.cellEditor") { return getSimpleInsets(state, insets, 1); } return getTextFieldInsets(state, insets); } else if (id == Region.SEPARATOR || id == Region.POPUP_MENU_SEPARATOR || id == Region.TOOL_BAR_SEPARATOR) { return getSeparatorInsets(state, insets); } return insets; } private Insets getButtonInsets(SynthContext context, Insets insets) { // The following calculations are derived from gtkbutton.c // (GTK+ version 2.8.20), gtk_button_size_allocate() method. int CHILD_SPACING = 1; int focusSize = getClassSpecificIntValue(context, "focus-line-width",1); int focusPad = getClassSpecificIntValue(context, "focus-padding", 1); int xThickness = getXThickness(); int yThickness = getYThickness(); int w = focusSize + focusPad + xThickness + CHILD_SPACING; int h = focusSize + focusPad + yThickness + CHILD_SPACING; insets.left = insets.right = w; insets.top = insets.bottom = h; Component component = context.getComponent(); if ((component instanceof JButton) &&
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?