This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gui] Patch: javax.swing.plaf.basic and javax.swing.text
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Wed, 30 Jun 2004 21:52:17 +0200
- Subject: [gui] Patch: javax.swing.plaf.basic and javax.swing.text
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I just commited the attached patch to fix some things in
javax.swing.plaf.basic and javax.swing.text.
Michael
2004-06-30 Michael Koch <konqueror@gmx.de>
* javax/swing/plaf/basic/BasicButtonUI.java
(paintFocus): Fixed method signature.
(paintButtonPressed): Likewise.
(paintButtonNormal): Likewise.
(paintText): New method.
* javax/swing/plaf/basic/BasicLabelUI.java
(paint): Re-indented.
* javax/swing/plaf/basic/BasicTextUI.java
(installUI): Set parent textComponent to opaque.
* javax/swing/text/DefaultHighlighter.java
(checkPositions): New helper method.
(addHighlight): Throws BadLocationException, check positions.
(changeHighlight): Likewise.
* javax/swing/text/EditorKit.java
(EditorKit): Implements Serializable.
* javax/swing/text/JTextComponent.java
(getUI): Added javadoc.
(setUI): Likewise.
(upadteUI): Added javadoc, don't revalidate and repaint.
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD4DBQFA4xn0WSOgCCdjSDsRAk8MAJY18XWyUihbK0+kxWI7Vf3xXUlnAJ0aaS0c
wn+/OWsn7pjxJaW+sak6zQ==
=NhZV
-----END PGP SIGNATURE-----
Index: javax/swing/plaf/basic/BasicButtonUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicButtonUI.java,v
retrieving revision 1.6.2.5
diff -u -b -B -r1.6.2.5 BasicButtonUI.java
--- javax/swing/plaf/basic/BasicButtonUI.java 24 Jun 2004 05:31:34 -0000 1.6.2.5
+++ javax/swing/plaf/basic/BasicButtonUI.java 30 Jun 2004 19:48:44 -0000
@@ -239,14 +239,14 @@
if ((b.getModel().isArmed() && b.getModel().isPressed())
|| b.isSelected())
- paintButtonPressed(g, br, c);
+ paintButtonPressed(g, b);
else
paintButtonNormal(g, br, c);
paintIcon(g, c, ir);
if (text != null)
- paintText(g, c, tr, b.getText());
- paintFocus(g, c, vr, tr, ir);
+ paintText(g, b, tr, b.getText());
+ paintFocus(g, b, vr, tr, ir);
}
/**
@@ -256,7 +256,7 @@
* "focusPainted" property is <code>true</code>.
*
* @param g Graphics context to paint with
- * @param c Component to paint the focus of
+ * @param b Button to paint the focus of
* @param vr Visible rectangle, the area in which to paint
* @param tr Text rectangle, contained in visible rectangle
* @param ir Icon rectangle, contained in visible rectangle
@@ -264,10 +264,9 @@
* @see AbstractButton.isFocusPainted()
* @see JComponent.hasFocus()
*/
- protected void paintFocus(Graphics g, JComponent c, Rectangle vr,
+ protected void paintFocus(Graphics g, AbstractButton b, Rectangle vr,
Rectangle tr, Rectangle ir)
{
- AbstractButton b = (AbstractButton) c;
if (b.hasFocus() && b.isFocusPainted())
{
Graphics2D g2 = (Graphics2D) g;
@@ -313,13 +312,14 @@
* pressedBackgroundColor}.
*
* @param g The graphics context to paint with
- * @param area The area in which to paint
- * @param b The component to paint the state of
+ * @param b The button to paint the state of
*/
- protected void paintButtonPressed(Graphics g, Rectangle area, JComponent b)
+ protected void paintButtonPressed(Graphics g, AbstractButton b)
{
- if (((AbstractButton)b).isContentAreaFilled())
+ if (b.isContentAreaFilled())
{
+ Rectangle area = new Rectangle();
+ SwingUtilities.calculateInnerArea(b, area);
g.setColor(b.getBackground().darker());
g.fillRect(area.x, area.y, area.width, area.height);
}
@@ -334,7 +334,7 @@
* @param area The area in which to paint
* @param b The component to paint the state of
*/
- protected void paintButtonNormal(Graphics g, Rectangle area, JComponent b)
+ private void paintButtonNormal(Graphics g, Rectangle area, JComponent b)
{
if (((AbstractButton)b).isContentAreaFilled() && b.isOpaque())
{
@@ -355,20 +355,37 @@
protected void paintText(Graphics g, JComponent c, Rectangle textRect,
String text)
{
- Font f = c.getFont();
+ paintText(g, (AbstractButton) c, textRect, text);
+ }
+
+ /**
+ * Paints the "text" property of an {@link AbstractButton}, using the
+ * {@link textColor} color.
+ *
+ * @param g The graphics context to paint with
+ * @param b The button to paint the state of
+ * @param textRect The area in which to paint the text
+ * @param text The text to paint
+ *
+ * @since 1.4
+ */
+ protected void paintText(Graphics g, AbstractButton b, Rectangle textRect,
+ String text)
+ {
+ Font f = b.getFont();
g.setFont(f);
FontMetrics fm = g.getFontMetrics(f);
- if (c.isEnabled())
+ if (b.isEnabled())
{
- g.setColor(c.getForeground());
+ g.setColor(b.getForeground());
g.drawString(text, textRect.x, textRect.y + fm.getAscent());
}
else
{
- g.setColor(c.getBackground().brighter());
+ g.setColor(b.getBackground().brighter());
g.drawString(text, textRect.x, textRect.y + fm.getAscent());
- g.setColor(c.getBackground().darker());
+ g.setColor(b.getBackground().darker());
g.drawString(text, textRect.x + 1, textRect.y + fm.getAscent() + 1);
}
}
Index: javax/swing/plaf/basic/BasicLabelUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicLabelUI.java,v
retrieving revision 1.4.16.5
diff -u -b -B -r1.4.16.5 BasicLabelUI.java
Index: javax/swing/plaf/basic/BasicTextUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicTextUI.java,v
retrieving revision 1.4.16.6
diff -u -b -B -r1.4.16.6 BasicTextUI.java
--- javax/swing/plaf/basic/BasicTextUI.java 29 Jun 2004 11:30:49 -0000 1.4.16.6
+++ javax/swing/plaf/basic/BasicTextUI.java 30 Jun 2004 19:48:44 -0000
@@ -157,6 +157,7 @@
public void installUI(final JComponent c)
{
super.installUI(c);
+ c.setOpaque(true);
textComponent = (JTextComponent) c;
Index: javax/swing/text/DefaultHighlighter.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/Attic/DefaultHighlighter.java,v
retrieving revision 1.1.2.1
diff -u -b -B -r1.1.2.1 DefaultHighlighter.java
--- javax/swing/text/DefaultHighlighter.java 29 Jun 2004 11:30:50 -0000 1.1.2.1
+++ javax/swing/text/DefaultHighlighter.java 30 Jun 2004 19:48:44 -0000
@@ -84,6 +84,16 @@
{
}
+ private void checkPositions(int p0, int p1)
+ throws BadLocationException
+ {
+ if (p0 < 0)
+ throw new BadLocationException("DefaultHighlighter", p0);
+
+ if (p1 < p0)
+ throw new BadLocationException("DefaultHighlighter", p1);
+ }
+
public void install(JTextComponent c)
{
textComponent = c;
@@ -96,7 +106,9 @@
}
public Object addHighlight(int p0, int p1, Highlighter.HighlightPainter painter)
+ throws BadLocationException
{
+ checkPositions(p0, p1);
HighlightEntry entry = new HighlightEntry(p0, p1, painter);
highlights.add(entry);
return entry;
@@ -118,7 +130,9 @@
}
public void changeHighlight(Object tag, int p0, int p1)
+ throws BadLocationException
{
+ checkPositions(p0, p1);
HighlightEntry entry = (HighlightEntry) tag;
entry.p0 = p0;
entry.p1 = p1;
Index: javax/swing/text/EditorKit.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/EditorKit.java,v
retrieving revision 1.2.8.2
diff -u -b -B -r1.2.8.2 EditorKit.java
--- javax/swing/text/EditorKit.java 29 Jun 2004 09:59:11 -0000 1.2.8.2
+++ javax/swing/text/EditorKit.java 30 Jun 2004 19:48:44 -0000
@@ -48,7 +48,7 @@
public abstract class EditorKit
- implements Cloneable
+ implements Cloneable, Serializable
{
private static final long serialVersionUID = -5044124649345887822L;
Index: javax/swing/text/JTextComponent.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/JTextComponent.java,v
retrieving revision 1.4.2.13
diff -u -b -B -r1.4.2.13 JTextComponent.java
--- javax/swing/text/JTextComponent.java 29 Jun 2004 11:30:50 -0000 1.4.2.13
+++ javax/swing/text/JTextComponent.java 30 Jun 2004 19:48:44 -0000
@@ -393,21 +393,33 @@
return "JTextComponent";
}
+ /**
+ * This method returns the label's UI delegate.
+ *
+ * @return The label's UI delegate.
+ */
public TextUI getUI()
{
return (TextUI) ui;
}
+ /**
+ * This method sets the label's UI delegate.
+ *
+ * @param ui The label's UI delegate.
+ */
public void setUI(TextUI newUI)
{
super.setUI(newUI);
}
+ /**
+ * This method resets the label's UI delegate to the default UI for the
+ * current look and feel.
+ */
public void updateUI()
{
setUI((TextUI) UIManager.getUI(this));
- invalidate();
- repaint();
}
public Dimension getPreferredScrollableViewportSize()