Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extCatalog / src / org / gvsig / catalog / gui / SearchDialog.java @ 31496

History | View | Annotate | Download (5.8 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.catalog.gui;
42

    
43
import java.awt.Frame;
44
import java.awt.geom.Rectangle2D;
45

    
46
import javax.swing.Icon;
47
import javax.swing.JDialog;
48

    
49
import org.gvsig.andami.PluginServices;
50
import org.gvsig.andami.ui.mdiManager.IWindow;
51
import org.gvsig.andami.ui.mdiManager.WindowInfo;
52
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
53
import org.gvsig.catalog.CatalogClient;
54
import org.gvsig.catalog.drivers.GetRecordsReply;
55
import org.gvsig.catalog.querys.Coordinates;
56
import org.gvsig.catalog.ui.search.SearchDialogPanel;
57
import org.gvsig.catalog.utils.Frames;
58
import org.gvsig.fmap.mapcontext.events.ColorEvent;
59
import org.gvsig.fmap.mapcontext.events.ExtentEvent;
60
import org.gvsig.fmap.mapcontext.events.ProjectionEvent;
61
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener;
62
import org.gvsig.i18n.Messages;
63

    
64

    
65
/**
66
 * This class is used to search a record using the catalog client
67
 * @author luisw
68
 * @modified by Jorge Piera
69
 */
70
public class SearchDialog extends SearchDialogPanel implements
71
IWindow,ViewPortListener {    
72
        public WindowInfo m_windowInfo = null;
73
        public ConnectDialog parentDialog = null;
74
        public JDialog frame = null;
75

    
76
        public SearchDialog(CatalogClient client, Object serverConnectFrame) {
77
                super(client,serverConnectFrame);
78
                parentDialog = (ConnectDialog)serverConnectFrame;
79
                setViewChangeListener();                
80
                loadViewPortCoordinates();
81
        }
82

    
83
        /* (non-Javadoc)
84
         * @see com.iver.andami.ui.mdiManager.View#getViewInfo()
85
         */
86
        public WindowInfo getWindowInfo() {
87
                if (m_windowInfo == null){
88
                        m_windowInfo = new WindowInfo(WindowInfo.PALETTE);
89
                        m_windowInfo.setTitle(Messages.getText("gazetteer_search") + " [" +
90
                                        getCurrentServer() + "]");                
91
                        m_windowInfo.setHeight(80);
92
                        m_windowInfo.setWidth(525);
93
                }
94
                return m_windowInfo;
95

    
96
        }
97
        public Object getWindowProfile(){
98
                return WindowInfo.TOOL_PROFILE;
99
        }
100

    
101
        protected void showResultsActionPerformed(GetRecordsReply recordsReply) {
102
                JDialog panel = new JDialog((Frame) PluginServices.getMainFrame(), false);
103
                Frames.centerFrame(panel,620,420);
104
                panel.setTitle(Messages.getText( "search_results")); 
105
                panel.setResizable(false);
106
                ShowResultsDialog dialog = new ShowResultsDialog(panel,
107
                                client,
108
                                recordsReply,
109
                                1);
110
                panel.getContentPane().add(dialog);
111
                panel.setVisible(true); 
112
        }
113

    
114
        protected void closeButtonActionPerformed() {
115
                closeJDialog();
116
        }
117

    
118
        /**
119
         * Size button action performed
120
         */         
121
        protected void resizeButtonActionPerformed(){
122
                if (isMinimized){
123
                        frame.setSize(frame.getWidth(),495);
124
                        getLowerPanel().setVisible(true);
125
                        getUpperPanel().setIcon(getUpIcon());
126
                }else{
127
                        frame.setSize(frame.getWidth(),165);
128
                        getLowerPanel().setVisible(false);                                 
129
                        getUpperPanel().setIcon(getDownIcon());
130
                }
131
                isMinimized = !isMinimized;
132
        }
133
        
134
        /*
135
         * (non-Javadoc)
136
         * @see org.gvsig.catalog.ui.search.SearchDialogPanel#getUpIcon()
137
         */
138
        protected Icon getUpIcon(){
139
                return PluginServices.getIconTheme().get("catalog-up");
140
        }
141
        
142
        /*
143
         * (non-Javadoc)
144
         * @see org.gvsig.catalog.ui.search.SearchDialogPanel#getDownIcon()
145
         */
146
        protected Icon getDownIcon(){
147
                return PluginServices.getIconTheme().get("catalog-down");
148
        }
149
        
150
        /**
151
         * Return button action
152
         */
153
        protected void lastButtonActionPerformed() {  
154
                closeJDialog();
155
                ConnectDialog serverConnect = (ConnectDialog)serverConnectFrame;
156
                serverConnect.setVisible(true);
157
                serverConnect.getControlsPanel().enableSearchButton(false);
158
                PluginServices.getMDIManager().addWindow(serverConnect);
159
        } 
160

    
161
        public void closeJDialog() {
162
                frame.setVisible(false);
163
        }
164

    
165
        /**
166
         * This method loads the view coordinates to the catalog search dialog
167
         *
168
         */
169
        private void loadViewPortCoordinates(){
170
                AbstractViewPanel activeView = 
171
                        (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
172

    
173
                Rectangle2D r2d= activeView.getMapControl().getViewPort().getExtent();
174

    
175
                try{
176
                        getLowerPanel().setCoordinates(new Coordinates(r2d.getMinX(),
177
                                        r2d.getMaxY(),
178
                                        r2d.getMaxX(),
179
                                        r2d.getMinY()));
180
                }catch(NullPointerException E){
181
                        //We cant retrieve the coordinates if it doesn't 
182
                        //exist a loaded layer
183
                }
184
        }
185
        /*
186
         * This method joins the viewPort event to the listener
187
         */
188
        private void setViewChangeListener(){
189
                AbstractViewPanel activeView = 
190
                        (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
191

    
192
                activeView.getMapControl().getViewPort().addViewPortListener(this);
193

    
194
        }
195

    
196
        public void extentChanged(ExtentEvent e) {
197
                loadViewPortCoordinates();   
198

    
199
        }
200

    
201
        public void backColorChanged(ColorEvent e) {
202
                // TODO Auto-generated method stub
203

    
204
        }
205

    
206
        public void projectionChanged(ProjectionEvent e) {
207
                loadViewPortCoordinates();                
208
        }
209

    
210
        public void setFrame(JDialog frame) {
211
                this.frame = frame;
212
        }                      
213
}