ComboBoxUI, TextFieldUI, PasswordFieldUI

cusax-fix
Yana Stamcheva 20 years ago
parent d13102fbea
commit ddfe0404ed

@ -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);
}
}
}
}

@ -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 {
}
}

@ -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();
}
}

@ -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,

@ -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);
}
}

@ -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);
}

@ -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);
}
}

@ -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);
}
}

Loading…
Cancel
Save