import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.*;
import javax.swing.border.Border;
-import javax.swing.event.ListSelectionEvent;
-import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableColumn;
import java.awt.*;
import java.awt.event.*;
for (Edge e : patternEdges) {
managedNode.addEdge(e);
}
+
String timeout = (String) managedNode.getProperty(timeoutPropertyName);
if (timeout != null) {
managedNode.addEdge(timeoutEdge != null ? timeoutEdge : new TimeoutEdge(managedNode));
}
managedNode.setProperty(EdgeConditionModel.EDGE_PROPERTY, explicitEdges);
+
return timeoutEdge;
}
*/
public static class PatternTable extends JPanel {
private JTable table;
- private EdgeConditionModel edgeModel;
private JButton newButton, deleteButton;
public PatternTable(EdgeConditionModel edgeModel) {
super(new BorderLayout());
- this.edgeModel = edgeModel;
-
// set up table
table = new JTable(edgeModel);
final JScrollPane jsp = GUI.createScrollPane(table, new Dimension(300, 150));
// set up "New" and "Delete" buttons for editing the table
JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
- deleteButton = new CmdButton(new Runnable() {
- public void run() {
- if (!table.isEditing() || table.getCellEditor().stopCellEditing()) {
- edgeModel.deleteRows(table.getSelectedRows());
- }
+ deleteButton = new CmdButton(() -> {
+ if (!table.isEditing() || table.getCellEditor().stopCellEditing()) {
+ edgeModel.deleteRows(table.getSelectedRows());
}
}, com.clt.diamant.Resources.getString("Delete"));
+
buttons.add(deleteButton);
deleteButton.setEnabled(table.getSelectedRow() >= 0);
- table.getSelectionModel().addListSelectionListener(
- new ListSelectionListener() {
- public void valueChanged(ListSelectionEvent e) {
- deleteButton.setEnabled(table.getSelectedRow() >= 0);
- }
+
+ table.getSelectionModel().addListSelectionListener((e) -> {
+ deleteButton.setEnabled(table.getSelectedRow() >= 0);
});
- newButton = new CmdButton(new Runnable() {
- public void run() {
- if (!table.isEditing() || table.getCellEditor().stopCellEditing()) {
- int row = edgeModel.addRow();
- table.setRowSelectionInterval(row, row);
- }
+ newButton = new CmdButton(() -> {
+ if (!table.isEditing() || table.getCellEditor().stopCellEditing()) {
+ int row = edgeModel.addRow();
+ table.setRowSelectionInterval(row, row);
}
}, com.clt.diamant.Resources.getString("New"));
+
buttons.add(newButton);
add(buttons, BorderLayout.SOUTH);
JTabbedPane tabs = GUI.createTabbedPane();
-// final JPanel p = new JPanel(new BorderLayout());
- final EdgeConditionModel edgeModel = new EdgeConditionModel(this,
- properties, com.clt.diamant.Resources
- .getString("InputPatterns"));
+ final EdgeConditionModel edgeModel
+ = new EdgeConditionModel(this, properties,
+ com.clt.diamant.Resources.getString("InputPatterns"));
final PatternTable patternTable = new PatternTable(edgeModel);
grammars.addAll(definedGrammars);
}
- final JComboBox language = NodePropertiesDialog.createComboBox(
- properties, LANGUAGE, languages);
+ final JComboBox language = NodePropertiesDialog.createComboBox(properties, LANGUAGE, languages);
final JComboBox grammar = new JComboBox(grammars);
grammar.setRenderer(new com.clt.gui.ComponentRenderer());
* button to open a new window to edit the selected grammar/grammar
* expression
*/
- final JButton editGrammar = new CmdButton(com.clt.diamant.Resources
- .getString("Edit"), () -> {
+ final JButton editGrammar = new CmdButton(com.clt.diamant.Resources.getString("Edit"), () -> {
Object selection = grammar.getSelectedItem();
if (selection instanceof Grammar) {
Grammar g = (Grammar) selection;
properties.putIfAbsent(GRAMMAR_EXPRESSION, "");
editGrammar.setText(Resources.getString("EditExpression"));
editGrammar.setEnabled(true);
- edgeModel.setName(Resources
- .getString("InputPatterns"));
+ edgeModel.setName(Resources.getString("InputPatterns"));
// editGrammar.doClick();
}
});
header.add(language, gbc);
patternTable.setHeader(header);
-
-// p.add(header, BorderLayout.NORTH); // AK
-
-/*
-
- final JTable table = new JTable(edgeModel);
- final JScrollPane jsp = GUI.createScrollPane(table, new Dimension(300,
- 150));
- // table.setRowSelectionAllowed(false);
- // table.setColumnSelectionAllowed(false);
- table.getTableHeader().setReorderingAllowed(false);
-
- TableRowDragger.addDragHandler(table);
- TableColumn column = table.getColumnModel().getColumn(0);
- // column.setCellEditor(new TableCellEditor()
- column.setCellRenderer(new TextRenderer() {
-
- @Override
- public Component getTableCellRendererComponent(JTable table,
- Object value, boolean isSelected, boolean hasFocus,
- int row, int column) {
-
- JLabel label = (JLabel) super.getTableCellRendererComponent(
- table, value, isSelected, hasFocus, row, column);
- if (!table.isEnabled()) {
- label.setForeground(jsp.getBackground());
- label.setBackground(jsp.getBackground());
- } else if (!edgeModel.isCellEditable(row, column)) {
- label.setForeground(Color.lightGray);
- }
- return label;
- }
- });
-
- JPanel center = new JPanel(new BorderLayout());
- center.add(jsp, BorderLayout.CENTER);
- p.add(center, BorderLayout.CENTER);
-
- JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
-
- final JButton deleteButton = new CmdButton(() -> {
- if (!table.isEditing() || table.getCellEditor().stopCellEditing()) {
- edgeModel.deleteRows(table.getSelectedRows());
- }
- }, com.clt.diamant.Resources.getString("Delete"));
- buttons.add(deleteButton);
- deleteButton.setEnabled(table.getSelectedRow() >= 0);
- table.getSelectionModel().addListSelectionListener(
- evt -> deleteButton.setEnabled(table.getSelectedRow() >= 0));
- final JButton newButton = new CmdButton(() -> {
- if (!table.isEditing() || table.getCellEditor().stopCellEditing()) {
- int row = edgeModel.addRow();
- table.setRowSelectionInterval(row, row);
- }
- }, com.clt.diamant.Resources.getString("New"));
- buttons.add(newButton);
-
- p.add(buttons, BorderLayout.SOUTH);
- p.add(Box.createHorizontalStrut(8), BorderLayout.WEST);
- p.add(Box.createHorizontalStrut(8), BorderLayout.EAST);
-*/
-
+
final JTextField tf = NodePropertiesDialog.createTextField(properties, TIMEOUT);
final JCheckBox timeout = new JCheckBox(com.clt.diamant.Resources
final JButton test = new JButton(Resources.getString("TryRecognition"));
test.addActionListener(evt -> new Thread(() -> {
patternTable.stopCellEditing();
-// if (table.getCellEditor() != null) {
-// table.getCellEditor().stopCellEditing();
-// }
RootPaneContainer rpc = GUI.getParent(test, RootPaneContainer.class);
try {
recognizeExec(rpc.getLayeredPane(),
throw exn;
// return null; // null is the proper return value for timeouts
} catch (ExecutionException exn) {
- throw new NodeExecutionException(this, Resources
- .getString("RecognizerError")
- + ".", exn.getCause());
+ throw new NodeExecutionException(this,
+ Resources.getString("RecognizerError") + ".",
+ exn.getCause());
} catch (Throwable exn) {
- throw new NodeExecutionException(this, Resources
- .getString("RecognizerError")
- + ".", exn);
+ throw new NodeExecutionException(this,
+ Resources.getString("RecognizerError") + ".",
+ exn);
}
return mr;
}
import com.clt.diamant.graph.Edge;
import com.clt.diamant.graph.InputHandler;
import com.clt.diamant.graph.Node;
+import com.clt.diamant.graph.nodes.AbstractInputNode;
import com.clt.gui.table.MovableRowsTableModel;
+/**
+ * A model for the outgoing edges of a node. Objects of this class are
+ * meant to be constructed as part of the {@link Node#createEditorComponent(java.util.Map) }
+ * method of a specialized Node class, and can then be used to update
+ * the actual outgoing edges of a node using an {@link AbstractInputNode.EdgeManager}.<p>
+ *
+ * One crucial detail is that the "properties" argument that is passed to the constructor
+ * of the EdgeConditionModel must be the "properties" argument which is passed to the
+ * createEditorComponent method. This is because createEditorComponent is called with
+ * a copy of the Node's original properties, so that changes can be undone if the
+ * properties window is closed by clicking the "Cancel" button.
+ *
+ *
+ * @author koller
+ */
public class EdgeConditionModel extends AbstractTableModel implements MovableRowsTableModel {
public static final String EDGE_PROPERTY = "tmp_edges";
this.addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent e) {
- EdgeConditionModel.this.p.put(EdgeConditionModel.EDGE_PROPERTY,
- EdgeConditionModel.this.v);
+ EdgeConditionModel.this.p.put(EdgeConditionModel.EDGE_PROPERTY, EdgeConditionModel.this.v);
}
});
}
public void setName(String name) {
this.name = name;
- this
- .fireTableChanged(new TableModelEvent(this, TableModelEvent.HEADER_ROW));
+ this.fireTableChanged(new TableModelEvent(this, TableModelEvent.HEADER_ROW));
}
public void showPreAndPostfix(boolean showPreAndPostfix) {
this.v.add(new Edge(this.source, null, ""));
int row = this.getPrefixSize() + this.v.size() - 1;
this.fireTableRowsInserted(row, row);
+
return row;
}