File:  [Repository] / FM2SQL / Attic / TableComponent.java
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Fri Dec 5 11:46:39 2003 UTC (20 years, 6 months ago) by rogo
Branches: MAIN
CVS tags: HEAD
Initial revision

import javax.swing.*;
import java.awt.event.*;

import java.util.*;
import java.awt.*;
import javax.swing.table.*;
import javax.swing.event.*;
/**
 Table component 
*/
 
public class TableComponent extends JPanel implements TableModelListener
{

  JScrollPane tableScroller;
  JTable table;
  DefaultTableModel tableModel;
  JPanel content;
  int row, col;
  int realCount = 0;
  String columnNames[] = { "no database","connection" };
  String[][] rowData = {  {"","" }
  };
  boolean callState = false;
  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  static JLabel label;
  int selIndex = 0;
  Icon trueIcon = null, falseIcon = null, empty = null;
  TableComponent tableComp = this;
  /**
   * Constructs an  empty table with default header and  dummy data
   */

  public TableComponent()
  {

    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");
    }

    content = this;
    tableModel = new DefaultTableModel(rowData, columnNames)
    {
      boolean firstCall = true;
      public Class getColumnClass(int column)
      {
        if (row > dataVector.size())
          row = dataVector.size() - 1;
        Vector rowVector = (Vector) dataVector.elementAt(row);
        if (rowVector.isEmpty())
          return Object.class;
        if (rowVector.elementAt(column) == null)
          return Object.class;
        else
          return rowVector.elementAt(column).getClass();

      }
      public Object getValueAt(int i, int j)
      {
        if (((Vector) dataVector.elementAt(i)).isEmpty())
          return null;
        else
          return super.getValueAt(i, j);
      }
      public void setDataVector(Vector rows, Vector columnNames)
      {
        // System.out.println(firstCall);

        if (firstCall)
        {
          realCount = rows.size();
          //System.out.println(realCount);
        } else
          firstCall = true;
        super.setDataVector(rows, columnNames);

        //realCount =(rows==null) ? 0:rows.size();
      }
    };

    table = new JTable(tableModel)
    {
      public TableCellRenderer getCellRenderer(int row, int column)
      {

        tableComp.row = row;
        TableCellRenderer renderer = null;
        if (renderer == null)
        {
          renderer = getDefaultRenderer(getColumnClass(column));
        }
        return renderer;
      }
      public TableCellEditor getCellEditor(int row, int column)
      {
        tableComp.row = row;

        TableCellEditor editor = null;
        
        if (editor == null)
        {
          editor = getDefaultEditor(getColumnClass(column));
        }
        return editor;
      }
			public boolean isCellEditable(int row,int column)
			{
        tableComp.row=row;
        boolean value=false;
				if(getColumnClass(column)==ArrayList.class||getColumnClass(column)==JComboBox.class||getColumnClass(column)== SQLCommand.class) 
				value=true;
				//System.out.println("tried to edit at row "+row+" column "+column+" "+value); 
															
			return value;
			}
    
     /* public boolean editCellAt(int row, int column, EventObject e){
      System.out.println(getCellEditor());
      if(isEditing()) editingStopped(null);
      return super.editCellAt(row,col,e);
      }*/
    };
    
    table.getColumnModel().getColumn(0).setPreferredWidth(200);
    table.getColumnModel().getColumn(1).setPreferredWidth(50);
    row = tableModel.getRowCount();
    col = tableModel.getColumnCount();
    ((DefaultTableModel) table.getModel()).setRowCount(10);

    tableScroller = new JScrollPane(table);
    Dimension d = table.getPreferredSize();
    tableScroller.setPreferredSize(new Dimension(d.width, d.height + 9));

    content.add(tableScroller);
    ((DefaultTableModel) table.getModel()).setRowCount(74);

    tableModel.addTableModelListener(this);
    setLayout(new FlowLayout(FlowLayout.LEFT));
    //this.add(content);
  
    table.setDefaultEditor(JComboBox.class, new VectorEditor());
    table.setDefaultRenderer(JComboBox.class, new VectorCellRenderer());
  
    table.setDefaultEditor(ArrayList.class, new ArrayListEditor());
    table.setDefaultRenderer(ArrayList.class, new ArrayListCellRenderer());
	/*	table.setDefaultEditor(SQLCommand.class,new DefaultCellEditor(new JTextField()) {
		public Object getCellEditorValue()
		 {
		   return new SQLCommand(super.getCellEditorValue().toString());
		 }
		});*/
    table.setDefaultEditor(SQLCommand.class, new SQLCommandEditor());
    
    table.setDefaultRenderer(Boolean.class, new TableCellRenderer()
    {
      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);

  }

  /**
   *  Fills  the  table  with the array of Objects
   *@param array of Objects 
   * 
   */

  public void setData(Object[][] data)
  {
    callState = true;
    clear();
    for (int i = 0; i < tableModel.getColumnCount(); ++i)
    {
      for (int j = 0; j < data[0].length; ++j)
      {
        tableModel.setValueAt(data[i][j], j, i);
      }
    }
    callState = false;
    //tableModel.setDataVector(data,columnNames);
    //tableModel.setRowCount(100);

  } // to method
  public void clear()
  {
    callState = true;
    for (int i = 0; i < tableModel.getColumnCount(); ++i)
    {
      for (int j = 0; j < tableModel.getRowCount(); ++j)
      {
        tableModel.setValueAt("", j, i);
      }
    }
    //tableModel.setDataVector(rowData,columnNames);
    //tableModel.setRowCount(100);
  }
  public void disable(boolean state)
  {
    if (state)
    {
      table.setEnabled(state);
    } else
    {
      clear();
      table.setEnabled(state);

    }

  }

  public void setEnabled(boolean state)
  {
    table.setEnabled(state);
  }

  public void tableChanged(TableModelEvent e)
  {
  }
  public int getMaxHeaderWidth()
  {
    TableColumnModel model = table.getColumnModel();
    int maxWidth = -10000000;
    for (int i = 0; i < model.getColumnCount(); ++i)
    {
      label = new JLabel(model.getColumn(i).getHeaderValue().toString());
      int width = label.getPreferredSize().width + 20;
      if (width > maxWidth)
        maxWidth = width;
    }
    return maxWidth;
  }
  public void enlarge(int windowWidth, int windowHeight)
  {

    //  Class tre=table.getColumnModel().getColumn(1).getHeaderValue().getClass();
    //Graphics2D g2=((Graphics2D)getGraphics());
    table.setAutoResizeMode(table.AUTO_RESIZE_OFF);

    TableColumnModel model = table.getColumnModel();
    for (int i = 0; i < model.getColumnCount(); ++i)
    {
      label = new JLabel(model.getColumn(i).getHeaderValue().toString());
      model.getColumn(i).setPreferredWidth(label.getPreferredSize().width + 50);

    }
    Dimension d = table.getPreferredSize();
    Dimension d2 = tableScroller.getPreferredSize();
    tableScroller.setPreferredSize(new Dimension((d.width >= screenSize.width) ? (screenSize.width - 50) : (d.width), d2.height));
    // tableModel.setRowCount(80);
    if (d.width < windowWidth)
      model.getColumn(model.getColumnCount() - 1).setPreferredWidth((windowWidth - d.width) + model.getColumn(model.getColumnCount() - 1).getPreferredWidth());

    table.setGridColor(Color.red);
    d2 = tableScroller.getPreferredSize();
    table.validate();
    content.setPreferredSize(new Dimension(d2.width, d2.height + 10));
    content.validate();
  }
  public void sizeToFit(int windowWidth, int windowHeight)
  {
    table.setAutoResizeMode(table.AUTO_RESIZE_LAST_COLUMN);

    TableColumnModel model = table.getColumnModel();
    Dimension d2 = getPreferredSize();

    int columnWidth = (windowWidth) / model.getColumnCount();
    for (int i = 0; i < model.getColumnCount(); ++i)
    {
      model.getColumn(i).setPreferredWidth(columnWidth);
      //model.getColumn (i).setWidth(columnWidth);
    }
    // System.out.println(table.getPreferredSize()+" "+model.getTotalColumnWidth()+" "+columnWidth);
    /* Dimension d = table.getPreferredSize();
     d2=getPreferredSize();
    
    
     System.out.println("window width"+windowWidth+" width "+d2.width+" "+model.getTotalColumnWidth());
    //  d2=getPreferredSize();
     tableScroller.setPreferredSize(new Dimension( windowWidth, d.height));
    
    
    // System.out.println("window width"+windowWidth+" "+windowHeight+" "+getWidth()+" "+getHeight());
    
     table.setAutoResizeMode(table.AUTO_RESIZE_OFF);
    */
    Dimension d = table.getPreferredSize();
    if (columnWidth < getMaxHeaderWidth() || d.width > screenSize.width)
      enlarge(windowWidth, windowHeight);
    table.validate();
    table.setGridColor(Color.red);

  }
	class VectorEditor implements TableCellEditor,ActionListener 
	 {
		 JComboBox box = new JComboBox();
		 DefaultComboBoxModel model = new DefaultComboBoxModel();
		 JComboBox boxValue;
		 CellEditorListener listener=table;
		 int row,column;
		 public VectorEditor()
		 {
	//     super(new JCheckBox());
		
	 	box.addActionListener(this);
/*	 	box.addFocusListener(new FocusAdapter() {
	 	public void focusLost(FocusEvent e)
	 	{
			 VectorEditor.this.listener.editingStopped(new ChangeEvent(VectorEditor.this));
		 	System.out.println("lost focus");
	 	}
	 	});*/
		 }
		 public Object getCellEditorValue()
		 {
			 //selIndex = box.getSelectedIndex();
			System.out.println("Called "+selIndex);
			//tableModel.fireTableCellUpdated(row,column);
			 if(box.getModel().getSize()>0)
			 return boxValue;
		 else return null;
	
		 }

