diff options
author | Mark Wielaard <mark@gcc.gnu.org> | 2005-11-18 00:59:33 +0000 |
---|---|---|
committer | Mark Wielaard <mark@gcc.gnu.org> | 2005-11-18 00:59:33 +0000 |
commit | ca9e049bc145ae985bc0e2dd6079dacdd51717ac (patch) | |
tree | 4c44aaa3ed1ee1b4f15732664c05cfc9214e1fa9 /libjava/classpath/javax/swing | |
parent | fb3a09c214e19c97d3751003d9a2ea8008f5005e (diff) | |
download | gcc-ca9e049bc145ae985bc0e2dd6079dacdd51717ac.tar.gz |
Imported GNU Classpath gcj-import-20051117.
* gnu/java/net/protocol/file/Connection.java: Removed, fully merged.
* sources.am: Regenerated.
* Makefile.in: Likewise.
From-SVN: r107153
Diffstat (limited to 'libjava/classpath/javax/swing')
60 files changed, 1700 insertions, 1218 deletions
diff --git a/libjava/classpath/javax/swing/JApplet.java b/libjava/classpath/javax/swing/JApplet.java index 3ee1046c802..e90c451891e 100644 --- a/libjava/classpath/javax/swing/JApplet.java +++ b/libjava/classpath/javax/swing/JApplet.java @@ -189,7 +189,7 @@ public class JApplet extends Applet protected String paramString() { - return "JFrame"; + return super.paramString(); } protected void processKeyEvent(KeyEvent e) diff --git a/libjava/classpath/javax/swing/JComponent.java b/libjava/classpath/javax/swing/JComponent.java index 021a2a34080..deb08c5db59 100644 --- a/libjava/classpath/javax/swing/JComponent.java +++ b/libjava/classpath/javax/swing/JComponent.java @@ -1918,9 +1918,15 @@ public abstract class JComponent extends Container implements Serializable g2 = getComponentGraphics(g2); g2.setClip(r.x, r.y, r.width, r.height); isPaintingDoubleBuffered = true; - paint(g2); - isPaintingDoubleBuffered = false; - g2.dispose(); + try + { + paint(g2); + } + finally + { + isPaintingDoubleBuffered = false; + g2.dispose(); + } // Paint the buffer contents on screen. g.drawImage(buffer, 0, 0, this); @@ -2921,8 +2927,7 @@ public abstract class JComponent extends Container implements Serializable { super.removeNotify(); - // FIXME: remove the WHEN_IN_FOCUSED_WINDOW bindings from the - // KeyboardManager + KeyboardManager.getManager().clearBindingsForComp(this); // Notify ancestor listeners. fireAncestorEvent(this, AncestorEvent.ANCESTOR_REMOVED); diff --git a/libjava/classpath/javax/swing/JEditorPane.java b/libjava/classpath/javax/swing/JEditorPane.java index 9ddf970deea..39f7c1f142f 100644 --- a/libjava/classpath/javax/swing/JEditorPane.java +++ b/libjava/classpath/javax/swing/JEditorPane.java @@ -59,6 +59,9 @@ import javax.swing.text.Document; import javax.swing.text.EditorKit; import javax.swing.text.Element; import javax.swing.text.JTextComponent; +import javax.swing.text.View; +import javax.swing.text.ViewFactory; +import javax.swing.text.WrappedPlainView; import javax.swing.text.html.HTML; import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.HTMLEditorKit; @@ -466,6 +469,30 @@ public class JEditorPane extends JTextComponent } } + /** + * An EditorKit used for plain text. This is the default editor kit for + * JEditorPanes. + * + * @author Roman Kennke (kennke@aicas.com) + */ + private static class PlainEditorKit extends DefaultEditorKit + { + + /** + * Returns a ViewFactory that supplies WrappedPlainViews. + */ + public ViewFactory getViewFactory() + { + return new ViewFactory() + { + public View create(Element el) + { + return new WrappedPlainView(el); + } + }; + } + } + private static final long serialVersionUID = 3140472492599046285L; private URL page; @@ -497,12 +524,12 @@ public class JEditorPane extends JTextComponent protected EditorKit createDefaultEditorKit() { - return new DefaultEditorKit(); + return new PlainEditorKit(); } public static EditorKit createEditorKitForContentType(String type) { - return new DefaultEditorKit(); + return new PlainEditorKit(); } /** diff --git a/libjava/classpath/javax/swing/JList.java b/libjava/classpath/javax/swing/JList.java index 4f5d3cc72c5..caa7f310ea8 100644 --- a/libjava/classpath/javax/swing/JList.java +++ b/libjava/classpath/javax/swing/JList.java @@ -1322,7 +1322,11 @@ public class JList extends JComponent implements Accessible, Scrollable /** - * Returns index of the cell to which specified location is closest to + * Returns index of the cell to which specified location is closest to. If + * the location is outside the bounds of the list, then the greatest index + * in the list model is returned. If the list model is empty, then + * <code>-1</code> is returned. + * * @param location for which to look for in the list * * @return index of the cell to which specified location is closest to. diff --git a/libjava/classpath/javax/swing/JMenu.java b/libjava/classpath/javax/swing/JMenu.java index 9734eb8732f..369c44d40c6 100644 --- a/libjava/classpath/javax/swing/JMenu.java +++ b/libjava/classpath/javax/swing/JMenu.java @@ -96,6 +96,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement public JMenu() { super(); + setOpaque(false); } /** @@ -107,6 +108,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement { super(text); popupMenu.setInvoker(this); + setOpaque(false); } /** @@ -120,6 +122,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement super(action); createActionChangeListener(this); popupMenu.setInvoker(this); + setOpaque(false); } /** diff --git a/libjava/classpath/javax/swing/JPanel.java b/libjava/classpath/javax/swing/JPanel.java index 7805e92b6e9..c02a9cfad6f 100644 --- a/libjava/classpath/javax/swing/JPanel.java +++ b/libjava/classpath/javax/swing/JPanel.java @@ -137,6 +137,6 @@ public class JPanel extends JComponent implements Accessible protected String paramString() { - return "JPanel"; + return super.paramString(); } } diff --git a/libjava/classpath/javax/swing/JSplitPane.java b/libjava/classpath/javax/swing/JSplitPane.java index cdab7bb6c4e..70feefab26e 100644 --- a/libjava/classpath/javax/swing/JSplitPane.java +++ b/libjava/classpath/javax/swing/JSplitPane.java @@ -170,13 +170,15 @@ public class JSplitPane extends JComponent implements Accessible public static final int HORIZONTAL_SPLIT = 1; /** The property fired when the last divider location property changes. */ - public static final String LAST_DIVIDER_LOCATION_PROPERTY = "lastDividerLocation"; + public static final String LAST_DIVIDER_LOCATION_PROPERTY = + "lastDividerLocation"; /** The constraints string used to add components to the left. */ public static final String LEFT = "left"; /** The property fired when the one touch expandable property changes. */ - public static final String ONE_TOUCH_EXPANDABLE_PROPERTY = "oneTouchExpandable"; + public static final String ONE_TOUCH_EXPANDABLE_PROPERTY = + "oneTouchExpandable"; /** The property fired when the orientation property changes. */ public static final String ORIENTATION_PROPERTY = "orientation"; @@ -199,7 +201,8 @@ public class JSplitPane extends JComponent implements Accessible /** Whether the JSplitPane uses one touch expandable buttons. */ protected boolean oneTouchExpandable = false; - // This is the master dividerSize variable and sets the BasicSplitPaneDivider one accordingly + // This is the master dividerSize variable and sets the + // BasicSplitPaneDivider one accordingly /** The size of the divider. */ protected int dividerSize = 10; @@ -286,7 +289,8 @@ public class JSplitPane extends JComponent implements Accessible */ public JSplitPane() { - this(HORIZONTAL_SPLIT, false, null, null); + this(HORIZONTAL_SPLIT, false, new JButton("left button"), + new JButton("right button")); } /** @@ -300,7 +304,8 @@ public class JSplitPane extends JComponent implements Accessible * @param constraints The constraints string to use. * @param index Where to place to component in the list of components. * - * @throws IllegalArgumentException When the constraints is not a known identifier. + * @throws IllegalArgumentException When the constraints is not a known + * identifier. */ protected void addImpl(Component comp, Object constraints, int index) { @@ -310,34 +315,35 @@ public class JSplitPane extends JComponent implements Accessible int place; if (constraints == null) { - if (leftComponent == null) - constraints = LEFT; - else if (rightComponent == null) - constraints = RIGHT; + if (leftComponent == null) + constraints = LEFT; + else if (rightComponent == null) + constraints = RIGHT; } if (constraints instanceof String) { - String placement = (String) constraints; - - if (placement.equals(BOTTOM) || placement.equals(RIGHT)) - { - if (rightComponent != null) - remove(rightComponent); - rightComponent = comp; - } - else if (placement.equals(LEFT) || placement.equals(TOP)) - { - if (leftComponent != null) - remove(leftComponent); - leftComponent = comp; - } - else if (placement.equals(DIVIDER)) - constraints = null; - else - throw new IllegalArgumentException("Constraints is not a known identifier."); - - super.addImpl(comp, constraints, index); + String placement = (String) constraints; + + if (placement.equals(BOTTOM) || placement.equals(RIGHT)) + { + if (rightComponent != null) + remove(rightComponent); + rightComponent = comp; + } + else if (placement.equals(LEFT) || placement.equals(TOP)) + { + if (leftComponent != null) + remove(leftComponent); + leftComponent = comp; + } + else if (placement.equals(DIVIDER)) + constraints = null; + else + throw new + IllegalArgumentException("Constraints is not a known identifier."); + + super.addImpl(comp, constraints, index); } invalidate(); layout(); @@ -614,10 +620,10 @@ public class JSplitPane extends JComponent implements Accessible { if (newContinuousLayout != continuousLayout) { - boolean oldValue = continuousLayout; - continuousLayout = newContinuousLayout; - firePropertyChange(CONTINUOUS_LAYOUT_PROPERTY, oldValue, - continuousLayout); + boolean oldValue = continuousLayout; + continuousLayout = newContinuousLayout; + firePropertyChange(CONTINUOUS_LAYOUT_PROPERTY, oldValue, + continuousLayout); } } @@ -634,7 +640,8 @@ public class JSplitPane extends JComponent implements Accessible public void setDividerLocation(double proportionalLocation) { if (proportionalLocation > 1 || proportionalLocation < 0) - throw new IllegalArgumentException("proportion has to be between 0 and 1."); + throw new IllegalArgumentException + ("proportion has to be between 0 and 1."); int max = (orientation == HORIZONTAL_SPLIT) ? getWidth() : getHeight(); setDividerLocation((int) (proportionalLocation * max)); @@ -649,9 +656,9 @@ public class JSplitPane extends JComponent implements Accessible { if (ui != null && location != getDividerLocation()) { - int oldLocation = getDividerLocation(); - ((SplitPaneUI) ui).setDividerLocation(this, location); - firePropertyChange(DIVIDER_LOCATION_PROPERTY, oldLocation, location); + int oldLocation = getDividerLocation(); + ((SplitPaneUI) ui).setDividerLocation(this, location); + firePropertyChange(DIVIDER_LOCATION_PROPERTY, oldLocation, location); } } @@ -664,9 +671,9 @@ public class JSplitPane extends JComponent implements Accessible { if (newSize != dividerSize) { - int oldSize = dividerSize; - dividerSize = newSize; - firePropertyChange(DIVIDER_SIZE_PROPERTY, oldSize, dividerSize); + int oldSize = dividerSize; + dividerSize = newSize; + firePropertyChange(DIVIDER_SIZE_PROPERTY, oldSize, dividerSize); } } @@ -683,10 +690,10 @@ public class JSplitPane extends JComponent implements Accessible { if (newLastLocation != lastDividerLocation) { - int oldValue = lastDividerLocation; - lastDividerLocation = newLastLocation; - firePropertyChange(LAST_DIVIDER_LOCATION_PROPERTY, oldValue, - lastDividerLocation); + int oldValue = lastDividerLocation; + lastDividerLocation = newLastLocation; + firePropertyChange(LAST_DIVIDER_LOCATION_PROPERTY, oldValue, + lastDividerLocation); } } @@ -696,11 +703,11 @@ public class JSplitPane extends JComponent implements Accessible * @param comp The left component. */ public void setLeftComponent(Component comp) - { + { if (comp != null) add(comp, LEFT); else - add(new JButton("left button"), LEFT); + remove (leftComponent); } /** @@ -715,10 +722,10 @@ public class JSplitPane extends JComponent implements Accessible { if (newValue != oneTouchExpandable) { - boolean oldValue = oneTouchExpandable; - oneTouchExpandable = newValue; - firePropertyChange(ONE_TOUCH_EXPANDABLE_PROPERTY, oldValue, - oneTouchExpandable); + boolean oldValue = oneTouchExpandable; + oneTouchExpandable = newValue; + firePropertyChange(ONE_TOUCH_EXPANDABLE_PROPERTY, oldValue, + oneTouchExpandable); } } @@ -732,13 +739,14 @@ public class JSplitPane extends JComponent implements Accessible public void setOrientation(int orientation) { if (orientation != HORIZONTAL_SPLIT && orientation != VERTICAL_SPLIT) - throw new IllegalArgumentException("orientation must be one of VERTICAL_SPLIT, HORIZONTAL_SPLIT"); + throw new IllegalArgumentException + ("orientation must be one of VERTICAL_SPLIT, HORIZONTAL_SPLIT"); if (orientation != this.orientation) { - int oldOrientation = this.orientation; - this.orientation = orientation; - firePropertyChange(ORIENTATION_PROPERTY, oldOrientation, - this.orientation); + int oldOrientation = this.orientation; + this.orientation = orientation; + firePropertyChange(ORIENTATION_PROPERTY, oldOrientation, + this.orientation); } } @@ -766,7 +774,7 @@ public class JSplitPane extends JComponent implements Accessible if (comp != null) add(comp, RIGHT); else - add(new JButton("right button"), RIGHT); + remove (rightComponent); } /** diff --git a/libjava/classpath/javax/swing/JTextPane.java b/libjava/classpath/javax/swing/JTextPane.java index 1f5b99e43c5..a2aebd4ca68 100644 --- a/libjava/classpath/javax/swing/JTextPane.java +++ b/libjava/classpath/javax/swing/JTextPane.java @@ -47,7 +47,9 @@ import javax.swing.text.Document; import javax.swing.text.EditorKit; import javax.swing.text.Element; import javax.swing.text.MutableAttributeSet; +import javax.swing.text.SimpleAttributeSet; import javax.swing.text.Style; +import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; import javax.swing.text.StyledEditorKit; @@ -192,9 +194,20 @@ public class JTextPane */ public void insertComponent(Component component) { - // TODO: One space must be inserted here with attributes set to indicate - // that the component must be displayed here. Have to figure out the - // attributes. + SimpleAttributeSet atts = new SimpleAttributeSet(); + atts.addAttribute(StyleConstants.ComponentAttribute, component); + atts.addAttribute(StyleConstants.NameAttribute, + StyleConstants.ComponentElementName); + try + { + getDocument().insertString(getCaret().getDot(), " ", atts); + } + catch (BadLocationException ex) + { + AssertionError err = new AssertionError("Unexpected bad location"); + err.initCause(ex); + throw err; + } } /** @@ -204,9 +217,20 @@ public class JTextPane */ public void insertIcon(Icon icon) { - // TODO: One space must be inserted here with attributes set to indicate - // that the icon must be displayed here. Have to figure out the - // attributes. + SimpleAttributeSet atts = new SimpleAttributeSet(); + atts.addAttribute(StyleConstants.IconAttribute, icon); + atts.addAttribute(StyleConstants.NameAttribute, + StyleConstants.IconElementName); + try + { + getDocument().insertString(getCaret().getDot(), " ", atts); + } + catch (BadLocationException ex) + { + AssertionError err = new AssertionError("Unexpected bad location"); + err.initCause(ex); + throw err; + } } /** diff --git a/libjava/classpath/javax/swing/KeyboardManager.java b/libjava/classpath/javax/swing/KeyboardManager.java index d3868309d08..aa9524cfe57 100644 --- a/libjava/classpath/javax/swing/KeyboardManager.java +++ b/libjava/classpath/javax/swing/KeyboardManager.java @@ -53,7 +53,7 @@ import java.util.Vector; * Components register keyboard actions with the condition * JComponent.WHEN_IN_FOCUSED_WINDOW. * - * @author Anthony Balkissoon <abalkiss@redhat.com> + * @author Anthony Balkissoon abalkiss at redhat dot com * */ class KeyboardManager diff --git a/libjava/classpath/javax/swing/ToolTipManager.java b/libjava/classpath/javax/swing/ToolTipManager.java index 03835794b68..289149fb603 100644 --- a/libjava/classpath/javax/swing/ToolTipManager.java +++ b/libjava/classpath/javax/swing/ToolTipManager.java @@ -173,18 +173,9 @@ public class ToolTipManager extends MouseAdapter implements MouseMotionListener /** The last known position of the mouse cursor. */ private static Point currentPoint; - - /** - * The panel that holds the tooltip when the tooltip is displayed fully - * inside the current container. - */ - private static Container containerPanel; - - /** - * The window used when the tooltip doesn't fit inside the current - * container. - */ - private static JDialog tooltipWindow; + + /** */ + private static Popup popup; /** * Creates a new ToolTipManager and sets up the timers. @@ -369,26 +360,27 @@ public class ToolTipManager extends MouseAdapter implements MouseMotionListener && getContentPaneDeepestComponent(event) == currentComponent) return; currentPoint = event.getPoint(); + currentComponent = (Component) event.getSource(); if (exitTimer.isRunning()) { - exitTimer.stop(); - insideTimer.start(); - return; + exitTimer.stop(); + showTip(); + return; } - // This should always be stopped unless we have just fake-exited. - if (! enterTimer.isRunning()) + if (!enterTimer.isRunning()) enterTimer.start(); } /** - * This method is called when the mouse exits a JComponent registered with - * the ToolTipManager. When the mouse exits, the tooltip should be hidden + * This method is called when the mouse exits a JComponent registered with the + * ToolTipManager. When the mouse exits, the tooltip should be hidden * immediately. - * - * @param event The MouseEvent. + * + * @param event + * The MouseEvent. */ public void mouseExited(MouseEvent event) { @@ -399,7 +391,7 @@ public class ToolTipManager extends MouseAdapter implements MouseMotionListener currentComponent = null; hideTip(); - if (! enterTimer.isRunning() && insideTimer.isRunning()) + if (! enterTimer.isRunning()) exitTimer.start(); if (enterTimer.isRunning()) enterTimer.stop(); @@ -460,77 +452,36 @@ public class ToolTipManager extends MouseAdapter implements MouseMotionListener void showTip() { if (!enabled || currentComponent == null || !currentComponent.isEnabled() - || (currentTip != null && currentTip.isVisible())) - return; + || !currentComponent.isShowing()) + { + popup = null; + return; + } if (currentTip == null || currentTip.getComponent() != currentComponent && currentComponent instanceof JComponent) currentTip = ((JComponent) currentComponent).createToolTip(); - currentTip.setVisible(true); - Container parent = currentComponent.getParent(); Point p = currentPoint; + Point cP = currentComponent.getLocationOnScreen(); Dimension dims = currentTip.getPreferredSize(); - if (parent instanceof JPopupMenu) - setLightWeightPopupEnabled(((JPopupMenu) parent).isLightWeightPopupEnabled()); - else - setLightWeightPopupEnabled(true); - - if (isLightWeightPopupEnabled()) - { - JLayeredPane pane = null; - JRootPane r = ((JRootPane) SwingUtilities. - getAncestorOfClass(JRootPane.class, currentComponent)); - if (r != null) - pane = r.getLayeredPane(); - if (pane == null) - return; - - if (containerPanel != null) - hideTip(); - - containerPanel = new Panel(); - JRootPane root = new JRootPane(); - root.getContentPane().add(currentTip); - containerPanel.add(root); - - LayoutManager lm = containerPanel.getLayout(); - if (lm instanceof FlowLayout) - { - FlowLayout fm = (FlowLayout) lm; - fm.setVgap(0); - fm.setHgap(0); - } - - p = SwingUtilities.convertPoint(currentComponent, p, pane); - p = adjustLocation(p, pane, dims); - - pane.add(containerPanel); - containerPanel.setBounds(p.x, p.y, dims.width, dims.height); - currentTip.setBounds(0, 0, dims.width, dims.height); - containerPanel.validate(); - containerPanel.repaint(); - } - else if (currentComponent.isShowing()) - { - SwingUtilities.convertPointToScreen(p, currentComponent); - p = adjustLocation(p, SwingUtilities.getWindowAncestor(currentComponent), - dims); - - tooltipWindow = new JDialog(); - tooltipWindow.setContentPane(currentTip); - tooltipWindow.setUndecorated(true); - tooltipWindow.getRootPane(). - setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); - tooltipWindow.pack(); - tooltipWindow.setBounds(p.x, p.y, dims.width, dims.height); - tooltipWindow.show(); - tooltipWindow.validate(); - tooltipWindow.repaint(); - currentTip.revalidate(); - currentTip.repaint(); - } + JLayeredPane pane = null; + JRootPane r = ((JRootPane) SwingUtilities.getAncestorOfClass(JRootPane.class, + currentComponent)); + if (r != null) + pane = r.getLayeredPane(); + if (pane == null) + return; + + p.translate(cP.x, cP.y); + adjustLocation(p, pane, dims); + + currentTip.setBounds(0, 0, dims.width, dims.height); + + PopupFactory factory = PopupFactory.getSharedInstance(); + popup = factory.getPopup(currentComponent, currentTip, p.x, p.y); + popup.show(); } /** @@ -550,7 +501,7 @@ public class ToolTipManager extends MouseAdapter implements MouseMotionListener if (p.y + d.height < c.getHeight()) p.y += d.height; if (p.y + d.height > c.getHeight()) - p.y -= d.height*2; + p.y -= d.height; return p; } @@ -561,29 +512,8 @@ public class ToolTipManager extends MouseAdapter implements MouseMotionListener */ void hideTip() { - if (currentTip == null || ! currentTip.isVisible() || ! enabled) - return; - currentTip.setVisible(false); - if (containerPanel != null) - { - Container parent = containerPanel.getParent(); - if (parent == null) - return; - parent.remove(containerPanel); - - parent = currentTip.getParent(); - if (parent == null) - return; - parent.remove(currentTip); - containerPanel = null; - } - if (tooltipWindow != null) - { - tooltipWindow.hide(); - tooltipWindow.dispose(); - tooltipWindow = null; - } - currentTip = null; + if (popup != null) + popup.hide(); } /** diff --git a/libjava/classpath/javax/swing/UIManager.java b/libjava/classpath/javax/swing/UIManager.java index 15a78190303..fbf1c7c79cb 100644 --- a/libjava/classpath/javax/swing/UIManager.java +++ b/libjava/classpath/javax/swing/UIManager.java @@ -132,6 +132,11 @@ public class UIManager implements Serializable static UIDefaults currentUIDefaults; + /** + * UIDefaults set by the user. + */ + static UIDefaults userUIDefaults; + /** Property change listener mechanism. */ static SwingPropertyChangeSupport listeners = new SwingPropertyChangeSupport(UIManager.class); @@ -305,7 +310,12 @@ public class UIManager implements Serializable */ public static Object get(Object key) { - return getLookAndFeelDefaults().get(key); + Object val = null; + if (userUIDefaults != null) + val = userUIDefaults.get(key); + if (val == null) + val = getLookAndFeelDefaults().get(key); + return val; } /** @@ -318,7 +328,12 @@ public class UIManager implements Serializable */ public static Object get(Object key, Locale locale) { - return getLookAndFeelDefaults().get(key ,locale); + Object val = null; + if (userUIDefaults != null) + val = userUIDefaults.get(key, locale); + if (val == null) + val = getLookAndFeelDefaults().get(key, locale); + return val; } /** @@ -329,7 +344,7 @@ public class UIManager implements Serializable */ public static boolean getBoolean(Object key) { - Boolean value = (Boolean) getLookAndFeelDefaults().get(key); + Boolean value = (Boolean) get(key); return value != null ? value.booleanValue() : false; } @@ -341,7 +356,7 @@ public class UIManager implements Serializable */ public static boolean getBoolean(Object key, Locale locale) { - Boolean value = (Boolean) getLookAndFeelDefaults().get(key, locale); + Boolean value = (Boolean) get(key, locale); return value != null ? value.booleanValue() : false; } @@ -350,7 +365,7 @@ public class UIManager implements Serializable */ public static Border getBorder(Object key) { - return (Border) getLookAndFeelDefaults().get(key); + return (Border) get(key); } /** @@ -360,7 +375,7 @@ public class UIManager implements Serializable */ public static Border getBorder(Object key, Locale locale) { - return (Border) getLookAndFeelDefaults().get(key, locale); + return (Border) get(key, locale); } /** @@ -368,7 +383,7 @@ public class UIManager implements Serializable */ public static Color getColor(Object key) { - return (Color) getLookAndFeelDefaults().get(key); + return (Color) get(key); } /** @@ -376,7 +391,7 @@ public class UIManager implements Serializable */ public static Color getColor(Object key, Locale locale) { - return (Color) getLookAndFeelDefaults().get(key); + return (Color) get(key); } /** @@ -405,7 +420,7 @@ public class UIManager implements Serializable */ public static Dimension getDimension(Object key) { - return (Dimension) getLookAndFeelDefaults().get(key); + return (Dimension) get(key); } /** @@ -413,7 +428,7 @@ public class UIManager implements Serializable */ public static Dimension getDimension(Object key, Locale locale) { - return (Dimension) getLookAndFeelDefaults().get(key, locale); + return (Dimension) get(key, locale); } /** @@ -426,7 +441,7 @@ public class UIManager implements Serializable */ public static Font getFont(Object key) { - return (Font) getLookAndFeelDefaults().get(key); + return (Font) get(key); } /** @@ -439,7 +454,7 @@ public class UIManager implements Serializable */ public static Font getFont(Object key, Locale locale) { - return (Font) getLookAndFeelDefaults().get(key ,locale); + return (Font) get(key ,locale); } /** @@ -447,7 +462,7 @@ public class UIManager implements Serializable */ public static Icon getIcon(Object key) { - return (Icon) getLookAndFeelDefaults().get(key); + return (Icon) get(key); } /** @@ -455,7 +470,7 @@ public class UIManager implements Serializable */ public static Icon getIcon(Object key, Locale locale) { - return (Icon) getLookAndFeelDefaults().get(key, locale); + return (Icon) get(key, locale); } /** @@ -463,7 +478,11 @@ public class UIManager implements Serializable */ public static Insets getInsets(Object key) { - return getLookAndFeelDefaults().getInsets(key); + Object o = get(key); + if (o instanceof Insets) + return (Insets) o; + else + return null; } /** @@ -471,7 +490,11 @@ public class UIManager implements Serializable */ public static Insets getInsets(Object key, Locale locale) { - return getLookAndFeelDefaults().getInsets(key, locale); + Object o = get(key, locale); + if (o instanceof Insets) + return (Insets) o; + else + return null; } /** @@ -487,7 +510,7 @@ public class UIManager implements Serializable public static int getInt(Object key) { - Integer x = (Integer) getLookAndFeelDefaults().get(key); + Integer x = (Integer) get(key); if (x == null) return 0; return x.intValue(); @@ -495,7 +518,7 @@ public class UIManager implements Serializable public static int getInt(Object key, Locale locale) { - Integer x = (Integer) getLookAndFeelDefaults().get(key, locale); + Integer x = (Integer) get(key, locale); if (x == null) return 0; return x.intValue(); @@ -529,7 +552,7 @@ public class UIManager implements Serializable */ public static String getString(Object key) { - return (String) getLookAndFeelDefaults().get(key); + return (String) get(key); } /** @@ -537,7 +560,7 @@ public class UIManager implements Serializable */ public static String getString(Object key, Locale locale) { - return (String) getLookAndFeelDefaults().get(key, locale); + return (String) get(key, locale); } /** @@ -562,7 +585,13 @@ public class UIManager implements Serializable */ public static ComponentUI getUI(JComponent target) { - return getLookAndFeelDefaults().getUI(target); + ComponentUI ui = null; + if (userUIDefaults != null + && userUIDefaults.get(target.getUIClassID()) != null) + ui = userUIDefaults.getUI(target); + if (ui == null) + ui = currentUIDefaults.getUI(target); + return ui; } /** @@ -591,7 +620,11 @@ public class UIManager implements Serializable */ public static Object put(Object key, Object value) { - return getLookAndFeelDefaults().put(key,value); + Object old = get(key); + if (userUIDefaults == null) + userUIDefaults = new UIDefaults(); + userUIDefaults.put(key, value); + return old; } /** @@ -617,7 +650,6 @@ public class UIManager implements Serializable { if (newLookAndFeel != null && ! newLookAndFeel.isSupportedLookAndFeel()) throw new UnsupportedLookAndFeelException(newLookAndFeel.getName()); - LookAndFeel oldLookAndFeel = currentLookAndFeel; if (oldLookAndFeel != null) oldLookAndFeel.uninitialize(); diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicBorders.java b/libjava/classpath/javax/swing/plaf/basic/BasicBorders.java index cec7bec8501..5d4ce18932b 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicBorders.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicBorders.java @@ -51,7 +51,6 @@ import javax.swing.JButton; import javax.swing.JPopupMenu; import javax.swing.JSplitPane; import javax.swing.JToolBar; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.border.AbstractBorder; import javax.swing.border.BevelBorder; @@ -95,21 +94,18 @@ public class BasicBorders */ public static Border getButtonBorder() { - UIDefaults defaults; Border outer; - defaults = UIManager.getLookAndFeelDefaults(); - /* The keys for UIDefaults have been determined by writing a * test program that dumps the UIDefaults to stdout; that program * was run on a JDK 1.4.1_01 for GNU/Linux. Note that in the API, * the key "light" is usually called "highlight", and "highlight" * is usually called "lightHighlight". */ - outer = new ButtonBorder(defaults.getColor("Button.shadow"), - defaults.getColor("Button.darkShadow"), - defaults.getColor("Button.light"), - defaults.getColor("Button.highlight")); + outer = new ButtonBorder(UIManager.getColor("Button.shadow"), + UIManager.getColor("Button.darkShadow"), + UIManager.getColor("Button.light"), + UIManager.getColor("Button.highlight")); /* While the inner border is shared between multiple buttons, * we do not share the outer border because ButtonBorders store @@ -145,11 +141,8 @@ public class BasicBorders */ public static Border getRadioButtonBorder() { - UIDefaults defaults; Border outer; - defaults = UIManager.getLookAndFeelDefaults(); - /* The keys for UIDefaults have been determined by writing a * test program that dumps the UIDefaults to stdout; that program * was run on a JDK 1.4.1_01 for GNU/Linux. Note that in the API, @@ -157,10 +150,10 @@ public class BasicBorders * is usually called "lightHighlight". */ outer = new RadioButtonBorder( - defaults.getColor("RadioButton.shadow"), - defaults.getColor("RadioButton.darkShadow"), - defaults.getColor("RadioButton.light"), - defaults.getColor("RadioButton.highlight")); + UIManager.getColor("RadioButton.shadow"), + UIManager.getColor("RadioButton.darkShadow"), + UIManager.getColor("RadioButton.light"), + UIManager.getColor("RadioButton.highlight")); /* While the inner border is shared between multiple buttons, we * do not share the outer border because RadioButtonBorders, being @@ -197,11 +190,8 @@ public class BasicBorders */ public static Border getToggleButtonBorder() { - UIDefaults defaults; Border outer; - defaults = UIManager.getLookAndFeelDefaults(); - /* The keys for UIDefaults have been determined by writing a * test program that dumps the UIDefaults to stdout; that program * was run on a JDK 1.4.1_01 for GNU/Linux. Note that in the API, @@ -209,10 +199,10 @@ public class BasicBorders * is usually called "lightHighlight". */ outer = new ToggleButtonBorder( - defaults.getColor("ToggleButton.shadow"), - defaults.getColor("ToggleButton.darkShadow"), - defaults.getColor("ToggleButton.light"), - defaults.getColor("ToggleButton.highlight")); + UIManager.getColor("ToggleButton.shadow"), + UIManager.getColor("ToggleButton.darkShadow"), + UIManager.getColor("ToggleButton.light"), + UIManager.getColor("ToggleButton.highlight")); /* While the inner border is shared between multiple buttons, we * do not share the outer border because ToggleButtonBorders, being @@ -247,12 +237,9 @@ public class BasicBorders */ public static Border getMenuBarBorder() { - UIDefaults defaults; - /* See comment in methods above for why this border is not shared. */ - defaults = UIManager.getLookAndFeelDefaults(); - return new MenuBarBorder(defaults.getColor("MenuBar.shadow"), - defaults.getColor("MenuBar.highlight")); + return new MenuBarBorder(UIManager.getColor("MenuBar.shadow"), + UIManager.getColor("MenuBar.highlight")); } @@ -279,12 +266,9 @@ public class BasicBorders */ public static Border getSplitPaneBorder() { - UIDefaults defaults; - /* See comment in methods above for why this border is not shared. */ - defaults = UIManager.getLookAndFeelDefaults(); - return new SplitPaneBorder(defaults.getColor("SplitPane.highlight"), - defaults.getColor("SplitPane.darkShadow")); + return new SplitPaneBorder(UIManager.getColor("SplitPane.highlight"), + UIManager.getColor("SplitPane.darkShadow")); } @@ -314,13 +298,10 @@ public class BasicBorders */ public static Border getSplitPaneDividerBorder() { - UIDefaults defaults; - /* See comment in methods above for why this border is not shared. */ - defaults = UIManager.getLookAndFeelDefaults(); return new SplitPaneDividerBorder( - defaults.getColor("SplitPane.highlight"), - defaults.getColor("SplitPane.darkShadow")); + UIManager.getColor("SplitPane.highlight"), + UIManager.getColor("SplitPane.darkShadow")); } @@ -346,15 +327,12 @@ public class BasicBorders */ public static Border getTextFieldBorder() { - UIDefaults defaults; - /* See comment in methods above for why this border is not shared. */ - defaults = UIManager.getLookAndFeelDefaults(); return new FieldBorder( - defaults.getColor("TextField.shadow"), - defaults.getColor("TextField.darkShadow"), - defaults.getColor("TextField.light"), - defaults.getColor("TextField.highlight")); + UIManager.getColor("TextField.shadow"), + UIManager.getColor("TextField.darkShadow"), + UIManager.getColor("TextField.light"), + UIManager.getColor("TextField.highlight")); } @@ -394,17 +372,14 @@ public class BasicBorders */ public static Border getInternalFrameBorder() { - UIDefaults defaults; Color shadow, darkShadow, highlight, lightHighlight, line; /* See comment in methods above for why this border is not shared. */ - defaults = UIManager.getLookAndFeelDefaults(); - - shadow = defaults.getColor("InternalFrame.borderShadow"); - darkShadow = defaults.getColor("InternalFrame.borderDarkShadow"); - highlight = defaults.getColor("InternalFrame.borderLight"); - lightHighlight = defaults.getColor("InternalFrame.borderHighlight"); - line = defaults.getColor("InternalFrame.borderColor"); + shadow = UIManager.getColor("InternalFrame.borderShadow"); + darkShadow = UIManager.getColor("InternalFrame.borderDarkShadow"); + highlight = UIManager.getColor("InternalFrame.borderLight"); + lightHighlight = UIManager.getColor("InternalFrame.borderHighlight"); + line = UIManager.getColor("InternalFrame.borderColor"); return new BorderUIResource.CompoundBorderUIResource( /* outer border */ diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicButtonUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicButtonUI.java index 2d3dbd350e0..7a63331b9c8 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicButtonUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicButtonUI.java @@ -52,7 +52,6 @@ import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.LookAndFeel; import javax.swing.SwingUtilities; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.plaf.ButtonUI; import javax.swing.plaf.ComponentUI; @@ -161,7 +160,6 @@ public class BasicButtonUI extends ButtonUI b.setIconTextGap(UIManager.getInt(prefix + "textIconGap")); b.setInputMap(JComponent.WHEN_FOCUSED, (InputMap) UIManager.get(prefix + "focusInputMap")); - b.setRolloverEnabled(UIManager.getBoolean(prefix + "rollover")); } /** @@ -444,9 +442,8 @@ public class BasicButtonUI extends ButtonUI } else { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); String prefix = getPropertyPrefix(); - g.setColor(defaults.getColor(prefix + "disabledText")); + g.setColor(UIManager.getColor(prefix + "disabledText")); g.drawString(text, textRect.x, textRect.y + fm.getAscent()); } } diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicCheckBoxUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicCheckBoxUI.java index 3cf02a00156..14dadb85cf9 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicCheckBoxUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicCheckBoxUI.java @@ -40,7 +40,6 @@ package javax.swing.plaf.basic; import javax.swing.Icon; import javax.swing.JComponent; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; @@ -53,12 +52,11 @@ public class BasicCheckBoxUI extends BasicRadioButtonUI public Icon getDefaultIcon() { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - return defaults.getIcon("CheckBox.icon"); + return UIManager.getIcon("CheckBox.icon"); } /** - * Returns the prefix for entries in the {@link UIDefaults} table. + * Returns the prefix for entries in the {@link UIManager} defaults table. * * @return "CheckBox." */ diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicComboBoxUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicComboBoxUI.java index 464c8dd9f63..b22aa15f901 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicComboBoxUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicComboBoxUI.java @@ -805,10 +805,10 @@ public class BasicComboBoxUI extends ComboBoxUI isPressed, hasFocus); if (! comboBox.isEnabled()) { - comp.setBackground(UIManager.getLookAndFeelDefaults().getColor( - "ComboBox.disabledBackground")); - comp.setForeground(UIManager.getLookAndFeelDefaults().getColor( - "ComboBox.disabledForeground")); + comp.setBackground(UIManager.getColor( + "ComboBox.disabledBackground")); + comp.setForeground(UIManager.getColor( + "ComboBox.disabledForeground")); comp.setEnabled(false); } comp.setBounds(0, 0, bounds.width, bounds.height); diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicEditorPaneUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicEditorPaneUI.java index d5b34d9eef6..d514a87c8ee 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicEditorPaneUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicEditorPaneUI.java @@ -42,10 +42,7 @@ import javax.swing.JComponent; import javax.swing.JEditorPane; import javax.swing.plaf.ComponentUI; import javax.swing.text.EditorKit; -import javax.swing.text.Element; import javax.swing.text.JTextComponent; -import javax.swing.text.PlainView; -import javax.swing.text.View; /** * The UI class for {@link JEditorPane}s. @@ -76,14 +73,6 @@ public class BasicEditorPaneUI extends BasicTextUI // Do nothing here. } - // FIXME: Should not be overridden here but instead be handled by the - // JEditorPane's EditorKit. However, as long as we don't have styles in - // place this doesn't make much sense. - public View create(Element elem) - { - return new PlainView(elem); - } - /** * Returns the property prefix to be used by this UI class. This is * <code>EditorPane</code> in this case. diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicFileChooserUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicFileChooserUI.java index 9c639656545..60179dc0706 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicFileChooserUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicFileChooserUI.java @@ -79,7 +79,6 @@ import javax.swing.ListCellRenderer; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.Timer; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @@ -1429,27 +1428,25 @@ public class BasicFileChooserUI extends FileChooserUI */ protected void installStrings(JFileChooser fc) { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + acceptAllFileFilterText = UIManager.getString("FileChooser.acceptAllFileFilterText"); + cancelButtonMnemonic = UIManager.getInt("FileChooser.cancelButtonMnemonic"); + cancelButtonText = UIManager.getString("FileChooser.cancelButtonText"); + cancelButtonToolTipText = UIManager.getString("FileChooser.cancelButtonToolTipText"); - acceptAllFileFilterText = defaults.getString("FileChooser.acceptAllFileFilterText"); - cancelButtonMnemonic = defaults.getInt("FileChooser.cancelButtonMnemonic"); - cancelButtonText = defaults.getString("FileChooser.cancelButtonText"); - cancelButtonToolTipText = defaults.getString("FileChooser.cancelButtonToolTipText"); + dirDescText = UIManager.getString("FileChooser.directoryDescriptionText"); + fileDescText = UIManager.getString("FileChooser.fileDescriptionText"); - dirDescText = defaults.getString("FileChooser.directoryDescriptionText"); - fileDescText = defaults.getString("FileChooser.fileDescriptionText"); + helpButtonMnemonic = UIManager.getInt("FileChooser.helpButtonMnemonic"); + helpButtonText = UIManager.getString("FileChooser.helpButtonText"); + helpButtonToolTipText = UIManager.getString("FileChooser.helpButtonToolTipText"); - helpButtonMnemonic = defaults.getInt("FileChooser.helpButtonMnemonic"); - helpButtonText = defaults.getString("FileChooser.helpButtonText"); - helpButtonToolTipText = defaults.getString("FileChooser.helpButtonToolTipText"); + openButtonMnemonic = UIManager.getInt("FileChooser.openButtonMnemonic"); + openButtonText = UIManager.getString("FileChooser.openButtonText"); + openButtonToolTipText = UIManager.getString("FileChooser.openButtonToolTipText"); - openButtonMnemonic = defaults.getInt("FileChooser.openButtonMnemonic"); - openButtonText = defaults.getString("FileChooser.openButtonText"); - openButtonToolTipText = defaults.getString("FileChooser.openButtonToolTipText"); - - saveButtonMnemonic = defaults.getInt("FileChooser.saveButtonMnemonic"); - saveButtonText = defaults.getString("FileChooser.saveButtonText"); - saveButtonToolTipText = defaults.getString("FileChooser.saveButtonToolTipText"); + saveButtonMnemonic = UIManager.getInt("FileChooser.saveButtonMnemonic"); + saveButtonText = UIManager.getString("FileChooser.saveButtonText"); + saveButtonToolTipText = UIManager.getString("FileChooser.saveButtonToolTipText"); } /** diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java b/libjava/classpath/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java index 73d3e6173d3..56022f3331e 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java @@ -66,7 +66,6 @@ import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; -import javax.swing.UIDefaults; import javax.swing.UIManager; /** @@ -718,13 +717,11 @@ public class BasicInternalFrameTitlePane extends JComponent */ protected void installDefaults() { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - - title.setFont(defaults.getFont("InternalFrame.titleFont")); - selectedTextColor = defaults.getColor("InternalFrame.activeTitleForeground"); - selectedTitleColor = defaults.getColor("InternalFrame.activeTitleBackground"); - notSelectedTextColor = defaults.getColor("InternalFrame.inactiveTitleForeground"); - notSelectedTitleColor = defaults.getColor("InternalFrame.inactiveTitleBackground"); + title.setFont(UIManager.getFont("InternalFrame.titleFont")); + selectedTextColor = UIManager.getColor("InternalFrame.activeTitleForeground"); + selectedTitleColor = UIManager.getColor("InternalFrame.activeTitleBackground"); + notSelectedTextColor = UIManager.getColor("InternalFrame.inactiveTitleForeground"); + notSelectedTitleColor = UIManager.getColor("InternalFrame.inactiveTitleBackground"); closeIcon = UIManager.getIcon("InternalFrame.closeIcon"); iconIcon = UIManager.getIcon("InternalFrame.iconifyIcon"); @@ -901,6 +898,9 @@ public class BasicInternalFrameTitlePane extends JComponent */ protected void paintTitleBackground(Graphics g) { + if (!isOpaque()) + return; + Color saved = g.getColor(); Dimension dims = getSize(); diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicListUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicListUI.java index 33932991473..2d66645fb7d 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicListUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicListUI.java @@ -703,12 +703,17 @@ public class BasicListUI extends ListUI */ protected int getRowHeight(int row) { - if (row < 0 || row >= cellHeights.length) - return -1; - else if (cellHeight != -1) - return cellHeight; + int height; + if (cellHeights == null) + height = cellHeight; else - return cellHeights[row]; + { + if (row < 0 || row >= cellHeights.length) + height = -1; + else + height = cellHeights[row]; + } + return height; } /** @@ -803,9 +808,7 @@ public class BasicListUI extends ListUI // If a fixed cell height is set, then we can work more efficient. if (cellHeight > 0) - { - index = Math.max(y0 / cellHeight, index); - } + index = Math.min(y0 / cellHeight, index); // If we have no fixed cell height, we must add up each cell height up // to y0. else @@ -992,8 +995,7 @@ public class BasicListUI extends ListUI */ protected void installKeyboardActions() { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - InputMap focusInputMap = (InputMap)defaults.get("List.focusInputMap"); + InputMap focusInputMap = (InputMap) UIManager.get("List.focusInputMap"); InputMapUIResource parentInputMap = new InputMapUIResource(); // FIXME: The JDK uses a LazyActionMap for parentActionMap ActionMap parentActionMap = new ActionMapUIResource(); diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicLookAndFeel.java b/libjava/classpath/javax/swing/plaf/basic/BasicLookAndFeel.java index 8ebe650350c..13c78add6f8 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicLookAndFeel.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicLookAndFeel.java @@ -1159,7 +1159,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel "Tree.hash", new ColorUIResource(new Color(128, 128, 128)), "Tree.leftChildIndent", new Integer(7), "Tree.rightChildIndent", new Integer(13), - "Tree.rowHeight", new Integer(16), + "Tree.rowHeight", new Integer(0), "Tree.scrollsOnExpand", Boolean.TRUE, "Tree.selectionBackground", new ColorUIResource(Color.black), "Tree.nonSelectionBackground", new ColorUIResource(new Color(255, 255, 255)), diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicMenuItemUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicMenuItemUI.java index 2a3556a5db9..c8754a3e049 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicMenuItemUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicMenuItemUI.java @@ -475,7 +475,6 @@ public class BasicMenuItemUI extends MenuItemUI menuItem.setHorizontalTextPosition(SwingConstants.TRAILING); menuItem.setHorizontalAlignment(SwingConstants.LEADING); - menuItem.setOpaque(true); } /** @@ -553,11 +552,20 @@ public class BasicMenuItemUI extends MenuItemUI */ protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) { - Dimension size = getPreferredSize(menuItem); - Color foreground = g.getColor(); - g.setColor(bgColor); - g.drawRect(0, 0, size.width, size.height); - g.setColor(foreground); + // Menu item is considered to be highlighted when it is selected. + // But we don't want to paint the background of JCheckBoxMenuItems + ButtonModel mod = menuItem.getModel(); + if ((menuItem.isSelected() && checkIcon == null) || (mod != null && + mod.isArmed()) + && (menuItem.getParent() instanceof MenuElement)) + { + if (menuItem.isContentAreaFilled()) + { + g.setColor(selectionBackground); + g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight()); + } + } + } /** @@ -612,28 +620,6 @@ public class BasicMenuItemUI extends MenuItemUI br.width += insets.right + insets.left; br.height += insets.top + insets.bottom; - // Menu item is considered to be highlighted when it is selected. - // But we don't want to paint the background of JCheckBoxMenuItems - ButtonModel mod = m.getModel(); - if ((m.isSelected() && checkIcon == null) || (mod != null && - mod.isArmed()) - && (m.getParent() instanceof MenuElement)) - { - if (m.isContentAreaFilled()) - { - g.setColor(selectionBackground); - g.fillRect(br.x, br.y, br.width, br.height); - } - } - else - { - if (m.isContentAreaFilled()) - { - g.setColor(m.getBackground()); - g.fillRect(br.x, br.y, br.width, br.height); - } - } - // If this menu item is a JCheckBoxMenuItem then paint check icon if (checkIcon != null) { diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicMenuUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicMenuUI.java index 827cbb0f50d..e638b68e1dc 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicMenuUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicMenuUI.java @@ -211,7 +211,6 @@ public class BasicMenuUI extends BasicMenuItemUI selectionForeground = UIManager.getColor("Menu.selectionForeground"); arrowIcon = UIManager.getIcon("Menu.arrowIcon"); oldBorderPainted = UIManager.getBoolean("Menu.borderPainted"); - menuItem.setOpaque(true); } /** diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicProgressBarUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicProgressBarUI.java index 88d949b1caf..d3674664d4c 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicProgressBarUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicProgressBarUI.java @@ -212,6 +212,8 @@ public class BasicProgressBarUI extends ProgressBarUI /** * Holds the value of the bouncing box that is returned by {@link #getBox}. + * + * @since 1.5 */ protected Rectangle boxRect; diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java index f3698e85908..66e53803722 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java @@ -48,7 +48,6 @@ import javax.swing.AbstractButton; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.SwingUtilities; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; @@ -122,8 +121,7 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI */ public Icon getDefaultIcon() { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - return defaults.getIcon(getPropertyPrefix() + "icon"); + return UIManager.getIcon(getPropertyPrefix() + "icon"); } /** diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java index 2f5eaf391e1..a2f5b82dbec 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java @@ -62,7 +62,6 @@ import javax.swing.LookAndFeel; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.Timer; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -501,14 +500,12 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, */ protected void configureScrollBarColors() { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - - trackColor = defaults.getColor("ScrollBar.track"); - trackHighlightColor = defaults.getColor("ScrollBar.trackHighlight"); - thumbColor = defaults.getColor("ScrollBar.thumb"); - thumbHighlightColor = defaults.getColor("ScrollBar.thumbHighlight"); - thumbDarkShadowColor = defaults.getColor("ScrollBar.thumbDarkShadow"); - thumbLightShadowColor = defaults.getColor("ScrollBar.thumbShadow"); + trackColor = UIManager.getColor("ScrollBar.track"); + trackHighlightColor = UIManager.getColor("ScrollBar.trackHighlight"); + thumbColor = UIManager.getColor("ScrollBar.thumb"); + thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight"); + thumbDarkShadowColor = UIManager.getColor("ScrollBar.thumbDarkShadow"); + thumbLightShadowColor = UIManager.getColor("ScrollBar.thumbShadow"); } /** @@ -660,11 +657,7 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, width += decrButton.getPreferredSize().getWidth(); width += (scrollbar.getMaximum() - scrollbar.getMinimum()); - - height = Math.max(incrButton.getPreferredSize().height, - decrButton.getPreferredSize().height); - height = Math.max(getMinimumThumbSize().height, height); - height = Math.min(getMaximumThumbSize().height, height); + height = UIManager.getInt("ScrollBar.width"); } else { @@ -672,11 +665,7 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, height += decrButton.getPreferredSize().getHeight(); height += (scrollbar.getMaximum() - scrollbar.getMinimum()); - - width = Math.max(incrButton.getPreferredSize().width, - decrButton.getPreferredSize().width); - width = Math.max(getMinimumThumbSize().width, width); - width = Math.min(getMaximumThumbSize().width, width); + width = UIManager.getInt("ScrollBar.width"); } Insets insets = scrollbar.getInsets(); diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicSplitPaneUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicSplitPaneUI.java index 746f628df6f..cf31e8b5df1 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicSplitPaneUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicSplitPaneUI.java @@ -126,14 +126,14 @@ public class BasicSplitPaneUI extends SplitPaneUI { int i = 0; if (place == null) - i = 2; + i = 2; else if (place.equals(JSplitPane.TOP) || place.equals(JSplitPane.LEFT)) - i = 0; + i = 0; else if (place.equals(JSplitPane.BOTTOM) || place.equals(JSplitPane.RIGHT)) - i = 1; + i = 1; else - throw new IllegalArgumentException("Illegal placement in JSplitPane"); + throw new IllegalArgumentException("Illegal placement in JSplitPane"); components[i] = component; resetSizeAt(i); splitPane.revalidate(); @@ -164,7 +164,7 @@ public class BasicSplitPaneUI extends SplitPaneUI protected int getInitialLocation(Insets insets) { if (insets != null) - return insets.left; + return insets.left; return 0; } @@ -205,7 +205,7 @@ public class BasicSplitPaneUI extends SplitPaneUI { Dimension dims = c.getPreferredSize(); if (dims != null) - return dims.width; + return dims.width; return 0; } @@ -250,23 +250,23 @@ public class BasicSplitPaneUI extends SplitPaneUI { if (container instanceof JSplitPane) { - JSplitPane split = (JSplitPane) container; - distributeExtraSpace(); - Insets insets = split.getInsets(); - int width = getInitialLocation(insets); - Dimension dims = split.getSize(); - for (int i = 0; i < components.length; i += 2) - { - if (components[i] == null) - continue; - setComponentToSize(components[i], sizes[i], width, insets, dims); - width += sizes[i]; - } - if (components[1] != null) - { - setComponentToSize(components[1], sizes[1], width, insets, dims); - width += sizes[1]; - } + JSplitPane split = (JSplitPane) container; + distributeExtraSpace(); + Insets insets = split.getInsets(); + int width = getInitialLocation(insets); + Dimension dims = split.getSize(); + for (int i = 0; i < components.length; i += 2) + { + if (components[i] == null) + continue; + setComponentToSize(components[i], sizes[i], width, insets, dims); + width += sizes[i]; + } + if (components[1] != null) + { + setComponentToSize(components[1], sizes[1], width, insets, dims); + width += sizes[1]; + } } } @@ -297,23 +297,23 @@ public class BasicSplitPaneUI extends SplitPaneUI { if (target instanceof JSplitPane) { - JSplitPane split = (JSplitPane) target; - Insets insets = target.getInsets(); - - int height = 0; - int width = 0; - for (int i = 0; i < components.length; i++) - { - if (components[i] == null) - continue; - Dimension dims = components[i].getMinimumSize(); - if (dims != null) - { - width += dims.width; - height = Math.max(height, dims.height); - } - } - return new Dimension(width, height); + JSplitPane split = (JSplitPane) target; + Insets insets = target.getInsets(); + + int height = 0; + int width = 0; + for (int i = 0; i < components.length; i++) + { + if (components[i] == null) + continue; + Dimension dims = components[i].getMinimumSize(); + if (dims != null) + { + width += dims.width; + height = Math.max(height, dims.height); + } + } + return new Dimension(width, height); } return null; } @@ -331,24 +331,24 @@ public class BasicSplitPaneUI extends SplitPaneUI { if (target instanceof JSplitPane) { - JSplitPane split = (JSplitPane) target; - Insets insets = target.getInsets(); - - int height = 0; - int width = 0; - for (int i = 0; i < components.length; i++) - { - if (components[i] == null) - continue; - Dimension dims = components[i].getPreferredSize(); - if (dims != null) - { - width += dims.width; - if (! (components[i] instanceof BasicSplitPaneDivider)) - height = Math.max(height, dims.height); - } - } - return new Dimension(width, height); + JSplitPane split = (JSplitPane) target; + Insets insets = target.getInsets(); + + int height = 0; + int width = 0; + for (int i = 0; i < components.length; i++) + { + if (components[i] == null) + continue; + Dimension dims = components[i].getPreferredSize(); + if (dims != null) + { + width += dims.width; + if (!(components[i] instanceof BasicSplitPaneDivider)) + height = Math.max(height, dims.height); + } + } + return new Dimension(width, height); } return null; } @@ -362,11 +362,11 @@ public class BasicSplitPaneUI extends SplitPaneUI { for (int i = 0; i < components.length; i++) { - if (component == components[i]) - { - components[i] = null; - sizes[i] = 0; - } + if (component == components[i]) + { + components[i] = null; + sizes[i] = 0; + } } } @@ -378,7 +378,7 @@ public class BasicSplitPaneUI extends SplitPaneUI protected void resetSizeAt(int index) { if (components[index] != null) - sizes[index] = getPreferredSizeOfComponent(components[index]); + sizes[index] = getPreferredSizeOfComponent(components[index]); } /** @@ -387,7 +387,7 @@ public class BasicSplitPaneUI extends SplitPaneUI public void resetToPreferredSizes() { for (int i = 0; i < components.length; i++) - resetSizeAt(i); + resetSizeAt(i); } /** @@ -433,13 +433,13 @@ public class BasicSplitPaneUI extends SplitPaneUI if (left != null) { - components[0] = left; - resetSizeAt(0); + components[0] = left; + resetSizeAt(0); } if (right != null) { - components[1] = right; - resetSizeAt(1); + components[1] = right; + resetSizeAt(1); } components[2] = divider; resetSizeAt(2); @@ -480,9 +480,9 @@ public class BasicSplitPaneUI extends SplitPaneUI { Dimension dims = components[index].getMinimumSize(); if (dims != null) - return dims.width; + return dims.width; else - return 0; + return 0; } } //end BasicHorizontalLayoutManager @@ -534,7 +534,7 @@ public class BasicSplitPaneUI extends SplitPaneUI { Dimension dims = c.getPreferredSize(); if (dims != null) - return dims.height; + return dims.height; return 0; } @@ -563,23 +563,23 @@ public class BasicSplitPaneUI extends SplitPaneUI { if (container instanceof JSplitPane) { - JSplitPane split = (JSplitPane) container; - Insets insets = container.getInsets(); - - int height = 0; - int width = 0; - for (int i = 0; i < components.length; i++) - { - if (components[i] == null) - continue; - Dimension dims = components[i].getMinimumSize(); - if (dims != null) - { - height += dims.height; - width = Math.max(width, dims.width); - } - } - return new Dimension(width, height); + JSplitPane split = (JSplitPane) container; + Insets insets = container.getInsets(); + + int height = 0; + int width = 0; + for (int i = 0; i < components.length; i++) + { + if (components[i] == null) + continue; + Dimension dims = components[i].getMinimumSize(); + if (dims != null) + { + height += dims.height; + width = Math.max(width, dims.width); + } + } + return new Dimension(width, height); } return null; } @@ -597,23 +597,23 @@ public class BasicSplitPaneUI extends SplitPaneUI { if (container instanceof JSplitPane) { - JSplitPane split = (JSplitPane) container; - Insets insets = container.getInsets(); - - int height = 0; - int width = 0; - for (int i = 0; i < components.length; i++) - { - if (components[i] == null) - continue; - Dimension dims = components[i].getPreferredSize(); - if (dims != null) - { - height += dims.height; - width = Math.max(width, dims.width); - } - } - return new Dimension(width, height); + JSplitPane split = (JSplitPane) container; + Insets insets = container.getInsets(); + + int height = 0; + int width = 0; + for (int i = 0; i < components.length; i++) + { + if (components[i] == null) + continue; + Dimension dims = components[i].getPreferredSize(); + if (dims != null) + { + height += dims.height; + width = Math.max(width, dims.width); + } + } + return new Dimension(width, height); } return null; } @@ -652,9 +652,9 @@ public class BasicSplitPaneUI extends SplitPaneUI { Dimension dims = components[index].getMinimumSize(); if (dims != null) - return dims.height; + return dims.height; else - return 0; + return 0; } } @@ -813,27 +813,27 @@ public class BasicSplitPaneUI extends SplitPaneUI { if (e.getPropertyName().equals(JSplitPane.DIVIDER_SIZE_PROPERTY)) { - int newSize = splitPane.getDividerSize(); - int[] tmpSizes = layoutManager.getSizes(); - dividerSize = tmpSizes[2]; - int newSpace = newSize - tmpSizes[2]; - tmpSizes[2] = newSize; - - tmpSizes[0] += newSpace / 2; - tmpSizes[1] += newSpace / 2; + int newSize = splitPane.getDividerSize(); + int[] tmpSizes = layoutManager.getSizes(); + dividerSize = tmpSizes[2]; + int newSpace = newSize - tmpSizes[2]; + tmpSizes[2] = newSize; + + tmpSizes[0] += newSpace / 2; + tmpSizes[1] += newSpace / 2; - layoutManager.setSizes(tmpSizes); + layoutManager.setSizes(tmpSizes); } else if (e.getPropertyName().equals(JSplitPane.ORIENTATION_PROPERTY)) { - int max = layoutManager.getAvailableSize(splitPane.getSize(), - splitPane.getInsets()); - int dividerLoc = getDividerLocation(splitPane); - double prop = ((double) dividerLoc) / max; - - resetLayoutManager(); - if (prop <= 1 && prop >= 0) - splitPane.setDividerLocation(prop); + int max = layoutManager.getAvailableSize(splitPane.getSize(), + splitPane.getInsets()); + int dividerLoc = getDividerLocation(splitPane); + double prop = ((double) dividerLoc) / max; + + resetLayoutManager(); + if (prop <= 1 && prop >= 0) + splitPane.setDividerLocation(prop); } layoutManager.layoutContainer(splitPane); splitPane.repaint(); @@ -843,13 +843,13 @@ public class BasicSplitPaneUI extends SplitPaneUI // Don't have to deal with resize_weight (as there // will be no extra space associated with this // event - the changes to the weighting will - // be taken into account the next time the + // be taken into account the next time the // sizes change.) - // Don't have to deal with divider_location + // Don't have to deal with divider_location // The method in JSplitPane calls our setDividerLocation // so we'll know about those anyway. // Don't have to deal with last_divider_location - // Although I'm not sure why, it doesn't seem to + // Although I'm not sure why, it doesn't seem to // have any effect on Sun's JSplitPane. // one_touch_expandable changes are dealt with // by our divider. @@ -962,10 +962,10 @@ public class BasicSplitPaneUI extends SplitPaneUI { if (c instanceof JSplitPane) { - splitPane = (JSplitPane) c; - installDefaults(); - installListeners(); - installKeyboardActions(); + splitPane = (JSplitPane) c; + installDefaults(); + installListeners(); + installKeyboardActions(); } } @@ -1218,8 +1218,8 @@ public class BasicSplitPaneUI extends SplitPaneUI { if (nonContinuousLayoutDivider == null) { - nonContinuousLayoutDivider = new Canvas(); - nonContinuousLayoutDivider.setBackground(Color.DARK_GRAY); + nonContinuousLayoutDivider = new Canvas(); + nonContinuousLayoutDivider.setBackground(Color.DARK_GRAY); } return nonContinuousLayoutDivider; } @@ -1300,12 +1300,14 @@ public class BasicSplitPaneUI extends SplitPaneUI { location = validLocation(location); Container p = jc.getParent(); - Dimension rightPrefSize = jc.getRightComponent().getPreferredSize(); + Component right = jc.getRightComponent(); + Dimension rightPrefSize = right == null ? new Dimension(0, 0) + : right.getPreferredSize(); Dimension size = jc.getSize(); // check if the size has been set for the splitpane if (size.width == 0 && size.height == 0) size = jc.getPreferredSize(); - + if (getOrientation() == 0 && location > size.height) { location = size.height; @@ -1324,11 +1326,11 @@ public class BasicSplitPaneUI extends SplitPaneUI p = p.getParent(); } } - + setLastDragLocation(getDividerLocation(splitPane)); splitPane.setLastDividerLocation(getDividerLocation(splitPane)); int[] tmpSizes = layoutManager.getSizes(); - tmpSizes[0] = location + tmpSizes[0] = location - layoutManager.getInitialLocation(splitPane.getInsets()); tmpSizes[1] = layoutManager.getAvailableSize(splitPane.getSize(), splitPane.getInsets()) @@ -1483,19 +1485,21 @@ public class BasicSplitPaneUI extends SplitPaneUI */ protected void startDragging() { + Component left = splitPane.getLeftComponent(); + Component right = splitPane.getRightComponent(); dividerSize = divider.getDividerSize(); setLastDragLocation(-1); - if (! splitPane.getLeftComponent().isLightweight() - || ! splitPane.getRightComponent().isLightweight()) + if ((left != null && !left.isLightweight()) + || (right != null && !right.isLightweight())) draggingHW = true; if (splitPane.isContinuousLayout()) nonContinuousLayoutDivider.setVisible(false); else { - nonContinuousLayoutDivider.setVisible(true); - nonContinuousLayoutDivider.setBounds(divider.getBounds()); + nonContinuousLayoutDivider.setVisible(true); + nonContinuousLayoutDivider.setBounds(divider.getBounds()); } splitPane.revalidate(); splitPane.repaint(); @@ -1518,12 +1522,12 @@ public class BasicSplitPaneUI extends SplitPaneUI splitPane.setDividerLocation(location); else { - Point p = nonContinuousLayoutDivider.getLocation(); - if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) - p.x = location; - else - p.y = location; - nonContinuousLayoutDivider.setLocation(p); + Point p = nonContinuousLayoutDivider.getLocation(); + if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) + p.x = location; + else + p.y = location; + nonContinuousLayoutDivider.setLocation(p); } setLastDragLocation(location); splitPane.repaint(); diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicTableUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicTableUI.java index 25a845b36b8..015443946d7 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicTableUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicTableUI.java @@ -66,7 +66,6 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; import javax.swing.ListSelectionModel; import javax.swing.LookAndFeel; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.event.ChangeEvent; @@ -398,8 +397,7 @@ public class BasicTableUI extends TableUI protected void installKeyboardActions() { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - InputMap ancestorMap = (InputMap)defaults.get("Table.ancestorInputMap"); + InputMap ancestorMap = (InputMap) UIManager.get("Table.ancestorInputMap"); InputMapUIResource parentInputMap = new InputMapUIResource(); // FIXME: The JDK uses a LazyActionMap for parentActionMap ActionMap parentActionMap = new ActionMapUIResource(); diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicTextPaneUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicTextPaneUI.java index decbed56829..a988c5a63c8 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicTextPaneUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicTextPaneUI.java @@ -45,12 +45,9 @@ import javax.swing.JTextPane; import javax.swing.plaf.ColorUIResource; import javax.swing.UIDefaults; import javax.swing.plaf.ComponentUI; -import javax.swing.text.Element; -import javax.swing.text.PlainView; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; -import javax.swing.text.View; public class BasicTextPaneUI extends BasicEditorPaneUI { @@ -64,11 +61,6 @@ public class BasicTextPaneUI extends BasicEditorPaneUI return new BasicTextPaneUI(); } - public View create(Element elem) - { - return new PlainView(elem); - } - /** * Returns the prefix for entries in the {@link UIDefaults} table. * diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java index b9de92640c8..e8eeece3b32 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java @@ -58,7 +58,6 @@ import javax.swing.JComponent; import javax.swing.LookAndFeel; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; @@ -618,13 +617,14 @@ public abstract class BasicTextUI extends TextUI protected Keymap createKeymap() { String prefix = getPropertyPrefix(); - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); JTextComponent.KeyBinding[] bindings = - (JTextComponent.KeyBinding[]) defaults.get(prefix + ".keyBindings"); + (JTextComponent.KeyBinding[]) UIManager.get(prefix + ".keyBindings"); if (bindings == null) { bindings = new JTextComponent.KeyBinding[0]; - defaults.put(prefix + ".keyBindings", bindings); + // FIXME: Putting something into the defaults map is certainly wrong. + // Must be fixed somehow. + UIManager.put(prefix + ".keyBindings", bindings); } Keymap km = JTextComponent.addKeymap(getKeymapName(), @@ -661,17 +661,16 @@ public abstract class BasicTextUI extends TextUI InputMap getInputMap(int condition) { String prefix = getPropertyPrefix(); - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); switch (condition) { case JComponent.WHEN_IN_FOCUSED_WINDOW: // FIXME: is this the right string? nobody seems to use it. - return (InputMap) defaults.get(prefix + ".windowInputMap"); + return (InputMap) UIManager.get(prefix + ".windowInputMap"); case JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT: - return (InputMap) defaults.get(prefix + ".ancestorInputMap"); + return (InputMap) UIManager.get(prefix + ".ancestorInputMap"); default: case JComponent.WHEN_FOCUSED: - return (InputMap) defaults.get(prefix + ".focusInputMap"); + return (InputMap) UIManager.get(prefix + ".focusInputMap"); } } @@ -685,12 +684,14 @@ public abstract class BasicTextUI extends TextUI ActionMap getActionMap() { String prefix = getPropertyPrefix(); - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - ActionMap am = (ActionMap) defaults.get(prefix + ".actionMap"); + ActionMap am = (ActionMap) UIManager.get(prefix + ".actionMap"); if (am == null) { am = createActionMap(); - defaults.put(prefix + ".actionMap", am); + // FIXME: Putting something in the UIDefaults map is certainly wrong. + // However, the whole method seems wrong and must be replaced by + // something that is less wrong. + UIManager.put(prefix + ".actionMap", am); } return am; } diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicToolBarUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicToolBarUI.java index ef4ed835f86..7bf2a4ab167 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicToolBarUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicToolBarUI.java @@ -404,6 +404,8 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants boolean tmp = ((loc == SwingConstants.NORTH) || (loc == SwingConstants.SOUTH) || (loc == -1)); + cachedOrientation = toolBar.getOrientation(); + cachedBounds = toolBar.getSize(); if (((cachedOrientation == SwingConstants.HORIZONTAL) && tmp) || ((cachedOrientation == VERTICAL) && ! tmp)) { @@ -571,9 +573,6 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants dragWindow = createDragWindow(toolBar); - cachedBounds = toolBar.getPreferredSize(); - cachedOrientation = toolBar.getOrientation(); - nonRolloverBorder = createNonRolloverBorder(); rolloverBorder = createRolloverBorder(); diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicTreeUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicTreeUI.java index e967cd424fc..2d54983e61f 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicTreeUI.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicTreeUI.java @@ -81,7 +81,6 @@ import javax.swing.KeyStroke; import javax.swing.LookAndFeel; import javax.swing.SwingUtilities; import javax.swing.Timer; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.event.CellEditorListener; import javax.swing.event.ChangeEvent; @@ -239,14 +238,14 @@ public class BasicTreeUI extends TreeUI /** Boolean to keep track of editing. */ boolean isEditing; - /** The bounds of the current cell. */ - Rectangle bounds; - /** The current path of the visible nodes in the tree. */ TreePath currentVisiblePath; /** The gap between the icon and text. */ int gap = 4; + + /** Default row height, if none was set. */ + int rowHeight = 20; /** Listeners */ private PropertyChangeListener propertyChangeListener; @@ -304,7 +303,7 @@ public class BasicTreeUI extends TreeUI */ protected Color getHashColor() { - return UIManager.getLookAndFeelDefaults().getColor("Tree.hash"); + return UIManager.getColor("Tree.hash"); } /** @@ -315,8 +314,8 @@ public class BasicTreeUI extends TreeUI */ protected void setHashColor(Color color) { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - defaults.put("Tree.hash", color); + // FIXME: Putting something in the UIDefaults map is certainly wrong. + UIManager.put("Tree.hash", color); } /** @@ -437,6 +436,8 @@ public class BasicTreeUI extends TreeUI */ protected void setRowHeight(int rowHeight) { + if (rowHeight == 0) + rowHeight = this.rowHeight; treeState.setRowHeight(rowHeight); } @@ -624,21 +625,19 @@ public class BasicTreeUI extends TreeUI */ public Rectangle getPathBounds(JTree tree, TreePath path) { + Rectangle bounds = null; + int row = -1; + Object cell = null; if (path != null) { - Object cell = path.getLastPathComponent(); - - if (treeModel != null) - { - Object root = treeModel.getRoot(); - - if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root))) - root = getNextNode(root); - Point loc = getCellLocation(0, 0, tree, treeModel, cell, root); - return getCellBounds(loc.x, loc.y, cell); - } + row = getRowForPath(tree, path); + cell = path.getLastPathComponent(); + bounds = new Rectangle(0, row * getRowHeight(), 0, 0); } - return null; + return nodeDimensions.getNodeDimensions(cell, row, + getLevel(cell), + tree.isExpanded(path), + bounds); } /** @@ -700,7 +699,6 @@ public class BasicTreeUI extends TreeUI */ public int getRowCount(JTree tree) { - updateCurrentVisiblePath(); if (currentVisiblePath != null) return currentVisiblePath.getPathCount(); return 0; @@ -1035,7 +1033,9 @@ public class BasicTreeUI extends TreeUI */ protected void uninstallKeyboardActions() { - // TODO: Implement this properly. + action = null; + tree.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).setParent(null); + tree.getActionMap().setParent(null); } /** @@ -1227,7 +1227,7 @@ public class BasicTreeUI extends TreeUI rightChildIndent = UIManager.getInt("Tree.rightChildIndent"); leftChildIndent = UIManager.getInt("Tree.leftChildIndent"); setRowHeight(UIManager.getInt("Tree.rowHeight")); - tree.setRowHeight(UIManager.getInt("Tree.rowHeight")); + tree.setRowHeight(getRowHeight()); tree.requestFocusInWindow(false); tree.setScrollsOnExpand(UIManager.getBoolean("Tree.scrollsOnExpand")); setExpandedIcon(UIManager.getIcon("Tree.expandedIcon")); @@ -1239,8 +1239,7 @@ public class BasicTreeUI extends TreeUI */ protected void installKeyboardActions() { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - InputMap focusInputMap = (InputMap) defaults.get("Tree.focusInputMap"); + InputMap focusInputMap = (InputMap) UIManager.get("Tree.focusInputMap"); InputMapUIResource parentInputMap = new InputMapUIResource(); ActionMap parentActionMap = new ActionMapUIResource(); action = new TreeAction(); @@ -1409,14 +1408,30 @@ public class BasicTreeUI extends TreeUI JTree tree = (JTree) c; if (currentVisiblePath == null) updateCurrentVisiblePath(); - - if (currentVisiblePath != null && treeModel != null) + + Rectangle clip = g.getClipBounds(); + Insets insets = tree.getInsets(); + + if (clip != null && treeModel != null && currentVisiblePath != null) { - Object root = treeModel.getRoot(); - paintRecursive(g, 0, 0, 0, tree, treeModel, root); - - if (hasControlIcons()) - paintControlIcons(g, 0, 0, 0, tree, treeModel, root); + int startIndex = tree.getClosestRowForLocation(clip.x, clip.y); + int endIndex = tree.getClosestRowForLocation(clip.x + clip.width, + clip.y + clip.height); + + paintVerticalPartOfLeg(g, clip, insets, currentVisiblePath); + for (int i = startIndex; i <= endIndex; i++) + { + Object curr = currentVisiblePath.getPathComponent(i); + boolean isLeaf = treeModel.isLeaf(curr); + TreePath path = new TreePath(getPathToRoot(curr, 0)); + + boolean isExpanded = tree.isExpanded(path); + Rectangle bounds = getPathBounds(tree, path); + paintHorizontalPartOfLeg(g, clip, insets, bounds, path, i, + isExpanded, false, isLeaf); + paintRow(g, clip, insets, bounds, path, i, isExpanded, false, + isLeaf); + } } } @@ -1590,7 +1605,7 @@ public class BasicTreeUI extends TreeUI int y; if (event == null) { - bounds = getPathBounds(tree, path); + Rectangle bounds = getPathBounds(tree, path); x = bounds.x; y = bounds.y; } @@ -1670,7 +1685,7 @@ public class BasicTreeUI extends TreeUI if (!isLeaf(row)) { - bounds = getPathBounds(tree, path); + Rectangle bounds = getPathBounds(tree, path); if (hasControlIcons() && (mouseX < bounds.x) && (mouseX > (bounds.x - getCurrentControlIcon(path).getIconWidth() - gap))) @@ -1991,7 +2006,7 @@ public class BasicTreeUI extends TreeUI } /** - * Creats, if necessary, and starts a Timer to check if needed to resize the + * Creates, if necessary, and starts a Timer to check if needed to resize the * bounds */ protected void startTimer() @@ -2227,7 +2242,7 @@ public class BasicTreeUI extends TreeUI if (path != null) { - bounds = getPathBounds(tree, path); + Rectangle bounds = getPathBounds(tree, path); int row = getRowForPath(tree, path); boolean cntlClick = isLocationInExpandControl(path, click.x, click.y); @@ -2268,6 +2283,7 @@ public class BasicTreeUI extends TreeUI handleExpandControlClick(path, click.x, click.y); if (cellEditor != null) cellEditor.cancelCellEditing(); + tree.scrollPathToVisible(path); } else if (tree.isEditable()) startEditing(path, e); @@ -2451,9 +2467,12 @@ public class BasicTreeUI extends TreeUI } /** - * Responsible for getting the size of a particular node. + * Returns, by reference in bounds, the size and x origin to place value at. + * The calling method is responsible for determining the Y location. + * If bounds is null, a newly created Rectangle should be returned, + * otherwise the value should be placed in bounds and returned. * - * @param value + * @param cell * the value to be represented * @param row * row being queried @@ -2465,10 +2484,23 @@ public class BasicTreeUI extends TreeUI * a Rectangle containing the size needed to represent value * @return containing the node dimensions, or null if node has no dimension */ - public Rectangle getNodeDimensions(Object value, int row, int depth, + public Rectangle getNodeDimensions(Object cell, int row, int depth, boolean expanded, Rectangle size) { - return null; + if (size == null || cell == null) + return null; + + String s = cell.toString(); + Font f = tree.getFont(); + FontMetrics fm = tree.getToolkit().getFontMetrics(f); + + if (s != null) + { + size.x = getRowX(row, depth); + size.width = SwingUtilities.computeStringWidth(fm, s); + size.height = fm.getHeight(); + } + return size; } /** @@ -2478,7 +2510,9 @@ public class BasicTreeUI extends TreeUI */ protected int getRowX(int row, int depth) { - return 0; + if (row == 0) + return 0; + return depth * rightChildIndent; } }// NodeDimensionsHandler @@ -3057,241 +3091,6 @@ public class BasicTreeUI extends TreeUI } /** - * Returns the cell bounds for painting selected cells Package private for use - * in inner classes. - * - * @param x - * is the x location of the cell - * @param y - * is the y location of the cell - * @param cell - * is the Object to get the bounds for - * @returns Rectangle that represents the cell bounds - */ - Rectangle getCellBounds(int x, int y, Object cell) - { - if (cell != null) - { - String s = cell.toString(); - Font f = tree.getFont(); - FontMetrics fm = tree.getToolkit().getFontMetrics(f); - - if (s != null) - return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s), - fm.getHeight()); - } - return new Rectangle(x, y, 0, 0); - } - - /** - * Retrieves the location of some node, recursively starting at from some - * node. Package private for use in inner classes. - * - * @param x - * is the starting x position, offset - * @param y - * is the starting y position, offset - * @param tree - * is the tree to traverse - * @param mod - * is the TreeModel to use - * @param node - * is the node to get the location for - * @param startNode - * is the node to start searching from - * @return Point - the location of node - */ - Point getCellLocation(int x, int y, JTree tree, TreeModel mod, Object node, - Object startNode) - { - int rowHeight = getRowHeight(); - if (startNode == null || startNode.equals(node)) - { - int level = getLevel(node); - if (level == 0) - return new Point(x, y); - if (!tree.isRootVisible() && - tree.isExpanded(new TreePath(mod.getRoot()))) - return new Point(x + ((level - 1) * rightChildIndent), y); - return new Point(x + (level * rightChildIndent), y); - } - return getCellLocation(x, y + rowHeight, tree, mod, node, - getNextVisibleNode(startNode)); - } - - /** - * Recursively paints all elements of the tree Package private for use in - * inner classes. - * - * @param g - * the Graphics context in which to paint - * @param indentation - * of the current object - * @param descent - * is the number of elements drawn - * @param depth - * is the depth of the current object in the tree - * @param tree - * is the tree to draw to - * @param mod - * is the TreeModel we are using to draw - * @param curr - * is the current object to draw - * @return int - current descent of the tree - */ - int paintRecursive(Graphics g, int indentation, int descent, - int depth, JTree tree, TreeModel mod, Object curr) - { - Rectangle clip = tree.getVisibleRect(); - if (indentation > clip.x + clip.width + rightChildIndent - || descent > clip.y + clip.height + getRowHeight()) - return descent; - - TreePath path = new TreePath(getPathToRoot(curr, 0)); - int halfHeight = getRowHeight() / 2; - int halfWidth = rightChildIndent / 2; - int y0 = descent + halfHeight; - int heightOfLine = descent + halfHeight; - int row = getRowForPath(tree, path); - boolean isRootVisible = tree.isRootVisible(); - boolean isExpanded = tree.isExpanded(path); - boolean isLeaf = mod.isLeaf(curr); - Rectangle bounds = getPathBounds(tree, path); - Object root = mod.getRoot(); - - if (isLeaf) - { - paintRow(g, clip, null, bounds, path, row, true, false, true); - descent += getRowHeight(); - } - else - { - if (depth > 0 || isRootVisible) - { - paintRow(g, clip, null, bounds, path, row, isExpanded, false, false); - descent += getRowHeight(); - y0 += halfHeight; - } - - if (isExpanded) - { - int max = mod.getChildCount(curr); - for (int i = 0; i < max; i++) - { - Object child = mod.getChild(curr, i); - boolean childVis = tree.isVisible(new TreePath - (getPathToRoot(child, 0))); - int indent = indentation + rightChildIndent; - if (!isRootVisible && depth == 0) - indent = 0; - else if (isRootVisible || - (!isRootVisible && !curr.equals(root)) && childVis) - { - g.setColor(getHashColor()); - heightOfLine = descent + halfHeight; - paintHorizontalLine(g, (JComponent) tree, heightOfLine, - indentation + halfWidth, indentation + rightChildIndent); - } - - descent = paintRecursive(g, indent, descent, depth + 1, - tree, mod, child); - } - } - } - - if (isExpanded) - if (y0 != heightOfLine - && (mod.getChildCount(curr) > 0 && - tree.isVisible(new TreePath(getPathToRoot(mod.getChild - (curr, 0), 0))))) - { - g.setColor(getHashColor()); - paintVerticalLine(g, (JComponent) tree, indentation + halfWidth, y0, - heightOfLine); - } - return descent; - } - - /** - * Recursively paints all the control icons on the tree. Package private for - * use in inner classes. - * - * @param g - * the Graphics context in which to paint - * @param indentation - * of the current object - * @param descent - * is the number of elements drawn - * @param depth - * is the depth of the current object in the tree - * @param tree - * is the tree to draw to - * @param mod - * is the TreeModel we are using to draw - * @param node - * is the current object to draw - * @return int current descent of the tree - */ - int paintControlIcons(Graphics g, int indentation, int descent, - int depth, JTree tree, TreeModel mod, - Object node) - { - int rowHeight = getRowHeight(); - TreePath path = new TreePath(getPathToRoot(node, 0)); - Icon icon = getCurrentControlIcon(path); - - Rectangle clip = tree.getVisibleRect(); - if (indentation > clip.x + clip.width + rightChildIndent - || descent > clip.y + clip.height + getRowHeight()) - return descent; - - if (mod.isLeaf(node)) - descent += rowHeight; - else - { - if (!node.equals(mod.getRoot()) && - (tree.isRootVisible() || getLevel(node) != 1)) - { - int width = icon.getIconWidth(); - int height = icon.getIconHeight() + 2; - int posX = indentation - rightChildIndent; - int posY = descent; - if (width > rightChildIndent) - posX -= gap; - else posX += width/2; - - if (height < rowHeight) - posY += height/2; - - icon.paintIcon(tree, g, posX, posY); - } - - if (depth > 0 || tree.isRootVisible()) - descent += rowHeight; - - if (tree.isExpanded(path)) - { - int max = 0; - if (!mod.isLeaf(node)) - max = mod.getChildCount(node); - - for (int i = 0; i < max; i++) - { - int indent = indentation + rightChildIndent; - Object child = mod.getChild(node, i); - if (depth == 0 && !tree.isRootVisible()) - indent = 1; - if (tree.isVisible(new TreePath(getPathToRoot(child, 0)))) - descent = paintControlIcons(g, indent, descent, depth + 1, - tree, mod, child); - } - } - } - - return descent; - } - - /** * Returns true if the LookAndFeel implements the control icons. Package * private for use in inner classes. * @@ -3376,7 +3175,6 @@ public class BasicTreeUI extends TreeUI */ Object getPreviousVisibleNode(Object node) { - updateCurrentVisiblePath(); if (currentVisiblePath != null) { Object[] nodes = currentVisiblePath.getPath(); @@ -3568,16 +3366,22 @@ public class BasicTreeUI extends TreeUI int getLevel(Object node) { int count = -1; - + Object current = node; - do + if (treeModel != null) { - current = getParent(treeModel.getRoot(), current); - count++; + Object root = treeModel.getRoot(); + if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root))) + count--; + + do + { + current = getParent(root, current); + count++; + } + while (current != null); } - while (current != null); - return count; } @@ -3598,6 +3402,8 @@ public class BasicTreeUI extends TreeUI protected void paintVerticalLine(Graphics g, JComponent c, int x, int top, int bottom) { + // FIXME: Check if drawing a dashed line or not. + g.setColor(getHashColor()); g.drawLine(x, top, x, bottom); } @@ -3618,6 +3424,8 @@ public class BasicTreeUI extends TreeUI protected void paintHorizontalLine(Graphics g, JComponent c, int y, int left, int right) { + // FIXME: Check if drawing a dashed line or not. + g.setColor(getHashColor()); g.drawLine(left, y, right, y); } @@ -3633,14 +3441,19 @@ public class BasicTreeUI extends TreeUI * @param x * is the center position in x-direction * @param y - * is the center position in y-direction FIXME what to do if x < - * (icon.width / 2). Same with y + * is the center position in y-direction */ protected void drawCentered(Component c, Graphics g, Icon icon, int x, int y) { - int beginPositionX = x - icon.getIconWidth() / 2; - int beginPositionY = y - icon.getIconHeight() / 2; - icon.paintIcon(c, g, beginPositionX, beginPositionY); + x -= icon.getIconWidth() / 2; + y -= icon.getIconHeight() / 2; + + if (x < 0) + x = 0; + if (y < 0) + y = 0; + + icon.paintIcon(c, g, x, y); } /** @@ -3653,6 +3466,7 @@ public class BasicTreeUI extends TreeUI */ protected void drawDashedHorizontalLine(Graphics g, int y, int x1, int x2) { + g.setColor(getHashColor()); for (int i = x1; i < x2; i += 2) g.drawLine(i, y, i + 1, y); } @@ -3667,6 +3481,7 @@ public class BasicTreeUI extends TreeUI */ protected void drawDashedVerticalLine(Graphics g, int x, int y1, int y2) { + g.setColor(getHashColor()); for (int i = y1; i < y2; i += 2) g.drawLine(x, i, x, i + 1); } @@ -3691,8 +3506,15 @@ public class BasicTreeUI extends TreeUI boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) { - if (treeModel != null && hasControlIcons()) - paintControlIcons(g, 0, 0, 0, tree, treeModel, path.getLastPathComponent()); + if (shouldPaintExpandControl(path, row, isExpanded, hasBeenExpanded, isLeaf)) + { + Icon icon = getCurrentControlIcon(path); + int iconW = icon.getIconWidth(); + int x = bounds.x - rightChildIndent + iconW/2; + if (x + iconW > bounds.x) + x = bounds.x - rightChildIndent - gap; + icon.paintIcon(tree, g, x, bounds.y + bounds.height/2 - icon.getIconHeight()/2); + } } /** @@ -3703,9 +3525,9 @@ public class BasicTreeUI extends TreeUI * @param g - the graphics configuration * @param clipBounds - * @param insets - - * @param bounds - bounds of expand control - * @param path - path to draw control for - * @param row - row to draw control for + * @param bounds - bounds of the cell + * @param path - path to draw leg for + * @param row - row to start drawing at * @param isExpanded - is the row expanded * @param hasBeenExpanded - has the row already been expanded * @param isLeaf - is the path a leaf @@ -3716,7 +3538,9 @@ public class BasicTreeUI extends TreeUI boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) { - // FIXME: not implemented + if (row != 0) + paintHorizontalLine(g, tree, bounds.y + bounds.height/2, bounds.x - gap - 2, + bounds.x); } /** @@ -3731,7 +3555,24 @@ public class BasicTreeUI extends TreeUI protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path) { - // FIXME: not implemented + int max = tree.getVisibleRowCount(); + for (int i = 0; i < max; i++) + { + Object curr = path.getPathComponent(i); + TreePath currPath = new TreePath(getPathToRoot(curr, 0)); + int numChild = treeModel.getChildCount(curr); + if (numChild > 0 && tree.isExpanded(currPath)) + { + Rectangle bounds = getPathBounds(tree, currPath); + Rectangle lastChildBounds = getPathBounds(tree, + new TreePath(getPathToRoot( + treeModel.getChild(curr, numChild - 1), + 0))); + paintVerticalLine(g, tree, bounds.x + gap + 2, bounds.y + + bounds.height - 2, lastChildBounds.y + + lastChildBounds.height/2); + } + } } /** @@ -3762,7 +3603,12 @@ public class BasicTreeUI extends TreeUI { if (!validCachedPreferredSize) updateCachedPreferredSize(); - bounds.x += gap; + + + paintExpandControl(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf); + + if (row != 0) + bounds.x += gap; bounds.width = preferredSize.width + bounds.x; if (editingComponent != null && editingPath != null && isEditing(tree) @@ -3808,10 +3654,7 @@ public class BasicTreeUI extends TreeUI boolean isLeaf) { Object node = path.getLastPathComponent(); - if (treeModel != null && (!isLeaf && !node.equals(treeModel.getRoot())) && - (tree.isRootVisible() || getLevel(node) != 1)) - return true; - return false; + return (!isLeaf && getLevel(node) != 0 && hasControlIcons()); } /** @@ -3824,24 +3667,28 @@ public class BasicTreeUI extends TreeUI return; Object next = treeModel.getRoot(); - Rectangle bounds = getCellBounds(0, 0, next); - boolean rootVisible = isRootVisible(); + TreePath rootPath = new TreePath(next); + Rectangle bounds = getPathBounds(tree, rootPath); // If root is not a valid size to be visible, or is // not visible and the tree is expanded, then the next node acts // as the root - if ((bounds.width == 0 && bounds.height == 0) || (!rootVisible + if ((bounds.width == 0 && bounds.height == 0) || (!isRootVisible() && tree.isExpanded(new TreePath(next)))) + { next = getNextNode(next); + rootPath = new TreePath(next); + } Object root = next; TreePath current = null; while (next != null) { if (current == null) - current = new TreePath(next); - else - current = current.pathByAddingChild(next); + current = rootPath; + else + current = current.pathByAddingChild(next); + do { TreePath path = new TreePath(getPathToRoot(next, 0)); @@ -3860,7 +3707,7 @@ public class BasicTreeUI extends TreeUI { next = getNextSibling(parent); if (next == null) - parent = getParent(treeModel.getRoot(), next); + parent = getParent(root, parent); } } } @@ -3870,9 +3717,7 @@ public class BasicTreeUI extends TreeUI } currentVisiblePath = current; - if (currentVisiblePath != null) - tree.setVisibleRowCount(currentVisiblePath.getPathCount()); - else tree.setVisibleRowCount(0); + tree.setVisibleRowCount(getRowCount(tree)); if (tree.getSelectionModel() != null && tree.getSelectionCount() == 0 && currentVisiblePath != null) diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalBorders.java b/libjava/classpath/javax/swing/plaf/metal/MetalBorders.java index 4fa3b364056..28143d51ecd 100644 --- a/libjava/classpath/javax/swing/plaf/metal/MetalBorders.java +++ b/libjava/classpath/javax/swing/plaf/metal/MetalBorders.java @@ -56,7 +56,6 @@ import javax.swing.JTextField; import javax.swing.JToggleButton; import javax.swing.JToolBar; import javax.swing.SwingConstants; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.border.AbstractBorder; import javax.swing.border.Border; @@ -131,6 +130,82 @@ public class MetalBorders public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { + // With the OceanTheme the button border is painted entirely different. + // However, I couldn't figure out how this is determined besides checking + // for instanceof OceanTheme. The button painting is definitely not + // influenced by a UI default property and it is definitely performed + // by the same Border class. + if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme) + paintOceanButtonBorder(c, g, x, y, w, h); + else + { + ButtonModel bmodel = null; + + if (c instanceof AbstractButton) + bmodel = ((AbstractButton) c).getModel(); + + Color darkShadow = MetalLookAndFeel.getControlDarkShadow(); + Color shadow = MetalLookAndFeel.getControlShadow(); + Color light = MetalLookAndFeel.getControlHighlight(); + Color middle = MetalLookAndFeel.getControl(); + + if (c.isEnabled()) + { + // draw dark border + g.setColor(darkShadow); + g.drawRect(x, y, w - 2, h - 2); + + if (!bmodel.isPressed()) + { + // draw light border + g.setColor(light); + g.drawRect(x + 1, y + 1, w - 2, h - 2); + + // draw crossing pixels of both borders + g.setColor(middle); + g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); + g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); + } + else + { + // draw light border + g.setColor(light); + g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); + g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); + + // draw shadow border + g.setColor(middle); + g.drawLine(x + 1, y + 1, x + w - 2, y + 1); + g.drawLine(x + 1, y + 1, x + 1, y + h - 2); + + // draw crossing pixels of both borders + g.setColor(shadow); + g.drawRect(x + 1, y + h - 2, 0, 0); + g.drawRect(x + w - 2, y + 1, 0, 0); + } + } + else + { + // draw disabled border + g.setColor(MetalLookAndFeel.getInactiveControlTextColor()); + g.drawRect(x, y, w - 2, h - 2); + } + } + } + + /** + * Paints the button border for the OceanTheme. + * + * @param c the button + * @param g the graphics context + * @param x the X coordinate of the upper left corner of the painting rect + * @param y the Y coordinate of the upper left corner of the painting rect + * @param w the width of the painting rect + * @param h the height of the painting rect + */ + private void paintOceanButtonBorder(Component c, Graphics g, int x, + int y, int w, int h) + { ButtonModel bmodel = null; if (c instanceof AbstractButton) @@ -138,44 +213,31 @@ public class MetalBorders Color darkShadow = MetalLookAndFeel.getControlDarkShadow(); Color shadow = MetalLookAndFeel.getControlShadow(); - Color light = MetalLookAndFeel.getWhite(); + Color light = MetalLookAndFeel.getControlHighlight(); Color middle = MetalLookAndFeel.getControl(); if (c.isEnabled()) - { - // draw dark border - g.setColor(darkShadow); - g.drawRect(x, y, w - 2, h - 2); - - if (!bmodel.isPressed()) - { - // draw light border - g.setColor(light); - g.drawRect(x + 1, y + 1, w - 2, h - 2); - - // draw crossing pixels of both borders - g.setColor(middle); - g.drawRect(x + 1, y + h - 2, 0, 0); - g.drawRect(x + w - 2, y + 1, 0, 0); - } - else - { - // draw light border - g.setColor(light); - g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); - g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); - - // draw shadow border - g.setColor(middle); - g.drawLine(x + 1, y + 1, x + w - 2, y + 1); - g.drawLine(x + 1, y + 1, x + 1, y + h - 2); - - // draw crossing pixels of both borders - g.setColor(shadow); - g.drawRect(x + 1, y + h - 2, 0, 0); - g.drawRect(x + w - 2, y + 1, 0, 0); - } - } + { + if (bmodel.isPressed()) + { + // draw fat border + g.drawLine(x + 1, y + 1, x + w - 2, y + 1); + g.drawLine(x + 1, y + 1, x + 1, y + h - 2); + } + else if (bmodel.isRollover()) + { + g.setColor(shadow); + g.drawRect(x, y, w - 1, h - 1); + g.drawRect(x + 2, y + 2, w - 5, h - 5); + g.setColor(darkShadow); + g.drawRect(x + 1, y + 1, w - 3, h - 3); + } + else + { + g.setColor(darkShadow); + g.drawRect(x, y, w - 1, h - 1); + } + } else { // draw disabled border @@ -654,24 +716,23 @@ public class MetalBorders { JOptionPane pane = (JOptionPane) f.getContentPane(); int type = pane.getMessageType(); - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); if (type == JOptionPane.QUESTION_MESSAGE) { - Color bc = defaults.getColor( + Color bc = UIManager.getColor( "OptionPane.questionDialog.border.background"); if (bc != null) g.setColor(bc); } if (type == JOptionPane.WARNING_MESSAGE) { - Color bc = defaults.getColor( + Color bc = UIManager.getColor( "OptionPane.warningDialog.border.background"); if (bc != null) g.setColor(bc); } else if (type == JOptionPane.ERROR_MESSAGE) { - Color bc = defaults.getColor( + Color bc = UIManager.getColor( "OptionPane.errorDialog.border.background"); if (bc != null) g.setColor(bc); diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalButtonUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalButtonUI.java index 02c39c1499e..10e51117329 100644 --- a/libjava/classpath/javax/swing/plaf/metal/MetalButtonUI.java +++ b/libjava/classpath/javax/swing/plaf/metal/MetalButtonUI.java @@ -47,7 +47,7 @@ import java.awt.Rectangle; import javax.swing.AbstractButton; import javax.swing.JButton; import javax.swing.JComponent; -import javax.swing.UIDefaults; +import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.UIResource; @@ -78,10 +78,9 @@ public class MetalButtonUI public MetalButtonUI() { super(); - UIDefaults def = UIManager.getLookAndFeelDefaults(); - focusColor = def.getColor(getPropertyPrefix() + "focus"); - selectColor = def.getColor(getPropertyPrefix() + "select"); - disabledTextColor = def.getColor(getPropertyPrefix() + "disabledText"); + focusColor = UIManager.getColor(getPropertyPrefix() + "focus"); + selectColor = UIManager.getColor(getPropertyPrefix() + "select"); + disabledTextColor = UIManager.getColor(getPropertyPrefix() + "disabledText"); } /** @@ -135,11 +134,8 @@ public class MetalButtonUI public void installDefaults(AbstractButton button) { super.installDefaults(button); - if (button.isRolloverEnabled()) - { - if (button.getBorder() instanceof UIResource) - button.setBorder(MetalBorders.getRolloverBorder()); - } + button.setRolloverEnabled(UIManager.getBoolean( + getPropertyPrefix() + "rollover")); } /** @@ -148,8 +144,7 @@ public class MetalButtonUI public void uninstallDefaults(AbstractButton button) { super.uninstallDefaults(button); - if (button.getBorder() instanceof UIResource) - button.setBorder(null); + button.setRolloverEnabled(false); } /** @@ -230,4 +225,24 @@ public class MetalButtonUI g.drawString(text, textRect.x, textRect.y + fm.getAscent()); } } + + /** + * If the property <code>Button.gradient</code> is set, then a gradient is + * painted as background, otherwise the normal superclass behaviour is + * called. + */ + public void update(Graphics g, JComponent c) + { + AbstractButton b = (AbstractButton) c; + if (b.isOpaque() && UIManager.get(getPropertyPrefix() + "gradient") != null + && !b.getModel().isPressed() && b.isEnabled()) + { + MetalUtils.paintGradient(g, 0, 0, c.getWidth(), c.getHeight(), + SwingConstants.VERTICAL, + getPropertyPrefix() + "gradient"); + paint(g, c); + } + else + super.update(g, c); + } } diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalCheckBoxIcon.java b/libjava/classpath/javax/swing/plaf/metal/MetalCheckBoxIcon.java index 6b9f31b85b6..fb8280e44da 100644 --- a/libjava/classpath/javax/swing/plaf/metal/MetalCheckBoxIcon.java +++ b/libjava/classpath/javax/swing/plaf/metal/MetalCheckBoxIcon.java @@ -44,6 +44,8 @@ import java.io.Serializable; import javax.swing.Icon; import javax.swing.JCheckBox; +import javax.swing.SwingConstants; +import javax.swing.UIManager; import javax.swing.plaf.UIResource; /** @@ -128,6 +130,9 @@ public class MetalCheckBoxIcon */ public void paintIcon(Component c, Graphics g, int x, int y) { + if (UIManager.get("CheckBox.gradient") != null) + MetalUtils.paintGradient(g, x, y, getIconWidth(), getIconHeight(), + SwingConstants.VERTICAL, "CheckBox.gradient"); border.paintBorder(c, g, x, y, getIconWidth(), getIconHeight()); JCheckBox cb = (JCheckBox) c; if (cb.isSelected()) diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalIconFactory.java b/libjava/classpath/javax/swing/plaf/metal/MetalIconFactory.java index 6f4feccfc37..bcb86e61047 100644 --- a/libjava/classpath/javax/swing/plaf/metal/MetalIconFactory.java +++ b/libjava/classpath/javax/swing/plaf/metal/MetalIconFactory.java @@ -52,6 +52,8 @@ import javax.swing.JInternalFrame; import javax.swing.JRadioButton; import javax.swing.JRadioButtonMenuItem; import javax.swing.JSlider; +import javax.swing.SwingConstants; +import javax.swing.UIManager; import javax.swing.plaf.UIResource; @@ -779,6 +781,10 @@ public class MetalIconFactory implements Serializable */ public void paintIcon(Component c, Graphics g, int x, int y) { + if (UIManager.get("RadioButton.gradient") != null) + MetalUtils.paintGradient(g, x, y, getIconWidth(), getIconHeight(), + SwingConstants.VERTICAL, "RadioButton.gradient"); + Color savedColor = g.getColor(); JRadioButton b = (JRadioButton) c; diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java b/libjava/classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java index 33eb3491ad0..2cf5f67d55d 100644 --- a/libjava/classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java +++ b/libjava/classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java @@ -55,7 +55,6 @@ import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.plaf.basic.BasicInternalFrameTitlePane; @@ -260,9 +259,8 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane notSelectedTextColor = MetalLookAndFeel.getInactiveControlTextColor(); notSelectedTitleColor = MetalLookAndFeel.getWindowTitleInactiveBackground(); - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - paletteTitleHeight = defaults.getInt("InternalFrame.paletteTitleHeight"); - paletteCloseIcon = defaults.getIcon("InternalFrame.paletteCloseIcon"); + paletteTitleHeight = UIManager.getInt("InternalFrame.paletteTitleHeight"); + paletteCloseIcon = UIManager.getIcon("InternalFrame.paletteCloseIcon"); minIcon = MetalIconFactory.getInternalFrameAltMaximizeIcon(16); title = new JLabel(frame.getTitle(), @@ -351,8 +349,14 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane { Color savedColor = g.getColor(); Rectangle b = SwingUtilities.getLocalBounds(this); - g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); - g.fillRect(b.x, b.y, b.width, b.height); + + if (UIManager.get("InternalFrame.activeTitleGradient") != null + && frame.isSelected()) + { + MetalUtils.paintGradient(g, b.x, b.y, b.width, b.height, + SwingConstants.VERTICAL, + "InternalFrame.activeTitleGradient"); + } MetalUtils.fillMetalPattern(this, g, b.x + 4, b.y + 2, b.width - paletteCloseIcon.getIconWidth() - 13, b.height - 5, MetalLookAndFeel.getPrimaryControlHighlight(), @@ -393,6 +397,14 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane g.drawLine(0, d.height - 1, d.width - 1, d.height - 1); // draw the metal pattern + if (UIManager.get("InternalFrame.activeTitleGradient") != null + && frame.isSelected()) + { + MetalUtils.paintGradient(g, 0, 0, getWidth(), getHeight(), + SwingConstants.VERTICAL, + "InternalFrame.activeTitleGradient"); + } + Rectangle b = title.getBounds(); int startX = b.x + b.width + 5; int endX = startX; diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalLabelUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalLabelUI.java index e4eaa71724d..12b858e0a93 100644 --- a/libjava/classpath/javax/swing/plaf/metal/MetalLabelUI.java +++ b/libjava/classpath/javax/swing/plaf/metal/MetalLabelUI.java @@ -43,7 +43,6 @@ import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JLabel; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicGraphicsUtils; @@ -83,22 +82,20 @@ public class MetalLabelUI /** * Draws the text for a disabled label, using the color defined in the - * {@link UIDefaults} with the key <code>Label.disabledForeground</code>. + * {@link UIManager} defaults with the key + * <code>Label.disabledForeground</code>. * * @param l the label. * @param g the graphics device. * @param s the label text. * @param textX the x-coordinate for the label. * @param textY the y-coordinate for the label. - * - * @see UIManager#getLookAndFeelDefaults() */ protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY) { Color savedColor = g.getColor(); - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - g.setColor(defaults.getColor("Label.disabledForeground")); + g.setColor(UIManager.getColor("Label.disabledForeground")); int mnemIndex = l.getDisplayedMnemonicIndex(); if (mnemIndex != -1) BasicGraphicsUtils.drawStringUnderlineCharAt(g, s, mnemIndex, textX, diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java b/libjava/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java index ec8014b17b3..da019379bf5 100644 --- a/libjava/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java +++ b/libjava/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java @@ -693,6 +693,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel "DesktopIconUI", "javax.swing.plaf.metal.MetalDesktopIconUI", "InternalFrameUI", "javax.swing.plaf.metal.MetalInternalFrameUI", "LabelUI", "javax.swing.plaf.metal.MetalLabelUI", + "MenuBarUI", "javax.swing.plaf.metal.MetalMenuBarUI", "PopupMenuSeparatorUI", "javax.swing.plaf.metal.MetalPopupMenuSeparatorUI", "ProgressBarUI", "javax.swing.plaf.metal.MetalProgressBarUI", @@ -1162,7 +1163,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel "Tree.line", getPrimaryControl(), "Tree.openIcon", MetalIconFactory.getTreeFolderIcon(), "Tree.rightChildIndent", new Integer(13), - "Tree.rowHeight", new Integer(20), + "Tree.rowHeight", new Integer(0), "Tree.scrollsOnExpand", Boolean.TRUE, "Tree.selectionBackground", getTextHighlightColor(), "Tree.selectionBorder", new BorderUIResource.LineBorderUIResource(new Color(102, 102, 153)), @@ -1201,4 +1202,13 @@ public class MetalLookAndFeel extends BasicLookAndFeel defaults.putDefaults(uiDefaults); } + /** + * Returns the current theme setting for the Metal L&F. + * + * @return the current theme setting for the Metal L&F + */ + public static MetalTheme getCurrentTheme() + { + return theme; + } } diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalMenuBarUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalMenuBarUI.java new file mode 100644 index 00000000000..31d8d671fa1 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/metal/MetalMenuBarUI.java @@ -0,0 +1,88 @@ +/* MetalMenuBarUI.java -- MenuBar UI for the Metal L&F + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.plaf.metal; + +import java.awt.Graphics; + +import javax.swing.JComponent; +import javax.swing.SwingConstants; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicMenuBarUI; + +/** + * A UI implementation for MenuBar in the Metal Look & Feel. + * + * @author Roman Kennke (kennke@aicas.com) + * + * @since 1.5 + */ +public class MetalMenuBarUI extends BasicMenuBarUI +{ + /** + * Creates and returns a new instance of this UI for the specified component. + * + * @param c the component to create a UI for + * + * @return the UI for the component + */ + public static ComponentUI createUI(JComponent c) + { + return new MetalMenuBarUI(); + } + + + /** + * If the property <code>MenuBar.gradient</code> is set, then a gradient + * is painted as background, otherwise the normal superclass behaviour is + * called. + */ + public void update(Graphics g, JComponent c) + { + if (c.isOpaque() && UIManager.get("MenuBar.gradient") != null) + { + MetalUtils.paintGradient(g, 0, 0, c.getWidth(), c.getHeight(), + SwingConstants.VERTICAL, "MenuBar.gradient"); + paint(g, c); + } + else + super.update(g, c); + } + +} diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalRadioButtonUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalRadioButtonUI.java index f37626e630f..de71fe8e5b2 100644 --- a/libjava/classpath/javax/swing/plaf/metal/MetalRadioButtonUI.java +++ b/libjava/classpath/javax/swing/plaf/metal/MetalRadioButtonUI.java @@ -46,7 +46,6 @@ import java.awt.Rectangle; import javax.swing.AbstractButton; import javax.swing.JComponent; import javax.swing.JRadioButton; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicRadioButtonUI; @@ -96,10 +95,9 @@ public class MetalRadioButtonUI public void installDefaults(AbstractButton b) { super.installDefaults(b); - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - disabledTextColor = defaults.getColor("RadioButton.disabledText"); - focusColor = defaults.getColor("RadioButton.focus"); - selectColor = defaults.getColor("RadioButton.select"); + disabledTextColor = UIManager.getColor("RadioButton.disabledText"); + focusColor = UIManager.getColor("RadioButton.focus"); + selectColor = UIManager.getColor("RadioButton.select"); } /** @@ -118,7 +116,7 @@ public class MetalRadioButtonUI /** * Returns the color used to fill the {@link JRadioButton}'s icon when the * button is pressed. The default color is obtained from the - * {@link UIDefaults} via an entry with the key + * {@link UIManager} defaults via an entry with the key * <code>RadioButton.select</code>. * * @return The select color. @@ -130,8 +128,8 @@ public class MetalRadioButtonUI /** * Returns the color for the {@link JRadioButton}'s text when the button is - * disabled. The default color is obtained from the {@link UIDefaults} via - * an entry with the key <code>RadioButton.disabledText</code>. + * disabled. The default color is obtained from the {@link UIManager} + * defaults via an entry with the key <code>RadioButton.disabledText</code>. * * @return The disabled text color. */ @@ -143,7 +141,7 @@ public class MetalRadioButtonUI /** * Returns the color used to draw the focus rectangle when the * {@link JRadioButton} has the focus. The default color is obtained from - * the {@link UIDefaults} via an entry with the key + * the {@link UIManager} defaults via an entry with the key * <code>RadioButton.focus</code>. * * @return The color used to draw the focus rectangle. diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalScrollBarUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalScrollBarUI.java index 9602ade9947..0ff501f89a9 100644 --- a/libjava/classpath/javax/swing/plaf/metal/MetalScrollBarUI.java +++ b/libjava/classpath/javax/swing/plaf/metal/MetalScrollBarUI.java @@ -48,7 +48,6 @@ import java.beans.PropertyChangeListener; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JScrollBar; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicScrollBarUI; @@ -195,8 +194,7 @@ public class MetalScrollBarUI extends BasicScrollBarUI */ protected JButton createDecreaseButton(int orientation) { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - scrollBarWidth = defaults.getInt("ScrollBar.width"); + scrollBarWidth = UIManager.getInt("ScrollBar.width"); decreaseButton = new MetalScrollButton(orientation, scrollBarWidth, isFreeStanding); return decreaseButton; @@ -213,8 +211,7 @@ public class MetalScrollBarUI extends BasicScrollBarUI */ protected JButton createIncreaseButton(int orientation) { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - scrollBarWidth = defaults.getInt("ScrollBar.width"); + scrollBarWidth = UIManager.getInt("ScrollBar.width"); increaseButton = new MetalScrollButton(orientation, scrollBarWidth, isFreeStanding); return increaseButton; @@ -403,8 +400,7 @@ public class MetalScrollBarUI extends BasicScrollBarUI } // draw the shadow line - UIDefaults def = UIManager.getLookAndFeelDefaults(); - g.setColor(def.getColor("ScrollBar.shadow")); + g.setColor(UIManager.getColor("ScrollBar.shadow")); g.drawLine(x + w, y + 1, x + w, y + h - 1); } @@ -456,8 +452,7 @@ public class MetalScrollBarUI extends BasicScrollBarUI } // draw the shadow line - UIDefaults def = UIManager.getLookAndFeelDefaults(); - g.setColor(def.getColor("ScrollBar.shadow")); + g.setColor(UIManager.getColor("ScrollBar.shadow")); g.drawLine(x + 1, y + h, x + w - 2, y + h); } diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalSplitPaneUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalSplitPaneUI.java index b39fb23366e..dbcc0910d46 100644 --- a/libjava/classpath/javax/swing/plaf/metal/MetalSplitPaneUI.java +++ b/libjava/classpath/javax/swing/plaf/metal/MetalSplitPaneUI.java @@ -42,7 +42,6 @@ import java.awt.Color; import javax.swing.JComponent; import javax.swing.JSplitPane; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicSplitPaneDivider; @@ -83,9 +82,8 @@ public class MetalSplitPaneUI extends BasicSplitPaneUI */ public BasicSplitPaneDivider createDefaultDivider() { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - Color light = defaults.getColor("SplitPane.highlight"); - Color dark = defaults.getColor("SplitPane.darkShadow"); + Color light = UIManager.getColor("SplitPane.highlight"); + Color dark = UIManager.getColor("SplitPane.darkShadow"); return new MetalSplitPaneDivider(this, light, dark); } } diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalToggleButtonUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalToggleButtonUI.java index 46a19bdbe9e..0b56d591442 100644 --- a/libjava/classpath/javax/swing/plaf/metal/MetalToggleButtonUI.java +++ b/libjava/classpath/javax/swing/plaf/metal/MetalToggleButtonUI.java @@ -47,8 +47,8 @@ import java.awt.Rectangle; import javax.swing.AbstractButton; import javax.swing.JComponent; import javax.swing.JToggleButton; +import javax.swing.SwingConstants; import javax.swing.SwingUtilities; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicButtonUI; @@ -131,10 +131,9 @@ public class MetalToggleButtonUI public void installDefaults(AbstractButton b) { super.installDefaults(b); - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - focusColor = defaults.getColor(getPropertyPrefix() + "focus"); - selectColor = defaults.getColor(getPropertyPrefix() + "select"); - disabledTextColor = defaults.getColor(getPropertyPrefix() + "disabledText"); + focusColor = UIManager.getColor(getPropertyPrefix() + "focus"); + selectColor = UIManager.getColor(getPropertyPrefix() + "select"); + disabledTextColor = UIManager.getColor(getPropertyPrefix() + "disabledText"); } /** @@ -200,5 +199,23 @@ public class MetalToggleButtonUI g.drawRect(fr.x - 1, fr.y - 1, fr.width + 1, fr.height + 1); g.setColor(saved); } + + /** + * If the property <code>ToggleButton.gradient</code> is set, then a gradient + * is painted as background, otherwise the normal superclass behaviour is + * called. + */ + public void update(Graphics g, JComponent c) + { + if (c.isOpaque() && UIManager.get(getPropertyPrefix() + "gradient") != null) + { + MetalUtils.paintGradient(g, 0, 0, c.getWidth(), c.getHeight(), + SwingConstants.VERTICAL, + getPropertyPrefix() + "gradient"); + paint(g, c); + } + else + super.update(g, c); + } } diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalToolTipUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalToolTipUI.java index 5085d170ac2..f183ed5a149 100644 --- a/libjava/classpath/javax/swing/plaf/metal/MetalToolTipUI.java +++ b/libjava/classpath/javax/swing/plaf/metal/MetalToolTipUI.java @@ -56,7 +56,6 @@ import javax.swing.JToolTip; import javax.swing.KeyStroke; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.plaf.ComponentUI; @@ -107,13 +106,12 @@ public class MetalToolTipUI public MetalToolTipUI() { super(); - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - activeBorder = defaults.getBorder("ToolTip.border"); - inactiveBorder = defaults.getBorder("ToolTip.borderInactive"); - isAcceleratorHidden = defaults.getBoolean("ToolTip.hideAccelerator"); - acceleratorFont = defaults.getFont("MenuItem.acceleratorFont"); - acceleratorForeground = defaults.getColor("MenuItem.acceleratorForeground"); - acceleratorDelimiter = defaults.getString("MenuItem.acceleratorDelimiter"); + activeBorder = UIManager.getBorder("ToolTip.border"); + inactiveBorder = UIManager.getBorder("ToolTip.borderInactive"); + isAcceleratorHidden = UIManager.getBoolean("ToolTip.hideAccelerator"); + acceleratorFont = UIManager.getFont("MenuItem.acceleratorFont"); + acceleratorForeground = UIManager.getColor("MenuItem.acceleratorForeground"); + acceleratorDelimiter = UIManager.getString("MenuItem.acceleratorDelimiter"); } /** diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalTreeUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalTreeUI.java index 0ffa0d17470..24432a2b5f6 100644 --- a/libjava/classpath/javax/swing/plaf/metal/MetalTreeUI.java +++ b/libjava/classpath/javax/swing/plaf/metal/MetalTreeUI.java @@ -41,24 +41,10 @@ package javax.swing.plaf.metal; import java.awt.Graphics; import java.awt.Insets; import java.awt.Rectangle; -import java.awt.event.ComponentListener; -import java.awt.event.FocusListener; -import java.awt.event.KeyListener; -import java.awt.event.MouseListener; -import java.beans.PropertyChangeListener; -import java.util.Hashtable; import javax.swing.JComponent; import javax.swing.JTree; -import javax.swing.UIDefaults; -import javax.swing.UIManager; -import javax.swing.tree.TreeCellEditor; -import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; -import javax.swing.event.CellEditorListener; -import javax.swing.event.TreeExpansionListener; -import javax.swing.event.TreeModelListener; -import javax.swing.event.TreeSelectionListener; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicTreeUI; @@ -67,19 +53,6 @@ import javax.swing.plaf.basic.BasicTreeUI; */ public class MetalTreeUI extends BasicTreeUI { - - /** Listeners */ - private PropertyChangeListener propertyChangeListener; - private FocusListener focusListener; - private TreeSelectionListener treeSelectionListener; - private MouseListener mouseListener; - private KeyListener keyListener; - private PropertyChangeListener selectionModelPropertyChangeListener; - private ComponentListener componentListener; - private CellEditorListener cellEditorListener; - private TreeExpansionListener treeExpansionListener; - private TreeModelListener treeModelListener; - /** * Constructs a new instance of <code>MetalTreeUI</code>. */ @@ -128,71 +101,8 @@ public class MetalTreeUI extends BasicTreeUI */ public void installUI(JComponent c) { - tree = (JTree) c; - configureLayoutCache(); - - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - tree.setFont(defaults.getFont("Tree.font")); - tree.setForeground(defaults.getColor("Tree.foreground")); - tree.setBackground(defaults.getColor("Tree.background")); - tree.setOpaque(true); - tree.setScrollsOnExpand(defaults.getBoolean("Tree.scrollsOnExpand")); - rightChildIndent = defaults.getInt("Tree.rightChildIndent"); - leftChildIndent = defaults.getInt("Tree.leftChildIndent"); - setRowHeight(defaults.getInt("Tree.rowHeight")); - tree.setRowHeight(defaults.getInt("Tree.rowHeight")); - tree.requestFocusInWindow(false); - - setExpandedIcon(defaults.getIcon("Tree.expandedIcon")); - setCollapsedIcon(defaults.getIcon("Tree.collapsedIcon")); - - currentCellRenderer = createDefaultCellRenderer(); - rendererPane = createCellRendererPane(); - createdRenderer = true; - setCellEditor(createDefaultCellEditor()); - createdCellEditor = true; - TreeModel mod = tree.getModel(); - setModel(mod); - - treeSelectionModel = tree.getSelectionModel(); - drawingCache = new Hashtable(); - nodeDimensions = createNodeDimensions(); - - propertyChangeListener = createPropertyChangeListener(); - focusListener = createFocusListener(); - treeSelectionListener = createTreeSelectionListener(); - mouseListener = createMouseListener(); - keyListener = createKeyListener(); - selectionModelPropertyChangeListener = createSelectionModelPropertyChangeListener(); - componentListener = createComponentListener(); - cellEditorListener = createCellEditorListener(); - treeExpansionListener = createTreeExpansionListener(); - treeModelListener = createTreeModelListener(); - - editingRow = -1; - lastSelectedRow = -1; - - installKeyboardActions(); - - tree.addPropertyChangeListener(propertyChangeListener); - tree.addFocusListener(focusListener); - tree.addTreeSelectionListener(treeSelectionListener); - tree.addMouseListener(mouseListener); - tree.addKeyListener(keyListener); - tree.addPropertyChangeListener(selectionModelPropertyChangeListener); - tree.addComponentListener(componentListener); - tree.addTreeExpansionListener(treeExpansionListener); - if (treeModel != null) - treeModel.addTreeModelListener(treeModelListener); - - if (mod != null) - { - TreePath path = new TreePath(mod.getRoot()); - if (!tree.isExpanded(path)) - toggleExpandState(path); - } - - completeUIInstall(); + // TODO: What to do here, if anything? + super.installUI(c); } /** @@ -212,31 +122,8 @@ public class MetalTreeUI extends BasicTreeUI */ public void uninstallUI(JComponent c) { - tree.setFont(null); - tree.setForeground(null); - tree.setBackground(null); - - uninstallKeyboardActions(); - - tree.removePropertyChangeListener(propertyChangeListener); - tree.removeFocusListener(focusListener); - tree.removeTreeSelectionListener(treeSelectionListener); - tree.removeMouseListener(mouseListener); - tree.removeKeyListener(keyListener); - tree.removePropertyChangeListener(selectionModelPropertyChangeListener); - tree.removeComponentListener(componentListener); - tree.removeTreeExpansionListener(treeExpansionListener); - - TreeCellEditor tce = tree.getCellEditor(); - if (tce != null) - tce.removeCellEditorListener(cellEditorListener); - TreeModel tm = tree.getModel(); - if (tm != null) - tm.removeTreeModelListener(treeModelListener); - - tree = null; - uninstallComponents(); - completeUIUninstall(); + // TODO: What to do here? + super.uninstallUI(c); } /** diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalUtils.java b/libjava/classpath/javax/swing/plaf/metal/MetalUtils.java index c0b4e657676..50112ce2161 100644 --- a/libjava/classpath/javax/swing/plaf/metal/MetalUtils.java +++ b/libjava/classpath/javax/swing/plaf/metal/MetalUtils.java @@ -44,6 +44,10 @@ import java.awt.Graphics2D; import java.awt.TexturePaint; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; +import java.util.List; + +import javax.swing.SwingConstants; +import javax.swing.UIManager; /** * Some utility and helper methods for the Metal Look & Feel. @@ -151,4 +155,252 @@ class MetalUtils g.fillRect(3, 3, 1, 1); g.dispose(); } + + /** + * Paints the typical Metal gradient. See {@link #paintGradient(Graphics, + * int, int, int, int, double, double, Color, Color, Color, int)} + * for more details. + * + * The parameters are fetched from the UIManager using the key + * <code>uiProp</code>. The value is expected to be a {@link List} that + * contains 4 values: two {@link Double}s and 3 {@link Color} object that + * together make up the parameters passed to the painting method. + * + * @param g the graphics context to use + * @param x the X coordinate of the upper left corner of the rectangle + * @param y the Y coordinate of the upper left corner of the rectangle + * @param w the width of the rectangle + * @param h the height of the rectangle + * @param dir the direction of the gradient, either + * @param uiProp the key of the UIManager property that has the parameters + */ + static void paintGradient(Graphics g, int x, int y, int w, int h, + int dir, String uiProp) + { + List params = (List) UIManager.get(uiProp); + double g1 = ((Double) params.get(0)).doubleValue(); + double g2 = ((Double) params.get(1)).doubleValue(); + Color c1 = (Color) params.get(2); + Color c2 = (Color) params.get(3); + Color c3 = (Color) params.get(4); + paintGradient(g, x, y, w, h, g1, g2, c1, c2, c3, dir); + } + + /** + * Paints the typical Metal gradient. The gradient is painted as follows: + * <pre> + * + * +-------+--------+--------+-----------------------------+ + * | | | | | + * +-------+--------+--------+-----------------------------+ + * c1 -> c2 -- c2 -> c1 --------> c3 + * < -g1- > < -g2- > < -g1- > + * </pre> + * + * There are 4 distinct areas in this gradient: + * <ol> + * <li>A gradient from color 1 to color 2 with the relative width specified + * by <code>g1</code></li> + * <li>A solid area with the color 2 and the relative width specified by + * <code>g2</code></li> + * <li>A gradient from color 2 to color 1 with the relative width specified + * by <code>g1</code></li> + * + * @param g the graphics context to use + * @param x the X coordinate of the upper left corner of the rectangle + * @param y the Y coordinate of the upper left corner of the rectangle + * @param w the width of the rectangle + * @param h the height of the rectangle + * @param g1 the relative width of the c1->c2 gradients + * @param g2 the relative width of the c2 solid area + * @param c1 the color 1 + * @param c2 the color 2 + * @param c3 the color 3 + * @param dir the direction of the gradient, either + * {@link SwingConstants#HORIZONTAL} or {@link SwingConstants#VERTICAL} + */ + static void paintGradient(Graphics g, int x, int y, int w, int h, double g1, + double g2, Color c1, Color c2, Color c3, int dir) + { + if (dir == SwingConstants.HORIZONTAL) + paintHorizontalGradient(g, x, y, w, h, g1, g2, c1, c2, c3); + else + paintVerticalGradient(g, x, y, w, h, g1, g2, c1, c2, c3); + } + + /** + * Paints a horizontal gradient. See {@link #paintGradient(Graphics, int, + * int, int, int, double, double, Color, Color, Color, int)} for details. + * + * @param x the X coordinate of the upper left corner of the rectangle + * @param y the Y coordinate of the upper left corner of the rectangle + * @param w the width of the rectangle + * @param h the height of the rectangle + * @param g1 the relative width of the c1->c2 gradients + * @param g2 the relative width of the c2 solid area + * @param c1 the color 1 + * @param c2 the color 2 + * @param c3 the color 3 + */ + static void paintHorizontalGradient(Graphics g, int x, int y, int w, int h, + double g1, double g2, Color c1, Color c2, + Color c3) + { + // Calculate the coordinates. + // The size of the first gradient area (c1->2). + int w1 = (int) (w * g1); + // The size of the solid c2 area. + int w2 = (int) (w * g2); + int x0 = x; + int x1 = x0 + w1; + int x2 = x1 + w2; + int x3 = x2 + w1; + int x4 = x + w; + + // Paint first gradient area (c1->c2). + int xc; // The current y coordinate. + for (xc = x0; xc < x1; xc++) + { + if (xc > x + w) + break; + + // Perform color interpolation; + double factor = (xc - x0) / (double) w1; + int rInt = (int) ((c2.getRed() - c1.getRed()) * factor + c1.getRed()); + int gInt = (int) ((c2.getGreen() - c1.getGreen()) * factor + + c1.getGreen()); + int bInt = (int) ((c2.getBlue() - c1.getBlue()) * factor + + c1.getBlue()); + Color interpolated = new Color(rInt, gInt, bInt); + g.setColor(interpolated); + g.drawLine(xc, y, xc, y + h); + } + // Paint solid c2 area. + g.setColor(c2); + g.fillRect(x1, y, x2 - x1, h); + + // Paint second gradient area (c2->c1). + for (xc = x2; xc < x3; xc++) + { + if (xc > x + w) + break; + + // Perform color interpolation; + double factor = (xc - x2) / (double) w1; + int rInt = (int) ((c1.getRed() - c2.getRed()) * factor + c2.getRed()); + int gInt = (int) ((c1.getGreen() - c2.getGreen()) * factor + + c2.getGreen()); + int bInt = (int) ((c1.getBlue() - c2.getBlue()) * factor + + c2.getBlue()); + Color interpolated = new Color(rInt, gInt, bInt); + g.setColor(interpolated); + g.drawLine(xc, y, xc, y + h); + } + + // Paint third gradient area (c1->c3). + for (xc = x3; xc < x4; xc++) + { + if (xc > x + w) + break; + + // Perform color interpolation; + double factor = (xc - x3) / (double) (x4 - x3); + int rInt = (int) ((c3.getRed() - c1.getRed()) * factor + c1.getRed()); + int gInt = (int) ((c3.getGreen() - c1.getGreen()) * factor + + c1.getGreen()); + int bInt = (int) ((c3.getBlue() - c1.getBlue()) * factor + + c1.getBlue()); + Color interpolated = new Color(rInt, gInt, bInt); + g.setColor(interpolated); + g.drawLine(xc, y, xc, y + h); + } + } + + /** + * Paints a vertical gradient. See {@link #paintGradient(Graphics, int, int, + * int, int, double, double, Color, Color, Color, int)} for details. + * + * @param x the X coordinate of the upper left corner of the rectangle + * @param y the Y coordinate of the upper left corner of the rectangle + * @param w the width of the rectangle + * @param h the height of the rectangle + * @param g1 the relative width of the c1->c2 gradients + * @param g2 the relative width of the c2 solid area + * @param c1 the color 1 + * @param c2 the color 2 + * @param c3 the color 3 + */ + static void paintVerticalGradient(Graphics g, int x, int y, int w, int h, + double g1, double g2, Color c1, Color c2, + Color c3) + { + // Calculate the coordinates. + // The size of the first gradient area (c1->2). + int w1 = (int) (h * g1); + // The size of the solid c2 area. + int w2 = (int) (h * g2); + int y0 = y; + int y1 = y0 + w1; + int y2 = y1 + w2; + int y3 = y2 + w1; + int y4 = y + h; + + // Paint first gradient area (c1->c2). + int yc; // The current y coordinate. + for (yc = y0; yc < y1; yc++) + { + if (yc > y + h) + break; + + // Perform color interpolation; + double factor = (yc - y0) / (double) w1; + int rInt = (int) ((c2.getRed() - c1.getRed()) * factor + c1.getRed()); + int gInt = (int) ((c2.getGreen() - c1.getGreen()) * factor + + c1.getGreen()); + int bInt = (int) ((c2.getBlue() - c1.getBlue()) * factor + + c1.getBlue()); + Color interpolated = new Color(rInt, gInt, bInt); + g.setColor(interpolated); + g.drawLine(x, yc, x + w, yc); + } + // Paint solid c2 area. + g.setColor(c2); + g.fillRect(x, y1, w, y2 - y1); + + // Paint second gradient area (c2->c1). + for (yc = y2; yc < y3; yc++) + { + if (yc > y + h) + break; + + // Perform color interpolation; + double factor = (yc - y2) / (double) w1; + int rInt = (int) ((c1.getRed() - c2.getRed()) * factor + c2.getRed()); + int gInt = (int) ((c1.getGreen() - c2.getGreen()) * factor + + c2.getGreen()); + int bInt = (int) ((c1.getBlue() - c2.getBlue()) * factor + + c2.getBlue()); + Color interpolated = new Color(rInt, gInt, bInt); + g.setColor(interpolated); + g.drawLine(x, yc, x + w, yc); + } + + // Paint third gradient area (c1->c3). + for (yc = y3; yc < y4; yc++) + { + if (yc > y + h) + break; + + // Perform color interpolation; + double factor = (yc - y3) / (double) (y4 - y3); + int rInt = (int) ((c3.getRed() - c1.getRed()) * factor + c1.getRed()); + int gInt = (int) ((c3.getGreen() - c1.getGreen()) * factor + + c1.getGreen()); + int bInt = (int) ((c3.getBlue() - c1.getBlue()) * factor + + c1.getBlue()); + Color interpolated = new Color(rInt, gInt, bInt); + g.setColor(interpolated); + g.drawLine(x, yc, x + w, yc); + } + } } diff --git a/libjava/classpath/javax/swing/plaf/metal/OceanTheme.java b/libjava/classpath/javax/swing/plaf/metal/OceanTheme.java index 85a8cb1ff86..f1886b167cf 100644 --- a/libjava/classpath/javax/swing/plaf/metal/OceanTheme.java +++ b/libjava/classpath/javax/swing/plaf/metal/OceanTheme.java @@ -37,6 +37,9 @@ exception statement from your version. */ package javax.swing.plaf.metal; +import java.awt.Color; +import java.util.Arrays; + import javax.swing.UIDefaults; import javax.swing.plaf.ColorUIResource; @@ -204,6 +207,37 @@ public class OceanTheme extends DefaultMetalTheme */ public void addCustomEntriesToTable(UIDefaults defaults) { + defaults.put("Button.gradient", Arrays.asList(new Object[] + {new Double(0.3), new Double(0.0), new ColorUIResource(221, 232, 243), + new ColorUIResource(Color.WHITE), new ColorUIResource(184, 207, 229)})); + defaults.put("CheckBox.gradient", Arrays.asList(new Object[] + {new Double(0.3), new Double(0.0), new ColorUIResource(221, 232, 243), + new ColorUIResource(Color.WHITE), new ColorUIResource(184, 207, 229)})); + defaults.put("CheckBoxMenuItem.gradient", Arrays.asList(new Object[] + {new Double(0.3), new Double(0.0), new ColorUIResource(221, 232, 243), + new ColorUIResource(Color.WHITE), new ColorUIResource(184, 207, 229)})); + defaults.put("MenuBar.gradient", Arrays.asList(new Object[] + {new Double(1.0), new Double(0.0), new ColorUIResource(Color.WHITE), + new ColorUIResource(218, 218, 218), new ColorUIResource(218, 218, 218)})); + defaults.put("RadioButton.gradient", Arrays.asList(new Object[] + {new Double(0.3), new Double(0.0), new ColorUIResource(221, 232, 243), + new ColorUIResource(Color.WHITE), new ColorUIResource(184, 207, 229)})); + defaults.put("RadioButtonMenuItem.gradient", Arrays.asList(new Object[] + {new Double(0.3), new Double(0.0), new ColorUIResource(221, 232, 243), + new ColorUIResource(Color.WHITE), new ColorUIResource(184, 207, 229)})); + defaults.put("ScrollBar.gradient", Arrays.asList(new Object[] + {new Double(1.0), new Double(0.0), new ColorUIResource(Color.WHITE), + new ColorUIResource(218, 218, 218), new ColorUIResource(218, 218, 218)})); + defaults.put("Slider.gradient", Arrays.asList(new Object[] + {new Double(0.3), new Double(0.2), new ColorUIResource(200, 221, 242), + new ColorUIResource(Color.WHITE), new ColorUIResource(184, 207, 229)})); + defaults.put("ToggleButton.gradient", Arrays.asList(new Object[] + {new Double(0.3), new Double(0.0), new ColorUIResource(221, 232, 243), + new ColorUIResource(Color.WHITE), new ColorUIResource(184, 207, 229)})); + defaults.put("InternalFrame.activeTitleGradient", Arrays.asList(new Object[] + {new Double(0.3), new Double(0.0), new ColorUIResource(221, 232, 243), + new ColorUIResource(Color.WHITE), new ColorUIResource(184, 207, 229)})); + defaults.put("Button.rollover", Boolean.TRUE); } } diff --git a/libjava/classpath/javax/swing/text/AbstractDocument.java b/libjava/classpath/javax/swing/text/AbstractDocument.java index baf8608b888..a324425562e 100644 --- a/libjava/classpath/javax/swing/text/AbstractDocument.java +++ b/libjava/classpath/javax/swing/text/AbstractDocument.java @@ -672,20 +672,8 @@ public abstract class AbstractDocument implements Document, Serializable new DefaultDocumentEvent(offset, length, DocumentEvent.EventType.REMOVE); - // Here we set up the parameters for an ElementChange, if one - // needs to be added to the DocumentEvent later - Element root = getDefaultRootElement(); - int start = root.getElementIndex(offset); - int end = root.getElementIndex(offset + length); - - Element[] removed = new Element[end - start + 1]; - for (int i = start; i <= end; i++) - removed[i - start] = root.getElement(i); - removeUpdate(event); - Element[] added = new Element[1]; - added[0] = root.getElement(start); boolean shouldFire = content.getString(offset, length).length() != 0; writeLock(); @@ -694,17 +682,6 @@ public abstract class AbstractDocument implements Document, Serializable postRemoveUpdate(event); - GapContent.UndoRemove changes = null; - if (content instanceof GapContent) - changes = (GapContent.UndoRemove) temp; - - if (changes != null && !(start == end)) - { - // We need to add an ElementChange to our DocumentEvent - ElementEdit edit = new ElementEdit (root, start, removed, added); - event.addEdit(edit); - } - if (shouldFire) fireRemoveUpdate(event); } @@ -2143,7 +2120,10 @@ public abstract class AbstractDocument implements Document, Serializable */ public String getName() { - return ContentElementName; + String name = super.getName(); + if (name == null) + name = ContentElementName; + return name; } /** diff --git a/libjava/classpath/javax/swing/text/BoxView.java b/libjava/classpath/javax/swing/text/BoxView.java index f201045dbdb..5c9587dfe5d 100644 --- a/libjava/classpath/javax/swing/text/BoxView.java +++ b/libjava/classpath/javax/swing/text/BoxView.java @@ -476,7 +476,6 @@ public class BoxView protected View getViewAtPoint(int x, int y, Rectangle r) { View result = null; - int count = getViewCount(); Rectangle copy = new Rectangle(r); @@ -490,7 +489,9 @@ public class BoxView break; } } - + + if (result == null && count > 0) + return getView(count - 1); return result; } @@ -498,10 +499,12 @@ public class BoxView * Computes the allocation for a child <code>View</code>. The parameter * <code>a</code> stores the allocation of this <code>CompositeView</code> * and is then adjusted to hold the allocation of the child view. - * - * @param index the index of the child <code>View</code> - * @param a the allocation of this <code>CompositeView</code> before the - * call, the allocation of the child on exit + * + * @param index + * the index of the child <code>View</code> + * @param a + * the allocation of this <code>CompositeView</code> before the + * call, the allocation of the child on exit */ protected void childAllocation(int index, Rectangle a) { @@ -737,4 +740,22 @@ public class BoxView yLayoutValid = false; super.preferenceChanged(child, width, height); } + + /** + * Maps the document model position <code>pos</code> to a Shape + * in the view coordinate space. This method overrides CompositeView's + * method to make sure the children are allocated properly before + * calling the super's behaviour. + */ + public Shape modelToView(int pos, Shape a, Position.Bias bias) + throws BadLocationException + { + // Make sure everything is allocated properly and then call super + if (!isAllocationValid()) + { + Rectangle bounds = a.getBounds(); + setSize(bounds.width, bounds.height); + } + return super.modelToView(pos, a, bias); + } } diff --git a/libjava/classpath/javax/swing/text/ComponentView.java b/libjava/classpath/javax/swing/text/ComponentView.java index 16112c8f4de..830dda3ecdc 100644 --- a/libjava/classpath/javax/swing/text/ComponentView.java +++ b/libjava/classpath/javax/swing/text/ComponentView.java @@ -38,10 +38,13 @@ exception statement from your version. */ package javax.swing.text; import java.awt.Component; +import java.awt.Container; import java.awt.Graphics; +import java.awt.Rectangle; import java.awt.Shape; import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; /** * A {@link View} implementation that is able to render arbitrary @@ -52,12 +55,17 @@ import javax.swing.SwingConstants; * this <code>ComponentView</code>, so this view must not be shared between * multiple <code>JTextComponent</code>s. * + * @author Roman Kennke (kennke@aicas.com) * @author original author unknown - * @author Roman Kennke (roman@kennke.org) */ -// FIXME: This class is a complete stub and needs to be implemented properly. public class ComponentView extends View { + + /** + * The component that is displayed by this view. + */ + private Component comp; + /** * Creates a new instance of <code>ComponentView</code> for the specified * <code>Element</code>. @@ -77,7 +85,7 @@ public class ComponentView extends View * * @return the component that is rendered */ - protected Component createComponent() + protected Component createComponent() { return StyleConstants.getComponent(getElement().getAttributes()); } @@ -91,7 +99,14 @@ public class ComponentView extends View */ public float getAlignment(int axis) { - return 0; + float align; + if (axis == X_AXIS) + align = getComponent().getAlignmentX(); + else if (axis == Y_AXIS) + align = getComponent().getAlignmentY(); + else + throw new IllegalArgumentException(); + return align; } /** @@ -103,7 +118,9 @@ public class ComponentView extends View */ public final Component getComponent() { - return null; + if (comp == null) + comp = createComponent(); + return comp; } /** @@ -118,49 +135,115 @@ public class ComponentView extends View */ public float getMaximumSpan(int axis) { - return 0; + float span; + if (axis == X_AXIS) + span = getComponent().getMaximumSize().width; + else if (axis == Y_AXIS) + span = getComponent().getMaximumSize().height; + else + throw new IllegalArgumentException(); + return span; } public float getMinimumSpan(int axis) { - // TODO: Implement this properly. - return 0; + float span; + if (axis == X_AXIS) + span = getComponent().getMinimumSize().width; + else if (axis == Y_AXIS) + span = getComponent().getMinimumSize().height; + else + throw new IllegalArgumentException(); + return span; } public float getPreferredSpan(int axis) { - // TODO: Implement this properly. - return 0; + float span; + if (axis == X_AXIS) + span = getComponent().getPreferredSize().width; + else if (axis == Y_AXIS) + span = getComponent().getPreferredSize().height; + else + throw new IllegalArgumentException(); + return span; } public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException { - // TODO: Implement this properly. - return null; + Element el = getElement(); + if (pos < el.getStartOffset() || pos >= el.getEndOffset()) + throw new BadLocationException("Illegal offset for this view", pos); + Rectangle r = a.getBounds(); + Component c = getComponent(); + return new Rectangle(r.x, r.y, c.getWidth(), c.getHeight()); } - + + /** + * The real painting behavour is performed by normal component painting, + * triggered by the text component that hosts this view. This method does + * not paint by itself. However, it sets the size of the component according + * to the allocation that is passed here. + * + * @param g the graphics context + * @param a the allocation of the child + */ public void paint(Graphics g, Shape a) { - // TODO: Implement this properly. + Rectangle r = a.getBounds(); + getComponent().setBounds(r.x, r.y, r.width, r.height); } - - public void setParent(View p) + + /** + * This sets up the component when the view is added to its parent, or + * cleans up the view when it is removed from its parent. + * + * When this view is added to a parent view, the component of this view + * is added to the container that hosts this view. When <code>p</code> is + * <code>null</code>, then the view is removed from it's parent and we have + * to also remove the component from it's parent container. + * + * @param p the parent view or <code>null</code> if this view is removed + * from it's parent + */ + public void setParent(final View p) { - // TODO: Implement this properly. + if (SwingUtilities.isEventDispatchThread()) + setParentImpl(p); + else + SwingUtilities.invokeLater + (new Runnable() + { + public void run() + { + setParentImpl(p); + } + }); } - - public void setSize(float width, float height) + + /** + * The implementation of {@link #setParent}. This is package private to + * avoid a synthetic accessor method. + * + * @param p the parent view to set + */ + void setParentImpl(View p) { - // TODO: Implement this properly. + if (p != null) + { + Component c = getComponent(); + p.getContainer().add(c); + } + else + { + Component c = getComponent(); + Container parent = c.getParent(); + parent.remove(c); + comp = null; + } } - public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) - { - // TODO: Implement this properly. - return 0; - } - /** * Maps coordinates from the <code>View</code>'s space into a position * in the document model. @@ -173,10 +256,13 @@ public class ComponentView extends View * @return the position in the document that corresponds to the screen * coordinates <code>x, y</code> */ - public int viewToModel(float x, float y, Shape a, Position.Bias b) + public int viewToModel(float x, float y, Shape a, Position.Bias[] b) { - // FIXME: Implement this properly. - return 0; + // The element should only have one character position and it is clear + // that this position is the position that best matches the given screen + // coordinates, simply because this view has only this one position. + Element el = getElement(); + return el.getStartOffset(); } /** @@ -205,7 +291,7 @@ public class ComponentView extends View Position.Bias[] biasRet) throws BadLocationException { - // TODO: Implement this properly. - throw new AssertionError("Not implemented yet."); + // FIXME: Implement this method. + throw new AssertionError("Not yet implemented"); } } diff --git a/libjava/classpath/javax/swing/text/CompositeView.java b/libjava/classpath/javax/swing/text/CompositeView.java index bc626a40696..e6c2e4cc2d8 100644 --- a/libjava/classpath/javax/swing/text/CompositeView.java +++ b/libjava/classpath/javax/swing/text/CompositeView.java @@ -264,50 +264,56 @@ public abstract class CompositeView * Maps coordinates from the <code>View</code>'s space into a position * in the document model. * - * @param x the x coordinate in the view space - * @param y the y coordinate in the view space + * @param x the x coordinate in the view space, x >= 0 + * @param y the y coordinate in the view space, y >= 0 * @param a the allocation of this <code>View</code> * @param b the bias to use * * @return the position in the document that corresponds to the screen - * coordinates <code>x, y</code> + * coordinates <code>x, y</code> >= 0 */ public int viewToModel(float x, float y, Shape a, Position.Bias[] b) { - Rectangle r = getInsideAllocation(a); - View view = getViewAtPoint((int) x, (int) y, r); - return view.viewToModel(x, y, a, b); + if (x >= 0 && y >= 0) + { + Rectangle r = getInsideAllocation(a); + View view = getViewAtPoint((int) x, (int) y, r); + return view.viewToModel(x, y, a, b); + } + return 0; } /** * Returns the next model location that is visible in eiter north / south - * direction or east / west direction. This is used to determine the - * placement of the caret when navigating around the document with - * the arrow keys. - * - * This is a convenience method for - * {@link #getNextNorthSouthVisualPositionFrom} and - * {@link #getNextEastWestVisualPositionFrom}. - * - * @param pos the model position to start search from - * @param b the bias for <code>pos</code> - * @param a the allocated region for this view - * @param direction the direction from the current position, can be one of - * the following: - * <ul> - * <li>{@link SwingConstants#WEST}</li> - * <li>{@link SwingConstants#EAST}</li> - * <li>{@link SwingConstants#NORTH}</li> - * <li>{@link SwingConstants#SOUTH}</li> - * </ul> - * @param biasRet the bias of the return value gets stored here - * + * direction or east / west direction. This is used to determine the placement + * of the caret when navigating around the document with the arrow keys. This + * is a convenience method for {@link #getNextNorthSouthVisualPositionFrom} + * and {@link #getNextEastWestVisualPositionFrom}. + * + * @param pos + * the model position to start search from + * @param b + * the bias for <code>pos</code> + * @param a + * the allocated region for this view + * @param direction + * the direction from the current position, can be one of the + * following: + * <ul> + * <li>{@link SwingConstants#WEST}</li> + * <li>{@link SwingConstants#EAST}</li> + * <li>{@link SwingConstants#NORTH}</li> + * <li>{@link SwingConstants#SOUTH}</li> + * </ul> + * @param biasRet + * the bias of the return value gets stored here * @return the position inside the model that represents the next visual * location - * - * @throws BadLocationException if <code>pos</code> is not a valid location - * inside the document model - * @throws IllegalArgumentException if <code>direction</code> is invalid + * @throws BadLocationException + * if <code>pos</code> is not a valid location inside the document + * model + * @throws IllegalArgumentException + * if <code>direction</code> is invalid */ public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) diff --git a/libjava/classpath/javax/swing/text/DefaultCaret.java b/libjava/classpath/javax/swing/text/DefaultCaret.java index 66e2f4723cf..3ebeceb947d 100644 --- a/libjava/classpath/javax/swing/text/DefaultCaret.java +++ b/libjava/classpath/javax/swing/text/DefaultCaret.java @@ -781,28 +781,34 @@ public class DefaultCaret extends Rectangle */ public void moveDot(int dot) { - this.dot = dot; - handleHighlight(); - adjustVisibility(this); - appear(); + if (dot >= 0) + { + this.dot = dot; + handleHighlight(); + adjustVisibility(this); + appear(); + } } /** * Sets the current position of this <code>Caret</code> within the - * <code>Document</code>. This also sets the <code>mark</code> to the - * new location. - * - * @param dot the new position to be set - * + * <code>Document</code>. This also sets the <code>mark</code> to the new + * location. + * + * @param dot + * the new position to be set * @see #moveDot(int) */ public void setDot(int dot) { - this.dot = dot; - this.mark = dot; - handleHighlight(); - adjustVisibility(this); - appear(); + if (dot >= 0) + { + this.mark = dot; + this.dot = dot; + handleHighlight(); + adjustVisibility(this); + appear(); + } } /** @@ -878,7 +884,7 @@ public class DefaultCaret extends Rectangle } Rectangle area = null; try - { + { area = getComponent().modelToView(getDot()); } catch (BadLocationException ex) diff --git a/libjava/classpath/javax/swing/text/FlowView.java b/libjava/classpath/javax/swing/text/FlowView.java index fd6785b6f18..765f515a20d 100644 --- a/libjava/classpath/javax/swing/text/FlowView.java +++ b/libjava/classpath/javax/swing/text/FlowView.java @@ -601,6 +601,9 @@ public abstract class FlowView extends BoxView */ public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory vf) { + // First we must send the insertUpdate to the logical view so it can + // be updated accordingly. + layoutPool.insertUpdate(changes, a, vf); strategy.insertUpdate(this, changes, getInsideAllocation(a)); } diff --git a/libjava/classpath/javax/swing/text/GlyphView.java b/libjava/classpath/javax/swing/text/GlyphView.java index eb1fadd4f2d..d3dd75e624b 100644 --- a/libjava/classpath/javax/swing/text/GlyphView.java +++ b/libjava/classpath/javax/swing/text/GlyphView.java @@ -457,9 +457,6 @@ public class GlyphView extends View implements TabableView, Cloneable Bias[] biasRet) { Rectangle b = a.getBounds(); - assert b.contains(x, y) : "The coordinates are expected to be within the " - + "view's bounds: x=" + x + ", y=" + y - + "a=" + a; int pos = getBoundedPosition(v, v.getStartOffset(), b.x, x - b.x); return pos; } diff --git a/libjava/classpath/javax/swing/text/IconView.java b/libjava/classpath/javax/swing/text/IconView.java index 6dd0f7ad34a..86c27dd5fda 100644 --- a/libjava/classpath/javax/swing/text/IconView.java +++ b/libjava/classpath/javax/swing/text/IconView.java @@ -39,11 +39,25 @@ exception statement from your version. */ package javax.swing.text; import java.awt.Graphics; +import java.awt.Rectangle; import java.awt.Shape; +import javax.swing.Icon; +import javax.swing.JTextPane; import javax.swing.SwingConstants; -// TODO: Implement this class. +/** + * A View that can render an icon. This view is created by the + * {@link StyledEditorKit}'s view factory for all elements that have name + * {@link StyleConstants#IconElementName}. This is usually created by + * inserting an icon into <code>JTextPane</code> using + * {@link JTextPane#insertIcon(Icon)} + * + * The icon is determined using the attribute + * {@link StyleConstants#IconAttribute}, which's value must be an {@link Icon}. + * + * @author Roman Kennke (kennke@aicas.com) + */ public class IconView extends View { @@ -67,7 +81,9 @@ public class IconView */ public void paint(Graphics g, Shape a) { - // TODO: Implement me. + Icon icon = StyleConstants.getIcon(getElement().getAttributes()); + Rectangle b = a.getBounds(); + icon.paintIcon(getContainer(), g, b.x, b.y); } /** @@ -80,8 +96,15 @@ public class IconView */ public float getPreferredSpan(int axis) { - // TODO: Implement me. - return 0F; + Icon icon = StyleConstants.getIcon(getElement().getAttributes()); + float span; + if (axis == X_AXIS) + span = icon.getIconWidth(); + else if (axis == Y_AXIS) + span = icon.getIconHeight(); + else + throw new IllegalArgumentException(); + return span; } /** @@ -106,8 +129,12 @@ public class IconView public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException { - // Implement me. - return null; + Element el = getElement(); + if (pos < el.getStartOffset() || pos >= el.getEndOffset()) + throw new BadLocationException("Illegal offset for this view", pos); + Rectangle r = a.getBounds(); + Icon icon = StyleConstants.getIcon(el.getAttributes()); + return new Rectangle(r.x, r.y, icon.getIconWidth(), icon.getIconHeight()); } /** @@ -124,8 +151,11 @@ public class IconView */ public int viewToModel(float x, float y, Shape a, Position.Bias[] b) { - // FIXME: not implemented - return 0; + // The element should only have one character position and it is clear + // that this position is the position that best matches the given screen + // coordinates, simply because this view has only this one position. + Element el = getElement(); + return el.getStartOffset(); } /** @@ -157,4 +187,5 @@ public class IconView // TODO: Implement this properly. throw new AssertionError("Not implemented yet."); } + } diff --git a/libjava/classpath/javax/swing/text/ParagraphView.java b/libjava/classpath/javax/swing/text/ParagraphView.java index 6fb121f949e..c4864503187 100644 --- a/libjava/classpath/javax/swing/text/ParagraphView.java +++ b/libjava/classpath/javax/swing/text/ParagraphView.java @@ -38,6 +38,10 @@ exception statement from your version. */ package javax.swing.text; +import java.awt.Shape; + +import javax.swing.event.DocumentEvent; + /** * A {@link FlowView} that flows it's children horizontally and boxes the rows * vertically. @@ -67,6 +71,26 @@ public class ParagraphView extends FlowView implements TabExpander } /** + * The indentation of the first line of the paragraph. + */ + protected int firstLineIndent; + + /** + * The justification of the paragraph. + */ + private int justification; + + /** + * The line spacing of this paragraph. + */ + private float lineSpacing; + + /** + * The TabSet of this paragraph. + */ + private TabSet tabSet; + + /** * Creates a new <code>ParagraphView</code> for the given * <code>Element</code>. * @@ -116,4 +140,93 @@ public class ParagraphView extends FlowView implements TabExpander else return 0.0F; } + + /** + * Receives notification when some attributes of the displayed element + * changes. This triggers a refresh of the cached attributes of this + * paragraph. + * + * @param ev the document event + * @param a the allocation of this view + * @param fv the view factory to use for creating new child views + */ + public void changedUpdate(DocumentEvent ev, Shape a, ViewFactory fv) + { + setPropertiesFromAttributes(); + } + + /** + * Fetches the cached properties from the element's attributes. + */ + protected void setPropertiesFromAttributes() + { + Element el = getElement(); + AttributeSet atts = el.getAttributes(); + setFirstLineIndent(StyleConstants.getFirstLineIndent(atts)); + setLineSpacing(StyleConstants.getLineSpacing(atts)); + setJustification(StyleConstants.getAlignment(atts)); + tabSet = StyleConstants.getTabSet(atts); + } + + /** + * Sets the indentation of the first line of the paragraph. + * + * @param i the indentation to set + */ + protected void setFirstLineIndent(float i) + { + firstLineIndent = (int) i; + } + + /** + * Sets the justification of the paragraph. + * + * @param j the justification to set + */ + protected void setJustification(int j) + { + justification = j; + } + + /** + * Sets the line spacing for this paragraph. + * + * @param s the line spacing to set + */ + protected void setLineSpacing(float s) + { + lineSpacing = s; + } + + /** + * Returns the i-th view from the logical views, before breaking into rows. + * + * @param i the index of the logical view to return + * + * @return the i-th view from the logical views, before breaking into rows + */ + protected View getLayoutView(int i) + { + return layoutPool.getView(i); + } + + /** + * Returns the number of logical child views. + * + * @return the number of logical child views + */ + protected int getLayoutViewCount() + { + return layoutPool.getViewCount(); + } + + /** + * Returns the TabSet used by this ParagraphView. + * + * @return the TabSet used by this ParagraphView + */ + protected TabSet getTabSet() + { + return tabSet; + } } diff --git a/libjava/classpath/javax/swing/text/PlainDocument.java b/libjava/classpath/javax/swing/text/PlainDocument.java index 9e600c4c908..0c00a06ff25 100644 --- a/libjava/classpath/javax/swing/text/PlainDocument.java +++ b/libjava/classpath/javax/swing/text/PlainDocument.java @@ -105,10 +105,65 @@ public class PlainDocument extends AbstractDocument return root; } - protected void insertUpdate(DefaultDocumentEvent event, AttributeSet attributes) + protected void insertUpdate(DefaultDocumentEvent event, + AttributeSet attributes) { - reindex(); + int offset = event.getOffset(); + int end = offset + event.getLength(); + int elementIndex = rootElement.getElementIndex(offset); + Element firstElement = rootElement.getElement(elementIndex); + + // added and removed are Element arrays used to add an ElementEdit + // to the DocumentEvent if there were entire lines added or removed. + Element[] removed = new Element[1]; + Element[] added; + try + { + String str = content.getString(0, content.length()); + ArrayList elts = new ArrayList(); + // Determine how many NEW lines were added by finding the newline + // characters within the newly inserted text + int j = firstElement.getStartOffset(); + int i = str.indexOf('\n', offset); + while (i != -1 && i <= end) + { + // For each new line, create a new element + elts.add(createLeafElement(rootElement, SimpleAttributeSet.EMPTY, + j, i + 1)); + j = i + 1; + if (j >= str.length()) + break; + i = str.indexOf('\n', j); + } + // If there were new lines added we have to add an ElementEdit to + // the DocumentEvent and we have to call rootElement.replace to + // insert the new lines + if (elts.size() != 0) + { + // Set up the ElementEdit by filling the added and removed + // arrays with the proper Elements + added = new Element[elts.size()]; + for (int k = 0; k < elts.size(); ++k) + added[k] = (Element) elts.get(k); + removed[0] = firstElement; + + // Now create and add the ElementEdit + ElementEdit e = new ElementEdit(rootElement, elementIndex, removed, + added); + event.addEdit(e); + + // And call replace to actually make the changes + ((BranchElement) rootElement).replace(elementIndex, 1, added); + } + } + catch (BadLocationException e) + { + // This shouldn't happen so we throw an AssertionError + AssertionError ae = new AssertionError(); + ae.initCause(e); + throw ae; + } super.insertUpdate(event, attributes); } @@ -116,24 +171,37 @@ public class PlainDocument extends AbstractDocument { super.removeUpdate(event); + // added and removed are Element arrays used to add an ElementEdit + // to the DocumentEvent if there were entire lines added or removed + // from the Document + Element[] added = new Element[1]; + Element[] removed; int p0 = event.getOffset(); - int len = event.getLength(); - int p1 = len + p0; // check if we must collapse some elements int i1 = rootElement.getElementIndex(p0); - int i2 = rootElement.getElementIndex(p1); + int i2 = rootElement.getElementIndex(p0 + event.getLength()); if (i1 != i2) { - Element el1 = rootElement.getElement(i1); - Element el2 = rootElement.getElement(i2); - int start = el1.getStartOffset(); - int end = el2.getEndOffset(); - // collapse elements if the removal spans more than 1 line - Element newEl = createLeafElement(rootElement, + // If there were lines removed then we have to add an ElementEdit + // to the DocumentEvent so we set it up now by filling the Element + // arrays "removed" and "added" appropriately + removed = new Element [i2 - i1 + 1]; + for (int i = i1; i <= i2; i++) + removed[i-i1] = rootElement.getElement(i); + + int start = rootElement.getElement(i1).getStartOffset(); + int end = rootElement.getElement(i2).getEndOffset(); + added[0] = createLeafElement(rootElement, SimpleAttributeSet.EMPTY, start, end); - rootElement.replace(i1, i2 - i1 + 1, new Element[]{ newEl }); + + // Now create and add the ElementEdit + ElementEdit e = new ElementEdit(rootElement, i1, removed, added); + event.addEdit(e); + + // collapse elements if the removal spans more than 1 line + rootElement.replace(i1, i2 - i1 + 1, added); } } @@ -167,7 +235,7 @@ public class PlainDocument extends AbstractDocument throws BadLocationException { String string = str; - if (Boolean.TRUE.equals(getProperty("filterNewlines"))) + if (str != null && Boolean.TRUE.equals(getProperty("filterNewlines"))) string = str.replaceAll("\n", " "); super.insertString(offs, string, atts); } diff --git a/libjava/classpath/javax/swing/text/WrappedPlainView.java b/libjava/classpath/javax/swing/text/WrappedPlainView.java index b90519046ae..b03399d0974 100644 --- a/libjava/classpath/javax/swing/text/WrappedPlainView.java +++ b/libjava/classpath/javax/swing/text/WrappedPlainView.java @@ -50,7 +50,7 @@ import javax.swing.event.DocumentEvent; import javax.swing.text.Position.Bias; /** - * @author abalkiss + * @author Anthony Balkissoon abalkiss at redhat dot com * */ public class WrappedPlainView extends BoxView implements TabExpander diff --git a/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java b/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java index 2891a778ee9..ae8b99c2fe5 100644 --- a/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java +++ b/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java @@ -339,9 +339,8 @@ public class DefaultTreeCellEditor lastPath = tree.getLeadSelectionPath(); tree.addTreeSelectionListener(this); editingContainer = createContainer(); - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - setFont(defaults.getFont("Tree.font")); - setBorderSelectionColor(defaults.getColor("Tree.selectionBorderColor")); + setFont(UIManager.getFont("Tree.font")); + setBorderSelectionColor(UIManager.getColor("Tree.selectionBorderColor")); editingIcon = renderer.getIcon(); timer = new javax.swing.Timer(1200, this); } @@ -735,9 +734,8 @@ public class DefaultTreeCellEditor */ protected TreeCellEditor createTreeCellEditor() { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); realEditor = new DefaultCellEditor(new DefaultTreeCellEditor.DefaultTextField( - defaults.getBorder("Tree.selectionBorder"))); + UIManager.getBorder("Tree.selectionBorder"))); return realEditor; } } diff --git a/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java b/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java index d1cb9c0e8b7..df70ba7fb9f 100644 --- a/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java +++ b/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java @@ -51,7 +51,6 @@ import javax.swing.border.Border; import javax.swing.Icon; import javax.swing.JLabel; import javax.swing.JTree; -import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.SwingUtilities; import javax.swing.plaf.UIResource; @@ -133,17 +132,15 @@ public class DefaultTreeCellRenderer */ public DefaultTreeCellRenderer() { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - setLeafIcon(getDefaultLeafIcon()); setOpenIcon(getDefaultOpenIcon()); setClosedIcon(getDefaultClosedIcon()); - setTextNonSelectionColor(defaults.getColor("Tree.textForeground")); - setTextSelectionColor(defaults.getColor("Tree.selectionForeground")); - setBackgroundNonSelectionColor(defaults.getColor("Tree.nonSelectionBackground")); - setBackgroundSelectionColor(defaults.getColor("Tree.selectionBackground")); - setBorderSelectionColor(defaults.getColor("Tree.selectionBorderColor")); + setTextNonSelectionColor(UIManager.getColor("Tree.textForeground")); + setTextSelectionColor(UIManager.getColor("Tree.selectionForeground")); + setBackgroundNonSelectionColor(UIManager.getColor("Tree.nonSelectionBackground")); + setBackgroundSelectionColor(UIManager.getColor("Tree.selectionBackground")); + setBorderSelectionColor(UIManager.getColor("Tree.selectionBorderColor")); } // ------------------------------------------------------------- @@ -157,7 +154,7 @@ public class DefaultTreeCellRenderer */ public Icon getDefaultOpenIcon() { - return UIManager.getLookAndFeelDefaults().getIcon("Tree.openIcon"); + return UIManager.getIcon("Tree.openIcon"); } /** @@ -167,7 +164,7 @@ public class DefaultTreeCellRenderer */ public Icon getDefaultClosedIcon() { - return UIManager.getLookAndFeelDefaults().getIcon("Tree.closedIcon"); + return UIManager.getIcon("Tree.closedIcon"); } /** @@ -177,7 +174,7 @@ public class DefaultTreeCellRenderer */ public Icon getDefaultLeafIcon() { - return UIManager.getLookAndFeelDefaults().getIcon("Tree.leafIcon"); + return UIManager.getIcon("Tree.leafIcon"); } /** @@ -412,7 +409,7 @@ public class DefaultTreeCellRenderer setOpaque(false); setVerticalAlignment(TOP); setEnabled(true); - super.setFont(UIManager.getLookAndFeelDefaults().getFont("Tree.font")); + super.setFont(UIManager.getFont("Tree.font")); if (selected) { @@ -459,8 +456,7 @@ public class DefaultTreeCellRenderer Rectangle tr = new Rectangle(); Insets insets = new Insets(0, 0, 0, 0); - Border border = UIManager.getLookAndFeelDefaults().getBorder( - "Tree.selectionBorder"); + Border border = UIManager.getBorder("Tree.selectionBorder"); if (border != null) insets = border.getBorderInsets(this); |