--- FM2SQL/Attic/TableComponent.java 2004/02/18 13:25:24 1.3 +++ FM2SQL/Attic/TableComponent.java 2004/02/19 10:35:06 1.4 @@ -8,7 +8,7 @@ import javax.swing.event.*; /** Table component */ - + public class TableComponent extends JPanel implements TableModelListener { @@ -18,8 +18,8 @@ public class TableComponent extends JPan JPanel content; int row, col; int realCount = 0; - String columnNames[] = { "no database","connection" }; - String[][] rowData = { {"","" } + String columnNames[] = { "no database", "connection" }; + String[][] rowData = { { "", "" } }; boolean callState = false; Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); @@ -140,31 +140,31 @@ public class TableComponent extends JPan 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); - }*/ + 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 || getColumnClass(column) == IDComboBox.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(); @@ -181,24 +181,24 @@ public class TableComponent extends JPan 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 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(); + JLabel label = new JLabel(); public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (value instanceof Integer) @@ -366,98 +366,102 @@ public class TableComponent extends JPan 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()) - { - + 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"); - - } + 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) */ @@ -465,141 +469,148 @@ public class TableComponent extends JPan { // System.out.println(e.getActionCommand()); if (table.isEditing()) - if(listener!=null) - listener.editingStopped(new ChangeEvent(this)); + 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() { - 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() { + // 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') + copy = editor.getText(); + if (copy.charAt(e.getOffset()) == '\n') { - window.setSize(window.getWidth(),window.getHeight()+20); + window.setSize(window.getWidth(), window.getHeight() + 20); window.validate(); } } public void removeUpdate(DocumentEvent e) { - if(copy.charAt(e.getOffset())=='\n') + if (copy.charAt(e.getOffset()) == '\n') { - window.setSize(window.getWidth(),window.getHeight()-20); + 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) + table.addMouseListener(new MouseAdapter() { - 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) + 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) { - - // 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 (!window.isVisible()) + return; + + } else + return; + 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 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() + } + 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.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() + window = new JDialog(FM2SQL.fmInstance); + window.getContentPane().add(pane); + window.addWindowListener(new WindowAdapter() + { + public void windowClosing(WindowEvent e) { - public void windowClosing(WindowEvent e) + if (listener != null) { - if (listener != null) - { - listener.editingStopped(new ChangeEvent(this)); - listener = null; - } - + listener.editingStopped(new ChangeEvent(this)); + listener = null; } - }); - } - Point p=table.getLocationOnScreen(); - // if(label.isShowing()) - // System.out.println( label.getLocationOnScreen()); - + + } + }); + } + Point p = table.getLocationOnScreen(); + // if(label.isShowing()) + // System.out.println( label.getLocationOnScreen()); Dimension dimEditor = editor.getPreferredSize(); if (dimEditor.width < 260) @@ -613,345 +624,362 @@ public class TableComponent extends JPan 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); + // 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; - } + System.out.println("row " + row + " col " + column + " location" + window.getLocation()); + // window.setVisible(true); - public boolean isCellEditable(EventObject anEvent) + //label=new JLabel(command.toString()); + label.setText(command.toString()); + label.setForeground(Color.red); + return label; + } + + public boolean isCellEditable(EventObject anEvent) + { + if (table.isEditing()) { - if (table.isEditing()) - { - if (listener == null) - listener = table; - if (listener != null) - listener.editingStopped(new ChangeEvent(this)); - } - - return true; + if (listener == null) + listener = table; + if (listener != null) + listener.editingStopped(new ChangeEvent(this)); } - public boolean shouldSelectCell(EventObject anEvent) - { - - return true; - } + return true; + } - public boolean stopCellEditing() - { - return true; - } + public boolean shouldSelectCell(EventObject anEvent) + { - public void cancelCellEditing() - { - System.out.println("cancel was called"); - } + return true; + } - public void addCellEditorListener(CellEditorListener l) - { - removeCalled=false; - listener=l; - } + public boolean stopCellEditing() + { + return true; + } - public void removeCellEditorListener(CellEditorListener l) - { - //if(listener!=null) - removeCalled = true; - //table.removeAll(); - - System.out.println("remove was called"); - } - + 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(); + ArrayList vec = new ArrayList(); DefaultListModel model = new DefaultListModel(); - JScrollPane pane =new JScrollPane(list); - JWindow window ; - CellEditorListener listener=table; - int row,x,y; + JScrollPane pane = new JScrollPane(list); + JWindow window; + CellEditorListener listener = table; + int row, x, y; public ArrayListEditor() { - // super(new JCheckBox()); + // super(new JCheckBox()); //this.list = list; - table.addMouseListener(new MouseAdapter() { - public void mouseEntered(MouseEvent 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); - - } - }); - - pane.addFocusListener(new FocusAdapter() - { - public void focusLost(FocusEvent e) - { - listener.editingStopped(new ChangeEvent(this)); - // table.setRowHeight(row,20); - System.out.println("lost focus"); - } + //System.out.println(e); + x = e.getX(); + y = e.getY(); - }); - pane.addMouseListener(new MouseAdapter() - { - public void mouseExited(MouseEvent e) + 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() { - // System.out.println(e); - listener.editingStopped(new ChangeEvent(this)); - } - }); - } + 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.setVisible(false); window.dispose(); - // table.setRowHeight(row,20); - - return vec; + // table.setRowHeight(row,20); + + return vec; } public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - this.row=row; + this.row = row; vec = (value != null) ? (ArrayList) value : new ArrayList(); - model.clear(); - for(int i=0;i50) ? 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; + 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)); - // return pane; + 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) - { + public boolean isCellEditable(EventObject anEvent) + { if (table.isEditing()) { System.out.println("Editing is in progress"); - - // if (listener == null) - // listener = table; + + // 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); + } - 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; + JList list = new JList(); + JComboBox box; JLabel label = new JLabel(); - DefaultListModel model=new DefaultListModel(); - JScrollPane listScroller=new JScrollPane(list); - + DefaultListModel model = new DefaultListModel(); + JScrollPane listScroller = new JScrollPane(list); + Color noIDColor=new Color(50,50,200); + public VectorCellRenderer() { //list = new JList(); - // vec = new Vector(); + // 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; + box = (JComboBox) value; + if (box == null) + return null; //label.setText(""); + else if (box.getSelectedItem() != null) + { + String text = box.getSelectedItem().toString(); + if (text == "") + { + if (box instanceof IDComboBox) + { + text = "\"no ID\""; + label.setForeground(noIDColor); + } else + { + text = "\"no Layout\""; + label.setForeground(Color.red); + } + } else + { + if (box instanceof IDComboBox) + label.setForeground(Color.darkGray); + + 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= 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; + 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; } } @@ -960,7 +988,7 @@ return label; * * @return StringBuffer containing the HTML code */ - + public StringBuffer exportToHTML() { StringBuffer buff = new StringBuffer(); @@ -1059,7 +1087,7 @@ return label; public static class SQLCommand { String command = ""; - + public SQLCommand() { } @@ -1072,5 +1100,12 @@ return label; return command; } } + public static class IDComboBox extends JComboBox + { + public IDComboBox(Vector vec) + { + super(vec); + } + } } \ No newline at end of file