javax.swing.table.TableModel Java Examples

The following examples show how to use javax.swing.table.TableModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: groovy   Author: apache   File: SwingExtensions.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns an {@link java.util.Iterator} which traverses the TableModel one row at a time.
 *
 * @param self a TableModel
 * @return an Iterator for a TableModel
 * @since 1.6.4
 */
public static Iterator<?> iterator(final TableModel self) {
    return new Iterator<Object>() {
        private int row = 0;

        public boolean hasNext() {
            return row < self.getRowCount();
        }

        public Object next() {
            int cols = self.getColumnCount();
            Object[] rowData = new Object[cols];
            for (int col = 0; col < cols; col++) {
                rowData[col] = self.getValueAt(row, col);
            }
            row++;
            return rowData;
        }

        public void remove() {
            throw new UnsupportedOperationException("TableModel is immutable.");
        }
    };
}
 
Example #2
Source Project: ghidra   Author: NationalSecurityAgency   File: AbstractVTCorrelatorTest.java    License: Apache License 2.0 6 votes vote down vote up
protected void chooseFromCorrelationPanel(final String correlatorName, Runnable wizardAction) {

		WizardPanel currentWizardPanel = wizardManager.getCurrentWizardPanel();
		assertNotNull(currentWizardPanel);
		assertTrue(currentWizardPanel instanceof CorrelatorPanel);
		CorrelatorPanel correlatorPanel = (CorrelatorPanel) currentWizardPanel;
		runSwing(() -> {
			GhidraTable table = (GhidraTable) TestUtils.getInstanceField("table", correlatorPanel);
			TableModel model = table.getModel();
			int column = getNamedColumnIndex("Name", model);
			assertTrue(column >= 0);
			int row = getRowWithFieldValueInColumn(correlatorName, model, column);
			assertTrue(row >= 0);
			model.setValueAt(Boolean.TRUE, row, 0);
			wizardAction.run();
		});
	}
 
