Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.framework / org.gvsig.andami / src / main / java / org / gvsig / andami / ui / mdiFrame / SelectableToolBar.java @ 43099

History | View | Annotate | Download (4.26 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.andami.ui.mdiFrame;
25

    
26
import java.awt.Component;
27
import javax.swing.ButtonGroup;
28
import javax.swing.JToggleButton;
29
import javax.swing.JToolBar;
30
import org.apache.commons.lang3.StringUtils;
31

    
32

    
33
/**
34
 * Caja de herramientas seleccionables
35
 */
36
public class SelectableToolBar extends JToolBar {
37
        private static final long serialVersionUID = 1L;
38
        /**
39
     * Andami visibility: determines whether this toolbar should
40
     * be shown by Andami. If it's false, the toolbar will be
41
     * hidden even if its associated extension is visible.
42
     */
43
    private boolean _visible;
44
    private int position;
45
    private String description;
46

    
47
    /**
48
     * Creates a new SelectableToolBar object.
49
     *
50
     * @param titulo T?tulo de la barra
51
     */
52
    public SelectableToolBar(String titulo) {
53
        this(titulo,null,0);
54
    }
55

    
56
    public SelectableToolBar(String titulo, String description, int position) {
57
        super(titulo);
58
        this.description = description;
59
        this.position = position;
60
    }
61

    
62
    public int getPosition() {
63
        return this.position;
64
    }
65
    
66
    public void setPosition(int position) {
67
        this.position = position;
68
    }
69
    
70
    public String getDescription() {
71
        return this.description;
72
    }
73
    
74
    /**
75
     * A?ade un boton a la caja
76
     *
77
     * @param btn bot?n a a?adir.
78
     */
79
    public void addButton(ButtonGroup group, JToggleButton btn) {
80
            group.add(btn);
81
        add(btn);
82
    }
83

    
84
    /**
85
     * Selects a toggleButton in this toolBar by ActionCommand
86
     * @param actionCommand
87
     */
88
    public void setSelectedTool(String actionCommand){
89
        for (int i = 0; i < getComponentCount(); i++) {
90
            if (getComponent(i) instanceof JToggleButton)
91
            {
92
                JToggleButton toggleButton = (JToggleButton) getComponent(i);
93
                String aux = toggleButton.getActionCommand();
94
                if (aux != null)
95
                  if (aux.equals(actionCommand)){
96
                        toggleButton.setSelected(true);
97
                      }
98
            }
99
        }
100

    
101
    }
102
    
103
    /**
104
     * Sets whether or not this toolbar should
105
     * be shown by Andami. If it's false, the toolbar will be
106
     * hidden even if its associated extension is visible.
107
     * 
108
     * @param visible
109
     */
110
    public void setAndamiVisibility(boolean visible) {
111
            _visible = visible;
112
    }
113
    
114
    /**
115
     * Gets whether this toolbar should
116
     * be shown by Andami. If it's false, the toolbar will be
117
     * hidden even if its associated extension is visible.
118
     * 
119
     * @return <code>true</code> if the toolbar should be shown
120
     * when it has some visible button, <code>false</code> if
121
     * the toolbar should be hidden even it it contains some
122
     * buttons that should be visible according to its associated
123
     * extension.
124
     */
125
    public boolean getAndamiVisibility() {
126
            return _visible;
127
    }
128
    
129
    public Component findComponent(String name) {
130
        if( StringUtils.isBlank(name) ) {
131
            return null;
132
        }
133
        Object lock = this.getTreeLock();
134
        synchronized(lock) {
135
            for( int i=0; i<this.getComponentCount(); i++ ) {
136
                Component c1= this.getComponent(i);
137
                if( name.equalsIgnoreCase(c1.getName()) ) {
138
                    return c1;
139
                }
140
            }
141
        }
142
        return null;
143
    }
144
}