01: /*
02: * FileDiscardAction.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.actions;
13:
14: import java.awt.event.ActionEvent;
15: import java.awt.event.InputEvent;
16: import java.awt.event.KeyEvent;
17:
18: import javax.swing.Action;
19: import javax.swing.ActionMap;
20: import javax.swing.InputMap;
21: import javax.swing.KeyStroke;
22:
23: import workbench.gui.sql.SqlPanel;
24: import workbench.resource.ResourceMgr;
25:
26: /**
27: * Discard the file currently loaded in the SQL Editor
28: * @author support@sql-workbench.net
29: */
30: public class FileDiscardAction extends WbAction {
31: private SqlPanel client;
32:
33: public FileDiscardAction(SqlPanel aClient) {
34: super ();
35: this .client = aClient;
36: String desc = ResourceMgr.getDescription("MnuTxtFileDiscard",
37: true);
38: this .putValue(Action.SHORT_DESCRIPTION, desc);
39: this .initMenuDefinition(ResourceMgr
40: .getString("MnuTxtFileDiscard"), desc, KeyStroke
41: .getKeyStroke(KeyEvent.VK_F4, InputEvent.CTRL_MASK));
42: this .setMenuItemName(ResourceMgr.MNU_TXT_FILE);
43: this .setEnabled(aClient.hasFileLoaded());
44: }
45:
46: public void addToInputMap(InputMap im, ActionMap am) {
47: super .addToInputMap(im, am);
48: im.put(KeyStroke.getKeyStroke(KeyEvent.VK_F4,
49: InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK), this
50: .getActionName());
51: }
52:
53: public void executeAction(ActionEvent e) {
54: this.client.closeFile(!isShiftPressed(e));
55: }
56: }
|