📄 smoothgradientborders.java
字号:
"OptionPane.questionDialog.border.background"); break; case(JOptionPane.WARNING_MESSAGE): borderColor = UIManager.getColor( "OptionPane.warningDialog.border.background"); break; case(JOptionPane.INFORMATION_MESSAGE): case(JOptionPane.PLAIN_MESSAGE): default: borderColor = MetalLookAndFeel.getPrimaryControlDarkShadow(); break; } g.setColor(borderColor); // Draw outermost lines g.drawLine( 1, 0, w-2, 0); g.drawLine( 0, 1, 0, h-2); g.drawLine( w-1, 1, w-1, h-2); g.drawLine( 1, h-1, w-2, h-1); // Draw the bulk of the border for (int i = 1; i < 3; i++) { g.drawRect(i, i, w-(i*2)-1, h-(i*2)-1); } g.translate(-x,-y); } public Insets getBorderInsets(Component c) { return insets; } public Insets getBorderInsets(Component c, Insets newInsets) { newInsets.top = insets.top; newInsets.left = insets.left; newInsets.bottom = insets.bottom; newInsets.right = insets.right; return newInsets; } } private static Border dialogBorder; static Border getDialogBorder() { if (dialogBorder == null) { dialogBorder = new DialogBorder(); } return dialogBorder; } private static class DialogBorder extends AbstractBorder implements UIResource { private static final Insets insets = new Insets(2, 2, 2, 2); private static final int corner = 14; protected Color getActiveBackground() { return SmoothGradientLookAndFeel.getPrimaryControlDarkShadow(); } protected Color getActiveHighlight() { return SmoothGradientLookAndFeel.getPrimaryControlShadow(); } protected Color getActiveShadow() { return SmoothGradientLookAndFeel.getPrimaryControlInfo(); } protected Color getInactiveBackground() { return SmoothGradientLookAndFeel.getControlDarkShadow(); } protected Color getInactiveHighlight() { return SmoothGradientLookAndFeel.getControlShadow(); } protected Color getInactiveShadow() { return SmoothGradientLookAndFeel.getControlInfo(); } public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { Color background; Color highlight; Color shadow; Window window = SwingUtilities.getWindowAncestor(c); if (window != null && window.isActive()) { background = getActiveBackground(); highlight = getActiveHighlight(); shadow = getActiveShadow(); } else { background = getInactiveBackground(); highlight = getInactiveHighlight(); shadow = getInactiveShadow(); } g.setColor(background); // Draw outermost lines g.drawLine( x + 1, y + 0, x + w-2, y + 0); g.drawLine( x + 0, y + 1, x + 0, y + h - 2); g.drawLine( x + w - 1, y + 1, x + w - 1, y + h - 2); g.drawLine( x + 1, y + h - 1, x + w - 2, y + h - 1); // Draw the bulk of the border for (int i = 1; i < 5; i++) { g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1); } if ((window instanceof Dialog) && ((Dialog) window).isResizable()) { g.setColor(highlight); // Draw the Long highlight lines g.drawLine( corner+1, 3, w-corner, 3); g.drawLine( 3, corner+1, 3, h-corner); g.drawLine( w-2, corner+1, w-2, h-corner); g.drawLine( corner+1, h-2, w-corner, h-2); g.setColor(shadow); // Draw the Long shadow lines g.drawLine( corner, 2, w-corner-1, 2); g.drawLine( 2, corner, 2, h-corner-1); g.drawLine( w-3, corner, w-3, h-corner-1); g.drawLine( corner, h-3, w-corner-1, h-3); } } public Insets getBorderInsets(Component c) { return insets; } public Insets getBorderInsets(Component c, Insets newInsets) { newInsets.top = insets.top; newInsets.left = insets.left; newInsets.bottom = insets.bottom; newInsets.right = insets.right; return newInsets; } } private static Border errorDialogBorder; static Border getErrorDialogBorder() { if (errorDialogBorder == null) { errorDialogBorder = new ErrorDialogBorder(); } return errorDialogBorder; } private static class ErrorDialogBorder extends DialogBorder implements UIResource { protected Color getActiveBackground() { return UIManager.getColor("OptionPane.errorDialog.border.background"); } } private static Border questionDialogBorder; static Border getQuestionDialogBorder() { if (questionDialogBorder == null) { questionDialogBorder = new QuestionDialogBorder(); } return questionDialogBorder; } private static class QuestionDialogBorder extends DialogBorder implements UIResource { protected Color getActiveBackground() { return UIManager.getColor("OptionPane.questionDialog.border.background"); } } private static Border warningDialogBorder; static Border getWarningDialogBorder() { if (warningDialogBorder == null) { warningDialogBorder = new WarningDialogBorder(); } return warningDialogBorder; } private static class WarningDialogBorder extends DialogBorder implements UIResource { protected Color getActiveBackground() { return UIManager.getColor("OptionPane.warningDialog.border.background"); } } private static class Flush3DBorder extends AbstractBorder implements UIResource { private static final Insets INSETS = new Insets(2, 2, 2, 2); public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { if (c.isEnabled()) SmoothGradientUtils.drawFlush3DBorder(g, x, y, w, h); else SmoothGradientUtils.drawDisabledBorder(g, x, y, w, h); } public Insets getBorderInsets(Component c) { return INSETS; } public Insets getBorderInsets(Component c, Insets newInsets) { newInsets.top = INSETS.top; newInsets.left = INSETS.left; newInsets.bottom = INSETS.bottom; newInsets.right = INSETS.right; return newInsets; } } private static class ButtonBorder extends AbstractBorder implements UIResource { protected static final Insets INSETS = new Insets(2, 3, 2, 3); public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); if (model.isEnabled()) { boolean isPressed = model.isPressed() && model.isArmed(); boolean isDefault = button instanceof JButton && ((JButton) button).isDefaultButton(); if (isPressed && isDefault) SmoothGradientUtils.drawDefaultButtonPressedBorder(g, x, y, w, h); else if (isPressed) SmoothGradientUtils.drawPressed3DBorder(g, x, y, w, h); else if (isDefault) SmoothGradientUtils.drawDefaultButtonBorder(g, x, y, w, h, false); else SmoothGradientUtils.drawButtonBorder(g, x, y, w, h, false); } else { // disabled state SmoothGradientUtils.drawDisabledBorder(g, x, y, w - 1, h - 1); } } public Insets getBorderInsets(Component c) { return INSETS; } public Insets getBorderInsets(Component c, Insets newInsets) { newInsets.top = INSETS.top; newInsets.left = INSETS.left; newInsets.bottom = INSETS.bottom; newInsets.right = INSETS.right; return newInsets; } } private static class ComboBoxEditorBorder extends AbstractBorder { private static final Insets INSETS = new Insets(2, 2, 2, 0); public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { if (c.isEnabled()) SmoothGradientUtils.drawFlush3DBorder(g, x, y, w + 2, h); else { SmoothGradientUtils.drawDisabledBorder(g, x, y, w + 2, h-1); g.setColor(UIManager.getColor("control")); g.drawLine(x, y + h-1, x + w, y + h-1); } } public Insets getBorderInsets(Component c) { return INSETS; } } private static class ComboBoxArrowButtonBorder extends AbstractBorder implements UIResource { protected static final Insets INSETS = new Insets(2, 2, 2, 2); public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); if (model.isEnabled()) { boolean isPressed = model.isPressed() && model.isArmed(); if (isPressed) SmoothGradientUtils.drawPressed3DBorder(g, x, y, w, h); else SmoothGradientUtils.drawButtonBorder(g, x, y, w, h, false); } else { SmoothGradientUtils.drawDisabledBorder(g, x, y, w - 1, h - 1); } } public Insets getBorderInsets(Component c) { return INSETS; } } /** * A border used for <code>JInternalFrame</code>s. */ private static class InternalFrameBorder extends AbstractBorder implements UIResource { private static final Insets NORMAL_INSETS = new Insets(3, 3, 3, 3); private static final int corner = 14; private static final Insets MAXIMIZED_INSETS = new Insets(2, 2, 2, 2); static final int ALPHA1 = 150; static final int ALPHA2 = 50; public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { Color background; Color highlight; Color shadow; if (c instanceof JInternalFrame && ((JInternalFrame)c).isSelected()) { background = SmoothGradientLookAndFeel.getPrimaryControlDarkShadow(); highlight = SmoothGradientLookAndFeel.getPrimaryControlShadow(); shadow = SmoothGradientLookAndFeel.getPrimaryControlInfo(); } else { background = SmoothGradientLookAndFeel.getControlDarkShadow(); highlight = SmoothGradientLookAndFeel.getControlShadow(); shadow = SmoothGradientLookAndFeel.getControlInfo(); } g.setColor(background); // Draw outermost lines g.drawLine( 1, 0, w-2, 0); g.drawLine( 0, 1, 0, h-2); g.drawLine( w-1, 1, w-1, h-2); g.drawLine( 1, h-1, w-2, h-1); // Draw the bulk of the border for (int i = 1; i < 5; i++) { g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1); } if (c instanceof JInternalFrame && ((JInternalFrame)c).isResizable()) { g.setColor(highlight); // Draw the Long highlight lines g.drawLine( corner+1, 3, w-corner, 3); g.drawLine( 3, corner+1, 3, h-corner);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -