You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ay...@apache.org on 2007/02/07 15:00:29 UTC
svn commit: r504549 - in /harmony/enhanced/classlib/trunk/modules/swing/src:
main/java/common/javax/swing/JTabbedPane.java
test/api/java/common/javax/swing/JTabbedPaneRTest.java
Author: ayza
Date: Wed Feb 7 06:00:28 2007
New Revision: 504549
URL: http://svn.apache.org/viewvc?view=rev&rev=504549
Log:
Applying patch from HARMONY-2515 ([classlib][swing] javax.swing.JTabbedPane.add(component, -1) throws unspecified ArrayIndexOutOfBoundsException)
Modified:
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JTabbedPane.java
harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JTabbedPaneRTest.java
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JTabbedPane.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JTabbedPane.java?view=diff&rev=504549&r1=504548&r2=504549
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JTabbedPane.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JTabbedPane.java Wed Feb 7 06:00:28 2007
@@ -48,7 +48,9 @@
*/
public class JTabbedPane extends JComponent implements Serializable, Accessible, SwingConstants {
private static final long serialVersionUID = 1671634173365704280L;
-
+
+ private static final int NOT_FOUND = -1;
+
// TODO: implement
protected class AccessibleJTabbedPane extends AccessibleJComponent implements
AccessibleSelection, ChangeListener {
@@ -301,7 +303,7 @@
return;
}
JTabInfo tabInfo = getTabAt(index);
- if (oldIndex != -1) {
+ if (oldIndex != NOT_FOUND) {
removeTabAt(oldIndex);
}
if (tabInfo.getComp() != comp) {
@@ -335,7 +337,7 @@
@Override
public String getToolTipText(MouseEvent event) {
int index = indexAtLocation(event.getX(), event.getY());
- return index > -1 ? getToolTipTextAt(index) : super.getToolTipText(event);
+ return index > NOT_FOUND ? getToolTipTextAt(index) : super.getToolTipText(event);
}
public void setToolTipTextAt(int index, String toolTipText) {
@@ -347,7 +349,7 @@
}
public int indexAtLocation(int x, int y) {
- return getUI() != null ? getUI().tabForCoordinate(this, x, y) : -1;
+ return getUI() != null ? getUI().tabForCoordinate(this, x, y) : NOT_FOUND;
}
public int indexOfComponent(Component comp) {
@@ -356,7 +358,7 @@
return i;
}
}
- return -1;
+ return NOT_FOUND;
}
public int indexOfTab(Icon icon) {
@@ -378,20 +380,23 @@
}
public void insertTab(String title, Icon icon, Component comp, String tip, int index) {
- int oldIndex = comp != null ? indexOfComponent(comp) : -1;
- if (oldIndex != -1) {
+ int oldIndex = comp != null ? indexOfComponent(comp) : NOT_FOUND;
+ if (oldIndex != NOT_FOUND) {
tabInfos.remove(oldIndex);
}
String realTitle = title == null ? "" : title;
JTabInfo tabInfo = new JTabInfo(realTitle, icon, comp, tip);
+ if (index == -1) {
+ index = tabInfos.size();
+ }
tabInfos.add(index, tabInfo);
- if (oldIndex == -1) {
+ if (oldIndex == NOT_FOUND) {
addComponentToContainer(comp);
}
if (getTabCount() == 1) {
setSelectedIndex(0);
} else if (index <= getSelectedIndex()
- && (oldIndex == -1 || oldIndex > getSelectedIndex())) {
+ && (oldIndex == NOT_FOUND || oldIndex > getSelectedIndex())) {
setSelectedIndex(getSelectedIndex() + 1);
}
repaint();
@@ -413,7 +418,7 @@
return;
}
int index = indexOfComponent(comp);
- if (index != -1) {
+ if (index != NOT_FOUND) {
removeTabAt(index);
}
}
@@ -540,7 +545,7 @@
public void setSelectedComponent(Component comp) {
int index = indexOfComponent(comp);
- if (index == -1) {
+ if (index == NOT_FOUND) {
throw new IllegalArgumentException("Component not found in the tabbed pane");
}
setSelectedIndex(index);
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JTabbedPaneRTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JTabbedPaneRTest.java?view=diff&rev=504549&r1=504548&r2=504549
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JTabbedPaneRTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JTabbedPaneRTest.java Wed Feb 7 06:00:28 2007
@@ -37,6 +37,13 @@
protected void tearDown() throws Exception {
super.tearDown();
}
+
+ /**
+ * Regression test for HARMONY-2515
+ * */
+ public void testAddComponentToTail() {
+ pane.add(new JButton(), -1);
+ }
public void testAddNull() {
final JComponent comp1 = new JLabel();