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