metacitybluecurve.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,134 行 · 第 1/3 页

JAVA
1,134
字号
    }    private void unfocus_background(Graphics g, int width, int height) {	/*	  <include name="outer_bevel"/>	  <include name="corners_unfocused"/>	*/	outer_bevel(g, width, height);	corners_unfocused(g, width, height);    }    private void focus_background(Graphics g, int width, int height) {	/*	  <include name="outer_bevel"/>	  <include name="corners_focused"/>	*/	outer_bevel(g, width, height);	corners_focused(g, width, height);    }    private void title_gradient(Graphics g, int width, int height, JInternalFrame frame) {	Image object;	int title_width = calculateTitleWidth(g, frame);	/*		<!-- Normally, there would be buttons placed over the outlines. This is to handle windows w/o buttons -->		<include name="left_corner_outline"/>		<include name="right_corner_outline"/>	*/	left_corner_outline(g, width, height);	right_corner_outline(g, width, height);	/*		<!-- base vertical gradient -->		<gradient type="vertical" x="0" y="0" width="width" height="height-1">			<color value="shade/gtk:bg[SELECTED]/1.4"/>			<color value="shade/gtk:bg[SELECTED]/1.0"/>			<color value="shade/gtk:bg[SELECTED]/0.8"/>		</gradient>	*/	drawVerticalGradient(g,			     shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 1.4F),			     shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 1.0F),			     shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 0.8F),			     0, 0, width, height-1);	/*		<!-- stripes -->		<image filename="white_stripes_tile.png" fill_type="tile" 			x="(LeftTitleTextPad+title_width-40) `max` 1" 			y="1+1" width="width-(LeftTitleTextPad+title_width-40)-2" height="height-4"			alpha="0.0:0.3:0.4:0.4"/>	*/	object = getImage("white_stripes_tile");	tileImage(g, object,		  Math.max(LeftTitleTextPad+title_width-40, 1), 1+1,		  width-(LeftTitleTextPad+title_width-40)-2, height-4,		  new float[] { 0.0F, 0.3F, 0.4F, 0.4F });	/*		<!-- top title shine -->		<gradient type="diagonal" x="0" y="0" width="width" height="2" alpha="0.2">			<color value="shade/gtk:bg[SELECTED]/2.0"/>			<color value="shade/gtk:bg[SELECTED]/1.7"/>		</gradient>		<gradient type="vertical" x="0" y="0" width="width" height="1" alpha="0.4">			<color value="shade/gtk:bg[SELECTED]/2.0"/>			<color value="shade/gtk:bg[SELECTED]/1.4"/>		</gradient>	*/	drawDiagonalGradient(g,			     shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 2.0F),			     shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 1.7F),			     0, 0, width, 2, 0.2F);	drawVerticalGradient(g,			     shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 2.0F),			     shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 1.4F),			     0, 0, width, 1, 0.4F);	/*		<!-- bottom title darken -->		<gradient type="diagonal" x="0" y="height-2" width="width" height="2" alpha="0.2">			<color value="shade/gtk:bg[SELECTED]/0.8"/>			<color value="shade/gtk:bg[SELECTED]/0.5"/>		</gradient>		<gradient type="vertical" x="0" y="height-2" width="width" height="1" alpha="0.9">			<color value="shade/gtk:bg[SELECTED]/1.0"/>			<color value="shade/gtk:bg[SELECTED]/0.7"/>		</gradient>	*/	drawDiagonalGradient(g,			     shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 0.8F),			     shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 0.5F),			     0, height-2, width, 2, 0.2F);	drawVerticalGradient(g,			     shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 1.0F),			     shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 0.7F),			     0, height-2, width, 1, 0.9F);	/*		<!-- bottom seperator line -->		<line color="shade/gtk:bg[SELECTED]/0.1" x1="0" y1="height-1" x2="width" y2="height-1"/>	*/	g.setColor(shadeColor(getColor(SELECTED, GTKColorType.BACKGROUND), 0.1F));	g.drawLine(0, height-1, width, height-1);    }    private void title_text_focused_no_icon(Graphics g, int width, int height, JInternalFrame frame) {	FontMetrics fm = g.getFontMetrics();	int title_height = fm.getAscent() + fm.getDescent();	/*		<clip x="0" y="0" width="width-8" height="height"/>		<title color="blend/gtk:fg[NORMAL]/gtk:bg[SELECTED]/0.7"			x="LeftTitleTextPad+1"			y="(((height - title_height) / 2) `max` 0)+1"/>		<title color="gtk:fg[SELECTED]"			x="LeftTitleTextPad"			y="((height - title_height) / 2) `max` 0"/>	*/	Rectangle clipRect = g.getClipBounds();	g.setClip(0, 0, width-8, height);	g.setColor(blendColor(getColor(ENABLED, GTKColorType.TEXT_FOREGROUND),			      getColor(SELECTED, GTKColorType.BACKGROUND), 0.7F));	paintTitle(g, LeftTitleTextPad+1, Math.max((height - title_height) / 2, 0)+1, frame);	g.setColor(getColor(SELECTED, ColorType.TEXT_FOREGROUND));	paintTitle(g, LeftTitleTextPad, Math.max((height - title_height) / 2, 0), frame);	g.setClip(clipRect);    }    private void title_text_no_icon(Graphics g, int width, int height, JInternalFrame frame) {	FontMetrics fm = g.getFontMetrics();	int title_height = fm.getAscent() + fm.getDescent();	/*		<clip x="0" y="0" width="width-8" height="height"/>		<title color="blend/gtk:fg[INSENSITIVE]/gtk:bg[INSENSITIVE]/0.0"			x="LeftTitleTextPad"			y="((height - title_height) / 2) `max` 0"/>	*/	Rectangle clipRect = g.getClipBounds();	g.setClip(0, 0, width-8, height);	g.setColor(blendColor(getColor(DISABLED, GTKColorType.TEXT_FOREGROUND),			      getColor(DISABLED, GTKColorType.BACKGROUND), 0.0F));	paintTitle(g, LeftTitleTextPad, Math.max((height - title_height) / 2, 0), frame);	g.setClip(clipRect);    }    private void title_normal(Graphics g, int width, int height, JInternalFrame frame) {	/*		<include name="titlebar_bg_unfocused"/>		<include name="title_text_no_icon"/>		<line color="blend/gtk:bg[INSENSITIVE]/gtk:fg[INSENSITIVE]/0.3" x1="0" y1="0" x2="0" y2="height-2"/>		<line color="blend/gtk:bg[INSENSITIVE]/gtk:fg[INSENSITIVE]/0.3" x1="width-1" y1="0" x2="width-1" y2="height-2"/>	*/	titlebar_bg_unfocused(g, width, height);	title_text_no_icon(g, width, height, frame);	g.setColor(blendColor(getColor(DISABLED, GTKColorType.BACKGROUND),			      getColor(DISABLED, GTKColorType.FOREGROUND), 0.3F));	g.drawLine(0,       0, 0,       height-2);	g.drawLine(width-1, 0, width-1, height-2);    }    private void title_focused(Graphics g, int width, int height, JInternalFrame frame) {	/*		<include name="title_gradient"/>		<include name="title_text_focused_no_icon"/>		<line color="blend/gtk:bg[SELECTED]/#000000/0.4" x1="0" y1="0" x2="0" y2="height"/>		<line color="blend/gtk:bg[SELECTED]/#000000/0.4" x1="width-1" y1="0" x2="width-1" y2="height"/>	*/	title_gradient(g, width, height, frame);	title_text_focused_no_icon(g, width, height, frame);	g.setColor(blendColor(getColor(SELECTED, GTKColorType.BACKGROUND),			      getColor(SELECTED, GTKColorType.FOREGROUND), 0.4F));	g.drawLine(0,       0, 0,       height);	g.drawLine(width-1, 0, width-1, height);    }    private void paintTitle(Graphics g, int x0, int y0, JInternalFrame frame) {	String title = frame.getTitle();        if (title != null) {	    if (frame.getComponentOrientation().isLeftToRight()) {		title = getTitle(title, g.getFontMetrics(), calculateTitleWidth(g, frame));	    }            g.drawString(title, x0, y0 + g.getFontMetrics().getAscent());        }    }    private int calculateTitleWidth(Graphics g, JInternalFrame frame) {	FrameGeometry gm = getFrameGeometry();	String title = frame.getTitle();	if (title != null) {	    JComponent titlePane = findChild(frame, "InternalFrame.northPane");	    JComponent button = null;	    if (frame.isIconifiable()) {		button = findChild(titlePane, "InternalFrameTitlePane.iconifyButton");	    } 	    if (button == null && frame.isMaximizable()) {		button = findChild(titlePane, "InternalFrameTitlePane.maximizeButton");	    } 	    if (button == null && frame.isClosable()) {		button = findChild(titlePane, "InternalFrameTitlePane.closeButton");	    }	    int buttonX = (button != null) ? button.getX() : (titlePane.getWidth() - gm.right_titlebar_edge);// 	    return Math.min(SwingUtilities.computeStringWidth(fm, title),// 			    buttonX - (left_width + ButtonWidth + IconTitleSpacing) - 3);	    return SwingUtilities.computeStringWidth(g.getFontMetrics(), title);	}	return 0;    }    private String getTitle(String text, FontMetrics fm, int availTextWidth) {        if ((text == null) || (text.equals(""))) {	    return "";	}        int textWidth = SwingUtilities.computeStringWidth(fm, text);        String clipString = "...";        if (textWidth > availTextWidth) {            int totalWidth = SwingUtilities.computeStringWidth(fm, clipString);            int nChars;            for (nChars = 0; nChars < text.length(); nChars++) {                totalWidth += fm.charWidth(text.charAt(nChars));                if (totalWidth > availTextWidth) {                    break;                }            }            text = text.substring(0, nChars) + clipString;        }        return text;    }    void paintFrameBorder(SynthContext context, Graphics g, int x0, int y0, int width, int height) {	this.context = context;	JInternalFrame frame = (JInternalFrame)context.getComponent();	JComponent titlePane = findChild(frame, "InternalFrame.northPane");	frame.setOpaque(false);	findChild(titlePane, "InternalFrameTitlePane.closeButton").setOpaque(false);	//boolean active = ((context.getComponentState() & SELECTED) != 0);	boolean active = frame.isSelected();	FrameGeometry gm = frame.isMaximum() ? normalMaximizedFrameGeometry					     : normalFrameGeometry;	setFrameGeometry(titlePane, gm);	Font oldFont = g.getFont();	g.setFont(titlePane.getFont());	g.translate(x0, y0);// 	Shape oldClip = g.getClip();// 	g.setClip(new RoundRectangle2D.Float(0F, 0F,// 					     (float)width, (float)height,// 					     12F, 12F));	// Paint border background because we are not opaque and have no rounded clip	g.setColor(frame.getBackground());	g.fillRect(0, gm.top_height,		   gm.left_width, height - gm.top_height - gm.bottom_height);	g.fillRect(width - gm.right_width - 1, gm.top_height,		   gm.right_width, height - gm.top_height - gm.bottom_height);	g.fillRect(gm.left_width, height - gm.bottom_height - 1,		   width - gm.left_width - gm.right_width, gm.bottom_height);	int titleX = 0;	int titleWidth = width;	JComponent menuButton = findChild(titlePane, "InternalFrameTitlePane.menuButton");	if (menuButton != null) {	    int x = menuButton.getX() + menuButton.getWidth() - x0;	    titleX += x;	    titleWidth -= x;	}	JComponent button = null;	if (frame.isIconifiable()) {	    button = findChild(titlePane, "InternalFrameTitlePane.iconifyButton");	} 	if (button == null && frame.isMaximizable()) {	    button = findChild(titlePane, "InternalFrameTitlePane.maximizeButton");	} 	if (button == null && frame.isClosable()) {	    button = findChild(titlePane, "InternalFrameTitlePane.closeButton");	}	if (button != null) {	    titleWidth = Math.min(width, button.getX() - x0);	}	if (!active) {	    /*		<frame focus="no" state="normal" resize="both" style="normal_unfocused"/>		    <piece position="entire_background" draw_ops="unfocus_background"/>		    <piece position="title" draw_ops="title_normal"/>	    */	    unfocus_background(g, width, height);	    g.translate(titleX, 1);	    title_normal(g, titleWidth, titlePane.getHeight()-1, frame);	    g.translate(-titleX, -1);	} else {	    /*		<frame focus="yes" state="normal" resize="both" style="normal_focused"/>		    <piece position="entire_background" draw_ops="focus_background"/>		    <piece position="title" draw_ops="title_focused"/>	    */	    focus_background(g, width, height);	    g.translate(titleX, 1);	    title_focused(g, titleWidth, titlePane.getHeight()-1, frame);	    g.translate(-titleX, -1);	}// 	g.setClip(oldClip);	g.translate(-x0, -y0);	g.setFont(oldFont);    }    Insets getBorderInsets(SynthContext context, Insets insets) {	FrameGeometry gm = getFrameGeometry();	if (insets == null) {	    insets = new Insets(0, 0, 0, 0);	}	insets.top    = gm.title_border.top;	insets.bottom = gm.bottom_height;	insets.left   = gm.left_width;	insets.right  = gm.right_width;	return insets;    }    private HashMap images = new HashMap();    private Image getImage(String key, Color c) {	Image image = (Image)images.get(key+"-"+c.getRGB());	if (image == null) {	    image = colorizeImage(getImage(key), c);	    if (image != null) {		images.put(key+"-"+c.getRGB(), image);	    }	}	return image;    }    private Image getImage(String key) {	Image image = (Image)images.get(key);	if (image == null) {	    if (themeDir != null) {		final String file = themeDir + File.separator + key + ".png";		image = (Image)AccessController.doPrivileged(new PrivilegedAction() {		    public Object run() {			return new ImageIcon(file).getImage();		    }		});	    } else {		String filename = "resources/metacity/"+key+".png";		URL url = getClass().getResource(filename);		if  (url != null) {		    image = new ImageIcon(url).getImage();		}	    }	    if (image != null) {		images.put(key, image);	    }	}	return image;    }    private void drawImage(Graphics g, Image im, Color colorize, float alpha, int x, int y) {	if (g instanceof Graphics2D) {	    Graphics2D g2 = (Graphics2D)g;	    Composite oldComp = g2.getComposite();	    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));	    g2.drawImage(im, x, y, null);	    g2.setComposite(oldComp);	}    }}

⌨️ 快捷键说明

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