001: package net.sourceforge.squirrel_sql.plugins.graph;
002:
003: import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
004: import net.sourceforge.squirrel_sql.fw.util.StringManager;
005: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
006:
007: import javax.swing.*;
008: import java.awt.event.*;
009:
010: public class GraphSelectionDialogController {
011: private static final StringManager s_stringMgr = StringManagerFactory
012: .getStringManager(GraphSelectionDialogController.class);
013:
014: GraphSelectionDialog _dlg;
015: private boolean _ok;
016: private GraphController m_selectedController;
017: private JFrame _parent;
018:
019: public GraphSelectionDialogController(
020: GraphController[] controllers, JFrame parent) {
021: _parent = parent;
022: _dlg = new GraphSelectionDialog(parent);
023: _dlg.lstControllers.setListData(controllers);
024: _dlg.lstControllers.setSelectedIndex(0);
025:
026: _dlg.lstControllers.addMouseListener(new MouseAdapter() {
027: public void mouseClicked(MouseEvent e) {
028: onMouseClickedList(e);
029: }
030: });
031:
032: _dlg.btnOK.addActionListener(new ActionListener() {
033: public void actionPerformed(ActionEvent e) {
034: onOK();
035: }
036: });
037:
038: _dlg.btnCreateNewGraph.addActionListener(new ActionListener() {
039: public void actionPerformed(ActionEvent e) {
040: onCreateNewGraph();
041: }
042: });
043:
044: _dlg.btnCancel.addActionListener(new ActionListener() {
045: public void actionPerformed(ActionEvent e) {
046: onCancel();
047: }
048: });
049:
050: AbstractAction closeAction = new AbstractAction() {
051: public void actionPerformed(ActionEvent actionEvent) {
052: close();
053: }
054: };
055: KeyStroke escapeStroke = KeyStroke.getKeyStroke(
056: KeyEvent.VK_ESCAPE, 0);
057: _dlg.getRootPane().getInputMap(
058: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
059: escapeStroke, "CloseAction");
060: _dlg.getRootPane().getInputMap(
061: JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke,
062: "CloseAction");
063: _dlg.getRootPane().getInputMap(JComponent.WHEN_FOCUSED).put(
064: escapeStroke, "CloseAction");
065: _dlg.getRootPane().getActionMap().put("CloseAction",
066: closeAction);
067:
068: }
069:
070: private void onCancel() {
071: close();
072: }
073:
074: private void close() {
075: _dlg.setVisible(false);
076: _dlg.dispose();
077: }
078:
079: private void onCreateNewGraph() {
080: // getSelectedController() == null means: Create a new Graph
081: _ok = true;
082: close();
083: }
084:
085: private void onOK() {
086: processSelection();
087: }
088:
089: private void onMouseClickedList(MouseEvent e) {
090: if (1 < e.getClickCount()) {
091: processSelection();
092: }
093: }
094:
095: private void processSelection() {
096: if (null == _dlg.lstControllers.getSelectedValue()) {
097: // i18n[graph.noSel=No selection]
098: JOptionPane.showMessageDialog(_parent, s_stringMgr
099: .getString("graph.noSel"));
100: return;
101: }
102:
103: close();
104:
105: _ok = true;
106: if (_dlg.lstControllers.getSelectedValue() instanceof GraphController) {
107: m_selectedController = (GraphController) _dlg.lstControllers
108: .getSelectedValue();
109: }
110: }
111:
112: public void doModal() {
113: GUIUtils.centerWithinParent(_dlg);
114: _dlg.setVisible(true);
115: }
116:
117: public boolean isOK() {
118: return _ok;
119: }
120:
121: /**
122: * getSelectedController() == null means: Create a new Graph
123: */
124: public GraphController getSelectedController() {
125: return m_selectedController;
126: }
127:
128: }
|