/* * TableToGridMapper.java 0.90 00/03/26 * * Copyright 2000 Eliad Technologies, Inc. All Rights Reserved. * * This software is the proprietary information of Eliad Technologies, Inc. */ package example04; import javax.swing.table.*; import javax.swing.event.*; import com.eliad.model.*; /** * A wrapper class to present a table model, with an optional companion * table column model, as a grid model. This makes it easy to use a JSmartGrid * to display the same data as a JTable. The class directly implements the * GridModel that the JSmartGrid view will need, and also provides, through * the getColumnHeaderModel method, the GridModel needed for a column * header similar to the traditional JTableHeader. * The easiest way to display a TableModel in a grid is the following: *
   import com.eliad.swing.*;
 *   ...
 *   TableModel tm;
 *   ...
 *   TableToGridMapper mapper=new TableToGridMapper(tm);
 *   JSmartGrid grid=new JSmartGrid(mapper);
 *   grid.setAutoCreateRowHeader(true);
 *   grid.setAutoCreateColumnHeader(true);
* If you put the grid in a JScrollPane, in the usual way: *
   JScrollPane scrollPane = new JScrollPane(grid);
 *   ...
 *   panel.add(scrollPane);
 *   ...
 *   frame.add(panel);
 *   ...
 *   frame.pack();
* two headers will appear, a row header with line numbers, and a column * header with spreadsheet-like headings. In order to have the column names * back in place, you just add (after frame.pack()): *
   scrollPane.setColumnHeaderView(
 *      new JSmartGridHeader(grid,grid.HORIZONTAL,mapper.getColumnHeaderModel(),null,null);
*

* If you have developped a specific renderer for table cells, it should be easy to transform into * a specific renderer for grid cells. The base interface is GridCellRenderer. If you extended * from the DefaultTableCellRenderer, it is especially simple. You just change: *

   class MyRenderer extends DefaultTableCellRenderer {
* into *
   class MyRenderer extends DefaultGridCellRenderer {
* More often that not, that will be enough, unless you overloaded the getTableCellRenderComponent method, * which you often leave alone when you are subclassing the default renderers. If you did, and of course if you * subclassed directly TableCellRenderer (which becomes GridCellRenderer), then you must * note the following differences: