metacity.java

来自「JAVA 所有包」· Java 代码 · 共 2,097 行 · 第 1/5 页

JAVA
2,097
字号
	int x2 = aee.evaluate(getStringAttr(attrs, "x2"));	int y2 = aee.evaluate(getStringAttr(attrs, "y2"));	int lineWidth = aee.evaluate(getStringAttr(attrs, "width"), 1);	g.setColor(color);	if (lineWidth != 1) {	    Graphics2D g2d = (Graphics2D)g;	    Stroke stroke = g2d.getStroke();	    g2d.setStroke(new BasicStroke((float)lineWidth));	    g2d.drawLine(x1, y1, x2, y2);	    g2d.setStroke(stroke);	} else {	    g.drawLine(x1, y1, x2, y2);	}    }    protected void drawRectangle(Node node, Graphics g) {	NamedNodeMap attrs = node.getAttributes();	Color color = parseColor(getStringAttr(attrs, "color"));	boolean filled = getBooleanAttr(node, "filled", false);	int x = aee.evaluate(getStringAttr(attrs, "x"));	int y = aee.evaluate(getStringAttr(attrs, "y"));	int w = aee.evaluate(getStringAttr(attrs, "width"));	int h = aee.evaluate(getStringAttr(attrs, "height"));	g.setColor(color);	if (getInt("width") == -1) {	    x -= w;	}	if (getInt("height") == -1) {	    y -= h;	}	if (filled) {	    g.fillRect(x, y, w, h);	} else {	    g.drawRect(x, y, w, h);	}    }    protected void drawTile(Node node, Graphics g, JInternalFrame jif) {	NamedNodeMap attrs = node.getAttributes();	int x0 = aee.evaluate(getStringAttr(attrs, "x"));	int y0 = aee.evaluate(getStringAttr(attrs, "y"));	int w = aee.evaluate(getStringAttr(attrs, "width"));	int h = aee.evaluate(getStringAttr(attrs, "height"));	int tw = aee.evaluate(getStringAttr(attrs, "tile_width"));	int th = aee.evaluate(getStringAttr(attrs, "tile_height"));	int width  = getInt("width");	int height = getInt("height");	if (width == -1) {	    x0 -= w;	}	if (height == -1) {	    y0 -= h;	}	Shape oldClip = g.getClip();	if (g instanceof Graphics2D) {	    ((Graphics2D)g).clip(new Rectangle(x0, y0, w, h));	}	variables.put("width",  tw);	variables.put("height", th);	Node draw_ops = getNode("draw_ops", new String[] { "name", getStringAttr(node, "name") });		int y = y0;	while (y < y0 + h) {	    int x = x0;	    while (x < x0 + w) {		g.translate(x, y);		draw(draw_ops, g, jif);		g.translate(-x, -y);		x += tw;	    }	    y += th;	}	variables.put("width",  width);	variables.put("height", height);	g.setClip(oldClip);    }    protected void drawTint(Node node, Graphics g) {	NamedNodeMap attrs = node.getAttributes();	Color color = parseColor(getStringAttr(attrs, "color"));	float alpha = Float.parseFloat(getStringAttr(attrs, "alpha"));	int x = aee.evaluate(getStringAttr(attrs, "x"));	int y = aee.evaluate(getStringAttr(attrs, "y"));	int w = aee.evaluate(getStringAttr(attrs, "width"));	int h = aee.evaluate(getStringAttr(attrs, "height"));	if (getInt("width") == -1) {	    x -= w;	}	if (getInt("height") == -1) {	    y -= h;	}	if (g instanceof Graphics2D) {	    Graphics2D g2 = (Graphics2D)g;	    Composite oldComp = g2.getComposite();	    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);	    g2.setComposite(ac);	    g2.setColor(color);	    g2.fillRect(x, y, w, h);	    g2.setComposite(oldComp);	}    }    protected void drawTitle(Node node, Graphics g, JInternalFrame jif) {	NamedNodeMap attrs = node.getAttributes();	String colorStr = getStringAttr(attrs, "color");	int i = colorStr.indexOf("gtk:fg[");	if (i > 0) {	    colorStr = colorStr.substring(0, i) + "gtk:text[" + colorStr.substring(i+7);	}	Color color = parseColor(colorStr);	int x = aee.evaluate(getStringAttr(attrs, "x"));	int y = aee.evaluate(getStringAttr(attrs, "y"));	String title = jif.getTitle();        if (title != null) {            FontMetrics fm = SwingUtilities2.getFontMetrics(jif, g);	    if (jif.getComponentOrientation().isLeftToRight()) {		title = SwingUtilities2.clipStringIfNecessary(jif, fm, title,                             calculateTitleTextWidth(g, jif));	    }	    g.setColor(color);            SwingUtilities2.drawString(jif, g, title, x, y + fm.getAscent());        }    }    protected Dimension calculateButtonSize(JComponent titlePane) {	int buttonHeight = getInt("button_height");	if (buttonHeight == 0) {	    buttonHeight = titlePane.getHeight();	    if (buttonHeight == 0) {		buttonHeight = 13;	    } else {		Insets button_border = (Insets)frameGeometry.get("button_border");		if (button_border != null) {		    buttonHeight -= (button_border.top + button_border.bottom);		}	    }	}	int buttonWidth = getInt("button_width");	if (buttonWidth == 0) {	    buttonWidth = buttonHeight;	    Float aspect_ratio = (Float)frameGeometry.get("aspect_ratio");	    if (aspect_ratio != null) {		buttonWidth = (int)(buttonHeight / aspect_ratio.floatValue());	    }	}	return new Dimension(buttonWidth, buttonHeight);    }    protected Rectangle calculateTitleArea(JInternalFrame jif) {	JComponent titlePane = findChild(jif, "InternalFrame.northPane");	Dimension buttonDim = calculateButtonSize(titlePane);	Insets title_border = (Insets)frameGeometry.get("title_border");	Rectangle r = new Rectangle();	r.x = getInt("left_titlebar_edge") + buttonDim.width;	r.y = 0;	r.height = titlePane.getHeight();	if (title_border != null) {	    r.x += title_border.left;	    r.y += title_border.top;	    r.height -= (title_border.top + title_border.bottom);	}	r.width = titlePane.getWidth() - r.x - getInt("right_titlebar_edge");	if (jif.isClosable()) {	    r.width -= buttonDim.width;	}	if (jif.isMaximizable()) {	    r.width -= buttonDim.width;	}	if (jif.isIconifiable()) {	    r.width -= buttonDim.width;	}	if (title_border != null) {	    r.width -= title_border.right;	}	return r;    }    protected int calculateTitleTextWidth(Graphics g, JInternalFrame jif) {	String title = jif.getTitle();	if (title != null) {	    Rectangle r = calculateTitleArea(jif);	    return Math.min(SwingUtilities2.stringWidth(jif,                     SwingUtilities2.getFontMetrics(jif, g), title), r.width);	}	return 0;    }    protected void setClip(Node node, Graphics g) {	NamedNodeMap attrs = node.getAttributes();	int x = aee.evaluate(getStringAttr(attrs, "x"));	int y = aee.evaluate(getStringAttr(attrs, "y"));	int w = aee.evaluate(getStringAttr(attrs, "width"));	int h = aee.evaluate(getStringAttr(attrs, "height"));	if (getInt("width") == -1) {	    x -= w;	}	if (getInt("height") == -1) {	    y -= h;	}	if (g instanceof Graphics2D) {	    ((Graphics2D)g).clip(new Rectangle(x, y, w, h));	}    }    protected void drawGTKArrow(Node node, Graphics g) {	NamedNodeMap attrs = node.getAttributes();	String arrow    = getStringAttr(attrs, "arrow");	String shadow   = getStringAttr(attrs, "shadow");	String stateStr = getStringAttr(attrs, "state").toUpperCase();	int x = aee.evaluate(getStringAttr(attrs, "x"));	int y = aee.evaluate(getStringAttr(attrs, "y"));	int w = aee.evaluate(getStringAttr(attrs, "width"));	int h = aee.evaluate(getStringAttr(attrs, "height"));	int state = -1;	if ("NORMAL".equals(stateStr)) {	    state = ENABLED;	} else if ("SELECTED".equals(stateStr)) {	    state = SELECTED;	} else if ("INSENSITIVE".equals(stateStr)) {	    state = DISABLED;	} else if ("PRELIGHT".equals(stateStr)) {	    state = MOUSE_OVER;	}	ShadowType shadowType = null;	if ("in".equals(shadow)) {	    shadowType = ShadowType.IN;	} else if ("out".equals(shadow)) {	    shadowType = ShadowType.OUT;	} else if ("etched_in".equals(shadow)) {	    shadowType = ShadowType.ETCHED_IN;	} else if ("etched_out".equals(shadow)) {	    shadowType = ShadowType.ETCHED_OUT;	} else if ("none".equals(shadow)) {	    shadowType = ShadowType.NONE;	}	ArrowType direction = null;	if ("up".equals(arrow)) {	    direction = ArrowType.UP;	} else if ("down".equals(arrow)) {	    direction = ArrowType.DOWN;	} else if ("left".equals(arrow)) {	    direction = ArrowType.LEFT;	} else if ("right".equals(arrow)) {	    direction = ArrowType.RIGHT;	}        GTKPainter.INSTANCE.paintMetacityElement(context, g, state,                "metacity-arrow", x, y, w, h, shadowType, direction);    }    protected void drawGTKBox(Node node, Graphics g) {	NamedNodeMap attrs = node.getAttributes();	String shadow   = getStringAttr(attrs, "shadow");	String stateStr = getStringAttr(attrs, "state").toUpperCase();	int x = aee.evaluate(getStringAttr(attrs, "x"));	int y = aee.evaluate(getStringAttr(attrs, "y"));	int w = aee.evaluate(getStringAttr(attrs, "width"));	int h = aee.evaluate(getStringAttr(attrs, "height"));	int state = -1;	if ("NORMAL".equals(stateStr)) {	    state = ENABLED;	} else if ("SELECTED".equals(stateStr)) {	    state = SELECTED;	} else if ("INSENSITIVE".equals(stateStr)) {	    state = DISABLED;	} else if ("PRELIGHT".equals(stateStr)) {	    state = MOUSE_OVER;	}	ShadowType shadowType = null;	if ("in".equals(shadow)) {	    shadowType = ShadowType.IN;	} else if ("out".equals(shadow)) {	    shadowType = ShadowType.OUT;	} else if ("etched_in".equals(shadow)) {	    shadowType = ShadowType.ETCHED_IN;	} else if ("etched_out".equals(shadow)) {	    shadowType = ShadowType.ETCHED_OUT;	} else if ("none".equals(shadow)) {	    shadowType = ShadowType.NONE;	}        GTKPainter.INSTANCE.paintMetacityElement(context, g, state,                "metacity-box", x, y, w, h, shadowType, null);    }    protected void drawGTKVLine(Node node, Graphics g) {	NamedNodeMap attrs = node.getAttributes();	String stateStr = getStringAttr(attrs, "state").toUpperCase();	int x  = aee.evaluate(getStringAttr(attrs, "x"));	int y1 = aee.evaluate(getStringAttr(attrs, "y1"));	int y2 = aee.evaluate(getStringAttr(attrs, "y2"));	int state = -1;	if ("NORMAL".equals(stateStr)) {	    state = ENABLED;	} else if ("SELECTED".equals(stateStr)) {	    state = SELECTED;	} else if ("INSENSITIVE".equals(stateStr)) {	    state = DISABLED;	} else if ("PRELIGHT".equals(stateStr)) {	    state = MOUSE_OVER;	}        GTKPainter.INSTANCE.paintMetacityElement(context, g, state,                "metacity-vline", x, y1, 1, y2 - y1, null, null);    }    protected void drawGradient(Node node, Graphics g) {	NamedNodeMap attrs = node.getAttributes();	String type = getStringAttr(attrs, "type");	float alpha = getFloatAttr(node, "alpha", -1F);	int x = aee.evaluate(getStringAttr(attrs, "x"));	int y = aee.evaluate(getStringAttr(attrs, "y"));	int w = aee.evaluate(getStringAttr(attrs, "width"));	int h = aee.evaluate(getStringAttr(attrs, "height"));	if (getInt("width") == -1) {	    x -= w;	}	if (getInt("height") == -1) {	    y -= h;	}	// Get colors from child nodes	Node[] colorNodes = getNodesByName(node, "color");	Color[] colors = new Color[colorNodes.length];	for (int i = 0; i < colorNodes.length; i++) {	    colors[i] = parseColor(getStringAttr(colorNodes[i], "value"));	}	boolean horizontal = ("diagonal".equals(type) || "horizontal".equals(type));	boolean vertical   = ("diagonal".equals(type) || "vertical".equals(type));	if (g instanceof Graphics2D) {	    Graphics2D g2 = (Graphics2D)g;	    Composite oldComp = g2.getComposite();	    if (alpha >= 0F) {		g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));	    }	    int n = colors.length - 1;	    for (int i = 0; i < n; i++) {		g2.setPaint(new GradientPaint(x + (horizontal ? (i*w/n) : 0),					      y + (vertical   ? (i*h/n) : 0),					      colors[i],					      x + (horizontal ? ((i+1)*w/n) : 0),					      y + (vertical   ? ((i+1)*h/n) : 0),					      colors[i+1]));		g2.fillRect(x + (horizontal ? (i*w/n) : 0),			    y + (vertical   ? (i*h/n) : 0),			    (horizontal ? (w/n) : w),			    (vertical   ? (h/n) : h));	    }	    g2.setComposite(oldComp);	}    }    protected void drawImage(Node node, Graphics g) {	NamedNodeMap attrs = node.getAttributes();	String filename = getStringAttr(attrs, "filename");	String colorizeStr = getStringAttr(attrs, "colorize");	Color colorize = (colorizeStr != null) ? parseColor(colorizeStr) : null;	String alpha = getStringAttr(attrs, "alpha");	Image object = (colorize != null) ? getImage(filename, colorize) : getImage(filename);	variables.put("object_width",  object.getWidth(null));	variables.put("object_height", object.getHeight(null));	String fill_type = getStringAttr(attrs, "fill_type"); 	int x = aee.evaluate(getStringAttr(attrs, "x"));	int y = aee.evaluate(getStringAttr(attrs, "y"));	int w = aee.evaluate(getStringAttr(attrs, "width"));	int h = aee.evaluate(getStringAttr(attrs, "height"));	if (getInt("width") == -1) {	    x -= w;	}	if (getInt("height") == -1) {	    y -= h;	}	if (alpha != null) {	    if ("tile".equals(fill_type)) {		StringTokenizer tokenizer = new StringTokenizer(alpha, ":");		float[] alphas = new float[tokenizer.countTokens()];		for (int i = 0; i < alphas.length; i++) {		    alphas[i] = Float.parseFloat(tokenizer.nextToken());		}		tileImage(g, object, x, y, w, h, alphas);	    } else {		float a = Float.parseFloat(alpha);		if (g instanceof Graphics2D) {		    Graphics2D g2 = (Graphics2D)g;		    Composite oldComp = g2.getComposite();		    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, a));		    g2.drawImage(object, x, y, w, h, null);		    g2.setComposite(oldComp);		}	    }	} else {	    g.drawImage(object, x, y, w, h, null);	}    }    protected void drawIcon(Node node, Graphics g, JInternalFrame jif) {	Icon icon = jif.getFrameIcon();	if (icon == null) {	    return;	}	NamedNodeMap attrs = node.getAttributes();	String alpha = getStringAttr(attrs, "alpha");	int x = aee.evaluate(getStringAttr(attrs, "x"));	int y = aee.evaluate(getStringAttr(attrs, "y"));

⌨️ 快捷键说明

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