Re: [cp-patches] FYI: JTabbedPane fixes

2006-07-26 Thread Robert Schuster
Ok,
I revert this and look for another way to resolve this.

Thanks Mark for finding this!

@Roman: The doc for setSelectedComponent() says it does the hiding and showing
of the old and new selected component. However I saw no code in that method
which does it. That is why I thought it should be added here. Please add notes
to code which relies on a certain behavior of the UI.

cya
Robert

Mark Wielaard wrote:
 Hi Robert,
 
 On Tue, 2006-07-25 at 21:21 +0200, Robert Schuster wrote:
 
Hi,
this patch fixes some minor JTabbedPane issues.

2006-07-25  Robert Schuster [EMAIL PROTECTED]

* javax/swing/JTabbedPane.java:
(remove(Component)): Rewritten.
(setSelectedIndex): Implemented updating of component visibility 
 state.
 
 
 This seems to revert part of a patch from Roman:
 
 2006-06-09  Roman Kennke  [EMAIL PROTECTED]
 
 * javax/swing/JTabbedPane.java
 (setSelectedIndex): Don't change the visibility of the components,
 this is done by the UI class.
 * javax/swing/plaf/basic/BasicTabbedPaneUI.java
 (TabbedPaneLayout.layoutContainer): Change visibility of component
 here, depending on the selected index. Only do this if the new
 selected component is not null. Some programs seem to expect
 this.
 (visibleComponent): New field.
 (getVisibleComponent): Changed to return visibleComponent field.
 (setVisibleComponent): Changed to set the visibility of
 the old and new visible component.
 
 And it does indeed seem to break the showcase application Roman posted
 about: http://kennke.org/blog/?p=9
 
 Could you coordinate on a correct fix?
 
 Thanks,
 
 Mark
 
 


signature.asc
Description: OpenPGP digital signature


[cp-patches] FYI: JTabbedPane fixes

2006-07-25 Thread Robert Schuster
Hi,
this patch fixes some minor JTabbedPane issues.

2006-07-25  Robert Schuster [EMAIL PROTECTED]

* javax/swing/JTabbedPane.java:
(remove(Component)): Rewritten.
(setSelectedIndex): Implemented updating of component visibility state.

cya
Robert
Index: javax/swing/JTabbedPane.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/JTabbedPane.java,v
retrieving revision 1.41
diff -u -r1.41 JTabbedPane.java
--- javax/swing/JTabbedPane.java	9 Jun 2006 23:34:34 -	1.41
+++ javax/swing/JTabbedPane.java	25 Jul 2006 19:17:46 -
@@ -990,7 +990,17 @@
 checkIndex(index, -1, tabs.size());
 if (index != getSelectedIndex())
   {
+// Hiding and showing the involved components
+// is important for the focus traversal mechanism
+// to report the correct source and destination
+// components.
+Component c = getSelectedComponent();
+if (c != null)
+  c.setVisible(false);
+
 	model.setSelectedIndex(index);
+
+getSelectedComponent().setVisible(true);
   }
   }
 
@@ -1247,7 +1257,25 @@
*/
   public void remove(Component component)
   {
-super.remove(component);
+// Container.remove(Component) is implemented in a
+// way that it calls Container.remove(int). Since
+// JTabbedPane's remove(int) is overridden to
+// remove tabs and this in turn should not happen
+// with components implementing UIResource
+// we find out the component's index and
+// call the superclass' remove(int) method
+// directly.
+// For non-UIResource implementing components
+// the normal implementation is suitable.
+if (component instanceof UIResource)
+  {
+Component[] cs = getComponents();
+for (int i = 0; i cs.length; i++)
+  if (cs[i] == component)
+super.remove(i);
+  }
+else
+  super.remove(component);
   }
 
   /**
@@ -1257,7 +1285,6 @@
*/
   public void remove(int index)
   {
-super.remove(index);
 removeTabAt(index);
   }
 


signature.asc
Description: OpenPGP digital signature


Re: [cp-patches] FYI: JTabbedPane fixes

2006-07-25 Thread Mark Wielaard
Hi Robert,

On Tue, 2006-07-25 at 21:21 +0200, Robert Schuster wrote:
 Hi,
 this patch fixes some minor JTabbedPane issues.
 
 2006-07-25  Robert Schuster [EMAIL PROTECTED]
 
 * javax/swing/JTabbedPane.java:
 (remove(Component)): Rewritten.
 (setSelectedIndex): Implemented updating of component visibility 
 state.

This seems to revert part of a patch from Roman:

2006-06-09  Roman Kennke  [EMAIL PROTECTED]

* javax/swing/JTabbedPane.java
(setSelectedIndex): Don't change the visibility of the components,
this is done by the UI class.
* javax/swing/plaf/basic/BasicTabbedPaneUI.java
(TabbedPaneLayout.layoutContainer): Change visibility of component
here, depending on the selected index. Only do this if the new
selected component is not null. Some programs seem to expect
this.
(visibleComponent): New field.
(getVisibleComponent): Changed to return visibleComponent field.
(setVisibleComponent): Changed to set the visibility of
the old and new visible component.

And it does indeed seem to break the showcase application Roman posted
about: http://kennke.org/blog/?p=9

Could you coordinate on a correct fix?

Thanks,

Mark




[cp-patches] FYI: JTabbedPane fixes

2006-03-30 Thread Roman Kennke
This patch fixes a couple of issues in the JTabbedPane:
- in removeTabAt, the selection needs to be adjusted, so that it doesn't
point to an illegal tab afterwards.
- not only the tab must be removed, but also the component that is
displayed by the tab. This has been a potential memory leak (no
components ever removed from the JTabbedPane)
- in removeAll() we need to use getTabCount() instead of tabs.size()
(the latter causes an ArrayIndexOutOfBounds later somehow) and set the
selectionIndex to -1

