return 465;
}
@Override
protected JComponent getDialogContent() {
final DCPanel formPanel = new DCPanel();
int row = 0;
WidgetUtils.addToGridBag(DCLabel.bright("String pattern name"), formPanel, 0, row);
WidgetUtils.addToGridBag(_expressionNameField, formPanel, 1, row);
row++;
WidgetUtils.addToGridBag(DCLabel.bright("Expression:"), formPanel, 0, row);
_expressionField.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
checkInputFields();
}
public void insertUpdate(DocumentEvent e) {
checkInputFields();
}
public void removeUpdate(DocumentEvent e) {
checkInputFields();
}
});
WidgetUtils.addToGridBag(_expressionField, formPanel, 1, row);
_resetButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
_expressionField.setText(_expressionString);
}
});
WidgetUtils.addToGridBag(_resetButton, formPanel, 2, row);
row++;
_saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String expressionName = _expressionNameField.getText();
if (StringUtils.isNullOrEmpty(expressionName)) {
JOptionPane.showMessageDialog(RegexStringPatternDialog.this,
"Please fill out the name of the regular expression");
return;
}
String expression = _expressionField.getText();
if (StringUtils.isNullOrEmpty(expression)) {
JOptionPane.showMessageDialog(RegexStringPatternDialog.this, "Please fill out the regular expression");
return;
}
if (_regexStringPattern != null && _catalog.containsStringPattern(_regexStringPattern.getName())) {
_catalog.removeStringPattern(_catalog.getStringPattern(_regexStringPattern.getName()));
}
RegexStringPattern regexStringPattern = new RegexStringPattern(expressionName, expression, true);
_regexStringPattern = regexStringPattern;
_catalog.addStringPattern(regexStringPattern);
RegexStringPatternDialog.this.dispose();
}
});
final DCPanel buttonPanel = new DCPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
buttonPanel.add(_saveButton);
WidgetUtils.addToGridBag(buttonPanel, formPanel, 0, row, 2, 1);
final DCPanel testitPanel = new DCPanel();
testitPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
_errorLabel = DCLabel.bright("");
WidgetUtils.addToGridBag(_errorLabel, testitPanel, 0, row);
row++;
JLabel testInputLabel = DCLabel.bright("Test input");
testInputLabel.setIcon(imageManager.getImageIcon("images/actions/test-pattern.png"));
testInputLabel.setFont(WidgetUtils.FONT_HEADER1);
WidgetUtils.addToGridBag(testInputLabel, testitPanel, 0, row);
_inputFields = new ArrayList<JTextField>(NUM_TEST_FIELDS);
_statusLabels = new ArrayList<JLabel>(NUM_TEST_FIELDS);
for (int i = 0; i < NUM_TEST_FIELDS; i++) {
final int index = i;
JTextField inputField = WidgetFactory.createTextField("Test Input");
inputField.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
checkInputField(index);
}
public void insertUpdate(DocumentEvent e) {
checkInputField(index);
}
public void removeUpdate(DocumentEvent e) {
checkInputField(index);
}
});
// inputField.setPreferredSize(d);
WidgetUtils.addToGridBag(inputField, testitPanel, 0, 4 + i);
JLabel statusLabel = new JLabel();
WidgetUtils.addToGridBag(statusLabel, testitPanel, 1, 4 + i);
_inputFields.add(inputField);
_statusLabels.add(statusLabel);
}
final DCLabel descriptionLabel = DCLabel
.brightMultiLine("A regex (regular expression) is a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. The registered regexes can be used to identify certain types of strings and validate their pattern-correctness.");
descriptionLabel.setBorder(new EmptyBorder(10, 10, 10, 20));
descriptionLabel.setPreferredSize(new Dimension(300, 100));
final DCPanel mainPanel = new DCPanel();
mainPanel.setLayout(new VerticalLayout(4));
mainPanel.add(descriptionLabel);
mainPanel.add(formPanel);
mainPanel.add(testitPanel);
return mainPanel;
}