Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extCatalog / src / org / gvsig / catalog / gui / SearchDialog.java @ 28434

History | View | Annotate | Download (5.79 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.ImageIcon;
48
import javax.swing.JDialog;
49

    
50
import org.gvsig.catalog.CatalogClient;
51
import org.gvsig.catalog.drivers.GetRecordsReply;
52
import org.gvsig.catalog.querys.Coordinates;
53
import org.gvsig.catalog.ui.search.SearchDialogPanel;
54
import org.gvsig.catalog.utils.Frames;
55
import org.gvsig.fmap.mapcontext.events.ColorEvent;
56
import org.gvsig.fmap.mapcontext.events.ExtentEvent;
57
import org.gvsig.fmap.mapcontext.events.ProjectionEvent;
58
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener;
59
import org.gvsig.i18n.Messages;
60

    
61
import com.iver.andami.PluginServices;
62
import com.iver.andami.ui.mdiManager.IWindow;
63
import com.iver.andami.ui.mdiManager.WindowInfo;
64
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
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
                return PluginServices.getIconTheme().get("catalog-up");
141
        }
142
        
143
        /*
144
         * (non-Javadoc)
145
         * @see org.gvsig.catalog.ui.search.SearchDialogPanel#getDownIcon()
146
         */
147
        protected Icon getDownIcon(){
148
                return PluginServices.getIconTheme().get("catalog-down");
149
        }
150
        
151
        /**
152
         * Return button action
153
         */
154
        protected void lastButtonActionPerformed() {  
155
                closeJDialog();
156
                ConnectDialog serverConnect = (ConnectDialog)serverConnectFrame;
157
                serverConnect.setVisible(true);
158
                serverConnect.getControlsPanel().enableSearchButton(false);
159
                PluginServices.getMDIManager().addWindow(serverConnect);
160
        } 
161

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

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

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

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

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

    
195
        }
196

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

    
200
        }
201

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

    
205
        }
206

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

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