root / branches / v2_0_0_prep / libraries / org.gvsig.annotation / org.gvsig.annotation.swing / org.gvsig.annotation.swing.impl / src / main / java / org / gvsig / annotation / swing / impl / DefaultAnnotationWindowManager.java @ 38608
History | View | Annotate | Download (3.88 KB)
1 | 33272 | jpiera | /* 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.annotation.swing.impl; |
||
23 | |||
24 | import java.awt.BorderLayout; |
||
25 | import java.awt.Dimension; |
||
26 | import java.awt.Toolkit; |
||
27 | import java.awt.event.ComponentEvent; |
||
28 | import java.awt.event.ComponentListener; |
||
29 | |||
30 | import javax.swing.JFrame; |
||
31 | import javax.swing.JOptionPane; |
||
32 | import javax.swing.JPanel; |
||
33 | |||
34 | import org.gvsig.annotation.swing.AnnotationWindowManager; |
||
35 | import org.gvsig.annotation.swing.AnnotationWizardPanelActionListener; |
||
36 | import org.gvsig.annotation.swing.JAnnotationCreationServicePanel; |
||
37 | 33278 | jpiera | import org.gvsig.annotation.swing.JAnnotationPreferencesPanel; |
38 | 33272 | jpiera | |
39 | /**
|
||
40 | * Default implementation for the {@link AnnotationWindowManager}.
|
||
41 | *
|
||
42 | * @author gvSIG Team
|
||
43 | * @version $Id$
|
||
44 | */
|
||
45 | public class DefaultAnnotationWindowManager implements |
||
46 | AnnotationWindowManager, ComponentListener {
|
||
47 | |||
48 | public void showWindow(JAnnotationCreationServicePanel panel, String title, int mode) { |
||
49 | 33278 | jpiera | JFrame frame = showJPanel(panel, title, mode) ;
|
50 | panel.setAnnotationServicePanelActionListener(new FrameWizardListener(frame));
|
||
51 | } |
||
52 | |||
53 | |||
54 | public void showPreferencesWindow(JAnnotationPreferencesPanel panel, String title, int modeDialog) { |
||
55 | showJPanel(panel, title, modeDialog); |
||
56 | } |
||
57 | |||
58 | private JFrame showJPanel(JPanel panel, String title, int modeDialog) { |
||
59 | JFrame frame = new JFrame(); |
||
60 | |||
61 | 33272 | jpiera | final Dimension s = Toolkit.getDefaultToolkit().getScreenSize(); |
62 | frame.setLocation(s.width / 4, s.height / 4); |
||
63 | |||
64 | frame.setLayout(new BorderLayout()); |
||
65 | frame.setTitle(title); |
||
66 | frame.add(panel, BorderLayout.CENTER);
|
||
67 | |||
68 | frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||
69 | |||
70 | panel.addComponentListener(this);
|
||
71 | |||
72 | frame.pack(); |
||
73 | 33278 | jpiera | frame.setVisible(true);
|
74 | return frame;
|
||
75 | } |
||
76 | |||
77 | 33272 | jpiera | public void componentHidden(ComponentEvent componentEvent) { |
78 | JFrame frame =
|
||
79 | (JFrame) ((JPanel) componentEvent.getSource()).getRootPane() |
||
80 | .getParent(); |
||
81 | frame.setVisible(false);
|
||
82 | frame.dispose(); |
||
83 | } |
||
84 | |||
85 | public void componentMoved(ComponentEvent arg0) { |
||
86 | // Do nothing
|
||
87 | } |
||
88 | |||
89 | public void componentResized(ComponentEvent arg0) { |
||
90 | // Do nothing
|
||
91 | } |
||
92 | |||
93 | public void componentShown(ComponentEvent arg0) { |
||
94 | // Do nothing
|
||
95 | } |
||
96 | |||
97 | public class FrameWizardListener implements AnnotationWizardPanelActionListener{ |
||
98 | private JFrame frame = null; |
||
99 | |||
100 | public FrameWizardListener(JFrame frame) { |
||
101 | super();
|
||
102 | this.frame = frame;
|
||
103 | } |
||
104 | |||
105 | public void cancel( |
||
106 | JAnnotationCreationServicePanel annotationCreationServicePanel) { |
||
107 | frame.setVisible(false);
|
||
108 | System.exit(0); |
||
109 | } |
||
110 | |||
111 | public void finish( |
||
112 | JAnnotationCreationServicePanel annotationCreationServicePanel) { |
||
113 | frame.setVisible(false);
|
||
114 | System.exit(0); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | public boolean showFileExistsPopup(String title, String text) { |
||
119 | int resp = JOptionPane.showConfirmDialog( |
||
120 | new JFrame(), text, |
||
121 | title, JOptionPane.YES_NO_OPTION);
|
||
122 | if (resp == JOptionPane.YES_OPTION) { |
||
123 | return true; |
||
124 | } |
||
125 | return false; |
||
126 | } |
||
127 | |||
128 | 33278 | jpiera | |
129 | 33272 | jpiera | } |