Statistics
| Revision:

svn-gvsig-desktop / tmp / trunk / cliente / WorkSpace_WPSClient / extWPSCallejero / src / es / logex / gvsig / gui / dialogs / StreetsMapsPaletteDialog.java @ 26601

History | View | Annotate | Download (7.74 KB)

1
package es.logex.gvsig.gui.dialogs;
2

    
3
import java.awt.Dimension;
4
import java.awt.GridBagConstraints;
5
import java.awt.GridBagLayout;
6
import java.awt.Insets;
7
import java.awt.geom.Rectangle2D;
8
import java.beans.PropertyChangeEvent;
9
import java.beans.PropertyChangeListener;
10
import java.net.URL;
11
import java.util.ArrayList;
12
import java.util.List;
13

    
14
import javax.swing.WindowConstants;
15
import javax.swing.JFrame;
16
import javax.swing.JPanel;
17
import javax.swing.JTabbedPane;
18

    
19
import org.cresques.cts.ICoordTrans;
20
import org.cresques.cts.IProjection;
21

    
22

    
23
import com.iver.andami.ui.mdiManager.IWindow;
24
import com.iver.andami.ui.mdiManager.IWindowListener;
25
import com.iver.andami.ui.mdiManager.WindowInfo;
26
import com.iver.cit.gvsig.fmap.MapControl;
27
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
28

    
29
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
30
import com.iver.cit.gvsig.project.documents.view.gui.View;
31

    
32
import es.logex.gvsig.streetsmap.core.SMProtocolHandler;
33
import es.logex.gvsig.streetsmap.core.SMProtocolHandlerFactory;
34
import es.logex.gvsig.streetsmap.query.QueryResultData;
35
import es.logex.gvsig.streetsmap.query.QueryResultDataImpl;
36
import es.logex.gvsig.streetsmap.ui.PanelConnectionWPS;
37
import es.logex.gvsig.streetsmap.ui.PanelQuerysRequestsHandler;
38
import es.logex.gvsig.streetsmap.ui.PanelQuerysBuilder;
39
import es.logex.gvsig.streetsmap.ui.events.ConnectionSucceedListener;
40
import es.logex.gvsig.streetsmap.ui.events.ConnectionSucceedEvent;
41
import es.logex.gvsig.wps.client.WPSClient;
42

    
43
/**
44
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI Builder, which is free for non-commercial use. If Jigloo is being used commercially (ie, by a corporation, company or business for any purpose whatever) then you should purchase a license for each developer using Jigloo. Please visit www.cloudgarden.com for details. Use of Jigloo implies acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
45
 * @uml.dependency   supplier="es.logex.gvsig.streetsmap.query.QueryResultData"
46
 * @uml.dependency   supplier="es.logex.gvsig.streetsmap.query.QueryResultDataImpl"
47
 * @uml.dependency   supplier="es.logex.gvsig.streetsmap.ui.PanelQuerysBuilder"
48
 */
49
public class StreetsMapsPaletteDialog extends javax.swing.JPanel implements 
50
        PanelQuerysRequestsHandler,ConnectionSucceedListener, IWindow, IWindowListener, PropertyChangeListener
