001: /*
002: * SelectTabAction.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.actions;
013:
014: import java.awt.event.ActionEvent;
015: import java.awt.event.InputEvent;
016: import java.awt.event.KeyEvent;
017:
018: import javax.swing.JTabbedPane;
019: import javax.swing.KeyStroke;
020:
021: import workbench.log.LogMgr;
022: import workbench.resource.ResourceMgr;
023:
024: /**
025: * @author support@sql-workbench.net
026: */
027: public class SelectTabAction extends WbAction {
028: private JTabbedPane client;
029: private int index;
030:
031: public SelectTabAction(JTabbedPane aPane, int anIndex) {
032: super ();
033: this .client = aPane;
034: this .index = anIndex;
035: this .initName();
036: }
037:
038: private void initName() {
039: switch (this .index) {
040: case 0:
041: this .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1,
042: InputEvent.CTRL_MASK));
043: break;
044: case 1:
045: this .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2,
046: InputEvent.CTRL_MASK));
047: break;
048: case 2:
049: this .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3,
050: InputEvent.CTRL_MASK));
051: break;
052: case 3:
053: this .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4,
054: InputEvent.CTRL_MASK));
055: break;
056: case 4:
057: this .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_5,
058: InputEvent.CTRL_MASK));
059: break;
060: case 5:
061: this .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_6,
062: InputEvent.CTRL_MASK));
063: break;
064: case 6:
065: this .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_7,
066: InputEvent.CTRL_MASK));
067: break;
068: case 7:
069: this .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_8,
070: InputEvent.CTRL_MASK));
071: break;
072: case 8:
073: this .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_9,
074: InputEvent.CTRL_MASK));
075: break;
076: default:
077: this .setAccelerator(null);
078: }
079: this .setActionName("SelectTab" + (this .index + 1));
080: this .setMenuText(ResourceMgr.getDefaultTabLabel());// + " &" + Integer.toString(this.index+1));
081: this .setIcon(null);
082: }
083:
084: public int getIndex() {
085: return this .index;
086: }
087:
088: public void setNewIndex(int anIndex) {
089: this .index = anIndex;
090: this .initName();
091: }
092:
093: public void executeAction(ActionEvent e) {
094: if (client != null) {
095: try {
096: this .client.setSelectedIndex(this .index);
097: } catch (Exception ex) {
098: LogMgr.logError("SelectTabAction.executeAction()",
099: "Error when selecting tab " + this.index, ex);
100: }
101: }
102: }
103: }
|