		 public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
		 {
			boxValue = (value != null) ? (JComboBox) value : null;
			this.row=row;this.column=column;
      if(boxValue!=null) box.setModel(boxValue.getModel());
      else return null;
   		return box;
		 }

		 public boolean isCellEditable(EventObject anEvent)
		 {
       if(table.isEditing()) 
           {
          
        //     System.out.println(getCellEditorValue());
             if(listener!=null)
             listener.editingStopped(new ChangeEvent(this));
          
                  //   listener = null;
                  //  Object local =getCellEditorValue();
                    //table.getModel().setValueAt(local, table.getEditingRow(), table.getEditingColumn());
                  //  table.remove(label);   
                  //  table.validate();
                    //System.out.println("before "+table.getComponentCount());
                 //  if(table.getEditor)
                  // table.editCellAt(row,column);
                  // table.removeAll();
                  //return null;
                  }

       //System.out.println(anEvent);
			 return true;
		 }

		 public boolean shouldSelectCell(EventObject anEvent)
		 {
			//System.out.println(anEvent);
				 return true;
		 }

		 public boolean stopCellEditing()
		 {
			 return true;
		 }

		 public void cancelCellEditing()
		 {
			listener.editingStopped(new ChangeEvent(this));
		 }

		 public void addCellEditorListener(CellEditorListener l)
		 {
			listener=l;
			//System.out.println(l);
		 }

