Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.swing / org.gvsig.raster.swing.api / src / main / java / org / gvsig / raster / swing / basepanel / AbstractButtonsPanel.java @ 1743

History | View | Annotate | Download (5.11 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 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 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
 * 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.raster.swing.basepanel;
25

    
26
import java.awt.Component;
27
import java.awt.Container;
28
import java.awt.LayoutManager;
29
import java.awt.Window;
30

    
31
import javax.swing.JPanel;
32

    
33
import org.gvsig.raster.swing.RasterSwingLocator;
34

    
35

    
36
/**
37
 * <code>AbstractButtonsPanel</code> is a panel which inherits of <code>JPanel</code>.
38
 * That reimplemented panel permits add generic buttons of apply, accept and cancel to
39
 * a panel.
40
 * @author BorSanZa - Borja Sanchez Zamorano 
41
 */
42
public abstract class AbstractButtonsPanel extends JPanel {
43
        private static final long serialVersionUID = 1536590395737700551L;
44
        IButtonsPanel             bp               = null;
45
        JPanel                    content          = null;
46
        private int               margin           = 4;
47
        
48
        /**
49
         * Crea el <code>DefaultButtonsPanel</code> con los botones por defecto.
50
         */
51
        public AbstractButtonsPanel() {
52
                super.setLayout(new java.awt.BorderLayout(0, 0));
53
                getButtonsPanel().addAccept();
54
                getButtonsPanel().addCancel();
55
                getButtonsPanel().addApply();
56
                super.add((JPanel)getButtonsPanel(), java.awt.BorderLayout.SOUTH);
57
                super.add(getContent(), java.awt.BorderLayout.CENTER);
58
                this.setBorder(javax.swing.BorderFactory.createEmptyBorder(margin, margin, margin, margin));
59
        }
60

    
61
        /**
62
         * Crea el <code>DialogPanel</code> con los botones que definamos de la clase
63
         * <code>ButtonsPanel</code>
64
         *
65
         * @param buttons Constante para definir que botones se crear?n
66
         */
67
        public AbstractButtonsPanel(int buttons) {
68
                super.setLayout(new java.awt.BorderLayout(0, 0));
69
                bp = RasterSwingLocator.getSwingManager().createButtonsPanel(buttons, this);
70
                super.add((JPanel)getButtonsPanel(), java.awt.BorderLayout.SOUTH);
71
                super.add(getContent(), java.awt.BorderLayout.CENTER);
72
                this.setBorder(javax.swing.BorderFactory.createEmptyBorder(margin, margin, margin, margin));
73
        }
74

    
75
        /**
76
         * Obtener el objeto <code>ButtonsPanel</code> del <code>DialogPanel</code>.
77
         * En caso de no estar creado, lo crear?.
78
         *
79
         * @return El componente bp
80
         */
81
        public IButtonsPanel getButtonsPanel() {
82
                if (bp == null)
83
                        bp = RasterSwingLocator.getSwingManager().createButtonsPanel(IButtonsPanel.BUTTONS_NONE, this);
84
                return bp;
85
        }
86

    
87
        /**
88
         * Obtener el contenido del <code>DialogPanel</code>. En caso de no estar creado,
89
         * lo crear?.
90
         *
91
         * @return El componente content
92
         */
93
        public JPanel getContent() {
94
                if (content == null)
95
                        content = new JPanel();
96
                return content;
97
        }
98

    
99
        public void addButtonPressedListener(ButtonsPanelListener listener) {
100
                getButtonsPanel().addButtonPressedListener(listener);
101
        }
102

    
103
        public void removeButtonPressedListener(ButtonsPanelListener listener) {
104
                getButtonsPanel().removeButtonPressedListener(listener);
105
        }
106

    
107
        /*
108
         * (non-Javadoc)
109
         * @see java.awt.Container#getLayout()
110
         */
111
        public LayoutManager getLayout() {
112
                return getContent().getLayout();
113
        }
114

    
115
        /*
116
         * (non-Javadoc)
117
         * @see java.awt.Container#setLayout(java.awt.LayoutManager)
118
         */
119
        public void setLayout(LayoutManager mgr) {
120
                getContent().setLayout(mgr);
121
        }
122

    
123
        /**
124
         * Devuelve el Window que contiene dicha ventana o null en caso de que no sea
125
         * asi
126
         * @return
127
         */
128
        public Window getWindow() {
129
                Container container = getParent();
130
                while (container != null) {
131
                        if (container instanceof Window)
132
                                return (Window) container;
133
                        container = container.getParent();
134
                }
135
                return null;
136
        }
137

    
138
        /*
139
         * (non-Javadoc)
140
         * @see java.awt.Container#add(java.awt.Component)
141
         */
142
        public Component add(Component comp) {
143
                return getContent().add(comp);
144
        }
145

    
146
        /*
147
         * (non-Javadoc)
148
         * @see java.awt.Container#add(java.awt.Component, int)
149
         */
150
        public Component add(Component comp, int index) {
151
                return getContent().add(comp, index);
152
        }
153

    
154
        /*
155
         * (non-Javadoc)
156
         * @see java.awt.Container#add(java.awt.Component, java.lang.Object)
157
         */
158
        public void add(Component comp, Object constraints) {
159
                getContent().add(comp, constraints);
160
        }
161

    
162
        /*
163
         * (non-Javadoc)
164
         * @see java.awt.Container#add(java.awt.Component, java.lang.Object, int)
165
         */
166
        public void add(Component comp, Object constraints, int index) {
167
                getContent().add(comp, constraints, index);
168
        }
169

    
170
        /*
171
         * (non-Javadoc)
172
         * @see java.awt.Container#add(java.lang.String, java.awt.Component)
173
         */
174
        public Component add(String name, Component comp) {
175
                return getContent().add(name, comp);
176
        }
177
}