aboutsummaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authorArnaud Vandyck <arnaud.vandyck@ulg.ac.be>2003-10-08 17:29:52 +0200
committerMichael Koch <mkoch@gcc.gnu.org>2003-10-08 15:29:52 +0000
commite55f4a34138fbecad0143015d76106f9a552f757 (patch)
tree3cdd6eb860708117420e165586f0c939bd425d42 /libjava
parenta761195bfd2503e485c47a79c4fe64195417b343 (diff)
downloadgcc-e55f4a34138fbecad0143015d76106f9a552f757.zip
gcc-e55f4a34138fbecad0143015d76106f9a552f757.tar.gz
gcc-e55f4a34138fbecad0143015d76106f9a552f757.tar.bz2
2003-10-08 Arnaud Vandyck <arnaud.vandyck@ulg.ac.be>
* javax/swing/table/AbstractTableModel.java (getColumnName): Simplified code much. Thanks to Yannick Boogaerts who helped stop pulling my hair on this +1 then -1 tricky thing! From-SVN: r72228
Diffstat (limited to 'libjava')
-rw-r--r--libjava/ChangeLog6
-rw-r--r--libjava/javax/swing/table/AbstractTableModel.java55
2 files changed, 13 insertions, 48 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 5d84c73..a5adfdf 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,9 @@
+2003-10-08 Arnaud Vandyck <arnaud.vandyck@ulg.ac.be>
+
+ * javax/swing/table/AbstractTableModel.java
+ (getColumnName): Simplified code much. Thanks to Yannick Boogaerts who
+ helped stop pulling my hair on this +1 then -1 tricky thing!
+
2003-10-07 Thomas Fitzsimmons <fitzsim@redhat.com>
* gnu/java/awt/peer/gtk/GtkTextAreaPeer.java (gtkTextGetSize):
diff --git a/libjava/javax/swing/table/AbstractTableModel.java b/libjava/javax/swing/table/AbstractTableModel.java
index 64e4d12..38e36e1 100644
--- a/libjava/javax/swing/table/AbstractTableModel.java
+++ b/libjava/javax/swing/table/AbstractTableModel.java
@@ -77,56 +77,15 @@ public abstract class AbstractTableModel implements TableModel, Serializable
*/
public String getColumnName (int columnIndex)
{
- // Ok, this is not the best solution in the world
- // and it does produce wrong answers starting 1378
- // but it's a start. I sure hope there is a more
- // simple algorithm. I started with a base 10 to
- // base 26 converter and later found that there
- // were so many are exceptions that it has morphed
- // into a pile of goop.
-
- // NOTE2: I have a working algorithm which is much
- // much simplier and works for all values...I'll
- // be adding it soon...
-
+ int index = columnIndex + 1;
StringBuffer buffer = new StringBuffer();
- int left = columnIndex;
- boolean foundFirst = false;
-
- // Process Exponent levels.
- for (int index = 6; index >= 0; index--)
- {
- int base = (int) (Math.pow (26, index));
-
- if (index > 1)
- {
- base = base + (int) (Math.pow (26, index - 1));
- }
-
- if (base <= left)
- {
- int multiplier = left / base;
-
- if (foundFirst == false
- && index > 0)
- {
- buffer.append ((char) (multiplier + 64));
- }
- else
- {
- buffer.append ((char) (multiplier + 65));
- }
-
- left = left - (base * multiplier);
- foundFirst = true;
- }
- else if (foundFirst == true
- || index == 0)
- {
- buffer.append('A');
- }
- }
+ while (index > 0)
+ {
+ buffer.insert (0, (char) ('A' + ((index - 1) % 26)));
+ index = (index - 1) / 26;
+ }
+
// Return column name.
return buffer.toString();
}