		 public void removeCellEditorListener(CellEditorListener l)
		 {
			//System.out.println("removed listener");
		  
		 }
    /* (non-Javadoc)
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    public void actionPerformed(ActionEvent e)
    {
      // System.out.println(e.getActionCommand());
      if (table.isEditing())
      if(listener!=null)
     listener.editingStopped(new ChangeEvent(this)); 
    }
	
	 }
  class SQLCommandEditor implements TableCellEditor
    {
      JTextArea editor = new JTextArea();
      JScrollPane pane =new JScrollPane(editor);
      JDialog window ;
      CellEditorListener listener=table;
      JLabel label = new JLabel();
      int x=0,y=0;
      String copy="";boolean removeCalled=true;
      public SQLCommandEditor()
      {
   //     super(new JCheckBox());
        //this.list = list;
        editor.getDocument().addDocumentListener(new DocumentListener() {

        public void insertUpdate(DocumentEvent e)
        {
          //System.out.println(editor.getText().charAt( e.getOffset()));
          copy=editor.getText();
          if(copy.charAt(e.getOffset())=='\n')
          {
            window.setSize(window.getWidth(),window.getHeight()+20);
            window.validate();
          }
        }

        public void removeUpdate(DocumentEvent e)
        {
         if(copy.charAt(e.getOffset())=='\n')
          {
            window.setSize(window.getWidth(),window.getHeight()-20);
            window.validate();
            copy = editor.getText();
          }
          
        }

        public void changedUpdate(DocumentEvent e)
        {   
        }
      
      });
      table.addMouseListener(new MouseAdapter() {
      public void mouseEntered(MouseEvent e) 
      {
        if(true) return;
        //System.out.println(e);
        x = e.getX();
        y = e.getY();
          
        int row = table.rowAtPoint(new Point(e.getX(),e.getY()));
        int col = table.columnAtPoint(new Point(e.getX(),e.getY()));
        
        if(window!=null)
        {
        if(!window.isVisible()) return;
         
        }else return;
        if(row!=table.getEditingRow()||col!=table.getEditingColumn())
        if (listener != null)
        {        
          listener.editingStopped(new ChangeEvent(this));
          listener = null;
        }
      }
      public void mousePressed(MouseEvent e) 
          {
            
           // System.out.println(e);
            x = e.getX();
            y = e.getY();
            
            if(window!=null)
            if(!window.isVisible()) return;
    
            int row = table.rowAtPoint(new Point(x,y));
            int col = table.columnAtPoint(new Point(x,y));
      
            if(row!=table.getEditingRow()||col!=table.getEditingColumn())
            if (listener != null)
            {
              listener.editingStopped(new ChangeEvent(this));
              listener = null;
            }
          }
    
      public void mouseExited(MouseEvent e) {
      //  System.out.println(e);
     
      }
      });
      }
      public Object getCellEditorValue()
      {
         window.setVisible(false);
         window.dispose();
         //table.repaint();
        return new SQLCommand(editor.getText());
      }

      public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
      {
        // checks if editor was finished if not remove old editor
        //this.row=row;
        SQLCommand command = (value != null) ? (SQLCommand) value : null;
        editor.setText(command.toString());
        System.out.println("editor size "+editor.getPreferredSize());
        pane.setBorder(new javax.swing.border.LineBorder(Color.red));
       
        if(window == null)
        {
          window= new JDialog(FM2SQL.fmInstance);
          window.getContentPane().add(pane);
          window.addWindowListener( new WindowAdapter()
          {
            public void windowClosing(WindowEvent e)
            {
              if (listener != null)
              {
                listener.editingStopped(new ChangeEvent(this));
                listener = null;
              }

            }
          });
       }
       Point p=table.getLocationOnScreen();
 //      if(label.isShowing())
 //      System.out.println( label.getLocationOnScreen());
    

      Dimension dimEditor = editor.getPreferredSize();
      if (dimEditor.width < 260)
        dimEditor.width = 260;
      window.setSize((dimEditor.width < 280) ? dimEditor.width + 20 : 280, (dimEditor.height > 50) ? 200 : 60);
      TableColumnModel model = table.getColumnModel();
      int offset_x = 0, offset_y = 0;
      for (int i = 0; i <= column; ++i)
      {
        if (i == column)
          offset_x -= (window.getWidth() - model.getColumn(i).getWidth()) / 2;
        else
          offset_x += model.getColumn(i).getWidth();
      
      }
      for (int i = 0; i < row; ++i)
      {
        offset_y += table.getRowHeight(row);
      }
     // System.out.println(table.getCellRect(row, column, false));
      window.setTitle("Editing row "+row+" column "+column);
      window.setLocation(p.x+offset_x,p.y+offset_y);
      window.setVisible(true);
      System.out.println("row "+row+" col "+column+" location"+ window.getLocation());
    // window.setVisible(true);
      
        //label=new JLabel(command.toString());
        label.setText(command.toString());
        label.setForeground(Color.red);
        return label;
      }

      public boolean isCellEditable(EventObject anEvent)
      {
        if (table.isEditing())
        {

          if (listener == null)
            listener = table;
          if (listener != null)
            listener.editingStopped(new ChangeEvent(this));
        }
   
        return true;
      }

      public boolean shouldSelectCell(EventObject anEvent)
      {
    
        return true;
      }

      public boolean stopCellEditing()
      {
        return true;
      }

      public void cancelCellEditing()
      {
        System.out.println("cancel was called");
      }

      public void addCellEditorListener(CellEditorListener l)
      {
        removeCalled=false;
        listener=l;   
      }

      public void removeCellEditorListener(CellEditorListener l)
      {
        //if(listener!=null)
        removeCalled = true;
        //table.removeAll();
        
        System.out.println("remove was called");
      }
  
    }


  class ArrayListEditor implements TableCellEditor
  {
    JList list = new JList();
		ArrayList vec = new ArrayList();
    DefaultListModel model = new DefaultListModel();
    JScrollPane pane =new JScrollPane(list);
    JWindow window ;
    CellEditorListener listener=table;
    int row,x,y;
    public ArrayListEditor()
    {
 //     super(new JCheckBox());
      //this.list = list;
      table.addMouseListener(new MouseAdapter() {
         public void mouseEntered(MouseEvent e) 
         {
          // if(true) return;
           //System.out.println(e);
           x = e.getX();
           y = e.getY();
          
           int row = table.rowAtPoint(new Point(e.getX(),e.getY()));
           int col = table.columnAtPoint(new Point(e.getX(),e.getY()));
        
           if(window!=null)
           {
             if(!window.isVisible()) return;
            
           } else return;
          
           if(row!=table.getEditingRow()||col!=table.getEditingColumn())
           if (listener != null)
           {        
             listener.editingStopped(new ChangeEvent(this));
             //listener = null;
           }
         }
         public void mousePressed(MouseEvent e) 
             {
            
              // System.out.println(e);
               x = e.getX();
               y = e.getY();
            
               if(window!=null)
               if(!window.isVisible()) return;
    
               int row = table.rowAtPoint(new Point(x,y));
               int col = table.columnAtPoint(new Point(x,y));
      
               if(row!=table.getEditingRow()||col!=table.getEditingColumn())
               if (listener != null)
               {
                 listener.editingStopped(new ChangeEvent(this));
                 //listener = null;
               }
             }
    
         public void mouseExited(MouseEvent e) {
         //  System.out.println(e);
     
         }
         });
   
  pane.addFocusListener(new FocusAdapter()
  {
    public void focusLost(FocusEvent e)
    {
      listener.editingStopped(new ChangeEvent(this));
      //		table.setRowHeight(row,20);
      System.out.println("lost focus");
    }

  });
    pane.addMouseListener(new MouseAdapter()
    {
      public void mouseExited(MouseEvent e)
      {
        //  System.out.println(e);
        listener.editingStopped(new ChangeEvent(this));
      }
    });
  }
    public Object getCellEditorValue()
    {
      selIndex = list.getSelectedIndex();
		  window.setVisible(false);
      window.dispose();
    //	table.setRowHeight(row,20);
    
		  return vec;
    }

    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
    {
      this.row=row;
      vec = (value != null) ? (ArrayList) value : new ArrayList();
		model.clear();
       for(int i=0;i<vec.size();++i)
		model.addElement(vec.get(i));
		list.setModel(model);
        list.setModel(model);
      pane.setBorder(new javax.swing.border.LineBorder(Color.red));
			//if(!isSelected)
			//table.setRowHeight(row,80);
      if(window == null)
           {
             window= new JWindow(FM2SQL.fmInstance);
             window.getContentPane().add(pane);
          }
          Point p=table.getLocationOnScreen();
    //      if(label.isShowing())
    //      System.out.println( label.getLocationOnScreen());
    

        Dimension dimEditor = pane.getPreferredSize();
        window.setSize((dimEditor.width<250) ? dimEditor.width+20:250,(dimEditor.height>50) ? 200:50);
        TableColumnModel model = table.getColumnModel();
                 int offset_x = 0,offset_y = 0;
                 for (int i = 0; i <= column; ++i)
                 {
                   if(i==column)
                   offset_x-=(window.getWidth()-model.getColumn(i).getWidth())/2;
                   else
                   offset_x+=model.getColumn(i).getWidth();

                 }
                for (int i = 0; i < row; ++i)
                {
                    offset_y +=table.getRowHeight(row);
                }
           window.setVisible(true);
        // System.out.println(table.getCellRect(row, column, false));
      
         window.setLocation(p.x+offset_x,p.y+offset_y);
       // System.out.println("row "+row+" col "+column+" location"+ window.getBounds());
       // window.setVisible(true);
           //label=new JLabel(command.toString());
           label.setText("editing");
           label.setForeground(Color.red);
           return label;

     // return pane;
    }

		public boolean isCellEditable(EventObject anEvent)
		{
      if (table.isEditing())
      {
        System.out.println("Editing is in progress");
    
       // if (listener == null)
         // listener = table;
        if (listener != null)
          listener.editingStopped(new ChangeEvent(this));

      }
      return true;
		}

		public boolean shouldSelectCell(EventObject anEvent)
		{
			return true;
		}

		public boolean stopCellEditing()
		{
			return true;
		}

		public void cancelCellEditing()
		{
		}

		public void addCellEditorListener(CellEditorListener l)
		{
			listener=l;		
 		}

		public void removeCellEditorListener(CellEditorListener l)
		{
		  System.out.println(l);
		}
	
  }
  class VectorCellRenderer implements TableCellRenderer
  {
    JList list=new JList();
		JComboBox box;
    JLabel label = new JLabel();
    DefaultListModel model=new DefaultListModel();
	 JScrollPane listScroller=new JScrollPane(list);
   
    public VectorCellRenderer()
    {
      //list = new JList();
     // vec = new Vector();
      label.setForeground(Color.blue);
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
    {
			box = (JComboBox) value ;
 			if(box==null) return null;//label.setText("");
 			else
 			if(box.getSelectedItem()!=null)
 			{
			String text=box.getSelectedItem().toString();
 			if(text=="")
 			{ 
 				text="\"no Layout\"";
 			  label.setForeground(Color.red);
 			  
 			}else  label.setForeground(Color.blue); 
			label.setText(text);

 			}
      else label.setText("");
        return label;
    }

  }
	class ArrayListCellRenderer implements TableCellRenderer
	{
		JList list=new JList();
		ArrayList vec;
		JLabel label = new JLabel();
		DefaultListModel model=new DefaultListModel();
	JScrollPane listScroller=new JScrollPane(list);
   
		public ArrayListCellRenderer()
		{
			//list = new JList();
			vec = new ArrayList();
			label.setForeground(Color.blue);
		}

		public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
		{
			vec = (value != null) ? (ArrayList) value : new ArrayList();
			model.clear();
			for(int i=0;i<vec.size();++i)
			model.addElement(vec.get(i));
			list.setModel(model);

		 // if (selIndex < vec.size() && selIndex >= 0)
			 // list.setSelectedIndex(selIndex);
		/*	if (hasFocus) {
						label.setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
						if (table.isCellEditable(row, column)) {
								label.setForeground( UIManager.getColor("Table.focusCellForeground") );
								label.setBackground( UIManager.getColor("Table.focusCellBackground") );
						}
				} else {
						label.setBorder(BorderFactory.createEmptyBorder());
				}*/
/*
			if (vec.size() >0)
			{
				label.setText(vec.get(0).toString());
				return label;
			} else if (vec.isEmpty())
			{
				label.setText("null");
				return label;

			} else
				return list;
		}*/
   