2006-03-30  Roman Kennke  [EMAIL PROTECTED]

* javax/swing/JTabbedPane.java
(removeTabAt): Adjust selection correctly when removing a tab
before the selected tab. Also remove the component from the
container, not only the tab object. Repaint and revalidate the
component after the removal.
(removeAll): Set selection to -1 before removing the tabs.

/Roman

Index: javax/swing/JTabbedPane.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/JTabbedPane.java,v
retrieving revision 1.34
diff -u -1 -0 -r1.34 JTabbedPane.java
--- javax/swing/JTabbedPane.java	24 Mar 2006 12:58:48 -	1.34
+++ javax/swing/JTabbedPane.java	30 Mar 2006 12:08:43 -
@@ -1150,22 +1150,61 @@
   /**
* Removes the tab at index. After the component associated with 
* index is removed, its visibility is reset to true to ensure it 
* will be visible if added to other containers.
*
* @param index The index of the tab to remove.
*/
   public void removeTabAt(int index)
   {
 checkIndex(index, 0, tabs.size());
+
+// We need to adjust the selection if we remove a tab that comes
+// before the selected tab or if the selected tab is removed.
+// This decrements the selected index by 1 if any of this is the case.
+// Note that this covers all cases:
+// - When the selected tab comes after the removed tab, this simply
+//   adjusts the selection so that after the removal the selected tab
+//   is still the same.
+// - When we remove the currently selected tab, then the tab before the
+//   selected tab gets selected.
+// - When the last tab is removed, then we have an index==0, which gets
+//   decremented to -1, which means no selection, which is 100% perfect.
+int selectedIndex = getSelectedIndex();
+System.err.println(index:  + index);
+System.err.println(selectedIndex:  + selectedIndex);
+if (selectedIndex = index)
+  setSelectedIndex(selectedIndex - 1);
+
+Component comp = getComponentAt(index);
+
+// Remove the tab object.
 tabs.remove(index);
-getComponentAt(index).show();
+
+// Remove the component. I think we cannot assume that the tab order
+// is equal to the component order, so we iterate over the children
+// here to find the and remove the correct component.
+if (comp != null)
+  {
+Component[] children = getComponents();
+for (int i = children.length - 1; i = 0; --i)
+  {
+if (children[i] == comp)
+  {
+super.remove(i);
+comp.setVisible(true);
+break;
+  }
+  }
+  }
+revalidate();
+repaint();
   }
 
   /**
* Removes the specified Component from the JTabbedPane.
*
* @param component The Component to remove.
*/
   public void remove(Component component)
   {
 super.remove(component);
@@ -1181,21 +1220,22 @@
 super.remove(index);
 removeTabAt(index);
   }
 
   /**
* This method removes all tabs and associated components from the
* JTabbedPane.
*/
   public void removeAll()
   {
-for (int i = tabs.size() - 1; i = 0; i--)
+setSelectedIndex(-1);
+for (int i = getTabCount() - 1; i = 0; i--)
   removeTabAt(i);
   }
 
   /**
* This method returns how many tabs are in the JTabbedPane.
*
* @return The number of tabs in the JTabbedPane.
*/
   public int getTabCount()
   {


Re: [cp-patches] FYI: JTabbedPane fixes

2006-03-30 Thread Mark Wielaard
Hi Roman,

On Thu, 2006-03-30 at 14:18 +0200, Roman Kennke wrote:
 +int selectedIndex = getSelectedIndex();
 +System.err.println(index:  + index);
 +System.err.println(selectedIndex:  + selectedIndex);
 +if (selectedIndex = index)
 +  setSelectedIndex(selectedIndex - 1); 

You left in some debug code.

Cheers,

Mark



signature.asc
Description: This is a digitally signed message part


Re: [cp-patches] FYI: JTabbedPane fixes

2006-03-30 Thread Roman Kennke
Hi Mark,

 On Thu, 2006-03-30 at 14:18 +0200, Roman Kennke wrote:
  +int selectedIndex = getSelectedIndex();
  +System.err.println(index:  + index);
  +System.err.println(selectedIndex:  + selectedIndex);
  +if (selectedIndex = index)
  +  setSelectedIndex(selectedIndex - 1); 
 
 You left in some debug code.

Ouch. :

2006-03-30  Roman Kennke  [EMAIL PROTECTED]

* javax/swing/JTabbedPane.java
(removeTabAt): Removed debug code.

Roman

Index: javax/swing/JTabbedPane.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/JTabbedPane.java,v
retrieving revision 1.35
diff -u -1 -0 -r1.35 JTabbedPane.java
--- javax/swing/JTabbedPane.java	30 Mar 2006 12:15:51 -	1.35
+++ javax/swing/JTabbedPane.java	30 Mar 2006 14:52:01 -
@@ -1163,22 +1163,20 @@
 // This decrements the selected index by 1 if any of this is the case.
 // Note that this covers all cases:
 // - When the selected tab comes after the removed tab, this simply
 //   adjusts the selection so that after the removal the selected tab
 //   is still the same.
 // - When we remove the currently selected tab, then the tab before the
 //   selected tab gets selected.
 // - When the last tab is removed, then we have an index==0, which gets
 //   decremented to -1, which means no selection, which is 100% perfect.
 int selectedIndex = getSelectedIndex();
-System.err.println(index:  + index);
-System.err.println(selectedIndex:  + selectedIndex);
 if (selectedIndex = index)
   setSelectedIndex(selectedIndex - 1);
 
 Component comp = getComponentAt(index);
 
 // Remove the tab object.
 tabs.remove(index);
 
 // Remove the component. I think we cannot assume that the tab order
 // is equal to the component order, so we iterate over the children