Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.main / src / main / java / org / gvsig / tools / main / MainAction.java @ 100

History | View | Annotate | Download (2.2 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

    
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2010 {}  {{Task}}
26
*/
27
package org.gvsig.tools.main;
28

    
29
import java.awt.event.ActionEvent;
30

    
31
import javax.swing.AbstractAction;
32
import javax.swing.Icon;
33
import javax.swing.JComponent;
34
import javax.swing.JTabbedPane;
35

    
36
/**
37
 * @author 2010-     C?sar Ordi?ana - gvSIG team
38
 */
39
public abstract class MainAction extends AbstractAction {
40

    
41
        private static final long serialVersionUID = 7286136693329716214L;
42
        private final JTabbedPane tabbedPane;
43

    
44
        /**
45
         * @see AbstractAction#AbstractAction()
46
         */
47
        public MainAction(JTabbedPane tabbedPane) {
48
                super();
49
                this.tabbedPane = tabbedPane;
50
        }
51

    
52
        /**
53
         * @see AbstractAction#AbstractAction(String)
54
         */
55
        public MainAction(String name, JTabbedPane tabbedPane) {
56
                super(name);
57
                this.tabbedPane = tabbedPane;
58
        }
59

    
60
        /**
61
         * @see AbstractAction#AbstractAction(String, Icon)
62
         */
63
        public MainAction(String name, Icon icon, JTabbedPane tabbedPane) {
64
                super(name, icon);
65
                this.tabbedPane = tabbedPane;
66
        }
67

    
68
        public void actionPerformed(ActionEvent e) {
69
                String title = getComponentTitle();
70
                int index = tabbedPane.indexOfTab(title);
71
                if (index <= -1) {
72
                        tabbedPane.addTab(title, createComponent());
73
                        index = tabbedPane.indexOfTab(title);
74
                }
75
                tabbedPane.setSelectedIndex(index);
76
        }
77
        
78
        protected abstract JComponent createComponent();
79

    
80
        protected abstract String getComponentTitle();
81

    
82
}