/[classpath]/classpath/javax/swing/table/AbstractTableModel.java
ViewVC logotype

Diff of /classpath/javax/swing/table/AbstractTableModel.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by mkoch, Mon Sep 29 11:03:52 2003 UTC revision 1.8 by mkoch, Thu Oct 2 20:23:42 2003 UTC
# Line 77  public abstract class AbstractTableModel Line 77  public abstract class AbstractTableModel
77     */     */
78    public String getColumnName (int columnIndex)    public String getColumnName (int columnIndex)
79    {    {
80      // Ok, this is not the best solution in the world      int index = columnIndex + 1;
     // 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...  
81    
82      StringBuffer buffer = new StringBuffer();      while (index > 0)
     int left = columnIndex;  
     boolean foundFirst = false;  
       
     // Process Exponent levels.  
     for (int index = 6; index >= 0; index--)  
83        {        {
84          int base = (int) (Math.pow (26, index));          buffer.insert (0, (char) ('A' + ((index - 1) % 26)));
85                    index = (index - 1) / 26;
86          if (index > 1)        }
87            {      
             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');  
           }  
     }  
   
88      // Return column name.      // Return column name.
89      return buffer.toString();      return buffer.toString();
90    }    }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26