summaryrefslogtreecommitdiff
path: root/javax/swing
diff options
context:
space:
mode:
Diffstat (limited to 'javax/swing')
-rw-r--r--javax/swing/DefaultCellEditor.java95
-rw-r--r--javax/swing/JTable.java219
-rw-r--r--javax/swing/JTree.java42
-rw-r--r--javax/swing/plaf/basic/BasicLabelUI.java180
-rw-r--r--javax/swing/plaf/basic/BasicLookAndFeel.java17
-rw-r--r--javax/swing/plaf/basic/BasicSplitPaneUI.java8
-rw-r--r--javax/swing/plaf/basic/BasicTableUI.java1046
-rw-r--r--javax/swing/plaf/basic/BasicTreeUI.java1225
-rw-r--r--javax/swing/plaf/basic/BasicViewportUI.java6
-rw-r--r--javax/swing/plaf/metal/MetalLookAndFeel.java4
-rw-r--r--javax/swing/table/DefaultTableCellRenderer.java7
-rw-r--r--javax/swing/text/GapContent.java71
-rw-r--r--javax/swing/tree/DefaultTreeCellRenderer.java9
-rw-r--r--javax/swing/tree/DefaultTreeModel.java842
14 files changed, 2080 insertions, 1691 deletions
diff --git a/javax/swing/DefaultCellEditor.java b/javax/swing/DefaultCellEditor.java
index 52d2e5254..c1c016a27 100644
--- a/javax/swing/DefaultCellEditor.java
+++ b/javax/swing/DefaultCellEditor.java
@@ -43,9 +43,13 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
+import java.awt.event.MouseEvent;
import java.io.Serializable;
import java.util.EventObject;
+import javax.swing.JTable;
+import javax.swing.JTextField;
+import javax.swing.event.CellEditorListener;
import javax.swing.table.TableCellEditor;
import javax.swing.tree.TreeCellEditor;
@@ -91,8 +95,10 @@ public class DefaultCellEditor
*
* @param event TODO
*/
- public void setValue(Object event)
+ public void setValue(Object value)
{
+ // TODO: should be setting the value in the editorComp
+ this.value = value;
}
/**
@@ -102,7 +108,8 @@ public class DefaultCellEditor
*/
public Object getCellEditorValue()
{
- return null; // TODO
+ // TODO: should be getting the updated value from the editorComp
+ return value;
} // getCellEditorValue()
/**
@@ -114,7 +121,11 @@ public class DefaultCellEditor
*/
public boolean isCellEditable(EventObject event)
{
- return false; // TODO
+ if (!(event instanceof MouseEvent))
+ return true;
+
+ //Todo: if the right number of clicks has occured, return true;
+ return false;
} // isCellEditable()
/**
@@ -126,7 +137,8 @@ public class DefaultCellEditor
*/
public boolean shouldSelectCell(EventObject event)
{
- return false; // TODO
+ // return true to indicate that the editing cell may be selected
+ return true;
} // shouldSelectCell()
/**
@@ -136,7 +148,8 @@ public class DefaultCellEditor
*/
public boolean stopCellEditing()
{
- return false; // TODO
+ fireEditingStopped();
+ return true;
} // stopCellEditing()
/**
@@ -144,7 +157,7 @@ public class DefaultCellEditor
*/
public void cancelCellEditing()
{
- // TODO
+ fireEditingCanceled();
} // cancelCellEditing()
/**
@@ -156,7 +169,8 @@ public class DefaultCellEditor
*/
public boolean startCellEditing(EventObject event)
{
- return false; // TODO
+ // return true to indicate that editing has begun
+ return true;
} // startCellEditing()
/**
@@ -166,7 +180,7 @@ public class DefaultCellEditor
*/
public void actionPerformed(ActionEvent event)
{
- // TODO
+ stopCellEditing();
} // actionPerformed()
/**
@@ -176,9 +190,23 @@ public class DefaultCellEditor
*/
public void itemStateChanged(ItemEvent event)
{
- // TODO
+ stopCellEditing();
} // itemStateChanged()
+ void fireEditingStopped()
+ {
+ CellEditorListener[] listeners = getCellEditorListeners();
+ for (int index = 0; index < listeners.length; index++)
+ listeners[index].editingStopped(changeEvent);
+
+ }
+
+ void fireEditingCanceled()
+ {
+ CellEditorListener[] listeners = getCellEditorListeners();
+ for (int index = 0; index < listeners.length; index++)
+ listeners[index].editingCanceled(changeEvent);
+ }
} // EditorDelegate
/**
@@ -203,7 +231,8 @@ public class DefaultCellEditor
*/
public DefaultCellEditor(JTextField textfield)
{
- // TODO
+ editorComponent = textfield;
+ clickCountToStart = 2;
} // DefaultCellEditor()
/**
@@ -213,7 +242,8 @@ public class DefaultCellEditor
*/
public DefaultCellEditor(JCheckBox checkbox)
{
- // TODO
+ editorComponent = checkbox;
+ clickCountToStart = 1;
} // DefaultCellEditor()
/**
@@ -223,7 +253,8 @@ public class DefaultCellEditor
*/
public DefaultCellEditor(JComboBox combobox)
{
- // TODO
+ editorComponent = combobox;
+ clickCountToStart = 1;
} // DefaultCellEditor()
/**
@@ -233,7 +264,7 @@ public class DefaultCellEditor
*/
public Component getComponent()
{
- return null; // TODO
+ return editorComponent;
} // getComponent()
/**
@@ -243,7 +274,7 @@ public class DefaultCellEditor
*/
public int getClickCountToStart()
{
- return 0; // TODO
+ return clickCountToStart;
} // getClickCountToStart()
/**
@@ -253,7 +284,7 @@ public class DefaultCellEditor
*/
public void setClickCountToStart(int count)
{
- // TODO
+ clickCountToStart = count;
} // setClickCountToStart()
/**
@@ -263,7 +294,7 @@ public class DefaultCellEditor
*/
public Object getCellEditorValue()
{
- return null; // TODO
+ return delegate.getCellEditorValue();
} // getCellEditorValue()
/**
@@ -275,7 +306,7 @@ public class DefaultCellEditor
*/
public boolean isCellEditable(EventObject event)
{
- return false; // TODO
+ return delegate.isCellEditable(event);
} // isCellEditable()
/**
@@ -287,7 +318,7 @@ public class DefaultCellEditor
*/
public boolean shouldSelectCell(EventObject event)
{
- return false; // TODO
+ return delegate.shouldSelectCell(event);
} // shouldSelectCell()
/**
@@ -297,7 +328,7 @@ public class DefaultCellEditor
*/
public boolean stopCellEditing()
{
- return false; // TODO
+ return delegate.stopCellEditing();
} // stopCellEditing()
/**
@@ -305,7 +336,7 @@ public class DefaultCellEditor
*/
public void cancelCellEditing()
{
- // TODO
+ delegate.cancelCellEditing();
} // cancelCellEditing()
/**
@@ -339,10 +370,30 @@ public class DefaultCellEditor
*
* @returns Component
*/
- public Component getTableCellEditorComponent(JTable tree, Object value,
+ public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row,
int column)
{
- return null; // TODO
+ // NOTE: as specified by Sun, we don't call new() everytime, we return
+ // editorComponent on each call to getTableCellEditorComponent or
+ // getTreeCellEditorComponent. However, currently JTextFields have a
+ // problem with getting rid of old text, so without calling new() there
+ // are some strange results. If you edit more than one cell in the table
+ // text from previously edited cells may unexpectedly show up in the
+ // cell you are currently editing. This will be fixed automatically
+ // when JTextField is fixed.
+ if (editorComponent instanceof JTextField)
+ {
+ ((JTextField)editorComponent).setText(value.toString());
+ delegate = new EditorDelegate();
+ ((JTextField)editorComponent).addActionListener(delegate);
+ }
+ else
+ {
+ // TODO
+ }
+ return editorComponent;
} // getTableCellEditorComponent()
+
+
}
diff --git a/javax/swing/JTable.java b/javax/swing/JTable.java
index e683d509f..1c63c3b37 100644
--- a/javax/swing/JTable.java
+++ b/javax/swing/JTable.java
@@ -43,9 +43,14 @@ import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Date;
+import java.util.EventObject;
import java.util.Hashtable;
import java.util.Vector;
@@ -69,6 +74,7 @@ import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
+import javax.swing.text.Caret;
public class JTable extends JComponent
implements TableModelListener, Scrollable, TableColumnModelListener,
@@ -351,6 +357,7 @@ public class JTable extends JComponent
*/
protected transient Component editorComp;
+
/**
* Whether or not the table should automatically compute a matching
* {@link TableColumnModel} and assign it to the {@link #columnModel}
@@ -555,7 +562,27 @@ public class JTable extends JComponent
*/
protected JTableHeader tableHeader;
-
+ /**
+ * The row of the cell being edited.
+ */
+ int rowBeingEdited = -1;
+
+ /**
+ * The column of the cell being edited.
+ */
+ int columnBeingEdited = -1;
+
+ /**
+ * The action listener for the editor's Timer.
+ */
+ Timer editorTimer = new EditorUpdateTimer();
+
+ /**
+ * Stores the old value of a cell before it was edited, in case
+ * editing is cancelled
+ */
+ Object oldCellValue;
+
/**
* Creates a new <code>JTable</code> instance.
*/
@@ -673,6 +700,51 @@ public class JTable extends JComponent
this(new DefaultTableModel(data, columnNames));
}
+ /**
+ * The timer that updates the editor component.
+ */
+ private class EditorUpdateTimer
+ extends Timer
+ implements ActionListener
+ {
+ /**
+ * Creates a new EditorUpdateTimer object with a default delay of 0.5 seconds.
+ */
+ public EditorUpdateTimer()
+ {
+ super(500, null);
+ addActionListener(this);
+ }
+
+ /**
+ * Lets the caret blink and repaints the table.
+ */
+ public void actionPerformed(ActionEvent ev)
+ {
+ Caret c = ((JTextField)JTable.this.editorComp).getCaret();
+ if (c != null)
+ c.setVisible(!c.isVisible());
+ JTable.this.repaint();
+ }
+
+ /**
+ * Updates the blink delay according to the current caret.
+ */
+ public void update()
+ {
+ stop();
+ Caret c = ((JTextField)JTable.this.editorComp).getCaret();
+ if (c != null)
+ {
+ setDelay(c.getBlinkRate());
+ if (((JTextField)JTable.this.editorComp).isEditable())
+ start();
+ else
+ c.setVisible(false);
+ }
+ }
+ }
+
public void addColumn(TableColumn column)
{
if (column.getHeaderValue() == null)
@@ -774,11 +846,40 @@ public class JTable extends JComponent
public void editingCanceled (ChangeEvent event)
{
+ if (rowBeingEdited > -1 && columnBeingEdited > -1)
+ {
+ if (getValueAt(rowBeingEdited, columnBeingEdited) instanceof JTextField)
+ {
+ remove ((Component)getValueAt(rowBeingEdited, columnBeingEdited));
+ setValueAt(oldCellValue, rowBeingEdited, columnBeingEdited);
+ }
+ rowBeingEdited = -1;
+ columnBeingEdited = -1;
+ }
+ editorTimer.stop();
+ editorComp = null;
+ cellEditor = null;
+ requestFocusInWindow(false);
repaint();
}
public void editingStopped (ChangeEvent event)
{
+ if (rowBeingEdited > -1 && columnBeingEdited > -1)
+ {
+ if (getValueAt(rowBeingEdited, columnBeingEdited) instanceof JTextField)
+ {
+ remove((Component)getValueAt(rowBeingEdited, columnBeingEdited));
+ setValueAt(((JTextField)editorComp).getText(),
+ rowBeingEdited, columnBeingEdited);
+ }
+ rowBeingEdited = -1;
+ columnBeingEdited = -1;
+ }
+ editorTimer.stop();
+ editorComp = null;
+ cellEditor = null;
+ requestFocusInWindow(false);
repaint();
}
@@ -809,20 +910,23 @@ public class JTable extends JComponent
*/
public int columnAtPoint(Point point)
{
- int x0 = getLocation().x;
- int ncols = getColumnCount();
- Dimension gap = getIntercellSpacing();
- TableColumnModel cols = getColumnModel();
- int x = point.x;
-
- for (int i = 0; i < ncols; ++i)
+ if (point != null)
{
- int width = cols.getColumn(i).getWidth() + (gap == null ? 0 : gap.width);
- if (0 <= x && x < width)
- return i;
- x -= width;
+ int x0 = getLocation().x;
+ int ncols = getColumnCount();
+ Dimension gap = getIntercellSpacing();
+ TableColumnModel cols = getColumnModel();
+ int x = point.x;
+
+ for (int i = 0; i < ncols; ++i)
+ {
+ int width = cols.getColumn(i).getWidth()
+ + (gap == null ? 0 : gap.width);
+ if (0 <= x && x < width)
+ return i;
+ x -= width;
+ }
}
-
return -1;
}
@@ -836,19 +940,21 @@ public class JTable extends JComponent
*/
public int rowAtPoint(Point point)
{
- int y0 = getLocation().y;
- int nrows = getRowCount();
- Dimension gap = getIntercellSpacing();
- int height = getRowHeight() + (gap == null ? 0 : gap.height);
- int y = point.y;
-
- for (int i = 0; i < nrows; ++i)
+ if (point != null)
{
- if (0 <= y && y < height)
- return i;
- y -= height;
+ int y0 = getLocation().y;
+ int nrows = getRowCount();
+ Dimension gap = getIntercellSpacing();
+ int height = getRowHeight() + (gap == null ? 0 : gap.height);
+ int y = point.y;
+
+ for (int i = 0; i < nrows; ++i)
+ {
+ if (0 <= y && y < height)
+ return i;
+ y -= height;
+ }
}
-
return -1;
}
@@ -980,7 +1086,7 @@ public class JTable extends JComponent
if (editor == null)
editor = getDefaultEditor(dataModel.getColumnClass(column));
-
+
return editor;
}
@@ -1475,7 +1581,7 @@ public class JTable extends JComponent
*/
public void setRowHeight(int r)
{
- if (rowHeight < 1)
+ if (r < 1)
throw new IllegalArgumentException();
rowHeight = r;
@@ -1490,7 +1596,7 @@ public class JTable extends JComponent
* @param rh is the new rowHeight
* @param row is the row to change the rowHeight of
*/
- public void setRowHeight(int rh, int row)
+ public void setRowHeight(int row, int rh)
{
setRowHeight(rh);
// FIXME: not implemented
@@ -2116,6 +2222,11 @@ public class JTable extends JComponent
public void setValueAt(Object value, int row, int column)
{
+ if (!isCellEditable(row, column))
+ return;
+
+ if (value instanceof Component)
+ add((Component)value);
dataModel.setValueAt(value, row, convertColumnIndexToModel(column));
}
@@ -2207,4 +2318,58 @@ public class JTable extends JComponent
}
}
+
+ /**
+ * Programmatically starts editing the specified cell.
+ *
+ * @param row the row of the cell to edit.
+ * @param column the column of the cell to edit.
+ */
+ public boolean editCellAt (int row, int column)
+ {
+ oldCellValue = getValueAt(row, column);
+ setCellEditor(getCellEditor(row, column));
+ editorComp = prepareEditor(cellEditor, row, column);
+ cellEditor.addCellEditorListener(this);
+ rowBeingEdited = row;
+ columnBeingEdited = column;
+ setValueAt(editorComp, row, column);
+ ((JTextField)editorComp).requestFocusInWindow(false);
+ editorTimer.start();
+ return true;
+ }
+
+ /**
+ * Programmatically starts editing the specified cell.
+ *
+ * @param row the row of the cell to edit.
+ * @param column the column of the cell to edit.
+ */
+ public boolean editCellAt (int row, int column, EventObject e)
+ {
+ return editCellAt(row, column);
+ }
+
+ /**
+ * Discards the editor object.
+ */
+ public void removeEditor()
+ {
+ editingStopped(new ChangeEvent(this));
+ }
+
+ /**
+ * Prepares the editor by querying for the value and selection state of the
+ * cell at (row, column).
+ *
+ * @param editor the TableCellEditor to set up
+ * @param row the row of the cell to edit
+ * @param column the column of the cell to edit
+ * @return the Component being edited
+ */
+ public Component prepareEditor (TableCellEditor editor, int row, int column)
+ {
+ return editor.getTableCellEditorComponent
+ (this, getValueAt(row, column), isCellSelected(row, column), row, column);
+ }
}
diff --git a/javax/swing/JTree.java b/javax/swing/JTree.java
index 638f28ff3..e5de57550 100644
--- a/javax/swing/JTree.java
+++ b/javax/swing/JTree.java
@@ -775,16 +775,17 @@ public class JTree
{
if (treeModel == model)
return;
-
- TreeModel oldValue = treeModel;
- treeModel = model;
-
- firePropertyChange(TREE_MODEL_PROPERTY, oldValue, model);
-
+
// add treeModelListener to the new model
if (treeModelListener == null)
treeModelListener = createTreeModelListener();
- model.addTreeModelListener(treeModelListener);
+ if (model != null) // as setModel(null) is allowed
+ model.addTreeModelListener(treeModelListener);
+
+ TreeModel oldValue = treeModel;
+ treeModel = model;
+
+ firePropertyChange(TREE_MODEL_PROPERTY, oldValue, model);
}
/**
@@ -1296,7 +1297,7 @@ public class JTree
// Don't expand if last path component is a leaf node.
if ((path == null) || (treeModel.isLeaf(path.getLastPathComponent())))
return;
-
+
setExpandedState(path, true);
}
@@ -1502,21 +1503,9 @@ public class JTree
return null;
}
- private void checkExpandParents(TreePath path) throws ExpandVetoException
- {
-
- TreePath parent = path.getParentPath();
-
- if (parent != null)
- checkExpandParents(parent);
-
- fireTreeWillExpand(path);
- }
-
private void doExpandParents(TreePath path, boolean state)
{
- TreePath parent = path.getParentPath();
-
+ TreePath parent = path.getParentPath();
if (isExpanded(parent))
{
nodeStates.put(path, state ? EXPANDED : COLLAPSED);
@@ -1536,17 +1525,6 @@ public class JTree
TreePath parent = path.getParentPath();
- try
- {
- if (parent != null)
- checkExpandParents(parent);
- }
- catch (ExpandVetoException e)
- {
- // Expansion vetoed.
- return;
- }
-
doExpandParents(path, state);
}
diff --git a/javax/swing/plaf/basic/BasicLabelUI.java b/javax/swing/plaf/basic/BasicLabelUI.java
index e71e82f03..16c132dfc 100644
--- a/javax/swing/plaf/basic/BasicLabelUI.java
+++ b/javax/swing/plaf/basic/BasicLabelUI.java
@@ -1,39 +1,39 @@
/* BasicLabelUI.java
- Copyright (C) 2002, 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., 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. */
+ Copyright (C) 2002, 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., 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.basic;
@@ -56,12 +56,13 @@ import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.LabelUI;
-
/**
* This is the Basic Look and Feel class for the JLabel. One BasicLabelUI
* object is used to paint all JLabels that utilize the Basic Look and Feel.
*/
-public class BasicLabelUI extends LabelUI implements PropertyChangeListener
+public class BasicLabelUI
+ extends LabelUI
+ implements PropertyChangeListener
{
/** The labelUI that is shared by all labels. */
protected static BasicLabelUI labelUI;
@@ -99,20 +100,20 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
*
* @return The preferred size.
*/
- public Dimension getPreferredSize(JComponent c)
+ public Dimension getPreferredSize(JComponent c)
{
- JLabel lab = (JLabel)c;
+ JLabel lab = (JLabel) c;
Rectangle vr = new Rectangle();
Rectangle ir = new Rectangle();
Rectangle tr = new Rectangle();
- Insets insets = lab.getInsets();
+ Insets insets = lab.getInsets();
FontMetrics fm = lab.getToolkit().getFontMetrics(lab.getFont());
layoutCL(lab, fm, lab.getText(), lab.getIcon(), vr, ir, tr);
Rectangle cr = tr.union(ir);
- return new Dimension(insets.left + cr.width + insets.right,
- insets.top + cr.height + insets.bottom);
-
- }
+ return new Dimension(insets.left + cr.width + insets.right, insets.top
+ + cr.height + insets.bottom);
+
+ }
/**
* This method returns the minimum size of the {@link JComponent} given. If
@@ -144,7 +145,7 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
/**
* The method that paints the label according to its current state.
- *
+ *
* @param g The {@link Graphics} object to paint with.
* @param c The {@link JComponent} to paint.
*/
@@ -169,26 +170,39 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
vr.width = 0;
if (vr.height < 0)
vr.height = 0;
-
+
Icon icon = (b.isEnabled()) ? b.getIcon() : b.getDisabledIcon();
String text = layoutCL(b, fm, b.getText(), icon, vr, ir, tr);
-
+
if (icon != null)
- icon.paintIcon(b, g, ir.x, ir.y);
- if (text != null && ! text.equals(""))
+ icon.paintIcon(b, g, ir.x, ir.y);
+ if (text != null && !text.equals(""))
+ {
+ g.setColor(b.getBackground());
+
+ if (b.isOpaque())
+ g.fillRect(vr.x, vr.y, vr.width, vr.height);
+ else
{
- if (b.isEnabled())
- paintEnabledText(b, g, text, tr.x, tr.y + fm.getAscent());
- else
- paintDisabledText(b, g, text, tr.x, tr.y + fm.getAscent());
+ g.fillRect(tr.x, tr.y, tr.width, tr.height);
+ if (b.getBorder() != null)
+ b.getBorder().paintBorder(b, g, tr.x, tr.y, tr.width, tr.height);
+ b.setBorder(null);
}
+
+ if (b.isEnabled())
+ paintEnabledText(b, g, text, tr.x, tr.y + fm.getAscent());
+ else
+ paintDisabledText(b, g, text, tr.x, tr.y + fm.getAscent());
+ }
+
g.setFont(saved_font);
}
/**
* This method is simply calls SwingUtilities's layoutCompoundLabel.
- *
+ *
* @param label The label to lay out.
* @param fontMetrics The FontMetrics for the font used.
* @param text The text to paint.
@@ -196,20 +210,16 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
* @param viewR The entire viewable rectangle.
* @param iconR The icon bounds rectangle.
* @param textR The text bounds rectangle.
- *
+ *
* @return A possibly clipped version of the text.
*/
- protected String layoutCL(JLabel label, FontMetrics fontMetrics,
- String text, Icon icon, Rectangle viewR,
- Rectangle iconR, Rectangle textR)
+ protected String layoutCL(JLabel label, FontMetrics fontMetrics, String text,
+ Icon icon, Rectangle viewR, Rectangle iconR, Rectangle textR)
{
return SwingUtilities.layoutCompoundLabel(label, fontMetrics, text, icon,
- label.getVerticalAlignment(),
- label.getHorizontalAlignment(),
- label.getVerticalTextPosition(),
- label.getHorizontalTextPosition(),
- viewR, iconR, textR,
- label.getIconTextGap());
+ label.getVerticalAlignment(), label.getHorizontalAlignment(), label
+ .getVerticalTextPosition(), label.getHorizontalTextPosition(),
+ viewR, iconR, textR, label.getIconTextGap());
}
/**
@@ -225,7 +235,7 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
* @param textY The y coordinate of the start of the baseline.
*/
protected void paintDisabledText(JLabel l, Graphics g, String s, int textX,
- int textY)
+ int textY)
{
Color saved_color = g.getColor();
@@ -235,14 +245,14 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
if (mnemIndex != -1)
BasicGraphicsUtils.drawStringUnderlineCharAt(g, s, mnemIndex, textX,
- textY);
+ textY);
else
g.drawString(s, textX, textY);
g.setColor(l.getBackground().darker());
if (mnemIndex != -1)
BasicGraphicsUtils.drawStringUnderlineCharAt(g, s, mnemIndex, textX + 1,
- textY + 1);
+ textY + 1);
else
g.drawString(s, textX + 1, textY + 1);
@@ -260,7 +270,7 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
* @param textY The y coordinate of the start of the baseline.
*/
protected void paintEnabledText(JLabel l, Graphics g, String s, int textX,
- int textY)
+ int textY)
{
Color saved_color = g.getColor();
g.setColor(l.getForeground());
@@ -269,7 +279,7 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
if (mnemIndex != -1)
BasicGraphicsUtils.drawStringUnderlineCharAt(g, s, mnemIndex, textX,
- textY);
+ textY);
else
g.drawString(s, textX, textY);
@@ -287,14 +297,14 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
{
super.installUI(c);
if (c instanceof JLabel)
- {
- JLabel l = (JLabel) c;
-
- installComponents(l);
- installDefaults(l);
- installListeners(l);
- installKeyboardActions(l);
- }
+ {
+ JLabel l = (JLabel) c;
+
+ installComponents(l);
+ installDefaults(l);
+ installListeners(l);
+ installKeyboardActions(l);
+ }
}
/**
@@ -308,14 +318,14 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
{
super.uninstallUI(c);
if (c instanceof JLabel)
- {
- JLabel l = (JLabel) c;
-
- uninstallKeyboardActions(l);
- uninstallListeners(l);
- uninstallDefaults(l);
- uninstallComponents(l);
- }
+ {
+ JLabel l = (JLabel) c;
+
+ uninstallKeyboardActions(l);
+ uninstallListeners(l);
+ uninstallDefaults(l);
+ uninstallComponents(l);
+ }
}
/**
diff --git a/javax/swing/plaf/basic/BasicLookAndFeel.java b/javax/swing/plaf/basic/BasicLookAndFeel.java
index 2161d5d97..3d84e5ad3 100644
--- a/javax/swing/plaf/basic/BasicLookAndFeel.java
+++ b/javax/swing/plaf/basic/BasicLookAndFeel.java
@@ -886,13 +886,24 @@ public abstract class BasicLookAndFeel extends LookAndFeel
"shift KP_DOWN", "selectNextRowExtendSelection",
"shift KP_LEFT", "selectPreviousColumnExtendSelection",
"ESCAPE", "cancel",
- "ctrl shift PAGE_UP", "scrollRightExtendSelection",
+ "ctrl shift PAGE_UP", "scrollLeftExtendSelection",
"shift KP_RIGHT", " selectNextColumnExtendSelection",
"ctrl PAGE_UP", "scrollLeftChangeSelection",
"shift PAGE_UP", "scrollUpExtendSelection",
- "ctrl shift PAGE_DOWN", "scrollLeftExtendSelection",
+ "ctrl shift PAGE_DOWN", "scrollRightExtendSelection",
"ctrl PAGE_DOWN", "scrollRightChangeSelection",
- "PAGE_UP", "scrollUpChangeSelection"
+ "PAGE_UP", "scrollUpChangeSelection",
+ "ctrl shift LEFT", "selectPreviousColumnExtendSelection",
+ "shift KP_UP", "selectPreviousRowExtendSelection",
+ "ctrl shift UP", "selectPreviousRowExtendSelection",
+ "ctrl shift RIGHT", "selectNextColumnExtendSelection",
+ "ctrl shift KP_RIGHT", "selectNextColumnExtendSelection",
+ "ctrl shift DOWN", "selectNextRowExtendSelection",
+ "ctrl BACK_SLASH", "clearSelection",
+ "ctrl shift KP_UP", "selectPreviousRowExtendSelection",
+ "ctrl shift KP_LEFT", "selectPreviousColumnExtendSelection",
+ "ctrl SLASH", "selectAll",
+ "ctrl shift KP_DOWN", "selectNextRowExtendSelection",
}),
"Table.background", new ColorUIResource(light),
"Table.focusCellBackground", new ColorUIResource(light),
diff --git a/javax/swing/plaf/basic/BasicSplitPaneUI.java b/javax/swing/plaf/basic/BasicSplitPaneUI.java
index ff7e8acfb..fd7224757 100644
--- a/javax/swing/plaf/basic/BasicSplitPaneUI.java
+++ b/javax/swing/plaf/basic/BasicSplitPaneUI.java
@@ -1337,9 +1337,11 @@ public class BasicSplitPaneUI extends SplitPaneUI
*/
public int getMinimumDividerLocation(JSplitPane jc)
{
- int value = layoutManager.getInitialLocation(jc.getInsets());
- if (layoutManager.components[0] != null)
- value += layoutManager.minimumSizeOfComponent(0);
+ int value = layoutManager.getInitialLocation(jc.getInsets())
+ - layoutManager.getAvailableSize(jc.getSize(), jc.getInsets())
+ + splitPane.getDividerSize();
+ if (layoutManager.components[1] != null)
+ value += layoutManager.minimumSizeOfComponent(1);
return value;
}
diff --git a/javax/swing/plaf/basic/BasicTableUI.java b/javax/swing/plaf/basic/BasicTableUI.java
index d13373008..9312d13dc 100644
--- a/javax/swing/plaf/basic/BasicTableUI.java
+++ b/javax/swing/plaf/basic/BasicTableUI.java
@@ -45,6 +45,7 @@ import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.InputEvent;
@@ -52,14 +53,19 @@ import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
+import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.CellRendererPane;
+import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JTable;
+import javax.swing.JTextField;
+import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border;
+import javax.swing.event.ChangeEvent;
import javax.swing.event.MouseInputListener;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.TableUI;
@@ -87,6 +93,9 @@ public class BasicTableUI
/** The cell border for selected/highlighted cells. */
Border highlightCellBorder;
+ /** The action bound to KeyStrokes. */
+ TableAction action;
+
class FocusHandler implements FocusListener
{
public void focusGained(FocusEvent e)
@@ -97,174 +106,202 @@ public class BasicTableUI
}
}
- class KeyHandler implements KeyListener
+ class MouseInputHandler implements MouseInputListener
{
+ Point begin, curr;
- /**
- * A helper method for the keyPressed event. Used because the actions
- * for TAB, SHIFT-TAB, ENTER, and SHIFT-ENTER are very similar.
- *
- * Selects the next (previous if SHIFT pressed) column for TAB, or row for
- * ENTER from within the currently selected cells.
- *
- * @param firstModel the ListSelectionModel for columns (TAB) or
- * rows (ENTER)
- * @param firstMin the first selected index in firstModel
- * @param firstMax the last selected index in firstModel
- * @param secondModel the ListSelectionModel for rows (TAB) or
- * columns (ENTER)
- * @param secondMin the first selected index in secondModel
- * @param secondMax the last selected index in secondModel
- * @param reverse true if shift was held for the event
- * @param eventIsTab true if TAB was pressed, false if ENTER pressed
- */
- void advanceMultipleSelection (ListSelectionModel firstModel, int firstMin,
- int firstMax, ListSelectionModel secondModel,
- int secondMin, int secondMax, boolean reverse,
- boolean eventIsTab)
+ private void updateSelection(boolean controlPressed)
{
- // If eventIsTab, all the "firsts" correspond to columns, otherwise, to rows
- // "seconds" correspond to the opposite
- int firstLead = firstModel.getLeadSelectionIndex();
- int secondLead = secondModel.getLeadSelectionIndex();
- int numFirsts = eventIsTab ?
- table.getModel().getColumnCount() : table.getModel().getRowCount();
- int numSeconds = eventIsTab ?
- table.getModel().getRowCount() : table.getModel().getColumnCount();
-
- // check if we have to wrap the "firsts" around, going to the other side
- if ((firstLead == firstMax && !reverse) ||
- (reverse && firstLead == firstMin))
+ // Update the rows
+ int lo_row = table.rowAtPoint(begin);
+ int hi_row = table.rowAtPoint(curr);
+ ListSelectionModel rowModel = table.getSelectionModel();
+ if (lo_row != -1 && hi_row != -1)
{
- firstModel.addSelectionInterval(reverse ? firstMax : firstMin,
- reverse ? firstMax : firstMin);
-
- // check if we have to wrap the "seconds"
- if ((secondLead == secondMax && !reverse) ||
- (reverse && secondLead == secondMin))
- secondModel.addSelectionInterval(reverse ? secondMax : secondMin,
- reverse ? secondMax : secondMin);
-
- // if we're not wrapping the seconds, we have to find out where we
- // are within the secondModel and advance to the next cell (or
- // go back to the previous cell if reverse == true)
+ if (controlPressed && rowModel.getSelectionMode()
+ != ListSelectionModel.SINGLE_SELECTION)
+ rowModel.addSelectionInterval(lo_row, hi_row);
else
- {
- int[] secondsSelected;
- if (eventIsTab && table.getRowSelectionAllowed() ||
- !eventIsTab && table.getColumnSelectionAllowed())
- secondsSelected = eventIsTab ?
- table.getSelectedRows() : table.getSelectedColumns();
- else
- {
- // if row selection is not allowed, then the entire column gets
- // selected when you click on it, so consider ALL rows selected
- secondsSelected = new int[numSeconds];
- for (int i = 0; i < numSeconds; i++)
- secondsSelected[i] = i;
- }
-
- // and now find the "next" index within the model
- int secondIndex = reverse ? secondsSelected.length - 1 : 0;
- if (!reverse)
- while (secondsSelected[secondIndex] <= secondLead)
- secondIndex++;
- else
- while (secondsSelected[secondIndex] >= secondLead)
- secondIndex--;
-
- // and select it - updating the lead selection index
- secondModel.addSelectionInterval(secondsSelected[secondIndex],
- secondsSelected[secondIndex]);
- }
+ rowModel.setSelectionInterval(lo_row, hi_row);
}
- // We didn't have to wrap the firsts, so just find the "next" first
- // and select it, we don't have to change "seconds"
- else
+
+ // Update the columns
+ int lo_col = table.columnAtPoint(begin);
+ int hi_col = table.columnAtPoint(curr);
+ ListSelectionModel colModel = table.getColumnModel().
+ getSelectionModel();
+ if (lo_col != -1 && hi_col != -1)
{
- int[] firstsSelected;
- if (eventIsTab && table.getColumnSelectionAllowed() ||
- !eventIsTab && table.getRowSelectionAllowed())
- firstsSelected = eventIsTab ?
- table.getSelectedColumns() : table.getSelectedRows();
+ if (controlPressed && colModel.getSelectionMode() !=
+ ListSelectionModel.SINGLE_SELECTION)
+ colModel.addSelectionInterval(lo_col, hi_col);
else
- {
- // if selection not allowed, consider ALL firsts to be selected
- firstsSelected = new int[numFirsts];
- for (int i = 0; i < numFirsts; i++)
- firstsSelected[i] = i;
- }
- int firstIndex = reverse ? firstsSelected.length - 1 : 0;
- if (!reverse)
- while (firstsSelected[firstIndex] <= firstLead)
- firstIndex++;
- else
- while (firstsSelected[firstIndex] >= firstLead)
- firstIndex--;
- firstModel.addSelectionInterval(firstsSelected[firstIndex],
- firstsSelected[firstIndex]);
- secondModel.addSelectionInterval(secondLead, secondLead);
+ colModel.setSelectionInterval(lo_col, hi_col);
}
}
-
- /**
- * A helper method for the keyPressed event. Used because the actions
- * for TAB, SHIFT-TAB, ENTER, and SHIFT-ENTER are very similar.
- *
- * Selects the next (previous if SHIFT pressed) column (TAB) or row (ENTER)
- * in the table, changing the current selection. All cells in the table
- * are eligible, not just the ones that are currently selected.
- * @param firstModel the ListSelectionModel for columns (TAB) or rows
- * (ENTER)
- * @param firstMax the last index in firstModel
- * @param secondModel the ListSelectionModel for rows (TAB) or columns
- * (ENTER)
- * @param secondMax the last index in secondModel
- * @param reverse true if SHIFT was pressed for the event
- */
- void advanceSingleSelection (ListSelectionModel firstModel, int firstMax,
- ListSelectionModel secondModel, int secondMax,
- boolean reverse)
+ public void mouseClicked(MouseEvent e)
{
- // for TABs, "first" corresponds to columns and "seconds" to rows.
- // the opposite is true for ENTERs
- int firstLead = firstModel.getLeadSelectionIndex();
- int secondLead = secondModel.getLeadSelectionIndex();
-
- // if we are going backwards subtract 2 because we later add 1
- // for a net change of -1
- if (reverse && (firstLead == 0))
- {
- // check if we have to wrap around
- if (secondLead == 0)
- secondLead += secondMax + 1;
- secondLead -= 2;
+ }
+ public void mouseDragged(MouseEvent e)
+ {
+ curr = new Point(e.getX(), e.getY());
+ updateSelection(e.isControlDown());
+ }
+ public void mouseEntered(MouseEvent e)
+ {
+ }
+ public void mouseExited(MouseEvent e)
+ {
+ }
+ public void mouseMoved(MouseEvent e)
+ {
+ }
+ public void mousePressed(MouseEvent e)
+ {
+ ListSelectionModel rowModel = table.getSelectionModel();
+ ListSelectionModel colModel = table.getColumnModel().getSelectionModel();
+ int rowLead = rowModel.getLeadSelectionIndex();
+ int colLead = colModel.getLeadSelectionIndex();
+
+ begin = new Point(e.getX(), e.getY());
+ curr = new Point(e.getX(), e.getY());
+ //if control is pressed and the cell is already selected, deselect it
+ if (e.isControlDown() && table.
+ isCellSelected(table.rowAtPoint(begin),table.columnAtPoint(begin)))
+ {
+ table.getSelectionModel().
+ removeSelectionInterval(table.rowAtPoint(begin),
+ table.rowAtPoint(begin));
+ table.getColumnModel().getSelectionModel().
+ removeSelectionInterval(table.columnAtPoint(begin),
+ table.columnAtPoint(begin));
}
-
- // do we have to wrap the "seconds"?
- if (reverse && (firstLead == 0) || !reverse && (firstLead == firstMax))
- secondModel.setSelectionInterval((secondLead + 1)%(secondMax + 1),
- (secondLead + 1)%(secondMax + 1));
- // if not, just reselect the current lead
else
- secondModel.setSelectionInterval(secondLead, secondLead);
-
- // if we are going backwards, subtract 2 because we add 1 later
- // for net change of -1
- if (reverse)
- {
- // check for wraparound
- if (firstLead == 0)
- firstLead += firstMax + 1;
- firstLead -= 2;
- }
- // select the next "first"
- firstModel.setSelectionInterval ((firstLead + 1)%(firstMax + 1),
- (firstLead + 1)%(firstMax + 1));
+ updateSelection(e.isControlDown());
+
+ // If we were editing, but the moved to another cell, stop editing
+ if (rowLead != rowModel.getLeadSelectionIndex() ||
+ colLead != colModel.getLeadSelectionIndex())
+ if (table.isEditing())
+ table.editingStopped(new ChangeEvent(e));
+ }
+ public void mouseReleased(MouseEvent e)
+ {
+ begin = null;
+ curr = null;
}
+ }
+
+ protected FocusListener createFocusListener()
+ {
+ return new FocusHandler();
+ }
+
+ protected MouseInputListener createMouseInputListener()
+ {
+ return new MouseInputHandler();
+ }
+
+ public Dimension getMaximumSize(JComponent comp)
+ {
+ return getPreferredSize(comp);
+ }
+
+ public Dimension getMinimumSize(JComponent comp)
+ {
+ return getPreferredSize(comp);
+ }
+
+ public Dimension getPreferredSize(JComponent comp)
+ {
+ int width = table.getColumnModel().getTotalColumnWidth();
+ int height = table.getRowCount() * table.getRowHeight();
+ return new Dimension(width, height);
+ }
- public void keyPressed(KeyEvent evt)
+ protected void installDefaults()
+ {
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+ table.setFont(defaults.getFont("Table.font"));
+ table.setGridColor(defaults.getColor("Table.gridColor"));
+ table.setForeground(defaults.getColor("Table.foreground"));
+ table.setBackground(defaults.getColor("Table.background"));
+ table.setSelectionForeground(defaults.getColor("Table.selectionForeground"));
+ table.setSelectionBackground(defaults.getColor("Table.selectionBackground"));
+ table.setOpaque(true);
+
+ highlightCellBorder = defaults.getBorder("Table.focusCellHighlightBorder");
+ cellBorder = BorderFactory.createEmptyBorder(1, 1, 1, 1);
+ }
+
+ private int convertModifiers(int mod)
+ {
+ if ((mod & KeyEvent.SHIFT_DOWN_MASK) != 0)
+ {
+ mod |= KeyEvent.SHIFT_MASK;
+ mod &= ~KeyEvent.SHIFT_DOWN_MASK;
+ }
+ if ((mod & KeyEvent.CTRL_DOWN_MASK) != 0)
+ {
+ mod |= KeyEvent.CTRL_MASK;
+ mod &= ~KeyEvent.CTRL_DOWN_MASK;
+ }
+ if ((mod & KeyEvent.META_DOWN_MASK) != 0)
+ {
+ mod |= KeyEvent.META_MASK;
+ mod &= ~KeyEvent.META_DOWN_MASK;
+ }
+ if ((mod & KeyEvent.ALT_DOWN_MASK) != 0)
+ {
+ mod |= KeyEvent.ALT_MASK;
+ mod &= ~KeyEvent.ALT_DOWN_MASK;
+ }
+ if ((mod & KeyEvent.ALT_GRAPH_DOWN_MASK) != 0)
+ {
+ mod |= KeyEvent.ALT_GRAPH_MASK;
+ mod &= ~KeyEvent.ALT_GRAPH_DOWN_MASK;
+ }
+ return mod;
+ }
+
+ protected void installKeyboardActions()
+ {
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+ InputMap ancestorMap = (InputMap)defaults.get("Table.ancestorInputMap");
+ action = new TableAction();
+ Object keys[] = ancestorMap.allKeys();
+ // Register the key bindings with the JTable.
+ // Note that we register key bindings with both the old and new modifier
+ // masks: InputEvent.SHIFT_MASK and InputEvent.SHIFT_DOWN_MASK and so on.
+ for (int i = 0; i < keys.length; i++)
+ {
+ table.registerKeyboardAction(action,(String)ancestorMap.get((KeyStroke)keys[i]),
+ KeyStroke.getKeyStroke
+ (((KeyStroke)keys[i]).getKeyCode(), convertModifiers(((KeyStroke)keys[i]).getModifiers())),
+ JComponent.WHEN_FOCUSED);
+
+ table.registerKeyboardAction(action,(String)ancestorMap.get((KeyStroke)keys[i]),
+ KeyStroke.getKeyStroke
+ (((KeyStroke)keys[i]).getKeyCode(), ((KeyStroke)keys[i]).getModifiers()),
+ JComponent.WHEN_FOCUSED);
+ }
+ }
+
+ /**
+ * This class implements the actions that we want to happen
+ * when specific keys are pressed for the JTable. The actionPerformed
+ * method is called when a key that has been registered for the JTable
+ * is received.
+ */
+ class TableAction extends AbstractAction
+ {
+ /**
+ * What to do when this action is called.
+ *
+ * @param e the ActionEvent that caused this action.
+ */
+ public void actionPerformed (ActionEvent e)
{
ListSelectionModel rowModel = table.getSelectionModel();
ListSelectionModel colModel = table.getColumnModel().getSelectionModel();
@@ -275,224 +312,141 @@ public class BasicTableUI
int colLead = colModel.getLeadSelectionIndex();
int colMax = table.getModel().getColumnCount() - 1;
- if ((evt.getKeyCode() == KeyEvent.VK_DOWN)
- || (evt.getKeyCode() == KeyEvent.VK_KP_DOWN))
+ if (e.getActionCommand().equals("selectPreviousRowExtendSelection"))
{
- if (evt.getModifiers() == 0)
- {
-
- table.clearSelection();
- rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax),
- Math.min(rowLead + 1, rowMax));
- colModel.setSelectionInterval(colLead,colLead);
- }
- else if (evt.getModifiers() == InputEvent.SHIFT_MASK)
- {
- rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax));
- colModel.setLeadSelectionIndex(colLead);
- }
+ rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0));
+ colModel.setLeadSelectionIndex(colLead);
}
- else if ((evt.getKeyCode() == KeyEvent.VK_UP)
- || (evt.getKeyCode() == KeyEvent.VK_KP_UP))
+ else if (e.getActionCommand().equals("selectLastColumn"))
{
- if (evt.getModifiers() == 0)
- {
- table.clearSelection();
- rowModel.setSelectionInterval(Math.max(rowLead - 1, 0),
- Math.max(rowLead - 1, 0));
- colModel.setSelectionInterval(colLead,colLead);
- }
- else if (evt.getModifiers() == InputEvent.SHIFT_MASK)
- {
- rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0));
- colModel.setLeadSelectionIndex(colLead);
- }
+ table.clearSelection();
+ rowModel.setSelectionInterval(rowLead, rowLead);
+ colModel.setSelectionInterval(colMax, colMax);
}
- else if ((evt.getKeyCode() == KeyEvent.VK_LEFT)
- || (evt.getKeyCode() == KeyEvent.VK_KP_LEFT))
+ else if (e.getActionCommand().equals("startEditing"))
{
- if (evt.getModifiers() == InputEvent.SHIFT_MASK)
- {
- colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0));
- rowModel.setLeadSelectionIndex(rowLead);
- }
- else if (evt.getModifiers() == 0)
- {
- table.clearSelection();
- rowModel.setSelectionInterval(rowLead,rowLead);
- colModel.setSelectionInterval(Math.max(colLead - 1, 0),
- Math.max(colLead - 1, 0));
- }
+ if (table.isCellEditable(rowLead, colLead))
+ table.editCellAt(rowLead,colLead);
+ }
+ else if (e.getActionCommand().equals("selectFirstRowExtendSelection"))
+ {
+ rowModel.setLeadSelectionIndex(0);
+ colModel.setLeadSelectionIndex(colLead);
}
- else if ((evt.getKeyCode() == KeyEvent.VK_RIGHT)
- || (evt.getKeyCode() == KeyEvent.VK_KP_RIGHT))
+ else if (e.getActionCommand().equals("selectFirstColumn"))
{
- if (evt.getModifiers() == InputEvent.SHIFT_MASK)
- {
- colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax));
- rowModel.setLeadSelectionIndex(rowLead);
- }
- else if (evt.getModifiers() == 0)
- {
- table.clearSelection();
- rowModel.setSelectionInterval(rowLead,rowLead);
- colModel.setSelectionInterval(Math.min(colLead + 1, colMax),
- Math.min(colLead + 1, colMax));
- }
+ rowModel.setSelectionInterval(rowLead, rowLead);
+ colModel.setSelectionInterval(0, 0);
}
- else if (evt.getKeyCode() == KeyEvent.VK_END)
+ else if (e.getActionCommand().equals("selectFirstColumnExtendSelection"))
{
- if (evt.getModifiers() == (InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK))
- {
- rowModel.setLeadSelectionIndex(rowMax);
- colModel.setLeadSelectionIndex(colLead);
- }
- else if (evt.getModifiers() == InputEvent.CTRL_MASK)
- {
- table.clearSelection();
- rowModel.setSelectionInterval(rowMax,rowMax);
- colModel.setSelectionInterval(colLead, colLead);
- }
- else if (evt.getModifiers() == InputEvent.SHIFT_MASK)
- {
- colModel.setLeadSelectionIndex(colMax);
- rowModel.setLeadSelectionIndex(rowLead);
- }
- else if (evt.getModifiers() == 0)
- {
- table.clearSelection();
- rowModel.setSelectionInterval(rowLead, rowLead);
- colModel.setSelectionInterval(colMax, colMax);
- }
+ colModel.setLeadSelectionIndex(0);
+ rowModel.setLeadSelectionIndex(rowLead);
}
- else if (evt.getKeyCode() == KeyEvent.VK_HOME)
+ else if (e.getActionCommand().equals("selectLastRow"))
{
- if (evt.getModifiers() ==
- (InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK))
- {
- rowModel.setLeadSelectionIndex(0);
- colModel.setLeadSelectionIndex(colLead);
- }
- else if (evt.getModifiers() == InputEvent.CTRL_MASK)
- {
- table.clearSelection();
- rowModel.setSelectionInterval(0,0);
- colModel.setSelectionInterval(colLead, colLead);
- }
- else if (evt.getModifiers() == InputEvent.SHIFT_MASK)
- {
- colModel.setLeadSelectionIndex(0);
- rowModel.setLeadSelectionIndex(rowLead);
- }
- else if (evt.getModifiers() == 0)
- {
- table.clearSelection();
- rowModel.setSelectionInterval(rowLead, rowLead);
- colModel.setSelectionInterval(0, 0);
- }
+ rowModel.setSelectionInterval(rowMax,rowMax);
+ colModel.setSelectionInterval(colLead, colLead);
+ }
+ else if (e.getActionCommand().equals("selectNextRowExtendSelection"))
+ {
+ rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax));
+ colModel.setLeadSelectionIndex(colLead);
+ }
+ else if (e.getActionCommand().equals("selectFirstRow"))
+ {
+ rowModel.setSelectionInterval(0,0);
+ colModel.setSelectionInterval(colLead, colLead);
+ }
+ else if (e.getActionCommand().equals("selectNextColumnExtendSelection"))
+ {
+ colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax));
+ rowModel.setLeadSelectionIndex(rowLead);
+ }
+ else if (e.getActionCommand().equals("selectLastColumnExtendSelection"))
+ {
+ colModel.setLeadSelectionIndex(colMax);
+ rowModel.setLeadSelectionIndex(rowLead);
}
- else if (evt.getKeyCode() == KeyEvent.VK_F2)
+ else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection"))
{
- // FIXME: Implement "start editing"
+ colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0));
+ rowModel.setLeadSelectionIndex(rowLead);
}
- else if (evt.getKeyCode() == KeyEvent.VK_PAGE_UP)
+ else if (e.getActionCommand().equals("selectNextRow"))
+ {
+ rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax),
+ Math.min(rowLead + 1, rowMax));
+ colModel.setSelectionInterval(colLead,colLead);
+ }
+ else if (e.getActionCommand().equals("scrollUpExtendSelection"))
{
int target;
- if (!evt.isControlDown())
- {
- if (rowLead == getFirstVisibleRowIndex())
- target = Math.max
- (0, rowLead - (getLastVisibleRowIndex() -
- getFirstVisibleRowIndex() + 1));
- else
- target = getFirstVisibleRowIndex();
-
- if (evt.getModifiers() == 0)
- {
- rowModel.setSelectionInterval(target, target);
- colModel.setSelectionInterval(colLead, colLead);
- }
- else if (evt.getModifiers() == InputEvent.SHIFT_MASK)
- {
- rowModel.setLeadSelectionIndex(target);
- colModel.setLeadSelectionIndex(colLead);
- }
- }
+ if (rowLead == getFirstVisibleRowIndex())
+ target = Math.max
+ (0, rowLead - (getLastVisibleRowIndex() -
+ getFirstVisibleRowIndex() + 1));
else
- {
- if (colLead == getFirstVisibleColumnIndex())
- target = Math.max
- (0, colLead - (getLastVisibleColumnIndex() -
- getFirstVisibleColumnIndex() + 1));
- else
- target = getFirstVisibleColumnIndex();
-
- if (evt.getModifiers() == InputEvent.CTRL_MASK)
- {
- colModel.setSelectionInterval(target, target);
- rowModel.setSelectionInterval(rowLead, rowLead);
- }
- else if (evt.getModifiers() ==
- (InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK))
- {
- colModel.setLeadSelectionIndex(target);
- rowModel.setLeadSelectionIndex(rowLead);
- }
- }
+ target = getFirstVisibleRowIndex();
+
+ rowModel.setLeadSelectionIndex(target);
+ colModel.setLeadSelectionIndex(colLead);
+ }
+ else if (e.getActionCommand().equals("selectPreviousRow"))
+ {
+ rowModel.setSelectionInterval(Math.max(rowLead - 1, 0),
+ Math.max(rowLead - 1, 0));
+ colModel.setSelectionInterval(colLead,colLead);
}
- else if (evt.getKeyCode() == KeyEvent.VK_PAGE_DOWN)
+ else if (e.getActionCommand().equals("scrollRightChangeSelection"))
{
int target;
- if (!evt.isControlDown())
- {
- if (rowLead == getLastVisibleRowIndex())
- target = Math.min
- (rowMax, rowLead + (getLastVisibleRowIndex() -
- getFirstVisibleRowIndex() + 1));
- else
- target = getLastVisibleRowIndex();
-
- if (evt.getModifiers() == 0)
- {
- rowModel.setSelectionInterval(target, target);
- colModel.setSelectionInterval(colLead, colLead);
- }
- else if (evt.getModifiers() == InputEvent.SHIFT_MASK)
- {
- rowModel.setLeadSelectionIndex(target);
- colModel.setLeadSelectionIndex(colLead);
- }
- }
+ if (colLead == getLastVisibleColumnIndex())
+ target = Math.min
+ (colMax, colLead + (getLastVisibleColumnIndex() -
+ getFirstVisibleColumnIndex() + 1));
else
- {
- if (colLead == getLastVisibleColumnIndex())
- target = Math.min
- (colMax, colLead + (getLastVisibleColumnIndex() -
- getFirstVisibleColumnIndex() + 1));
- else
- target = getLastVisibleColumnIndex();
-
- if (evt.getModifiers() == InputEvent.CTRL_MASK)
- {
- colModel.setSelectionInterval(target, target);
- rowModel.setSelectionInterval(rowLead, rowLead);
- }
- else if (evt.getModifiers() ==
- (InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK))
- {
- colModel.setLeadSelectionIndex(target);
- rowModel.setLeadSelectionIndex(rowLead);
- }
- }
+ target = getLastVisibleColumnIndex();
+
+ colModel.setSelectionInterval(target, target);
+ rowModel.setSelectionInterval(rowLead, rowLead);
+ }
+ else if (e.getActionCommand().equals("selectPreviousColumn"))
+ {
+ rowModel.setSelectionInterval(rowLead,rowLead);
+ colModel.setSelectionInterval(Math.max(colLead - 1, 0),
+ Math.max(colLead - 1, 0));
}
- else if (evt.getKeyCode() == KeyEvent.VK_TAB
- || evt.getKeyCode() == KeyEvent.VK_ENTER)
+ else if (e.getActionCommand().equals("scrollLeftChangeSelection"))
{
- // If modifers other than SHIFT are pressed, do nothing
- if (evt.getModifiers() != 0 && evt.getModifiers() !=
- InputEvent.SHIFT_MASK)
- return;
+ int target;
+ if (colLead == getFirstVisibleColumnIndex())
+ target = Math.max
+ (0, colLead - (getLastVisibleColumnIndex() -
+ getFirstVisibleColumnIndex() + 1));
+ else
+ target = getFirstVisibleColumnIndex();
+ colModel.setSelectionInterval(target, target);
+ rowModel.setSelectionInterval(rowLead, rowLead);
+ }
+ else if (e.getActionCommand().equals("clearSelection"))
+ {
+ table.clearSelection();
+ }
+ else if (e.getActionCommand().equals("cancel"))
+ {
+ // FIXME: implement other parts of "cancel" like undo-ing last
+ // selection. Right now it just calls editingCancelled if
+ // we're currently editing.
+ if (table.isEditing())
+ table.editingCanceled(new ChangeEvent("cancel"));
+ }
+ else if (e.getActionCommand().equals("selectNextRowCell")
+ || e.getActionCommand().equals("selectPreviousRowCell")
+ || e.getActionCommand().equals("selectNextColumnCell")
+ || e.getActionCommand().equals("selectPreviousColumnCell"))
+ {
// If nothing is selected, select the first cell in the table
if (table.getSelectedRowCount() == 0 &&
table.getSelectedColumnCount() == 0)
@@ -517,25 +471,24 @@ public class BasicTableUI
// multRowsSelected and multColsSelected tell us if multiple rows or
// columns are selected, respectively
boolean multRowsSelected, multColsSelected;
- multRowsSelected = (table.getSelectedRowCount() > 1) ||
- (!table.getRowSelectionAllowed() &&
- table.getSelectedColumnCount() > 0);
- multColsSelected = (table.getSelectedColumnCount() > 1) ||
- (!table.getColumnSelectionAllowed() &&
- table.getSelectedRowCount() > 0);
+ multRowsSelected = table.getSelectedRowCount() > 1 &&
+ table.getRowSelectionAllowed();
+
+ multColsSelected = table.getSelectedColumnCount() > 1 &&
+ table.getColumnSelectionAllowed();
// If there is just one selection, select the next cell, and wrap
// when you get to the edges of the table.
- if (!multColsSelected || !multRowsSelected)
+ if (!multColsSelected && !multRowsSelected)
{
- if (evt.getKeyCode() == KeyEvent.VK_TAB)
+ if (e.getActionCommand().indexOf("Column") != -1)
advanceSingleSelection(colModel, colMax, rowModel, rowMax,
- (evt.getModifiers() ==
- InputEvent.SHIFT_MASK));
+ (e.getActionCommand().equals
+ ("selectPreviousColumnCell")));
else
advanceSingleSelection(rowModel, rowMax, colModel, colMax,
- (evt.getModifiers() ==
- InputEvent.SHIFT_MASK));
+ (e.getActionCommand().equals
+ ("selectPreviousRowCell")));
return;
}
@@ -555,56 +508,112 @@ public class BasicTableUI
// If there are multiple rows and columns selected, select the next
// cell and wrap at the edges of the selection.
- if (evt.getKeyCode() == KeyEvent.VK_TAB)
+ if (e.getActionCommand().indexOf("Column") != -1)
advanceMultipleSelection(colModel, colMinSelected, colMaxSelected,
rowModel, rowMinSelected, rowMaxSelected,
- (evt.getModifiers() ==
- InputEvent.SHIFT_MASK), true);
+ (e.getActionCommand().equals
+ ("selectPreviousColumnCell")), true);
+
else
advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected,
colModel, colMinSelected, colMaxSelected,
- (evt.getModifiers() ==
- InputEvent.SHIFT_MASK), false);
+ (e.getActionCommand().equals
+ ("selectPreviousRowCell")), false);
table.repaint();
}
- else if (evt.getKeyCode() == KeyEvent.VK_ESCAPE)
+ else if (e.getActionCommand().equals("selectNextColumn"))
+ {
+ rowModel.setSelectionInterval(rowLead,rowLead);
+ colModel.setSelectionInterval(Math.min(colLead + 1, colMax),
+ Math.min(colLead + 1, colMax));
+ }
+ else if (e.getActionCommand().equals("scrollLeftExtendSelection"))
{
- // FIXME: implement "cancel"
+ int target;
+ if (colLead == getFirstVisibleColumnIndex())
+ target = Math.max
+ (0, colLead - (getLastVisibleColumnIndex() -
+ getFirstVisibleColumnIndex() + 1));
+ else
+ target = getFirstVisibleColumnIndex();
+
+ colModel.setLeadSelectionIndex(target);
+ rowModel.setLeadSelectionIndex(rowLead);
}
- else if ((evt.getKeyCode() == KeyEvent.VK_A || evt.getKeyCode()
- == KeyEvent.VK_SLASH) && (evt.getModifiers() ==
- InputEvent.CTRL_MASK))
+ else if (e.getActionCommand().equals("scrollDownChangeSelection"))
+ {
+ int target;
+ if (rowLead == getLastVisibleRowIndex())
+ target = Math.min
+ (rowMax, rowLead + (getLastVisibleRowIndex() -
+ getFirstVisibleRowIndex() + 1));
+ else
+ target = getLastVisibleRowIndex();
+
+ rowModel.setSelectionInterval(target, target);
+ colModel.setSelectionInterval(colLead, colLead);
+ }
+ else if (e.getActionCommand().equals("scrollRightExtendSelection"))
+ {
+ int target;
+ if (colLead == getLastVisibleColumnIndex())
+ target = Math.min
+ (colMax, colLead + (getLastVisibleColumnIndex() -
+ getFirstVisibleColumnIndex() + 1));
+ else
+ target = getLastVisibleColumnIndex();
+
+ colModel.setLeadSelectionIndex(target);
+ rowModel.setLeadSelectionIndex(rowLead);
+ }
+ else if (e.getActionCommand().equals("selectAll"))
{
table.selectAll();
}
- else if (evt.getKeyCode() == KeyEvent.VK_BACK_SLASH
- && (evt.getModifiers() == InputEvent.CTRL_MASK))
+ else if (e.getActionCommand().equals("selectLastRowExtendSelection"))
{
- table.clearSelection();
+ rowModel.setLeadSelectionIndex(rowMax);
+ colModel.setLeadSelectionIndex(colLead);
+ }
+ else if (e.getActionCommand().equals("scrollDownExtendSelection"))
+ {
+ int target;
+ if (rowLead == getLastVisibleRowIndex())
+ target = Math.min
+ (rowMax, rowLead + (getLastVisibleRowIndex() -
+ getFirstVisibleRowIndex() + 1));
+ else
+ target = getLastVisibleRowIndex();
+
+ rowModel.setLeadSelectionIndex(target);
+ colModel.setLeadSelectionIndex(colLead);
+ }
+ else if (e.getActionCommand().equals("scrollUpChangeSelection"))
+ {
+ int target;
+ if (rowLead == getFirstVisibleRowIndex())
+ target = Math.max
+ (0, rowLead - (getLastVisibleRowIndex() -
+ getFirstVisibleRowIndex() + 1));
+ else
+ target = getFirstVisibleRowIndex();
+
+ rowModel.setSelectionInterval(target, target);
+ colModel.setSelectionInterval(colLead, colLead);
}
- else if (evt.getKeyCode() == KeyEvent.VK_SPACE
- && (evt.getModifiers() == InputEvent.CTRL_MASK))
+ else
{
- table.changeSelection(rowLead, colLead, true, false);
+ // If we're here that means we bound this TableAction class
+ // to a keyboard input but we either want to ignore that input
+ // or we just haven't implemented its action yet.
}
+
table.scrollRectToVisible
(table.getCellRect(rowModel.getLeadSelectionIndex(),
colModel.getLeadSelectionIndex(), false));
}
-
- public void keyReleased(KeyEvent e)
- {
- }
-
- public void keyTyped(KeyEvent e)
- {
- }
-
- /**
- * Returns the column index of the first visible column.
- *
- */
+
int getFirstVisibleColumnIndex()
{
ComponentOrientation or = table.getComponentOrientation();
@@ -663,133 +672,172 @@ public class BasicTableUI
}
return table.rowAtPoint(r.getLocation());
}
- }
-
- class MouseInputHandler implements MouseInputListener
- {
- Point begin, curr;
- private void updateSelection(boolean controlPressed)
+ /**
+ * A helper method for the key bindings. Used because the actions
+ * for TAB, SHIFT-TAB, ENTER, and SHIFT-ENTER are very similar.
+ *
+ * Selects the next (previous if SHIFT pressed) column for TAB, or row for
+ * ENTER from within the currently selected cells.
+ *
+ * @param firstModel the ListSelectionModel for columns (TAB) or
+ * rows (ENTER)
+ * @param firstMin the first selected index in firstModel
+ * @param firstMax the last selected index in firstModel
+ * @param secondModel the ListSelectionModel for rows (TAB) or
+ * columns (ENTER)
+ * @param secondMin the first selected index in secondModel
+ * @param secondMax the last selected index in secondModel
+ * @param reverse true if shift was held for the event
+ * @param eventIsTab true if TAB was pressed, false if ENTER pressed
+ */
+ void advanceMultipleSelection (ListSelectionModel firstModel, int firstMin,
+ int firstMax, ListSelectionModel secondModel,
+ int secondMin, int secondMax, boolean reverse,
+ boolean eventIsTab)
{
- // Update the rows
- int lo_row = table.rowAtPoint(begin);
- int hi_row = table.rowAtPoint(curr);
- ListSelectionModel rowModel = table.getSelectionModel();
- if (lo_row != -1 && hi_row != -1)
+ // If eventIsTab, all the "firsts" correspond to columns, otherwise, to rows
+ // "seconds" correspond to the opposite
+ int firstLead = firstModel.getLeadSelectionIndex();
+ int secondLead = secondModel.getLeadSelectionIndex();
+ int numFirsts = eventIsTab ?
+ table.getModel().getColumnCount() : table.getModel().getRowCount();
+ int numSeconds = eventIsTab ?
+ table.getModel().getRowCount() : table.getModel().getColumnCount();
+
+ // check if we have to wrap the "firsts" around, going to the other side
+ if ((firstLead == firstMax && !reverse) ||
+ (reverse && firstLead == firstMin))
{
- if (controlPressed && rowModel.getSelectionMode()
- != ListSelectionModel.SINGLE_SELECTION)
- rowModel.addSelectionInterval(lo_row, hi_row);
+ firstModel.addSelectionInterval(reverse ? firstMax : firstMin,
+ reverse ? firstMax : firstMin);
+
+ // check if we have to wrap the "seconds"
+ if ((secondLead == secondMax && !reverse) ||
+ (reverse && secondLead == secondMin))
+ secondModel.addSelectionInterval(reverse ? secondMax : secondMin,
+ reverse ? secondMax : secondMin);
+
+ // if we're not wrapping the seconds, we have to find out where we
+ // are within the secondModel and advance to the next cell (or
+ // go back to the previous cell if reverse == true)
else
- rowModel.setSelectionInterval(lo_row, hi_row);
+ {
+ int[] secondsSelected;
+ if (eventIsTab && table.getRowSelectionAllowed() ||
+ !eventIsTab && table.getColumnSelectionAllowed())
+ secondsSelected = eventIsTab ?
+ table.getSelectedRows() : table.getSelectedColumns();
+ else
+ {
+ // if row selection is not allowed, then the entire column gets
+ // selected when you click on it, so consider ALL rows selected
+ secondsSelected = new int[numSeconds];
+ for (int i = 0; i < numSeconds; i++)
+ secondsSelected[i] = i;
+ }
+
+ // and now find the "next" index within the model
+ int secondIndex = reverse ? secondsSelected.length - 1 : 0;
+ if (!reverse)
+ while (secondsSelected[secondIndex] <= secondLead)
+ secondIndex++;
+ else
+ while (secondsSelected[secondIndex] >= secondLead)
+ secondIndex--;
+
+ // and select it - updating the lead selection index
+ secondModel.addSelectionInterval(secondsSelected[secondIndex],
+ secondsSelected[secondIndex]);
+ }
}
-
- // Update the columns
- int lo_col = table.columnAtPoint(begin);
- int hi_col = table.columnAtPoint(curr);
- ListSelectionModel colModel = table.getColumnModel().
- getSelectionModel();
- if (lo_col != -1 && hi_col != -1)
+ // We didn't have to wrap the firsts, so just find the "next" first
+ // and select it, we don't have to change "seconds"
+ else
{
- if (controlPressed && colModel.getSelectionMode() !=
- ListSelectionModel.SINGLE_SELECTION)
- colModel.addSelectionInterval(lo_col, hi_col);
+ int[] firstsSelected;
+ if (eventIsTab && table.getColumnSelectionAllowed() ||
+ !eventIsTab && table.getRowSelectionAllowed())
+ firstsSelected = eventIsTab ?
+ table.getSelectedColumns() : table.getSelectedRows();
else
- colModel.setSelectionInterval(lo_col, hi_col);
+ {
+ // if selection not allowed, consider ALL firsts to be selected
+ firstsSelected = new int[numFirsts];
+ for (int i = 0; i < numFirsts; i++)
+ firstsSelected[i] = i;
+ }
+ int firstIndex = reverse ? firstsSelected.length - 1 : 0;
+ if (!reverse)
+ while (firstsSelected[firstIndex] <= firstLead)
+ firstIndex++;
+ else
+ while (firstsSelected[firstIndex] >= firstLead)
+ firstIndex--;
+ firstModel.addSelectionInterval(firstsSelected[firstIndex],
+ firstsSelected[firstIndex]);
+ secondModel.addSelectionInterval(secondLead, secondLead);
}
}
+
+ /**
+ * A helper method for the key bindings. Used because the actions
+ * for TAB, SHIFT-TAB, ENTER, and SHIFT-ENTER are very similar.
+ *
+ * Selects the next (previous if SHIFT pressed) column (TAB) or row (ENTER)
+ * in the table, changing the current selection. All cells in the table
+ * are eligible, not just the ones that are currently selected.
+ * @param firstModel the ListSelectionModel for columns (TAB) or rows
+ * (ENTER)
+ * @param firstMax the last index in firstModel
+ * @param secondModel the ListSelectionModel for rows (TAB) or columns
+ * (ENTER)
+ * @param secondMax the last index in secondModel
+ * @param reverse true if SHIFT was pressed for the event
+ */
- public void mouseClicked(MouseEvent e)
- {
- }
- public void mouseDragged(MouseEvent e)
- {
- curr = new Point(e.getX(), e.getY());
- updateSelection(e.isControlDown());
- }
- public void mouseEntered(MouseEvent e)
- {
- }
- public void mouseExited(MouseEvent e)
- {
- }
- public void mouseMoved(MouseEvent e)
- {
- }
- public void mousePressed(MouseEvent e)
+ void advanceSingleSelection (ListSelectionModel firstModel, int firstMax,
+ ListSelectionModel secondModel, int secondMax,
+ boolean reverse)
{
- begin = new Point(e.getX(), e.getY());
- curr = new Point(e.getX(), e.getY());
- //if control is pressed and the cell is already selected, deselect it
- if (e.isControlDown() && table.
- isCellSelected(table.rowAtPoint(begin),table.columnAtPoint(begin)))
- {
- table.getSelectionModel().
- removeSelectionInterval(table.rowAtPoint(begin),
- table.rowAtPoint(begin));
- table.getColumnModel().getSelectionModel().
- removeSelectionInterval(table.columnAtPoint(begin),
- table.columnAtPoint(begin));
+ // for TABs, "first" corresponds to columns and "seconds" to rows.
+ // the opposite is true for ENTERs
+ int firstLead = firstModel.getLeadSelectionIndex();
+ int secondLead = secondModel.getLeadSelectionIndex();
+
+ // if we are going backwards subtract 2 because we later add 1
+ // for a net change of -1
+ if (reverse && (firstLead == 0))
+ {
+ // check if we have to wrap around
+ if (secondLead == 0)
+ secondLead += secondMax + 1;
+ secondLead -= 2;
}
+
+ // do we have to wrap the "seconds"?
+ if (reverse && (firstLead == 0) || !reverse && (firstLead == firstMax))
+ secondModel.setSelectionInterval((secondLead + 1)%(secondMax + 1),
+ (secondLead + 1)%(secondMax + 1));
+ // if not, just reselect the current lead
else
- updateSelection(e.isControlDown());
+ secondModel.setSelectionInterval(secondLead, secondLead);
- }
- public void mouseReleased(MouseEvent e)
- {
- begin = null;
- curr = null;
+ // if we are going backwards, subtract 2 because we add 1 later
+ // for net change of -1
+ if (reverse)
+ {
+ // check for wraparound
+ if (firstLead == 0)
+ firstLead += firstMax + 1;
+ firstLead -= 2;
+ }
+ // select the next "first"
+ firstModel.setSelectionInterval ((firstLead + 1)%(firstMax + 1),
+ (firstLead + 1)%(firstMax + 1));
}
}
- protected FocusListener createFocusListener()
- {
- return new FocusHandler();
- }
- protected KeyListener createKeyListener()
- {
- return new KeyHandler();
- }
- protected MouseInputListener createMouseInputListener()
- {
- return new MouseInputHandler();
- }
-
- public Dimension getMaximumSize(JComponent comp)
- {
- return getPreferredSize(comp);
- }
-
- public Dimension getMinimumSize(JComponent comp)
- {
- return getPreferredSize(comp);
- }
-
- public Dimension getPreferredSize(JComponent comp)
- {
- int width = table.getColumnModel().getTotalColumnWidth();
- int height = table.getRowCount() * table.getRowHeight();
- return new Dimension(width, height);
- }
-
- protected void installDefaults()
- {
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- table.setFont(defaults.getFont("Table.font"));
- table.setGridColor(defaults.getColor("Table.gridColor"));
- table.setForeground(defaults.getColor("Table.foreground"));
- table.setBackground(defaults.getColor("Table.background"));
- table.setSelectionForeground(defaults.getColor("Table.selectionForeground"));
- table.setSelectionBackground(defaults.getColor("Table.selectionBackground"));
- table.setOpaque(true);
-
- highlightCellBorder = defaults.getBorder("Table.focusCellHighlightBorder");
- cellBorder = BorderFactory.createEmptyBorder(1, 1, 1, 1);
- }
- protected void installKeyboardActions()
- {
- }
-
protected void installListeners()
{
table.addFocusListener(focusListener);
@@ -834,7 +882,6 @@ public class BasicTableUI
{
table = (JTable)comp;
focusListener = createFocusListener();
- keyListener = createKeyListener();
mouseInputListener = createMouseInputListener();
installDefaults();
installKeyboardActions();
@@ -896,6 +943,8 @@ public class BasicTableUI
((JComponent) comp).setBorder(cellBorder);
}
comp.paint(gfx);
+ if (comp instanceof JTextField)
+ ((JTextField)comp).getCaret().paint(gfx);
gfx.translate(-x, -y);
}
y += height;
@@ -948,6 +997,5 @@ public class BasicTableUI
}
gfx.setColor(save);
}
-
}
}
diff --git a/javax/swing/plaf/basic/BasicTreeUI.java b/javax/swing/plaf/basic/BasicTreeUI.java
index 0ccc0f5be..74bd6110b 100644
--- a/javax/swing/plaf/basic/BasicTreeUI.java
+++ b/javax/swing/plaf/basic/BasicTreeUI.java
@@ -1,39 +1,39 @@
/* BasicTreeUI.java --
- Copyright (C) 2002, 2004, 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. */
+ Copyright (C) 2002, 2004, 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.basic;
@@ -90,6 +90,7 @@ import javax.swing.plaf.TreeUI;
import javax.swing.tree.AbstractLayoutCache;
import javax.swing.tree.DefaultTreeCellEditor;
import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.tree.ExpandVetoException;
import javax.swing.tree.FixedHeightLayoutCache;
import javax.swing.tree.TreeCellEditor;
import javax.swing.tree.TreeCellRenderer;
@@ -106,128 +107,138 @@ import javax.swing.tree.TreeSelectionModel;
* @author Sascha Brawer (brawer@dandelis.ch)
* @author Lillian Angel (langel@redhat.com)
*/
-public class BasicTreeUI extends TreeUI
+public class BasicTreeUI
+ extends TreeUI
{
/** Collapse Icon for the tree. */
protected transient Icon collapsedIcon;
-
+
/** Expanded Icon for the tree. */
protected transient Icon expandedIcon;
-
+
/** Distance between left margin and where vertical dashes will be drawn. */
protected int leftChildIndent;
-
+
/**
* Distance between leftChildIndent and where cell contents will be drawn.
*/
protected int rightChildIndent;
-
+
/**
* Total fistance that will be indented. The sum of leftChildIndent and
* rightChildIndent .
*/
protected int totalChildIndent;
-
+
/** Minimum preferred size. */
protected Dimension preferredMinsize;
-
+
/** Index of the row that was last selected. */
protected int lastSelectedRow;
-
+
/** Component that we're going to be drawing onto. */
protected JTree tree;
-
+
/** Renderer that is being used to do the actual cell drawing. */
protected transient TreeCellRenderer currentCellRenderer;
-
+
/**
* Set to true if the renderer that is currently in the tree was created by
* this instance.
*/
protected boolean createdRenderer;
-
+
/** Editor for the tree. */
protected transient TreeCellEditor cellEditor;
-
+
/**
* Set to true if editor that is currently in the tree was created by this
* instance.
*/
protected boolean createdCellEditor;
-
+
/**
* Set to false when editing and shouldSelectCall() returns true meaning the
* node should be selected before editing, used in completeEditing.
*/
protected boolean stopEditingInCompleteEditing;
-
+
/** Used to paint the TreeCellRenderer. */
protected CellRendererPane rendererPane;
-
+
/** Size needed to completely display all the nodes. */
protected Dimension preferredSize;
-
+
/** Is the preferredSize valid? */
protected boolean validCachedPreferredSize;
-
+
/** Object responsible for handling sizing and expanded issues. */
protected AbstractLayoutCache treeState;
-
+
/** Used for minimizing the drawing of vertical lines. */
protected Hashtable drawingCache;
-
+
/**
* True if doing optimizations for a largeModel. Subclasses that don't
* support this may wish to override createLayoutCache to not return a
* FixedHeightLayoutCache instance.
*/
protected boolean largeModel;
-
+
/** Responsible for telling the TreeState the size needed for a node. */
protected AbstractLayoutCache.NodeDimensions nodeDimensions;
-
+
/** Used to determine what to display. */
protected TreeModel treeModel;
-
+
/** Model maintaining the selection. */
protected TreeSelectionModel treeSelectionModel;
-
+
/**
* How much the depth should be offset to properly calculate x locations.
* This is based on whether or not the root is visible, and if the root
* handles are visible.
*/
protected int depthOffset;
-
+
/**
* When editing, this will be the Component that is doing the actual editing.
*/
protected Component editingComponent;
-
+
/** Path that is being edited. */
protected TreePath editingPath;
-
+
/**
* Row that is being edited. Should only be referenced if editingComponent is
* null.
*/
protected int editingRow;
-
+
/** Set to true if the editor has a different size than the renderer. */
protected boolean editorHasDifferentSize;
-
+
/** Listeners */
private PropertyChangeListener propertyChangeListener;
+
private FocusListener focusListener;
+
private TreeSelectionListener treeSelectionListener;
+
private MouseInputListener mouseInputListener;
+
private KeyListener keyListener;
+
private PropertyChangeListener selectionModelPropertyChangeListener;
+
private ComponentListener componentListener;
+
private CellEditorListener cellEditorListener;
+
private TreeExpansionListener treeExpansionListener;
+
private TreeModelListener treeModelListener;
-
+
/**
* Creates a new BasicTreeUI object.
*/
@@ -239,7 +250,7 @@ public class BasicTreeUI extends TreeUI
nodeDimensions = createNodeDimensions();
rendererPane = createCellRendererPane();
configureLayoutCache();
-
+
propertyChangeListener = createPropertyChangeListener();
focusListener = createFocusListener();
treeSelectionListener = createTreeSelectionListener();
@@ -250,13 +261,13 @@ public class BasicTreeUI extends TreeUI
cellEditorListener = createCellEditorListener();
treeExpansionListener = createTreeExpansionListener();
treeModelListener = createTreeModelListener();
-
+
createdRenderer = true;
createdCellEditor = true;
editingRow = -1;
lastSelectedRow = -1;
}
-
+
/**
* Returns an instance of the UI delegate for the specified component.
*
@@ -268,7 +279,7 @@ public class BasicTreeUI extends TreeUI
{
return new BasicTreeUI();
}
-
+
/**
* Returns the Hash color.
*
@@ -278,7 +289,7 @@ public class BasicTreeUI extends TreeUI
{
return UIManager.getLookAndFeelDefaults().getColor("Tree.hash");
}
-
+
/**
* Sets the Hash color.
*
@@ -287,9 +298,9 @@ public class BasicTreeUI extends TreeUI
protected void setHashColor(Color color)
{
// FIXME: not implemented
-
+
}
-
+
/**
* Sets the left child's indent value.
*
@@ -299,7 +310,7 @@ public class BasicTreeUI extends TreeUI
{
leftChildIndent = newAmount;
}
-
+
/**
* Returns the indent value for the left child.
*
@@ -309,7 +320,7 @@ public class BasicTreeUI extends TreeUI
{
return leftChildIndent;
}
-
+
/**
* Sets the right child's indent value.
*
@@ -319,7 +330,7 @@ public class BasicTreeUI extends TreeUI
{
rightChildIndent = newAmount;
}
-
+
/**
* Returns the indent value for the right child.
*
@@ -329,7 +340,7 @@ public class BasicTreeUI extends TreeUI
{
return rightChildIndent;
}
-
+
/**
* Sets the expanded icon.
*
@@ -339,7 +350,7 @@ public class BasicTreeUI extends TreeUI
{
expandedIcon = newG;
}
-
+
/**
* Returns the current expanded icon.
*
@@ -349,7 +360,7 @@ public class BasicTreeUI extends TreeUI
{
return expandedIcon;
}
-
+
/**
* Sets the collapsed icon.
*
@@ -359,7 +370,7 @@ public class BasicTreeUI extends TreeUI
{
collapsedIcon = newG;
}
-
+
/**
* Returns the current collapsed icon.
*
@@ -369,7 +380,7 @@ public class BasicTreeUI extends TreeUI
{
return collapsedIcon;
}
-
+
/**
* Updates the componentListener, if necessary.
*
@@ -384,7 +395,7 @@ public class BasicTreeUI extends TreeUI
tree.addComponentListener(componentListener);
}
}
-
+
/**
* Returns true if largeModel is set
*
@@ -394,7 +405,7 @@ public class BasicTreeUI extends TreeUI
{
return largeModel;
}
-
+
/**
* Sets the row height.
*
@@ -404,7 +415,7 @@ public class BasicTreeUI extends TreeUI
{
treeState.setRowHeight(rowHeight);
}
-
+
/**
* Returns the current row height.
*
@@ -414,7 +425,7 @@ public class BasicTreeUI extends TreeUI
{
return treeState.getRowHeight();
}
-
+
/**
* Sets the TreeCellRenderer to <code>tcr</code>. This invokes
* <code>updateRenderer</code>.
@@ -424,9 +435,10 @@ public class BasicTreeUI extends TreeUI
protected void setCellRenderer(TreeCellRenderer tcr)
{
currentCellRenderer = tcr;
+ tree.setCellRenderer(tcr);
updateRenderer();
}
-
+
/**
* Return currentCellRenderer, which will either be the trees renderer, or
* defaultCellRenderer, which ever was not null.
@@ -437,10 +449,10 @@ public class BasicTreeUI extends TreeUI
{
if (currentCellRenderer != null)
return currentCellRenderer;
-
+
return createDefaultCellRenderer();
}
-
+
/**
* Sets the tree's model.
*
@@ -449,9 +461,9 @@ public class BasicTreeUI extends TreeUI
protected void setModel(TreeModel model)
{
tree.setModel(model);
- treeModel = model;
+ treeModel = tree.getModel();
}
-
+
/**
* Returns the tree's model
*
@@ -461,7 +473,7 @@ public class BasicTreeUI extends TreeUI
{
return treeModel;
}
-
+
/**
* Sets the root to being visible.
*
@@ -471,7 +483,7 @@ public class BasicTreeUI extends TreeUI
{
tree.setRootVisible(newValue);
}
-
+
/**
* Returns true if the root is visible.
*
@@ -481,7 +493,7 @@ public class BasicTreeUI extends TreeUI
{
return tree.isRootVisible();
}
-
+
/**
* Determines whether the node handles are to be displayed.
*
@@ -491,7 +503,7 @@ public class BasicTreeUI extends TreeUI
{
tree.setShowsRootHandles(newValue);
}
-
+
/**
* Returns true if the node handles are to be displayed.
*
@@ -501,7 +513,7 @@ public class BasicTreeUI extends TreeUI
{
return tree.getShowsRootHandles();
}
-
+
/**
* Sets the cell editor.
*
@@ -511,7 +523,7 @@ public class BasicTreeUI extends TreeUI
{
cellEditor = editor;
}
-
+
/**
* Returns the <code>TreeCellEditor</code> for this tree.
*
@@ -521,7 +533,7 @@ public class BasicTreeUI extends TreeUI
{
return cellEditor;
}
-
+
/**
* Configures the receiver to allow, or not allow, editing.
*
@@ -531,7 +543,7 @@ public class BasicTreeUI extends TreeUI
{
tree.setEditable(newValue);
}
-
+
/**
* Returns true if the receiver allows editing.
*
@@ -541,7 +553,7 @@ public class BasicTreeUI extends TreeUI
{
return tree.isEditable();
}
-
+
/**
* Resets the selection model. The appropriate listeners are installed on the
* model.
@@ -556,7 +568,7 @@ public class BasicTreeUI extends TreeUI
tree.setSelectionModel(treeSelectionModel);
}
}
-
+
/**
* Returns the current selection model.
*
@@ -566,7 +578,7 @@ public class BasicTreeUI extends TreeUI
{
return treeSelectionModel;
}
-
+
/**
* Returns the Rectangle enclosing the label portion that the last item in
* path will be drawn to. Will return null if any component in path is
@@ -583,17 +595,19 @@ public class BasicTreeUI extends TreeUI
{
Object cell = path.getLastPathComponent();
TreeModel mod = tree.getModel();
- TreeNode root = (TreeNode) mod.getRoot();
- if (!tree.isRootVisible()
- && tree.isExpanded(new TreePath(root)))
- root = getNextNode(root);
-
- Point loc = getCellLocation(0, 0, tree, mod, cell, root);
- return getCellBounds(loc.x, loc.y, cell);
+ if (mod != null)
+ {
+ Object root = mod.getRoot();
+ if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root)))
+ root = getNextNode(root);
+
+ Point loc = getCellLocation(0, 0, tree, mod, cell, root);
+ return getCellBounds(loc.x, loc.y, cell);
+ }
}
return null;
}
-
+
/**
* Returns the path for passed in row. If row is not visible null is
* returned.
@@ -605,22 +619,25 @@ public class BasicTreeUI extends TreeUI
*/
public TreePath getPathForRow(JTree tree, int row)
{
- TreeNode node = ((TreeNode) (tree.getModel()).getRoot());
- if (!tree.isRootVisible()
- && tree.isExpanded(new TreePath(getPathToRoot(node, 0))))
- node = getNextNode(node);
-
- for (int i = 0; i < row; i++)
- node = getNextVisibleNode(node);
-
- // in case nothing was found
- if (node == null)
- return null;
-
- // something was found
- return new TreePath(getPathToRoot(node, 0));
+ TreeModel mod = tree.getModel();
+ if (mod != null)
+ {
+ Object node = mod.getRoot();
+ if (!tree.isRootVisible()
+ && tree.isExpanded(new TreePath(getPathToRoot(node, 0))))
+ node = getNextNode(node);
+
+ for (int i = 0; i < row; i++)
+ node = getNextVisibleNode(node);
+
+ if (node == null)
+ return null;
+
+ return new TreePath(getPathToRoot(node, 0));
+ }
+ return null;
}
-
+
/**
* Returns the row that the last item identified in path is visible at. Will
* return -1 if any of the elments in the path are not currently visible.
@@ -638,7 +655,7 @@ public class BasicTreeUI extends TreeUI
// expand/collapse is not implemented
return path.getPathCount() - 1;
}
-
+
/**
* Returns the number of rows that are being displayed.
*
@@ -647,23 +664,24 @@ public class BasicTreeUI extends TreeUI
*/
public int getRowCount(JTree tree)
{
- TreeNode node = ((TreeNode) (tree.getModel())
- .getRoot());
- if (!tree.isRootVisible()
- && tree.isExpanded(new TreePath((getPathToRoot(node, 0)))))
- node = getNextNode(node);
-
+ TreeModel mod = tree.getModel();
int count = 0;
-
- while (node != null)
+ if (mod != null)
{
- count++;
- node = getNextVisibleNode(node);
+ Object node = mod.getRoot();
+ if (!tree.isRootVisible()
+ && tree.isExpanded(new TreePath((getPathToRoot(node, 0)))))
+ node = getNextNode(node);
+
+ while (node != null)
+ {
+ count++;
+ node = getNextVisibleNode(node);
+ }
}
-
return count;
}
-
+
/**
* Returns the path to the node that is closest to x,y. If there is nothing
* currently visible this will return null, otherwise it'll always return a
@@ -679,20 +697,20 @@ public class BasicTreeUI extends TreeUI
{
//FIXME: what if root is hidden? should not depend on (0,0)
// should start counting rows from where root is.
-
+
int row = Math.round(y / getRowHeight());
TreePath path = getPathForRow(tree, row);
-
+
// no row is visible at this node
while (row > 0 && path == null)
{
--row;
path = getPathForRow(tree, row);
}
-
+
return path;
}
-
+
/**
* Returns true if the tree is being edited. The item that is being edited
* can be returned by getEditingPath().
@@ -705,7 +723,7 @@ public class BasicTreeUI extends TreeUI
// FIXME: not implemented
return false;
}
-
+
/**
* Stops the current editing session. This has no effect if the tree is not
* being edited. Returns true if the editor allows the editing session to
@@ -719,7 +737,7 @@ public class BasicTreeUI extends TreeUI
// FIXME: not implemented
return false;
}
-
+
/**
* Cancels the current editing session.
*
@@ -729,7 +747,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Selects the last item in path and tries to edit it. Editing will fail if
* the CellEditor won't allow it for the selected item.
@@ -741,7 +759,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Returns the path to the element that is being editted.
*
@@ -753,7 +771,7 @@ public class BasicTreeUI extends TreeUI
// FIXME: not implemented
return null;
}
-
+
/**
* Invoked after the tree instance variable has been set, but before any
* default/listeners have been installed.
@@ -762,7 +780,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Invoked from installUI after all the defaults/listeners have been
* installed.
@@ -771,7 +789,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Invoked from uninstallUI after all the defaults/listeners have been
* uninstalled.
@@ -780,7 +798,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Installs the subcomponents of the tree, which is the renderer pane.
*/
@@ -788,7 +806,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Creates an instance of NodeDimensions that is able to determine the size
* of a given node in the tree.
@@ -800,7 +818,7 @@ public class BasicTreeUI extends TreeUI
// FIXME: not implemented
return null;
}
-
+
/**
* Creates a listener that is reponsible for the updates the UI based on how
* the tree changes.
@@ -811,7 +829,7 @@ public class BasicTreeUI extends TreeUI
{
return new PropertyChangeHandler();
}
-
+
/**
* Creates the listener responsible for updating the selection based on mouse
* events.
@@ -822,7 +840,7 @@ public class BasicTreeUI extends TreeUI
{
return new MouseHandler();
}
-
+
/**
* Creates the listener that is responsible for updating the display when
* focus is lost/grained.
@@ -833,7 +851,7 @@ public class BasicTreeUI extends TreeUI
{
return new FocusHandler();
}
-
+
/**
* Creates the listener reponsible for getting key events from the tree.
*
@@ -843,7 +861,7 @@ public class BasicTreeUI extends TreeUI
{
return new KeyHandler();
}
-
+
/**
* Creates the listener responsible for getting property change events from
* the selection model.
@@ -855,7 +873,7 @@ public class BasicTreeUI extends TreeUI
{
return new SelectionModelPropertyChangeHandler();
}
-
+
/**
* Creates the listener that updates the display based on selection change
* methods.
@@ -866,7 +884,7 @@ public class BasicTreeUI extends TreeUI
{
return new TreeSelectionHandler();
}
-
+
/**
* Creates a listener to handle events from the current editor
*
@@ -876,7 +894,7 @@ public class BasicTreeUI extends TreeUI
{
return new CellEditorHandler();
}
-
+
/**
* Creates and returns a new ComponentHandler. This is used for the large
* model to mark the validCachedPreferredSize as invalid when the component
@@ -888,7 +906,7 @@ public class BasicTreeUI extends TreeUI
{
return new ComponentHandler();
}
-
+
/**
* Creates and returns the object responsible for updating the treestate when
* a nodes expanded state changes.
@@ -899,7 +917,7 @@ public class BasicTreeUI extends TreeUI
{
return new TreeExpansionHandler();
}
-
+
/**
* Creates the object responsible for managing what is expanded, as well as
* the size of nodes.
@@ -910,7 +928,7 @@ public class BasicTreeUI extends TreeUI
{
return new FixedHeightLayoutCache();
}
-
+
/**
* Returns the renderer pane that renderer components are placed in.
*
@@ -920,7 +938,7 @@ public class BasicTreeUI extends TreeUI
{
return new CellRendererPane();
}
-
+
/**
* Creates a default cell editor.
*
@@ -928,10 +946,12 @@ public class BasicTreeUI extends TreeUI
*/
protected TreeCellEditor createDefaultCellEditor()
{
- return new DefaultTreeCellEditor(tree,
- (DefaultTreeCellRenderer) createDefaultCellRenderer(), cellEditor);
+ return new DefaultTreeCellEditor(
+ tree,
+ (DefaultTreeCellRenderer) createDefaultCellRenderer(),
+ cellEditor);
}
-
+
/**
* Returns the default cell renderer that is used to do the stamping of each
* node.
@@ -943,7 +963,7 @@ public class BasicTreeUI extends TreeUI
{
return new DefaultTreeCellRenderer();
}
-
+
/**
* Returns a listener that can update the tree when the model changes.
*
@@ -953,7 +973,7 @@ public class BasicTreeUI extends TreeUI
{
return new TreeModelHandler();
}
-
+
/**
* Uninstall all registered listeners
*/
@@ -967,7 +987,7 @@ public class BasicTreeUI extends TreeUI
tree.removePropertyChangeListener(selectionModelPropertyChangeListener);
tree.removeComponentListener(componentListener);
tree.removeTreeExpansionListener(treeExpansionListener);
-
+
TreeCellEditor tce = tree.getCellEditor();
if (tce != null)
tce.removeCellEditorListener(cellEditorListener);
@@ -975,14 +995,14 @@ public class BasicTreeUI extends TreeUI
if (tm != null)
tm.removeTreeModelListener(treeModelListener);
}
-
+
/**
* Uninstall all keyboard actions.
*/
protected void uninstallKeyboardActions()
{
}
-
+
/**
* Uninstall the rendererPane.
*/
@@ -990,7 +1010,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* The vertical element of legs between nodes starts at the bottom of the
* parent node by default. This method makes the leg start below that.
@@ -1002,7 +1022,7 @@ public class BasicTreeUI extends TreeUI
// FIXME: not implemented
return 0;
}
-
+
/**
* The horizontal element of legs between nodes starts at the right of the
* left-hand side of the child node by default. This method makes the leg end
@@ -1015,7 +1035,7 @@ public class BasicTreeUI extends TreeUI
// FIXME: not implemented
return 0;
}
-
+
/**
* Make all the nodes that are expanded in JTree expanded in LayoutCache.
* This invokes update ExpandedDescendants with the root path.
@@ -1024,7 +1044,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Updates the expanded state of all the descendants of the <code>path</code>
* by getting the expanded descendants from the tree and forwarding to the
@@ -1036,7 +1056,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Returns a path to the last child of <code>parent</code>
*
@@ -1047,7 +1067,7 @@ public class BasicTreeUI extends TreeUI
{
return ((TreePath) parent.getLastPathComponent());
}
-
+
/**
* Updates how much each depth should be offset by.
*/
@@ -1055,7 +1075,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Updates the cellEditor based on editability of the JTree that we're
* contained in. Ig the tree is editable but doesn't have a cellEditor, a
@@ -1065,7 +1085,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Messaged from the tree we're in when the renderer has changed.
*/
@@ -1073,7 +1093,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Resets the treeState instance based on the tree we're providing the look
* and feel for.
@@ -1082,7 +1102,7 @@ public class BasicTreeUI extends TreeUI
{
treeState = createLayoutCache();
}
-
+
/**
* Marks the cached size as being invalid, and messages the tree with
* <code>treeDidChange</code>.
@@ -1091,7 +1111,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Updates the <code>preferredSize</code> instance variable, which is
* returned from <code>getPreferredSize()</code>. For left to right
@@ -1103,7 +1123,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Messaged from the VisibleTreeNode after it has been expanded.
*
@@ -1113,7 +1133,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Messaged from the VisibleTreeNode after it has collapsed
*/
@@ -1121,7 +1141,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Install all defaults for the tree.
*
@@ -1130,24 +1150,24 @@ public class BasicTreeUI extends TreeUI
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);
-
+
rightChildIndent = defaults.getInt("Tree.rightChildIndent");
leftChildIndent = defaults.getInt("Tree.leftChildIndent");
setRowHeight(defaults.getInt("Tree.rowHeight"));
}
-
+
/**
* Install all keyboard actions for this
*/
protected void installKeyboardActions()
{
}
-
+
/**
* Install all listeners for this
*/
@@ -1162,9 +1182,10 @@ public class BasicTreeUI extends TreeUI
tree.addComponentListener(componentListener);
cellEditor.addCellEditorListener(cellEditorListener);
tree.addTreeExpansionListener(treeExpansionListener);
- treeModel.addTreeModelListener(treeModelListener);
+ if (treeModel != null)
+ treeModel.addTreeModelListener(treeModelListener);
}
-
+
/**
* Install the UI for the component
*
@@ -1175,15 +1196,17 @@ public class BasicTreeUI extends TreeUI
super.installUI(c);
installDefaults((JTree) c);
tree = (JTree) c;
- setModel(tree.getModel());
+ TreeModel mod = tree.getModel();
+ setModel(mod);
tree.setRootVisible(true);
- tree.expandPath(new TreePath(tree.getModel().getRoot()));
+ if (mod != null)
+ tree.expandPath(new TreePath(mod.getRoot()));
treeSelectionModel = tree.getSelectionModel();
installListeners();
installKeyboardActions();
completeUIInstall();
}
-
+
/**
* Uninstall the defaults for the tree
*
@@ -1191,13 +1214,11 @@ public class BasicTreeUI extends TreeUI
*/
protected void uninstallDefaults(JTree tree)
{
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
tree.setFont(null);
tree.setForeground(null);
tree.setBackground(null);
- tree.setCellRenderer(null);
}
-
+
/**
* Uninstall the UI for the component
*
@@ -1211,7 +1232,7 @@ public class BasicTreeUI extends TreeUI
tree = null;
completeUIUninstall();
}
-
+
/**
* Paints the specified component appropriate for the look and feel. This
* method is invoked from the ComponentUI.update method when the specified
@@ -1227,17 +1248,20 @@ public class BasicTreeUI extends TreeUI
{
JTree tree = (JTree) c;
TreeModel mod = tree.getModel();
- Object root = mod.getRoot();
-
- if (!tree.isRootVisible())
- tree.expandPath(new TreePath(root));
-
- paintRecursive(g, 0, 0, 0, 0, tree, mod, root);
-
- if (hasControlIcons())
- paintControlIcons(g, 0, 0, 0, 0, tree, mod, root);
- }
-
+ if (mod != null)
+ {
+ Object root = mod.getRoot();
+
+ if (!tree.isRootVisible())
+ tree.expandPath(new TreePath(root));
+
+ paintRecursive(g, 0, 0, 0, 0, tree, mod, root);
+
+ if (hasControlIcons())
+ paintControlIcons(g, 0, 0, 0, 0, tree, mod, root);
+ }
+ }
+
/**
* Ensures that the rows identified by beginRow through endRow are visible.
*
@@ -1248,7 +1272,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Sets the preferred minimum size.
*
@@ -1258,7 +1282,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Gets the preferred minimum size.
*
@@ -1269,7 +1293,7 @@ public class BasicTreeUI extends TreeUI
// FIXME: not implemented
return null;
}
-
+
/**
* Returns the preferred size to properly display the tree, this is a cover
* method for getPreferredSize(c, false).
@@ -1283,7 +1307,7 @@ public class BasicTreeUI extends TreeUI
{
return getPreferredSize(c, false);
}
-
+
/**
* Returns the preferred size to represent the tree in c. If checkConsistancy
* is true, checkConsistancy is messaged first.
@@ -1295,26 +1319,30 @@ public class BasicTreeUI extends TreeUI
public Dimension getPreferredSize(JComponent c, boolean checkConsistancy)
{
// FIXME: checkConsistancy not implemented, c not used
- TreeNode node = ((TreeNode) (tree.getModel())
- .getRoot());
+ TreeModel model = tree.getModel();
int maxWidth = 0;
int count = 0;
- if (node != null)
+ if (model != null)
{
- maxWidth = (int) (getCellBounds(0, 0, node).getWidth());
- while (node != null)
+ Object node = model.getRoot();
+ if (node != null)
{
- count++;
- TreeNode nextNode = getNextVisibleNode(node);
- if (nextNode != null)
- maxWidth = Math.max(maxWidth, (int) (getCellBounds(0, 0, nextNode)
- .getWidth()));
- node = nextNode;
+ maxWidth = (int) (getCellBounds(0, 0, node).getWidth());
+ while (node != null)
+ {
+ count++;
+ Object nextNode = getNextVisibleNode(node);
+ if (nextNode != null)
+ maxWidth = Math.max(
+ maxWidth,
+ (int) (getCellBounds(0, 0, nextNode).getWidth()));
+ node = nextNode;
+ }
}
}
return new Dimension(maxWidth, (getRowHeight() * count));
}
-
+
/**
* Returns the minimum size for this component. Which will be the min
* preferred size or (0,0).
@@ -1327,7 +1355,7 @@ public class BasicTreeUI extends TreeUI
// FIXME: not implemented
return getPreferredSize(c);
}
-
+
/**
* Returns the maximum size for the component, which will be the preferred
* size if the instance is currently in JTree or (0,0).
@@ -1340,7 +1368,7 @@ public class BasicTreeUI extends TreeUI
// FIXME: not implemented
return getPreferredSize(c);
}
-
+
/**
* Messages to stop the editing session. If the UI the receiver is providing
* the look and feel for returns true from
@@ -1352,7 +1380,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Stops the editing session. If messageStop is true, the editor is messaged
* with stopEditing, if messageCancel is true the editor is messaged with
@@ -1368,7 +1396,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Will start editing for node if there is a cellEditor and shouldSelectCall
* returns true. This assumes that path is valid and visible.
@@ -1382,7 +1410,7 @@ public class BasicTreeUI extends TreeUI
// FIXME: not implemented
return false;
}
-
+
/**
* If the <code>mouseX</code> and <code>mouseY</code> are in the expand
* or collapse region of the row, this will toggle the row.
@@ -1396,7 +1424,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Returns true if the <code>mouseX</code> and <code>mouseY</code> fall
* in the area of row that is used to expand/collpse the node and the node at
@@ -1415,7 +1443,7 @@ public class BasicTreeUI extends TreeUI
// FIXME: not implemented
return false;
}
-
+
/**
* Messaged when the user clicks the particular row, this invokes
* toggleExpandState.
@@ -1428,7 +1456,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Expands path if it is not expanded, or collapses row if it is expanded. If
* expanding a path and JTree scroll on expand, ensureRowsAreVisible is
@@ -1441,7 +1469,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Returning true signifies a mouse event on the node should toggle the
* selection of only the row under the mouse.
@@ -1455,7 +1483,7 @@ public class BasicTreeUI extends TreeUI
// FIXME: not implemented
return false;
}
-
+
/**
* Returning true signifies a mouse event on the node should select from the
* anchor point.
@@ -1469,7 +1497,7 @@ public class BasicTreeUI extends TreeUI
// FIXME: not implemented
return false;
}
-
+
/**
* Returning true indicates the row under the mouse should be toggled based
* on the event. This is invoked after checkForClickInExpandControl, implying
@@ -1484,7 +1512,7 @@ public class BasicTreeUI extends TreeUI
// FIXME: not implemented
return false;
}
-
+
/**
* Messaged to update the selection based on a MouseEvent over a particular
* row. If the even is a toggle selection event, the row is either selected,
@@ -1500,7 +1528,7 @@ public class BasicTreeUI extends TreeUI
{
// FIXME: not implemented
}
-
+
/**
* Returns true if the node at <code>row</code> is a leaf.
*
@@ -1512,37 +1540,33 @@ public class BasicTreeUI extends TreeUI
TreePath pathForRow = getPathForRow(tree, row);
if (pathForRow == null)
return true;
-
+
Object node = pathForRow.getLastPathComponent();
-
- if (node instanceof TreeNode)
- return ((TreeNode) node).isLeaf();
- else
- return true;
+ return tree.getModel().isLeaf(node);
}
-
+
/**
* Updates the preferred size when scrolling, if necessary.
*/
public class ComponentHandler
- extends ComponentAdapter
- implements ActionListener
+ extends ComponentAdapter
+ implements ActionListener
{
/**
* Timer used when inside a scrollpane and the scrollbar is adjusting
*/
protected Timer timer;
-
+
/** ScrollBar that is being adjusted */
protected JScrollBar scrollBar;
-
+
/**
* Constructor
*/
public ComponentHandler()
{
}
-
+
/**
* Invoked when the component's position changes.
*
@@ -1551,7 +1575,7 @@ public class BasicTreeUI extends TreeUI
public void componentMoved(ComponentEvent e)
{
}
-
+
/**
* Creats, if necessary, and starts a Timer to check if needed to resize
* the bounds
@@ -1559,7 +1583,7 @@ public class BasicTreeUI extends TreeUI
protected void startTimer()
{
}
-
+
/**
* Returns the JScrollPane housing the JTree, or null if one isn't found.
*
@@ -1569,7 +1593,7 @@ public class BasicTreeUI extends TreeUI
{
return null;
}
-
+
/**
* Public as a result of Timer. If the scrollBar is null, or not
* adjusting, this stops the timer and updates the sizing.
@@ -1580,13 +1604,13 @@ public class BasicTreeUI extends TreeUI
{
}
}// ComponentHandler
-
+
/**
* Listener responsible for getting cell editing events and updating the tree
* accordingly.
*/
public class CellEditorHandler
- implements CellEditorListener
+ implements CellEditorListener
{
/**
* Constructor
@@ -1594,7 +1618,7 @@ public class BasicTreeUI extends TreeUI
public CellEditorHandler()
{
}
-
+
/**
* Messaged when editing has stopped in the tree. Tells the listeners
* editing has stopped.
@@ -1604,7 +1628,7 @@ public class BasicTreeUI extends TreeUI
public void editingStopped(ChangeEvent e)
{
}
-
+
/**
* Messaged when editing has been canceled in the tree. This tells the
* listeners the editor has canceled editing.
@@ -1615,12 +1639,12 @@ public class BasicTreeUI extends TreeUI
{
}
}// CellEditorHandler
-
+
/**
* Repaints the lead selection row when focus is lost/grained.
*/
public class FocusHandler
- implements FocusListener
+ implements FocusListener
{
/**
* Constructor
@@ -1628,7 +1652,7 @@ public class BasicTreeUI extends TreeUI
public FocusHandler()
{
}
-
+
/**
* Invoked when focus is activated on the tree we're in, redraws the lead
* row. Invoked when a component gains the keyboard focus.
@@ -1638,7 +1662,7 @@ public class BasicTreeUI extends TreeUI
public void focusGained(FocusEvent e)
{
}
-
+
/**
* Invoked when focus is deactivated on the tree we're in, redraws the
* lead row. Invoked when a component loses the keyboard focus.
@@ -1649,27 +1673,27 @@ public class BasicTreeUI extends TreeUI
{
}
}// FocusHandler
-
+
/**
* This is used to get multiple key down events to appropriately genereate
* events.
*/
public class KeyHandler
- extends KeyAdapter
+ extends KeyAdapter
{
/** Key code that is being generated for. */
protected Action repeatKeyAction;
-
+
/** Set to true while keyPressed is active */
protected boolean isKeyDown;
-
+
/**
* Constructor
*/
public KeyHandler()
{
}
-
+
/**
* Invoked when a key has been typed. Moves the keyboard focus to the
* first element whose first letter matches the alphanumeric key pressed
@@ -1681,7 +1705,7 @@ public class BasicTreeUI extends TreeUI
public void keyTyped(KeyEvent e)
{
}
-
+
/**
* Invoked when a key has been pressed.
*
@@ -1689,63 +1713,84 @@ public class BasicTreeUI extends TreeUI
*/
public void keyPressed(KeyEvent e)
{
+ TreeModel mod = BasicTreeUI.this.tree.getModel();
TreePath start = BasicTreeUI.this.tree.getLeadSelectionPath();
- TreeNode last = null;
+ Object last = null;
if (start != null)
- last = (TreeNode) start.getLastPathComponent();
-
+ last = start.getLastPathComponent();
+
if (last != null)
{
// DOWN, KP_DOWN
if (e.getKeyCode() == KeyEvent.VK_DOWN
|| e.getKeyCode() == KeyEvent.VK_KP_DOWN)
{
- TreeNode next = (TreeNode) BasicTreeUI.this.
- getNextVisibleNode(last);
+ Object next = BasicTreeUI.this.getNextVisibleNode(last);
if (next != null)
{
TreePath newPath = new TreePath(getPathToRoot(next, 0));
BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, newPath);
if (e.isControlDown())
tree.setLeadSelectionPath(newPath);
- else if (!next.isLeaf() && e.isShiftDown())
+ else if (!mod.isLeaf(next) && e.isShiftDown())
{
BasicTreeUI.this.tree.expandPath(newPath);
+ try
+ {
+ BasicTreeUI.this.tree.fireTreeWillExpand(newPath);
+ }
+ catch (ExpandVetoException ev)
+ {
+ }
BasicTreeUI.this.tree.fireTreeExpanded(newPath);
}
}
}
// UP, KP_UP
else if (e.getKeyCode() == KeyEvent.VK_UP
- || e.getKeyCode() == KeyEvent.VK_KP_UP)
+ || e.getKeyCode() == KeyEvent.VK_KP_UP)
{
- TreeNode prev = (TreeNode) BasicTreeUI.this.
- getPreviousVisibleNode(last);
-
+ Object prev = BasicTreeUI.this.getPreviousVisibleNode(last);
+
if (prev != null)
{
TreePath newPath = new TreePath(getPathToRoot(prev, 0));
BasicTreeUI.this.selectPath(BasicTreeUI.this.tree,
- new TreePath(getPathToRoot(prev, 0)));
+ new TreePath(getPathToRoot(prev,
+ 0)));
if (e.isControlDown())
tree.setLeadSelectionPath(newPath);
- else if (!prev.isLeaf() && e.isShiftDown())
+ else if (!mod.isLeaf(prev) && e.isShiftDown())
{
BasicTreeUI.this.tree.expandPath(newPath);
+ try
+ {
+ BasicTreeUI.this.tree.fireTreeWillExpand(newPath);
+ }
+ catch (ExpandVetoException ev)
+ {
+ }
BasicTreeUI.this.tree.fireTreeExpanded(newPath);
}
}
}
// LEFT, KP_LEFT
else if (e.getKeyCode() == KeyEvent.VK_LEFT
- || e.getKeyCode() == KeyEvent.VK_KP_LEFT)
+ || e.getKeyCode() == KeyEvent.VK_KP_LEFT)
{
TreePath path = new TreePath(getPathToRoot(last, 0));
- TreeNode p = last.getParent();
-
- if (!last.isLeaf() && BasicTreeUI.this.tree.isExpanded(path))
+ Object p = getParent(mod.getRoot(), last);
+
+ if (!mod.isLeaf(last) && BasicTreeUI.this.tree.isExpanded(path))
{
BasicTreeUI.this.tree.collapsePath(path);
+ try
+ {
+ BasicTreeUI.this.tree.fireTreeWillCollapse(path);
+ }
+ catch (ExpandVetoException ev)
+ {
+ }
BasicTreeUI.this.tree.fireTreeCollapsed(path);
}
else if (p != null)
@@ -1754,46 +1799,70 @@ public class BasicTreeUI extends TreeUI
}
// RIGHT, KP_RIGHT
else if (e.getKeyCode() == KeyEvent.VK_RIGHT
- || e.getKeyCode() == KeyEvent.VK_KP_RIGHT)
+ || e.getKeyCode() == KeyEvent.VK_KP_RIGHT)
{
TreePath path = new TreePath(getPathToRoot(last, 0));
-
- if (!last.isLeaf() && BasicTreeUI.this.tree.isCollapsed(path))
+
+ if (!mod.isLeaf(last) && BasicTreeUI.this.tree.isCollapsed(path))
{
BasicTreeUI.this.tree.expandPath(path);
+ try
+ {
+ BasicTreeUI.this.tree.fireTreeWillExpand(path);
+ }
+ catch (ExpandVetoException ev)
+ {
+ }
BasicTreeUI.this.tree.fireTreeExpanded(path);
}
else
{
- TreeNode next = (TreeNode) BasicTreeUI.this.
- getNextVisibleNode(last);
-
+ Object next = BasicTreeUI.this.getNextVisibleNode(last);
+
if (next != null)
- BasicTreeUI.this.selectPath(BasicTreeUI.this.tree,
- new TreePath(getPathToRoot(next, 0)));
+ BasicTreeUI.this.selectPath(
+ BasicTreeUI.this.tree,
+ new TreePath(
+ getPathToRoot(
+ next,
+ 0)));
}
}
// Enter
else if (e.getKeyCode() == KeyEvent.VK_ENTER)
{
TreePath path = new TreePath(getPathToRoot(last, 0));
- if (!last.isLeaf())
+ if (!mod.isLeaf(last))
{
if (BasicTreeUI.this.tree.isExpanded(path))
{
BasicTreeUI.this.tree.collapsePath(path);
+ try
+ {
+ BasicTreeUI.this.tree.fireTreeWillCollapse(path);
+ }
+ catch (ExpandVetoException ev)
+ {
+ }
BasicTreeUI.this.tree.fireTreeCollapsed(path);
}
else
{
BasicTreeUI.this.tree.expandPath(path);
+ try
+ {
+ BasicTreeUI.this.tree.fireTreeWillExpand(path);
+ }
+ catch (ExpandVetoException ev)
+ {
+ }
BasicTreeUI.this.tree.fireTreeExpanded(path);
}
}
}
}
}
-
+
/**
* Invoked when a key has been released
*
@@ -1803,14 +1872,14 @@ public class BasicTreeUI extends TreeUI
{
}
}// KeyHandler
-
+
/**
* MouseListener is responsible for updating the selevtion based on mouse
* events.
*/
public class MouseHandler
- extends MouseAdapter
- implements MouseMotionListener
+ extends MouseAdapter
+ implements MouseMotionListener
{
/**
* Constructor
@@ -1818,7 +1887,7 @@ public class BasicTreeUI extends TreeUI
public MouseHandler()
{
}
-
+
/**
* Invoked when a mouse button has been pressed on a component.
*
@@ -1827,7 +1896,7 @@ public class BasicTreeUI extends TreeUI
public void mousePressed(MouseEvent e)
{
}
-
+
/**
* Invoked when a mouse button is pressed on a component and then dragged.
* MOUSE_DRAGGED events will continue to be delivered to the component
@@ -1840,7 +1909,7 @@ public class BasicTreeUI extends TreeUI
public void mouseDragged(MouseEvent e)
{
}
-
+
/**
* Invoked when the mouse button has been moved on a component (with no
* buttons no down).
@@ -1850,7 +1919,7 @@ public class BasicTreeUI extends TreeUI
public void mouseMoved(MouseEvent e)
{
}
-
+
/**
* Invoked when a mouse button has been released on a component.
*
@@ -1860,27 +1929,27 @@ public class BasicTreeUI extends TreeUI
{
}
}// MouseHandler
-
+
/**
* MouseInputHandler handles passing all mouse events, including mouse motion
* events, until the mouse is released to the destination it is constructed
* with.
*/
public class MouseInputHandler
- implements MouseInputListener
+ implements MouseInputListener
{
/** Source that events are coming from */
protected Component source;
-
+
/** Destination that receives all events. */
protected Component destination;
-
+
/** Number of mouse clicks on a non-leaf */
private int clickCount = 0;
-
+
/** The last non-leaf cell that was clicked */
private Object lastClicked = null;
-
+
/**
* Constructor
*
@@ -1892,7 +1961,7 @@ public class BasicTreeUI extends TreeUI
MouseEvent e)
{
}
-
+
/**
* Invoked when the mouse button has been clicked (pressed and released)
* on a component.
@@ -1903,28 +1972,28 @@ public class BasicTreeUI extends TreeUI
{
Point click = e.getPoint();
int row = Math.round(click.y / BasicTreeUI.this.getRowHeight());
- TreePath path = BasicTreeUI.this.getClosestPathForLocation(tree,
- click.x, click.y);
-
+ TreePath path = BasicTreeUI.this.getClosestPathForLocation(tree, click.x,
+ click.y);
+
if (path != null)
{
boolean inBounds = false;
boolean cntlClick = false;
Rectangle bounds = BasicTreeUI.this.getPathBounds(
- BasicTreeUI.this.tree, path);
-
+ BasicTreeUI.this.tree,
+ path);
+
bounds.x -= rightChildIndent - 4;
bounds.width += rightChildIndent + 4;
-
+
if (bounds.contains(click.x, click.y))
inBounds = true;
else if (BasicTreeUI.this.hasControlIcons()
- && (click.x < (bounds.x - rightChildIndent + 5) &&
- click.x > (bounds.x - rightChildIndent - 5)))
+ && (click.x < (bounds.x - rightChildIndent + 5) && click.x > (bounds.x
+ - rightChildIndent - 5)))
cntlClick = true;
-
- if ((inBounds || cntlClick)
- && BasicTreeUI.this.tree.isVisible(path))
+
+ if ((inBounds || cntlClick) && BasicTreeUI.this.tree.isVisible(path))
{
if (!cntlClick && !BasicTreeUI.this.isLeaf(row))
{
@@ -1937,7 +2006,7 @@ public class BasicTreeUI extends TreeUI
clickCount = 1;
}
}
-
+
if (clickCount == 2 || cntlClick == true)
{
clickCount = 0;
@@ -1946,20 +2015,34 @@ public class BasicTreeUI extends TreeUI
if (BasicTreeUI.this.tree.isExpanded(path))
{
BasicTreeUI.this.tree.collapsePath(path);
+ try
+ {
+ BasicTreeUI.this.tree.fireTreeWillCollapse(path);
+ }
+ catch (ExpandVetoException ev)
+ {
+ }
BasicTreeUI.this.tree.fireTreeCollapsed(path);
}
else
{
BasicTreeUI.this.tree.expandPath(path);
+ try
+ {
+ BasicTreeUI.this.tree.fireTreeWillExpand(path);
+ }
+ catch (ExpandVetoException ev)
+ {
+ }
BasicTreeUI.this.tree.fireTreeExpanded(path);
}
}
-
+
BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, path);
}
}
}
-
+
/**
* Invoked when a mouse button has been pressed on a component.
*
@@ -1968,7 +2051,7 @@ public class BasicTreeUI extends TreeUI
public void mousePressed(MouseEvent e)
{
}
-
+
/**
* Invoked when a mouse button has been released on a component.
*
@@ -1977,7 +2060,7 @@ public class BasicTreeUI extends TreeUI
public void mouseReleased(MouseEvent e)
{
}
-
+
/**
* Invoked when the mouse enters a component.
*
@@ -1986,7 +2069,7 @@ public class BasicTreeUI extends TreeUI
public void mouseEntered(MouseEvent e)
{
}
-
+
/**
* Invoked when the mouse exits a component.
*
@@ -1995,7 +2078,7 @@ public class BasicTreeUI extends TreeUI
public void mouseExited(MouseEvent e)
{
}
-
+
/**
* Invoked when a mouse button is pressed on a component and then dragged.
* MOUSE_DRAGGED events will continue to be delivered to the component
@@ -2008,7 +2091,7 @@ public class BasicTreeUI extends TreeUI
public void mouseDragged(MouseEvent e)
{
}
-
+
/**
* Invoked when the mouse cursor has been moved onto a component but no
* buttons have been pushed.
@@ -2018,7 +2101,7 @@ public class BasicTreeUI extends TreeUI
public void mouseMoved(MouseEvent e)
{
}
-
+
/**
* Removes event from the source
*/
@@ -2026,14 +2109,14 @@ public class BasicTreeUI extends TreeUI
{
}
}// MouseInputHandler
-
+
/**
* Class responsible for getting size of node, method is forwarded to
* BasicTreeUI method. X location does not include insets, that is handled in
* getPathBounds.
*/
public class NodeDimensionsHandler
- extends AbstractLayoutCache.NodeDimensions
+ extends AbstractLayoutCache.NodeDimensions
{
/**
* Constructor
@@ -2041,7 +2124,7 @@ public class BasicTreeUI extends TreeUI
public NodeDimensionsHandler()
{
}
-
+
/**
* Responsible for getting the size of a particular node.
*
@@ -2058,7 +2141,7 @@ public class BasicTreeUI extends TreeUI
{
return null;
}
-
+
/**
* Returns the amount to indent the given row
*
@@ -2069,22 +2152,22 @@ public class BasicTreeUI extends TreeUI
return 0;
}
}// NodeDimensionsHandler
-
+
/**
* PropertyChangeListener for the tree. Updates the appropriate varaible, or
* TreeState, based on what changes.
*/
public class PropertyChangeHandler
- implements PropertyChangeListener
+ implements PropertyChangeListener
{
-
+
/**
* Constructor
*/
public PropertyChangeHandler()
{
}
-
+
/**
* This method gets called when a bound property is changed.
*
@@ -2095,22 +2178,22 @@ public class BasicTreeUI extends TreeUI
{
}
}// PropertyChangeHandler
-
+
/**
* Listener on the TreeSelectionModel, resets the row selection if any of the
* properties of the model change.
*/
public class SelectionModelPropertyChangeHandler
- implements PropertyChangeListener
+ implements PropertyChangeListener
{
-
+
/**
* Constructor
*/
public SelectionModelPropertyChangeHandler()
{
}
-
+
/**
* This method gets called when a bound property is changed.
*
@@ -2121,21 +2204,21 @@ public class BasicTreeUI extends TreeUI
{
}
}// SelectionModelPropertyChangeHandler
-
+
/**
* ActionListener that invokes cancelEditing when action performed.
*/
public class TreeCancelEditingAction
- extends AbstractAction
+ extends AbstractAction
{
-
+
/**
* Constructor
*/
public TreeCancelEditingAction()
{
}
-
+
/**
* Invoked when an action occurs.
*
@@ -2144,7 +2227,7 @@ public class BasicTreeUI extends TreeUI
public void actionPerformed(ActionEvent e)
{
}
-
+
/**
* Returns true if the action is enabled.
*
@@ -2155,21 +2238,21 @@ public class BasicTreeUI extends TreeUI
return false;
}
}// TreeCancelEditingAction
-
+
/**
* Updates the TreeState in response to nodes expanding/collapsing.
*/
public class TreeExpansionHandler
- implements TreeExpansionListener
+ implements TreeExpansionListener
{
-
+
/**
* Constructor
*/
public TreeExpansionHandler()
{
}
-
+
/**
* Called whenever an item in the tree has been expanded.
*
@@ -2179,7 +2262,7 @@ public class BasicTreeUI extends TreeUI
{
BasicTreeUI.this.tree.repaint();
}
-
+
/**
* Called whenever an item in the tree has been collapsed.
*
@@ -2190,18 +2273,18 @@ public class BasicTreeUI extends TreeUI
BasicTreeUI.this.tree.repaint();
}
}// TreeExpansionHandler
-
+
/**
* TreeHomeAction is used to handle end/home actions. Scrolls either the
* first or last cell to be visible based on direction.
*/
public class TreeHomeAction
- extends AbstractAction
+ extends AbstractAction
{
-
+
/** direction is either home or end */
protected int direction;
-
+
/**
* Constructor
*
@@ -2211,7 +2294,7 @@ public class BasicTreeUI extends TreeUI
public TreeHomeAction(int direction, String name)
{
}
-
+
/**
* Invoked when an action occurs.
*
@@ -2220,7 +2303,7 @@ public class BasicTreeUI extends TreeUI
public void actionPerformed(ActionEvent e)
{
}
-
+
/**
* Returns true if the action is enabled.
*
@@ -2231,18 +2314,18 @@ public class BasicTreeUI extends TreeUI
return false;
}
}// TreeHomeAction
-
+
/**
* TreeIncrementAction is used to handle up/down actions. Selection is moved
* up or down based on direction.
*/
public class TreeIncrementAction
- extends AbstractAction
+ extends AbstractAction
{
-
+
/** Specifies the direction to adjust the selection by. */
protected int direction;
-
+
/**
* Constructor
*
@@ -2252,7 +2335,7 @@ public class BasicTreeUI extends TreeUI
public TreeIncrementAction(int direction, String name)
{
}
-
+
/**
* Invoked when an action occurs.
*
@@ -2261,7 +2344,7 @@ public class BasicTreeUI extends TreeUI
public void actionPerformed(ActionEvent e)
{
}
-
+
/**
* Returns true if the action is enabled.
*
@@ -2272,12 +2355,12 @@ public class BasicTreeUI extends TreeUI
return false;
}
}// TreeIncrementAction
-
+
/**
* Forwards all TreeModel events to the TreeState.
*/
public class TreeModelHandler
- implements TreeModelListener
+ implements TreeModelListener
{
/**
* Constructor
@@ -2285,7 +2368,7 @@ public class BasicTreeUI extends TreeUI
public TreeModelHandler()
{
}
-
+
/**
* Invoked after a node (or a set of siblings) has changed in some way.
* The node(s) have not changed locations in the tree or altered their
@@ -2301,7 +2384,7 @@ public class BasicTreeUI extends TreeUI
public void treeNodesChanged(TreeModelEvent e)
{
}
-
+
/**
* Invoked after nodes have been inserted into the tree. Use e.getPath()
* to get the parent of the new node(s). e.getChildIndices() returns the
@@ -2312,7 +2395,7 @@ public class BasicTreeUI extends TreeUI
public void treeNodesInserted(TreeModelEvent e)
{
}
-
+
/**
* Invoked after nodes have been removed from the tree. Note that if a
* subtree is removed from the tree, this method may only be invoked once
@@ -2326,7 +2409,7 @@ public class BasicTreeUI extends TreeUI
public void treeNodesRemoved(TreeModelEvent e)
{
}
-
+
/**
* Invoked after the tree has drastically changed structure from a given
* node down. If the path returned by e.getPath() is of length one and the
@@ -2340,16 +2423,16 @@ public class BasicTreeUI extends TreeUI
{
}
}// TreeModelHandler
-
+
/**
* TreePageAction handles page up and page down events.
*/
public class TreePageAction
- extends AbstractAction
+ extends AbstractAction
{
/** Specifies the direction to adjust the selection by. */
protected int direction;
-
+
/**
* Constructor
*
@@ -2359,7 +2442,7 @@ public class BasicTreeUI extends TreeUI
public TreePageAction(int direction, String name)
{
}
-
+
/**
* Invoked when an action occurs.
*
@@ -2368,7 +2451,7 @@ public class BasicTreeUI extends TreeUI
public void actionPerformed(ActionEvent e)
{
}
-
+
/**
* Returns true if the action is enabled.
*
@@ -2379,13 +2462,13 @@ public class BasicTreeUI extends TreeUI
return false;
}
}// TreePageAction
-
+
/**
* Listens for changes in the selection model and updates the display
* accordingly.
*/
public class TreeSelectionHandler
- implements TreeSelectionListener
+ implements TreeSelectionListener
{
/**
* Constructor
@@ -2393,7 +2476,7 @@ public class BasicTreeUI extends TreeUI
public TreeSelectionHandler()
{
}
-
+
/**
* Messaged when the selection changes in the tree we're displaying for.
* Stops editing, messages super and displays the changed paths.
@@ -2404,12 +2487,12 @@ public class BasicTreeUI extends TreeUI
{
}
}// TreeSelectionHandler
-
+
/**
* For the first selected row expandedness will be toggled.
*/
public class TreeToggleAction
- extends AbstractAction
+ extends AbstractAction
{
/**
* Constructor
@@ -2419,7 +2502,7 @@ public class BasicTreeUI extends TreeUI
public TreeToggleAction(String name)
{
}
-
+
/**
* Invoked when an action occurs.
*
@@ -2428,7 +2511,7 @@ public class BasicTreeUI extends TreeUI
public void actionPerformed(ActionEvent e)
{
}
-
+
/**
* Returns true if the action is enabled.
*
@@ -2439,20 +2522,20 @@ public class BasicTreeUI extends TreeUI
return false;
}
} // TreeToggleAction
-
+
/**
* TreeTraverseAction is the action used for left/right keys. Will toggle
* the expandedness of a node, as well as potentially incrementing the
* selection.
*/
public class TreeTraverseAction
- extends AbstractAction
+ extends AbstractAction
{
/**
* Determines direction to traverse, 1 means expand, -1 means collapse.
*/
protected int direction;
-
+
/**
* Constructor
*
@@ -2462,7 +2545,7 @@ public class BasicTreeUI extends TreeUI
public TreeTraverseAction(int direction, String name)
{
}
-
+
/**
* Invoked when an action occurs.
*
@@ -2471,7 +2554,7 @@ public class BasicTreeUI extends TreeUI
public void actionPerformed(ActionEvent e)
{
}
-
+
/**
* Returns true if the action is enabled.
*
@@ -2482,7 +2565,7 @@ public class BasicTreeUI extends TreeUI
return false;
}
} // TreeTraverseAction
-
+
/**
* Returns the cell bounds for painting selected cells
* Package private for use in inner classes.
@@ -2500,14 +2583,15 @@ public class BasicTreeUI extends TreeUI
String s = cell.toString();
Font f = tree.getFont();
FontMetrics fm = tree.getToolkit().getFontMetrics(tree.getFont());
-
+
if (s != null)
- return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s) + 4,
+ return new Rectangle(x, y,
+ SwingUtilities.computeStringWidth(fm, s) + 4,
fm.getHeight());
}
return new Rectangle(x, y, 0, 0);
}
-
+
/**
* Retrieves the location of some node, recursively starting at from
* some node.
@@ -2522,34 +2606,32 @@ public class BasicTreeUI extends TreeUI
*
* @return Point - the location of node
*/
- Point getCellLocation(int x, int y, JTree tree, TreeModel mod,
- Object node, Object startNode)
+ Point getCellLocation(int x, int y, JTree tree, TreeModel mod, Object node,
+ Object startNode)
{
int rowHeight = getRowHeight();
if (startNode == null || startNode.equals(node))
{
- if (!tree.isRootVisible() && tree.isExpanded(new TreePath(mod.getRoot())))
- return new Point(x + ((getLevel((TreeNode) node)) *
- rightChildIndent), y);
-
- return new Point(x + ((getLevel((TreeNode) node) + 1)
- * rightChildIndent), y);
+ if (!tree.isRootVisible()
+ && tree.isExpanded(new TreePath(mod.getRoot())))
+ return new Point(x + ((getLevel(node)) * rightChildIndent), y);
+
+ return new Point(x + ((getLevel(node) + 1) * rightChildIndent), y);
}
-
+
if (!mod.isLeaf(startNode)
- && tree.isExpanded(new TreePath(getPathToRoot(((TreeNode) startNode),
- 0))))
+ && tree.isExpanded(new TreePath(getPathToRoot(startNode, 0)))
+ && mod.getChildCount(startNode) > 0)
{
Object child = mod.getChild(startNode, 0);
if (child != null)
- return getCellLocation(x, y + rowHeight, tree, mod,
- node, child);
+ return getCellLocation(x, y + rowHeight, tree, mod, node, child);
}
-
+
return getCellLocation(x, y + rowHeight, tree, mod, node,
- getNextVisibleNode((TreeNode) startNode));
+ getNextVisibleNode(startNode));
}
-
+
/**
* Paints a node in the tree Package private for use in inner classes.
*
@@ -2562,61 +2644,28 @@ public class BasicTreeUI extends TreeUI
void paintNode(Graphics g, int x, int y, JTree tree, Object node,
boolean isLeaf)
{
- TreePath curr = new TreePath(getPathToRoot(((TreeNode) node), 0));
+ TreePath curr = new TreePath(getPathToRoot(node, 0));
boolean selected = tree.isPathSelected(curr);
boolean expanded = false;
boolean hasIcons = false;
-
+
if (tree.isVisible(curr))
{
- DefaultTreeCellRenderer dtcr = (DefaultTreeCellRenderer)
- createDefaultCellRenderer();
-
+ TreeCellRenderer dtcr = tree.getCellRenderer();
+ if (dtcr == null)
+ dtcr = createDefaultCellRenderer();
+
if (!isLeaf)
expanded = tree.isExpanded(curr);
-
- Icon icon = null;
- if (!isLeaf && expanded)
- icon = dtcr.getOpenIcon();
- else if (!isLeaf && !expanded)
- icon = dtcr.getClosedIcon();
- else
- icon = dtcr.getLeafIcon();
-
- if (icon.getIconHeight() > -1 && icon.getIconWidth() > -1)
- hasIcons = true;
-
+
Component c = dtcr.getTreeCellRendererComponent(tree, node, selected,
- expanded, isLeaf, 0, false);
-
- if (hasIcons)
- {
- if (selected)
- {
- Rectangle cell = getPathBounds(tree, curr);
- g.setColor(dtcr.getBackgroundSelectionColor());
- g.fillRect(cell.x + icon.getIconWidth()/2, cell.y, cell.width,
- cell.height);
-
- if (curr.equals(tree.getLeadSelectionPath()))
- {
- g.setColor(UIManager.getLookAndFeelDefaults().getColor(
- "Tree.selectionBorderColor"));
- g.drawRect(cell.x + icon.getIconWidth()/2, cell.y,
- cell.width, cell.height);
- }
- }
-
- g.translate(x, y);
- c.paint(g);
- g.translate(-x, -y);
- }
- else
- rendererPane.paintComponent(g, c, c.getParent(),
- getCellBounds(x, y, node));
+ expanded, isLeaf, 0,
+ false);
+ rendererPane.paintComponent(g, c, c.getParent(), getCellBounds(x, y,
+ node));
}
}
-
+
/**
* Recursively paints all elements of the tree Package private for use in
* inner classes.
@@ -2632,20 +2681,20 @@ public class BasicTreeUI extends TreeUI
*
* @return int - current descent of the tree
*/
- int paintRecursive(Graphics g, int indentation, int descent,
- int childNumber, int depth, JTree tree, TreeModel mod, Object curr)
+ 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 + getRowHeight())
return descent;
-
+
int halfHeight = getRowHeight() / 2;
int halfWidth = rightChildIndent / 2;
int y0 = descent + halfHeight;
int heightOfLine = descent + halfHeight;
boolean isRootVisible = tree.isRootVisible();
-
+
if (mod.isLeaf(curr))
{
paintNode(g, indentation + 4, descent, tree, curr, true);
@@ -2659,42 +2708,41 @@ public class BasicTreeUI extends TreeUI
descent += getRowHeight();
y0 += halfHeight;
}
-
+
int max = mod.getChildCount(curr);
- if (tree.isExpanded(new TreePath(getPathToRoot(((TreeNode) curr), 0))))
+ if (tree.isExpanded(new TreePath(getPathToRoot(curr, 0))))
{
- for (int i = 0; i < max; ++i)
+ for (int i = 0; i < max; i++)
{
int indent = indentation + rightChildIndent;
if (!isRootVisible && depth == 0)
indent = 0;
- else if ((!isRootVisible && !curr.equals(mod.getRoot())) ||
- isRootVisible)
+ else if ((!isRootVisible && !curr.equals(mod.getRoot()))
+ || isRootVisible)
{
g.setColor(getHashColor());
heightOfLine = descent + halfHeight;
- g.drawLine(indentation + halfWidth, heightOfLine, indentation
- + rightChildIndent, heightOfLine);
+ g.drawLine(indentation + halfWidth, heightOfLine,
+ indentation + rightChildIndent, heightOfLine);
}
-
- descent = paintRecursive(g, indent,
- descent, i, depth + 1, tree, mod,
- mod.getChild(curr, i));
+
+ descent = paintRecursive(g, indent, descent, i, depth + 1,
+ tree, mod, mod.getChild(curr, i));
}
}
}
-
- if (tree.isExpanded(new TreePath(getPathToRoot(((TreeNode) curr), 0))))
- if (y0 != heightOfLine)
+
+ if (tree.isExpanded(new TreePath(getPathToRoot(curr, 0))))
+ if (y0 != heightOfLine && mod.getChildCount(curr) > 0)
{
g.setColor(getHashColor());
g.drawLine(indentation + halfWidth, y0, indentation + halfWidth,
heightOfLine);
}
-
+
return descent;
}
-
+
/**
* Recursively paints all the control icons on the tree.
* Package private for use in inner classes.
@@ -2711,51 +2759,49 @@ public class BasicTreeUI extends TreeUI
* @return int - current descent of the tree
*/
int paintControlIcons(Graphics g, int indentation, int descent,
- int childNumber, int depth, JTree tree, TreeModel mod, Object node)
+ int childNumber, int depth, JTree tree, TreeModel mod,
+ Object node)
{
int h = descent;
int rowHeight = getRowHeight();
- Icon ei = UIManager.getLookAndFeelDefaults()
- .getIcon("Tree.expandedIcon");
- Icon ci = UIManager.getLookAndFeelDefaults()
- .getIcon("Tree.collapsedIcon");
+ Icon ei = UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon");
+ Icon ci = UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon");
Rectangle clip = g.getClipBounds();
if (indentation > clip.x + clip.width + rightChildIndent
|| descent > clip.y + clip.height + getRowHeight())
return descent;
-
+
if (mod.isLeaf(node))
descent += rowHeight;
- else
+ else
{
if (depth > 0 || tree.isRootVisible())
descent += rowHeight;
-
+
int max = mod.getChildCount(node);
- if (tree.isExpanded(new TreePath(getPathToRoot(((TreeNode) node), 0))))
+ if (tree.isExpanded(new TreePath(getPathToRoot(node, 0))))
{
if (!node.equals(mod.getRoot()))
- drawCentered(tree, g, ei, indentation - rightChildIndent - 3, h);
-
- for (int i = 0; i < max; ++i)
+ ei.paintIcon(tree, g, indentation - rightChildIndent - 3, h);
+
+ for (int i = 0; i < max; i++)
{
int indent = indentation + rightChildIndent;
if (depth == 0 && !tree.isRootVisible())
indent = -1;
-
- descent = paintControlIcons(g, indent,
- descent, i, depth + 1, tree, mod,
- mod.getChild(node, i));
+
+ descent = paintControlIcons(g, indent, descent, i, depth + 1,
+ tree, mod, mod.getChild(node, i));
}
}
else if (!node.equals(mod.getRoot()))
- drawCentered(tree, g, ei, indentation - rightChildIndent - 3,
+ ci.paintIcon(tree, g, indentation - rightChildIndent - 3,
descent - getRowHeight());
}
-
+
return descent;
}
-
+
/**
* Returns true if the LookAndFeel implements the control icons
* Package private for use in inner classes.
@@ -2764,47 +2810,84 @@ public class BasicTreeUI extends TreeUI
*/
boolean hasControlIcons()
{
- if (UIManager.getLookAndFeelDefaults().
- getIcon("Tree.expandedIcon") == null ||
- UIManager.getLookAndFeelDefaults().
- getIcon("Tree.collapsedIcon") == null)
+ if (UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon") == null
+ || UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon") == null)
return false;
return true;
}
-
+
/**
- * Get next visible node in the tree.
- * Package private for use in inner classes.
+ * Returns the parent of the current node
+ *
+ * @param root is the root of the tree
+ * @param node is the current node
+ * @return is the parent of the current node
+ */
+ Object getParent(Object root, Object node)
+ {
+ if (root == null || node == null)
+ return null;
+ if (node instanceof TreeNode)
+ return ((TreeNode) node).getParent();
+ return findNode(root, node);
+ }
+
+ /**
+ * Recursively checks the tree for the specified node, starting
+ * at the root.
+ *
+ * @param root is starting node to start searching at.
+ * @param node is the node to search for
+ * @return the parent node of node
+ */
+ private Object findNode(Object root, Object node)
+ {
+ TreeModel mod = tree.getModel();
+ for (int i = 0; i < mod.getChildCount(root); i++)
+ {
+ if (mod.getIndexOfChild(root, node) != -1)
+ return root;
+
+ Object n = findNode(mod.getChild(root, i), node);
+ if (n != null)
+ return n;
+ }
+ return null;
+ }
+
+ /**
+ * Get next visible node in the tree. Package private for use in inner
+ * classes.
*
* @param the current node
* @return the next visible node in the JTree. Return null if there are no
* more.
*/
- TreeNode getNextVisibleNode(TreeNode node)
+ Object getNextVisibleNode(Object node)
{
- TreeNode next = null;
+ Object next = null;
TreePath current = null;
-
+
if (node != null)
next = getNextNode(node);
-
+
if (next != null)
{
current = new TreePath(getPathToRoot(next, 0));
if (tree.isVisible(current))
return next;
-
+
while (next != null && !tree.isVisible(current))
{
next = getNextNode(next);
-
+
if (next != null)
current = new TreePath(getPathToRoot(next, 0));
}
}
return next;
}
-
+
/**
* Get previous visible node in the tree.
* Package private for use in inner classes.
@@ -2813,53 +2896,54 @@ public class BasicTreeUI extends TreeUI
* @return the next visible node in the JTree. Return null if there are no
* more.
*/
- TreeNode getPreviousVisibleNode(TreeNode node)
+ Object getPreviousVisibleNode(Object node)
{
- TreeNode prev = null;
+ Object prev = null;
TreePath current = null;
-
+
if (node != null)
prev = getPreviousNode(node);
-
+
if (prev != null)
{
current = new TreePath(getPathToRoot(prev, 0));
if (tree.isVisible(current))
return prev;
-
+
while (prev != null && !tree.isVisible(current))
{
prev = getPreviousNode(prev);
-
+
if (prev != null)
current = new TreePath(getPathToRoot(prev, 0));
}
}
return prev;
}
-
+
/**
* Returns the next node in the tree
* Package private for use in inner classes.
*
- * @return TreeNode, the next node in the tree
+ * @param the current node
+ * @return the next node in the tree
*/
- TreeNode getNextNode(TreeNode curr)
+ Object getNextNode(Object curr)
{
- if (curr.getChildCount() != 0)
- return curr.getChildAt(0);
+ TreeModel mod = tree.getModel();
+ if (mod.getChildCount(curr) > 0)
+ return mod.getChild(curr, 0);
+
+ Object node = curr;
+ Object sibling = null;
- TreeNode node = curr;
- TreeNode sibling;
-
do
{
sibling = getNextSibling(node);
- node = node.getParent();
+ node = getParent(mod.getRoot(), node);
}
- while (sibling == null &&
- node != null);
-
+ while (sibling == null && node != null);
+
return sibling;
}
@@ -2867,69 +2951,75 @@ public class BasicTreeUI extends TreeUI
* Returns the previous node in the tree
* Package private for use in inner classes.
*
- * @return TreeNode, the previous node in the tree
+ * @param the current node
+ * @return the previous node in the tree
*/
- TreeNode getPreviousNode(TreeNode node)
+ Object getPreviousNode(Object node)
{
- TreeNode parent = node.getParent();
+ TreeModel mod = tree.getModel();
+ Object parent = getParent(mod.getRoot(), node);
if (parent == null)
return null;
-
- TreeNode sibling = getPreviousSibling(node);
+
+ Object sibling = getPreviousSibling(node);
if (sibling == null)
return parent;
- int size = sibling.getChildCount();
+ int size = mod.getChildCount(sibling);
while (size > 0)
- {
- sibling = sibling.getChildAt(size - 1);
- size = sibling.getChildCount();
- }
-
+ {
+ sibling = mod.getChild(sibling, size - 1);
+ size = mod.getChildCount(sibling);
+ }
+
return sibling;
}
-
+
/**
* Returns the next sibling in the tree
* Package private for use in inner classes.
*
- * @return TreeNode, the next sibling in the tree
+ * @param the current node
+ * @return the next sibling in the tree
*/
- TreeNode getNextSibling(TreeNode node)
+ Object getNextSibling(Object node)
{
- TreeNode parent = node.getParent();
+ TreeModel mod = tree.getModel();
+ Object parent = getParent(mod.getRoot(), node);
if (parent == null)
return null;
- int index = parent.getIndex(node) + 1;
-
- if (index == parent.getChildCount())
+ int index = mod.getIndexOfChild(parent, node) + 1;
+
+ if (index == 0 || index >= mod.getChildCount(parent))
return null;
- return parent.getChildAt(index);
+ return mod.getChild(parent, index);
}
/**
* Returns the previous sibling in the tree
* Package private for use in inner classes.
- *
- * @return TreeNode, the previous sibling in the tree
+ *
+ * @param the current node
+ * @return the previous sibling in the tree
*/
- TreeNode getPreviousSibling(TreeNode node)
+ Object getPreviousSibling(Object node)
{
- TreeNode parent = node.getParent();
+ TreeModel mod = tree.getModel();
+ Object parent = getParent(mod.getRoot(), node);
if (parent == null)
return null;
- int index = parent.getIndex(node) - 1;
+ int index = mod.getIndexOfChild(parent, node) - 1;
- if (index < 0)
+ if (index < 0 || index >= mod.getChildCount(parent))
return null;
- return parent.getChildAt(index);
+ return mod.getChild(parent, index);
}
-
+
/**
* Selects the specified path in the tree depending on modes.
* Package private for use in inner classes.
@@ -2943,15 +3033,13 @@ public class BasicTreeUI extends TreeUI
{
if (tree.isPathSelected(path))
tree.removeSelectionPath(path);
- else if (tree.getSelectionModel().getSelectionMode()
- == TreeSelectionModel.SINGLE_TREE_SELECTION)
+ else if (tree.getSelectionModel().getSelectionMode() == TreeSelectionModel.SINGLE_TREE_SELECTION)
{
tree.getSelectionModel().clearSelection();
tree.addSelectionPath(path);
tree.setLeadSelectionPath(path);
}
- else if (tree.getSelectionModel().getSelectionMode()
- == TreeSelectionModel.CONTIGUOUS_TREE_SELECTION)
+ else if (tree.getSelectionModel().getSelectionMode() == TreeSelectionModel.CONTIGUOUS_TREE_SELECTION)
{
// TODO
}
@@ -2964,7 +3052,7 @@ public class BasicTreeUI extends TreeUI
}
}
}
-
+
/**
* Returns the path from node to the root.
* Package private for use in inner classes.
@@ -2974,41 +3062,43 @@ public class BasicTreeUI extends TreeUI
*
* @return an array of tree nodes that represent the path to node.
*/
- TreeNode[] getPathToRoot(TreeNode node, int depth)
+ Object[] getPathToRoot(Object node, int depth)
{
+ TreeModel mod = tree.getModel();
if (node == null)
{
if (depth == 0)
return null;
-
- return new TreeNode[depth];
+
+ return new Object[depth];
}
- TreeNode[] path = getPathToRoot(node.getParent(), depth + 1);
+ Object[] path = getPathToRoot(getParent(mod.getRoot(), node), depth + 1);
path[path.length - depth - 1] = node;
return path;
}
-
+
/**
* Returns the level of the node in the tree.
*
+ * @param the current node
* @return the number of the level
*/
- public int getLevel(TreeNode node)
+ int getLevel(Object node)
{
int count = -1;
- TreeNode current = node;
+ Object current = node;
do
{
- current = current.getParent();
+ current = getParent(tree.getModel().getRoot(), current);
count++;
}
while (current != null);
return count;
}
-
+
/**
* Draws a vertical line using the given graphic context
*
@@ -3018,10 +3108,12 @@ public class BasicTreeUI extends TreeUI
* @param top specifies the top of the line
* @param bottom specifies the bottom of the line
*/
- protected void paintVerticalLine(Graphics g, JComponent c, int x, int top, int bottom) {
+ protected void paintVerticalLine(Graphics g, JComponent c, int x, int top,
+ int bottom)
+ {
g.drawLine(x, top, x, bottom);
}
-
+
/**
* Draws a horizontal line using the given graphic context
*
@@ -3031,10 +3123,12 @@ public class BasicTreeUI extends TreeUI
* @param left specifies the left point of the line
* @param right specifies the right point of the line
*/
- protected void paintHorizontalLine(Graphics g, JComponent c, int y, int left, int right) {
+ protected void paintHorizontalLine(Graphics g, JComponent c, int y, int left,
+ int right)
+ {
g.drawLine(left, y, right, y);
}
-
+
/**
* Draws an icon at around a specific position
*
@@ -3046,9 +3140,10 @@ public class BasicTreeUI extends TreeUI
*
* FIXME what to do if x < (icon.width / 2). Same with y
*/
- protected void drawCentered(JComponent c, Graphics g, Icon icon, int x, int y) {
+ protected void drawCentered(JComponent 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);
- }
-} // BasicTreeUI \ No newline at end of file
+ }
+} // BasicTreeUI
diff --git a/javax/swing/plaf/basic/BasicViewportUI.java b/javax/swing/plaf/basic/BasicViewportUI.java
index 29074e60f..0d461332a 100644
--- a/javax/swing/plaf/basic/BasicViewportUI.java
+++ b/javax/swing/plaf/basic/BasicViewportUI.java
@@ -161,17 +161,17 @@ public class BasicViewportUI extends ViewportUI
Rectangle portBounds)
{
Rectangle oldClip = g.getClipBounds();
- g.setClip(portBounds);
+ g.setClip(new Rectangle(0, 0, portBounds.width, portBounds.height));
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,
diff --git a/javax/swing/plaf/metal/MetalLookAndFeel.java b/javax/swing/plaf/metal/MetalLookAndFeel.java
index a6cce510d..7579c689b 100644
--- a/javax/swing/plaf/metal/MetalLookAndFeel.java
+++ b/javax/swing/plaf/metal/MetalLookAndFeel.java
@@ -44,6 +44,8 @@ import java.awt.Insets;
import javax.swing.ImageIcon;
import javax.swing.UIDefaults;
+import javax.swing.border.Border;
+import javax.swing.plaf.BorderUIResource;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.FontUIResource;
import javax.swing.plaf.IconUIResource;
@@ -864,6 +866,8 @@ public class MetalLookAndFeel extends BasicLookAndFeel
"Tree.selectionBackground", new ColorUIResource(new Color(204, 204, 255)),
"Tree.nonSelectionBackground", new ColorUIResource(Color.white),
"Tree.selectionBorderColor", new ColorUIResource(new Color(102, 102, 153)),
+ "Tree.selectionBorder", new BorderUIResource.LineBorderUIResource(new Color(102, 102, 153)),
+ "Tree.nonSelectionBorder", new BorderUIResource.LineBorderUIResource(Color.white),
"Tree.selectionForeground", new ColorUIResource(Color.black),
"Tree.textBackground", new ColorUIResource(new Color(204, 204, 255)),
"Tree.textForeground", new ColorUIResource(Color.black),
diff --git a/javax/swing/table/DefaultTableCellRenderer.java b/javax/swing/table/DefaultTableCellRenderer.java
index 02e9fd7dc..349f4baad 100644
--- a/javax/swing/table/DefaultTableCellRenderer.java
+++ b/javax/swing/table/DefaultTableCellRenderer.java
@@ -47,6 +47,7 @@ import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
+import javax.swing.JTextField;
/**
* Class to display every cells.
@@ -123,7 +124,11 @@ public class DefaultTableCellRenderer extends JLabel
int row, int column)
{
if (value != null)
- super.setText(value.toString());
+ {
+ if (value instanceof JTextField)
+ return new JTextField(((JTextField)value).getText());
+ super.setText(value.toString());
+ }
setOpaque(true);
diff --git a/javax/swing/text/GapContent.java b/javax/swing/text/GapContent.java
index d7bad0a08..dcd81d5b0 100644
--- a/javax/swing/text/GapContent.java
+++ b/javax/swing/text/GapContent.java
@@ -228,19 +228,8 @@ public class GapContent
throw new BadLocationException("the where argument cannot be greater"
+ " than the content length", where);
- // check if the gap is big enough to hold the string
- if ((gapEnd - gapStart) < strLen)
- // make room for this string and some more
- shiftEnd(strLen + DEFAULT_BUFSIZE);
-
- // are we at the gap boundary?
- if (where != gapStart)
- shiftGap(where);
-
- // now we can simple copy the string into the gap and adjust the
- // gap boundaries
- System.arraycopy(str.toCharArray(), 0, buffer, gapStart, strLen);
- gapStart += strLen;
+ replace(where, 0, str.toCharArray(), str.length());
+
return null;
}
@@ -268,12 +257,8 @@ public class GapContent
throw new BadLocationException("where + nitems cannot be greater"
+ " than the content length", where + nitems);
- // check if we are at the gap boundary
- if (where != gapStart)
- shiftGap(where);
+ replace(where, nitems, null, 0);
- // now we simply have to enlarge the gap
- gapEnd += nitems;
return null;
}
@@ -419,40 +404,40 @@ public class GapContent
// Update the positions between newGapEnd and (old) gapEnd. The marks
// must be shifted by (gapEnd - newGapEnd).
- int index1 = Collections.binarySearch(positions, new GapContentPosition(
- gapEnd));
- int index2 = Collections.binarySearch(positions, new GapContentPosition(
- newGapEnd));
+ int index1 = Collections.binarySearch(positions,
+ new GapContentPosition(gapEnd));
+ int index2 = Collections.binarySearch(positions,
+ new GapContentPosition(newGapEnd));
if (index1 > 0 && index2 > 0)
- {
- int i1 = Math.min(index1, index2);
- int i2 = Math.max(index1, index2);
- for (ListIterator i = positions.listIterator(i1); i.hasNext();)
{
- if (i.nextIndex() > i2)
- break;
-
- GapContentPosition p = (GapContentPosition) i.next();
- p.mark += gapEnd - newGapEnd;
+ int i1 = Math.min(index1, index2);
+ int i2 = Math.max(index1, index2);
+ for (ListIterator i = positions.listIterator(i1); i.hasNext();)
+ {
+ if (i.nextIndex() > i2)
+ break;
+
+ GapContentPosition p = (GapContentPosition) i.next();
+ p.mark += gapEnd - newGapEnd;
+ }
}
- if (newGapStart == gapStart)
- return;
- else if (newGapStart < gapStart)
+ if (newGapStart == gapStart)
+ return;
+ else if (newGapStart < gapStart)
{
System.arraycopy(buffer, newGapStart, buffer, newGapEnd, gapStart
- - newGapStart);
+ - newGapStart);
gapStart = newGapStart;
gapEnd = newGapEnd;
}
- else
+ else
{
System.arraycopy(buffer, gapEnd, buffer, gapStart, newGapStart
- - gapStart);
+ - gapStart);
gapStart = newGapStart;
gapEnd = newGapEnd;
}
- }
}
/**
@@ -473,7 +458,8 @@ public class GapContent
* @param addItems the items to add at location
* @param addSize the number of items to add
*/
- protected void replace(int position, int rmSize, Object addItems, int addSize)
+ protected void replace(int position, int rmSize, Object addItems,
+ int addSize)
{
// Remove content
shiftGap(position);
@@ -484,7 +470,10 @@ public class GapContent
shiftEnd(addSize);
// Add new items to the buffer.
- System.arraycopy(addItems, 0, buffer, gapStart, addSize);
- gapStart += addSize;
+ if (addItems != null)
+ {
+ System.arraycopy(addItems, 0, buffer, gapStart, addSize);
+ gapStart += addSize;
+ }
}
}
diff --git a/javax/swing/tree/DefaultTreeCellRenderer.java b/javax/swing/tree/DefaultTreeCellRenderer.java
index 0f1792161..c3d96e297 100644
--- a/javax/swing/tree/DefaultTreeCellRenderer.java
+++ b/javax/swing/tree/DefaultTreeCellRenderer.java
@@ -44,6 +44,7 @@ import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle;
+import javax.swing.border.Border;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JTree;
@@ -390,7 +391,7 @@ public class DefaultTreeCellRenderer
this.selected = selected;
this.hasFocus = hasFocus;
setHorizontalAlignment(LEFT);
- setOpaque(true);
+ setOpaque(false);
setVerticalAlignment(TOP);
setEnabled(true);
super.setFont(UIManager.getLookAndFeelDefaults().getFont("Tree.font"));
@@ -399,13 +400,15 @@ public class DefaultTreeCellRenderer
{
super.setBackground(getBackgroundSelectionColor());
setForeground(getTextSelectionColor());
+ setBorder(UIManager.getLookAndFeelDefaults().getBorder("Tree.selectionBorder"));
}
else
{
super.setBackground(getBackgroundNonSelectionColor());
setForeground(getTextNonSelectionColor());
- }
-
+ setBorder(UIManager.getLookAndFeelDefaults().getBorder("Tree.nonSelectionBorder"));
+ }
+
return this;
}
diff --git a/javax/swing/tree/DefaultTreeModel.java b/javax/swing/tree/DefaultTreeModel.java
index e4291e130..b8042a47a 100644
--- a/javax/swing/tree/DefaultTreeModel.java
+++ b/javax/swing/tree/DefaultTreeModel.java
@@ -1,6 +1,6 @@
-/* DefaultTreeModel.java --
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
-
+/* DefaultTreeModel.java --
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
@@ -10,16 +10,16 @@ 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
+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
+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
+making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
@@ -29,13 +29,12 @@ 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
+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
+obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package javax.swing.tree;
import java.io.IOException;
@@ -51,405 +50,434 @@ import javax.swing.tree.DefaultMutableTreeNode;
/**
* DefaultTreeModel
+ *
* @author Andrew Selkirk
*/
public class DefaultTreeModel
- implements Serializable, TreeModel
+ implements Serializable, TreeModel
{
- static final long serialVersionUID = -2621068368932566998L;
-
- /**
- * root
- */
- protected TreeNode root = null;
-
- /**
- * listenerList
- */
- protected EventListenerList listenerList = new EventListenerList();
-
- /**
- * asksAllowsChildren
- */
- protected boolean asksAllowsChildren;
-
- /**
- * Constructor DefaultTreeModel
- * @param root the tree root.
- */
- public DefaultTreeModel(TreeNode root)
- {
- if (root == null)
- root = new DefaultMutableTreeNode();
- setRoot(root);
- }
-
- /**
- * Constructor DefaultTreeModel
- * @param root the tree root.
- * @param asksAllowsChildren TODO
- */
- public DefaultTreeModel(TreeNode root, boolean asksAllowsChildren)
- {
- setRoot(root);
- this.asksAllowsChildren = asksAllowsChildren;
- }
-
- /**
- * writeObject
- * @param obj the object.
- * @exception IOException TODO
- */
- private void writeObject(ObjectOutputStream obj) throws IOException
- {
- // TODO
- }
-
- /**
- * readObject
- * @param value0 TODO
- * @exception IOException TODO
- * @exception ClassNotFoundException TODO
- */
- private void readObject(ObjectInputStream value0) throws IOException,
- ClassNotFoundException
- {
- // TODO
- }
-
- /**
- * asksAllowsChildren
- * @return boolean
- */
- public boolean asksAllowsChildren()
- {
- return asksAllowsChildren;
- }
-
- /**
- * setAsksAllowsChildren
- * @param value TODO
- */
- public void setAsksAllowsChildren(boolean value)
- {
- asksAllowsChildren = value; // TODO
- }
-
- /**
- * setRoot
- * @param root the root node.
- */
- public void setRoot(TreeNode root)
- {
- // Sanity Check
- if (root == null)
- {
- throw new IllegalArgumentException("null root");
- }
- // Set new root
- this.root = root;
-
- // TODO
- }
-
- /**
- * getRoot
- * @return Object
- */
- public Object getRoot()
- {
- return root;
- }
-
- /**
- * getIndexOfChild
- * @param parent TODO
- * @param child TODO
- * @return int
- */
- public int getIndexOfChild(Object parent, Object child)
- {
- return 0; // TODO
- }
-
- /**
- * getChild
- * @param node TODO
- * @param idx TODO
- * @return Object
- */
- public Object getChild(Object node, int idx)
- {
- if (node instanceof TreeNode)
- return ((TreeNode) node).getChildAt(idx);
- else
- return null;
- }
-
- /**
- * getChildCount
- * @param node TODO
- * @return int
- */
- public int getChildCount(Object node)
- {
- if (node instanceof TreeNode)
- return ((TreeNode) node).getChildCount();
- else
- return 0;
- }
-
- /**
- * isLeaf
- * @param node TODO
- * @return boolean
- */
- public boolean isLeaf(Object node)
- {
- if (node instanceof TreeNode)
- return ((TreeNode) node).isLeaf();
- else
- return true;
- }
-
- /**
- * reload
- */
- public void reload()
- {
- // TODO
- }
-
- /**
- * reload
- * @param value0 TODO
- */
- public void reload(TreeNode value0)
- {
- // TODO
- }
-
- /**
- * valueForPathChanged
- * @param value0 TODO
- * @param value1 TODO
- */
- public void valueForPathChanged(TreePath value0, Object value1)
- {
- // TODO
- }
-
- /**
- * insertNodeInto
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- public void insertNodeInto(MutableTreeNode value0, MutableTreeNode value1,
- int value2)
- {
- // TODO
- }
-
- /**
- * removeNodeFromParent
- * @param value0 TODO
- */
- public void removeNodeFromParent(MutableTreeNode value0)
- {
- // TODO
- }
-
- /**
- * nodeChanged
- * @param value0 TODO
- */
- public void nodeChanged(TreeNode value0)
- {
- // TODO
- }
-
- /**
- * nodesWereInserted
- * @param value0 TODO
- * @param value1 TODO
- */
- public void nodesWereInserted(TreeNode value0, int[] value1)
- {
- // TODO
- }
-
- /**
- * nodesWereRemoved
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- public void nodesWereRemoved(TreeNode value0, int[] value1, Object[] value2)
- {
- // TODO
- }
-
- /**
- * nodesChanged
- * @param value0 TODO
- * @param value1 TODO
- */
- public void nodesChanged(TreeNode value0, int[] value1)
- {
- // TODO
- }
-
- /**
- * nodeStructureChanged
- * @param value0 TODO
- */
- public void nodeStructureChanged(TreeNode value0)
- {
- // TODO
- }
-
- /**
- * getPathToRoot
- * @param value0 TODO
- * @return TreeNode[]
- */
- public TreeNode[] getPathToRoot(TreeNode value0)
- {
- return null; // TODO
- }
-
- /**
- * getPathToRoot
- * @param value0 TODO
- * @param value1 TODO
- * @return TreeNode[]
- */
- protected TreeNode[] getPathToRoot(TreeNode value0, int value1)
- {
- return null; // TODO
- }
-
- /**
- * Registers a listere to the model.
- *
- * @param listener the listener to add
- */
- public void addTreeModelListener(TreeModelListener listener)
- {
- listenerList.add(TreeModelListener.class, listener);
- }
-
- /**
- * Removes a listener from the model.
- *
- * @param listener the listener to remove
- */
- public void removeTreeModelListener(TreeModelListener listener)
- {
- listenerList.remove(TreeModelListener.class, listener);
- }
-
- /**
- * Returns all registered <code>TreeModelListener</code> listeners.
- *
- * @return an array of listeners.
- *
- * @since 1.4
- */
- public TreeModelListener[] getTreeModelListeners()
- {
- return (TreeModelListener[]) listenerList
- .getListeners(TreeModelListener.class);
- }
-
- /**
- * fireTreeNodesChanged
- *
- * @param source the node being changed
- * @param path the path to the root node
- * @param childIndices the indices of the changed elements
- * @param children the changed elements
- */
- protected void fireTreeNodesChanged(Object source, Object[] path,
- int[] childIndices, Object[] children)
- {
- TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
- children);
- TreeModelListener[] listeners = getTreeModelListeners();
-
- for (int i = listeners.length - 1; i >= 0; --i)
- listeners[i].treeNodesChanged(event);
- }
-
- /**
- * fireTreeNodesInserted
- *
- * @param source the node where new nodes got inserted
- * @param path the path to the root node
- * @param childIndices the indices of the new elements
- * @param children the new elements
- */
- protected void fireTreeNodesInserted(Object source, Object[] path,
- int[] childIndices, Object[] children)
- {
- TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
- children);
- TreeModelListener[] listeners = getTreeModelListeners();
-
- for (int i = listeners.length - 1; i >= 0; --i)
- listeners[i].treeNodesInserted(event);
- }
-
- /**
- * fireTreeNodesRemoved
- *
- * @param source the node where nodes got removed-
- * @param path the path to the root node
- * @param childIndices the indices of the removed elements
- * @param children the removed elements
- */
- protected void fireTreeNodesRemoved(Object source, Object[] path,
- int[] childIndices, Object[] children)
- {
- TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
- children);
- TreeModelListener[] listeners = getTreeModelListeners();
-
- for (int i = listeners.length - 1; i >= 0; --i)
- listeners[i].treeNodesRemoved(event);
- }
-
- /**
- * fireTreeStructureChanged
- *
- * @param source the node where the model has changed
- * @param path the path to the root node
- * @param childIndices the indices of the affected elements
- * @param children the affected elements
- */
- protected void fireTreeStructureChanged(Object source, Object[] path,
- int[] childIndices, Object[] children)
- {
- TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
- children);
- TreeModelListener[] listeners = getTreeModelListeners();
-
- for (int i = listeners.length - 1; i >= 0; --i)
- listeners[i].treeStructureChanged(event);
- }
-
- /**
- * Returns the registered listeners of a given type.
- *
- * @param listenerType the listener type to return
- *
- * @return an array of listeners
- *
- * @since 1.3
- */
- public EventListener[] getListeners(Class listenerType)
- {
- return listenerList.getListeners(listenerType);
- }
+ static final long serialVersionUID = -2621068368932566998L;
+
+ /**
+ * root
+ */
+ protected TreeNode root = null;
+
+ /**
+ * listenerList
+ */
+ protected EventListenerList listenerList = new EventListenerList();
+
+ /**
+ * asksAllowsChildren
+ */
+ protected boolean asksAllowsChildren;
+
+ /**
+ * Constructor DefaultTreeModel
+ *
+ * @param root the tree root.
+ */
+ public DefaultTreeModel(TreeNode root)
+ {
+ if (root == null)
+ root = new DefaultMutableTreeNode();
+ setRoot(root);
+ }
+
+ /**
+ * Constructor DefaultTreeModel
+ *
+ * @param root the tree root.
+ * @param asksAllowsChildren TODO
+ */
+ public DefaultTreeModel(TreeNode root, boolean asksAllowsChildren)
+ {
+ setRoot(root);
+ this.asksAllowsChildren = asksAllowsChildren;
+ }
+
+ /**
+ * writeObject
+ *
+ * @param obj the object.
+ * @exception IOException TODO
+ */
+ private void writeObject(ObjectOutputStream obj) throws IOException
+ {
+ // TODO
+ }
+
+ /**
+ * readObject
+ *
+ * @param value0 TODO
+ * @exception IOException TODO
+ * @exception ClassNotFoundException TODO
+ */
+ private void readObject(ObjectInputStream value0) throws IOException,
+ ClassNotFoundException
+ {
+ // TODO
+ }
+
+ /**
+ * asksAllowsChildren
+ *
+ * @return boolean
+ */
+ public boolean asksAllowsChildren()
+ {
+ return asksAllowsChildren;
+ }
+
+ /**
+ * setAsksAllowsChildren
+ *
+ * @param value TODO
+ */
+ public void setAsksAllowsChildren(boolean value)
+ {
+ asksAllowsChildren = value; // TODO
+ }
+
+ /**
+ * setRoot
+ *
+ * @param root the root node.
+ */
+ public void setRoot(TreeNode root)
+ {
+ // Sanity Check
+ if (root == null)
+ {
+ throw new IllegalArgumentException("null root");
+ }
+ // Set new root
+ this.root = root;
+
+ // TODO
+ }
+
+ /**
+ * getRoot
+ *
+ * @return Object
+ */
+ public Object getRoot()
+ {
+ return root;
+ }
+
+ /**
+ * getIndexOfChild
+ *
+ * @param parent TODO
+ * @param child TODO
+ * @return int
+ */
+ public int getIndexOfChild(Object parent, Object child)
+ {
+ for (int i = 0; i < getChildCount(parent); i++)
+ {
+ if (getChild(parent, i).equals(child))
+ return i;
+ }
+ return -1;
+ }
+
+ /**
+ * getChild
+ *
+ * @param node TODO
+ * @param idx TODO
+ * @return Object
+ */
+ public Object getChild(Object node, int idx)
+ {
+ if (node instanceof TreeNode)
+ return ((TreeNode) node).getChildAt(idx);
+ else
+ return null;
+ }
+
+ /**
+ * getChildCount
+ *
+ * @param node TODO
+ * @return int
+ */
+ public int getChildCount(Object node)
+ {
+ if (node instanceof TreeNode)
+ return ((TreeNode) node).getChildCount();
+ else
+ return 0;
+ }
+
+ /**
+ * isLeaf
+ *
+ * @param node TODO
+ * @return boolean
+ */
+ public boolean isLeaf(Object node)
+ {
+ if (node instanceof TreeNode)
+ return ((TreeNode) node).isLeaf();
+ else
+ return true;
+ }
+
+ /**
+ * reload
+ */
+ public void reload()
+ {
+ // TODO
+ }
+
+ /**
+ * reload
+ *
+ * @param value0 TODO
+ */
+ public void reload(TreeNode value0)
+ {
+ // TODO
+ }
+
+ /**
+ * valueForPathChanged
+ *
+ * @param value0 TODO
+ * @param value1 TODO
+ */
+ public void valueForPathChanged(TreePath value0, Object value1)
+ {
+ // TODO
+ }
+
+ /**
+ * insertNodeInto
+ *
+ * @param value0 TODO
+ * @param value1 TODO
+ * @param value2 TODO
+ */
+ public void insertNodeInto(MutableTreeNode value0, MutableTreeNode value1,
+ int value2)
+ {
+ // TODO
+ }
+
+ /**
+ * removeNodeFromParent
+ *
+ * @param value0 TODO
+ */
+ public void removeNodeFromParent(MutableTreeNode value0)
+ {
+ // TODO
+ }
+
+ /**
+ * nodeChanged
+ *
+ * @param value0 TODO
+ */
+ public void nodeChanged(TreeNode value0)
+ {
+ // TODO
+ }
+
+ /**
+ * nodesWereInserted
+ *
+ * @param value0 TODO
+ * @param value1 TODO
+ */
+ public void nodesWereInserted(TreeNode value0, int[] value1)
+ {
+ // TODO
+ }
+
+ /**
+ * nodesWereRemoved
+ *
+ * @param value0 TODO
+ * @param value1 TODO
+ * @param value2 TODO
+ */
+ public void nodesWereRemoved(TreeNode value0, int[] value1, Object[] value2)
+ {
+ // TODO
+ }
+
+ /**
+ * nodesChanged
+ *
+ * @param value0 TODO
+ * @param value1 TODO
+ */
+ public void nodesChanged(TreeNode value0, int[] value1)
+ {
+ // TODO
+ }
+
+ /**
+ * nodeStructureChanged
+ *
+ * @param value0 TODO
+ */
+ public void nodeStructureChanged(TreeNode value0)
+ {
+ // TODO
+ }
+
+ /**
+ * getPathToRoot
+ *
+ * @param value0 TODO
+ * @return TreeNode[]
+ */
+ public TreeNode[] getPathToRoot(TreeNode value0)
+ {
+ return null; // TODO
+ }
+
+ /**
+ * getPathToRoot
+ *
+ * @param value0 TODO
+ * @param value1 TODO
+ * @return TreeNode[]
+ */
+ protected TreeNode[] getPathToRoot(TreeNode value0, int value1)
+ {
+ return null; // TODO
+ }
+
+ /**
+ * Registers a listere to the model.
+ *
+ * @param listener the listener to add
+ */
+ public void addTreeModelListener(TreeModelListener listener)
+ {
+ listenerList.add(TreeModelListener.class, listener);
+ }
+
+ /**
+ * Removes a listener from the model.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeTreeModelListener(TreeModelListener listener)
+ {
+ listenerList.remove(TreeModelListener.class, listener);
+ }
+
+ /**
+ * Returns all registered <code>TreeModelListener</code> listeners.
+ *
+ * @return an array of listeners.
+ *
+ * @since 1.4
+ */
+ public TreeModelListener[] getTreeModelListeners()
+ {
+ return (TreeModelListener[]) listenerList
+ .getListeners(TreeModelListener.class);
+ }
+
+ /**
+ * fireTreeNodesChanged
+ *
+ * @param source the node being changed
+ * @param path the path to the root node
+ * @param childIndices the indices of the changed elements
+ * @param children the changed elements
+ */
+ protected void fireTreeNodesChanged(Object source, Object[] path,
+ int[] childIndices, Object[] children)
+ {
+ TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
+ children);
+ TreeModelListener[] listeners = getTreeModelListeners();
+
+ for (int i = listeners.length - 1; i >= 0; --i)
+ listeners[i].treeNodesChanged(event);
+ }
+
+ /**
+ * fireTreeNodesInserted
+ *
+ * @param source the node where new nodes got inserted
+ * @param path the path to the root node
+ * @param childIndices the indices of the new elements
+ * @param children the new elements
+ */
+ protected void fireTreeNodesInserted(Object source, Object[] path,
+ int[] childIndices, Object[] children)
+ {
+ TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
+ children);
+ TreeModelListener[] listeners = getTreeModelListeners();
+
+ for (int i = listeners.length - 1; i >= 0; --i)
+ listeners[i].treeNodesInserted(event);
+ }
+
+ /**
+ * fireTreeNodesRemoved
+ *
+ * @param source the node where nodes got removed-
+ * @param path the path to the root node
+ * @param childIndices the indices of the removed elements
+ * @param children the removed elements
+ */
+ protected void fireTreeNodesRemoved(Object source, Object[] path,
+ int[] childIndices, Object[] children)
+ {
+ TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
+ children);
+ TreeModelListener[] listeners = getTreeModelListeners();
+
+ for (int i = listeners.length - 1; i >= 0; --i)
+ listeners[i].treeNodesRemoved(event);
+ }
+
+ /**
+ * fireTreeStructureChanged
+ *
+ * @param source the node where the model has changed
+ * @param path the path to the root node
+ * @param childIndices the indices of the affected elements
+ * @param children the affected elements
+ */
+ protected void fireTreeStructureChanged(Object source, Object[] path,
+ int[] childIndices, Object[] children)
+ {
+ TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
+ children);
+ TreeModelListener[] listeners = getTreeModelListeners();
+
+ for (int i = listeners.length - 1; i >= 0; --i)
+ listeners[i].treeStructureChanged(event);
+ }
+
+ /**
+ * Returns the registered listeners of a given type.
+ *
+ * @param listenerType the listener type to return
+ *
+ * @return an array of listeners
+ *
+ * @since 1.3
+ */
+ public EventListener[] getListeners(Class listenerType)
+ {
+ return listenerList.getListeners(listenerType);
+ }
}