use of javax.swing.table.TableCellRenderer in project intellij-community by JetBrains.
the class GuiUtils method enableComponent.
private static void enableComponent(Component component, boolean enabled) {
if (component.isEnabled() == enabled)
return;
component.setEnabled(enabled);
if (component instanceof JPanel) {
final Border border = ((JPanel) component).getBorder();
if (border instanceof TitledBorder) {
Color color = enabled ? component.getForeground() : UIUtil.getInactiveTextColor();
((TitledBorder) border).setTitleColor(color);
}
} else if (component instanceof JLabel) {
Color color = UIUtil.getInactiveTextColor();
if (color == null)
color = component.getForeground();
@NonNls String changeColorString = "<font color=#" + colorToHex(color) + ">";
final JLabel label = (JLabel) component;
@NonNls String text = label.getText();
if (text != null && text.startsWith("<html>")) {
if (StringUtil.startsWithConcatenation(text, "<html>", changeColorString) && enabled) {
text = "<html>" + text.substring(("<html>" + changeColorString).length());
} else if (!StringUtil.startsWithConcatenation(text, "<html>", changeColorString) && !enabled) {
text = "<html>" + changeColorString + text.substring("<html>".length());
}
label.setText(text);
}
} else if (component instanceof JTable) {
TableColumnModel columnModel = ((JTable) component).getColumnModel();
for (int i = 0; i < columnModel.getColumnCount(); i++) {
TableCellRenderer cellRenderer = columnModel.getColumn(0).getCellRenderer();
if (cellRenderer instanceof Component) {
enableComponent((Component) cellRenderer, enabled);
}
}
}
}
use of javax.swing.table.TableCellRenderer in project intellij-community by JetBrains.
the class StripeTable method paintHeader.
private static void paintHeader(Graphics g, JTable table, int x, int width) {
TableCellRenderer renderer = table.getTableHeader().getDefaultRenderer();
Component component = renderer.getTableCellRendererComponent(table, "", false, false, -1, 2);
component.setBounds(0, 0, width, table.getTableHeader().getHeight());
((JComponent) component).setOpaque(false);
RENDER_PANE.paintComponent(g, component, null, x, 0, width, table.getTableHeader().getHeight(), true);
}
use of javax.swing.table.TableCellRenderer in project intellij-community by JetBrains.
the class AbstractTableView method getColumnPreferredWidth.
protected int getColumnPreferredWidth(final int i) {
final ColumnInfo columnInfo = myTableModel.getColumnInfos()[i];
final java.util.List items = myTableModel.getItems();
int width = -1;
for (int j = 0; j < items.size(); j++) {
final TableCellRenderer renderer = myTable.getCellRenderer(j, i);
final Component component = renderer.getTableCellRendererComponent(myTable, columnInfo.valueOf(items.get(j)), false, false, j, i);
width = Math.max(width, component.getPreferredSize().width);
}
return width;
}
use of javax.swing.table.TableCellRenderer in project adempiere by adempiere.
the class VHeaderRenderer method getTableCellRendererComponent.
/**
* Get TableCell RendererComponent
* @param table
* @param value
* @param isSelected
* @param hasFocus
* @param row
* @param column
* @return Button
*/
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
// indicator for invisible column
Icon icon = null;
m_table = table;
m_column = column;
if (table instanceof CTable) {
CTable cTable = (CTable) table;
if (cTable.getSortColumn() == table.convertColumnIndexToModel(column)) {
icon = cTable.isSortAscending() ? Env.getImageIcon2("uparrow") : Env.getImageIcon2("downarrow");
}
}
/**
* If VHeaderRenderer is just created with display type as argument
*/
if (m_label == null && m_button == null && m_check == null) {
TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer();
Component headerComponent = headerRenderer == null ? null : headerRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (value == null)
headerComponent.setPreferredSize(new Dimension(0, 0));
if (headerComponent instanceof JLabel) {
((JLabel) headerComponent).setIcon(icon);
((JLabel) headerComponent).setHorizontalTextPosition(SwingConstants.LEADING);
}
return headerComponent;
}
/**
* If VHeaderRenderer has been created with GridField as argument
*/
if (m_button == null && m_check == null) {
m_label.setHorizontalAlignment(m_alignment);
if (value == null)
m_label.setPreferredSize(new Dimension(0, 0));
else {
m_label.setText(value.toString());
if (prefWidth != null && prefWidth > 0) {
m_label.setPreferredSize(new Dimension(prefWidth, m_label.getHeight()));
m_label.setToolTipText(value.toString());
}
}
m_label.setIcon(icon);
m_label.setHorizontalTextPosition(SwingConstants.LEADING);
return m_label;
}
/**
* VHeaderRenderer has been created with multi-selection true
*/
if (m_button == null) {
if (table != null) {
JTableHeader header = table.getTableHeader();
if (header != null) {
m_check.setForeground(header.getForeground());
m_check.setBackground(header.getBackground());
m_check.setBorder(new MatteBorder(0, 0, 1, 1, AdempierePLAF.getSecondary1()));
m_check.setFont(header.getFont());
m_check.setBorderPainted(true);
m_check.setEnabled(true);
header.addMouseListener(this);
}
}
return m_check;
} else {
/**
* VHeaderRenderer has been created with no argument
*/
if (value == null) {
m_button.setPreferredSize(new Dimension(0, 0));
return m_button;
}
m_button.setText(value.toString());
m_button.setIcon(icon);
m_button.setHorizontalTextPosition(SwingConstants.LEADING);
return m_button;
}
}
use of javax.swing.table.TableCellRenderer in project adempiere by adempiere.
the class Find method initFindAdvanced.
// addSelectionColumn
/**
* Init Find GridController
*/
private void initFindAdvanced() {
log.config("");
advancedTable.setModel(new DefaultTableModel(0, 7));
advancedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
advancedTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
advancedTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
TableCellRenderer renderer = new ProxyRenderer(advancedTable.getDefaultRenderer(Object.class));
advancedTable.setDefaultRenderer(Object.class, renderer);
InputMap im = advancedTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
final Action tabAction = advancedTable.getActionMap().get(im.get(tab));
Action tabActionWrapper = new AbstractAction() {
private static final long serialVersionUID = -6868476640719619801L;
public void actionPerformed(ActionEvent e) {
tabAction.actionPerformed(e);
JTable table = (JTable) e.getSource();
table.requestFocusInWindow();
}
};
advancedTable.getActionMap().put(im.get(tab), tabActionWrapper);
KeyStroke shiftTab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK);
final Action shiftTabAction = advancedTable.getActionMap().get(im.get(shiftTab));
Action shiftTabActionWrapper = new AbstractAction() {
private static final long serialVersionUID = 5493691483070046620L;
public void actionPerformed(ActionEvent e) {
shiftTabAction.actionPerformed(e);
JTable table = (JTable) e.getSource();
table.requestFocusInWindow();
}
};
advancedTable.getActionMap().put(im.get(shiftTab), shiftTabActionWrapper);
// 0 = Columns
ArrayList<ValueNamePair> items = new ArrayList<ValueNamePair>();
for (int c = 0; c < m_findFields.length; c++) {
GridField field = m_findFields[c];
String columnName = field.getColumnName();
String header = field.getHeader();
if (header == null || header.length() == 0) {
header = Msg.translate(Env.getCtx(), columnName);
if (header == null || header.length() == 0)
continue;
}
if (field.isKey())
header += (" (ID)");
ValueNamePair pp = new ValueNamePair(columnName, header);
// System.out.println(pp + " = " + field);
items.add(pp);
}
columnValueNamePairs = new ValueNamePair[items.size()];
items.toArray(columnValueNamePairs);
// sort alpha
Arrays.sort(columnValueNamePairs);
columns = new CComboBox(columnValueNamePairs);
columns.addActionListener(this);
TableColumn tc = advancedTable.getColumnModel().getColumn(INDEX_COLUMNNAME);
tc.setPreferredWidth(120);
FindCellEditor dce = new FindCellEditor(columns);
dce.addCellEditorListener(new CellEditorListener() {
public void editingCanceled(ChangeEvent ce) {
}
public void editingStopped(ChangeEvent ce) {
int col = advancedTable.getSelectedColumn();
int row = advancedTable.getSelectedRow();
if (col == INDEX_COLUMNNAME && row >= 0) {
advancedTable.setValueAt(null, row, INDEX_VALUE);
advancedTable.setValueAt(null, row, INDEX_VALUE2);
}
}
});
tc.setCellEditor(dce);
tc.setHeaderValue(Msg.translate(Env.getCtx(), "AD_Column_ID"));
// 0 = And/Or
andOr = new CComboBox(new String[] { "", Msg.getMsg(Env.getCtx(), "AND"), Msg.getMsg(Env.getCtx(), "OR") });
tc = advancedTable.getColumnModel().getColumn(INDEX_ANDOR);
tc.setPreferredWidth(45);
dce = new FindCellEditor(andOr);
tc.setCellEditor(dce);
tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "And/Or"));
// 1 = Left Bracket
leftBrackets = new CComboBox(new String[] { "", "(", "((", "(((" });
tc = advancedTable.getColumnModel().getColumn(INDEX_LEFTBRACKET);
tc.setPreferredWidth(25);
dce = new FindCellEditor(leftBrackets);
tc.setCellEditor(dce);
tc.setHeaderValue("(");
// 3 = Operators
operators = new CComboBox(MQuery.OPERATORS);
tc = advancedTable.getColumnModel().getColumn(INDEX_OPERATOR);
tc.setPreferredWidth(55);
dce = new FindCellEditor(operators);
tc.setCellEditor(dce);
tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "Operator"));
// 4 = QueryValue
tc = advancedTable.getColumnModel().getColumn(INDEX_VALUE);
FindValueEditor fve = new FindValueEditor(this, false);
tc.setCellEditor(fve);
tc.setPreferredWidth(120);
tc.setCellRenderer(new ProxyRenderer(new FindValueRenderer(this, false)));
tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "QueryValue"));
// 5 = QueryValue2
tc = advancedTable.getColumnModel().getColumn(INDEX_VALUE2);
tc.setPreferredWidth(120);
fve = new FindValueEditor(this, true);
tc.setCellEditor(fve);
tc.setCellRenderer(new ProxyRenderer(new FindValueRenderer(this, false)));
tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "QueryValue2"));
// 6 = Right Bracket
rightBrackets = new CComboBox(new String[] { "", ")", "))", ")))" });
tc = advancedTable.getColumnModel().getColumn(INDEX_RIGHTBRACKET);
tc.setPreferredWidth(25);
dce = new FindCellEditor(rightBrackets);
tc.setCellEditor(dce);
tc.setHeaderValue(")");
// phib: disabled auto-completion as it causes date fields to have to be entered twice
//AutoCompletion.enable(columns);
//AutoCompletion.enable(operators);
//user query
refreshUserQueries();
}
Aggregations