abstractregionpainter.java
来自「Mobile 应用程序使用 Java Micro Edition (Java M」· Java 代码 · 共 718 行 · 第 1/3 页
JAVA
718 行
return ((y-1) * centerHeight) + topHeight; } else if (y >= 2 && y <= 3) { return ((y-2) * bottomHeight) + topHeight + centerHeight; } else { throw new AssertionError("Invalid y"); } } /** * Decodes and returns a float value representing the actual pixel location for * the anchor point given the encoded X value of the control point, and the offset * distance to the anchor from that control point. * * @param x an encoded x value of the bezier control point (0...1, or 1...2, or 2...3) * @param dx the offset distance to the anchor from the control point x * @return the decoded x location of the control point */ protected final float decodeAnchorX(float x, float dx) { if (ctx.canvasSize == null) return x + dx; if (x >= 0 && x <= 1) { return decodeX(x) + (dx * leftScale); } else if (x > 1 && x < 2) { return decodeX(x) + (dx * centerHScale); } else if (x >= 2 && x <= 3) { return decodeX(x) + (dx * rightScale); } else { throw new AssertionError("Invalid x"); } } /** * Decodes and returns a float value representing the actual pixel location for * the anchor point given the encoded Y value of the control point, and the offset * distance to the anchor from that control point. * * @param y an encoded y value of the bezier control point (0...1, or 1...2, or 2...3) * @param dy the offset distance to the anchor from the control point y * @return the decoded y position of the control point */ protected final float decodeAnchorY(float y, float dy) { if (ctx.canvasSize == null) return y + dy; if (y >= 0 && y <= 1) { return decodeY(y) + (dy * topScale); } else if (y > 1 && y < 2) { return decodeY(y) + (dy * centerVScale); } else if (y >= 2 && y <= 3) { return decodeY(y) + (dy * bottomScale); } else { throw new AssertionError("Invalid y"); } } /** * Decodes and returns a color, which is derived from a base color in UI * defaults. * * @param key A key corrosponding to the value in the UI Defaults table * of UIManager where the base color is defined * @param hOffset The hue offset used for derivation. * @param sOffset The saturation offset used for derivation. * @param bOffset The brightness offset used for derivation. * @param aOffset The alpha offset used for derivation. Between 0...255 * @return The derived color, whos color value will change if the parent * uiDefault color changes. */ protected final Color decodeColor(String key, float hOffset, float sOffset, float bOffset, int aOffset) { if (UIManager.getLookAndFeel() instanceof NimbusLookAndFeel){ NimbusLookAndFeel laf = (NimbusLookAndFeel) UIManager.getLookAndFeel(); return laf.getDerivedColor(key, hOffset, sOffset, bOffset, aOffset, true); } else { // can not give a right answer as painter sould not be used outside // of nimbus laf but do the best we can return Color.getHSBColor(hOffset,sOffset,bOffset); } } /** * 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 */ protected final Color decodeColor(Color color1, Color color2, float midPoint) { return new Color(deriveARGB(color1, color2, midPoint)); } /** * Given parameters for creating a LinearGradientPaint, this method will * create and return a linear gradient paint. One primary purpose for this * method is to avoid creating a LinearGradientPaint where the start and * end points are equal. In such a case, the end y point is slightly * increased to avoid the overlap. * * @param x1 * @param y1 * @param x2 * @param y2 * @param midpoints * @param colors * @return a valid LinearGradientPaint. This method never returns null. */ protected final LinearGradientPaint decodeGradient(float x1, float y1, float x2, float y2, float[] midpoints, Color[] colors) { if (x1 == x2 && y1 == y2) { y2 += .00001f; } return new LinearGradientPaint(x1, y1, x2, y2, midpoints, colors); } /** * Given parameters for creating a RadialGradientPaint, this method will * create and return a radial gradient paint. One primary purpose for this * method is to avoid creating a RadialGradientPaint where the radius * is non-positive. In such a case, the radius is just slightly * increased to avoid 0. * * @param x * @param y * @param r * @param midpoints * @param colors * @return a valid RadialGradientPaint. This method never returns null. */ protected final RadialGradientPaint decodeRadialGradient(float x, float y, float r, float[] midpoints, Color[] colors) { if (r == 0f) { r = .00001f; } return new RadialGradientPaint(x, y, r, midpoints, colors); } /** * Get a color property from the given JComponent. First checks for a * <code>getXXX()</code> method and if that fails checks for a client * property with key <code>property</code>. If that still fails to return * a Color then <code>defaultColor</code> is returned. * * @param c The component to get the color property from * @param property The name of a bean style property or client property * @param defaultColor The color to return if no color was obtained from * the component. * @return The color that was obtained from the component or defaultColor */ protected final Color getComponentColor(JComponent c, String property, Color defaultColor, float saturationOffset, float brightnessOffset, int alphaOffset) { Color color = null; if (c != null) { // handle some special cases for performance if ("background".equals(property)) { color = c.getBackground(); } else if ("foreground".equals(property)) { color = c.getForeground(); } else if (c instanceof JList && "selectionForeground".equals(property)) { color = ((JList) c).getSelectionForeground(); } else if (c instanceof JList && "selectionBackground".equals(property)) { color = ((JList) c).getSelectionBackground(); } else if (c instanceof JTable && "selectionForeground".equals(property)) { color = ((JTable) c).getSelectionForeground(); } else if (c instanceof JTable && "selectionBackground".equals(property)) { color = ((JTable) c).getSelectionBackground(); } else { String s = "get" + Character.toUpperCase(property.charAt(0)) + property.substring(1); try { Method method = c.getClass().getMethod(s); color = (Color) method.invoke(c); } catch (Exception e) { //don't do anything, it just didn't work, that's all. //This could be a normal occurance if you use a property //name referring to a key in clientProperties instead of //a real property } if (color == null) { Object value = c.getClientProperty(property); if (value instanceof Color) { color = (Color) value; } } } } // we return the defaultColor if the color found is null, or if // it is a UIResource. This is done because the color for the // ENABLED state is set on the component, but you don't want to use // that color for the over state. So we only respect the color // specified for the property if it was set by the user, as opposed // to set by us. if (color == null || color instanceof UIResource) { return defaultColor; } else if (saturationOffset != 0 || brightnessOffset != 0 || alphaOffset != 0) { float[] tmp = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); tmp[1] = clamp(tmp[1] + saturationOffset); tmp[2] = clamp(tmp[2] + brightnessOffset); int alpha = clamp(color.getAlpha() + alphaOffset); return new Color((Color.HSBtoRGB(tmp[0], tmp[1], tmp[2]) & 0xFFFFFF) | (alpha <<24)); } else { return color; } } /** * A class encapsulating state useful when painting. Generally, instances of this * class are created once, and reused for each paint request without modification. * This class contains values useful when hinting the cache engine, and when decoding * control points and bezier curve anchors. */ protected static class PaintContext { protected static enum CacheMode { NO_CACHING, FIXED_SIZES, NINE_SQUARE_SCALE } private static Insets EMPTY_INSETS = new Insets(0, 0, 0, 0); private Insets stretchingInsets; private Dimension canvasSize; private boolean inverted; private CacheMode cacheMode; private double maxHorizontalScaleFactor; private double maxVerticalScaleFactor; private float a; // insets.left private float b; // canvasSize.width - insets.right private float c; // insets.top private float d; // canvasSize.height - insets.bottom; private float aPercent; // only used if inverted == true private float bPercent; // only used if inverted == true private float cPercent; // only used if inverted == true private float dPercent; // only used if inverted == true /** * Creates a new PaintContext which does not attempt to cache or scale any cached * images. *
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?