svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.framework / org.gvsig.andami / src / main / java / org / gvsig / andami / ui / ToolsWindowManager.java @ 42811
History | View | Annotate | Download (6.94 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.andami.ui; |
||
25 | |||
26 | import java.awt.BorderLayout; |
||
27 | import java.awt.Dimension; |
||
28 | import java.awt.GridBagConstraints; |
||
29 | 42482 | jjdelcerro | import java.awt.Image; |
30 | 40435 | jjdelcerro | import java.awt.event.ComponentEvent; |
31 | import java.awt.event.ComponentListener; |
||
32 | 42226 | jjdelcerro | import java.lang.reflect.InvocationTargetException; |
33 | 40435 | jjdelcerro | |
34 | import javax.swing.JComponent; |
||
35 | import javax.swing.JPanel; |
||
36 | 42226 | jjdelcerro | import javax.swing.SwingUtilities; |
37 | 40435 | jjdelcerro | |
38 | import org.gvsig.andami.PluginServices; |
||
39 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
40 | import org.gvsig.andami.ui.mdiManager.MDIManager; |
||
41 | import org.gvsig.andami.ui.mdiManager.WindowInfo; |
||
42 | 42482 | jjdelcerro | import org.gvsig.tools.swing.api.windowmanager.Dialog; |
43 | import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE; |
||
44 | import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
||
45 | import org.gvsig.tools.swing.impl.windowmanager.DefaultDialog; |
||
46 | 40435 | jjdelcerro | |
47 | |||
48 | /**
|
||
49 | * @author gvSIG Team
|
||
50 | * @version $Id$
|
||
51 | *
|
||
52 | */
|
||
53 | 42482 | jjdelcerro | public class ToolsWindowManager implements WindowManager_v2 { |
54 | 40435 | jjdelcerro | |
55 | public void showWindow(JComponent contents, String title, MODE mode) { |
||
56 | int align;
|
||
57 | switch(mode) {
|
||
58 | case DIALOG:
|
||
59 | align = GridBagConstraints.CENTER;
|
||
60 | break;
|
||
61 | case TOOL:
|
||
62 | align = GridBagConstraints.FIRST_LINE_END;
|
||
63 | break;
|
||
64 | case WINDOW:
|
||
65 | default:
|
||
66 | align = GridBagConstraints.FIRST_LINE_START;
|
||
67 | break;
|
||
68 | } |
||
69 | 42482 | jjdelcerro | showWindow(contents, title, mode, align, null);
|
70 | 40435 | jjdelcerro | } |
71 | |||
72 | 42488 | jjdelcerro | public void showWindow(final JComponent contents, final String title, final MODE mode, final int align) { |
73 | this.showWindow(contents, title, mode, align, null); |
||
74 | } |
||
75 | |||
76 | 42482 | jjdelcerro | public void showWindow(final JComponent contents, final String title, final MODE mode, final int align, final Image icon ) { |
77 | 42226 | jjdelcerro | if( !SwingUtilities.isEventDispatchThread() ) { |
78 | switch(mode) {
|
||
79 | case DIALOG:
|
||
80 | { |
||
81 | try {
|
||
82 | SwingUtilities.invokeAndWait(new Runnable() { |
||
83 | public void run() { |
||
84 | 42482 | jjdelcerro | showWindow(contents, title, mode, align, null);
|
85 | 42226 | jjdelcerro | } |
86 | }); |
||
87 | } catch (InterruptedException ex) { |
||
88 | } catch (InvocationTargetException ex) { |
||
89 | } |
||
90 | } |
||
91 | break;
|
||
92 | case TOOL:
|
||
93 | case WINDOW:
|
||
94 | default:
|
||
95 | SwingUtilities.invokeLater(new Runnable() { |
||
96 | public void run() { |
||
97 | 42482 | jjdelcerro | showWindow(contents, title, mode, align,null);
|
98 | 42226 | jjdelcerro | } |
99 | }); |
||
100 | break;
|
||
101 | } |
||
102 | return;
|
||
103 | } |
||
104 | 40435 | jjdelcerro | MDIManager manager = PluginServices.getMDIManager(); |
105 | IWindow window = new Window(contents, title, mode); |
||
106 | manager.addWindow(window,align); |
||
107 | } |
||
108 | |||
109 | public class Window extends JPanel implements IWindow, ComponentListener { |
||
110 | |||
111 | /**
|
||
112 | 42187 | fdiaz | *
|
113 | 40435 | jjdelcerro | */
|
114 | private static final long serialVersionUID = -6688594664366192449L; |
||
115 | protected WindowInfo windowInfo;
|
||
116 | protected Object profile; |
||
117 | protected JComponent contents; |
||
118 | 42187 | fdiaz | |
119 | 40435 | jjdelcerro | public Window(JComponent contents, String title, MODE mode) { |
120 | 42187 | fdiaz | int code = WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE | WindowInfo.ICONIFIABLE;
|
121 | 40435 | jjdelcerro | switch(mode) {
|
122 | case DIALOG:
|
||
123 | code |= WindowInfo.MODALDIALOG; |
||
124 | profile = WindowInfo.DIALOG_PROFILE; |
||
125 | break;
|
||
126 | case TOOL:
|
||
127 | code |= WindowInfo.MODELESSDIALOG | WindowInfo.PALETTE; |
||
128 | profile = WindowInfo.TOOL_PROFILE; |
||
129 | break;
|
||
130 | case WINDOW:
|
||
131 | default:
|
||
132 | profile = WindowInfo.EDITOR_PROFILE; |
||
133 | break;
|
||
134 | } |
||
135 | 42187 | fdiaz | |
136 | 40435 | jjdelcerro | this.contents = contents;
|
137 | 42187 | fdiaz | |
138 | 40435 | jjdelcerro | this.windowInfo = new WindowInfo(code); |
139 | this.windowInfo.setTitle(title);
|
||
140 | 42266 | llmarques | this.windowInfo.setNeedPack(true); |
141 | 42187 | fdiaz | |
142 | Dimension size = this.contents.getPreferredSize(); |
||
143 | 40435 | jjdelcerro | this.windowInfo.setHeight(size.height);
|
144 | this.windowInfo.setWidth(size.width);
|
||
145 | 42187 | fdiaz | |
146 | 40435 | jjdelcerro | this.setLayout(new BorderLayout()); |
147 | this.add(this.contents,BorderLayout.CENTER); |
||
148 | 42187 | fdiaz | |
149 | 40435 | jjdelcerro | this.contents.addComponentListener(this); |
150 | } |
||
151 | 42187 | fdiaz | |
152 | 41854 | jjdelcerro | public void fireClosingWindow() { |
153 | this.contents.removeComponentListener(this); |
||
154 | ComponentListener[] l = this.contents.getComponentListeners(); |
||
155 | for( int i=0; i<l.length; i++) { |
||
156 | l[i].componentHidden(new ComponentEvent(this, i)); |
||
157 | } |
||
158 | } |
||
159 | 42187 | fdiaz | |
160 | 40435 | jjdelcerro | public WindowInfo getWindowInfo() {
|
161 | return this.windowInfo; |
||
162 | } |
||
163 | |||
164 | public Object getWindowProfile() { |
||
165 | return this.profile; |
||
166 | } |
||
167 | |||
168 | public void componentHidden(ComponentEvent arg0) { |
||
169 | // Close window when hide contents panel.
|
||
170 | MDIManager manager = PluginServices.getMDIManager(); |
||
171 | manager.closeWindow(this);
|
||
172 | } |
||
173 | |||
174 | public void componentMoved(ComponentEvent arg0) { |
||
175 | // Do nothing
|
||
176 | } |
||
177 | |||
178 | public void componentResized(ComponentEvent arg0) { |
||
179 | // Do nothing
|
||
180 | } |
||
181 | |||
182 | public void componentShown(ComponentEvent arg0) { |
||
183 | // Do nothing
|
||
184 | } |
||
185 | 41854 | jjdelcerro | |
186 | 42187 | fdiaz | public JComponent getContents() { |
187 | return this.contents; |
||
188 | } |
||
189 | |||
190 | 40435 | jjdelcerro | } |
191 | 42482 | jjdelcerro | |
192 | |||
193 | @Override
|
||
194 | public Dialog createDialog(JComponent component, String title, String header, int buttons) { |
||
195 | DefaultDialog dialog = new DefaultDialog(component, title, header, buttons);
|
||
196 | return dialog;
|
||
197 | } |
||
198 | |||
199 | @Override
|
||
200 | public void showWindow(JComponent contents, String title, MODE mode, Image icon) { |
||
201 | int align;
|
||
202 | switch(mode) {
|
||
203 | case DIALOG:
|
||
204 | align = GridBagConstraints.CENTER;
|
||
205 | break;
|
||
206 | case TOOL:
|
||
207 | align = GridBagConstraints.FIRST_LINE_END;
|
||
208 | break;
|
||
209 | case WINDOW:
|
||
210 | default:
|
||
211 | align = GridBagConstraints.FIRST_LINE_START;
|
||
212 | break;
|
||
213 | } |
||
214 | showWindow(contents, title, mode, align, icon); |
||
215 | } |
||
216 | |||
217 | 40435 | jjdelcerro | } |