motifborders.java
来自「JAVA 所有包」· Java 代码 · 共 750 行 · 第 1/2 页
JAVA
750 行
getBorderInsets(c).right, height); if (!g.getClipBounds().intersects(borderRect)) { return false; } int startX = width - getBorderInsets(c).right; int startY = BORDER_SIZE; g.setColor(frameColor); g.fillRect(startX + 1, startY, 2, height - 1); g.setColor(frameShadow); g.fillRect(startX + 3, startY, 2, height - 1); g.setColor(frameHighlight); g.drawLine(startX, startY, startX, height - 1); return true; } /** Draws the FrameBorder's bottom border. */ protected boolean drawBottomBorder(Component c, Graphics g, int x, int y, int width, int height) { Rectangle borderRect; int marginHeight, startY; borderRect = new Rectangle(0, height - getBorderInsets(c).bottom, width, getBorderInsets(c).bottom); if (!g.getClipBounds().intersects(borderRect)) { return false; } startY = height - getBorderInsets(c).bottom; g.setColor(frameShadow); g.drawLine(x + 1, height - 1, width - 1, height - 1); g.drawLine(x + 2, height - 2, width - 2, height - 2); g.setColor(frameColor); g.fillRect(x + 2, startY + 1, width - 4, 2); g.setColor(frameHighlight); g.drawLine(x + 5, startY, width - 5, startY); return true; } // Returns true if the associated component has focus. protected boolean isActiveFrame() { return jcomp.hasFocus(); } /** Draws the FrameBorder in the given Rect. Calls * <b>drawTitleBar</b>, <b>drawLeftBorder</b>, <b>drawRightBorder</b> and * <b>drawBottomBorder</b>. */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { if (isActiveFrame()) { frameColor = UIManager.getColor("activeCaptionBorder"); } else { frameColor = UIManager.getColor("inactiveCaptionBorder"); } frameHighlight = frameColor.brighter(); frameShadow = frameColor.darker().darker(); drawTopBorder(c, g, x, y, width, height); drawLeftBorder(c, g, x, y, width, height); drawRightBorder(c, g, x, y, width, height); drawBottomBorder(c, g, x, y, width, height); } } public static class InternalFrameBorder extends FrameBorder { JInternalFrame frame; // The size of the bounding box for Motif frame corners. public final static int CORNER_SIZE = 24; /** Constructs an InternalFrameBorder for the InternalFrame * <b>aFrame</b>. */ public InternalFrameBorder(JInternalFrame aFrame) { super(aFrame); frame = aFrame; } /** Sets the InternalFrameBorder's InternalFrame. */ public void setFrame(JInternalFrame aFrame) { frame = aFrame; } /** Returns the InternalFrameBorder's InternalFrame. * @see #setFrame */ public JInternalFrame frame() { return frame; } /** Returns the width of the InternalFrameBorder's resize controls, * appearing along the InternalFrameBorder's bottom border. Clicking * and dragging within these controls lets the user change both the * InternalFrame's width and height, while dragging between the controls * constrains resizing to just the vertical dimension. Override this * method if you implement your own bottom border painting and use a * resize control with a different size. */ public int resizePartWidth() { if (!frame.isResizable()) { return 0; } return FrameBorder.BORDER_SIZE; } /** Draws the InternalFrameBorder's top border. */ protected boolean drawTopBorder(Component c, Graphics g, int x, int y, int width, int height) { if (super.drawTopBorder(c, g, x, y, width, height) && frame.isResizable()) { g.setColor(getFrameShadow()); g.drawLine(CORNER_SIZE - 1, y + 1, CORNER_SIZE - 1, y + 4); g.drawLine(width - CORNER_SIZE - 1, y + 1, width - CORNER_SIZE - 1, y + 4); g.setColor(getFrameHighlight()); g.drawLine(CORNER_SIZE, y, CORNER_SIZE, y + 4); g.drawLine(width - CORNER_SIZE, y, width - CORNER_SIZE, y + 4); return true; } return false; } /** Draws the InternalFrameBorder's left border. */ protected boolean drawLeftBorder(Component c, Graphics g, int x, int y, int width, int height) { if (super.drawLeftBorder(c, g, x, y, width, height) && frame.isResizable()) { g.setColor(getFrameHighlight()); int topY = y + CORNER_SIZE; g.drawLine(x, topY, x + 4, topY); int bottomY = height - CORNER_SIZE; g.drawLine(x + 1, bottomY, x + 5, bottomY); g.setColor(getFrameShadow()); g.drawLine(x + 1, topY - 1, x + 5, topY - 1); g.drawLine(x + 1, bottomY - 1, x + 5, bottomY - 1); return true; } return false; } /** Draws the InternalFrameBorder's right border. */ protected boolean drawRightBorder(Component c, Graphics g, int x, int y, int width, int height) { if (super.drawRightBorder(c, g, x, y, width, height) && frame.isResizable()) { int startX = width - getBorderInsets(c).right; g.setColor(getFrameHighlight()); int topY = y + CORNER_SIZE; g.drawLine(startX, topY, width - 2, topY); int bottomY = height - CORNER_SIZE; g.drawLine(startX + 1, bottomY, startX + 3, bottomY); g.setColor(getFrameShadow()); g.drawLine(startX + 1, topY - 1, width - 2, topY - 1); g.drawLine(startX + 1, bottomY - 1, startX + 3, bottomY - 1); return true; } return false; } /** Draws the InternalFrameBorder's bottom border. */ protected boolean drawBottomBorder(Component c, Graphics g, int x, int y, int width, int height) { if (super.drawBottomBorder(c, g, x, y, width, height) && frame.isResizable()) { int startY = height - getBorderInsets(c).bottom; g.setColor(getFrameShadow()); g.drawLine(CORNER_SIZE - 1, startY + 1, CORNER_SIZE - 1, height - 1); g.drawLine(width - CORNER_SIZE, startY + 1, width - CORNER_SIZE, height - 1); g.setColor(getFrameHighlight()); g.drawLine(CORNER_SIZE, startY, CORNER_SIZE, height - 2); g.drawLine(width - CORNER_SIZE + 1, startY, width - CORNER_SIZE + 1, height - 2); return true; } return false; } // Returns true if the associated internal frame has focus. protected boolean isActiveFrame() { return frame.isSelected(); } } public static void drawBezel(Graphics g, int x, int y, int w, int h, boolean isPressed, boolean hasFocus, Color shadow, Color highlight, Color darkShadow, Color focus) { Color oldColor = g.getColor(); g.translate(x, y); if (isPressed) { if (hasFocus){ g.setColor(focus); g.drawRect(0, 0, w-1, h-1); } g.setColor(shadow); // inner border g.drawRect(1, 1, w-3, h-3); g.setColor(highlight); // inner 3D border g.drawLine(2, h-3, w-3, h-3); g.drawLine(w-3, 2, w-3, h-4); } else { if (hasFocus) { g.setColor(focus); g.drawRect(0, 0, w-1, h-1); g.setColor(highlight); // inner 3D border g.drawLine(1, 1, 1, h-3); g.drawLine(2, 1, w-4, 1); g.setColor(shadow); g.drawLine(2, h-3, w-3, h-3); g.drawLine(w-3, 1, w-3, h-4); g.setColor(darkShadow); // black drop shadow __| g.drawLine(1, h-2, w-2, h-2); g.drawLine(w-2, h-2, w-2, 1); } else { g.setColor(highlight); // inner 3D border g.drawLine(1,1,1,h-3); g.drawLine(2,1,w-4,1); g.setColor(shadow); g.drawLine(2,h-3,w-3,h-3); g.drawLine(w-3,1,w-3,h-4); g.setColor(darkShadow); // black drop shadow __| g.drawLine(1,h-2,w-2,h-2); g.drawLine(w-2,h-2,w-2,0); } g.translate(-x, -y); } g.setColor(oldColor); } public static class MotifPopupMenuBorder extends AbstractBorder implements UIResource { protected Font font; protected Color background; protected Color foreground; protected Color shadowColor; protected Color highlightColor; // Space between the border and text static protected final int TEXT_SPACING = 2; // Space for the separator under the title static protected final int GROOVE_HEIGHT = 2; /** * Creates a MotifPopupMenuBorder instance * */ public MotifPopupMenuBorder( Font titleFont, Color bgColor, Color fgColor, Color shadow, Color highlight) { this.font = titleFont; this.background = bgColor; this.foreground = fgColor; this.shadowColor = shadow; this.highlightColor = highlight; } /** * Paints the border for the specified component with the * specified position and size. * @param c the component for which this border is being painted * @param g the paint graphics * @param x the x position of the painted border * @param y the y position of the painted border * @param width the width of the painted border * @param height the height of the painted border */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Font origFont = g.getFont(); Color origColor = g.getColor(); JPopupMenu popup = (JPopupMenu)c; String title = popup.getLabel(); if (title == null) { return; } g.setFont(font); FontMetrics fm = SwingUtilities2.getFontMetrics(popup, g, font); int fontHeight = fm.getHeight(); int descent = fm.getDescent(); int ascent = fm.getAscent(); Point textLoc = new Point(); int stringWidth = SwingUtilities2.stringWidth(popup, fm, title); textLoc.y = y + ascent + TEXT_SPACING; textLoc.x = x + ((width - stringWidth) / 2); g.setColor(background); g.fillRect(textLoc.x - TEXT_SPACING, textLoc.y - (fontHeight-descent), stringWidth + (2 * TEXT_SPACING), fontHeight - descent); g.setColor(foreground); SwingUtilities2.drawString(popup, g, title, textLoc.x, textLoc.y); MotifGraphicsUtils.drawGroove(g, x, textLoc.y + TEXT_SPACING, width, GROOVE_HEIGHT, shadowColor, highlightColor); g.setFont(origFont); g.setColor(origColor); } /** * Returns the insets of the border. * @param c the component for which this border insets value applies */ public Insets getBorderInsets(Component c) { return getBorderInsets(c, new Insets(0, 0, 0, 0)); } /** * Reinitialize the insets parameter with this Border's current Insets. * @param c the component for which this border insets value applies * @param insets the object to be reinitialized */ public Insets getBorderInsets(Component c, Insets insets) { FontMetrics fm; int descent = 0; int ascent = 16; String title = ((JPopupMenu)c).getLabel(); if (title == null) { insets.left = insets.top = insets.right = insets.bottom = 0; return insets; } fm = c.getFontMetrics(font); if(fm != null) { descent = fm.getDescent(); ascent = fm.getAscent(); } insets.top += ascent + descent + TEXT_SPACING + GROOVE_HEIGHT; return insets; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?