New Jide License
[indepmod/experimental.git] / IndependentModeler / src / cz / cvut / promod / gui / dialogs / simpleTextFieldDialog / SimpleTextFieldDialog.java
blobd4dc8ba55a38330ccb026c8212a3079b43e06eff
1 package cz.cvut.promod.gui.dialogs.simpleTextFieldDialog;
3 import com.jgoodies.binding.adapter.Bindings;
4 import com.jgoodies.binding.PresentationModel;
6 import javax.swing.*;
7 import java.awt.event.ActionListener;
8 import java.awt.event.ActionEvent;
9 import java.awt.event.KeyEvent;
10 import java.awt.*;
12 /**
13 * ProMod, master thesis project
14 * User: Petr Zverina, petr.zverina@gmail.com
15 * Date: 23:49:43, 23.10.2009
17 * A implementation of SimpleTextFieldDialog.
19 public class SimpleTextFieldDialog extends SimpleTextFieldDialogView{
21 private final SimpleTextFieldDialogModel model = new SimpleTextFieldDialogModel();
23 private final PresentationModel<SimpleTextFieldDialogModel> presentation = new PresentationModel<SimpleTextFieldDialogModel>(model);
25 private final SimpleTextFieldDialogExecutor executor;
28 public SimpleTextFieldDialog(final String title,
29 final String textLabelString,
30 final String inputTextFieldText,
31 final String confirmButtonText,
32 final String cancelButtonString,
33 final SimpleTextFieldDialogExecutor executor,
34 final Component locateRelativeToComponent,
35 final boolean modal){
37 if(locateRelativeToComponent != null){
38 setLocationRelativeTo(locateRelativeToComponent);
41 //init texts
42 setTitle(title);
44 textLabel.setText(textLabelString);
45 confirmButton.setText(confirmButtonText);
46 cancelButton.setText(cancelButtonString);
48 this.executor = executor;
50 initBinding();
52 inputTextField.setText(inputTextFieldText);
54 setModal(modal);
56 initEventHandling();
58 getRootPane().setDefaultButton(confirmButton);
60 setVisible(true);
63 private void initBinding() {
64 Bindings.bind(inputTextField, presentation.getModel(SimpleTextFieldDialogModel.PROPERTY_SUBFOLDER_NAME));
67 private void initEventHandling() {
68 cancelButton.addActionListener(new ActionListener(){
69 public void actionPerformed(ActionEvent e) {
70 disposeDialog();
72 });
74 confirmButton.addActionListener(new ActionListener(){
75 public void actionPerformed(ActionEvent e) {
76 final String result = executor.execute(model.getInputText());
78 if(result == null){
79 disposeDialog();
80 } else {
81 errorLabel.setText(result);
84 });
86 getRootPane().registerKeyboardAction(new ActionListener(){
87 public void actionPerformed(ActionEvent actionEvent) {
88 disposeDialog();
91 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
92 JComponent.WHEN_IN_FOCUSED_WINDOW);
95 private void disposeDialog(){
96 setVisible(false);
97 dispose();