/[classpath]/classpath/javax/swing/JTable.java
ViewVC logotype

Diff of /classpath/javax/swing/JTable.java

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

revision 1.20 by mkoch, Fri Dec 31 10:19:44 2004 UTC revision 1.21 by mkoch, Fri Jan 7 18:32:48 2005 UTC
# Line 42  import java.awt.Color; Line 42  import java.awt.Color;
42  import java.awt.Component;  import java.awt.Component;
43  import java.awt.Dimension;  import java.awt.Dimension;
44  import java.awt.Rectangle;  import java.awt.Rectangle;
45    import java.awt.Point;
46  import java.util.Hashtable;  import java.util.Hashtable;
47  import java.util.Vector;  import java.util.Vector;
48    
# Line 571  public class JTable extends JComponent Line 572  public class JTable extends JComponent
572      repaint();      repaint();
573    }    }
574    
575     /**
576       * Returns index of the column that contains specified point
577       * or -1 if this table doesn't contain this point.
578       *
579       * @param point point to identify the column
580       * @return index of the column that contains specified point or
581       * -1 if this table doesn't contain this point.
582       */
583      public int columnAtPoint(Point point)
584      {
585        int x0 = getLocation().x;
586        int ncols = getColumnCount();
587        Dimension gap = getIntercellSpacing();
588        TableColumnModel cols = getColumnModel();
589        int x = point.x;
590        
591        for (int i = 0; i < ncols; ++i)
592          {
593            int width = cols.getColumn(i).getWidth() + (gap == null ? 0 : gap.width);
594            if (0 <= x && x < width)
595              return i;
596            x -= width;  
597          }
598        
599        return -1;
600      }
601    
602      /**
603       * Returns index of the row that contains specified point or
604       * -1 if this table doesn't contain this point.
605       *
606       * @param point point to identify the row
607       * @return index of the row that contains specified point or
608       * -1 if this table doesn't contain this point.
609       */
610      public int rowAtPoint(Point point)
611      {
612        int y0 = getLocation().y;
613        int nrows = getRowCount();
614        Dimension gap = getIntercellSpacing();
615        int height = getRowHeight() + (gap == null ? 0 : gap.height);
616        int y = point.y;
617        
618        for (int i = 0; i < nrows; ++i)
619          {
620            if (0 <= y && y < height)
621              return i;
622            y -= height;
623          }
624          
625        return -1;
626      }
627    
628    /**    /**
629     * Calculate the visible rectangle for a particular row and column. The     * Calculate the visible rectangle for a particular row and column. The
# Line 921  public class JTable extends JComponent Line 974  public class JTable extends JComponent
974              break;              break;
975                            
976            case ListSelectionModel.SINGLE_INTERVAL_SELECTION:            case ListSelectionModel.SINGLE_INTERVAL_SELECTION:
977              sum = hi - lo;              sum = hi - lo + 1;
978              break;              break;
979                            
980            case ListSelectionModel.MULTIPLE_INTERVAL_SELECTION:                    case ListSelectionModel.MULTIPLE_INTERVAL_SELECTION:        
981              for (int i = lo; i < hi; ++i)              for (int i = lo; i <= hi; ++i)
982                if (lsm.isSelectedIndex(i))                        if (lsm.isSelectedIndex(i))        
983                  ++sum;                  ++sum;
984              break;              break;
# Line 952  public class JTable extends JComponent Line 1005  public class JTable extends JComponent
1005              break;                    break;      
1006                
1007            case ListSelectionModel.SINGLE_INTERVAL_SELECTION:                        case ListSelectionModel.SINGLE_INTERVAL_SELECTION:            
1008              for (int i = lo; i < hi; ++i)              for (int i = lo; i <= hi; ++i)
1009                ret[j++] = i;                ret[j++] = i;
1010              break;              break;
1011                            
1012            case ListSelectionModel.MULTIPLE_INTERVAL_SELECTION:                    case ListSelectionModel.MULTIPLE_INTERVAL_SELECTION:        
1013              for (int i = lo; i < hi; ++i)              for (int i = lo; i <= hi; ++i)
1014                if (lsm.isSelectedIndex(i))                        if (lsm.isSelectedIndex(i))        
1015                  ret[j++] = i;                  ret[j++] = i;
1016              break;              break;
# Line 1328  public class JTable extends JComponent Line 1381  public class JTable extends JComponent
1381    
1382    /**    /**
1383     * Set the value of the {@link #selectionMode} property by     * Set the value of the {@link #selectionMode} property by
1384     * delegation to the {@link #selectionModel} field.     * delegation to the {@link #selectionModel} field. The same selection
1385       * mode is set for row and column selection models.
1386     *     *
1387     * @param s The new value of the property     * @param s The new value of the property
1388     */     */
1389    public void setSelectionMode(int s)    public void setSelectionMode(int s)
1390    {    {
1391      selectionModel.setSelectionMode(s);      selectionModel.setSelectionMode(s);    
1392        columnModel.getSelectionModel().setSelectionMode(s);
1393        
1394      repaint();      repaint();
1395    }    }
1396    

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21

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