synthlookandfeel.java
来自「java jdk 1.4的源码」· Java 代码 · 共 528 行 · 第 1/2 页
JAVA
528 行
/* * @(#)SynthLookAndFeel.java 1.37 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.java.swing.plaf.gtk;import java.awt.*;import java.awt.event.*;import java.beans.*;import java.lang.ref.*;import java.util.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.plaf.*;import sun.awt.AppContext;/** * @version 1.37, 01/23/03 */class SynthLookAndFeel extends LookAndFeel { static final Insets EMPTY_UIRESOURCE_INSETS = new InsetsUIResource( 0, 0, 0, 0); private static final Object STYLE_FACTORY_KEY = new StringBuffer("com.sun.java.swing.plaf.gtk.StyleCache"); /** * The last SynthStyleFactory that was asked for from AppContext * <code>lastContext</code>. */ private static SynthStyleFactory lastFactory; /** * If this is true it indicates there is more than one AppContext active * and that we need to make sure in getStyleCache the requesting * AppContext matches that of <code>lastContext</code> before returning * it. */ private static boolean multipleApps; /** * AppContext lastLAF came from. */ private static AppContext lastContext; /** * Sets the SynthStyleFactory for the current AppContext, null unsets * its for the current AppContext. */ public static void setStyleFactory(SynthStyleFactory cache) { synchronized(SynthLookAndFeel.class) { if (lastFactory == null) { lastFactory = cache; lastContext = AppContext.getAppContext(); } else if (cache == null) { AppContext context = AppContext.getAppContext(); if (lastContext == context) { lastFactory = null; } AppContext.getAppContext().put(STYLE_FACTORY_KEY, null); } else { // More than one active multipleApps = true; AppContext.getAppContext().put(STYLE_FACTORY_KEY, cache); } } } /** * Returns the current SynthStyleFactory. */ public static SynthStyleFactory getStyleFactory() { synchronized(SynthLookAndFeel.class) { if (!multipleApps) { return lastFactory; } AppContext context = AppContext.getAppContext(); if (lastContext == context) { return lastFactory; } lastContext = context; lastFactory = (SynthStyleFactory)AppContext.getAppContext().get (STYLE_FACTORY_KEY); return lastFactory; } } public static int getComponentState(Component c) { if (c.isEnabled()) { if (c.isFocusOwner()) { return SynthUI.ENABLED | SynthUI.FOCUSED; } return SynthUI.ENABLED; } return SynthUI.DISABLED; } public static SynthStyle getStyle(JComponent c, Region region) { return getStyleFactory().getStyle(c, region); } /** * Returns the modifier to use in registering accelerators and the like. */ public static int getAcceleratorModifier() { // PENDING: this should be an instance method. return InputEvent.ALT_MASK; } /** * Returns true if the MouseEvent represents a primary MouseButton. */ public static boolean isPrimaryMouseButton(MouseEvent me) { // PENDING: this should be an instance method. return SwingUtilities.isLeftMouseButton(me); } /** * Returns true if the Style should be updated in response to the * specified PropertyChangeEvent. */ static boolean shouldUpdateStyle(PropertyChangeEvent event) { // 'ancestor' will be interned in JComponent, making this safe. return ("ancestor" == event.getPropertyName() && event.getNewValue() != null); } /** * A convience method that will reset the Style of StyleContext if * necessary. * * @return newStyle */ static SynthStyle updateStyle(SynthContext context, SynthUI ui) { SynthStyle newStyle = getStyle(context.getComponent(), context.getRegion()); SynthStyle oldStyle = context.getStyle(); if (newStyle != oldStyle) { if (oldStyle != null) { oldStyle.uninstallDefaults(context); } context.setStyle(newStyle); newStyle.installDefaults(context, ui); } return newStyle; } static SynthEventListener getSynthEventListener(Component c) { PropertyChangeListener[] listeners = c.getPropertyChangeListeners(); for (int counter = listeners.length - 1; counter >= 0; counter--) { if (listeners[counter] instanceof SynthEventListener) { return (SynthEventListener)listeners[counter]; } } return null; } static void playSound(JComponent c, Object actionKey) { // PENDING: sounds/* ActionMap map = c.getActionMap(); if (map != null) { Action audioAction = map.get(actionName); if (audioAction != null) { // pass off firing the Action to a utility method playSound(audioAction); } }*/ } /** * Returns the Region for c, or defaultRegion if a Region has * not been registered for c yet. */ // PENDING(sky) - need to rethink this. // Made public so that DefaultSynthStyleFactory could access it public static Region getRegion(JComponent c) { return Region.getRegion(c); } /** * A convenience method to return where the foreground should be * painted for the Component identified by the passed in * AbstractSynthContext. */ public static Insets getPaintingInsets(SynthContext state, Insets insets) { if (state.isSubregion()) { insets = state.getStyle().getInsets(state, insets); } else { insets = state.getComponent().getInsets(insets); } return insets; } /** * Convenience method to transfer focus to the next child of component. */ // PENDING: remove this when a variant of this is added to awt. static void compositeRequestFocus(Component component) { if (component instanceof Container) { Container container = (Container)component; if (container.isFocusCycleRoot()) { FocusTraversalPolicy policy = container. getFocusTraversalPolicy(); Component comp = policy.getDefaultComponent(container); if (comp!=null) { comp.requestFocus(); return; } } Container rootAncestor = container.getFocusCycleRootAncestor(); if (rootAncestor!=null) { FocusTraversalPolicy policy = rootAncestor. getFocusTraversalPolicy(); Component comp = policy.getComponentAfter(rootAncestor, container); if (comp!=null && SwingUtilities.isDescendingFrom(comp, container)) { comp.requestFocus(); return; } } } component.requestFocus(); } /** * A convenience method that handles painting of the background. * All SynthUI implementations should override update and invoke * this method. */ static void update(SynthContext state, Graphics g) { paintRegion(state, g, null); } /** * A convenience method that handles painting of the background for * subregions. All SynthUI's that have subregions should invoke * this method, than paint the foreground. */ static void updateSubregion(SynthContext state, Graphics g, Rectangle bounds) { paintRegion(state, g, bounds); } /** * Obtains a foreground Painter from context's SynthStyle and * paints it. * * @param bounds region to paint in, if null the bounds of * the component are used. */ static void paintForeground(SynthContext context, Graphics g, Rectangle bounds) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?