svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / main / java / org / gvsig / utils / console / JDockPanel.java @ 40561
History | View | Annotate | Download (8.19 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.utils.console; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Cursor; |
28 |
import java.awt.Dimension; |
29 |
import java.awt.GridBagConstraints; |
30 |
import java.awt.GridBagLayout; |
31 |
import java.awt.Point; |
32 |
|
33 |
import javax.swing.ImageIcon; |
34 |
import javax.swing.JButton; |
35 |
import javax.swing.JComponent; |
36 |
import javax.swing.JPanel; |
37 |
import javax.swing.JSeparator; |
38 |
import javax.swing.SwingUtilities; |
39 |
|
40 |
public class JDockPanel extends JPanel { |
41 |
|
42 |
private JPanel jPanelNorth = null; |
43 |
private JPanel jPanelButtons = null; |
44 |
private JComponent centerComponent; |
45 |
private JButton jButtonUp = null; |
46 |
private JButton jButtonDown = null; |
47 |
private JPanel jPanelCenterNorth = null; |
48 |
private JSeparator jSeparator1 = null; |
49 |
private JDockPanel the;
|
50 |
private int originalCenterComponentHeight; |
51 |
|
52 |
public JDockPanel(JComponent centerComponent) { |
53 |
super();
|
54 |
the = this;
|
55 |
initialize(); |
56 |
this.centerComponent = centerComponent;
|
57 |
this.originalCenterComponentHeight = centerComponent.getPreferredSize().height;
|
58 |
this.add(centerComponent, BorderLayout.CENTER); |
59 |
|
60 |
} |
61 |
|
62 |
/**
|
63 |
* This method initializes this
|
64 |
*
|
65 |
*/
|
66 |
private void initialize() { |
67 |
this.setLayout(new BorderLayout()); |
68 |
this.setSize(new java.awt.Dimension(388,225)); |
69 |
this.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,0,0)); |
70 |
this.add(getJPanelNorth(), java.awt.BorderLayout.NORTH);
|
71 |
|
72 |
} |
73 |
|
74 |
/**
|
75 |
* This method initializes jPanelNorth
|
76 |
*
|
77 |
* @return javax.swing.JPanel
|
78 |
*/
|
79 |
private JPanel getJPanelNorth() { |
80 |
if (jPanelNorth == null) { |
81 |
jPanelNorth = new JPanel(); |
82 |
jPanelNorth.setLayout(new BorderLayout()); |
83 |
jPanelNorth.setPreferredSize(new java.awt.Dimension(100,12)); |
84 |
jPanelNorth.add(getJPanelCenterNorth(), java.awt.BorderLayout.CENTER); |
85 |
jPanelNorth.add(getJPanelButtons(), java.awt.BorderLayout.EAST); |
86 |
|
87 |
|
88 |
} |
89 |
return jPanelNorth;
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* This method initializes jPanelButtons
|
94 |
*
|
95 |
* @return javax.swing.JPanel
|
96 |
*/
|
97 |
private JPanel getJPanelButtons() { |
98 |
if (jPanelButtons == null) { |
99 |
jPanelButtons = new JPanel(); |
100 |
jPanelButtons.setLayout(null);
|
101 |
jPanelButtons.setPreferredSize(new java.awt.Dimension(51,12)); |
102 |
jPanelButtons.add(getJButtonUp(), null);
|
103 |
jPanelButtons.add(getJButtonDown(), null);
|
104 |
} |
105 |
return jPanelButtons;
|
106 |
} |
107 |
|
108 |
/**
|
109 |
* This method initializes jButtonUp
|
110 |
*
|
111 |
* @return javax.swing.JButton
|
112 |
*/
|
113 |
private JButton getJButtonUp() { |
114 |
if (jButtonUp == null) { |
115 |
jButtonUp = new JButton(); |
116 |
jButtonUp.setCursor(Cursor.getDefaultCursor());
|
117 |
jButtonUp.setIcon(new ImageIcon(getClass().getResource("/images/up" + |
118 |
".png")));
|
119 |
jButtonUp.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM); |
120 |
jButtonUp.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); |
121 |
jButtonUp.setBounds(new java.awt.Rectangle(3,0,20,12)); |
122 |
jButtonUp.setPreferredSize(new java.awt.Dimension(20,12)); |
123 |
jButtonUp.addActionListener(new java.awt.event.ActionListener() {
|
124 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
125 |
// UP
|
126 |
centerComponent.setPreferredSize(new Dimension(centerComponent.getWidth(), originalCenterComponentHeight)); |
127 |
int hTot = centerComponent.getPreferredSize().height + getJPanelNorth().getHeight();
|
128 |
|
129 |
// the.setLocation(0, the.getParent().getHeight()-hTot);
|
130 |
// the.centerComponent.setLocation(0, getJPanelNorth().getHeight());
|
131 |
the.reshape(0, the.getParent().getHeight()-hTot, the.getWidth(), hTot);
|
132 |
the.validate(); |
133 |
the.doLayout(); |
134 |
// centerComponent.validate();
|
135 |
// centerComponent.doLayout();
|
136 |
|
137 |
} |
138 |
}); |
139 |
} |
140 |
return jButtonUp;
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* This method initializes jButton
|
145 |
*
|
146 |
* @return javax.swing.JButton
|
147 |
*/
|
148 |
private JButton getJButtonDown() { |
149 |
if (jButtonDown == null) { |
150 |
jButtonDown = new JButton(); |
151 |
jButtonDown.setCursor(Cursor.getDefaultCursor());
|
152 |
jButtonDown.setPreferredSize(new java.awt.Dimension(20,12)); |
153 |
jButtonDown.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM); |
154 |
jButtonDown.setIcon(new ImageIcon(getClass().getResource("/images/down.png"))); |
155 |
jButtonDown.setBounds(new java.awt.Rectangle(26,0,20,12)); |
156 |
jButtonDown.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); |
157 |
jButtonDown.addActionListener(new java.awt.event.ActionListener() {
|
158 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
159 |
// DOWN
|
160 |
centerComponent.setPreferredSize(new Dimension(centerComponent.getWidth(), 0)); |
161 |
|
162 |
int hTot = getJPanelNorth().getHeight();
|
163 |
// the.setLocation(0, the.getParent().getHeight()-hTot);
|
164 |
the.reshape(0, the.getParent().getHeight()-hTot, the.getWidth(), hTot);
|
165 |
// the.setPreferredSize()
|
166 |
the.validate(); |
167 |
the.doLayout(); |
168 |
} |
169 |
}); |
170 |
} |
171 |
return jButtonDown;
|
172 |
} |
173 |
|
174 |
/**
|
175 |
* This method initializes jPanelCenterNorth
|
176 |
*
|
177 |
* @return javax.swing.JPanel
|
178 |
*/
|
179 |
private JPanel getJPanelCenterNorth() { |
180 |
if (jPanelCenterNorth == null) { |
181 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
182 |
gridBagConstraints.insets = new java.awt.Insets(2,0,2,0); |
183 |
gridBagConstraints.weightx = 90.0D;
|
184 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
185 |
jPanelCenterNorth = new JPanel(); |
186 |
jPanelCenterNorth.setLayout(new GridBagLayout()); |
187 |
jPanelCenterNorth.add(getJSeparator1(), gridBagConstraints); |
188 |
} |
189 |
return jPanelCenterNorth;
|
190 |
} |
191 |
|
192 |
/**
|
193 |
* This method initializes jSeparator1
|
194 |
*
|
195 |
* @return javax.swing.JSeparator
|
196 |
*/
|
197 |
private JSeparator getJSeparator1() { |
198 |
if (jSeparator1 == null) { |
199 |
jSeparator1 = new JSeparator(); |
200 |
jSeparator1.setPreferredSize(new java.awt.Dimension(100,5)); |
201 |
jSeparator1.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR)); |
202 |
jSeparator1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
|
203 |
public void mouseDragged(java.awt.event.MouseEvent e) { |
204 |
Point pExt = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), the.getParent()); |
205 |
Dimension sizeFather = the.getParent().getSize();
|
206 |
int heightFather = sizeFather.height;
|
207 |
Dimension newDimension = new Dimension(the.getSize().width, heightFather - pExt.y); |
208 |
Dimension newCDimension = new Dimension(the.getSize().width, heightFather - pExt.y - getJPanelNorth().getHeight()); |
209 |
Point actualOrigin = the.getLocation();
|
210 |
// the.setSize(newDimension);
|
211 |
// the.setBounds(actualOrigin.x, pExt.y, newDimension.width, newDimension.height);
|
212 |
the.reshape(actualOrigin.x, pExt.y, newDimension.width, newDimension.height); |
213 |
// centerComponent.reshape(0, newDimension.width, getJPanelNorth().getHeight(), newDimension.height-getJPanelNorth().getHeight());
|
214 |
// the.doLayout();
|
215 |
// ComponentEvent ev = new ComponentEvent(the,
|
216 |
// ComponentEvent.COMPONENT_RESIZED);
|
217 |
// the.dispatchEvent(ev);
|
218 |
// invalidate();
|
219 |
// repaint();
|
220 |
originalCenterComponentHeight = newDimension.height; |
221 |
centerComponent.setPreferredSize(newCDimension); |
222 |
the.validate(); |
223 |
the.doLayout(); |
224 |
} |
225 |
}); |
226 |
} |
227 |
return jSeparator1;
|
228 |
} |
229 |
|
230 |
public JComponent getCenterComponent() { |
231 |
return centerComponent;
|
232 |
} |
233 |
|
234 |
public void setCenterComponent(JComponent centerComponent) { |
235 |
if (this.centerComponent != null) |
236 |
{ |
237 |
this.remove(this.centerComponent); |
238 |
} |
239 |
this.centerComponent = centerComponent;
|
240 |
this.originalCenterComponentHeight = centerComponent.getPreferredSize().height;
|
241 |
this.add(centerComponent, BorderLayout.CENTER); |
242 |
|
243 |
} |
244 |
|
245 |
} // @jve:decl-index=0:visual-constraint="10,10"
|
246 |
|
247 |
|