Diff for /FM2SQL/Attic/TableComponent.java between versions 1.5 and 1.6

version 1.5, 2004/03/23 11:57:06 version 1.6, 2004/05/26 11:37:32
Line 41  public class TableComponent extends JPan Line 41  public class TableComponent extends JPan
   int selIndex = 0;    int selIndex = 0;
   Icon trueIcon = null, falseIcon = null, empty = null;    Icon trueIcon = null, falseIcon = null, empty = null;
   TableComponent tableComp = this;    TableComponent tableComp = this;
     BooleanRenderer booleanRenderer = new BooleanRenderer();
   /**    /**
    * Constructs an  empty table with default header and  dummy data     * Constructs an  empty table with default header and  dummy data
    */     */
Line 165  public class TableComponent extends JPan Line 166  public class TableComponent extends JPan
       {        {
         tableComp.row = row;          tableComp.row = row;
         boolean value = false;          boolean value = false;
         if (getColumnClass(column) == ArrayList.class || getColumnClass(column) == JComboBox.class || getColumnClass(column) == SQLCommand.class || getColumnClass(column) == IDComboBox.class)          if (getColumnClass(column) == ArrayList.class || getColumnClass(column) == JComboBox.class || getColumnClass(column) == SQLCommand.class || getColumnClass(column) == IDComboBox.class|| getColumnClass(column) == Boolean.class)
           value = true;            value = true;
         //System.out.println("tried to edit at row "+row+" column "+column+" "+value);           //System.out.println("tried to edit at row "+row+" column "+column+" "+value); 
   
Line 209  public class TableComponent extends JPan Line 210  public class TableComponent extends JPan
         });*/          });*/
     table.setDefaultEditor(SQLCommand.class, new SQLCommandEditor());      table.setDefaultEditor(SQLCommand.class, new SQLCommandEditor());
   
     table.setDefaultRenderer(Boolean.class, new TableCellRenderer()      table.setDefaultRenderer(Boolean.class, booleanRenderer);
     {  
       JCheckBox checkBox = new JCheckBox();  
       JLabel label = new JLabel();  
       public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)  
       {  
         if (value instanceof Integer)  
         {  
           label.setText(value.toString());  
           label.setHorizontalAlignment(JLabel.RIGHT);  
   
           return label;  
         } else if (value instanceof String)  
         {  
           label.setText(value.toString());  
           label.setHorizontalAlignment(JLabel.CENTER);  
           return label;  
         }  
         checkBox.setHorizontalAlignment(JLabel.CENTER);  
         checkBox.setVerticalAlignment(JLabel.CENTER);  
   
         checkBox.setSelectedIcon(trueIcon);  
         if (value == null)  
           checkBox.setIcon(empty);  
         else  
           checkBox.setIcon(falseIcon);  
         checkBox.setForeground(table.getForeground());  
         checkBox.setBackground(table.getBackground());  
   
         checkBox.setSelected((value != null && ((Boolean) value).booleanValue()));  
         return checkBox;  
   
       }  
   
     });  
   
     table.setRowHeight(20);      table.setRowHeight(20);
   
Line 330  public class TableComponent extends JPan Line 297  public class TableComponent extends JPan
     for (int i = 0; i < model.getColumnCount(); ++i)      for (int i = 0; i < model.getColumnCount(); ++i)
     {      {
       label = new JLabel(model.getColumn(i).getHeaderValue().toString());        label = new JLabel(model.getColumn(i).getHeaderValue().toString());
         //System.out.println("labelWith "+label.getPreferredSize().width);
         if(label.getPreferredSize().width==0)
         model.getColumn(i).setPreferredWidth(20);
        else
       model.getColumn(i).setPreferredWidth(label.getPreferredSize().width + 50);        model.getColumn(i).setPreferredWidth(label.getPreferredSize().width + 50);
   
     }      }
Line 1098  public class TableComponent extends JPan Line 1069  public class TableComponent extends JPan
     }      }
     return alterMe;      return alterMe;
   }    }
     public static class BooleanRenderer implements TableCellRenderer
     {
      Icon trueIcon,falseIcon,empty; 
      // renders false state with empty icon
      boolean renderFalseEmpty=false;
       public BooleanRenderer(){
         try
         {
           trueIcon = new ImageIcon(getClass().getResource("icons/ok.gif"));
   
           falseIcon = new Icon()
           {
             public int getIconHeight()
             {
               return 23;
             }
             public int getIconWidth()
             {
               return 27;
             }
             public void paintIcon(Component c, Graphics g, int x, int y)
             {
               Graphics2D g2 = (Graphics2D) g;
               g2.setColor(Color.blue);
               g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
               g2.setStroke(new BasicStroke(2.0f));
               int xr = x + 20, yr = y + 15;
               int xl = x + 5, yl = y + 5;
               g2.drawLine(xl, yl, xr, yr);
               g2.drawLine(xl, yr, xr, yl);
   
             }
           };
           empty = new Icon()
           {
             public int getIconHeight()
             {
               return 23;
             }
             public int getIconWidth()
             {
               return 27;
             }
             public void paintIcon(Component c, Graphics g, int x, int y)
             {
   
             }
           };
   
         } catch (Exception e)
         {
           System.out.println("Error while loading ok.gif");
         }
   
       
       }
       JCheckBox checkBox = new JCheckBox();
       JLabel label = new JLabel();
     
     public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
     {
       if (value instanceof Integer)
       {
         label.setText(value.toString());
         label.setHorizontalAlignment(JLabel.RIGHT);
   
         return label;
       } else if (value instanceof String)
       {
         label.setText(value.toString());
         label.setHorizontalAlignment(JLabel.CENTER);
         return label;
       }
       checkBox.setHorizontalAlignment(JLabel.CENTER);
       checkBox.setVerticalAlignment(JLabel.CENTER);
   
       checkBox.setSelectedIcon(trueIcon);
       if(renderFalseEmpty|| value==null) 
         checkBox.setIcon(empty);
         else checkBox.setIcon(falseIcon);
       checkBox.setForeground(table.getForeground());
       checkBox.setBackground(table.getBackground());
   
       checkBox.setSelected((value != null && ((Boolean) value).booleanValue()));
       return checkBox;
   
     }
   }
   public static class SQLCommand    public static class SQLCommand
   {    {
     String command = "";      String command = "";

Removed from v.1.5  
changed lines
  Added in v.1.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>