   label.setText((vec.isEmpty()) ? "":vec.get(0).toString());
return label;
    }
  }

  /**
   * exports the current data in this tablecomponent to HTML
   *  
   * @return StringBuffer containing the HTML code
   */
  
  public StringBuffer exportToHTML()
  {
    StringBuffer buff = new StringBuffer();
    buff.append(" <table border cellspacing=0 width=\"50%\">");
    // table Header
    buff.append("<tr>");
    for (int i = 0; i < tableModel.getColumnCount(); ++i)
    {
      buff.append("<th>");
      buff.append(tableModel.getColumnName(i));
      buff.append("</th>");
    }
    buff.append("</tr>");
    for (int i = 0; i < realCount; ++i)
    {
      for (int j = 0; j < tableModel.getColumnCount(); ++j)
      {
        buff.append("<td>");
        String val = (tableModel.getValueAt(i, j) == null) ? "&nbsp" : tableModel.getValueAt(i, j).toString();
        buff.append(val);
        buff.append("</td>");
      }
      buff.append("<tr>");
      buff.append("</tr>\n");
    }
    buff.append("</table>");

    return convertUml(buff);
  }
  /**
   * MacOs and Windows Version of the Method 
   * converts german umlaute to html &umlaute;
   */
  public static StringBuffer convertUml(StringBuffer newName)
  {
    StringBuffer alterMe = newName; //new StringBuffer(newName.trim());
    int length = alterMe.length();
    int j = 0;
    while (j < length)
    {
      //if(Character.isSpaceChar(alterMe.charAt(j)))
      //  alterMe.setCharAt(j,'_');
      if (alterMe.charAt(j) == 'š' || alterMe.charAt(j) == 'ö')
      {
        alterMe.setCharAt(j, '&');
        alterMe.insert(j + 1, "ouml;");
        length = length + 5;
      }
      if (alterMe.charAt(j) == '…' || alterMe.charAt(j) == 'Ö')
      {
        alterMe.setCharAt(j, '&');
        alterMe.insert(j + 1, "Ouml;");
        length = length + 5;

      }
      if (alterMe.charAt(j) == 'Š' || alterMe.charAt(j) == 'ä')
      {
        alterMe.setCharAt(j, '&');
        alterMe.insert(j + 1, "auml;");
        length = length + 5;

      }
      if (alterMe.charAt(j) == '€' || alterMe.charAt(j) == 'Ä')
      {
        alterMe.setCharAt(j, '&');
        alterMe.insert(j + 1, "Auml;");
        length = length + 5;
      }
      if (alterMe.charAt(j) == 'Ÿ' || alterMe.charAt(j) == 'ü')
      {
        alterMe.setCharAt(j, '&');
        alterMe.insert(j + 1, "uuml;");
        length = length + 5;
      }
      if (alterMe.charAt(j) == '†' || alterMe.charAt(j) == 'Ü')
      {
        alterMe.setCharAt(j, '&');
        alterMe.insert(j + 1, "&Uuml;");
        length = length + 5;
      }
      if (alterMe.charAt(j) == '§' || alterMe.charAt(j) == 'ß')
      {
        alterMe.setCharAt(j, '&');
        alterMe.insert(j + 1, "szlig;");
        length = length + 6;
      }

      /*
      if(Character.isSpaceChar(alterMe.charAt(j))
          alterMe.setCharAt(j,'_');
      */
      ++j;
    }
    return alterMe;
  }
  public static class SQLCommand
  {
    String command = "";
    
    public SQLCommand()
    {
    }
    public SQLCommand(String command)
    {
      this.command = command;
    }
    public String toString()
    {
      return command;
    }
  }

}

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