return 465;
}
@Override
protected JComponent getDialogContent() {
final DCPanel formPanel = new DCPanel();
int row = 0;
WidgetUtils.addToGridBag(DCLabel.bright("Dictionary name:"), formPanel, 0, row);
WidgetUtils.addToGridBag(_nameTextField, formPanel, 1, row);
row++;
WidgetUtils.addToGridBag(DCLabel.bright("Filename:"), formPanel, 0, row);
WidgetUtils.addToGridBag(_filenameTextField, formPanel, 1, row);
row++;
WidgetUtils.addToGridBag(DCLabel.bright("Character encoding:"), formPanel, 0, row);
WidgetUtils.addToGridBag(_encodingComboBox, formPanel, 1, row);
row++;
final JButton saveButton = WidgetFactory.createButton("Save dictionary", "images/model/dictionary.png");
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String name = _nameTextField.getText();
if (StringUtils.isNullOrEmpty(name)) {
JOptionPane.showMessageDialog(TextFileDictionaryDialog.this,
"Please fill out the name of the dictionary");
return;
}
String filename = _filenameTextField.getFilename();
if (StringUtils.isNullOrEmpty(filename)) {
JOptionPane.showMessageDialog(TextFileDictionaryDialog.this,
"Please fill out the filename or select a file using the 'Browse' button");
return;
}
String encoding = (String) _encodingComboBox.getSelectedItem();
if (StringUtils.isNullOrEmpty(filename)) {
JOptionPane.showMessageDialog(TextFileDictionaryDialog.this, "Please select a character encoding");
return;
}
TextFileDictionary dict = new TextFileDictionary(name, filename, encoding);
if (_originalDictionary != null) {
_catalog.removeDictionary(_originalDictionary);
}
_catalog.addDictionary(dict);
TextFileDictionaryDialog.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 DCLabel descriptionLabel = DCLabel
.brightMultiLine("A text file dictionary is a dictionary based on a text file containing values separated by linebreaks.");
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);
return mainPanel;
}