Example #3
Source Project: meka   Author: Waikato   File: SortableAndSearchableTable.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets the model to display - only {@link #getTableModelClass()}.
 *
 * @param model	the model to display
 */
@Override
public synchronized void setModel(TableModel model) {
	Hashtable<String,Object> settings;

	if (!(getTableModelClass().isInstance(model)))
		model = createDefaultDataModel();

	// backup current setup
	if (m_Model != null) {
		settings = backupModelSettings(m_Model);
		getTableHeader().removeMouseListener(m_Model.getHeaderMouseListener());
	}
	else {
		settings = null;
	}

	m_Model = new SortableAndSearchableWrapperTableModel(model);
	super.setModel(m_Model);
	m_Model.addMouseListenerToHeader(this);

	// restore setup
	restoreModelSettings(m_Model, settings);
}
 
Example #4
Source Project: ghidra   Author: NationalSecurityAgency   File: EquatePlugin1Test.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMultipleEquatesSameValue() throws Exception {

	createSameValueDifferentNameEquates();

	putCursorOnOperand(0x010062d6, 1);

	SetEquateDialog d = showSetEquateDialog();

	GhidraTable table = findComponent(d.getComponent(), GhidraTable.class);
	assertNotNull(table);

	TableModel model = table.getModel();
	assertEquals(5, model.getRowCount());
	for (int i = 0; i < 5; i++) {
		String value = (String) model.getValueAt(i, 0);
		assertTrue(value.startsWith("MY_EQUATE_"));
	}

	cancel(d);
}
 
Example #5
Source Project: pentaho-reporting   Author: pentaho   File: TableEditorModel.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public void copyInto( final TableModel model ) {
  try {
    setSuspendEvents( true );
    clear();
    if ( model == null ) {
      return;
    }

    final int columnCount = model.getColumnCount();
    for ( int col = 0; col < columnCount; col++ ) {
      addColumn( model.getColumnName( col ), model.getColumnClass( col ) );
    }

    final int rowCount = model.getRowCount();
    for ( int r = 0; r < rowCount; r++ ) {
      addRow();
      for ( int col = 0; col < columnCount; col++ ) {
        final Object originalValue = model.getValueAt( r, col );
        setValueAt( originalValue, r, col + 1 );
      }
    }
  } finally {
    setSuspendEvents( false );
  }
}
 
Example #6
Source Project: pentaho-reporting   Author: pentaho   File: IsEmptyDataExpression.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Checks whether the report has a data-source and wether the datasource is empty. A datasource is considered empty,
 * if it contains no rows. The number of columns is not evaluated.
 *
 * @return the value of the function.
 */
public Object getValue() {

  final ExpressionRuntime runtime = getRuntime();
  if ( runtime == null ) {
    return null;
  }
  final TableModel data = runtime.getData();
  if ( data == null ) {
    return null;
  }
  if ( data.getRowCount() == 0 ) {
    return Boolean.TRUE;
  }
  return Boolean.FALSE;
}
 
Example #7
Source Project: ghidra   Author: NationalSecurityAgency   File: TableColumnModelState.java    License: Apache License 2.0 6 votes vote down vote up
private void saveColumnSettings(Element columnElement, TableColumn column) {
	TableModel tableModel = table.getUnwrappedTableModel();
	if (!(tableModel instanceof ConfigurableColumnTableModel)) {
		return;
	}

	ConfigurableColumnTableModel configurableTableModel =
		(ConfigurableColumnTableModel) tableModel;
	Settings settings = configurableTableModel.getColumnSettings(column.getModelIndex());
	if (settings == null) {
		return;
	}

	for (String name : settings.getNames()) {
		Object value = settings.getValue(name);
		if (value instanceof String) {
			addSettingElement(columnElement, name, "String", (String) value);
		}
		else if (value instanceof Long) {
			addSettingElement(columnElement, name, "Long", value.toString());
		}
		// else if (value instanceof byte[]) // we don't handle this case; OBE?
	}
}
 
Example #8
Source Project: pentaho-reporting   Author: pentaho   File: ExtSubReportDemo.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
private TableModel createFruitTableModel()
{
  final String[] names = new String[]{"Id Number", "Cat", "Fruit"};
  final Object[][] data = new Object[][]{
      {"I1", "A", "Apple"},
      {"I2", "A", "Orange"},
      {"I2", "A", "Orange"},
      {"I2", "A", "Orange"},
      {"I2", "A", "Orange"},
      {"I2", "A", "Orange"},
      {"I2", "A", "Orange"},
      {"I2", "A", "Orange"},
      {"I2", "A", "Orange"},
      {"I3", "B", "Water melon"},
      {"I3", "B", "Water melon"},
      {"I3", "B", "Water melon"},
      {"I3", "B", "Water melon"},
      {"I3", "B", "Water melon"},
      {"I3", "B", "Water melon"},
      {"I3", "B", "Water melon"},
      {"I3", "B", "Water melon"},
      {"I4", "B", "Strawberry"},
  };
  return new DefaultTableModel(data, names);
}
 
Example #9
Source Project: pentaho-reporting   Author: pentaho   File: PerfBenchmarkingTest.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
private TableModel createFruitTableModel() {
  final String[] names = new String[] { "Id Number", "Cat", "Fruit" };
  final Object[][] data = new Object[][] {
    { "I1", "A", "Apple" },
    { "I2", "A", "Orange" },
    { "I2", "A", "Orange" },
    { "I2", "A", "Orange" },
    { "I2", "A", "Orange" },
    { "I2", "A", "Orange" },
    { "I2", "A", "Orange" },
    { "I2", "A", "Orange" },
    { "I2", "A", "Orange" },
    { "I3", "B", "Water melon" },
    { "I3", "B", "Water melon" },
    { "I3", "B", "Water melon" },
    { "I3", "B", "Water melon" },
    { "I3", "B", "Water melon" },
    { "I3", "B", "Water melon" },
    { "I3", "B", "Water melon" },
    { "I3", "B", "Water melon" },
    { "I4", "B", "Strawberry" },
  };
  return new DefaultTableModel( data, names );
}
 
Example #10
Source Project: gameserver   Author: wangqi   File: MyTable.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
	if ( renderFactory != null ) {
		TableModel tableModel = this.getModel();
		if ( tableModel != null ) {
			int modelRowIndex = this.convertRowIndexToModel(row);
			int modelColumnIndex = this.convertColumnIndexToModel(column);
			String columnName = getColumnName(column, tableModel);
			TableCellRenderer renderer = this.renderFactory.getCellRenderer(
					modelRowIndex, modelColumnIndex, columnName, tableModel, this);
			if ( renderer != null ) {
				return renderer;
			}
		}
	}
	return super.getCellRenderer(row, column);
}
 
