gtklookandfeel.java

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

JAVA
1,397
字号
        GTKStyleFactory factory = (GTKStyleFactory)getStyleFactory();        GTKStyle windowStyle = (GTKStyle)factory.getStyle("GtkWindow");        table.put("window", windowStyle.getGTKColor(SynthConstants.ENABLED,                                                    GTKColorType.BACKGROUND));        table.put("windowText", windowStyle.getGTKColor(                SynthConstants.ENABLED, GTKColorType.TEXT_FOREGROUND));        GTKStyle entryStyle = (GTKStyle)factory.getStyle("GtkEntry");        table.put("text", entryStyle.getGTKColor(SynthConstants.ENABLED,                                           GTKColorType.TEXT_BACKGROUND));        table.put("textText", entryStyle.getGTKColor(SynthConstants.ENABLED,                                           GTKColorType.TEXT_FOREGROUND));        table.put("textHighlight",                  entryStyle.getGTKColor(SynthConstants.SELECTED,                                         GTKColorType.TEXT_BACKGROUND));        table.put("textHighlightText",                  entryStyle.getGTKColor(SynthConstants.SELECTED,                                         GTKColorType.TEXT_FOREGROUND));        table.put("textInactiveText",                  entryStyle.getGTKColor(SynthConstants.DISABLED,                                         GTKColorType.TEXT_FOREGROUND));        Object caretColor =            entryStyle.getClassSpecificValue(Region.TEXT_FIELD, "cursor-color");        if (caretColor == null) {            caretColor = GTKStyle.BLACK_COLOR;        }        table.put("caretColor", caretColor);                GTKStyle widgetStyle = (GTKStyle)factory.getStyle("GtkWidget");        table.put("control", widgetStyle.getGTKColor(SynthConstants.ENABLED,                                           GTKColorType.BACKGROUND));        table.put("controlText", widgetStyle.getGTKColor(                      SynthConstants.ENABLED,                      GTKColorType.TEXT_FOREGROUND));                table.put("controlHighlight", widgetStyle.getGTKColor(                SynthConstants.ENABLED, GTKColorType.BACKGROUND));        table.put("controlLtHighlight", widgetStyle.getGTKColor(                SynthConstants.ENABLED, GTKColorType.LIGHT));        table.put("controlShadow", widgetStyle.getGTKColor(                SynthConstants.ENABLED, GTKColorType.DARK));        table.put("controlDkShadow", widgetStyle.getGTKColor(                SynthConstants.ENABLED, GTKColorType.BLACK));                        GTKStyle menuStyle = (GTKStyle)factory.getStyle("GtkMenuItem");        table.put("menu", menuStyle.getGTKColor(SynthConstants.ENABLED,                                           GTKColorType.BACKGROUND));        table.put("menuText", menuStyle.getGTKColor(SynthConstants.ENABLED,                                           GTKColorType.TEXT_FOREGROUND));                GTKStyle scrollbarStyle = (GTKStyle)factory.getStyle("GtkScrollbar");        table.put("scrollbar", scrollbarStyle.getGTKColor(SynthConstants.ENABLED,                                           GTKColorType.BACKGROUND));                GTKStyle infoStyle = (GTKStyle)factory.getStyle("GtkMessageDialog");        table.put("info", scrollbarStyle.getGTKColor(SynthConstants.ENABLED,                                           GTKColorType.BACKGROUND));        table.put("infoText", scrollbarStyle.getGTKColor(SynthConstants.ENABLED,                                           GTKColorType.TEXT_FOREGROUND));                GTKStyle desktopStyle = (GTKStyle)factory.getStyle("GtkContainer");        table.put("desktop", scrollbarStyle.getGTKColor(SynthConstants.ENABLED,                                           GTKColorType.BACKGROUND));                // colors specific only for GTK        table.put("light", widgetStyle.getGTKColor(                SynthConstants.ENABLED, GTKColorType.LIGHT));        table.put("mid", widgetStyle.getGTKColor(                SynthConstants.ENABLED, GTKColorType.MID));        table.put("dark", widgetStyle.getGTKColor(                SynthConstants.ENABLED, GTKColorType.DARK));        table.put("black", widgetStyle.getGTKColor(                SynthConstants.ENABLED, GTKColorType.BLACK));        table.put("white", widgetStyle.getGTKColor(                SynthConstants.ENABLED, GTKColorType.WHITE));    }    /**     * Creates the GTK look and feel class for the passed in Component.     */    public static ComponentUI createUI(JComponent c) {        String key = c.getUIClassID().intern();        if (key == "FileChooserUI") {            return GTKFileChooserUI.createUI(c);	}        return SynthLookAndFeel.createUI(c);    }    /**     * Updates the <code>aaText</code> field.     */    static void updateAAText() {        if (!cjkLocale) {            Object aaValue = Toolkit.getDefaultToolkit().                getDesktopProperty("gnome.Xft/Antialias");            aaText = Boolean.valueOf(((aaValue instanceof Number) &&                                      ((Number)aaValue).intValue() == 1));        }    }    static boolean isLeftToRight(Component c) {        return c.getComponentOrientation().isLeftToRight();    }    private static boolean isLocalDisplay() {        try {            Class x11Class = Class.forName("sun.awt.X11GraphicsEnvironment");            Method isDisplayLocalMethod = x11Class.getMethod(                      "isDisplayLocal", new Class[0]);            return (Boolean)isDisplayLocalMethod.invoke(null, null);        } catch (NoSuchMethodException nsme) {        } catch (ClassNotFoundException cnfe) {        } catch (IllegalAccessException iae) {        } catch (InvocationTargetException ite) {        }        // If we get here we're most likely being run on Windows, return        // false.        return false;    }    public void initialize() {        super.initialize();        inInitialize = true;        loadStylesFromThemeFiles();        inInitialize = false;        Toolkit kit = Toolkit.getDefaultToolkit();        WeakPCL pcl = new WeakPCL(this, kit, "gnome.Net/ThemeName");        kit.addPropertyChangeListener(pcl.getKey(), pcl);        pcl = new WeakPCL(this, kit, "gnome.Gtk/FontName");        kit.addPropertyChangeListener(pcl.getKey(), pcl);        pcl = new WeakPCL(this, kit, "gnome.Xft/DPI");        kit.addPropertyChangeListener(pcl.getKey(), pcl);        String language = Locale.getDefault().getLanguage();        cjkLocale =             (Locale.CHINESE.getLanguage().equals(language) ||             Locale.JAPANESE.getLanguage().equals(language) ||             Locale.KOREAN.getLanguage().equals(language));        if (isLocalDisplay()) {            pcl = new WeakPCL(this, kit, "gnome.Xft/Antialias");            kit.addPropertyChangeListener(pcl.getKey(), pcl);            updateAAText();        }        flushUnreferenced();    }    static ReferenceQueue queue = new ReferenceQueue();    static void flushUnreferenced() {        WeakPCL pcl;        while ((pcl = (WeakPCL)queue.poll()) != null) {            pcl.dispose();        }    }    static class WeakPCL extends WeakReference implements            PropertyChangeListener {        private Toolkit kit;        private String key;        WeakPCL(Object target, Toolkit kit, String key) {            super(target, queue);            this.kit = kit;            this.key = key;        }        public String getKey() { return key; }        public void propertyChange(final PropertyChangeEvent pce) {            final GTKLookAndFeel lnf = (GTKLookAndFeel)get();            if (lnf == null || UIManager.getLookAndFeel() != lnf) {                 // The property was GC'ed, we're no longer interested in                // PropertyChanges, remove the listener.                dispose();            }            else {                // We are using invokeLater here because we are getting called                // on the AWT-Motif thread which can cause a deadlock.                SwingUtilities.invokeLater(new Runnable() {                    public void run() {                        if ("gnome.Xft/Antialias".equals(                                                  pce.getPropertyName())) {                            updateAAText();                        }                        lnf.loadStylesFromThemeFiles();                        Frame appFrames[] = Frame.getFrames();                        for (int i = 0; i < appFrames.length; i++) {                            SynthLookAndFeel.updateStyles(appFrames[i]);                        }                    }                });            }        }        void dispose() {            kit.removePropertyChangeListener(key, this);        }    }    public void propertyChange(PropertyChangeEvent evt) {        String propertyName = evt.getPropertyName();	loadStylesFromThemeFiles();        Frame appFrames[] = Frame.getFrames();        for (int i = 0; i < appFrames.length; i++) {            SynthLookAndFeel.updateStyles(appFrames[i]);        }    }    public boolean isSupportedLookAndFeel() {        return true;    }    public boolean isNativeLookAndFeel() {        return false;    }    public String getDescription() {        return "GTK look and feel";    }    public String getName() {        return "GTK look and feel";    }    public String getID() {        return "GTK";    }    // Subclassed to pass in false to the superclass, we don't want to try    // and load the system colors.    protected void loadSystemColors(UIDefaults table, String[] systemColors, boolean useNative) {        super.loadSystemColors(table, systemColors, false);    }    private void loadStylesFromThemeFiles() {        AccessController.doPrivileged(new PrivilegedAction() {            public Object run() {                GTKParser parser = new GTKParser();                // GTK rc file parsing:                // First, attempts to load the file specified in the                // swing.gtkthemefile system property.                // RC files come from one of the following locations:                // 1 - environment variable GTK2_RC_FILES, which is colon                //     separated list of rc files or                // 2 - SYSCONFDIR/gtk-2.0/gtkrc and ~/.gtkrc-2.0                //                 // Additionally the default Theme file is parsed last. The default                // theme name comes from the desktop property gnome.Net/ThemeName                //     Default theme is looked for in ~/.themes/THEME/gtk-2.0/gtkrc                //     and env variable GTK_DATA_PREFIX/THEME/gtkrc or                //     GTK_DATA_PREFIX/THEME/gtk-2.0/gtkrc                //     (or compiled GTK_DATA_PREFIX) GTK_DATA_PREFIX is                //     /usr/share/themes on debian,                //     /usr/sfw/share/themes on Solaris.                // Lastly key bindings are supposed to come from a different theme                // with the path built as above, using the desktop property                // named gnome.Gtk/KeyThemeName.                // Try system property override first:                String filename = System.getProperty("swing.gtkthemefile");                String sep = File.separator;                if (filename == null || !parseThemeFile(filename, parser)) {	            // Try to load user's theme first	            String userHome = System.getProperty("user.home");	            if (userHome != null) {                        parseThemeFile(userHome + sep + ".gtkrc-2.0", parser);	            }	            

⌨️ 快捷键说明

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