nimbuslookandfeel.java
来自「Mobile 应用程序使用 Java Micro Edition (Java M」· Java 代码 · 共 503 行 · 第 1/2 页
JAVA
503 行
* UIDefaults table. The key for each property, state, painter, and other * default registered in UIDefaults for a specific Region will begin with * the specified <code>prefix</code></p> * * <p>For example, suppose I had a component named JFoo. Suppose I then registered * this component with the NimbusLookAndFeel in this manner:</p> * * <pre><code> * laf.register(NimbusFooUI.FOO_REGION, "Foo"); * </code></pre> * * <p>In this case, I could then register properties for this component with * UIDefaults in the following manner:</p> * * <pre><code> * UIManager.put("Foo.background", new ColorUIResource(Color.BLACK)); * UIManager.put("Foo.Enabled.backgroundPainter", new FooBackgroundPainter()); * </code></pre> * * <p>It is also possible to register a named component with Nimbus. * For example, suppose you wanted to style the background of a JPanel * named "MyPanel" differently from other JPanels. You could accomplish this * by doing the following:</p> * * <pre><code> * laf.register(Region.PANEL, "\"MyPanel\""); * UIManager.put("\"MyPanel\".background", new ColorUIResource(Color.RED)); * </code></pre> * * @param region The Synth Region that is being registered. Such as Button, or * ScrollBarThumb, or NimbusFooUI.FOO_REGION. * @param prefix The UIDefault prefix. For example, could be ComboBox, or if * a named components, "MyComboBox", or even something like * ToolBar."MyComboBox"."ComboBox.arrowButton" */ public void register(Region region, String prefix) { defaults.register(region, prefix); } /** * Simple utility method that reads system keys. */ private String getSystemProperty(String key) { return AccessController.doPrivileged(new GetPropertyAction(key)); } @Override public Icon getDisabledIcon(JComponent component, Icon icon) { if (icon instanceof SynthIcon) { SynthIcon si = (SynthIcon)icon; BufferedImage img = EffectUtils.createCompatibleTranslucentImage( si.getIconWidth(), si.getIconHeight()); Graphics2D gfx = img.createGraphics(); si.paintIcon(component, gfx, 0, 0); gfx.dispose(); return new ImageIconUIResource(GrayFilter.createDisabledImage(img)); } else { return super.getDisabledIcon(component, icon); } } /** * Get a derived color, derived colors are shared instances and is color * value will change when its parent UIDefault color changes. * * @param uiDefaultParentName The parent UIDefault key * @param hOffset The hue offset * @param sOffset The saturation offset * @param bOffset The brightness offset * @param aOffset The alpha offset * @param uiResource True if the derived color should be a * UIResource, false if it should not be * @return The stored derived color */ public Color getDerivedColor(String uiDefaultParentName, float hOffset, float sOffset, float bOffset, int aOffset, boolean uiResource) { return defaults.getDerivedColor(uiDefaultParentName, hOffset, sOffset, bOffset, aOffset, uiResource); } /** * Decodes and returns a color, which is derived from an offset between two * other colors. * * @param color1 The first color * @param color2 The second color * @param midPoint The offset between color 1 and color 2, a value of 0.0 is * color 1 and 1.0 is color 2; * @param uiResource True if the derived color should be a UIResource * @return The derived color */ protected final Color getDerivedColor(Color color1, Color color2, float midPoint, boolean uiResource) { int argb = deriveARGB(color1, color2, midPoint); if (uiResource) { return new ColorUIResource(argb); } else { return new Color(argb); } } /** * Decodes and returns a color, which is derived from a offset between two * other colors. * * @param color1 The first color * @param color2 The second color * @param midPoint The offset between color 1 and color 2, a value of 0.0 is * color 1 and 1.0 is color 2; * @return The derived color, which will be a UIResource */ protected final Color getDerivedColor(Color color1, Color color2, float midPoint) { return getDerivedColor(color1, color2, midPoint, true); } /** * Package private method which returns either BorderLayout.NORTH, * BorderLayout.SOUTH, BorderLayout.EAST, or BorderLayout.WEST depending * on the location of the toolbar in its parent. The toolbar might be * in PAGE_START, PAGE_END, CENTER, or some other position, but will be * resolved to either NORTH,SOUTH,EAST, or WEST based on where the toolbar * actually IS, with CENTER being NORTH. * * This code is used to determine where the border line should be drawn * by the custom toolbar states, and also used by NimbusIcon to determine * whether the handle icon needs to be shifted to look correct. * * Toollbars are unfortunately odd in the way these things are handled, * and so this code exists to unify the logic related to toolbars so it can * be shared among the static files such as NimbusIcon and generated files * such as the ToolBar state classes. */ static Object resolveToolbarConstraint(JToolBar toolbar) { //NOTE: we don't worry about component orientation or PAGE_END etc //because the BasicToolBarUI always uses an absolute position of //NORTH/SOUTH/EAST/WEST. if (toolbar != null) { Container parent = toolbar.getParent(); if (parent != null) { LayoutManager m = parent.getLayout(); if (m instanceof BorderLayout) { BorderLayout b = (BorderLayout)m; Object con = b.getConstraints(toolbar); if (con == SOUTH || con == EAST || con == WEST) { return con; } return NORTH; } } } return NORTH; } /** * Derives the ARGB value for a color based on an offset between two * other colors. * * @param color1 The first color * @param color2 The second color * @param midPoint The offset between color 1 and color 2, a value of 0.0 is * color 1 and 1.0 is color 2; * @return the ARGB value for a new color based on this derivation */ static int deriveARGB(Color color1, Color color2, float midPoint) { int r = color1.getRed() + (int) ((color2.getRed() - color1.getRed()) * midPoint + 0.5f); int g = color1.getGreen() + (int) ((color2.getGreen() - color1.getGreen()) * midPoint + 0.5f); int b = color1.getBlue() + (int) ((color2.getBlue() - color1.getBlue()) * midPoint + 0.5f); int a = color1.getAlpha() + (int) ((color2.getAlpha() - color1.getAlpha()) * midPoint + 0.5f); return ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF); } /** * Simple Symbolic Link style UIDefalts Property */ private class LinkProperty implements UIDefaults.ActiveValue, UIResource{ private String dstPropName; private LinkProperty(String dstPropName) { this.dstPropName = dstPropName; } @Override public Object createValue(UIDefaults table) { return UIManager.get(dstPropName); } } /** * Nimbus Property that looks up Nimbus keys for standard key names. For * example "Button.background" --> "Button[Enabled].backgound" */ private class NimbusProperty implements UIDefaults.ActiveValue, UIResource { private String prefix; private String state = null; private String suffix; private boolean isFont; private NimbusProperty(String prefix, String suffix) { this.prefix = prefix; this.suffix = suffix; isFont = "font".equals(suffix); } private NimbusProperty(String prefix, String state, String suffix) { this(prefix,suffix); this.state = state; } /** * Creates the value retrieved from the <code>UIDefaults</code> table. * The object is created each time it is accessed. * * @param table a <code>UIDefaults</code> table * @return the created <code>Object</code> */ @Override public Object createValue(UIDefaults table) { Object obj = null; // check specified state if (state!=null){ obj = uiDefaults.get(prefix+"["+state+"]."+suffix); } // check enabled state if (obj==null){ obj = uiDefaults.get(prefix+"[Enabled]."+suffix); } // check for defaults if (obj==null){ if (isFont) { obj = uiDefaults.get("defaultFont"); } else { obj = uiDefaults.get(suffix); } } return obj; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?