Example #11
Source Project: CodenameOne   Author: codenameone   File: PropertySheetTable.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Overriden to register a listener on the model. This listener ensures
 * editing is cancelled when editing row is being changed.
 * 
 * @see javax.swing.JTable#setModel(javax.swing.table.TableModel)
 * @throws IllegalArgumentException
 *           if dataModel is not a {@link PropertySheetTableModel}
 */
public void setModel(TableModel newModel) {
  if (!(newModel instanceof PropertySheetTableModel)) {
    throw new IllegalArgumentException("dataModel must be of type "
        + PropertySheetTableModel.class.getName());
  }

  if (cancelEditing == null) {
    cancelEditing = new CancelEditing();
  }

  TableModel oldModel = getModel();
  if (oldModel != null) {
    oldModel.removeTableModelListener(cancelEditing);
  }
  super.setModel(newModel);
  newModel.addTableModelListener(cancelEditing);

  // ensure the "value" column can not be resized
  getColumnModel().getColumn(1).setResizable(false);
}
 
Example #12
Source Project: netbeans   Author: apache   File: DefaultOutlineModel.java    License: Apache License 2.0 6 votes vote down vote up
/** Creates a new instance of DefaultOutlineModel.  <strong><b>Note</b> 
 * Do not fire table structure changes from the wrapped TableModel (value
 * changes are okay).  Changes that affect the number of rows must come
 * from the TreeModel.
 * @param treeModel The tree model
 * @param tableModel The table model
 * @param largeModel <code>true</code> if it's a large model tree, <code>false</code> otherwise.
 * @param nodesColumnLabel Label of the node's column
 */
protected DefaultOutlineModel(TreeModel treeModel, TableModel tableModel, boolean largeModel, String nodesColumnLabel) {
    this.treeModel = treeModel;
    this.tableModel = tableModel;
    if (nodesColumnLabel != null) {
        this.nodesColumnLabel = nodesColumnLabel;
    }
    
    layout = largeModel ? (AbstractLayoutCache) new FixedHeightLayoutCache() 
        : (AbstractLayoutCache) new VariableHeightLayoutCache();
        
    broadcaster = new EventBroadcaster (this);
    
    layout.setRootVisible(true);
    layout.setModel(this);
    treePathSupport = new TreePathSupport(this, layout);
    treePathSupport.addTreeExpansionListener(broadcaster);
    treePathSupport.addTreeWillExpandListener(broadcaster);
    treeModel.addTreeModelListener(broadcaster);
    tableModel.addTableModelListener(broadcaster);
    if (tableModel instanceof ProxyTableModel) {
        ((ProxyTableModel) tableModel).setOutlineModel(this);
    }
}
 
Example #13
Source Project: visualvm   Author: oracle   File: ManageCalibration.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void refreshTimes(JTable table) {
    final TableModel model = table.getModel();
    for (int row = 0; row < model.getRowCount(); row++) {
        String javaPlatform = javaPlatforms[row];
        Long modified = null;
        String s = CalibrationSupport.getCalibrationDataFileName(javaPlatform);
        if (s != null) {
            File f = new File(s);
            if (f.isFile()) modified = Long.valueOf(f.lastModified());
        }
        final int index = row;
        final Long _modified = modified;
        SwingUtilities.invokeLater(new Runnable() {
            public void run() { model.setValueAt(_modified, index, 1); }
        });
    }
}
 
Example #14
Source Project: pentaho-reporting   Author: pentaho   File: ItemMinFunctionIT.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testReport() throws Exception {
  final TableModel tableModel = createTableModel();
  final MasterReport report = createReport( tableModel );

  report.addExpression( create( "cell-sum", VALUE, null, COLUMN_DIMENSION_B ) );
  report.addExpression( new ValidateFunctionResultExpression( "#cell-sum", true, null ) );

  report.addExpression( create( "detail-sum", VALUE, COLUMN_DIMENSION_B, ROW_DIMENSION_B ) );
  report.addExpression( new ValidateFunctionResultExpression( "#detail-sum", true, COLUMN_DIMENSION_B ) );

  report.addExpression( create( "row-b-sum", VALUE, COLUMN_DIMENSION_A, ROW_DIMENSION_B ) );
  report.addExpression( new ValidateFunctionResultExpression( "#row-b-sum", true, COLUMN_DIMENSION_A ) );

  report.addExpression( create( "row-a-sum", VALUE, COLUMN_DIMENSION_A, ROW_DIMENSION_A ) );
  report.addExpression( new ValidateFunctionResultExpression( "#row-a-sum", true, COLUMN_DIMENSION_A ) );

  report.addExpression( create( "column-a-sum", VALUE, null, COLUMN_DIMENSION_A ) );
  report.addExpression( new ValidateFunctionResultExpression( "#column-a-sum", true, null ) );

  report.addExpression( create( "column-b-sum", VALUE, COLUMN_DIMENSION_B, ROW_DIMENSION_A ) );
  report.addExpression( new ValidateFunctionResultExpression( "#column-b-sum", true, COLUMN_DIMENSION_B ) );

  DebugReportRunner.execGraphics2D( report );
}
 
