use of javax.swing.table.AbstractTableModel in project jdk8u_jdk by JetBrains.
the class bug6777378 method main.
public static void main(String[] args) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
Robot robot = new Robot();
robot.setAutoDelay(20);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
} catch (Exception e) {
e.printStackTrace();
}
JTable table = new JTable(new AbstractTableModel() {
public int getRowCount() {
return 10;
}
public int getColumnCount() {
return 10;
}
public Object getValueAt(int rowIndex, int columnIndex) {
return "" + rowIndex + " " + columnIndex;
}
});
header = new JTableHeader(table.getColumnModel());
header.setToolTipText("hello");
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(header);
frame.setSize(300, 300);
frame.setVisible(true);
}
});
toolkit.realSync();
Point point = header.getLocationOnScreen();
robot.mouseMove(point.x + 20, point.y + 50);
robot.mouseMove(point.x + 30, point.y + 50);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
use of javax.swing.table.AbstractTableModel in project jabref by JabRef.
the class IntegrityCheckAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
IntegrityCheck check = new IntegrityCheck(frame.getCurrentBasePanel().getBibDatabaseContext(), Globals.prefs.getFileDirectoryPreferences(), Globals.prefs.getBibtexKeyPatternPreferences(), Globals.journalAbbreviationLoader.getRepository(Globals.prefs.getJournalAbbreviationPreferences()));
List<IntegrityMessage> messages = check.checkBibtexDatabase();
if (messages.isEmpty()) {
JOptionPane.showMessageDialog(frame.getCurrentBasePanel(), Localization.lang("No problems found."));
} else {
Map<String, Boolean> showMessage = new HashMap<>();
// prepare data model
Object[][] model = new Object[messages.size()][4];
int i = 0;
for (IntegrityMessage message : messages) {
model[i][0] = message.getEntry().getId();
model[i][1] = message.getEntry().getCiteKeyOptional().orElse("");
model[i][2] = message.getFieldName();
model[i][3] = message.getMessage();
showMessage.put(message.getMessage(), true);
i++;
}
// construct view
JTable table = new JTable(model, new Object[] { "ID", Localization.lang("BibTeX key"), Localization.lang("Field"), Localization.lang("Message") });
// hide IDs
TableColumnModel columnModel = table.getColumnModel();
columnModel.removeColumn(columnModel.getColumn(0));
RowFilter<Object, Object> filter = new RowFilter<Object, Object>() {
@Override
public boolean include(Entry<?, ?> entry) {
return showMessage.get(entry.getStringValue(3));
}
};
TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel());
sorter.setRowFilter(filter);
table.setRowSorter(sorter);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setDefaultEditor(Object.class, null);
ListSelectionModel selectionModel = table.getSelectionModel();
selectionModel.addListSelectionListener(event -> {
if (!event.getValueIsAdjusting()) {
try {
String entryId = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][0];
String fieldName = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][2];
frame.getCurrentBasePanel().editEntryByIdAndFocusField(entryId, fieldName);
} catch (ArrayIndexOutOfBoundsException exception) {
}
}
});
// BibTeX key
table.getColumnModel().getColumn(0).setPreferredWidth(100);
// field name
table.getColumnModel().getColumn(1).setPreferredWidth(60);
// message
table.getColumnModel().getColumn(2).setPreferredWidth(400);
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
JScrollPane scrollPane = new JScrollPane(table);
String title = Localization.lang("%0 problem(s) found", String.valueOf(messages.size()));
JDialog dialog = new JDialog(frame, title, false);
JPopupMenu menu = new JPopupMenu();
for (String messageString : showMessage.keySet()) {
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(messageString, true);
menuItem.addActionListener(event -> {
showMessage.put(messageString, menuItem.isSelected());
((AbstractTableModel) table.getModel()).fireTableDataChanged();
});
menu.add(menuItem);
}
JButton menuButton = new JButton(Localization.lang("Filter"));
menuButton.addActionListener(entry -> menu.show(menuButton, 0, menuButton.getHeight()));
FormBuilder builder = FormBuilder.create().layout(new FormLayout("fill:pref:grow", "fill:pref:grow, 2dlu, pref"));
builder.add(scrollPane).xy(1, 1);
builder.add(menuButton).xy(1, 3, "c, b");
dialog.add(builder.getPanel());
dialog.setSize(600, 600);
// show view
dialog.setVisible(true);
}
}
use of javax.swing.table.AbstractTableModel in project processdash by dtuma.
the class TaskScheduleDialog method handleEvNodeChanged.
private void handleEvNodeChanged(EVTask node) {
try {
TreePath tp = new TreePath(node.getPath());
int row = treeTable.getTree().getRowForPath(tp);
if (row != -1) {
AbstractTableModel model = (AbstractTableModel) treeTable.getModel();
model.fireTableChanged(new TableModelEvent(model, row));
}
} catch (Exception e) {
}
}
use of javax.swing.table.AbstractTableModel in project CodenameOne by codenameone.
the class L10nEditor method initTable.
private void initTable() {
bundleTable.setModel(new AbstractTableModel() {
public int getRowCount() {
return keys.size();
}
public int getColumnCount() {
return 1 + localeList.size();
}
public boolean isCellEditable(int row, int col) {
boolean b = col != 0;
if (b) {
String s = (String) getValueAt(row, col);
return s == null || !s.contains("\n");
}
return b;
}
public String getColumnName(int columnIndex) {
if (columnIndex == 0) {
return "Key";
}
return (String) localeList.get(columnIndex - 1);
}
public Object getValueAt(int rowIndex, int columnIndex) {
if (columnIndex == 0) {
return keys.get(rowIndex);
}
Hashtable h = res.getL10N(localeName, (String) localeList.get(columnIndex - 1));
return h.get(keys.get(rowIndex));
}
public void setValueAt(Object val, int rowIndex, int columnIndex) {
res.setModified();
if (columnIndex == 0) {
if (!keys.contains(val)) {
// ...
}
return;
}
// Hashtable h = (Hashtable)bundle.get(localeList.get(columnIndex - 1));
// h.put(keys.get(rowIndex), val);
String currentKey = (String) keys.get(rowIndex);
res.setLocaleProperty(localeName, (String) localeList.get(columnIndex - 1), currentKey, val);
if (currentKey.equals("@im")) {
StringTokenizer tok = new StringTokenizer((String) val, "|");
boolean modified = false;
while (tok.hasMoreTokens()) {
String currentIm = tok.nextToken();
if ("ABC".equals(currentIm) || "123".equals(currentIm) || "Abc".equals(currentIm) || "abc".equals(currentIm)) {
continue;
}
String prop = "@im-" + currentIm;
if (!keys.contains(prop)) {
keys.add(prop);
for (Object locale : localeList) {
res.setLocaleProperty(localeName, (String) locale, prop, "");
}
modified = true;
}
}
if (modified) {
fireTableDataChanged();
}
return;
}
if (currentKey.equals("@vkb")) {
boolean modified = false;
StringTokenizer tok = new StringTokenizer((String) val, "|");
while (tok.hasMoreTokens()) {
String currentIm = tok.nextToken();
if ("ABC".equals(currentIm) || "123".equals(currentIm) || ".,123".equals(currentIm) || ".,?".equals(currentIm)) {
continue;
}
String prop = "@vkb-" + currentIm;
if (!keys.contains(prop)) {
keys.add(prop);
for (Object locale : localeList) {
res.setLocaleProperty(localeName, (String) locale, prop, "");
}
modified = true;
}
}
if (modified) {
fireTableDataChanged();
}
}
}
});
bundleTable.setDefaultRenderer(Object.class, new SwingRenderer() {
private JCheckBox chk = new JCheckBox();
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (column > 0) {
// constant value
String key = (String) keys.get(row);
if (key.startsWith("@")) {
if (key.equalsIgnoreCase("@rtl")) {
chk.setSelected(value != null && "true".equalsIgnoreCase(value.toString()));
updateComponentSelectedState(chk, isSelected, table, row, column, hasFocus);
return chk;
}
if (key.startsWith("@vkb") || key.startsWith("@im")) {
JButton b = new JButton("...");
updateComponentSelectedState(b, isSelected, table, row, column, hasFocus);
return b;
}
}
}
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
});
bundleTable.setDefaultEditor(Object.class, new DefaultCellEditor(new JTextField()) {
private Object currentValue;
String editedKey;
private DefaultCellEditor standardEditor = new DefaultCellEditor(new JTextField());
private DefaultCellEditor buttonEditor = new DefaultCellEditor(new JTextField()) {
private JButton button = new JButton("...");
{
button.setBorderPainted(false);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (editedKey.equals("@vkb") || editedKey.equals("@im")) {
currentValue = editInputModeOrder((String) currentValue, editedKey.equals("@vkb"));
fireEditingStoppedExt();
return;
}
/*if(editedKey.startsWith("@vkb")) {
VKBEditor v = new VKBEditor(button, editedKey.substring(5), (String)currentValue);
currentValue = v.getValue();
fireEditingStoppedExt();
return;
}*/
if (editedKey.startsWith("@im")) {
currentValue = editTextFieldInputMode((String) currentValue);
fireEditingStoppedExt();
return;
}
}
});
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
editedKey = (String) keys.get(row);
return button;
}
};
private DefaultCellEditor checkBoxEditor = new DefaultCellEditor(new JCheckBox()) {
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
return super.getTableCellEditorComponent(table, new Boolean("true".equalsIgnoreCase((String) value)), isSelected, row, column);
}
public Object getCellEditorValue() {
Boolean b = (Boolean) super.getCellEditorValue();
if (b.booleanValue()) {
return "true";
}
return "false";
}
};
private TableCellEditor current = standardEditor;
{
buttonEditor.setClickCountToStart(1);
checkBoxEditor.setClickCountToStart(1);
}
private void updateEditor(int row) {
// constant value
final String key = (String) keys.get(row);
if (key.startsWith("@")) {
if (key.equalsIgnoreCase("@rtl")) {
current = checkBoxEditor;
return;
}
if (key.startsWith("@vkb") || key.startsWith("@im")) {
current = buttonEditor;
return;
}
}
current = standardEditor;
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
updateEditor(row);
currentValue = value;
return current.getTableCellEditorComponent(table, value, isSelected, row, column);
}
public void fireEditingStoppedExt() {
fireEditingStopped();
}
public Object getCellEditorValue() {
if (current == buttonEditor) {
return currentValue;
}
return current.getCellEditorValue();
}
public boolean stopCellEditing() {
return current.stopCellEditing();
}
public void cancelCellEditing() {
current.cancelCellEditing();
}
public void addCellEditorListener(CellEditorListener l) {
current.addCellEditorListener(l);
super.addCellEditorListener(l);
}
public void removeCellEditorListener(CellEditorListener l) {
current.removeCellEditorListener(l);
super.removeCellEditorListener(l);
}
public boolean isCellEditable(EventObject anEvent) {
return current.isCellEditable(anEvent);
}
public boolean shouldSelectCell(EventObject anEvent) {
return current.shouldSelectCell(anEvent);
}
});
locales.setModel(new DefaultComboBoxModel(localeList.toArray()));
removeLocale.setEnabled(localeList.size() > 1);
}
use of javax.swing.table.AbstractTableModel in project vcell by virtualcell.
the class FRAPEstimationPanel_NotUsed method initTable.
private void initTable() {
TableModel tableModel = new AbstractTableModel() {
public String getColumnName(int col) {
return FRAP_ESTIMATE_COLUMN_NAMES[col].toString();
}
public int getRowCount() {
return FRAPParameterEstimateEnum.values().length;
}
public int getColumnCount() {
return FRAP_ESTIMATE_COLUMN_NAMES.length;
}
public Object getValueAt(int row, int col) {
if (col == PARAMETER_TYPE_COLUMN) {
return FRAPParameterEstimateEnum.values()[row].parameterTypeName;
} else if (col == UNIT_COLUMN) {
return FRAPParameterEstimateEnum.values()[row].unit;
}
return FRAPParameterEstimateEnum.values()[row].value;
}
public boolean isCellEditable(int row, int col) {
return false;
}
public void setValueAt(Object value, int row, int col) {
if (col == PARAMETER_TYPE_COLUMN || col == UNIT_COLUMN) {
throw new IllegalArgumentException("Can't update 'Parameter Type' or 'Unit' column");
}
FRAPParameterEstimateEnum.values()[row].value = (Double) value;
fireTableCellUpdated(row, col);
}
};
table.setModel(tableModel);
table.getTableHeader().getColumnModel().getColumn(UNIT_COLUMN).setMaxWidth(50);
}
Aggregations