Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.app / org.gvsig.raster.app.common / src / main / java / org / gvsig / raster / mainplugin / toolbar / ButtonItems.java @ 2861

History | View | Annotate | Download (3.15 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
package org.gvsig.raster.mainplugin.toolbar;
23

    
24
import java.util.ArrayList;
25
import java.util.List;
26

    
27
import javax.swing.JButton;
28

    
29
import org.gvsig.fmap.mapcontext.layers.FLayer;
30
import org.gvsig.gui.beans.controls.combobutton.ComboButton;
31
/**
32
 * Clase para gestionar y ordenar los items de un ComboButton
33
 *  
34
 * @version 13/02/2008
35
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
36
 */
37
public class ButtonItems {
38
        private ComboButton comboButton = null;
39
        private FLayer[] layers = null;
40
        private List<IGenericToolBarMenuItem> arrayList = new ArrayList<IGenericToolBarMenuItem>();
41
        private List<String> arrayKeys = new ArrayList<String>();
42

    
43
        public ButtonItems(ComboButton comboButton, FLayer[] layers) {
44
                this.comboButton = comboButton;
45
                this.layers = layers;
46
        }
47
        
48
        /**
49
         * A?ade un item al ComboButton
50
         * @param menuItem
51
         * @param key
52
         */
53
        public void addButton(IGenericToolBarMenuItem menuItem, String key) {
54
                int pos = 0;
55
                boolean find = false;
56
                for (int i = 0; i < arrayList.size(); i++) {
57
                        pos = i;
58
                        IGenericToolBarMenuItem aux = (IGenericToolBarMenuItem) arrayList.get(i);
59
                        if (aux.getGroupOrder() > menuItem.getGroupOrder()) {
60
                                find = true;
61
                                break;
62
                        }
63
                        if (aux.getGroupOrder() == menuItem.getGroupOrder()) {
64
                                if (aux.getOrder() > menuItem.getOrder()) {
65
                                        find = true;
66
                                        break;
67
                                }
68
                        }
69
                }
70
                if (!find)
71
                        pos = arrayList.size();
72
                arrayList.add(pos, menuItem);
73
                arrayKeys.add(pos, key);
74
        }
75
        
76
        /**
77
         * Refresca los items del ComboButton
78
         */
79
        public void refresh() {
80
                String actionCommand = comboButton.getActionCommand();
81
                comboButton.clearButtons();
82
                int group = -1;
83
                for (int i = 0; i < arrayList.size(); i++) {
84
                        IGenericToolBarMenuItem aux = (IGenericToolBarMenuItem) arrayList.get(i);
85

    
86
                        if ((group != -1) && (group != aux.getGroupOrder()))
87
                                comboButton.addSeparator();
88

    
89
                        JButton button2 = new JButton(aux.getText(), aux.getIcon());
90

    
91
                        if (!aux.isVisible(null, layers))
92
                                button2.setEnabled(false);
93

    
94
                        if (!aux.isEnabled(null, layers))
95
                                button2.setEnabled(false);
96
                        
97
                        button2.setActionCommand((String) arrayKeys.get(i));
98
                        comboButton.addButton(button2);
99
                        group = aux.getGroupOrder();
100
                }
101
                comboButton.setSelectedItem(actionCommand);
102
        }
103
}