Example #15
Source Project: java-swing-tips   Author: aterai   File: MainPanel.java    License: MIT License 6 votes vote down vote up
private void deleteActionPerformed() {
  int[] selection = table.getSelectedRows();
  if (selection.length == 0) {
    return;
  }
  for (int i: selection) {
    int mi = table.convertRowIndexToModel(i);
    deletedRowSet.add(mi);
    SwingWorker<?, ?> worker = getSwingWorker(mi);
    if (Objects.nonNull(worker) && !worker.isDone()) {
      worker.cancel(true);
      // executor.remove(worker);
    }
    // worker = null;
  }
  RowSorter<? extends TableModel> sorter = table.getRowSorter();
  ((TableRowSorter<? extends TableModel>) sorter).setRowFilter(new RowFilter<TableModel, Integer>() {
    @Override public boolean include(Entry<? extends TableModel, ? extends Integer> entry) {
      return !deletedRowSet.contains(entry.getIdentifier());
    }
  });
  table.clearSelection();
  table.repaint();
}
 
Example #16
Source Project: pentaho-reporting   Author: pentaho   File: ItemSumFunctionIT.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
private MasterReport createReport( final TableModel tableModel ) {
  final MasterReport report = new MasterReport();
  report.setDataFactory( new TableDataFactory( "query", tableModel ) );
  report.setQuery( "query" );
  final DesignTimeDataSchemaModel dataSchemaModel = new DesignTimeDataSchemaModel( report );

  final CrosstabBuilder builder = new CrosstabBuilder( dataSchemaModel );
  builder.addRowDimension( "Row-Dimension-A" );
  builder.addRowDimension( ROW_DIMENSION_B );
  builder.addColumnDimension( COLUMN_DIMENSION_A );
  builder.addColumnDimension( COLUMN_DIMENSION_B );
  builder.addDetails( VALUE, null );
  report.setRootGroup( builder.create() );
  return report;
}
 
Example #17
Source Project: pentaho-reporting   Author: pentaho   File: CdaDataSourceEditor.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
private TableModel fetchData(final String method,
                             final Map<String, String> extraParameter) throws ReportProcessingException
{
  // ugly but might still beat constructing the whole query
  final CdaDataFactory dataFactory = produceDataFactory();
  DataFactoryEditorSupport.configureDataFactoryForPreview(dataFactory, designTimeContext);

  HttpQueryBackend httpQuery = getHttpQuery();
  httpQuery.initialize(dataFactory.getDataFactoryContext());
  return httpQuery.fetchData(null, method, extraParameter);
}
 
Example #18
Source Project: netbeans   Author: apache   File: AnnotationSettings.java    License: Apache License 2.0 5 votes vote down vote up
private List<AnnotationExpression> getAnnotationExpressions() {
    TableModel model = panel.expresionsTable.getModel();
    List<AnnotationExpression> exps = new ArrayList<AnnotationExpression>(model.getRowCount());
    for (int r = 0; r < model.getRowCount(); r++) {
        String urlExp = (String) model.getValueAt(r, 0);
        if (urlExp.trim().equals("")) {
            continue;
        }
        String annotationExp = (String) model.getValueAt(r, 1);
        exps.add(new AnnotationExpression(urlExp, annotationExp));
    }
    return exps;
}
 
Example #19
Source Project: openAGV   Author: tcrct   File: OrdersTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
  TableModel tableModel = getModel();
  Object value = tableModel.getValueAt(row, column);
  TableCellRenderer renderer = getDefaultRenderer(value.getClass());

  return renderer;
}
 
