gtklookandfeel.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,397 行 · 第 1/5 页

JAVA
1,397
字号
/* * @(#)GTKLookAndFeel.java	1.75 06/12/14 * * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.java.swing.plaf.gtk;import com.sun.java.swing.SwingUtilities2;import java.lang.ref.*;import javax.swing.plaf.synth.*;import java.awt.*;import java.awt.event.*;import java.beans.*;import java.io.File;import java.lang.reflect.*;import java.security.AccessController;import java.security.PrivilegedAction;import java.util.HashMap;import java.util.Locale;import javax.swing.*;import javax.swing.colorchooser.*;import javax.swing.plaf.*;import javax.swing.text.DefaultEditorKit;import java.io.IOException;import sun.security.action.GetPropertyAction;/** * @version 1.75, 12/14/06 * @author Scott Violet */public class GTKLookAndFeel extends SynthLookAndFeel {    private static final boolean IS_22;    /**     * Whether or not text is drawn antialiased.  This keys off the     * desktop property 'gnome.Xft/Antialias'.     */    static Boolean aaText = Boolean.FALSE;    /**     * Whether or not the default locale is CJK. If it is,     * the GNOME desktop property for antialiasing is ignored     * and the text is always rendered w/o aa.     * This is done to be consistent with what GTK does - they     * disable text aa for CJK locales as well.     *     * Note: this doesn't work well with changing locales     * at runtime. But most of Swing/2D code (including fonts     * initialization) doesn't either.     */    static boolean cjkLocale;    /**     * Font to use in places where there is no widget.     */    private Font fallbackFont;    /**     * If true, GTKLookAndFeel is inside the <code>initialize</code>     * method.     */    private boolean inInitialize;    static {        // Backup for specifying the version, this isn't currently documented.        // If you pass in anything but 2.2 you got the 2.0 colors/look.        String version = (String)java.security.AccessController.doPrivileged(               new GetPropertyAction("swing.gtk.version"));        if (version != null) {            IS_22 = version.equals("2.2");        }        else {            IS_22 = true;        }    }    /**     * Returns true if running on system containing at least 2.2.     */    static boolean is2_2() {        // NOTE: We're currently hard coding to use 2.2.        // If we want to support both GTK 2.0 and 2.2, we'll        // need to get the major/minor/micro version from the .so.        // Refer to bug 4912613 for details.        return IS_22;    }    /**     * Maps a swing constant to a GTK constant.     */    static int SwingOrientationConstantToGTK(int side) {        switch (side) {        case SwingConstants.LEFT:            return GTKConstants.LEFT;        case SwingConstants.RIGHT:            return GTKConstants.RIGHT;        case SwingConstants.TOP:            return GTKConstants.TOP;        case SwingConstants.BOTTOM:            return GTKConstants.BOTTOM;        }        assert false : "Unknowning orientation: " + side;        return side;    }    /**     * Maps from a Synth state to the corresponding GTK state.      * The GTK states are named differently than Synth's states, the     * following gives the mapping:     * <table><tr><td>Synth<td>GTK     * <tr><td>SynthConstants.PRESSED<td>ACTIVE     * <tr><td>SynthConstants.SELECTED<td>SELECTED     * <tr><td>SynthConstants.MOUSE_OVER<td>PRELIGHT     * <tr><td>SynthConstants.DISABLED<td>INACTIVE     * <tr><td>SynthConstants.ENABLED<td>NORMAL     * </table>     * Additionally some widgets are special cased.     */    static int synthStateToGTKState(Region region, int state) {        int orgState = state;        if ((state & SynthConstants.PRESSED) != 0) {            if (region == Region.RADIO_BUTTON                    || region == Region.CHECK_BOX                    || region == Region.TOGGLE_BUTTON                    || region == Region.MENU                    || region == Region.MENU_ITEM                    || region == Region.RADIO_BUTTON_MENU_ITEM                    || region == Region.CHECK_BOX_MENU_ITEM                    || region == Region.SPLIT_PANE) {                state = SynthConstants.MOUSE_OVER;            } else {                state = SynthConstants.PRESSED;            }        }        else if ((state & SynthConstants.SELECTED) != 0) {            if (region == Region.MENU) {                state = SynthConstants.MOUSE_OVER;            } else if (region == Region.RADIO_BUTTON ||                          region == Region.TOGGLE_BUTTON ||                          region == Region.RADIO_BUTTON_MENU_ITEM ||                          region == Region.CHECK_BOX_MENU_ITEM ||                          region == Region.CHECK_BOX ||                          region == Region.BUTTON) {                // If the button is SELECTED and is PRELIGHT we need to                // make the state MOUSE_OVER otherwise we don't paint the                // PRELIGHT.                if ((state & SynthConstants.MOUSE_OVER) != 0) {                    state = SynthConstants.MOUSE_OVER;                } else if ((state & SynthConstants.DISABLED) != 0){                    state = SynthConstants.DISABLED;                } else {                    state = SynthConstants.PRESSED;                }            } else if (region == Region.TABBED_PANE_TAB) {                state = SynthConstants.ENABLED;            } else {                state = SynthConstants.SELECTED;            }        }        else if ((state & SynthConstants.MOUSE_OVER) != 0) {            state = SynthConstants.MOUSE_OVER;        }        else if ((state & SynthConstants.DISABLED) != 0) {            state = SynthConstants.DISABLED;        }        else {            if (region == Region.SLIDER_TRACK) {                state = SynthConstants.PRESSED;            } else if (region == Region.TABBED_PANE_TAB) {                state = SynthConstants.PRESSED;            } else {                state = SynthConstants.ENABLED;            }        }        return state;    }    static boolean isText(Region region) {        // These Regions treat FOREGROUND as TEXT.        return (region == Region.TEXT_FIELD ||                region == Region.FORMATTED_TEXT_FIELD ||                region == Region.LIST ||                region == Region.PASSWORD_FIELD ||                region == Region.SPINNER ||                region == Region.TABLE ||                region == Region.TEXT_AREA ||                region == Region.TEXT_FIELD ||                region == Region.TEXT_PANE ||                region == Region.TREE);    }    public UIDefaults getDefaults() {        // We need to call super for basic's properties file.        UIDefaults table = super.getDefaults();        initResourceBundle(table);        // For compatability with apps expecting certain defaults we'll        // populate the table with the values from basic.        initSystemColorDefaults(table);        initComponentDefaults(table);        return table;    }    private void initResourceBundle(UIDefaults table) {        table.addResourceBundle("com.sun.java.swing.plaf.gtk.resources.gtk");    }    protected void initComponentDefaults(UIDefaults table) {        // For compatability with apps expecting certain defaults we'll        // populate the table with the values from basic.        super.initComponentDefaults(table);        Object focusBorder = new GTKStyle.GTKLazyValue(            "com.sun.java.swing.plaf.gtk.GTKPainter$ListTableFocusBorder",            "getUnselectedCellBorder");        Object focusSelectedBorder = new GTKStyle.GTKLazyValue(            "com.sun.java.swing.plaf.gtk.GTKPainter$ListTableFocusBorder",            "getSelectedCellBorder");        GTKStyleFactory factory = (GTKStyleFactory)getStyleFactory();         GTKStyle tableStyle = (GTKStyle)factory.getStyle("GtkTreeView");        Color tableFocusCellBg = tableStyle.getColorForState(null, Region.TABLE,                SynthConstants.ENABLED, GTKColorType.BACKGROUND);        Color tableFocusCellFg = tableStyle.getColorForState(null, Region.TABLE,                SynthConstants.ENABLED, GTKColorType.FOREGROUND);                Integer caretBlinkRate = new Integer(500);        Insets zeroInsets = new InsetsUIResource(0, 0, 0, 0);        Double defaultCaretAspectRatio = new Double(0.025);        Color caretColor = table.getColor("caretColor");                Object fieldInputMap = new UIDefaults.LazyInputMap(new Object[] {                       "ctrl C", DefaultEditorKit.copyAction,                       "ctrl V", DefaultEditorKit.pasteAction,                       "ctrl X", DefaultEditorKit.cutAction,                         "COPY", DefaultEditorKit.copyAction,                        "PASTE", DefaultEditorKit.pasteAction,                          "CUT", DefaultEditorKit.cutAction,                   "shift LEFT", DefaultEditorKit.selectionBackwardAction,                "shift KP_LEFT", DefaultEditorKit.selectionBackwardAction,                  "shift RIGHT", DefaultEditorKit.selectionForwardAction,               "shift KP_RIGHT", DefaultEditorKit.selectionForwardAction,                    "ctrl LEFT", DefaultEditorKit.previousWordAction,                 "ctrl KP_LEFT", DefaultEditorKit.previousWordAction,                   "ctrl RIGHT", DefaultEditorKit.nextWordAction,                "ctrl KP_RIGHT", DefaultEditorKit.nextWordAction,              "ctrl shift LEFT", DefaultEditorKit.selectionPreviousWordAction,           "ctrl shift KP_LEFT", DefaultEditorKit.selectionPreviousWordAction,             "ctrl shift RIGHT", DefaultEditorKit.selectionNextWordAction,          "ctrl shift KP_RIGHT", DefaultEditorKit.selectionNextWordAction,                       "ctrl A", DefaultEditorKit.selectAllAction,                         "HOME", DefaultEditorKit.beginLineAction,                          "END", DefaultEditorKit.endLineAction,                   "shift HOME", DefaultEditorKit.selectionBeginLineAction,                    "shift END", DefaultEditorKit.selectionEndLineAction,                   "BACK_SPACE", DefaultEditorKit.deletePrevCharAction,                       "ctrl H", DefaultEditorKit.deletePrevCharAction,                       "DELETE", DefaultEditorKit.deleteNextCharAction,                        "RIGHT", DefaultEditorKit.forwardAction,                         "LEFT", DefaultEditorKit.backwardAction,                     "KP_RIGHT", DefaultEditorKit.forwardAction,                      "KP_LEFT", DefaultEditorKit.backwardAction,                        "ENTER", JTextField.notifyAction,              "ctrl BACK_SLASH", "unselect"/*DefaultEditorKit.unselectAction*/,               "control shift O", "toggle-componentOrientation"/*DefaultEditorKit.toggleComponentOrientation*/            });        Object passwordInputMap = new UIDefaults.LazyInputMap(new Object[] {                       "ctrl C", DefaultEditorKit.copyAction,                       "ctrl V", DefaultEditorKit.pasteAction,                       "ctrl X", DefaultEditorKit.cutAction,                         "COPY", DefaultEditorKit.copyAction,                        "PASTE", DefaultEditorKit.pasteAction,                          "CUT", DefaultEditorKit.cutAction,                   "shift LEFT", DefaultEditorKit.selectionBackwardAction,                "shift KP_LEFT", DefaultEditorKit.selectionBackwardAction,

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?