[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: implemented more of JTree and JList

Kaffe CVS cvs-commits at kaffe.org
Fri Dec 3 06:18:13 PST 2004


PatchSet 5520 
Date: 2004/12/03 14:14:04
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: implemented more of JTree and JList

2004-12-03  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/javax/swing/JList.java,
        libraries/javalib/javax/swing/JTree.java:
        Resynced with GNU Classpath.

        2004-11-26  Michael Koch  <konqueror at gmx.de>

        * javax/swing/JList.java, javax/swing/JTree.java:
        Added much new methods and fixed much methods setting bound properties.

Members: 
	ChangeLog:1.3066->1.3067 
	libraries/javalib/javax/swing/JList.java:1.4->1.5 
	libraries/javalib/javax/swing/JTree.java:1.6->1.7 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3066 kaffe/ChangeLog:1.3067
--- kaffe/ChangeLog:1.3066	Fri Dec  3 14:00:18 2004
+++ kaffe/ChangeLog	Fri Dec  3 14:14:04 2004
@@ -1,5 +1,16 @@
 2004-12-03  Dalibor Topic  <robilad at kaffe.org>
 
+	* libraries/javalib/javax/swing/JList.java,
+	libraries/javalib/javax/swing/JTree.java:
+        Resynced with GNU Classpath.
+
+	2004-11-26  Michael Koch  <konqueror at gmx.de>
+
+	* javax/swing/JList.java, javax/swing/JTree.java:
+	Added much new methods and fixed much methods setting bound properties.
+
+2004-12-03  Dalibor Topic  <robilad at kaffe.org>
+
 	* libraries/javalib/gnu/java/awt/peer/gtk/GdkGraphics2D.java:
         Resynced with GNU Classpath.
 
Index: kaffe/libraries/javalib/javax/swing/JList.java
diff -u kaffe/libraries/javalib/javax/swing/JList.java:1.4 kaffe/libraries/javalib/javax/swing/JList.java:1.5
--- kaffe/libraries/javalib/javax/swing/JList.java:1.4	Sun Oct 24 13:39:11 2004
+++ kaffe/libraries/javalib/javax/swing/JList.java	Fri Dec  3 14:14:08 2004
@@ -250,12 +250,10 @@
    */
   int visibleRowCount;
 
-
-
   /**
    * Fire a {@link ListSelectionEvent} to all the registered ListSelectionListeners.
    */
-  void fireSelectionValueChanged(int firstIndex, int lastIndex, boolean isAdjusting) 
+  protected void fireSelectionValueChanged(int firstIndex, int lastIndex, boolean isAdjusting) 
   {
     ListSelectionEvent evt = new ListSelectionEvent(this, firstIndex, lastIndex, isAdjusting);
     ListSelectionListener listeners[] = getListSelectionListeners();
@@ -265,7 +263,6 @@
       }
   }
 
