Statistics
| Revision:

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 @ 33272

History | View | Annotate | Download (5.48 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.annotation.swing.impl;
23

    
24
import java.awt.BorderLayout;
25
import java.awt.Component;
26
import java.awt.Dimension;
27
import java.awt.Frame;
28
import java.awt.Toolkit;
29
import java.awt.event.ComponentEvent;
30
import java.awt.event.ComponentListener;
31

    
32
import javax.swing.JFrame;
33
import javax.swing.JOptionPane;
34
import javax.swing.JPanel;
35
import javax.swing.Timer;
36

    
37
import org.gvsig.annotation.swing.AnnotationWindowManager;
38
import org.gvsig.annotation.swing.AnnotationWizardPanelActionListener;
39
import org.gvsig.annotation.swing.JAnnotationCreationServicePanel;
40
import org.gvsig.annotation.swing.thread.AnnotationCreationTask;
41
import org.gvsig.i18n.Messages;
42
import org.gvsig.utils.swing.threads.IProgressMonitorIF;
43
import org.gvsig.utils.swing.threads.TaskMonitorTimerListener;
44
import org.gvsig.utils.swing.threads.UndefinedProgressMonitor;
45

    
46
/**
47
 * Default implementation for the {@link AnnotationWindowManager}.
48
 * 
49
 * @author gvSIG Team
50
 * @version $Id$
51
 */
52
public class DefaultAnnotationWindowManager implements
53
    AnnotationWindowManager, ComponentListener {
54

    
55
    public void showWindow(JAnnotationCreationServicePanel panel, String title, int mode) {
56
        JFrame frame = new JFrame();        
57
        
58
        panel.setAnnotationServicePanelActionListener(new FrameWizardListener(frame));        
59
        
60
        final Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
61
        frame.setLocation(s.width / 4, s.height / 4);
62

    
63
        frame.setLayout(new BorderLayout());
64
        frame.setTitle(title);
65
        frame.add(panel, BorderLayout.CENTER);
66

    
67
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
68

    
69
        frame.setPreferredSize(new Dimension(700, 400));
70
        panel.addComponentListener(this);
71

    
72
        frame.pack();
73
        frame.setVisible(true);
74
    }
75

    
76
    public void componentHidden(ComponentEvent componentEvent) {
77
        JFrame frame =
78
            (JFrame) ((JPanel) componentEvent.getSource()).getRootPane()
79
                .getParent();
80
        frame.setVisible(false);
81
        frame.dispose();
82
    }
83

    
84
    public void componentMoved(ComponentEvent arg0) {
85
        // Do nothing
86
    }
87

    
88
    public void componentResized(ComponentEvent arg0) {
89
        // Do nothing
90
    }
91

    
92
    public void componentShown(ComponentEvent arg0) {
93
        // Do nothing
94
    }
95
    
96
    public class FrameWizardListener implements AnnotationWizardPanelActionListener{
97
            private JFrame frame = null;
98
            
99
            public FrameWizardListener(JFrame frame) {
100
                    super();
101
                    this.frame = frame;
102
            }
103

    
104
            public void cancel(
105
                            JAnnotationCreationServicePanel annotationCreationServicePanel) {
106
                    frame.setVisible(false);
107
                    System.exit(0);                
108
            }
109

    
110
            public void finish(
111
                            JAnnotationCreationServicePanel annotationCreationServicePanel) {
112
                    frame.setVisible(false);
113
                    System.exit(0);                
114
            }
115
    }
116

    
117
        public void showWindow(final AnnotationCreationTask annotationCreationTask) {
118
                final org.gvsig.utils.swing.threads.SwingWorker worker = new org.gvsig.utils.swing.threads.SwingWorker() {
119
                        public Object construct() {                        
120
                                try {
121
                                        annotationCreationTask.run();
122
                                } catch (Exception e) {
123
                                        // TODO Auto-generated catch block
124
                                        e.printStackTrace();
125
                                }
126
                                return annotationCreationTask;                                
127
                        }
128
                    /**
129
                     * Called on the event dispatching thread (not on the worker thread)
130
                     * after the <code>construct</code> method has returned.
131
                     */
132
                        public void finished() {
133
                                annotationCreationTask.finished();
134
                        }
135
                };
136

    
137
                JFrame mainFrame = new JFrame();                
138

    
139
                IProgressMonitorIF progressMonitor = null;
140
                String title = Messages.getText("PluginServices.Procesando");
141
                progressMonitor = new UndefinedProgressMonitor((Frame) mainFrame, title);
142
                progressMonitor.setIndeterminated(!annotationCreationTask.isDefined());
143
                progressMonitor.setInitialStep(annotationCreationTask.getInitialStep());
144
                progressMonitor.setLastStep(annotationCreationTask.getFinishStep());
145
                progressMonitor.setCurrentStep(annotationCreationTask.getCurrentStep());
146
                progressMonitor.setMainTitleLabel(annotationCreationTask.getStatusMessage());
147
                progressMonitor.setNote(annotationCreationTask.getNote());
148
                progressMonitor.open();
149
                int delay = 500;
150
                TaskMonitorTimerListener timerListener = new TaskMonitorTimerListener(
151
                                progressMonitor, annotationCreationTask);
152
                Timer timer = new Timer(delay, timerListener);
153
                timerListener.setTimer(timer);
154
                timer.start();
155

    
156
                worker.start();                
157
        }
158

    
159
        public boolean showFileExistsPopup(String title, String text) {
160
                int resp = JOptionPane.showConfirmDialog(
161
                                new JFrame(), text,
162
                                title, JOptionPane.YES_NO_OPTION);
163
                if (resp == JOptionPane.YES_OPTION) {
164
                        return true;
165
                }
166
                return false;
167
        }
168

    
169
}