metacitycrux.java

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

JAVA
852
字号
            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");	//boolean active = ((context.getComponentState() & SynthConstants.SELECTED) != 0);	boolean active = frame.isSelected();	setFrameGeometry(titlePane, normalFrameGeometry);	Image leftBorder        = getImage("left-border", active);	Image rightBorder       = getImage("right-border", active);	Image bottomLeftCorner  = getImage("bottom-left-corner", active);	Image bottomLeftBorder  = getImage("bottom-left-border", active);	Image bottomRightBorder = getImage("bottom-right-border", active);	Image bottomRightCorner = getImage("bottom-right-corner", active);	Image bottomMidBorder = getImage("bottom-mid-border", active);	Image bottomMidLeftBorder  = getImage("bottom-mid-left-border", active);	Image bottomMidRightBorder = getImage("bottom-mid-right-border", active);	Font oldFont = g.getFont();	g.setFont(titlePane.getFont());	g.translate(x0, y0);	paintTitleBar(g, width, titlePane.getHeight(), active, frame, titlePane);	FontMetrics fm = g.getFontMetrics();	int title_width = calculateTitleWidth(frame, titlePane, fm);	int title_height = (titlePane != null) ? titlePane.getPreferredSize().height : 16;	int x, y, w, h;	Image object;	if (leftBorder == null) {	    // Ouch, we don't have any images. Let's just paint a border for now.	    g.setColor(active ? Color.black : Color.gray);	    g.drawRect(0, 0, width-1, height-1);	} else if (!active) {	    /*	      <image filename="inactive-left-border.png" x="0" y="0" width="object_width" height="height"/>	    */	    object = leftBorder; x = 0; y = 0; w = object.getWidth(null); h = height;	    // Adjust for our positioning system	    y = title_height;	    h = height - title_height - bottomLeftCorner.getHeight(null);	    g.drawImage(object, x, y, w, h, null);	    /*	      <image filename="inactive-right-border.png" x="0" y="0" width="object_width" height="height"/>	    */	    object = rightBorder; x = 0; y = 0; w = object.getWidth(null); h = height;	    // Adjust for our positioning system	    x = width - rightBorder.getWidth(null);	    y = title_height;	    h = height - title_height - bottomRightCorner.getHeight(null);	    g.drawImage(object, x, y, w, h, null);	    /*	      <image filename="inactive-bottom-left-corner.png" 	         x="0" y="height - object_height" width="object_width" height="object_height"/>	    */	    object = bottomLeftCorner;	    x = 0; y = height - object.getHeight(null);	    w = object.getWidth(null); h = object.getHeight(null);	    g.drawImage(object, x, y, w, h, null);	    /*	      <image filename="inactive-bottom-left-border.png" x="5" y="height - object_height" 	         width="((title_width + height / 2 - 4) `min` (width - object_width - 26))"	         height="object_height"/>	    */	    object = bottomLeftBorder; x = 5; y = height - object.getHeight(null);	    w = Math.min((title_width + height / 2 - 4), (width - object.getWidth(null) - 26));	    h = object.getHeight(null);	    g.drawImage(object, x, y, w, h, null);	    /*	      <image filename="inactive-bottom-mid-border.png" 	         x="((title_width + height / 2) `min` (width - object_width - 6)) + 1" 	         y="height - object_height" width="object_width" height="object_height"/>	    */	    object = bottomMidBorder;	    if (bottomMidBorder == null) {		object = bottomMidLeftBorder;	    }	    x = Math.min((title_width + height / 2), (width - object.getWidth(null) - 6)) + 1;	    y = height - object.getHeight(null);	    w = object.getWidth(null); h = object.getHeight(null);	    g.drawImage(object, x, y, w, h, null);	    if (bottomMidBorder == null) {		object = bottomMidRightBorder;		g.drawImage(object, x, y, w, h, null);	    }	    /*	      <image filename="inactive-bottom-right-border.png"	         x="((title_width + height / 2 + 32)) + 1" 	         y="height - object_height" 	         width="(width - title_width - height / 2 - 32 - 7) `max` 0"	         height="object_height"/>	    */	    object = bottomRightBorder;	    x = (title_width + height / 2 + 32) + 1;	    y = height - object.getHeight(null); 	    w = Math.max((width - title_width - height / 2 - 32 - 7), 0);	    h = object.getHeight(null);	    g.drawImage(object, x, y, w, h, null);	    /*	      <image filename="inactive-bottom-right-corner.png" 	         x="width - object_width" y="height - object_height"	         width="object_height" height="object_height"/>	    */	    object = bottomRightCorner;	    x = width - object.getWidth(null); y = height - object.getHeight(null);	    w = object.getWidth(null); h = object.getHeight(null);	    g.drawImage(object, x, y, w, h, null);	} else {	    /*	      <image colorize="gtk:bg[SELECTED]" filename="active-left-border.png"	         x="0" y="0" width="object_width" height="height"/>	    */	    object = getImage("active-left-border", getColor(SELECTED, GTKColorType.BACKGROUND));	    x = 0; y = 0; w = object.getWidth(null); h = height;	    // Adjust for our positioning system	    y = title_height;	    h = height - title_height - bottomLeftCorner.getHeight(null);	    g.drawImage(object, x, y, w, h, null);	    /*	      <image filename="active-right-border.png"	         x="0" y="0" width="object_width" height="height"/>	    */	    object = rightBorder; x = 0; y = 0; w = object.getWidth(null); h = height;	    // Adjust for our positioning system	    x = width - rightBorder.getWidth(null);	    y = title_height;	    h = height - title_height - bottomRightCorner.getHeight(null);	    g.drawImage(object, x, y, w, h, null);	    /*	      <image filename="active-bottom-left-corner.png" 	         colorize="gtk:bg[SELECTED]"	         x="0" y="height - object_height" width="object_width" height="object_height"/>	    */	    object = getImage("active-bottom-left-corner", getColor(SELECTED, GTKColorType.BACKGROUND));	    x = 0; y = height - object.getHeight(null);	    w = object.getWidth(null); h = object.getHeight(null);	    g.drawImage(object, x, y, w, h, null);	    /*	      <image filename="active-bottom-left-border.png" x="5" y="height - object_height" 	         colorize="gtk:bg[SELECTED]"	         width="((title_width + height / 2 - 4) `min` (width - object_width - 26))"	         height="object_height"/>	    */	    object = getImage("active-bottom-left-border", getColor(SELECTED, GTKColorType.BACKGROUND));	    x = 5; y = height - object.getHeight(null);	    w = Math.min((title_width + height / 2 - 4), (width - object.getWidth(null) - 26));	    h = object.getHeight(null);	    g.drawImage(object, x, y, w, h, null);	    /*	      <image filename="active-bottom-mid-left-border.png" 	         colorize="gtk:bg[SELECTED]"	         x="((title_width + height / 2) `min` (width - object_width - 6)) + 1" 	         y="height - object_height" width="object_width" height="object_height"/>	    */	    object = getImage("active-bottom-mid-left-border", getColor(SELECTED, GTKColorType.BACKGROUND));	    x = Math.min((title_width + height / 2), (width - object.getWidth(null) - 6)) + 1;	    y = height - object.getHeight(null); w = object.getWidth(null); h = object.getHeight(null);	    g.drawImage(object, x, y, w, h, null);	    /*	      <image filename="active-bottom-mid-right-border.png" 	         x="((title_width + height / 2) `min` (width - object_width - 6)) + 1" 	         y="height - object_height" width="object_width" height="object_height"/>	    */	    object = bottomMidRightBorder;	    x = Math.min((title_width + height / 2), (width - object.getWidth(null) - 6)) + 1;	    y = height - object.getHeight(null); w = object.getWidth(null); h = object.getHeight(null);	    g.drawImage(object, x, y, w, h, null);	    /*	      <image filename="active-bottom-right-border.png"	         x="((title_width + height / 2 + 32)) + 1" 	         y="height - object_height" 	         width="(width - title_width - height / 2 - 32 - 7) `max` 0"	         height="object_height"/>	    */	    object = bottomRightBorder;	    x = (title_width + height / 2 + 32) + 1;	    y = height - object.getHeight(null); 	    w = Math.max((width - title_width - height / 2 - 32 - 7), 0);	    h = object.getHeight(null);	    g.drawImage(object, x, y, w, h, null);	    /*	      <image filename="active-bottom-right-corner.png" 	         x="width - object_width" y="height - object_height"	         width="object_height" height="object_height"/>	    */	    object = bottomRightCorner;	    x = width - object.getWidth(null); y = height - object.getHeight(null);	    w = object.getWidth(null); h = object.getHeight(null);	    g.drawImage(object, x, y, w, h, null);	}	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 && key.startsWith("inactive")) {		image = getImage(key.substring(2));	    }	    if (image != null) {		images.put(key, image);	    }	}	return image;    }    private Image getImage(String key, boolean active) {	return getImage((active ? "active" : "inactive") + "-" + key);    }}

⌨️ 快捷键说明

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