-
   /**
    * This private listener propagates {@link ListSelectionEvent} events
    * from the list's "selectionModel" property to the list's {@link
@@ -365,12 +362,22 @@
     listListener = new ListListener();
 
     setModel(new DefaultListModel());
-    setSelectionModel(new DefaultListSelectionModel());
+    setSelectionModel(createSelectionModel());
 
     updateUI();
   }
 
   /**
+   * Creates the default <code>ListSelectionModel</code>.
+   *
+   * @return the <code>ListSelectionModel</code>
+   */
+  protected ListSelectionModel createSelectionModel()
+  {
+    return new DefaultListSelectionModel();
+  }
+  
+  /**
    * Gets the value of the {@link #fixedCellHeight} property. This property
    * may be <code>-1</code> to indicate that no cell height has been
    * set. This property is also set implicitly when the
@@ -501,6 +508,11 @@
     return (ListSelectionListener[]) getListeners(ListSelectionListener.class);
   }
 
+  public int getSelectionMode()
+  {
+    return selectionModel.getSelectionMode();
+  }
+  
   /**
    * Sets the list's "selectionMode" property, which simply mirrors the
    * same property on the list's {@link #selectionModel} property. This
@@ -1195,5 +1207,120 @@
   public boolean getScrollableTracksViewportHeight()
   {
     return false;
+  }
+
+  public int getAnchorSelectionIndex()
+  {
+    return selectionModel.getAnchorSelectionIndex();
+  }
+
+  public int getLeadSelectionIndex()
+  {
+    return selectionModel.getLeadSelectionIndex();
+  }
+
+  public int getMinSelectionIndex()
+  {
+    return selectionModel.getMaxSelectionIndex();
+  }
+
+  public int getMaxSelectionIndex()
+  {
+    return selectionModel.getMaxSelectionIndex();
+  }
+
+  public void clearSelection()
+  {
+    selectionModel.clearSelection();
+  }
+
+  public void setSelectionInterval(int anchor, int lead)
+  {
+    selectionModel.setSelectionInterval(anchor, lead);
+  }
+
+  public void addSelectionInterval(int anchor, int lead)
+  {
+    selectionModel.addSelectionInterval(anchor, lead);
+  }
+
+  public void removeSelectionInterval(int index0, int index1)
+  {
+    selectionModel.removeSelectionInterval(index0, index1);
+  }
+
+  /**
+   * Returns the value of the <code>valueIsAdjusting</code> property.
+   *
+   * @return the value
+   */
+  public boolean getValueIsAdjusting()
+  {
+    return valueIsAdjusting;
+  }
+
+  /**
+   * Sets the <code>valueIsAdjusting</code> property.
+   *
+   * @param isAdjusting the new value
+   */
+  public void setValueIsAdjusting(boolean isAdjusting)
+  {
+    valueIsAdjusting = isAdjusting;
+  }
+
+  /**
+   * Return the value of the <code>dragEnabled</code> property.
+   *
+   * @return the value
+   * 
+   * @since 1.4
+   */
+  public boolean getDragEnabled()
+  {
+    return dragEnabled;
+  }
+
+  /**
+   * Set the <code>dragEnabled</code> property.
+   *
+   * @param enabled new value
+   * 
+   * @since 1.4
+   */
+  public void setDragEnabled(boolean enabled)
+  {
+    dragEnabled = enabled;
+  }
+
+  /**
+   * Returns the layout orientation.
+   *
+   * @return the orientation, one of <code>JList.VERTICAL</code>,
+   * </code>JList.VERTICAL_WRAP</code> and <code>JList.HORIZONTAL_WRAP</code>
+   *
+   * @since 1.4
+   */
+  public int getLayoutOrientation()
+  {
+    return layoutOrientation;
+  }
+
+  /**
+   * Sets the layout orientation.
+   *
+   * @param orientation the orientation to set, one of <code>JList.VERTICAL</code>,
+   * </code>JList.VERTICAL_WRAP</code> and <code>JList.HORIZONTAL_WRAP</code>
+   *
+   * @since 1.4
+   */
+  public void setLayoutOrientation(int orientation)
+  {
+    if (layoutOrientation == orientation)
+      return;
+
+    int old = layoutOrientation;
+    layoutOrientation = orientation;
+    firePropertyChange("layoutOrientation", old, orientation);
   }
 }
Index: kaffe/libraries/javalib/javax/swing/JTree.java
diff -u kaffe/libraries/javalib/javax/swing/JTree.java:1.6 kaffe/libraries/javalib/javax/swing/JTree.java:1.7
--- kaffe/libraries/javalib/javax/swing/JTree.java:1.6	Sat Nov 13 02:17:44 2004
+++ kaffe/libraries/javalib/javax/swing/JTree.java	Fri Dec  3 14:14:08 2004
@@ -87,6 +87,11 @@
   public static final String TREE_MODEL_PROPERTY = "model";
   public static final String VISIBLE_ROW_COUNT_PROPERTY = "visibleRowCount";
 
