01: package net.sourceforge.squirrel_sql.client.session.schemainfo;
02:
03: import net.sourceforge.squirrel_sql.client.mainframe.action.AliasPropertiesCommand;
04: import net.sourceforge.squirrel_sql.client.preferences.SquirrelPreferences;
05: import net.sourceforge.squirrel_sql.client.session.ISession;
06: import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
07:
08: import javax.swing.*;
09: import java.awt.event.ActionEvent;
10: import java.awt.event.ActionListener;
11: import java.awt.event.KeyEvent;
12:
13: public class SessionStartupTimeHintController {
14: private ISession _session;
15: private SessionStartupTimeHintDlg _dlg;
16:
17: public SessionStartupTimeHintController(ISession session) {
18: _session = session;
19: _dlg = new SessionStartupTimeHintDlg(_session.getApplication()
20: .getMainFrame(), session.getApplication());
21:
22: _dlg.btnClose.addActionListener(new ActionListener() {
23: public void actionPerformed(ActionEvent e) {
24: close();
25: }
26: });
27:
28: _dlg.btnShowProps.addActionListener(new ActionListener() {
29: public void actionPerformed(ActionEvent e) {
30: showAliasProperties();
31: }
32: });
33:
34: AbstractAction closeAction = new AbstractAction() {
35: public void actionPerformed(ActionEvent actionEvent) {
36: close();
37: }
38: };
39: KeyStroke escapeStroke = KeyStroke.getKeyStroke(
40: KeyEvent.VK_ESCAPE, 0);
41: _dlg.getRootPane().getInputMap(
42: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
43: escapeStroke, "CloseAction");
44: _dlg.getRootPane().getInputMap(
45: JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke,
46: "CloseAction");
47: _dlg.getRootPane().getInputMap(JComponent.WHEN_FOCUSED).put(
48: escapeStroke, "CloseAction");
49: _dlg.getRootPane().getActionMap().put("CloseAction",
50: closeAction);
51:
52: _dlg.setSize(350, 180);
53: GUIUtils.centerWithinParent(_dlg);
54: _dlg.setVisible(true);
55: }
56:
57: private void showAliasProperties() {
58: close();
59:
60: SwingUtilities.invokeLater(new Runnable() {
61: public void run() {
62: new AliasPropertiesCommand(_session.getAlias(),
63: _session.getApplication()).execute();
64: }
65: });
66: }
67:
68: private void close() {
69: _dlg.dispose();
70: SquirrelPreferences squirrelPreferences = _session
71: .getApplication().getSquirrelPreferences();
72: squirrelPreferences
73: .setShowSessionStartupTimeHint(false == _dlg.chkDontShowAgain
74: .isSelected());
75: }
76:
77: }
|