Statistics
| Revision:

gvsig-catalog / trunk / extCatalog / src / org / gvsig / catalog / gui / SearchDialog.java @ 10

History | View | Annotate | Download (6.03 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.IconThemeHelper;
50
import org.gvsig.andami.PluginServices;
51
import org.gvsig.andami.ui.mdiManager.IWindow;
52
import org.gvsig.andami.ui.mdiManager.WindowInfo;
53
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
54
import org.gvsig.catalog.CatalogClient;
55
import org.gvsig.catalog.drivers.GetRecordsReply;
56
import org.gvsig.catalog.querys.Coordinates;
57
import org.gvsig.catalog.ui.search.SearchDialogPanel;
58
import org.gvsig.catalog.utils.Frames;
59
import org.gvsig.fmap.mapcontext.events.ColorEvent;
60
import org.gvsig.fmap.mapcontext.events.ExtentEvent;
61
import org.gvsig.fmap.mapcontext.events.ProjectionEvent;
62
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener;
63
import org.gvsig.i18n.Messages;
64

    
65

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

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

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

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

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

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

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

    
168
        public void closeJDialog() {
169
                frame.setVisible(false);
170
        }
171

    
172
        /**
173
         * This method loads the view coordinates to the catalog search dialog
174
         *
175
         */
176
        private void loadViewPortCoordinates(){
177
                AbstractViewPanel activeView = 
178
                        (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
179

    
180
                Rectangle2D r2d= activeView.getMapControl().getViewPort().getExtent();
181

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

    
199
                activeView.getMapControl().getViewPort().addViewPortListener(this);
200

    
201
        }
202

    
203
        public void extentChanged(ExtentEvent e) {
204
                loadViewPortCoordinates();   
205

    
206
        }
207

    
208
        public void backColorChanged(ColorEvent e) {
209
                // TODO Auto-generated method stub
210

    
211
        }
212

    
213
        public void projectionChanged(ProjectionEvent e) {
214
                loadViewPortCoordinates();                
215
        }
216

    
217
        public void setFrame(JDialog frame) {
218
                this.frame = frame;
219
        }                      
220
}