51

    
52
{
53
        /**
54
         * 
55
         */
56
        private static final long serialVersionUID = 8091493079057956906L;
57
        private JTabbedPane jTabbedPaneMain;
58
        private PanelConnectionWPS jPanel1;
59
        private JPanel jPanel2;
60
        private WindowInfo viewInfo = null;
61
        private BaseView view = null;
62
        private SMProtocolHandler streetsMapProtocolHandler;
63
        private URL hostURL;
64
        private String title;
65

    
66
        /**
67
        * Auto-generated main method to display this 
68
        * JPanel inside a new JFrame.
69
        */
70
//        public static void main(String[] args) {
71
//                JFrame frame = new JFrame();
72
//                frame.getContentPane().add(new StreetsMapsPaletteDialog());
73
//                frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
74
//                frame.pack();
75
//                frame.setVisible(true);
76
//        }
77
        
78
        public StreetsMapsPaletteDialog() {
79
                super();
80
                initGUI();
81
        }
82
        
83
        public StreetsMapsPaletteDialog(BaseView view) {
84
                this();
85
                this.view = view;
86
                if(view instanceof View)
87
                {
88
                        this.title = ((View)view).getModel().getName();
89
                        ((View)view).getModel().addPropertyChangeListener(this);
90
                }
91
        }
92
        
93
        private void initGUI() {
94
                try {
95
                        GridBagLayout thisLayout = new GridBagLayout();
96
                        setPreferredSize(new Dimension(500, 300));
97
                        thisLayout.rowWeights = new double[] {0.0, 0.1, 0.0};
98
                        thisLayout.rowHeights = new int[] {7, 7, 7};
99
                        thisLayout.columnWeights = new double[] {0.0, 0.1, 0.0};
100
                        thisLayout.columnWidths = new int[] {7, 7, 7};
101
                        this.setLayout(thisLayout);
102
                        {
103
                                jTabbedPaneMain = new JTabbedPane();
104
                                this.add(jTabbedPaneMain, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
105
                                {
106
                                        jPanel1 = new PanelConnectionWPS();
107
                                        jTabbedPaneMain.addTab("Conexión", null, jPanel1, null);
108
                                        jPanel1.addConnectSucceedListener(this);
109
                                }
110
                                {
111
                                        jPanel2 = new PanelQuerysBuilder(this);
112
                                        jPanel2.setVisible(false);
113
                                        
114
                                        // Esto se hara cuando hayamos tenido una conexion exitosa
115
                                        jTabbedPaneMain.addTab("Búsqueda", null, jPanel2, null);
116
                                        jTabbedPaneMain.setEnabledAt(1, false);
117

    
118
                                }
119
                        }
120
                } catch (Exception e) {
121
                        e.printStackTrace();
122
                }
123
        }
124

    
125
        private Rectangle2D getProjectedExtent(Rectangle2D extent) {
126
                IProjection defaultServerProjection = CRSFactory
127
                                .getCRS(this.streetsMapProtocolHandler.getCrsDefault());
128

    
129
                IProjection viewProjection = view.getProjection();
130
                
131
                Rectangle2D projectedExtent = null;
132
                
133
                projectedExtent = extent;
134
                if (!defaultServerProjection.getAbrev().equals(viewProjection.getAbrev())) {
135
                        // projectar.
136
                        ICoordTrans ct = defaultServerProjection.getCT(viewProjection);
137
                        projectedExtent = ct.convert(extent);
138
                }
139

    
140
                return projectedExtent;
141
        }
142
        
143
        public void DoExtent(QueryResultData newExtent) {
144
                if(getView() != null)
145
                {
146
                        MapControl mapCtrl = getView().getMapControl();                
147
                        Rectangle2D toExtent = (Rectangle2D)newExtent.getUserData();
148
                
149
                        boolean firstTime = false;
150
                        
151
                        try {
152
                                
153
                                
154
                                if(this.streetsMapProtocolHandler == null)
155
                                {
156
                                        this.streetsMapProtocolHandler = SMProtocolHandlerFactory.createVersionHandler("1.0.0");
157
                                        this.streetsMapProtocolHandler.initialize(this.hostURL);
158
                                        firstTime = true;
159
                                }
160
                                toExtent = getProjectedExtent(toExtent);
161
                                mapCtrl.getMapContext().getViewPort().setExtent(toExtent);
162
                                
163
                                if (firstTime) {
164
                                        this.streetsMapProtocolHandler.attachToToc();
165
                                }
166
                                
167
                        } catch (ClassNotFoundException e) {
168
                                // TODO Auto-generated catch block
169
                                e.printStackTrace();
170
                        } catch (InstantiationException e) {
171
                                // TODO Auto-generated catch block
172
                                e.printStackTrace();
173
                        } catch (IllegalAccessException e) {
174
                                // TODO Auto-generated catch block
175
                                e.printStackTrace();
176
                        }
177

    
178

    
179
                }
180
                // TODO Auto-generated method stub
181
                
182
        }
183

    
184
        public List<QueryResultData> DoSearch(String municipio, String calle,
185
                        String numpolicia) {
186

    
187
                List<QueryResultData> retList = new ArrayList<QueryResultData>();
188
                WPSClient wpsClient = new WPSClient(this.hostURL.toString());
189
                wpsClient.connect();
190
                List<String> lista = wpsClient.executeProcessGetCandidates(municipio, calle, numpolicia);
191
                
192
                for (String s : lista) {
193
                        QueryResultData q = new QueryResultDataImpl(s);
194
                        retList.add(q);
195
                }
196
                
197
                return retList;
198
        }
199

    
200
        public void connectionSucceed(
201
                        ConnectionSucceedEvent connectRequestedEvent) {
202
                System.out.println("Connection established  to " + connectRequestedEvent.getURL().toString());
203

    
204
                this.hostURL = connectRequestedEvent.getURL();
205
                jTabbedPaneMain.setEnabledAt(1, true);
206

    
207
        }
208

    
209
        public WindowInfo getWindowInfo() {
210
                 if (viewInfo == null) {
211
                    viewInfo=new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.PALETTE | WindowInfo.RESIZABLE);/*  );  WindowInfo.MODALDIALOG |WindowInfo.MODELESSDIALOG |*/
212
                    viewInfo.setTitle(this.title);
213
                    viewInfo.setWidth(500);
214
                    viewInfo.setHeight(400);
215
                }
216
                 return viewInfo;
217
        }
218

    
219
        public void windowActivated() {
220
                // TODO Auto-generated method stub
221
                
222
        }
223

    
224
        public void windowClosed() {
225
                // TODO Auto-generated method stub
226
                
227
        }
228

    
229
        /**
230
         * @return the view
231
         */
232
        public BaseView getView() {
233
                return view;
234
        }
235

    
236
        /*
237
         * Cuando cambia el titulo de la vista refrescamos el titulo de la ventana
238
         * (non-Javadoc)
239
         * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
240
         */
241
        public void propertyChange(PropertyChangeEvent evt) {
242
                if(evt.getPropertyName().equalsIgnoreCase("name"))
243
                {
244
                        this.title = evt.getNewValue().toString();
245
                        this.viewInfo.setTitle(this.title);
246
                }
247
                
248
        }
249

    
250
}
251