+  private boolean dragEnabled;
+  private boolean expandsSelectedPaths;
+  private TreePath anchorSelectionPath;
+  private TreePath leadSelectionPath;
+
   protected TreeCellEditor cellEditor;
   protected TreeCellRenderer cellRenderer;
   protected boolean editable;
@@ -247,6 +252,39 @@
     }
   }
 
+  public int getRowForPath(TreePath path)
+  {
+    TreeUI ui = getUI();
+
+    if (ui != null)
+      return ui.getRowForPath(this, path);
+
+    return -1;
+  }
+  
+  public TreePath getPathForRow(int row)
+  {
+    TreeUI ui = getUI();
+    return ui != null ? ui.getPathForRow(this, row) : null;
+  }
+
+  protected TreePath[] getPathBetweenRows(int index0, int index1)
+  {
+    TreeUI ui = getUI();
+    
+    if (ui == null)
+      return null;
+    
+    int minIndex = Math.min(index0, index1);
+    int maxIndex = Math.max(index0, index1);
+    TreePath[] paths = new TreePath[maxIndex - minIndex + 1];
+    
+    for (int i = minIndex; i <= maxIndex; ++i)
+      paths[i - minIndex] = ui.getPathForRow(this, i);
+
+    return paths;
+  }
+  
   /**
    * Creates a new <code>TreeModel</code> object.
    *
@@ -517,7 +555,12 @@
    */
   public void setModel(TreeModel model)
   {
+    if (treeModel == model)
+      return;
+
+    TreeModel oldValue = treeModel;
     treeModel = model;
+    firePropertyChange(TREE_MODEL_PROPERTY, oldValue, model);
   }
 
   /**
@@ -544,7 +587,7 @@
 
     boolean oldValue = editable;
     editable = flag;
-    firePropertyChange("editable", oldValue, editable);
+    firePropertyChange(EDITABLE_PROPERTY, oldValue, editable);
   }
 
   /**
@@ -560,7 +603,12 @@
 
   public void setRootVisible(boolean flag)
   {
+    if (rootVisible == flag)
+      return;
+    
+    boolean oldValue = rootVisible;
     rootVisible = flag;
+    firePropertyChange(ROOT_VISIBLE_PROPERTY, oldValue, flag);
   }
 
   public boolean getShowsRootHandles()
@@ -570,7 +618,12 @@
 
   public void setShowsRootHandles(boolean flag)
   {
+    if (showsRootHandles == flag)
+      return;
+
+    boolean oldValue = showsRootHandles;
     showsRootHandles = flag;
+    firePropertyChange(SHOWS_ROOT_HANDLES_PROPERTY, oldValue, flag);
   }
 
   public TreeCellEditor getCellEditor()
@@ -580,7 +633,12 @@
 
   public void setCellEditor(TreeCellEditor editor)
   {
+    if (cellEditor == editor)
+      return;
+
+    TreeCellEditor oldValue = cellEditor;
     cellEditor = editor;
+    firePropertyChange(CELL_EDITOR_PROPERTY, oldValue, editor);
   }
   
   public TreeCellRenderer getCellRenderer()
@@ -590,7 +648,12 @@
   
   public void setCellRenderer(TreeCellRenderer newRenderer)
   {
+    if (cellRenderer == newRenderer)
+      return;
+
+    TreeCellRenderer oldValue = cellRenderer;
     cellRenderer = newRenderer;
+    firePropertyChange(CELL_RENDERER_PROPERTY, oldValue, newRenderer);
   }
 
   public TreeSelectionModel getSelectionModel()
@@ -600,7 +663,12 @@
 
   public void setSelectionModel(TreeSelectionModel model)
   {
+    if (selectionModel == model)
+      return;
+    
+    TreeSelectionModel oldValue = selectionModel;
     selectionModel = model;
+    firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue, model);
   }
 
   public int getVisibleRowCount()
@@ -610,7 +678,12 @@
 
   public void setVisibleRowCount(int rows)
   {
+    if (visibleRowCount == rows)
+      return;
+
+    int oldValue = visibleRowCount;
     visibleRowCount = rows;
+    firePropertyChange(VISIBLE_ROW_COUNT_PROPERTY, oldValue, rows);
   }
 
   public boolean isLargeModel()
@@ -620,7 +693,12 @@
 
   public void setLargeModel(boolean large)
   {
+    if (largeModel == large)
+      return;
+
+    boolean oldValue = largeModel;
     largeModel = large;
+    firePropertyChange(LARGE_MODEL_PROPERTY, oldValue, large);
   }
 
   public int getRowHeight()
@@ -630,7 +708,17 @@
 
   public void setRowHeight(int height)
   {
+    if (rowHeight == height)
+      return;
+    
+    int oldValue = rowHeight;
     rowHeight = height;
+    firePropertyChange(ROW_HEIGHT_PROPERTY, oldValue, height);
+  }
+
+  public boolean isFixedRowHeight()
+  {
+    return rowHeight > 0;
   }
 
   public boolean getInvokesStopCellEditing()
@@ -640,7 +728,12 @@
 
   public void setInvokesStopCellEditing(boolean invoke)
   {
+    if (invokesStopCellEditing == invoke)
+     return;
+
+    boolean oldValue = invokesStopCellEditing;
     invokesStopCellEditing = invoke;
+    firePropertyChange(INVOKES_STOP_CELL_EDITING_PROPERTY, oldValue, invoke);
   }
 
   /**
@@ -656,7 +749,12 @@
    */
   public void setToggleClickCount(int count)
   {
+    if (toggleClickCount == count)
+      return;
+    
+    int oldValue = toggleClickCount;
     toggleClickCount = count;
+    firePropertyChange(TOGGLE_CLICK_COUNT_PROPERTY, oldValue, count);
   }
 
   public boolean getScrollsOnExpand()