Example #20
Source Project: pentaho-reporting   Author: pentaho   File: DefaultFlowController.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public DefaultFlowController performSubReportQuery( final String query, final int queryLimit, final int queryTimeout,
    final ParameterMapping[] outputParameters, final List<SortConstraint> sortConstraints )
  throws ReportDataFactoryException {
  if ( outputParameters == null ) {
    throw new NullPointerException();
  }

  final MasterDataRow subReportDataRow = this.dataRow;
  // perform the query ...
  // add the resultset ...
  final TableModel tableData =
      performQueryData( subReportDataRow.getDataFactory(), query, queryLimit, queryTimeout, subReportDataRow
          .getGlobalView(), false, sortConstraints );
  final MasterDataRow masterRow = subReportDataRow.deriveWithQueryData( tableData );

  if ( isGlobalImportOrExport( outputParameters ) ) {
    if ( "true".equals( reportContext.getConfiguration().getConfigProperty(
        "org.pentaho.reporting.engine.classic.core.EnableGlobalSubReportImports" ) ) ) {
      masterRow.getParentDataRow().setImportedDataRow( new ImportedVariablesDataRow( masterRow ) );
    } else {
      masterRow.getParentDataRow().setImportedDataRow(
          new ImportedVariablesDataRow( masterRow, filterGlobalImport( outputParameters ) ) );
    }
  } else {
    // check and rebuild the parameter mapping from the inner to the outer
    // context. Only deep-traversal expressions will be able to see these
    // values (unless they have been defined as local variables).
    masterRow.getParentDataRow().setImportedDataRow( new ImportedVariablesDataRow( masterRow, outputParameters ) );
  }

  final DefaultFlowController fc = new DefaultFlowController( this, masterRow );
  fc.dataContextStack.push( new ReportDataContext( advanceRequested ) );
  fc.dataRow = masterRow;
  fc.dataRow.resetDataSchema();
  return fc;
}
 
Example #21
Source Project: pentaho-reporting   Author: pentaho   File: TotalItemMinFunctionIT.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
private TableModel createTableModel() {
  final TypedTableModel model = new TypedTableModel();
  model.addColumn( ROW_DIMENSION_A, String.class );
  model.addColumn( ROW_DIMENSION_B, String.class );
  model.addColumn( COLUMN_DIMENSION_A, String.class );
  model.addColumn( COLUMN_DIMENSION_B, String.class );
  model.addColumn( VALUE, String.class );
  model.addColumn( "validate-cell-sum", String.class );
  model.addColumn( "validate-detail-sum", String.class );
  model.addColumn( "validate-row-b-sum", String.class );
  model.addColumn( "validate-row-a-sum", String.class );
  model.addColumn( "validate-column-a-sum", String.class ); // same as row-b-sum
  model.addColumn( "validate-column-b-sum", String.class );

  model.addRow( "R1", "r1", "C1", "c1", 1, 1, 1, 1, 1, 1, 1 );
  model.addRow( "R1", "r1", "C1", "c2", 2, 2, 2, 1, 1, 1, 2 );
  model.addRow( "R1", "r1", "C2", "c1", 3, 3, 3, 3, 3, 3, 3 );
  model.addRow( "R1", "r1", "C2", "c2", 4, 4, 4, 3, 3, 3, 4 );
  model.addRow( "R1", "r2", "C1", "c1", 5, 5, 5, 5, 1, 5, 1 ); // *
  model.addRow( "R1", "r2", "C1", "c2", 6, 6, 6, 5, 1, 5, 2 );
  model.addRow( "R1", "r2", "C2", "c1", 7, 7, 7, 7, 3, 7, 3 ); //
  model.addRow( "R1", "r2", "C2", "c2", 8, 8, 8, 7, 3, 7, 4 );
  model.addRow( "R1", "r2", "C2", "c2", 8, 8, 8, 7, 3, 7, 4 );
  model.addRow( "R1", "r2", "C2", "c2", 8, 8, 8, 7, 3, 7, 4 ); //
  model.addRow( "R2", "r1", "C1", "c1", 10, 10, 10, 10, 10, 10, 10 );
  model.addRow( "R2", "r1", "C1", "c2", 11, 11, 11, 10, 10, 10, 11 );
  model.addRow( "R2", "r1", "C2", "c1", 12, 12, 12, 12, 12, 12, 12 );
  model.addRow( "R2", "r1", "C2", "c2", 13, 13, 13, 12, 12, 12, 13 );
  model.addRow( "R2", "r2", "C1", "c1", 14, 14, 14, 14, 10, 14, 10 );
  model.addRow( "R2", "r2", "C1", "c2", 15, 15, 15, 14, 10, 14, 11 );
  model.addRow( "R2", "r2", "C2", "c1", 16, 16, 16, 16, 12, 16, 12 );
  model.addRow( "R2", "r2", "C2", "c2", 17, 17, 17, 16, 12, 16, 13 );
  return model;
}
 
