use of javax.swing.table.DefaultTableCellRenderer in project mafscaling by vimsh.
the class ThrottleMaps method createDataTable.
protected JTable createDataTable(JPanel panel, String tableName, int colCount, int rowCount, int gridx, int gridy, boolean isOriginalTable, boolean extendRows, boolean extendCols) {
final JTable table = new JTable();
ExcelAdapter excelAdapter = new ExcelAdapter() {
protected void onPaste(JTable table, boolean extendRows, boolean extendCols) {
if (table.getSelectedRows() == null || table.getSelectedRows().length == 0 || table.getSelectedColumns() == null || table.getSelectedColumns().length == 0)
return;
if (table.getSelectedRows()[0] != 0 || table.getSelectedColumns()[0] != 0) {
JOptionPane.showMessageDialog(null, "Please paste copied table into the first cell", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
super.onPaste(table, extendRows, extendCols);
validateTable(table);
clearRunTables();
}
protected void onPasteVertical(JTable table, boolean extendRows, boolean extendCols) {
if (table.getSelectedRows() == null || table.getSelectedRows().length == 0 || table.getSelectedColumns() == null || table.getSelectedColumns().length == 0)
return;
if (table.getSelectedRows()[0] != 0 || table.getSelectedColumns()[0] != 0) {
JOptionPane.showMessageDialog(null, "Please paste copied table into the first cell", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
super.onPasteVertical(table, extendRows, extendCols);
validateTable(table);
clearRunTables();
}
};
if (tableName == origTableName)
excelAdapter.addTable(table, false, true, false, false, true, false, true, extendRows, extendCols);
else
excelAdapter.addTable(table, false, true, false, false, true, true, false, extendRows, extendCols);
excelAdapterList.add(excelAdapter);
DefaultTableColumnModel tableModel = new DefaultTableColumnModel();
final TableColumn tableColumn = new TableColumn(0, colCount * ColumnWidth);
tableColumn.setHeaderValue(tableName);
tableModel.addColumn(tableColumn);
JTableHeader lblTableHeaderName = table.getTableHeader();
lblTableHeaderName.setColumnModel(tableModel);
lblTableHeaderName.setReorderingAllowed(false);
DefaultTableCellRenderer headerRenderer = (DefaultTableCellRenderer) lblTableHeaderName.getDefaultRenderer();
headerRenderer.setHorizontalAlignment(SwingConstants.LEFT);
GridBagConstraints gbc_lblTableName = new GridBagConstraints();
gbc_lblTableName.insets = new Insets(0, 0, 0, 3);
gbc_lblTableName.anchor = GridBagConstraints.NORTHWEST;
gbc_lblTableName.fill = GridBagConstraints.HORIZONTAL;
gbc_lblTableName.gridx = gridx;
gbc_lblTableName.gridy = gridy;
panel.add(lblTableHeaderName, gbc_lblTableName);
table.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
tableColumn.setWidth(table.getWidth());
}
});
if (tableName == newTableName) {
table.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
if (event.getButton() == MouseEvent.BUTTON1) {
if (Utils.isTableEmpty(origTable) || Utils.isTableEmpty(newTable) || Utils.isTableEmpty(corrTable)) {
return;
}
JTable eventTable = (JTable) event.getSource();
int colIdx = eventTable.getSelectedColumn();
int rowIdx = eventTable.getSelectedRow();
ArrayList<Double> t3xAxisArray = new ArrayList<Double>();
for (int i = 1; i < corrTable.getColumnCount(); ++i) t3xAxisArray.add(Double.valueOf(corrTable.getValueAt(0, i).toString()));
ArrayList<Double> t1yAxisArray = new ArrayList<Double>();
for (int i = 0; i < origTable.getRowCount(); ++i) t1yAxisArray.add(Double.valueOf(origTable.getValueAt(i, 0).toString()));
ArrayList<Double> t3yAxisArray = new ArrayList<Double>();
for (int i = 1; i < corrTable.getRowCount(); ++i) t3yAxisArray.add(Double.valueOf(corrTable.getValueAt(i, 0).toString()));
if (colIdx > 0 && rowIdx >= 0) {
try {
calculate(t3xAxisArray, t1yAxisArray, t3yAxisArray, rowIdx, colIdx, true);
} catch (Exception e) {
}
}
}
}
});
}
Utils.addTableHeaderHighlight(table);
table.setName(tableName);
table.getTableHeader().setReorderingAllowed(false);
table.setColumnSelectionAllowed(true);
table.setCellSelectionEnabled(true);
table.setBorder(new LineBorder(new Color(0, 0, 0)));
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.setModel(new DefaultTableModel(rowCount, colCount));
table.putClientProperty("terminateEditOnFocusLost", true);
Utils.initializeTable(table, ColumnWidth);
formatTable(table);
GridBagConstraints gbc_table = new GridBagConstraints();
gbc_table.insets = new Insets(0, 0, 0, 3);
gbc_table.anchor = GridBagConstraints.NORTHWEST;
gbc_table.gridx = gridx;
gbc_table.gridy = gridy + 1;
panel.add(table, gbc_table);
return table;
}
use of javax.swing.table.DefaultTableCellRenderer in project Spark by igniterealtime.
the class CertificatesManagerSettingsPanel method addCertTableToPanel.
public void addCertTableToPanel() {
certControll.loadKeyStores();
certControll.createTableModel();
certTable = new JTable(certControll.getTableModel()) {
@Override
public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int columnIndex) {
JComponent component = (JComponent) super.prepareRenderer(renderer, rowIndex, columnIndex);
if (isRowSelected(rowIndex)) {
component.setBackground(getBackground());
component.setForeground(Color.black);
}
Object value = getModel().getValueAt(convertRowIndexToModel(rowIndex), columnIndex);
DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
centerRenderer.setHorizontalAlignment(JLabel.CENTER);
this.getColumnModel().getColumn(1).setCellRenderer(centerRenderer);
if (value.equals(Res.getString("cert.valid"))) {
component.setBackground(Color.green);
} else if (value.equals(Res.getString("cert.expired")) || value.equals(Res.getString("cert.not.valid.yet")) || value.equals(Res.getString("cert.revoked"))) {
component.setBackground(Color.red);
} else {
component.setBackground(Color.white);
}
return component;
}
};
scrollPane = new JScrollPane(certTable);
certTable.setFillsViewportHeight(true);
certTable.setAutoCreateRowSorter(true);
certControll.resizeColumnWidth(certTable);
certTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
}
use of javax.swing.table.DefaultTableCellRenderer in project mage by magefree.
the class CardSelector method initListViewComponents.
private void initListViewComponents() {
mainTable = new JTable();
mainModel = new TableModel();
mainModel.addListeners(mainTable);
mainTable.setModel(mainModel);
mainTable.setForeground(Color.white);
DefaultTableCellRenderer myRenderer = (DefaultTableCellRenderer) mainTable.getDefaultRenderer(String.class);
myRenderer.setBackground(new Color(0, 0, 0, 100));
mainTable.getColumnModel().getColumn(0).setMaxWidth(0);
mainTable.getColumnModel().getColumn(0).setPreferredWidth(10);
mainTable.getColumnModel().getColumn(1).setPreferredWidth(110);
mainTable.getColumnModel().getColumn(2).setPreferredWidth(90);
mainTable.getColumnModel().getColumn(3).setPreferredWidth(50);
mainTable.getColumnModel().getColumn(4).setPreferredWidth(170);
mainTable.getColumnModel().getColumn(5).setPreferredWidth(30);
mainTable.getColumnModel().getColumn(6).setPreferredWidth(15);
mainTable.getColumnModel().getColumn(7).setPreferredWidth(15);
// new mana render (svg support)
mainTable.getColumnModel().getColumn(mainModel.COLUMN_INDEX_COST).setCellRenderer(new ManaSymbolsCellRenderer());
mainTable.getColumnModel().getColumn(mainModel.COLUMN_INDEX_COLOR_IDENTITY).setCellRenderer(new ManaSymbolsCellRenderer());
// mainTable.setToolTipText(cardSelectorScrollPane.getToolTipText());
cardSelectorScrollPane.setViewportView(mainTable);
mainTable.setOpaque(false);
cbSortBy.setEnabled(false);
chkPiles.setEnabled(false);
chkNames.setSelected("true".equals(MageFrame.getPreferences().get(KEY_DECK_EDITOR_SEARCH_NAMES, "true")));
chkTypes.setSelected("true".equals(MageFrame.getPreferences().get(KEY_DECK_EDITOR_SEARCH_TYPES, "true")));
chkRules.setSelected("true".equals(MageFrame.getPreferences().get(KEY_DECK_EDITOR_SEARCH_RULES, "true")));
chkUnique.setSelected("true".equals(MageFrame.getPreferences().get(KEY_DECK_EDITOR_SEARCH_UNIQUE, "false")));
mainTable.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if ((e.getClickCount() & 1) == 0 && (e.getClickCount() > 0) && !e.isConsumed()) {
// double clicks and repeated double clicks
e.consume();
if (e.isAltDown()) {
jButtonAddToSideboardActionPerformed(null);
} else {
jButtonAddToMainActionPerformed(null);
}
}
}
});
jToggleCardView.setToolTipText(jToggleCardView.getToolTipText() + " (works only up to " + CardGrid.MAX_IMAGES + " cards).");
}
use of javax.swing.table.DefaultTableCellRenderer in project mage by magefree.
the class ManaSymbolsCellRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
// get table text cell settings
DefaultTableCellRenderer baseRenderer = (DefaultTableCellRenderer) table.getDefaultRenderer(String.class);
JLabel baseComp = (JLabel) baseRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
// apply settings to mana panel from parent
renderPanel.setOpaque(baseComp.isOpaque());
renderPanel.setForeground(CardRendererUtils.copyColor(baseComp.getForeground()));
renderPanel.setBackground(CardRendererUtils.copyColor(baseComp.getBackground()));
renderPanel.setBorder(baseComp.getBorder());
// icons size with margin
int symbolWidth = GUISizeHelper.symbolTableSize;
int symbolHorizontalMargin = 2;
// create each mana symbol as child label
String manaCost = (String) value;
renderPanel.removeAll();
renderPanel.setLayout(new BoxLayout(renderPanel, BoxLayout.X_AXIS));
if (manaCost != null) {
StringTokenizer tok = new StringTokenizer(manaCost, " ");
while (tok.hasMoreTokens()) {
String symbol = tok.nextToken();
JLabel symbolLabel = new JLabel();
symbolLabel.setFont(GUISizeHelper.tableFont);
symbolLabel.setBorder(new EmptyBorder(0, symbolHorizontalMargin, 0, 0));
BufferedImage image = ManaSymbols.getSizedManaSymbol(symbol, symbolWidth);
if (image != null) {
// icon
symbolLabel.setIcon(new ImageIcon(image));
} else {
// TODO: add auto-size text from ManaSymbols.draw
if (symbol.equals(CardInfo.SPLIT_MANA_SEPARATOR_SHORT)) {
symbolLabel.setText(CardInfo.SPLIT_MANA_SEPARATOR_RENDER);
} else {
symbolLabel.setText("{" + symbol + "}");
}
symbolLabel.setOpaque(false);
symbolLabel.setForeground(baseComp.getForeground());
symbolLabel.setBackground(baseComp.getBackground());
}
renderPanel.add(symbolLabel);
}
}
return renderPanel;
}
Aggregations