[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI various small fixes, plus some jtree stuff from libgcj
From: |
Mark Wielaard |
Subject: |
[cp-patches] FYI various small fixes, plus some jtree stuff from libgcj |
Date: |
Thu, 11 Nov 2004 18:18:08 +0100 |
Hi,
Graydon wrote:
"this patch fixes a bunch of minor issues I found all over the gui
branch in the past few weeks, while working on demonstrations of our
swing code. none of it is particularly controversial, although I did
throw in a small amount of code to support basic rendering of JTrees as
well (see http://people.redhat.com/graydon/jtree.png)."
In particular it fixes the paintDirtyRegions() that we were seeing.
2004-11-11 Graydon Hoare <address@hidden>
* gnu/java/awt/peer/gtk/GdkGraphics2D.java
(GdkGraphics2D): Set clip after transform.
(drawImage): Protect against null image.
* gnu/java/awt/peer/gtk/GtkFramePeer.java
(setIconImage): Protect against non-GtkImage args.
* gnu/java/awt/peer/gtk/GtkToolkit.java
(checkImage): Protect against non-GtkImage args.
* java/awt/print/PrinterJob.java:
(print): Add variant taking PrintRequestAttributeSet.
(printDialog): Likewise.
* javax/swing/JComponent.java:
(transferHandler): New field.
(getComponentGraphics): Build new Graphics for each sub-paint.
(getTransferHandler): New method.
(setTransferHandler): New method.
* javax/swing/JDesktopPane.java
(setDragMode): Force LIVE_DRAG_MODE.
* javax/swing/JMenuItem.java
(menuSelectionChanged): Protect against null parent.
* javax/swing/JTable.java (setDefaultRenderer): New method.
* javax/swing/JTree.java: Get basic ctors and UI working.
* javax/swing/JViewport.java (JViewport): Set scroll mode.
* javax/swing/RepaintManager.java
(addDirtyRegion): Skip empty regions.
* javax/swing/ScrollPaneLayout.java (minimumLayoutSize): Do not
bound scrollpane minimum by central view minimum.
* javax/swing/ToolTipManager.java
(showTip): Guard against null component.
* javax/swing/TransferHandler.java: Stub out.
* javax/swing/plaf/basic/BasicLookAndFeel.java:
Add entry for TextPaneUI, change Tree icons to pngs.
* javax/swing/plaf/basic/BasicMenuItemUI.java:
(installDefaults): Set text position and alignment.
(paintMenuItem): Layout icon with normal compound function.
* javax/swing/plaf/basic/BasicTableHeaderUI.java:
(getMaximumSize): Delete.
(getMinimumSize): Delete.
(getPreferredSize): Use column model's total width.
* javax/swing/plaf/basic/BasicTextPaneUI.java: New file.
* javax/swing/plaf/basic/BasicTextUI.java
(modelChanged): Make resilient against nulls.
* javax/swing/plaf/basic/BasicTreeUI.java:
Add some simplistic config / painting functions.
* javax/swing/plaf/basic/BasicViewportUI.java
(paintSimple): Add new non-backingstore paint mode.
(paintBackingStore): Split out backing store code.
(paint): Switch on painting mode.
* javax/swing/text/SimpleAttributeSet.java
(SimpleAttributeSet): Resist nulls.
* javax/swing/tree/DefaultTreeCellRenderer.java: Implement.
* javax/swing/tree/DefaultTreeModel.java: Partially implement.
Committed.
Cheers,
Mark
--- gnu/java/awt/peer/gtk/GdkGraphics2D.java 28 Oct 2004 11:43:09 -0000
1.7.2.21
+++ gnu/java/awt/peer/gtk/GdkGraphics2D.java 10 Nov 2004 06:24:37 -0000
@@ -187,8 +187,8 @@
setBackground (bg);
setPaint (paint);
setStroke (stroke);
- setClip (clip);
setTransform (transform);
+ setClip (clip);
stateStack = new Stack();
}
@@ -502,6 +502,10 @@
Color bgcolor,
ImageObserver obs)
{
+
+ if (img == null)
+ return false;
+
if (img instanceof GtkOffScreenImage &&
img.getGraphics () instanceof GdkGraphics2D &&
(xform == null
@@ -1286,6 +1290,9 @@
Color bgcolor, ImageObserver observer)
{
+ if (img == null)
+ return false;
+
Image subImage;
int sourceWidth = sx2 - sx1;
--- gnu/java/awt/peer/gtk/GtkFramePeer.java 9 Sep 2004 20:03:07 -0000
1.17.2.9
+++ gnu/java/awt/peer/gtk/GtkFramePeer.java 10 Nov 2004 06:24:37 -0000
@@ -170,7 +170,7 @@
native void nativeSetIconImageFromData (int[] pixels, int width, int height);
public void setIconImage (Image image)
{
- if (image != null)
+ if (image != null && image instanceof GtkImage)
{
GtkImage img = (GtkImage) image;
// FIXME: Image should be loaded, but if not, do image loading here.
--- gnu/java/awt/peer/gtk/GtkToolkit.java 9 Oct 2004 08:04:03 -0000
1.8.2.12
+++ gnu/java/awt/peer/gtk/GtkToolkit.java 10 Nov 2004 06:24:37 -0000
@@ -122,7 +122,14 @@
public int checkImage (Image image, int width, int height,
ImageObserver observer)
{
- int status = ((GtkImage) image).checkImage ();
+ int status = ImageObserver.ALLBITS
+ | ImageObserver.WIDTH
+ | ImageObserver.HEIGHT;
+
+ if (image instanceof GtkImage)
+ {
+ status = ((GtkImage) image).checkImage ();
+ }
if (observer != null)
observer.imageUpdate (image, status,
--- java/awt/print/PrinterJob.java 5 Jun 2003 19:58:40 -0000 1.3
+++ java/awt/print/PrinterJob.java 10 Nov 2004 06:24:37 -0000
@@ -37,6 +37,7 @@
package java.awt.print;
+import javax.print.attribute.PrintRequestAttributeSet;
/**
* This class controls printing.
@@ -194,6 +195,8 @@
* Prints the pages.
*/
public abstract void print () throws PrinterException;
+public abstract void print (PrintRequestAttributeSet attributes) throws
PrinterException;
+
/**
* Displays a dialog box to the user which allows the print job
@@ -205,6 +208,9 @@
public abstract boolean
printDialog();
+public abstract boolean
+printDialog(PrintRequestAttributeSet attributes);
+
/*************************************************************************/
/**
--- javax/swing/JComponent.java 25 Oct 2004 10:34:31 -0000 1.7.2.23
+++ javax/swing/JComponent.java 10 Nov 2004 06:24:38 -0000
@@ -325,6 +325,8 @@
private ActionMap actionMap;
private InputVerifier inputVerifier;
+ private TransferHandler transferHandler;
+
/**
* A lock held during recursive painting; this is used to serialize
* access to the double buffer, and also to select the "top level"
@@ -862,9 +864,10 @@
*/
protected Graphics getComponentGraphics(Graphics g)
{
- g.setFont(this.getFont());
- g.setColor(this.getForeground());
- return g;
+ Graphics g2 = g.create();
+ g2.setFont(this.getFont());
+ g2.setColor(this.getForeground());
+ return g2;
}
@@ -2069,6 +2072,32 @@
}
/**
+ * Get the value of the address@hidden #transferHandler} property.
+ *
+ * @return The current value of the property
+ *
+ * @see ComponentUI#setTransferHandler
+ */
+
+ public TransferHandler getTransferHandler()
+ {
+ return transferHandler;
+ }
+
+ /**
+ * Set the value of the address@hidden #transferHandler} property.
+ *
+ * @param newHandler The new value of the property
+ *
+ * @see ComponentUI#getTransferHandler
+ */
+
+ void setTransferHandler (TransferHandler newHandler)
+ {
+ transferHandler = newHandler;
+ }
+
+ /**
* Set the value of the address@hidden #opaque} property, revalidate and
repaint
* this component.
*
--- javax/swing/JDesktopPane.java 22 Oct 2004 12:41:12 -0000 1.3.8.6
+++ javax/swing/JDesktopPane.java 10 Nov 2004 06:24:38 -0000
@@ -154,7 +154,10 @@
// FIXME: Unsupported mode.
if (mode == OUTLINE_DRAG_MODE)
- throw new IllegalArgumentException("Outline drag modes are
unsupported.");
+ {
+ // throw new IllegalArgumentException("Outline drag modes are
unsupported.");
+ mode = LIVE_DRAG_MODE;
+ }
dragMode = mode;
}
--- javax/swing/JMenuItem.java 22 Oct 2004 12:41:14 -0000 1.2.18.16
+++ javax/swing/JMenuItem.java 10 Nov 2004 06:24:38 -0000
@@ -529,19 +529,20 @@
*/
public void menuSelectionChanged(boolean changed)
{
+ Component parent = this.getParent();
if (changed)
{
model.setArmed(true);
- if (this.getParent() instanceof JPopupMenu)
- ((JPopupMenu) this.getParent()).setSelected(this);
+ if (parent != null && parent instanceof JPopupMenu)
+ ((JPopupMenu) parent).setSelected(this);
}
else
{
model.setArmed(false);
- if (this.getParent() instanceof JPopupMenu)
- ((JPopupMenu) this.getParent()).getSelectionModel().clearSelection();
+ if (parent != null && parent instanceof JPopupMenu)
+ ((JPopupMenu) parent).getSelectionModel().clearSelection();
}
}
--- javax/swing/JTable.java 22 Oct 2004 12:41:15 -0000 1.4.18.8
+++ javax/swing/JTable.java 10 Nov 2004 06:24:38 -0000
@@ -675,6 +675,11 @@
return renderer;
}
+ public void setDefaultRenderer(Class columnClass, TableCellRenderer rend)
+ {
+ defaultRenderersByColumnClass.put(columnClass, rend);
+ }
+
public TableCellRenderer getDefaultRenderer(Class columnClass)
{
if (defaultRenderersByColumnClass.containsKey(columnClass))
--- javax/swing/JTree.java 22 Oct 2004 12:41:16 -0000 1.3.2.9
+++ javax/swing/JTree.java 10 Nov 2004 06:24:38 -0000
@@ -40,7 +40,9 @@
import java.awt.Dimension;
import java.awt.Rectangle;
+import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Iterator;
import java.util.Vector;
import javax.accessibility.Accessible;
@@ -52,6 +54,9 @@
import javax.swing.event.TreeWillExpandListener;
import javax.swing.plaf.TreeUI;
import javax.swing.tree.ExpandVetoException;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeCellEditor;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeModel;
@@ -59,6 +64,7 @@
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
+
public class JTree extends JComponent
implements Scrollable, Accessible
{
@@ -100,7 +106,7 @@
*/
public JTree()
{
- treeModel = createTreeModel(null);
+ this(createTreeModel(null));
}
/**
@@ -110,7 +116,7 @@
*/
public JTree(Hashtable value)
{
- treeModel = createTreeModel(value);
+ this(createTreeModel(value));
}
/**
@@ -120,7 +126,7 @@
*/
public JTree(Object[] value)
{
- treeModel = createTreeModel(value);
+ this(createTreeModel(value));
}
/**
@@ -131,6 +137,8 @@
public JTree(TreeModel model)
{
treeModel = model;
+ setCellRenderer(new DefaultTreeCellRenderer());
+ updateUI();
}
/**
@@ -152,6 +160,7 @@
*/
public JTree(TreeNode root, boolean asksAllowChildren)
{
+ this(new DefaultTreeModel(root, asksAllowChildren));
}
/**
@@ -161,7 +170,81 @@
*/
public JTree(Vector value)
{
- treeModel = createTreeModel(value);
+ this(createTreeModel(value));
+ }
+
+ public static class DynamicUtilTreeNode
+ extends DefaultMutableTreeNode
+ {
+ protected Object childValue;
+ protected boolean loadedChildren;
+ public DynamicUtilTreeNode(Object value,
+ Object children)
+ {
+ super(value);
+ childValue = children;
+ loadedChildren = false;
+ }
+
+ public int getChildCount()
+ {
+ loadChildren();
+ return super.getChildCount();
+ }
+
+ protected void loadChildren()
+ {
+ if (!loadedChildren)
+ {
+ createChildren(this, childValue);
+ loadedChildren = true;
+ }
+ }
+
+ public Enumeration children()
+ {
+ loadChildren();
+ return super.children();
+ }
+
+ public boolean isLeaf()
+ {
+ return (childValue == null ||
+ !(childValue instanceof Hashtable
+ || childValue instanceof Vector
+ || childValue.getClass().isArray()));
+ }
+
+ public static void createChildren(DefaultMutableTreeNode parent,
+ Object children)
+ {
+ if (children instanceof Hashtable)
+ {
+ Hashtable tab = (Hashtable) children;
+ Enumeration e = tab.keys();
+ while (e.hasMoreElements())
+ {
+ Object key = e.nextElement();
+ Object val = tab.get(key);
+ parent.add(new DynamicUtilTreeNode(key, val));
+ }
+ }
+ else if (children instanceof Vector)
+ {
+ Iterator i = ((Vector)children).iterator();
+ while (i.hasNext())
+ {
+ Object n = i.next();
+ parent.add(new DynamicUtilTreeNode(n,n));
+ }
+ }
+ else if (children.getClass().isArray())
+ {
+ Object[] arr = (Object[]) children;
+ for (int i = 0; i < arr.length; ++i)
+ parent.add(new DynamicUtilTreeNode(arr[i], arr[i]));
+ }
+ }
}
/**
@@ -171,8 +254,7 @@
*/
protected static TreeModel createTreeModel(Object value)
{
- // FIXME: Implement this.
- return null;
+ return new DefaultTreeModel(new DynamicUtilTreeNode(value, value));
}
/**
@@ -201,6 +283,8 @@
public void updateUI()
{
setUI((TreeUI) UIManager.getUI(this));
+ revalidate();
+ repaint();
}
/**
--- javax/swing/JViewport.java 22 Oct 2004 12:41:16 -0000 1.3.2.11
+++ javax/swing/JViewport.java 10 Nov 2004 06:24:38 -0000
@@ -127,6 +127,7 @@
public JViewport()
{
setOpaque(true);
+ setScrollMode(BLIT_SCROLL_MODE);
updateUI();
}
--- javax/swing/RepaintManager.java 22 Oct 2004 12:41:16 -0000 1.2.18.6
+++ javax/swing/RepaintManager.java 10 Nov 2004 06:24:38 -0000
@@ -309,6 +309,9 @@
public synchronized void addDirtyRegion(JComponent component, int x, int y,
int w, int h)
{
+ if (w == 0 || h == 0)
+ return;
+
Rectangle r = new Rectangle(x, y, w, h);
if (dirtyComponents.containsKey(component))
r = r.union((Rectangle)dirtyComponents.get(component));
--- javax/swing/ScrollPaneLayout.java 22 Oct 2004 12:41:16 -0000 1.3.18.9
+++ javax/swing/ScrollPaneLayout.java 10 Nov 2004 06:24:38 -0000
@@ -321,7 +321,6 @@
insetsSize.setSize(insets.left + insets.right,
insets.top + insets.bottom);
- maybeSetMinimumSize(viewport, viewportSize);
maybeSetMinimumSize(colHead, columnHeaderSize);
maybeSetMinimumSize(rowHead, rowHeaderSize);
--- javax/swing/ToolTipManager.java 22 Oct 2004 12:41:18 -0000 1.2.8.5
+++ javax/swing/ToolTipManager.java 10 Nov 2004 06:24:38 -0000
@@ -464,7 +464,7 @@
*/
private void showTip()
{
- if (! enabled)
+ if (! enabled || currentComponent == null)
return;
if (currentTip == null
--- javax/swing/TransferHandler.java 11 Aug 2004 12:59:01 -0000 1.1.2.1
+++ javax/swing/TransferHandler.java 10 Nov 2004 06:24:38 -0000
@@ -38,6 +38,8 @@
package javax.swing;
import java.io.Serializable;
+import java.awt.event.InputEvent;
+import java.awt.datatransfer.*;
public class TransferHandler implements Serializable
{
@@ -48,8 +50,66 @@
public static final int MOVE = 2;
public static final int COPY_OR_MOVE = 3;
+ static Action getCopyAction ()
+ {
+ return null;
+ }
+
+ static Action getCutAction ()
+ {
+ return null;
+ }
+
+ static Action getPasteAction ()
+ {
+ return null;
+ }
+
+
protected TransferHandler()
{
// Do nothing here.
}
+
+ public TransferHandler(String property)
+ {
+ }
+
+ public boolean canImport (JComponent c, DataFlavor[] flavors)
+ {
+ return false;
+ }
+
+ public Transferable createTransferable(JComponent c)
+ {
+ return null;
+ }
+
+ public void exportAsDrag (JComponent c, InputEvent e, int action)
+ {
+ }
+
+ protected void exportDone (JComponent c, Transferable data, int action)
+ {
+ }
+
+ public void exportToClipboard(JComponent c, Clipboard clip, int action)
+ {
+ }
+
+ public int getSourceActions (JComponent c)
+ {
+ return 0;
+ }
+
+ public Icon getVisualRepresentation (Transferable t)
+ {
+ return null;
+ }
+
+ public boolean importData (JComponent c, Transferable t)
+ {
+ return false;
+ }
+
}
--- javax/swing/plaf/basic/BasicLookAndFeel.java 22 Oct 2004 12:41:22
-0000 1.4.2.21
+++ javax/swing/plaf/basic/BasicLookAndFeel.java 10 Nov 2004 06:24:38
-0000
@@ -138,6 +138,7 @@
"TabbedPaneUI", "javax.swing.plaf.basic.BasicTabbedPaneUI",
"TableHeaderUI", "javax.swing.plaf.basic.BasicTableHeaderUI",
"TableUI", "javax.swing.plaf.basic.BasicTableUI",
+ "TextPaneUI", "javax.swing.plaf.basic.BasicTextPaneUI",
"TextAreaUI", "javax.swing.plaf.basic.BasicTextAreaUI",
"TextFieldUI", "javax.swing.plaf.basic.BasicTextFieldUI",
"TextPaneUI", "javax.swing.plaf.basic.BasicTextPaneUI",
@@ -901,8 +902,8 @@
}),
"Tree.background", new ColorUIResource(Color.white),
"Tree.changeSelectionWithFocus", Boolean.TRUE,
- // XXX Don't use gif
- "Tree.closedIcon", new IconUIResource(new
ImageIcon("icons/TreeClosed.gif")),
+ "Tree.closedIcon", new IconUIResource(new
ImageIcon("icons/TreeClosed.png")),
+ "Tree.collapsedIcon", new IconUIResource(new
ImageIcon("icons/TreeCollapsed.png")),
"Tree.drawsFocusBorderAroundIcon", Boolean.FALSE,
"Tree.editorBorder", new
BorderUIResource.LineBorderUIResource(Color.lightGray),
"Tree.focusInputMap", new UIDefaults.LazyInputMap(new Object[] {
@@ -950,13 +951,12 @@
"ctrl PAGE_DOWN", "scrollDownChangeLead"
}),
"Tree.font", new FontUIResource("Dialog", Font.PLAIN, 12),
+ "Tree.expandedIcon", new IconUIResource(new
ImageIcon("icons/TreeExpanded.png")),
"Tree.foreground", new ColorUIResource(Color.black),
"Tree.hash", new ColorUIResource(Color.gray),
- // XXX Don't use gif
- "Tree.leafIcon", new IconUIResource(new ImageIcon("icons/TreeLeaf.gif")),
+ "Tree.leafIcon", new IconUIResource(new ImageIcon("icons/TreeLeaf.png")),
"Tree.leftChildIndent", new Integer(7),
- // XXX Don't use gif
- "Tree.openIcon", new IconUIResource(new ImageIcon("icons/TreeOpen.gif")),
+ "Tree.openIcon", new IconUIResource(new ImageIcon("icons/TreeOpen.png")),
"Tree.rightChildIndent", new Integer(13),
"Tree.rowHeight", new Integer(16),
"Tree.scrollsOnExpand", Boolean.TRUE,
--- javax/swing/plaf/basic/BasicMenuItemUI.java 22 Oct 2004 12:41:22 -0000
1.1.2.19
+++ javax/swing/plaf/basic/BasicMenuItemUI.java 10 Nov 2004 06:24:38 -0000
@@ -60,6 +60,7 @@
import javax.swing.KeyStroke;
import javax.swing.MenuElement;
import javax.swing.MenuSelectionManager;
+import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
@@ -392,6 +393,9 @@
selectionBackground = defaults.getColor("MenuItem.selectionBackground");
selectionForeground = defaults.getColor("MenuItem.selectionForeground");
acceleratorDelimiter = defaults.getString("MenuItem.acceleratorDelimiter");
+
+ menuItem.setHorizontalTextPosition(SwingConstants.TRAILING);
+ menuItem.setHorizontalAlignment(SwingConstants.LEADING);
}
/**
@@ -551,23 +555,14 @@
}
}
- // paint icon
- // FIXME: should paint different icon at different button state's.
- // i.e disabled icon when button is disabled.. etc.
- Icon i = m.getIcon();
- if (i != null)
- {
- i.paintIcon(c, g, vr.x, vr.y);
-
- // Adjust view rectangle, s.t text would be drawn after menu item's
icon.
- vr.x += i.getIconWidth() + defaultTextIconGap;
- }
-
// paint text and user menu icon if it exists
- SwingUtilities.layoutCompoundLabel(c, fm, m.getText(), m.getIcon(),
+ Icon i = m.getIcon();
+ SwingUtilities.layoutCompoundLabel(c, fm, m.getText(), i,
vertAlign, horAlign, vertTextPos,
horTextPos, vr, ir, tr,
defaultTextIconGap);
+ if (i != null)
+ i.paintIcon(c, g, ir.x, ir.y);
paintText(g, m, tr, m.getText());
--- javax/swing/plaf/basic/BasicTableHeaderUI.java 22 Oct 2004 12:41:25
-0000 1.1.2.3
+++ javax/swing/plaf/basic/BasicTableHeaderUI.java 10 Nov 2004 06:24:38
-0000
@@ -182,84 +182,6 @@
}
- public Dimension getMaximumSize(JComponent c)
- {
- TableColumnModel cmod = header.getColumnModel();
- TableCellRenderer defaultRend = header.getDefaultRenderer();
- int ncols = cmod.getColumnCount();
- int spacing = 0;
- Dimension ret = getPreferredSize(c);
-
- if (header.getTable() != null
- && header.getTable().getInterCellSpacing() != null)
- spacing = header.getTable().getInterCellSpacing().width;
-
- ret.width = 0;
- for (int i = 0; i < ncols; ++i)
- {
- TableColumn col = cmod.getColumn(i);
- TableCellRenderer rend = col.getHeaderRenderer();
- if (rend == null)
- rend = defaultRend;
- Object val = col.getHeaderValue();
- Component comp = rend.getTableCellRendererComponent(header.getTable(),
- val,
- false, //
isSelected
- false, // isFocused
- -1, i);
- comp.setFont(header.getFont());
- comp.setBackground(header.getBackground());
- comp.setForeground(header.getForeground());
- if (comp instanceof JComponent)
- ((JComponent)comp).setBorder(cellBorder);
-
- Dimension d = comp.getMaximumSize();
- ret.width += col.getMaxWidth();
- ret.height = Math.max(ret.height, d.height);
- ret.width += spacing;
- }
- return ret;
- }
-
- public Dimension getMinimumSize(JComponent c)
- {
- TableColumnModel cmod = header.getColumnModel();
- TableCellRenderer defaultRend = header.getDefaultRenderer();
- int ncols = cmod.getColumnCount();
- int spacing = 0;
- Dimension ret = getPreferredSize(c);
-
- if (header.getTable() != null
- && header.getTable().getInterCellSpacing() != null)
- spacing = header.getTable().getInterCellSpacing().width;
-
- ret.width = 0;
- for (int i = 0; i < ncols; ++i)
- {
- TableColumn col = cmod.getColumn(i);
- TableCellRenderer rend = col.getHeaderRenderer();
- if (rend == null)
- rend = defaultRend;
- Object val = col.getHeaderValue();
- Component comp = rend.getTableCellRendererComponent(header.getTable(),
- val,
- false, //
isSelected
- false, // isFocused
- -1, i);
- comp.setFont(header.getFont());
- comp.setBackground(header.getBackground());
- comp.setForeground(header.getForeground());
- if (comp instanceof JComponent)
- ((JComponent)comp).setBorder(cellBorder);
-
- Dimension d = comp.getMinimumSize();
- ret.width += col.getMinWidth();
- ret.width += spacing;
- ret.height = Math.max(ret.height, d.height);
- }
- return ret;
- }
-
public Dimension getPreferredSize(JComponent c)
{
TableColumnModel cmod = header.getColumnModel();
@@ -291,10 +213,10 @@
((JComponent)comp).setBorder(cellBorder);
Dimension d = comp.getPreferredSize();
- ret.width += d.width;
ret.width += spacing;
ret.height = Math.max(d.height, ret.height);
}
+ ret.width = cmod.getTotalColumnWidth();
return ret;
}
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ javax/swing/plaf/basic/BasicTextPaneUI.java 10 Nov 2004 06:24:38 -0000
@@ -0,0 +1,69 @@
+/* BasicTextPaneUI.java --
+ Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.basic;
+
+import java.beans.PropertyChangeEvent;
+
+import javax.swing.JComponent;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.text.Element;
+import javax.swing.text.PlainView;
+import javax.swing.text.View;
+
+public class BasicTextPaneUI extends BasicTextUI
+{
+ public static ComponentUI createUI(JComponent comp)
+ {
+ return new BasicTextPaneUI();
+ }
+
+ public BasicTextPaneUI()
+ {
+ }
+
+ public View create(Element elem)
+ {
+ return new PlainView(elem);
+ }
+
+ protected String getPropertyPrefix()
+ {
+ return "TextPane";
+ }
+}
--- javax/swing/plaf/basic/BasicTextUI.java 22 Oct 2004 12:41:25 -0000
1.4.16.15
+++ javax/swing/plaf/basic/BasicTextUI.java 10 Nov 2004 06:24:38 -0000
@@ -461,8 +461,17 @@
protected void modelChanged()
{
+ if (textComponent == null || rootView == null)
+ return;
ViewFactory factory = rootView.getViewFactory();
- Element elem = textComponent.getDocument().getDefaultRootElement();
+ if (factory == null)
+ return;
+ Document doc = textComponent.getDocument();
+ if (doc == null)
+ return;
+ Element elem = doc.getDefaultRootElement();
+ if (elem == null)
+ return;
setView(factory.create(elem));
}
}
--- javax/swing/plaf/basic/BasicTreeUI.java 22 Oct 2004 12:41:25 -0000
1.5.14.1
+++ javax/swing/plaf/basic/BasicTreeUI.java 10 Nov 2004 06:24:38 -0000
@@ -38,11 +38,21 @@
package javax.swing.plaf.basic;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Graphics;
import java.awt.Rectangle;
+import javax.swing.JComponent;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
+import javax.swing.plaf.ComponentUI;
import javax.swing.JTree;
import javax.swing.plaf.TreeUI;
+import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeModel;
/**
* A delegate providing the user interface for <code>JTree</code>
@@ -57,6 +67,7 @@
public class BasicTreeUI
extends TreeUI
{
+
/**
* Determines the geometric extent of the label that is
* drawn for a path.
@@ -191,7 +202,6 @@
return true; // FIXME: not implemented
}
-
/**
* Cancels editing a tree cell, discarding any entered value.
* If no editing session is active, nothing happens. The cell
@@ -233,4 +243,157 @@
{
return null; // FIXME: not implemented
}
+
+ public static ComponentUI createUI(JComponent c)
+ {
+ return new BasicTreeUI();
+ }
+
+ int rightChildIndent;
+ int leftChildIndent;
+ int rowHeight;
+ Color hashColor;
+
+ protected void installDefaults(JTree tree)
+ {
+ 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);
+
+ hashColor = defaults.getColor("Tree.hash");
+ rightChildIndent = defaults.getInt("Tree.rightChildIndent");
+ leftChildIndent = defaults.getInt("Tree.leftChildIndent");
+ rowHeight = defaults.getInt("Tree.rowHeight");
+ }
+
+ protected void installKeyboardActions()
+ {
+ }
+
+ protected void installListeners()
+ {
+ }
+
+ public void installUI(JComponent c)
+ {
+ installDefaults((JTree) c);
+ }
+
+
+ protected void uninstallDefaults(JTree tree)
+ {
+ tree.setFont(null);
+ tree.setForeground(null);
+ tree.setBackground(null);
+
+ tree.setCellRenderer(null);
+ }
+
+ public void uninstallUI(JComponent c)
+ {
+ uninstallDefaults((JTree) c);
+ }
+
+ public Dimension getPreferredSize(JComponent c)
+ {
+ return new Dimension(200,200);
+ }
+
+ protected void paintLeaf(Graphics g, int x, int y, JTree tree, Object leaf)
+ {
+ Component c = tree.getCellRenderer().getTreeCellRendererComponent(tree,
+ leaf,
+ false,
// selected
+ false,
// expanded
+ true,
// leaf
+ 0,
// row
+ false
// hasFocus
+ );
+ g.translate(x, y);
+ c.paint(g);
+ g.translate(-x, -y);
+ }
+
+ protected void paintNonLeaf(Graphics g, int x, int y, JTree tree, Object
nonLeaf)
+ {
+ Component c = tree.getCellRenderer().getTreeCellRendererComponent(tree,
+ nonLeaf,
+ false,
// selected
+ false,
// expanded
+ false,
// leaf
+ 0,
// row
+ false
// hasFocus
+ );
+ g.translate(x, y);
+ c.paint(g);
+ g.translate(-x, -y);
+ }
+
+ protected int paintRecursive(Graphics g,
+ int indentation,
+ int descent,
+ int childNumber,
+ int depth,
+ JTree tree,
+ TreeModel mod,
+ Object curr)
+ {
+ Rectangle clip = g.getClipBounds();
+ if (indentation > clip.x + clip.width + rightChildIndent ||
+ descent > clip.y + clip.height + rowHeight)
+ return descent;
+
+
+ int halfHeight = rowHeight / 2;
+ int halfWidth = rightChildIndent / 2;
+ int y0 = descent + halfHeight;
+
+ if (mod.isLeaf(curr))
+ {
+ paintLeaf(g, indentation, descent, tree, curr);
+ descent += rowHeight;
+ }
+ else
+ {
+ if (depth > 0 || tree.isRootVisible())
+ {
+ paintNonLeaf(g, indentation, descent, tree, curr);
+ descent += rowHeight;
+ y0 += halfHeight;
+ }
+ int max = mod.getChildCount(curr);
+ for (int i = 0; i < max; ++i)
+ {
+ g.setColor(hashColor);
+ g.drawLine(indentation + halfWidth, descent + halfHeight,
+ indentation + rightChildIndent, descent + halfHeight);
+ descent = paintRecursive(g,
+ indentation + rightChildIndent, descent,
+ i, depth+1,
+ tree, mod, mod.getChild(curr, i));
+ }
+ }
+
+ int y1 = descent - halfHeight;
+ if (y0 != y1)
+ {
+ g.setColor(hashColor);
+ g.drawLine(indentation + halfWidth, y0,
+ indentation + halfWidth, y1);
+ }
+
+ return descent;
+ }
+
+ public void paint(Graphics g, JComponent c)
+ {
+ JTree tree = (JTree) c;
+ TreeModel mod = tree.getModel();
+ g.translate(10, 10);
+ paintRecursive(g, 0, 0, 0, 0, tree, mod, mod.getRoot());
+ g.translate(-10, -10);
+ }
}
--- javax/swing/plaf/basic/BasicViewportUI.java 22 Oct 2004 12:41:25 -0000
1.3.8.7
+++ javax/swing/plaf/basic/BasicViewportUI.java 10 Nov 2004 06:24:38 -0000
@@ -121,16 +121,15 @@
public void paint(Graphics g, JComponent c)
{
-
- JViewport v = (JViewport)c;
- Component view = v.getView();
+ JViewport port = (JViewport)c;
+ Component view = port.getView();
if (view == null)
return;
- Point pos = v.getViewPosition();
+ Point pos = port.getViewPosition();
Rectangle viewBounds = view.getBounds();
- Rectangle portBounds = v.getBounds();
+ Rectangle portBounds = port.getBounds();
if (viewBounds.width == 0
|| viewBounds.height == 0
@@ -138,6 +137,51 @@
|| portBounds.height == 0)
return;
+ switch (port.getScrollMode())
+ {
+
+ case JViewport.BACKINGSTORE_SCROLL_MODE:
+ paintBackingStore(g, port, view, pos, viewBounds, portBounds);
+ break;
+
+ case JViewport.BLIT_SCROLL_MODE:
+ // FIXME: implement separate blit mode
+
+ case JViewport.SIMPLE_SCROLL_MODE:
+ default:
+ paintSimple(g, port, view, pos, viewBounds, portBounds);
+ break;
+ }
+ }
+
+ private void paintSimple(Graphics g,
+ JViewport v,
+ Component view,
+ Point pos,
+ Rectangle viewBounds,
+ Rectangle portBounds)
+ {
+ Rectangle oldClip = g.getClipBounds ();
+ g.setClip (oldClip.intersection (viewBounds));
+ g.translate (-pos.x, -pos.y);
+ try
+ {
+ view.paint(g);
+ }
+ finally
+ {
+ g.translate (pos.x, pos.y);
+ g.setClip (oldClip);
+ }
+ }
+
+ private void paintBackingStore(Graphics g,
+ JViewport v,
+ Component view,
+ Point pos,
+ Rectangle viewBounds,
+ Rectangle portBounds)
+ {
if (backingStoreImage == null
|| backingStoreWidth != viewBounds.width
|| backingStoreHeight != viewBounds.height)
@@ -149,18 +193,17 @@
Graphics g2 = backingStoreImage.getGraphics();
-
- if (c.getBackground() != null)
+ if (v.getBackground() != null)
{
// fill the backing store background
java.awt.Color save = g2.getColor();
- g2.setColor(c.getBackground());
+ g2.setColor(v.getBackground());
g2.fillRect (0, 0, backingStoreWidth, backingStoreHeight);
g2.setColor(save);
// fill the viewport background
save = g.getColor();
- g.setColor(c.getBackground());
+ g.setColor(v.getBackground());
g.fillRect (0, 0, portBounds.width, portBounds.height);
g.setColor(save);
--- javax/swing/text/SimpleAttributeSet.java 22 Oct 2004 12:41:28 -0000
1.1.2.3
+++ javax/swing/text/SimpleAttributeSet.java 10 Nov 2004 06:24:38 -0000
@@ -57,6 +57,7 @@
public SimpleAttributeSet(AttributeSet a)
{
tab = new Hashtable();
+ if (a != null)
addAttributes(a);
}
--- javax/swing/tree/DefaultTreeCellRenderer.java 22 Oct 2004 12:41:29
-0000 1.3.18.1
+++ javax/swing/tree/DefaultTreeCellRenderer.java 10 Nov 2004 06:24:38
-0000
@@ -48,6 +48,9 @@
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JTree;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
+import javax.swing.plaf.UIResource;
/**
* DefaultTreeCellRenderer
@@ -125,8 +128,18 @@
* Constructor DefaultTreeCellRenderer
*/
public DefaultTreeCellRenderer() {
- // TODO
- } // 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.textBackground"));
+
setBackgroundSelectionColor(defaults.getColor("Tree.selectionBackground"));
+
setBorderSelectionColor(defaults.getColor("Tree.selectionBorderColor"));
+ }
//-------------------------------------------------------------
@@ -138,168 +151,172 @@
* @returns Icon
*/
public Icon getDefaultOpenIcon() {
- return null; // TODO
- } // getDefaultOpenIcon()
+ return UIManager.getLookAndFeelDefaults().getIcon("Tree.openIcon");
+ }
/**
* getDefaultClosedIcon
* @returns Icon
*/
public Icon getDefaultClosedIcon() {
- return null; // TODO
- } // getDefaultClosedIcon()
+ return UIManager.getLookAndFeelDefaults().getIcon("Tree.closedIcon");
+ }
/**
* getDefaultLeafIcon
* @returns Icon
*/
public Icon getDefaultLeafIcon() {
- return null; // TODO
- } // getDefaultLeafIcon()
+ return UIManager.getLookAndFeelDefaults().getIcon("Tree.leafIcon");
+ }
/**
* setOpenIcon
* @param value0 TODO
*/
- public void setOpenIcon(Icon value0) {
- // TODO
- } // setOpenIcon()
+ public void setOpenIcon(Icon i) {
+ openIcon = i;
+ }
/**
* getOpenIcon
* @returns Icon
*/
public Icon getOpenIcon() {
- return null; // TODO
- } // getOpenIcon()
+ return openIcon;
+ }
/**
* setClosedIcon
* @param value0 TODO
*/
- public void setClosedIcon(Icon value0) {
- // TODO
- } // setClosedIcon()
+ public void setClosedIcon(Icon i) {
+ closedIcon = i;
+ }
/**
* getClosedIcon
* @returns Icon
*/
public Icon getClosedIcon() {
- return null; // TODO
- } // getClosedIcon()
+ return closedIcon;
+ }
/**
* setLeafIcon
* @param value0 TODO
*/
- public void setLeafIcon(Icon value0) {
- // TODO
- } // setLeafIcon()
+ public void setLeafIcon(Icon i) {
+ leafIcon = i;
+ }
/**
* getLeafIcon
* @returns Icon
*/
public Icon getLeafIcon() {
- return null; // TODO
- } // getLeafIcon()
+ return leafIcon;
+ }
/**
* setTextSelectionColor
* @param value0 TODO
*/
- public void setTextSelectionColor(Color value0) {
- // TODO
- } // setTextSelectionColor()
+ public void setTextSelectionColor(Color c) {
+ textSelectionColor = c;
+ }
/**
* getTextSelectionColor
* @returns Color
*/
public Color getTextSelectionColor() {
- return null; // TODO
- } // getTextSelectionColor()
+ return textSelectionColor;
+ }
/**
* setTextNonSelectionColor
* @param value0 TODO
*/
- public void setTextNonSelectionColor(Color value0) {
- // TODO
- } // setTextNonSelectionColor()
+ public void setTextNonSelectionColor(Color c) {
+ textNonSelectionColor = c;
+ }
/**
* getTextNonSelectionColor
* @returns Color
*/
public Color getTextNonSelectionColor() {
- return null; // TODO
- } // getTextNonSelectionColor()
+ return textNonSelectionColor;
+ }
/**
* setBackgroundSelectionColor
* @param value0 TODO
*/
- public void setBackgroundSelectionColor(Color value0) {
- // TODO
- } // setBackgroundSelectionColor()
+ public void setBackgroundSelectionColor(Color c) {
+ backgroundSelectionColor = c;
+ }
/**
* getBackgroundSelectionColor
* @returns Color
*/
public Color getBackgroundSelectionColor() {
- return null; // TODO
- } // getBackgroundSelectionColor()
+ return backgroundSelectionColor;
+ }
/**
* setBackgroundNonSelectionColor
* @param value0 TODO
*/
- public void setBackgroundNonSelectionColor(Color value0) {
- // TODO
- } // setBackgroundNonSelectionColor()
+ public void setBackgroundNonSelectionColor(Color c) {
+ backgroundNonSelectionColor = c;
+ }
/**
* getBackgroundNonSelectionColor
* @returns Color
*/
public Color getBackgroundNonSelectionColor() {
- return null; // TODO
- } // getBackgroundNonSelectionColor()
+ return backgroundNonSelectionColor;
+ }
/**
* setBorderSelectionColor
* @param value0 TODO
*/
- public void setBorderSelectionColor(Color value0) {
- // TODO
- } // setBorderSelectionColor()
+ public void setBorderSelectionColor(Color c) {
+ borderSelectionColor = c;
+ }
/**
* getBorderSelectionColor
* @returns Color
*/
public Color getBorderSelectionColor() {
- return null; // TODO
- } // getBorderSelectionColor()
+ return borderSelectionColor;
+ }
/**
* setFont
* @param value0 TODO
*/
- public void setFont(Font value0) {
- // TODO
- } // setFont()
+ public void setFont(Font f) {
+ if (f != null && f instanceof UIResource)
+ f = null;
+ super.setFont(f);
+ }
/**
* setBackground
* @param value0 TODO
*/
- public void setBackground(Color value0) {
- // TODO
- } // setBackground()
+ public void setBackground(Color c) {
+ if (c != null && c instanceof UIResource)
+ c = null;
+ super.setBackground(c);
+ }
/**
* getTreeCellRendererComponent
@@ -312,17 +329,37 @@
* @param value6 TODO
* @returns Component
*/
- public Component getTreeCellRendererComponent(JTree value0, Object
value1, boolean value2, boolean value3, boolean value4, int value5, boolean
value6) {
- return null; // TODO
- } // getTreeCellRendererComponent()
+ public Component getTreeCellRendererComponent(JTree tree,
+ Object val,
+ boolean selected,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus) {
+ this.selected = selected;
+ this.hasFocus = hasFocus;
+
+ if (leaf)
+ setIcon(getLeafIcon());
+ else if (expanded)
+ setIcon(getOpenIcon());
+ else
+ setIcon(getClosedIcon());
+
+ setText(val.toString());
+ setHorizontalAlignment(LEFT);
+ setVerticalAlignment(TOP);
+
+ return this;
+ }
/**
* paint
* @param value0 TODO
*/
- public void paint(Graphics value0) {
- // TODO
- } // paint()
+ public void paint(Graphics g) {
+ super.paint(g);
+ }
/**
* getPreferredSize
--- javax/swing/tree/DefaultTreeModel.java 24 Oct 2004 09:20:48 -0000
1.3.18.3
+++ javax/swing/tree/DefaultTreeModel.java 10 Nov 2004 06:24:38 -0000
@@ -175,9 +175,12 @@
* @param value1 TODO
* @return Object
*/
- public Object getChild(Object value0, int value1)
+ public Object getChild(Object node, int idx)
{
- return null; // TODO
+ if (node instanceof TreeNode)
+ return ((TreeNode)node).getChildAt(idx);
+ else
+ return null;
}
/**
@@ -185,9 +188,12 @@
* @param value0 TODO
* @return int
*/
- public int getChildCount(Object value0)
+ public int getChildCount(Object node)
{
- return 0; // TODO
+ if (node instanceof TreeNode)
+ return ((TreeNode)node).getChildCount();
+ else
+ return 0;
}
/**
@@ -195,9 +201,12 @@
* @param value0 TODO
* @return boolean
*/
- public boolean isLeaf(Object value0)
+ public boolean isLeaf(Object node)
{
- return false; // TODO
+ if (node instanceof TreeNode)
+ return ((TreeNode)node).isLeaf();
+ else
+ return true;
}
/**
signature.asc
Description: This is a digitally signed message part
- [cp-patches] FYI various small fixes, plus some jtree stuff from libgcj,
Mark Wielaard <=