Example #22
Source Project: jdk8u_jdk   Author: JetBrains   File: XMBeanAttributes.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void tableChanged(final TableModelEvent e) {
    // only post changes to the draggable column
    if (isColumnEditable(e.getColumn())) {
        final TableModel model = (TableModel)e.getSource();
        Object tableValue = model.getValueAt(e.getFirstRow(),
                                         e.getColumn());

        if (LOGGER.isLoggable(Level.FINER)) {
            LOGGER.finer("tableChanged: firstRow="+e.getFirstRow()+
                ", lastRow="+e.getLastRow()+", column="+e.getColumn()+
                ", value="+tableValue);
        }
        // if it's a String, try construct new value
        // using the defined type.
        if (tableValue instanceof String) {
            try {
                tableValue =
                    Utils.createObjectFromString(getClassName(e.getFirstRow()), // type
                    (String)tableValue);// value
            } catch (Throwable ex) {
                popupAndLog(ex,"tableChanged",
                            Messages.PROBLEM_SETTING_ATTRIBUTE);
            }
        }
        final String attributeName = getValueName(e.getFirstRow());
        final Attribute attribute =
              new Attribute(attributeName,tableValue);
        setAttribute(attribute, "tableChanged");
    }
}
 
Example #23
Source Project: pgptool   Author: pgptool   File: HistoryQuickSearchView.java    License: GNU General Public License v3.0 5 votes vote down vote up
private DecryptionDialogParameters getSelectedRow() {
	int row = table.getSelectedRow();
	if (row < 0) {
		return null;
	}

	// NOTE: This is a internal convention that by columnIndex -1 we mean
	// object itself
	TableModel tableModel = pm.getRowsTableModel().getValue();
	if (tableModel == null) {
		return null;
	}
	return (DecryptionDialogParameters) tableModel.getValueAt(row, -1);
}
 
Example #24
Source Project: jdal   Author: chelu   File: AnnotationFormatTableCellRenderer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
		int row, int column) {
	
	Class<?> clazz = table.getColumnClass(column);
	if (Number.class.isAssignableFrom(clazz)) {
		TableModel tableModel = table.getModel();
		if (tableModel instanceof ListTableModel) {
			ListTableModel listTableModel = (ListTableModel) tableModel;
			Class<?> modelClass = ((ListTableModel) tableModel).getModelClass();
			String propertyName = listTableModel.getPropertyName(column);
			Printer<Object> printer = (Printer<Object>) FormatUtils.getPrinter(modelClass, propertyName);
			if (printer != null) {
				value = printer.print(value, Locale.getDefault());
				JLabel label  = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
				label.setHorizontalAlignment(JLabel.RIGHT);
				return label;
			}
		}
	}
	TableCellRenderer renderer = table.getDefaultRenderer(clazz);
	
	return renderer != null ? 
			renderer.getTableCellRendererComponent(
					table, value, isSelected, hasFocus, row, column) :
				null;
}
 
Example #25
Source Project: scelight   Author: icza   File: RepListComp.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed( final ActionEvent event ) {
 if ( !Utils.checkEmailSettings() )
  return;
 int[] rows = table.getSelectedModelRows();
 final List< Path > repList = new ArrayList< >();
 final TableModel model = table.getModel();
 for ( final int row : rows )
  repList.add( (Path) model.getValueAt( row, fileColIdx ) );
 new SendEmailDialog( "Send Replays via Email", repList, null );
}
 
Example #26
Source Project: openAGV   Author: tcrct   File: AttributesTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
  TableModel tableModel = getModel();
  Object value = tableModel.getValueAt(row, column);
  TableCellRenderer renderer = getDefaultRenderer(value.getClass());

  return renderer;
}
 
