From ddfe0404ed8627229942120a5d7e29b383895014 Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Fri, 12 May 2006 12:59:02 +0000 Subject: [PATCH] ComboBoxUI, TextFieldUI, PasswordFieldUI --- .../impl/gui/lookandfeel/SIPCommBorders.java | 80 ++++++++++++----- .../lookandfeel/SIPCommComboBoxEditor.java | 85 +++++++++++++++++++ .../gui/lookandfeel/SIPCommComboBoxUI.java | 8 +- .../gui/lookandfeel/SIPCommDefaultTheme.java | 2 + .../impl/gui/lookandfeel/SIPCommLFUtils.java | 32 +++++++ .../gui/lookandfeel/SIPCommLookAndFeel.java | 3 +- .../lookandfeel/SIPCommPasswordFieldUI.java | 38 +++++++++ .../gui/lookandfeel/SIPCommTextFieldUI.java | 8 ++ 8 files changed, 235 insertions(+), 21 deletions(-) create mode 100644 src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommComboBoxEditor.java create mode 100644 src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommPasswordFieldUI.java diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommBorders.java b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommBorders.java index 35e22d485..e8af4eeb3 100644 --- a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommBorders.java +++ b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommBorders.java @@ -1,3 +1,9 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ package net.java.sip.communicator.impl.gui.lookandfeel; import java.awt.Color; @@ -12,40 +18,35 @@ import javax.swing.plaf.basic.BasicBorders; import javax.swing.text.JTextComponent; +import net.java.sip.communicator.slick.runner.SipCommunicatorSlickRunner; +/** + * SIPCommBorders is where all component borders used in the SIPComm L&F + * are drawn. + * + * @author Yana Stamcheva + */ public class SIPCommBorders { - - private static Border textFieldBorder; /** - * Returns a border instance for a JTextField. - */ - public static Border getTextFieldBorder() { - if (textFieldBorder == null - || !(textFieldBorder instanceof SIPCommBorders.TextFieldBorder)) { - textFieldBorder = new SIPCommBorders.TextFieldBorder(); - } - return textFieldBorder; - } - - public static class TextFieldBorder extends AbstractBorder implements UIResource{ + * The RoundBorder is common border which is used throughout the + * SIPComm L&F. + */ + public static class RoundBorder 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) { - g.setColor(Color.GRAY); if (c.isEnabled()) { - g.drawRoundRect(x, y, w, h, 5, 5); + SIPCommLFUtils.drawRoundBorder(g, x, y, w, h, 5, 5); } else { - g.drawRoundRect(x, y, w, h, 5, 5); + SIPCommLFUtils.drawRoundDisabledBorder(g, x, y, w, h, 5, 5); } } - public Insets getBorderInsets(Component c) { return insets; } - public Insets getBorderInsets(Component c, Insets newInsets) { newInsets.top = insets.top; newInsets.left = insets.left; @@ -54,5 +55,46 @@ public Insets getBorderInsets(Component c, Insets newInsets) { return newInsets; } - } + } + + private static Border textFieldBorder; + + /** + * Returns a border instance for a JTextField. + */ + public static Border getTextFieldBorder() { + if (textFieldBorder == null + || !(textFieldBorder instanceof SIPCommBorders.TextFieldBorder)) { + textFieldBorder = new BorderUIResource.CompoundBorderUIResource( + new SIPCommBorders.TextFieldBorder(), + new BasicBorders.MarginBorder()); + } + return textFieldBorder; + } + + + /** + * The TextField border which is used in SIPComm L&F for all text fields. + */ + public static class TextFieldBorder extends RoundBorder { + + public void paintBorder(Component c, Graphics g, int x, int y, + int w, int h) { + + if (!(c instanceof JTextComponent)) { + if (c.isEnabled()) { + SIPCommLFUtils.drawRoundBorder(g, x, y, w, h, 5, 5); + } else { + SIPCommLFUtils.drawRoundDisabledBorder(g, x, y, w, h, 5, 5); + } + return; + } + + if (c.isEnabled() && ((JTextComponent)c).isEditable()) { + SIPCommLFUtils.drawRoundBorder(g, x, y, w, h, 5, 5); + } else { + SIPCommLFUtils.drawRoundDisabledBorder(g, x, y, w, h, 5, 5); + } + } + } } diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommComboBoxEditor.java b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommComboBoxEditor.java new file mode 100644 index 000000000..19387f53e --- /dev/null +++ b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommComboBoxEditor.java @@ -0,0 +1,85 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.gui.lookandfeel; + +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Insets; +import java.awt.Shape; +import java.awt.geom.GeneralPath; + +import javax.swing.JTextField; +import javax.swing.border.AbstractBorder; +import javax.swing.plaf.basic.BasicComboBoxEditor; +import javax.swing.plaf.metal.MetalComboBoxEditor; +import javax.swing.plaf.metal.MetalLookAndFeel; +import javax.swing.text.JTextComponent; + +import net.java.sip.communicator.impl.gui.utils.AntialiasingManager; + +/** + * The default editor for SIPCommunicator editable combo boxes. + * + * @author Yana Stamcheva + */ +public class SIPCommComboBoxEditor extends MetalComboBoxEditor { + + public SIPCommComboBoxEditor() { + super(); + + editor.setBorder(new EditorBorder()); + } + + protected static Insets editorBorderInsets = new Insets(2, 2, 2, 0); + private static final Insets SAFE_EDITOR_BORDER_INSETS = new Insets(2, 2, 2, 0); + + class EditorBorder extends AbstractBorder { + public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { + Graphics2D g2d = (Graphics2D)g; + + AntialiasingManager.activateAntialiasing(g2d); + + g2d.translate(x, y); + + g2d.setColor(SIPCommLookAndFeel.getControlDarkShadow()); + + GeneralPath path = new GeneralPath(); + int round = 2; + + path.moveTo(w, h-1); + path.lineTo(round, h-1); + path.curveTo(round, h-1, 0, h-1, 0, h-round-1); + path.lineTo(0, round); + path.curveTo(0, round, 0, 0, round, 0); + path.lineTo(w, 0); + + g2d.draw(path); + + g2d.translate(-x, -y); + } + + public Insets getBorderInsets( Component c ) { + if (System.getSecurityManager() != null) { + return SAFE_EDITOR_BORDER_INSETS; + } else { + return editorBorderInsets; + } + } + } + + /** + * A subclass of SIPCommComboBoxEditor that implements UIResource. + * SIPCommComboBoxEditor doesn't implement UIResource + * directly so that applications can safely override the + * cellRenderer property with BasicListCellRenderer subclasses. + */ + public static class UIResource extends SIPCommComboBoxEditor + implements javax.swing.plaf.UIResource { + } +} diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommComboBoxUI.java b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommComboBoxUI.java index 78560cb02..e414a3fc5 100644 --- a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommComboBoxUI.java +++ b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommComboBoxUI.java @@ -11,8 +11,10 @@ import java.awt.Rectangle; import java.awt.RenderingHints; +import javax.swing.ComboBoxEditor; import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.metal.MetalComboBoxEditor; import javax.swing.plaf.metal.MetalComboBoxUI; import javax.swing.plaf.metal.MetalLookAndFeel; @@ -31,6 +33,10 @@ public static ComponentUI createUI(JComponent c) { public void paint(Graphics g, JComponent c) { AntialiasingManager.activateAntialiasing(g); - super.paint(g, c); + super.paint(g, c); + } + + protected ComboBoxEditor createEditor() { + return new SIPCommComboBoxEditor.UIResource(); } } diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommDefaultTheme.java b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommDefaultTheme.java index 9c014f312..4ebd26bac 100644 --- a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommDefaultTheme.java +++ b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommDefaultTheme.java @@ -115,6 +115,8 @@ public void addCustomEntriesToTable(UIDefaults table) { "TabbedPane.unselectedBackground", LIGHT_GRAY, "TextField.border", textFieldBorder, + "PasswordField.border", textFieldBorder, + "FormattedTextField.border", textFieldBorder, "Table.gridColor", LIGHT_BLUE_GRAY, diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommLFUtils.java b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommLFUtils.java index a6beb6443..c10c01546 100644 --- a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommLFUtils.java +++ b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommLFUtils.java @@ -9,10 +9,42 @@ import java.awt.Color; import java.awt.Graphics; +import javax.swing.plaf.metal.MetalLookAndFeel; + +import net.java.sip.communicator.impl.gui.utils.AntialiasingManager; + /** * * @author Yana Stamcheva */ public class SIPCommLFUtils { + /** + * This draws the "Round Border" which is used throughout the SIPComm L&F + */ + static void drawRoundBorder(Graphics g, int x, int y, int w, int h, + int r1, int r2) { + AntialiasingManager.activateAntialiasing(g); + + g.translate(x, y); + + g.setColor(SIPCommLookAndFeel.getControlDarkShadow()); + g.drawRoundRect( 0, 0, w-1, h-1 , r1, r2); + + g.translate(-x, -y); + } + + /** + * This draws the "Round Disabled Border" which is used throughout the SIPComm L&F + */ + static void drawRoundDisabledBorder(Graphics g, int x, int y, int w, int h, + int r1, int r2) { + AntialiasingManager.activateAntialiasing(g); + + g.translate(x, y); + g.setColor(SIPCommLookAndFeel.getControlShadow()); + + g.drawRoundRect(0, 0, w-1, h-1, r1, r2); + g.translate(-x, -y); + } } diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommLookAndFeel.java b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommLookAndFeel.java index 5e47d8c91..d5ad374d1 100644 --- a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommLookAndFeel.java +++ b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommLookAndFeel.java @@ -48,7 +48,8 @@ protected void initClassDefaults(UIDefaults table) { "SplitPaneUI", lfPackageName + "SIPCommSplitPaneUI", "ScrollBarUI", lfPackageName + "SIPCommScrollBarUI", "ComboBoxUI", lfPackageName + "SIPCommComboBoxUI", - "TextFieldUI", lfPackageName + "SIPCommTextFieldUI" + "TextFieldUI", lfPackageName + "SIPCommTextFieldUI", + "PasswordFieldUI", lfPackageName + "SIPCommPasswordFieldUI" }; table.putDefaults(uiDefaults); } diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommPasswordFieldUI.java b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommPasswordFieldUI.java new file mode 100644 index 000000000..ba467113a --- /dev/null +++ b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommPasswordFieldUI.java @@ -0,0 +1,38 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.gui.lookandfeel; + +import java.awt.Graphics; + +import javax.swing.JComponent; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicPasswordFieldUI; +import javax.swing.text.JTextComponent; + +import net.java.sip.communicator.impl.gui.utils.AntialiasingManager; +/** + * The SIPCommPasswordFieldUI implementation. + * + * @author Yana Stamcheva + */ +public class SIPCommPasswordFieldUI extends BasicPasswordFieldUI { + + public static ComponentUI createUI(JComponent c) { + return new SIPCommPasswordFieldUI(); + } + + protected void paintSafely(Graphics g) { + AntialiasingManager.activateAntialiasing(g); + super.paintSafely(g); + } + + protected void paintBackground(Graphics g) { + JTextComponent c = this.getComponent(); + g.setColor(c.getBackground()); + g.fillRoundRect(1, 1, c.getWidth()-2, c.getHeight()-2, 5, 5); + } +} diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTextFieldUI.java b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTextFieldUI.java index 74b91edfb..2c04ca665 100644 --- a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTextFieldUI.java +++ b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTextFieldUI.java @@ -6,6 +6,7 @@ */ package net.java.sip.communicator.impl.gui.lookandfeel; +import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; @@ -15,6 +16,7 @@ import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.metal.MetalTextFieldUI; +import javax.swing.text.JTextComponent; import net.java.sip.communicator.impl.gui.utils.AntialiasingManager; @@ -33,4 +35,10 @@ protected void paintSafely(Graphics g) { AntialiasingManager.activateAntialiasing(g); super.paintSafely(g); } + + protected void paintBackground(Graphics g) { + JTextComponent c = this.getComponent(); + g.setColor(c.getBackground()); + g.fillRoundRect(1, 1, c.getWidth()-2, c.getHeight()-2, 5, 5); + } }