List of usage examples for javax.swing.table DefaultTableModel addTableModelListener
public void addTableModelListener(TableModelListener l)
From source file:edu.ku.brc.af.ui.forms.formatters.DataObjFieldFormatMultiplePanel.java
/** * @param model//from w w w .ja v a2 s. c om */ protected void addTableModelListener(DefaultTableModel model) { TableModelListener tml = new TableModelListener() { public void tableChanged(TableModelEvent e) { int row = e.getFirstRow(); int column = e.getColumn(); DefaultTableModel localModel = (DefaultTableModel) e.getSource(); String columnName = localModel.getColumnName(column); if (columnName.equals(FIELD_VALUE_COL)) { int formatColumn = formatSwitchTbl.getColumnModel().getColumnIndex(DISPLAY_FORMAT_COL); DataObjDataFieldFormat format = (DataObjDataFieldFormat) localModel.getValueAt(row, formatColumn); String value = (String) localModel.getValueAt(row, column); format.setValue(value); enableUIControls(); } } }; model.addTableModelListener(tml); }
From source file:com.mirth.connect.client.ui.ChannelSetup.java
private void initMetaDataTable() { metaDataTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); DefaultTableModel model = new DefaultTableModel(new Object[][] {}, new String[] { METADATA_NAME_COLUMN_NAME, METADATA_TYPE_COLUMN_NAME, METADATA_MAPPING_COLUMN_NAME }) { public boolean isCellEditable(int rowIndex, int columnIndex) { return true; }// www .j av a2 s. com @Override public void setValueAt(Object value, int row, int column) { // Enable the revert button if any data was changed. if (!value.equals(getValueAt(row, column))) { revertMetaDataButton.setEnabled(true); } super.setValueAt(value, row, column); } }; model.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if (e.getType() == TableModelEvent.UPDATE) { parent.setSaveEnabled(true); } } }); class AlphaNumericCellEditor extends TextFieldCellEditor { public AlphaNumericCellEditor() { super(); MirthFieldConstraints constraints = new MirthFieldConstraints("^[a-zA-Z_0-9]*$"); constraints.setLimit(30); getTextField().setDocument(constraints); } @Override protected boolean valueChanged(String value) { return true; } } metaDataTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); metaDataTable.setDragEnabled(false); metaDataTable.setSortable(false); metaDataTable.getTableHeader().setReorderingAllowed(false); metaDataTable.setModel(model); metaDataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { deleteMetaDataButton.setEnabled(metaDataTable.getSelectedRow() != -1); } }); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { metaDataTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } metaDataTable.getColumnModel() .getColumn(metaDataTable.getColumnModel().getColumnIndex(METADATA_NAME_COLUMN_NAME)) .setCellEditor(new AlphaNumericCellEditor()); metaDataTable.getColumnModel() .getColumn(metaDataTable.getColumnModel().getColumnIndex(METADATA_MAPPING_COLUMN_NAME)) .setCellEditor(new AlphaNumericCellEditor()); TableColumn column = metaDataTable.getColumnModel() .getColumn(metaDataTable.getColumnModel().getColumnIndex(METADATA_TYPE_COLUMN_NAME)); column.setCellRenderer(new MirthComboBoxTableCellRenderer(MetaDataColumnType.values())); column.setCellEditor( new MirthComboBoxTableCellEditor(metaDataTable, MetaDataColumnType.values(), 1, false, null)); column.setMinWidth(100); column.setMaxWidth(100); deleteMetaDataButton.setEnabled(false); }
From source file:plugins.ImageRectificationPanel.java
public final void createGui() { this.removeAll(); if (imageGCPsXCoords == null) { return;/* w ww. ja v a2 s. c o m*/ } int i; int newN = 0; for (i = 0; i < imageGCPsXCoords.length; i++) { if (useGCP[i]) { newN++; } } double[] X1 = new double[newN]; double[] Y1 = new double[newN]; double[] X2 = new double[newN]; double[] Y2 = new double[newN]; int j = 0; for (i = 0; i < imageGCPsXCoords.length; i++) { if (useGCP[i]) { X1[j] = imageGCPsXCoords[i]; Y1[j] = imageGCPsYCoords[i]; X2[j] = mapGCPsXCoords[i]; Y2[j] = mapGCPsYCoords[i]; j++; } } calculateEquations(X1, Y1, X2, Y2); // gui stuff this.setLayout(new BorderLayout()); DecimalFormat df = new DecimalFormat("###,###,##0.000"); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS)); JButton btnOK = createButton(bundle.getString("OK"), bundle.getString("OK"), "ok"); JButton btnExit = createButton(bundle.getString("Close"), bundle.getString("Close"), "close"); //JButton btnRefresh = createButton("Cancel", "Cancel"); buttonPane.add(Box.createHorizontalStrut(10)); buttonPane.add(btnOK); buttonPane.add(Box.createHorizontalStrut(5)); //buttonPane.add(btnRefresh); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(btnExit); buttonPane.add(Box.createHorizontalGlue()); progressBar = new JProgressBar(0, 100); buttonPane.add(progressBar); buttonPane.add(Box.createHorizontalStrut(5)); cancel = new JLabel(bundle.getString("Cancel")); cancel.setForeground(Color.BLUE.darker()); cancel.addMouseListener(this); buttonPane.add(cancel); buttonPane.add(Box.createHorizontalStrut(10)); this.add(buttonPane, BorderLayout.SOUTH); Box mainBox = Box.createVerticalBox(); mainBox.add(Box.createVerticalStrut(10)); Box box1 = Box.createHorizontalBox(); box1.add(Box.createHorizontalStrut(10)); box1.add(new JLabel(bundle.getString("PolynomialOrder") + ": ")); SpinnerModel model = new SpinnerNumberModel(polyOrder, //initial value 1, //min 5, //max 1); //step polyOrderSpinner = new JSpinner(model); polyOrderSpinner.setPreferredSize(new Dimension(15, polyOrderSpinner.getPreferredSize().height)); polyOrderSpinner.addChangeListener(this); JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) polyOrderSpinner.getEditor(); editor.getTextField().setEnabled(true); editor.getTextField().setEditable(false); box1.add(polyOrderSpinner); box1.add(Box.createHorizontalGlue()); JLabel label = new JLabel("RMSE: " + df.format(overallRMSE)); box1.add(label); box1.add(Box.createHorizontalStrut(10)); mainBox.add(box1); mainBox.add(Box.createVerticalStrut(10)); // Create columns names int numPoints = imageGCPsXCoords.length; Object dataValues[][] = new Object[numPoints][7]; j = 0; for (i = 0; i < numPoints; i++) { dataValues[i][0] = i + 1; dataValues[i][1] = df.format(imageGCPsXCoords[i]); dataValues[i][2] = df.format(imageGCPsYCoords[i]); dataValues[i][3] = df.format(mapGCPsXCoords[i]); dataValues[i][4] = df.format(mapGCPsYCoords[i]); if (useGCP[i]) { dataValues[i][5] = df.format(residualsXY[j]); j++; } else { dataValues[i][5] = null; } dataValues[i][6] = useGCP[i]; } String columnNames[] = { "GCP", bundle.getString("Image") + " X", bundle.getString("Image") + " Y", bundle.getString("Map") + " X", bundle.getString("Map") + " Y", messages.getString("Error"), "Use" }; DefaultTableModel tableModel = new DefaultTableModel(dataValues, columnNames); dataTable = new JTable(tableModel) { private static final long serialVersionUID = 1L; @Override public Class getColumnClass(int column) { switch (column) { case 0: return Integer.class; case 1: return String.class; //Double.class; case 2: return String.class; //Double.class; case 3: return String.class; //Double.class; case 4: return String.class; //Double.class; case 5: return String.class; //Double.class; case 6: return Boolean.class; default: return String.class; //Double.class; } } @Override public Component prepareRenderer(TableCellRenderer renderer, int index_row, int index_col) { Component comp = super.prepareRenderer(renderer, index_row, index_col); //even index, selected or not selected if (index_row % 2 == 0) { comp.setBackground(Color.WHITE); comp.setForeground(Color.BLACK); } else { comp.setBackground(new Color(225, 245, 255)); //new Color(210, 230, 255)); comp.setForeground(Color.BLACK); } if (isCellSelected(index_row, index_col)) { comp.setForeground(Color.RED); } return comp; } }; tableModel.addTableModelListener(this); TableCellRenderer rend = dataTable.getTableHeader().getDefaultRenderer(); TableColumnModel tcm = dataTable.getColumnModel(); //for (int j = 0; j < tcm.getColumnCount(); j += 1) { TableColumn tc = tcm.getColumn(0); TableCellRenderer rendCol = tc.getHeaderRenderer(); // likely null if (rendCol == null) { rendCol = rend; } Component c = rendCol.getTableCellRendererComponent(dataTable, tc.getHeaderValue(), false, false, 0, 0); tc.setPreferredWidth(35); tc = tcm.getColumn(6); rendCol = tc.getHeaderRenderer(); // likely null if (rendCol == null) { rendCol = rend; } c = rendCol.getTableCellRendererComponent(dataTable, tc.getHeaderValue(), false, false, 0, 6); tc.setPreferredWidth(35); JScrollPane scroll = new JScrollPane(dataTable); mainBox.add(scroll); this.add(mainBox, BorderLayout.CENTER); this.validate(); }