Example #27
Source Project: orbit-image-analysis   Author: mstritt   File: MetaTable.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void listMetas(List<RawMeta> metaList) {
    //List<RawMeta> metaList = DAORawMeta.LoadRawMetasByRawDataFile(rdf.getRawDataFileId());
    // append with metas from rawData
    //List<RawMeta> rdMetas = DAORawMeta.LoadRawMetasByRawData(rdf.getRawDataId());
    //for (RawMeta rm : rdMetas) {
    //	rm.setName("Container."+rm.getName());
    //}
    //metaList.addAll(rdMetas);
    List<ListWithName<RawMeta>> metaHash = RawMetaListBuilder.buildRawMetaHash(metaList);
    this.removeAll();
    int cnt = 0;
    for (final ListWithName<RawMeta> pGroup : metaHash) {

        Object[][] tableData = new Object[pGroup.getList().size()][2];
        for (int i = 0; i < pGroup.getList().size(); i++) {
            cnt++;
            RawMeta rm = pGroup.getList().get(i);
            tableData[i][0] = rm;
            tableData[i][1] = rm.getValueFormatted();
        }
        final TableModel tm = new MyEditableTableModel(tableData, tableHeader);
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                final JTable table = new JTable(tm);
                if (OrbitUtils.DARKUI)
                    table.getColumnModel().getColumn(0).setCellRenderer(new MyMetaTableCellRendererSubstance());
                else table.getColumnModel().getColumn(0).setCellRenderer(new MyMetaTableCellRendererNimbus());
                table.getColumnModel().getColumn(1).setCellEditor(new MetaCellEditor());
                MetaTable.this.add(pGroup.getName(), table);
            }
        });

    }
}
 
Example #28
Source Project: pentaho-reporting   Author: pentaho   File: TestFormulaContext.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a formula context using the given model for references.
 *
 * @param model     The table model to use
 * @param guessType if <code>resolveReferenceType</code> should guess the type of the reference or return a type
 *                  <code>Any</code>.
 */
public TestFormulaContext( final TableModel model, final boolean guessType ) {
  formulaContext = new DefaultFormulaContext
    ( LibFormulaBoot.getInstance().getGlobalConfig(), Locale.US, TimeZone.getDefault() );
  this.model = model;
  useGuessType = guessType;
  this.typeRegistry = new DefaultTypeRegistry();
  this.typeRegistry.initialize( this );
}
 
Example #29
Source Project: pentaho-reporting   Author: pentaho   File: TableJFreeChartDemo.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
private TableModel createTableModel()
{
  final Object[][] data = new Object[12 * 5][];
  final int[] votes = new int[5];
  for (int i = 0; i < 12; i++)
  {
    final Integer year = new Integer(1995 + i);
    votes[0] = (int) (Math.random() * 200);
    votes[1] = (int) (Math.random() * 50);
    votes[2] = (int) (Math.random() * 100);
    votes[3] = (int) (Math.random() * 50);
    votes[4] = (int) (Math.random() * 100);

    final JFreeChart chart = createChart(year.intValue(), votes);

    data[i * 5] = new Object[]{
        year, "Java", new Integer(votes[0]), chart
    };
    data[i * 5 + 1] = new Object[]{
        year, "Visual Basic", new Integer(votes[1]), chart
    };
    data[i * 5 + 2] = new Object[]{
        year, "C/C++", new Integer(votes[2]), chart
    };
    data[i * 5 + 3] = new Object[]{
        year, "PHP", new Integer(votes[3]), chart
    };
    data[i * 5 + 4] = new Object[]{
        year, "Perl", new Integer(votes[4]), chart
    };

  }

  final String[] colNames = {
      "year", "language", "votes", "chart"
  };

  return new DefaultTableModel(data, colNames);
}
 
Example #30
Source Project: netbeans   Author: apache   File: JWSCustomizerPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void appletParamsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_appletParamsButtonActionPerformed

    List<Map<String,String>> origProps = jwsProps.getAppletParamsProperties();
    List<Map<String,String>> props = copyList(origProps);
    TableModel appletParamsTableModel = new JWSProjectProperties.PropertiesTableModel(props, JWSProjectProperties.appletParamsSuffixes, appletParamsColumnNames);
    JPanel panel = new AppletParametersPanel((PropertiesTableModel) appletParamsTableModel, jwsProps.appletWidthDocument, jwsProps.appletHeightDocument);
    DialogDescriptor dialogDesc = new DialogDescriptor(panel, NbBundle.getMessage(JWSCustomizerPanel.class, "TITLE_AppletParameters"), true, null); //NOI18N
    Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDesc);
    dialog.setVisible(true);
    if (dialogDesc.getValue() == DialogDescriptor.OK_OPTION) {
        jwsProps.setAppletParamsProperties(props);
    }
    dialog.dispose();

}