@@ -666,6 +764,401 @@
 
   public void setScrollsOnExpand(boolean scroll)
   {
+    if (scrollsOnExpand == scroll)
+      return;
+
+    boolean oldValue = scrollsOnExpand;
     scrollsOnExpand = scroll;
+    firePropertyChange(SCROLLS_ON_EXPAND_PROPERTY, oldValue, scroll);
+  }
+
+  public void setSelectionPath(TreePath path)
+  {
+    selectionModel.setSelectionPath(path);
+  }
+
+  public void setSelectionPaths(TreePath[] paths)
+  {
+    selectionModel.setSelectionPaths(paths);
+  }
+  
+  public void setSelectionRow(int row)
+  {
+    TreePath path = getPathForRow(row);
+
+    if (path != null)
+      selectionModel.setSelectionPath(path);
+  }
+
+  public void setSelectionRows(int[] rows)
+  {
+    // Make sure we have an UI so getPathForRow() does not return null.
+    if (rows == null || getUI() == null)
+      return;
+
+    TreePath[] paths = new TreePath[rows.length];
+
+    for (int i = rows.length - 1; i >= 0; --i)
+      paths[i] = getPathForRow(rows[i]);
+
+    setSelectionPaths(paths);
+  }
+
+  public void setSelectionInterval(int index0, int index1)
+  {
+    TreePath[] paths = getPathBetweenRows(index0, index1);
+
+    if (paths != null)
+      setSelectionPaths(paths);
+  }
+
+  public void addSelectionPath(TreePath path)
+  {
+    selectionModel.addSelectionPath(path);
+  }
+
+  public void addSelectionPaths(TreePath[] paths)
+  {
+    selectionModel.addSelectionPaths(paths);
+  }
+
+  public void addSelectionRow(int row)
+  {
+    TreePath path = getPathForRow(row);
+
+    if (path != null)
+      selectionModel.addSelectionPath(path);
+  }
+
+  public void addSelectionRows(int[] rows)
+  {
+    // Make sure we have an UI so getPathForRow() does not return null.
+    if (rows == null || getUI() == null)
+      return;
+
+    TreePath[] paths = new TreePath[rows.length];
+
+    for (int i = rows.length - 1; i >= 0; --i)
+      paths[i] = getPathForRow(rows[i]);
+
+    addSelectionPaths(paths);
+  }
+
+  public void addSelectionInterval(int index0, int index1)
+  {
+    TreePath[] paths = getPathBetweenRows(index0, index1);
+
+    if (paths != null)
+      addSelectionPaths(paths);
+  }
+
+  public void removeSelectionPath(TreePath path)
+  {
+    selectionModel.removeSelectionPath(path);
+  }
+
+  public void removeSelectionPaths(TreePath[] paths)
+  {
+    selectionModel.removeSelectionPaths(paths);
+  }
+
+  public void removeSelectionRow(int row)
+  {
+    TreePath path = getPathForRow(row);
+
+    if (path != null)
+      selectionModel.removeSelectionPath(path);
+  }
+
+  public void removeSelectionRows(int[] rows)
+  {
+    // Make sure we have an UI so getPathForRow() does not return null.
+    if (rows == null || getUI() == null)
+      return;
+
+    TreePath[] paths = new TreePath[rows.length];
+
+    for (int i = rows.length - 1; i >= 0; --i)
+      paths[i] = getPathForRow(rows[i]);
+
+    removeSelectionPaths(paths);
+  }
+
+  public void removeSelectionInterval(int index0, int index1)
+  {
+    TreePath[] paths = getPathBetweenRows(index0, index1);
+
+    if (paths != null)
+      removeSelectionPaths(paths);
+  }
+
+  public void clearSelection()
+  {
+    selectionModel.clearSelection();
+  }
+  
+  public TreePath getLeadSelectionPath()
+  {
+    return leadSelectionPath;
+  }
+
+  /**
+   * @since 1.3
+   */
+  public void setLeadSelectionPath(TreePath path)
+  {
+    if (leadSelectionPath == path)
+      return;
+
+    TreePath oldValue = leadSelectionPath;
+    leadSelectionPath = path;
+    firePropertyChange(LEAD_SELECTION_PATH_PROPERTY, oldValue, path);
+  }
+
+  /**
+   * @since 1.3
+   */
+  public TreePath getAnchorSelectionPath()
+  {
+    return anchorSelectionPath;
+  }
+
+  /**
+   * @since 1.3
+   */
+  public void setAnchorSelectionPath(TreePath path)
+  {
+    if (anchorSelectionPath == path)
+      return;
+
+    TreePath oldValue = anchorSelectionPath;
+    anchorSelectionPath = path;
+    firePropertyChange(ANCHOR_SELECTION_PATH_PROPERTY, oldValue, path);
+  }
+
+  public int getLeadSelectionRow()
+  {
+    return selectionModel.getLeadSelectionRow();
+  }
+
+  public int getMaxSelectionRow()
+  {
+    return selectionModel.getMaxSelectionRow();
+  }
+
+  public int getMinSelectionRow()
+  {
+    return selectionModel.getMinSelectionRow();
+  }
+
+  public int getSelectionCount()
+  {
+    return selectionModel.getSelectionCount();
+  }
+
+  public TreePath getSelectionPath()
+  {
+    return selectionModel.getSelectionPath();
+  }
+
+  public TreePath[] getSelectionPaths()
+  {
+    return selectionModel.getSelectionPaths();
+  }
+
+  public int[] getSelectionRows()
+  {
+    return selectionModel.getSelectionRows();
+  }
+
+  public boolean isPathSelected(TreePath path)
+  {
+    return selectionModel.isPathSelected(path);
+  }
+
+  public boolean isRowSelected(int row)
+  {
+    return selectionModel.isRowSelected(row);
+  }
+
+  public boolean isSelectionEmpty()
+  {
+    return selectionModel.isSelectionEmpty();
+  }
+  
+  /**
+   * Return the value of the <code>dragEnabled</code> property.
+   *
+   * @return the value
+   * 
+   * @since 1.4
+   */
+  public boolean getDragEnabled()
+  {
+    return dragEnabled;
+  }
+
+  /**
+   * Set the <code>dragEnabled</code> property.
+   *
+   * @param enabled new value
+   * 
+   * @since 1.4
+   */
+  public void setDragEnabled(boolean enabled)
+  {
+    dragEnabled = enabled;
+  }
+
+  public int getRowCount()
+  {
+    TreeUI ui = getUI();
+
+    if (ui != null)
+      return ui.getRowCount(this);
+    
+    return 0;
+  }
+
+  /**
+   * @since 1.3
+   */
+  public boolean getExpandsSelectedPaths()
+  {
+    return expandsSelectedPaths;
+  }
+
+  /**
+   * @since 1.3
+   */
+  public void setExpandsSelectedPaths(boolean flag)
+  {
+    if (expandsSelectedPaths == flag)
+      return;
+
+    boolean oldValue = expandsSelectedPaths;
+    expandsSelectedPaths = flag;
+    firePropertyChange(EXPANDS_SELECTED_PATHS_PROPERTY, oldValue, flag);
+  }
+
+  public Rectangle getPathBounds(TreePath path)
+  {
+    TreeUI ui = getUI();
+
+    if (ui == null)
+      return null;
+
+    return ui.getPathBounds(this, path);
+  }
+
+  public Rectangle getRowBounds(int row)
+  {
+    TreePath path = getPathForRow(row);
+
+    if (path != null)
+      return getPathBounds(path);
+
+    return null;
+  }
+
+  public boolean isEditing()
+  {
+    TreeUI ui = getUI();
+
+    if (ui != null)
+      return ui.isEditing(this);
+
+    return false;
+  }
+
+  public boolean stopEditing()
+  {
+    TreeUI ui = getUI();
+
+    if (ui != null)
+      return ui.stopEditing(this);
+
+   return false;
+  }
+
+  public void cancelEditing()
+  {
+    TreeUI ui = getUI();
+
+    if (ui != null)
+      ui.cancelEditing(this);
+  }
+
+  public void startEditingAtPath(TreePath path)
+  {
+    TreeUI ui = getUI();
+
+    if (ui != null)
+      ui.startEditingAtPath(this, path);
+  }
+
+  public TreePath getEditingPath()
+  {
+    TreeUI ui = getUI();
+
+    if (ui != null)
+      return ui.getEditingPath(this);
+
+    return null;
+  }
+
+  public TreePath getPathForLocation(int x, int y)
+  {
+    TreePath path = getClosestPathForLocation(x, y);
+
+    if (path != null)
+      {
+	 Rectangle rect = getPathBounds(path);
+
+	 if ((rect != null) && rect.contains(x, y))
+	   return path;
+      }
+
+    return null;
+  }
+
+  public int getRowForLocation(int x, int y)
+  {
+    TreePath path = getPathForLocation(x, y);
+
+    if (path != null)
+      return getRowForPath(path);
+
+    return -1;
+  }
+  
+  public TreePath getClosestPathForLocation(int x, int y)
+  {
+    TreeUI ui = getUI();
+
+    if (ui != null)
+      return ui.getClosestPathForLocation(this, x, y);
+    
+    return null;
+  }
+
+  public int getClosestRowForLocation(int x, int y)
+  {
+    TreePath path = getClosestPathForLocation(x, y);
+
+    if (path != null)
+      return getRowForPath(path);
+
+    return -1;
+  }
+
+  public Object getLastSelectedPathComponent()
+  {
+    TreePath path = getSelectionPath();
+
+    if (path != null)
+      return path.getLastPathComponent();
+
+    return null;
   }
 }




More information about the kaffe mailing list