svn-gvsig-desktop / branches / v2_0_0_prep / frameworks / _fwAndami / src / org / gvsig / andami / ui / ToolsWindowManager.java @ 35606
History | View | Annotate | Download (4.38 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.andami.ui; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
import java.awt.Dimension; |
26 |
import java.awt.GridBagConstraints; |
27 |
import java.awt.event.ComponentEvent; |
28 |
import java.awt.event.ComponentListener; |
29 |
|
30 |
import javax.swing.JComponent; |
31 |
import javax.swing.JPanel; |
32 |
|
33 |
import org.gvsig.andami.PluginServices; |
34 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
35 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
36 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
37 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
38 |
|
39 |
|
40 |
/**
|
41 |
* @author gvSIG Team
|
42 |
* @version $Id$
|
43 |
*
|
44 |
*/
|
45 |
public class ToolsWindowManager implements WindowManager { |
46 |
|
47 |
public void showWindow(JComponent contents, String title, MODE mode) { |
48 |
int align;
|
49 |
switch(mode) {
|
50 |
case DIALOG:
|
51 |
align = GridBagConstraints.CENTER;
|
52 |
break;
|
53 |
case TOOL:
|
54 |
align = GridBagConstraints.FIRST_LINE_END;
|
55 |
break;
|
56 |
case WINDOW:
|
57 |
default:
|
58 |
align = GridBagConstraints.FIRST_LINE_START;
|
59 |
break;
|
60 |
} |
61 |
showWindow(contents, title, mode, align); |
62 |
} |
63 |
|
64 |
public void showWindow(JComponent contents, String title, MODE mode, int align ) { |
65 |
MDIManager manager = PluginServices.getMDIManager(); |
66 |
IWindow window = new Window(contents, title, mode); |
67 |
manager.addWindow(window,align); |
68 |
} |
69 |
|
70 |
public class Window extends JPanel implements IWindow, ComponentListener { |
71 |
|
72 |
/**
|
73 |
*
|
74 |
*/
|
75 |
private static final long serialVersionUID = -6688594664366192449L; |
76 |
protected WindowInfo windowInfo;
|
77 |
protected Object profile; |
78 |
protected JComponent contents; |
79 |
|
80 |
public Window(JComponent contents, String title, MODE mode) { |
81 |
int code = WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE | WindowInfo.ICONIFIABLE;
|
82 |
switch(mode) {
|
83 |
case DIALOG:
|
84 |
code |= WindowInfo.MODALDIALOG; |
85 |
profile = WindowInfo.DIALOG_PROFILE; |
86 |
break;
|
87 |
case TOOL:
|
88 |
code |= WindowInfo.MODELESSDIALOG | WindowInfo.PALETTE; |
89 |
profile = WindowInfo.TOOL_PROFILE; |
90 |
break;
|
91 |
case WINDOW:
|
92 |
default:
|
93 |
profile = WindowInfo.EDITOR_PROFILE; |
94 |
break;
|
95 |
} |
96 |
|
97 |
this.contents = contents;
|
98 |
|
99 |
this.windowInfo = new WindowInfo(code); |
100 |
this.windowInfo.setTitle(title);
|
101 |
|
102 |
Dimension size = this.contents.getPreferredSize(); |
103 |
this.windowInfo.setHeight(size.height);
|
104 |
this.windowInfo.setWidth(size.width);
|
105 |
|
106 |
this.setLayout(new BorderLayout()); |
107 |
this.add(this.contents,BorderLayout.CENTER); |
108 |
|
109 |
this.contents.addComponentListener(this); |
110 |
} |
111 |
|
112 |
public WindowInfo getWindowInfo() {
|
113 |
return this.windowInfo; |
114 |
} |
115 |
|
116 |
public Object getWindowProfile() { |
117 |
return this.profile; |
118 |
} |
119 |
|
120 |
public void componentHidden(ComponentEvent arg0) { |
121 |
// Close window when hide contents panel.
|
122 |
MDIManager manager = PluginServices.getMDIManager(); |
123 |
manager.closeWindow(this);
|
124 |
} |
125 |
|
126 |
public void componentMoved(ComponentEvent arg0) { |
127 |
// Do nothing
|
128 |
} |
129 |
|
130 |
public void componentResized(ComponentEvent arg0) { |
131 |
// Do nothing
|
132 |
} |
133 |
|
134 |
public void componentShown(ComponentEvent arg0) { |
135 |
// Do nothing
|
136 |
} |
137 |
|
138 |
} |
139 |
} |