gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.swing / org.gvsig.tools.swing.impl / src / main / java / org / gvsig / tools / swing / impl / windowmanager / DefaultWindowManager.java @ 1405
History | View | Annotate | Download (5.03 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 modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 2 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.tools.swing.impl.windowmanager; |
24 |
|
25 |
import java.awt.Component; |
26 |
import java.awt.Frame; |
27 |
import java.awt.Image; |
28 |
import java.awt.event.ComponentEvent; |
29 |
import java.awt.event.ComponentListener; |
30 |
|
31 |
import javax.swing.JComponent; |
32 |
import javax.swing.JDialog; |
33 |
import javax.swing.JFrame; |
34 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
35 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
36 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
37 |
|
38 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE; |
39 |
import static org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE.DIALOG; |
40 |
import static org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE.TOOL; |
41 |
import static org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE.WINDOW; |
42 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
43 |
|
44 |
public class DefaultWindowManager implements WindowManager_v2 { |
45 |
|
46 |
@Override
|
47 |
public void showWindow(JComponent component, String title, MODE mode, Image icon) { |
48 |
switch (mode) {
|
49 |
case TOOL:
|
50 |
case WINDOW:
|
51 |
MyFrame frame = new MyFrame(title);
|
52 |
frame.setContentPane(component); |
53 |
component.addComponentListener(frame); |
54 |
frame.setIconImage(icon); |
55 |
frame.pack(); |
56 |
frame.setLocationRelativeTo(null);
|
57 |
frame.setVisible(true);
|
58 |
break;
|
59 |
case DIALOG:
|
60 |
MyJDialog dialog = new MyJDialog(title, true); |
61 |
|
62 |
dialog.setContentPane(component); |
63 |
component.addComponentListener(dialog); |
64 |
|
65 |
dialog.setIconImage(icon); |
66 |
dialog.pack(); |
67 |
dialog.setLocationRelativeTo(null);
|
68 |
dialog.setVisible(true);
|
69 |
break;
|
70 |
|
71 |
} |
72 |
} |
73 |
|
74 |
@Override
|
75 |
public void showWindow(JComponent component, String title, MODE mode) { |
76 |
switch (mode) {
|
77 |
case TOOL:
|
78 |
case WINDOW:
|
79 |
MyFrame frame = new MyFrame(title);
|
80 |
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
81 |
|
82 |
frame.setContentPane(component); |
83 |
component.addComponentListener(frame); |
84 |
frame.pack(); |
85 |
frame.setLocationRelativeTo(null);
|
86 |
frame.setVisible(true);
|
87 |
break;
|
88 |
case DIALOG:
|
89 |
MyJDialog dialog = new MyJDialog(title, true); |
90 |
|
91 |
dialog.setContentPane(component); |
92 |
component.addComponentListener(dialog); |
93 |
dialog.pack(); |
94 |
dialog.setLocationRelativeTo(null);
|
95 |
dialog.setVisible(true);
|
96 |
break;
|
97 |
} |
98 |
} |
99 |
|
100 |
@Override
|
101 |
public Dialog createDialog(JComponent component, String title, String header, int buttons) { |
102 |
DefaultDialog dialog = new DefaultDialog(component, title, header, buttons);
|
103 |
return dialog;
|
104 |
} |
105 |
|
106 |
public class MyFrame extends JFrame implements ComponentListener { |
107 |
|
108 |
public MyFrame(String title) { |
109 |
super(title);
|
110 |
} |
111 |
|
112 |
@Override
|
113 |
public void componentHidden(ComponentEvent arg0) { |
114 |
this.setVisible(false); |
115 |
this.dispose();
|
116 |
} |
117 |
|
118 |
public void setComponentPane(Component component) { |
119 |
} |
120 |
|
121 |
@Override
|
122 |
public void componentMoved(ComponentEvent arg0) { |
123 |
} |
124 |
|
125 |
@Override
|
126 |
public void componentResized(ComponentEvent arg0) { |
127 |
} |
128 |
|
129 |
@Override
|
130 |
public void componentShown(ComponentEvent arg0) { |
131 |
} |
132 |
|
133 |
} |
134 |
|
135 |
public class MyJDialog extends JDialog implements ComponentListener { |
136 |
|
137 |
public MyJDialog(String title, boolean modal) { |
138 |
super((Frame) null, title, modal); |
139 |
} |
140 |
|
141 |
@Override
|
142 |
public void componentHidden(ComponentEvent arg0) { |
143 |
this.setVisible(false); |
144 |
this.dispose();
|
145 |
} |
146 |
|
147 |
@Override
|
148 |
public void componentMoved(ComponentEvent arg0) { |
149 |
} |
150 |
|
151 |
@Override
|
152 |
public void componentResized(ComponentEvent arg0) { |
153 |
} |
154 |
|
155 |
@Override
|
156 |
public void componentShown(ComponentEvent arg0) { |
157 |
} |
158 |
} |
159 |
|
160 |
} |