metacity.java
来自「JAVA 所有包」· Java 代码 · 共 2,097 行 · 第 1/5 页
JAVA
2,097 行
} else if ("base".equals(typeStr)) { type = GTKColorType.TEXT_BACKGROUND; } else if ("text".equals(typeStr)) { type = GTKColorType.TEXT_FOREGROUND; } else if ("dark".equals(typeStr)) { type = GTKColorType.DARK; } else if ("light".equals(typeStr)) { type = GTKColorType.LIGHT; } if (state >= 0 && type != null) { c = ((GTKStyle)context.getStyle()).getGTKColor(context, state, type); } } } } if (c == null) { c = parseColorString(str); } return c; } private static Color parseColorString(String str) { if (str.charAt(0) == '#') { str = str.substring(1); int i = str.length(); if (i < 3 || i > 12 || (i % 3) != 0) { return null; } i /= 3; int r; int g; int b; try { r = Integer.parseInt(str.substring(0, i), 16); g = Integer.parseInt(str.substring(i, i * 2), 16); b = Integer.parseInt(str.substring(i * 2, i * 3), 16); } catch (NumberFormatException nfe) { return null; } if (i == 4) { return new ColorUIResource(r / 65535.0f, g / 65535.0f, b / 65535.0f); } else if (i == 1) { return new ColorUIResource(r / 15.0f, g / 15.0f, b / 15.0f); } else if (i == 2) { return new ColorUIResource(r, g, b); } else { return new ColorUIResource(r / 4095.0f, g / 4095.0f, b / 4095.0f); } } else { return XColors.lookupColor(str); } } class ArithmeticExpressionEvaluator { private PeekableStringTokenizer tokenizer; int evaluate(String expr) { tokenizer = new PeekableStringTokenizer(expr, " \t+-*/%()", true); return Math.round(expression()); } int evaluate(String expr, int fallback) { return (expr != null) ? evaluate(expr) : fallback; } public float expression() { float value = getTermValue(); boolean done = false; while (!done && tokenizer.hasMoreTokens()) { String next = tokenizer.peek(); if ("+".equals(next) || "-".equals(next) || "`max`".equals(next) || "`min`".equals(next)) { tokenizer.nextToken(); float value2 = getTermValue(); if ("+".equals(next)) { value += value2; } else if ("-".equals(next)) { value -= value2; } else if ("`max`".equals(next)) { value = Math.max(value, value2); } else if ("`min`".equals(next)) { value = Math.min(value, value2); } } else { done = true; } } return value; } public float getTermValue() { float value = getFactorValue(); boolean done = false; while (!done && tokenizer.hasMoreTokens()) { String next = tokenizer.peek(); if ("*".equals(next) || "/".equals(next) || "%".equals(next)) { tokenizer.nextToken(); float value2 = getFactorValue(); if ("*".equals(next)) { value *= value2; } else if ("/".equals(next)) { value /= value2; } else { value %= value2; } } else { done = true; } } return value; } public float getFactorValue() { float value; if ("(".equals(tokenizer.peek())) { tokenizer.nextToken(); value = expression(); tokenizer.nextToken(); // skip right paren } else { String token = tokenizer.nextToken(); if (Character.isDigit(token.charAt(0))) { value = Float.parseFloat(token); } else { Integer i = variables.get(token); if (i == null) { i = (Integer)getFrameGeometry().get(token); } if (i == null) { logError(themeName, "Variable \"" + token + "\" not defined"); return 0; } value = (i != null) ? i.intValue() : 0F; } } return value; } } static class PeekableStringTokenizer extends StringTokenizer { String token = null; public PeekableStringTokenizer(String str, String delim, boolean returnDelims) { super(str, delim, returnDelims); peek(); } public String peek() { if (token == null) { token = nextToken(); } return token; } public boolean hasMoreTokens() { return (token != null || super.hasMoreTokens()); } public String nextToken() { if (token != null) { String t = token; token = null; if (hasMoreTokens()) { peek(); } return t; } else { String token = super.nextToken(); while ((token.equals(" ") || token.equals("\t")) && hasMoreTokens()) { token = super.nextToken(); } return token; } } } static class RoundRectClipShape extends RectangularShape { static final int TOP_LEFT = 1; static final int TOP_RIGHT = 2; static final int BOTTOM_LEFT = 4; static final int BOTTOM_RIGHT = 8; int x; int y; int width; int height; int arcwidth; int archeight; int corners; public RoundRectClipShape() { } public RoundRectClipShape(int x, int y, int w, int h, int arcw, int arch, int corners) { setRoundedRect(x, y, w, h, arcw, arch, corners); } public void setRoundedRect(int x, int y, int w, int h, int arcw, int arch, int corners) { this.corners = corners; this.x = x; this.y = y; this.width = w; this.height = h; this.arcwidth = arcw; this.archeight = arch; } public double getX() { return (double)x; } public double getY() { return (double)y; } public double getWidth() { return (double)width; } public double getHeight() { return (double)height; } public double getArcWidth() { return (double)arcwidth; } public double getArcHeight() { return (double)archeight; } public boolean isEmpty() { return false; // Not called } public Rectangle2D getBounds2D() { return null; // Not called } public int getCornerFlags() { return corners; } public void setFrame(double x, double y, double w, double h) { // Not called } public boolean contains(double x, double y) { return false; // Not called } private int classify(double coord, double left, double right, double arcsize) { return 0; // Not called } public boolean intersects(double x, double y, double w, double h) { return false; // Not called } public boolean contains(double x, double y, double w, double h) { return false; // Not called } public PathIterator getPathIterator(AffineTransform at) { return new RoundishRectIterator(this, at); } static class RoundishRectIterator implements PathIterator { double x, y, w, h, aw, ah; AffineTransform affine; int index; double ctrlpts[][]; int types[]; private static final double angle = Math.PI / 4.0; private static final double a = 1.0 - Math.cos(angle); private static final double b = Math.tan(angle); private static final double c = Math.sqrt(1.0 + b * b) - 1 + a; private static final double cv = 4.0 / 3.0 * a * b / c; private static final double acv = (1.0 - cv) / 2.0; // For each array: // 4 values for each point {v0, v1, v2, v3}: // point = (x + v0 * w + v1 * arcWidth, // y + v2 * h + v3 * arcHeight); private static final double CtrlPtTemplate[][] = { { 0.0, 0.0, 1.0, 0.0 }, /* BOTTOM LEFT corner */ { 0.0, 0.0, 1.0, -0.5 }, /* BOTTOM LEFT arc start */ { 0.0, 0.0, 1.0, -acv, /* BOTTOM LEFT arc curve */ 0.0, acv, 1.0, 0.0, 0.0, 0.5, 1.0, 0.0 }, { 1.0, 0.0, 1.0, 0.0 }, /* BOTTOM RIGHT corner */ { 1.0, -0.5, 1.0, 0.0 }, /* BOTTOM RIGHT arc start */ { 1.0, -acv, 1.0, 0.0, /* BOTTOM RIGHT arc curve */ 1.0, 0.0, 1.0, -acv, 1.0, 0.0, 1.0, -0.5 }, { 1.0, 0.0, 0.0, 0.0 }, /* TOP RIGHT corner */ { 1.0, 0.0, 0.0, 0.5 }, /* TOP RIGHT arc start */ { 1.0, 0.0, 0.0, acv, /* TOP RIGHT arc curve */ 1.0, -acv, 0.0, 0.0, 1.0, -0.5, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0 }, /* TOP LEFT corner */ { 0.0, 0.5, 0.0, 0.0 }, /* TOP LEFT arc start */ { 0.0, acv, 0.0, 0.0, /* TOP LEFT arc curve */ 0.0, 0.0, 0.0, acv, 0.0, 0.0, 0.0, 0.5 }, {}, /* Closing path element */ }; private static final int CornerFlags[] = { RoundRectClipShape.BOTTOM_LEFT, RoundRectClipShape.BOTTOM_RIGHT, RoundRectClipShape.TOP_RIGHT, RoundRectClipShape.TOP_LEFT, }; RoundishRectIterator(RoundRectClipShape rr, AffineTransform at) { this.x = rr.getX(); this.y = rr.getY(); this.w = rr.getWidth(); this.h = rr.getHeight(); this.aw = Math.min(w, Math.abs(rr.getArcWidth())); this.ah = Math.min(h, Math.abs(rr.getArcHeight())); this.affine = at; if (w < 0 || h < 0) { // Don't draw anything... ctrlpts = new double[0][]; types = new int[0]; } else { int corners = rr.getCornerFlags(); int numedges = 5; // 4xCORNER_POINT, CLOSE for (int i = 1; i < 0x10; i <<= 1) { // Add one for each corner that has a curve if ((corners & i) != 0) numedges++; } ctrlpts = new double[numedges][]; types = new int[numedges]; int j = 0; for (int i = 0; i < 4; i++) { types[j] = SEG_LINETO; if ((corners & CornerFlags[i]) == 0) { ctrlpts[j++] = CtrlPtTemplate[i*3+0]; } else { ctrlpts[j++] = CtrlPtTemplate[i*3+1]; types[j] = SEG_CUBICTO; ctrlpts[j++] = CtrlPtTemplate[i*3+2]; } } types[j] = SEG_CLOSE; ctrlpts[j++] = CtrlPtTemplate[12]; types[0] = SEG_MOVETO; } } public int getWindingRule() { return WIND_NON_ZERO; } public boolean isDone() { return index >= ctrlpts.length; } public void next() { index++; } public int currentSegment(float[] coords) { if (isDone()) { throw new NoSuchElementException("roundrect iterator out of bounds"); } double ctrls[] = ctrlpts[index]; int nc = 0; for (int i = 0; i < ctrls.length; i += 4) { coords[nc++] = (float) (x + ctrls[i + 0] * w + ctrls[i + 1] * aw); coords[nc++] = (float) (y + ctrls[i + 2] * h + ctrls[i + 3] * ah); } if (affine != null) { affine.transform(coords, 0, coords, 0, nc / 2); } return types[index]; } public int currentSegment(double[] coords) { if (isDone()) { throw new NoSuchElementException("roundrect iterator out of bounds"); } double ctrls[] = ctrlpts[index]; int nc = 0; for (int i = 0; i < ctrls.length; i += 4) { coords[nc++] = x + ctrls[i + 0] * w + ctrls[i + 1] * aw; coords[nc++] = y + ctrls[i + 2] * h + ctrls[i + 3] * ah; } if (affine != null) { affine.transform(coords, 0, coords, 0, nc / 2); } return types[index]; } } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?