use of javax.swing.table.TableCellEditor in project pcgen by PCGen.
the class CharacterHPDialog method initComponents.
private void initComponents() {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
JTable table = new JTable(tableModel) {
@Override
public TableCellEditor getCellEditor(int row, int column) {
if (column == 5) {
//TODO: the max roll should be calculated in a different manner
String hd = levels.getClassTaken(levels.getElementAt(row)).getHD();
int max = NumberUtils.toInt(hd);
return new IntegerEditor(1, max);
} else {
return super.getCellEditor(row, column);
}
}
};
table.setDefaultRenderer(JButton.class, new Renderer());
table.setDefaultEditor(JButton.class, new Editor());
table.setCellSelectionEnabled(false);
table.setRowHeight(new IntegerEditor(1, 10).getPreferredSize().height);
JTableHeader header = table.getTableHeader();
header.setReorderingAllowed(false);
JScrollPane scrollPane = new JScrollPane(table);
pane.add(scrollPane, BorderLayout.CENTER);
Box box = Box.createHorizontalBox();
box.add(new JLabel("Total Hp:"));
box.add(Box.createHorizontalStrut(3));
final ReferenceListener<Integer> hpListener = new ReferenceListener<Integer>() {
@Override
public void referenceChanged(ReferenceEvent<Integer> e) {
totalHp.setText(e.getNewReference().toString());
}
};
ReferenceFacade<Integer> hpRef = character.getTotalHPRef();
totalHp.setText(hpRef.get().toString());
hpRef.addReferenceListener(hpListener);
box.add(totalHp);
box.add(Box.createHorizontalStrut(5));
JButton button = new JButton("Reroll All");
button.setActionCommand("Reroll");
button.addActionListener(this);
box.add(button);
box.add(Box.createHorizontalGlue());
button = new JButton("Close");
button.setActionCommand("Close");
button.addActionListener(this);
box.add(button);
pane.add(box, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
//Make sure to remove the listeners so that the garbage collector can
//dispose of this dialog and prevent a memory leak
levels.removeHitPointListener(tableModel);
character.getTotalHPRef().removeReferenceListener(hpListener);
}
});
Utility.installEscapeCloseOperation(this);
}
use of javax.swing.table.TableCellEditor in project jdk8u_jdk by JetBrains.
the class TableTest method main.
public static void main(String[] args) throws Exception {
KeyboardFocusManager.getCurrentKeyboardFocusManager();
System.setSecurityManager(new AppletSecurity());
JTable table = new JTable();
TableCellEditor de = table.getDefaultEditor(Double.class);
if (de == null) {
throw new RuntimeException("Table default editor is null");
}
}
use of javax.swing.table.TableCellEditor in project intellij-community by JetBrains.
the class UiUtils method editTableCell.
private static void editTableCell(final ListTable table, final int row, final int column) {
final ListSelectionModel selectionModel = table.getSelectionModel();
selectionModel.setSelectionInterval(row, row);
EventQueue.invokeLater(() -> {
final ListWrappingTableModel tableModel = table.getModel();
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(table, true);
});
final Rectangle rectangle = table.getCellRect(row, column, true);
table.scrollRectToVisible(rectangle);
table.editCellAt(row, column);
final TableCellEditor editor = table.getCellEditor();
final Component component = editor.getTableCellEditorComponent(table, tableModel.getValueAt(row, column), true, row, column);
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(component, true);
});
});
}
use of javax.swing.table.TableCellEditor in project intellij-community by JetBrains.
the class TableUtil method stopEditing.
public static void stopEditing(@NotNull JTable table) {
if (table.isEditing()) {
final TableCellEditor cellEditor = table.getCellEditor();
if (cellEditor != null) {
cellEditor.stopCellEditing();
}
int row = table.getSelectedRow();
int column = table.getSelectedColumn();
if (row >= 0 && column >= 0) {
TableCellEditor editor = table.getCellEditor(row, column);
if (editor != null) {
editor.stopCellEditing();
//Object value = editor.getCellEditorValue();
//
//table.setValueAt(value, row, column);
}
}
}
}
use of javax.swing.table.TableCellEditor in project intellij-community by JetBrains.
the class ExtractedSettingsDialog method buildExtractedSettingsTree.
protected JComponent buildExtractedSettingsTree() {
Collection<Value> unusedValues = ContainerUtil.newHashSet(myValues);
myRoot = new DefaultMutableTreeNode();
for (Map.Entry<LanguageCodeStyleSettingsProvider.SettingsType, Map<CodeStyleSettingPresentation.SettingsGroup, List<CodeStyleSettingPresentation>>> typeEntry : myNameProvider.mySettings.entrySet()) {
DefaultMutableTreeNode settingsNode = null;
for (Map.Entry<CodeStyleSettingPresentation.SettingsGroup, List<CodeStyleSettingPresentation>> groupEntry : typeEntry.getValue().entrySet()) {
CodeStyleSettingPresentation.SettingsGroup group = groupEntry.getKey();
List<CodeStyleSettingPresentation> representations = groupEntry.getValue();
List<CodeStyleSettingPresentation> children = ContainerUtil.emptyList();
DefaultMutableTreeNode groupNode = null;
if (group.name == null && !representations.isEmpty()) {
//there is a setting with name coinciding with group name
if (representations.size() > 1) {
children = representations.subList(1, representations.size());
}
CodeStyleSettingPresentation headRep = representations.get(0);
Value myValue = CodeStyleSettingsNameProvider.getValue(headRep, myValues);
if (myValue == null) {
//value was not found (was not selected)
groupNode = new SettingsTreeNode(headRep.getUiName());
} else {
groupNode = new SettingsTreeNode(headRep.getUiName());
groupNode.add(new SettingsTreeNode(headRep.getValueUiName(myValue.value), headRep, true, myValue));
unusedValues.remove(myValue);
}
} else {
children = representations;
}
for (CodeStyleSettingPresentation representation : children) {
Value myValue = CodeStyleSettingsNameProvider.getValue(representation, myValues);
if (myValue != null) {
if (groupNode == null) {
groupNode = new SettingsTreeNode(group.name);
}
groupNode.add(new SettingsTreeNode(representation.getValueUiName(myValue.value), representation, false, myValue));
unusedValues.remove(myValue);
}
}
if (groupNode != null && !groupNode.isLeaf()) {
if (settingsNode == null) {
settingsNode = new SettingsTreeNode(CodeStyleSettingsNameProvider.getSettingsTypeName(typeEntry.getKey()));
}
settingsNode.add(groupNode);
}
}
if (settingsNode != null) {
myRoot.add(settingsNode);
}
}
//TODO: for now, settings without UI presentation are not displayed. Do something about it.
//unusedValues = ContainerUtil.filter(unusedValues, new Condition<Value>(){
// @Override
// public boolean value(Value value) {
// return value.state == Value.STATE.SELECTED;
// }
//});
//
//DefaultMutableTreeNode unnamedNode = null;
//for (Value value: unusedValues) {
// if (unnamedNode == null) {
// unnamedNode = new SettingsTreeNode("Settings without UI representation");
// }
// unnamedNode.add(new SettingsTreeNode(value.value.toString(), null, false, value.name, value));
//}
//
//if (unnamedNode != null) {
// myRoot.add(unnamedNode);
//}
final ColumnInfo[] COLUMNS = new ColumnInfo[] { getTitleColumnInfo(), getValueColumnInfo() };
ListTreeTableModel model = new ListTreeTableModel(myRoot, COLUMNS);
final TreeTable treeTable = new TreeTable(model) {
@Override
public TreeTableCellRenderer createTableRenderer(TreeTableModel treeTableModel) {
TreeTableCellRenderer tableRenderer = super.createTableRenderer(treeTableModel);
UIUtil.setLineStyleAngled(tableRenderer);
tableRenderer.setRootVisible(false);
tableRenderer.setShowsRootHandles(true);
return tableRenderer;
}
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
TreePath treePath = getTree().getPathForRow(row);
if (treePath == null)
return super.getCellRenderer(row, column);
Object node = treePath.getLastPathComponent();
TableCellRenderer renderer = COLUMNS[column].getRenderer(node);
return renderer == null ? super.getCellRenderer(row, column) : renderer;
}
@Override
public TableCellEditor getCellEditor(int row, int column) {
TreePath treePath = getTree().getPathForRow(row);
if (treePath == null)
return super.getCellEditor(row, column);
Object node = treePath.getLastPathComponent();
TableCellEditor editor = COLUMNS[column].getEditor(node);
return editor == null ? super.getCellEditor(row, column) : editor;
}
};
new TreeTableSpeedSearch(treeTable).setComparator(new SpeedSearchComparator(false));
treeTable.setRootVisible(false);
final JTree tree = treeTable.getTree();
tree.setCellRenderer(myTitleRenderer);
tree.setShowsRootHandles(true);
treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
treeTable.setTableHeader(null);
TreeUtil.expandAll(tree);
treeTable.getColumnModel().getSelectionModel().setAnchorSelectionIndex(1);
treeTable.getColumnModel().getSelectionModel().setLeadSelectionIndex(1);
int maxWidth = tree.getPreferredScrollableViewportSize().width + 10;
final TableColumn titleColumn = treeTable.getColumnModel().getColumn(0);
titleColumn.setPreferredWidth(maxWidth);
titleColumn.setMinWidth(maxWidth);
titleColumn.setMaxWidth(maxWidth);
titleColumn.setResizable(false);
final Dimension valueSize = new JLabel(ApplicationBundle.message("option.table.sizing.text")).getPreferredSize();
treeTable.setPreferredScrollableViewportSize(new Dimension(maxWidth + valueSize.width + 10, 20));
treeTable.setBackground(UIUtil.getPanelBackground());
treeTable.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
final Dimension screenSize = treeTable.getToolkit().getScreenSize();
JBScrollPane scroller = new JBScrollPane(treeTable) {
@Override
public Dimension getMinimumSize() {
return super.getPreferredSize();
}
};
final Dimension preferredSize = new Dimension(Math.min(screenSize.width / 2, treeTable.getPreferredSize().width), Math.min(screenSize.height / 2, treeTable.getPreferredSize().height));
getRootPane().setPreferredSize(preferredSize);
return scroller;
}
Aggregations