gvsig-projects-pool / org.gvsig.winmgr / trunk / org.gvsig.winmgr.app / org.gvsig.winmgr.app.mainplugin / src / main / java / org / gvsig / coreplugin / mdiManager / WindowInfoSupport.java @ 682
History | View | Annotate | Download (6.46 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.coreplugin.mdiManager; |
25 |
|
26 |
import java.awt.Dimension; |
27 |
import java.awt.Rectangle; |
28 |
import java.beans.PropertyChangeEvent; |
29 |
import java.beans.PropertyChangeListener; |
30 |
import java.util.Enumeration; |
31 |
import java.util.Hashtable; |
32 |
|
33 |
import org.gvsig.andami.plugins.PluginClassLoader; |
34 |
import org.gvsig.andami.ui.mdiFrame.MainFrame; |
35 |
import org.gvsig.andami.ui.mdiFrame.NoSuchMenuException; |
36 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
37 |
import org.gvsig.andami.ui.mdiManager.SingletonWindow; |
38 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
39 |
|
40 |
|
41 |
|
42 |
/**
|
43 |
* This class listens to changes in WindowInfo objects, and reflects this
|
44 |
* changes in the associated window.
|
45 |
*/
|
46 |
public class WindowInfoSupport { |
47 |
private static int serialId = 0; |
48 |
|
49 |
/**
|
50 |
* Support class which associates Frames and Windows
|
51 |
*/
|
52 |
private FrameWindowSupport fws;
|
53 |
|
54 |
// Correspondencias entre las ventanas y su informacion
|
55 |
/**
|
56 |
* key: IWindow, value: WindowInfo
|
57 |
*/
|
58 |
private Hashtable viewInfo = new Hashtable(); |
59 |
/**
|
60 |
* key: WindowInfo, value: IWindow
|
61 |
*/
|
62 |
private Hashtable infoView = new Hashtable(); |
63 |
private WindowPropertyChangeListener windowInfoListener = new WindowPropertyChangeListener(); |
64 |
private SingletonWindowSupport sws;
|
65 |
private MainFrame mdiFrame;
|
66 |
|
67 |
/**
|
68 |
* Creates a new ViewInfoSupport object.
|
69 |
*
|
70 |
* @param frame DOCUMENT ME!
|
71 |
* @param fvs DOCUMENT ME!
|
72 |
* @param svs
|
73 |
*/
|
74 |
public WindowInfoSupport(MainFrame frame, FrameWindowSupport fvs,
|
75 |
SingletonWindowSupport svs) { |
76 |
this.fws = fvs;
|
77 |
this.sws = svs;
|
78 |
this.mdiFrame = frame;
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* Devuelve la vista cuyo identificador es el parametro
|
83 |
*
|
84 |
* @param id Identificador de la vista que se quiere obtener
|
85 |
*
|
86 |
* @return La vista o null si no hay ninguna vista con ese identificador
|
87 |
*/
|
88 |
public IWindow getWindowById(int id) { |
89 |
Enumeration en = infoView.keys();
|
90 |
|
91 |
while (en.hasMoreElements()) {
|
92 |
WindowInfo vi = (WindowInfo) en.nextElement(); |
93 |
|
94 |
if (vi.getId() == id) {
|
95 |
return (IWindow) infoView.get(vi);
|
96 |
} |
97 |
} |
98 |
|
99 |
return null; |
100 |
} |
101 |
|
102 |
/**
|
103 |
* DOCUMENT ME!
|
104 |
*
|
105 |
* @param w DOCUMENT ME!
|
106 |
*
|
107 |
* @return DOCUMENT ME!
|
108 |
*/
|
109 |
public synchronized WindowInfo getWindowInfo(IWindow w) { |
110 |
WindowInfo wi = (WindowInfo) viewInfo.get(w); |
111 |
|
112 |
if (wi != null) { |
113 |
fws.updateWindowInfo(w, wi); |
114 |
} |
115 |
else {
|
116 |
wi = w.getWindowInfo(); |
117 |
|
118 |
//Para el t?tulo
|
119 |
if (wi.getHeight() != -1) { |
120 |
wi.setHeight(wi.getHeight() + 40);
|
121 |
} |
122 |
|
123 |
wi.addPropertyChangeListener(windowInfoListener); |
124 |
viewInfo.put(w, wi); |
125 |
infoView.put(wi, w); |
126 |
wi.setId(serialId++); |
127 |
} |
128 |
|
129 |
return wi;
|
130 |
} |
131 |
|
132 |
/**
|
133 |
* DOCUMENT ME!
|
134 |
*
|
135 |
* @param p DOCUMENT ME!
|
136 |
*/
|
137 |
public void deleteWindowInfo(IWindow p) { |
138 |
WindowInfo vi = (WindowInfo) viewInfo.remove(p); |
139 |
infoView.remove(vi); |
140 |
} |
141 |
|
142 |
/**
|
143 |
* DOCUMENT ME!
|
144 |
*
|
145 |
* @author $author$
|
146 |
* @version $Revision: 39115 $
|
147 |
*/
|
148 |
public class WindowPropertyChangeListener implements PropertyChangeListener { |
149 |
/**
|
150 |
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
|
151 |
*/
|
152 |
public void propertyChange(PropertyChangeEvent evt) { |
153 |
WindowInfo winInfo = (WindowInfo) evt.getSource(); |
154 |
IWindow win = (IWindow) infoView.get(winInfo); |
155 |
|
156 |
if (win instanceof SingletonWindow) { |
157 |
SingletonWindow sw = (SingletonWindow) win; |
158 |
|
159 |
if (evt.getPropertyName().equals("x")) { |
160 |
sws.setX(sw, ((Integer) evt.getNewValue()).intValue());
|
161 |
} else if (evt.getPropertyName().equals("y")) { |
162 |
sws.setY(sw, ((Integer) evt.getNewValue()).intValue());
|
163 |
} else if (evt.getPropertyName().equals("height")) { |
164 |
sws.setHeight(sw, ((Integer) evt.getNewValue()).intValue());
|
165 |
} else if (evt.getPropertyName().equals("width")) { |
166 |
sws.setWidth(sw, ((Integer) evt.getNewValue()).intValue());
|
167 |
} else if (evt.getPropertyName().equals("maximized")) { |
168 |
sws.setMaximized(sw, ((Boolean) evt.getNewValue()).booleanValue());
|
169 |
} else if (evt.getPropertyName().equals("normalBounds")) { |
170 |
sws.setNormalBounds(sw, (Rectangle) evt.getNewValue());
|
171 |
} else if (evt.getPropertyName().equals("minimumSize")) { |
172 |
sws.setMinimumSize(sw, (Dimension) evt.getNewValue());
|
173 |
} else if (evt.getPropertyName().equals("title")) { |
174 |
sws.setTitle(sw, (String) evt.getNewValue());
|
175 |
|
176 |
try {
|
177 |
mdiFrame.changeMenuName(new String[] { |
178 |
"Window", (String) evt.getOldValue() |
179 |
}, (String) evt.getNewValue(),
|
180 |
(PluginClassLoader) getClass().getClassLoader()); |
181 |
} catch (NoSuchMenuException e) {
|
182 |
/*
|
183 |
* No se hace nada porque puede modificarse el t?tulo de
|
184 |
* una ventana antes de ser a?adida a Andami
|
185 |
*/
|
186 |
} |
187 |
} |
188 |
} else {
|
189 |
if (evt.getPropertyName().equals("x")) { |
190 |
fws.setX(win, ((Integer) evt.getNewValue()).intValue());
|
191 |
} else if (evt.getPropertyName().equals("y")) { |
192 |
fws.setY(win, ((Integer) evt.getNewValue()).intValue());
|
193 |
} else if (evt.getPropertyName().equals("height")) { |
194 |
fws.setHeight(win, ((Integer) evt.getNewValue()).intValue());
|
195 |
} else if (evt.getPropertyName().equals("width")) { |
196 |
fws.setWidth(win, ((Integer) evt.getNewValue()).intValue());
|
197 |
} else if (evt.getPropertyName().equals("minimumSize")) { |
198 |
fws.setMinimumSize(win, (Dimension) evt.getNewValue());
|
199 |
} else if (evt.getPropertyName().equals("title")) { |
200 |
fws.setTitle(win, (String) evt.getNewValue());
|
201 |
try{
|
202 |
mdiFrame.changeMenuName(new String[] { |
203 |
"Ventana", (String) evt.getOldValue() |
204 |
}, (String) evt.getNewValue(),
|
205 |
(PluginClassLoader) getClass().getClassLoader()); |
206 |
} catch (NoSuchMenuException e) {
|
207 |
/*
|
208 |
* No se hace nada porque puede modificarse el t?tulo de
|
209 |
* una ventana antes de ser a?adida a Andami
|
210 |
*/
|
211 |
} |
212 |
} |
213 |
} |
214 |
} |
215 |
} |
216 |
} |