use of javax.swing.event.TableModelListener in project libgdx by libgdx.
the class EditorPanel method setValue.
protected static void setValue(DefaultTableModel tableModel, Object value, int row, int column) {
TableModelListener[] listeners = tableModel.getTableModelListeners();
TableModelListener listener = null;
if (listeners != null && listeners.length > 0) {
listener = listeners[0];
tableModel.removeTableModelListener(listener);
}
tableModel.setValueAt(value, row, column);
if (listener != null)
tableModel.addTableModelListener(listener);
}
use of javax.swing.event.TableModelListener in project libgdx by libgdx.
the class EffectPanel method initializeComponents.
private void initializeComponents() {
setLayout(new GridBagLayout());
{
JPanel sideButtons = new JPanel(new GridBagLayout());
add(sideButtons, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
{
JButton newButton = new JButton("New");
sideButtons.add(newButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
newButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
newEmitter("Untitled", true);
}
});
}
{
JButton newButton = new JButton("Duplicate");
sideButtons.add(newButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
newButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
duplicateEmitter();
}
});
}
{
JButton deleteButton = new JButton("Delete");
sideButtons.add(deleteButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
deleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
deleteEmitter();
}
});
}
{
sideButtons.add(new JSeparator(JSeparator.HORIZONTAL), new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
}
{
JButton saveButton = new JButton("Save");
sideButtons.add(saveButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
saveEffect();
}
});
}
{
JButton openButton = new JButton("Open");
sideButtons.add(openButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
openButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
openEffect(false);
}
});
}
{
JButton mergeButton = new JButton("Merge");
sideButtons.add(mergeButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
mergeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
openEffect(true);
}
});
}
{
JButton upButton = new JButton("Up");
sideButtons.add(upButton, new GridBagConstraints(0, -1, 1, 1, 0, 1, GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
upButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
move(-1);
}
});
}
{
JButton downButton = new JButton("Down");
sideButtons.add(downButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
downButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
move(1);
}
});
}
}
{
JScrollPane scroll = new JScrollPane();
add(scroll, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 6), 0, 0));
{
emitterTable = new JTable() {
public Class getColumnClass(int column) {
return column == 1 ? Boolean.class : super.getColumnClass(column);
}
};
emitterTable.getTableHeader().setReorderingAllowed(false);
emitterTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scroll.setViewportView(emitterTable);
emitterTableModel = new DefaultTableModel(new String[0][0], new String[] { "Emitter", "" });
emitterTable.setModel(emitterTableModel);
emitterTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent event) {
if (event.getValueIsAdjusting())
return;
emitterSelected();
}
});
emitterTableModel.addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent event) {
if (event.getColumn() != 1)
return;
emitterChecked(event.getFirstRow(), (Boolean) emitterTable.getValueAt(event.getFirstRow(), 1));
}
});
}
}
}
use of javax.swing.event.TableModelListener in project smile by haifengl.
the class PageTableModel method initToolBar.
/**
* Initialize context menu and toolbar.
*/
private void initToolBar() {
toolbar = new JToolBar();
toolbar.add(new Button(firstPageAction));
toolbar.add(new Button(pageUpAction));
toolbar.add(new Button(pageDownAction));
toolbar.add(new Button(lastPageAction));
toolbar.addSeparator();
toolbar.add(pageSizeLabel);
toolbar.add(pageSizeField);
pageSizeField.setText(Integer.toString(getPageSize()));
pageSizeField.setHorizontalAlignment(JTextField.RIGHT);
pageSizeField.setAction(pageSizeAction);
pageSizeField.setMaximumSize(pageSizeField.getPreferredSize());
toolbar.addSeparator();
totalRowCountLabel.setText(String.format(totalRowCountLabelFormat, getRealRowCount()));
toolbar.add(totalRowCountLabel);
toolbar.add(pageField);
pageField.setText(Integer.toString(getPage() + 1));
pageField.setHorizontalAlignment(JTextField.RIGHT);
pageField.setAction(gotoPageAction);
pageField.setMaximumSize(pageField.getPreferredSize());
pageCountLabel.setText(String.format(pageCountLabelFormat, getPageCount()));
toolbar.add(pageCountLabel);
setActionEnabled();
TableModelListener listener = new TableModelListener() {
@Override
public void tableChanged(TableModelEvent tme) {
if (tme.getType() == TableModelEvent.INSERT || tme.getType() == TableModelEvent.DELETE) {
if (getPage() >= getPageCount()) {
setPage(getPageCount() - 1);
}
totalRowCountLabel.setText(String.format(totalRowCountLabelFormat, getRealRowCount()));
pageField.setText(Integer.toString(getPage() + 1));
pageCountLabel.setText(String.format(pageCountLabelFormat, getPageCount()));
}
}
};
addTableModelListener(listener);
}
use of javax.swing.event.TableModelListener in project gephi by gephi.
the class ImportCSVUIVisualPanel1 method refreshPreviewTable.
public void refreshPreviewTable() {
if (selectedFile != null && selectedFile.exists()) {
try {
CsvReader reader = new CsvReader(new FileInputStream(selectedFile), getSelectedSeparator(), getSelectedCharset());
reader.setTrimWhitespace(false);
String[] headers;
try {
reader.readHeaders();
headers = reader.getHeaders();
} catch (Exception ex) {
//Some charsets can be problematic with unreal columns lenght. Don't show table when there are problems
headers = new String[0];
}
columnCount = headers.length;
//Check for repeated column names:
Set<String> columnNamesSet = new HashSet<>();
hasColumnNamesRepeated = false;
hasSourceNodeColumn = false;
hasTargetNodeColumn = false;
int sourceColumnIndex = 0, targetColumnIndex = 0, currentColumn = 0;
for (String header : headers) {
if (header.equalsIgnoreCase("source")) {
hasSourceNodeColumn = true;
sourceColumnIndex = currentColumn;
}
if (header.equalsIgnoreCase("target")) {
hasTargetNodeColumn = true;
targetColumnIndex = currentColumn;
}
if (columnNamesSet.contains(header)) {
hasColumnNamesRepeated = true;
break;
}
columnNamesSet.add(header);
currentColumn++;
}
ArrayList<String[]> records = new ArrayList<>();
hasRowsMissingSourcesOrTargets = false;
ImportCSVUIWizardAction.Mode mode = getMode();
if (columnCount > 0) {
String[] currentRecord;
while (reader.readRecord()) {
int recordColumnCount = reader.getColumnCount();
currentRecord = new String[recordColumnCount];
for (int i = 0; i < currentRecord.length; i++) {
currentRecord[i] = reader.get(i);
}
// Search for missing source or target columns for edges table
if (mode == ImportCSVUIWizardAction.Mode.EDGES_TABLE) {
if (recordColumnCount < sourceColumnIndex || currentRecord[sourceColumnIndex].trim().isEmpty() || recordColumnCount < targetColumnIndex || currentRecord[targetColumnIndex].trim().isEmpty()) {
hasRowsMissingSourcesOrTargets = true;
}
}
if (records.size() < MAX_ROWS_PREVIEW) {
records.add(currentRecord);
}
}
}
reader.close();
final String[] columnNames = headers;
final String[][] values = records.toArray(new String[0][]);
previewTable.setModel(new TableModel() {
@Override
public int getRowCount() {
return values.length;
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
@Override
public Class<?> getColumnClass(int columnIndex) {
return String.class;
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
if (values[rowIndex].length > columnIndex) {
return values[rowIndex][columnIndex];
} else {
return null;
}
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
}
@Override
public void addTableModelListener(TableModelListener l) {
}
@Override
public void removeTableModelListener(TableModelListener l) {
}
});
} catch (FileNotFoundException ex) {
Exceptions.printStackTrace(ex);
} catch (IOException ex) {
JOptionPane.showMessageDialog(this, getMessage("ImportCSVUIVisualPanel1.validation.error"), getMessage("ImportCSVUIVisualPanel1.validation.file-permissions-error"), JOptionPane.ERROR_MESSAGE);
}
}
wizard1.fireChangeEvent();
//To fire validation panel messages.
pathTextField.setText(pathTextField.getText());
}
use of javax.swing.event.TableModelListener in project knime-core by knime.
the class JavaSnippetNodeDialog method createPanel.
private JPanel createPanel(final boolean isPreview) {
final JPanel p = new JPanel(new BorderLayout());
final JComponent snippet = createSnippetPanel();
final JComponent colsAndVars = createColsAndVarsPanel();
final JPanel centerPanel = new JPanel(new GridLayout(0, 1));
final JSplitPane centerSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
centerSplitPane.setLeftComponent(colsAndVars);
centerSplitPane.setRightComponent(snippet);
// colsAndVars expands to 0.3, the snippet to 0.7
centerSplitPane.setResizeWeight(0.3);
m_inFieldsTable = createInFieldsTable();
m_outFieldsTable = createOutFieldsTable();
final TableModelListener tableModelListener = e -> {
if (e.getType() != TableModelEvent.DELETE) {
// Updating completion can result in a small delay,
// so we don't update when fields are removed.
updateAutocompletion();
}
};
m_inFieldsTable.getTable().getModel().addTableModelListener(tableModelListener);
m_outFieldsTable.getTable().getModel().addTableModelListener(tableModelListener);
// use split pane for fields
m_inFieldsTable.setBorder(BorderFactory.createTitledBorder("Input"));
m_outFieldsTable.setBorder(BorderFactory.createTitledBorder("Output"));
final JSplitPane fieldsPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
fieldsPane.setTopComponent(m_inFieldsTable);
fieldsPane.setBottomComponent(m_outFieldsTable);
fieldsPane.setOneTouchExpandable(true);
final JSplitPane mainSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
mainSplitPane.setTopComponent(centerSplitPane);
// minimize size of tables at the bottom
fieldsPane.setPreferredSize(fieldsPane.getMinimumSize());
mainSplitPane.setBottomComponent(fieldsPane);
mainSplitPane.setOneTouchExpandable(true);
// snippet gets more space, table with in/out gets less extra space
mainSplitPane.setResizeWeight(0.7);
centerPanel.add(mainSplitPane);
p.add(centerPanel, BorderLayout.CENTER);
final JPanel templateInfoPanel = createTemplateInfoPanel(isPreview);
p.add(templateInfoPanel, BorderLayout.NORTH);
final JPanel optionsPanel = createOptionsPanel();
if (optionsPanel != null) {
p.add(optionsPanel, BorderLayout.SOUTH);
}
return p;
}
Aggregations