Revision 2985 trunk/applications/appCatalogYNomenclatorClient/src/es/gva/cit/catalogClient/ui/SearchDialogPanel.java

View differences:

SearchDialogPanel.java
45 45

  
46 46
import org.w3c.dom.Node;
47 47

  
48

  
48 49
import java.awt.Dimension;
49 50
import java.awt.FlowLayout;
50 51
import java.awt.event.ActionEvent;
51 52
import java.awt.event.ActionListener;
53
import java.awt.event.ItemEvent;
54
import java.awt.event.ItemListener;
52 55

  
53 56
import javax.swing.BoxLayout;
54 57
import javax.swing.JButton;
58
import javax.swing.JCheckBox;
55 59
import javax.swing.JDialog;
60
import javax.swing.JFrame;
56 61
import javax.swing.JOptionPane;
57 62
import javax.swing.JPanel;
58 63

  
......
60 65
/**
61 66
 * @author Jorge Piera Llodra (piera_jor@gva.es)
62 67
 */
63
public class SearchDialogPanel extends JPanel implements ActionListener {
68
public class SearchDialogPanel extends JPanel implements ActionListener,ItemListener {
69
    //This component its used to resize the frame
70
    private JFrame parent;
71
    
64 72
    //Panels
65
    JPanel ppalPanel = null;
66
    SearchPanel controlsPanel = null;
67
    JPanel buttonsPanel = null;
73
    protected JPanel ppalPanel = null;
74
    protected AbstractSearchPanel controlsPanel = null;
75
    protected JPanel checkBoxPanel = null;
76
    protected JPanel buttonsPanel = null;
68 77

  
69 78
    //Buttons
70 79
    private JButton searchButton = null;
71 80
    private JButton closeButton = null;
81
    private JButton sizeButton = null;
82
    private JCheckBox areaCheckBox = null;
72 83

  
73 84
    //Otros
74
    protected CatalogClient cliente = null;
85
    protected CatalogClient client = null;
75 86
    protected Node[] nodesRecords = null;
76

  
87
    protected boolean isMinimized = true;
88
   
77 89
    /**
78 90
     * This method initializes
79 91
     *
80 92
     */
81
    public SearchDialogPanel() {
93
    public SearchDialogPanel(JFrame parent,boolean isMinimized,String title) {
82 94
        super();
83
        initialize();
95
        this.parent = parent;
96
        this.isMinimized = isMinimized;
97
        initialize(title);
84 98
    }
85 99

  
86 100
    /**
......
88 102
     *
89 103
     * @return void
90 104
     */
91
    private void initialize() {
105
    protected void initialize(String title) {
106
        ppalPanel = null;
92 107
        ppalPanel = new JPanel();
93 108
        ppalPanel.setLocation(0, 0);
94 109
        ppalPanel.setLayout(new BoxLayout(ppalPanel, BoxLayout.Y_AXIS));
95 110

  
96 111
        ppalPanel.add(getControlsPanel(), null);
97
        ppalPanel.add(getButtonPanel(), null);
112
        if (isMinimized)
113
            ppalPanel.add(getCheckBoxPanel(),null);
114
        
115
        ppalPanel.add(getButtonsPanel(), null);
98 116

  
99 117
        add(ppalPanel);
100 118

  
101 119
        setDefaultButtonListeners();
120
        
121
        setTitle(title);
102 122
    }
103

  
104
    public void setCatalogClient(CatalogClient catCli) {
105
        this.cliente = catCli;
123
    /**
124
     * Sets the CatalogClient 
125
     * @param client
126
     * CatalogClient
127
     */
128
    public void setCatalogClient(CatalogClient client) {
129
        this.client = client;
106 130
    }
107

  
108
    public JPanel getControlsPanel() {
109
        if (controlsPanel == null) {
131
    
132
    /**
133
     * It Gets the controlsPanel 
134
     * @return
135
     */
136
    
137
   public AbstractSearchPanel getControlsPanel() {
138
        if (isMinimized){
139
            parent.setSize(300, 130);  
140
            controlsPanel = new SearchMiniPanel();
141
            controlsPanel.setSize(200,55);
142
        }else{
143
            parent.setSize(675, 520);
110 144
            controlsPanel = new SearchPanel();
111
            controlsPanel.setPreferredSize(new java.awt.Dimension(727, 455));
112
            controlsPanel.setLocation(0, 0);
145
            controlsPanel.setSize(700,455);
113 146
        }
114

  
115 147
        return controlsPanel;
116 148
    }
117

  
118
    public JPanel getButtonPanel() {
149
   
150
   /**
151
    * It gets the checkBoxPanel
152
    * @return
153
    */
154
   public JPanel getCheckBoxPanel(){
155
       if (checkBoxPanel == null) {
156
           checkBoxPanel = new JPanel();
157
           checkBoxPanel.add(getAreaCheckBox());
158
       }
159
       return checkBoxPanel;
160
   }
161
   
162
   /**
163
    * It gets the buttons panel
164
    * @return
165
    */
166
    public JPanel getButtonsPanel() {
119 167
        if (buttonsPanel == null) {
120 168
            buttonsPanel = new JPanel(new FlowLayout());
121 169
            buttonsPanel.add(getSearchButton());
122 170
            buttonsPanel.add(getCloseButton());
171
            buttonsPanel.add(getSizeButton());
123 172
        }
124

  
125 173
        return buttonsPanel;
126 174
    }
127

  
175
    
176
    /**
177
     * It gets the search button
178
     * @return
179
     */
128 180
    public JButton getSearchButton() {
129 181
        if (searchButton == null) {
130 182
            searchButton = new JButton("Buscar");
131 183
            searchButton.setSize(new Dimension(30, 20));
132
            searchButton.setActionCommand("Buscar");
184
            searchButton.setActionCommand("Search");
133 185
        }
134 186

  
135 187
        return searchButton;
136 188
    }
137 189
    
190
    /**
191
     * It gets the close button
192
     * @return
193
     */
138 194
    public JButton getCloseButton() {
139 195
        if (closeButton == null) {
140 196
            closeButton = new JButton("Cerrar");
141 197
            closeButton.setSize(new Dimension(30, 20));
142
            closeButton.setActionCommand("Cerrar");
198
            closeButton.setActionCommand("Close");
143 199
        }
144 200

  
145 201
        return closeButton;
146 202
    }
147 203
    
204
    /**
205
     * It  gets the change size button
206
     * @return
207
     */
208
    public JButton getSizeButton() {
209
        if (sizeButton == null) {
210
            sizeButton = new JButton("Avanzada");
211
            if (!(isMinimized))
212
                sizeButton.setText("Simple");
213
            sizeButton.setSize(new Dimension(30, 20));
214
            sizeButton.setActionCommand("Size");
215
        }
216
        return sizeButton;
217
    }    
148 218
    
149

  
219
    /**
220
     * It gets the checkBox area component
221
     * @return
222
     */
223
    public JCheckBox getAreaCheckBox(){
224
        if (areaCheckBox == null){
225
            areaCheckBox = new JCheckBox("Restringir el area de B?squeda");
226
            areaCheckBox.setActionCommand("areaCheckButton");
227
        }
228
        return areaCheckBox;
229
    }
230
    
231
    /**
232
     * It sets the listeners
233
     *
234
     */
150 235
    public void setDefaultButtonListeners() {
151 236
        getSearchButton().addActionListener(this);
152 237
        getCloseButton().addActionListener(this);
238
        getSizeButton().addActionListener(this);
239
        if (isMinimized){
240
            getAreaCheckBox().addItemListener(this);
241
            
242
        }
243
        
153 244
    }
154

  
155
    /* (non-Javadoc)
245
    
246
     /* (non-Javadoc)
156 247
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
157 248
     */
158 249
    public void actionPerformed(ActionEvent e) {
159 250
        //Buscar
160
        if (e.getActionCommand() == "Buscar") {
251
        if (e.getActionCommand() == "Search") {
161 252
            searchButtonActionPerformed();
162 253
        } 
163
        if (e.getActionCommand() == "Cerrar") {
254
        if (e.getActionCommand() == "Close") {
164 255
            closeButtonActionPerformed();
165 256
        }
257
        if (e.getActionCommand() == "Size") {
258
            sizeButtonActionPerformed();
259
        }        
260
        
261
    }    
262
       
263
    protected void sizeButtonActionPerformed(){
264
        parent.setVisible(false);
265
        SearchDialog panel = new SearchDialog(client,!(isMinimized),controlsPanel.getTitle());
166 266
    }
167 267
    
168 268
    protected void searchButtonActionPerformed(){
......
175 275
    }
176 276
    
177 277
    protected void closeButtonActionPerformed(){
178
        this.setVisible(false);
278
        parent.setVisible(false);
179 279
    }
180 280

  
281
    /**
282
     * It returns the query that the user has selected
283
     * @return
284
     */
181 285
    public Query doQuery() {
182
        return new Query(controlsPanel.getTitulo(),
183
            controlsPanel.getConcordancia(), controlsPanel.getResumen(),
184
            controlsPanel.getClave(), controlsPanel.getCategoria(),
185
            controlsPanel.getEscala(), controlsPanel.getProveedor(),
186
            controlsPanel.getFechaDe(), controlsPanel.getFechaA(),
187
            controlsPanel.getCoordenadas(), controlsPanel.getCoordenadasOpcion());
286
        Query query = new Query(controlsPanel.getTitle(),
287
            controlsPanel.getTitleOption(), controlsPanel.getAbstract(),
288
            controlsPanel.getKeys(), controlsPanel.getCathegory(),
289
            controlsPanel.getScale(), controlsPanel.getProvider(),
290
            controlsPanel.getDateFrom(), controlsPanel.getDateTo(),
291
            controlsPanel.getCoordinates(), controlsPanel.getCoordinatesOption());
292
        query.setMinimized(isMinimized);
293
        return query;
188 294
    }
189

  
295
    
296
    /**
297
     * This method realizes the search
298
     *
299
     */
190 300
    public void doSearch() {
191
        nodesRecords = cliente.getLnkICatalogServerDriver().getRecords(cliente.getUrl(),
301
        nodesRecords = client.getLnkICatalogServerDriver().getRecords(client.getUrl(),
192 302
                doQuery(), 1);
193 303

  
194 304
        if (nodesRecords == null) {
......
201 311
                JOptionPane.INFORMATION_MESSAGE);
202 312
        }
203 313
    }
314
    
315
    /**
316
     * This methos calls to present results form
317
     * @param nodesRecords
318
     */
204 319

  
205 320
    public void showResults(Node[] nodesRecords) {
206
        JDialog dialog = new ShowResultsDialog(cliente, nodesRecords, 1);
321
        JDialog dialog = new ShowResultsDialog(client, nodesRecords, 1);
207 322
    }
323

  
324
    /* (non-Javadoc)
325
     * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
326
     * This methodhave to be implemented in gvSIG to load the bbox to o the search
327
     */
328
    public void itemStateChanged(ItemEvent e) {
329
        
330
        
331
    }
332
    
333
    /**
334
     * It sets the title field into the form
335
     * @param Title
336
     */
337
    public void setTitle(String title){
338
        controlsPanel.setTitle(title);
339
    }
340

  
341

  
342
    /**
343
     * @param isMinimized The isMinimized to set.
344
     */
345
    public void setMinimized(boolean isMinimized) {
346
        this.isMinimized = isMinimized;
347
    }
208 348
}

Also available in: Unified diff