Statistics
| Revision:

root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / ui / ShowResultsPanel.java @ 3036

History | View | Annotate | Download (15.9 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 es.gva.cit.catalogClient.ui;
42

    
43
import es.gva.cit.catalogClient.parsers.AbstractTags;
44
import es.gva.cit.catalogClient.parsers.IndicioTags;
45
import es.gva.cit.catalogClient.parsers.LongTags;
46
import es.gva.cit.catalogClient.parsers.ShortTags;
47

    
48
import org.w3c.dom.Node;
49

    
50
import java.awt.AlphaComposite;
51
import java.awt.BorderLayout;
52
import java.awt.Color;
53
import java.awt.FlowLayout;
54
import java.awt.Font;
55
import java.awt.GradientPaint;
56
import java.awt.Graphics2D;
57
import java.awt.RenderingHints;
58
import java.awt.Shape;
59
import java.awt.font.TextLayout;
60
import java.awt.geom.AffineTransform;
61
import java.awt.geom.Rectangle2D;
62
import java.awt.image.BufferedImage;
63

    
64
import java.net.URL;
65

    
66
import javax.swing.BorderFactory;
67
import javax.swing.BoxLayout;
68
import javax.swing.ImageIcon;
69
import javax.swing.JButton;
70
import javax.swing.JEditorPane;
71
import javax.swing.JLabel;
72
import javax.swing.JPanel;
73
import javax.swing.JScrollPane;
74
import javax.swing.border.BevelBorder;
75

    
76

    
77
/**
78
 * @author Jorge Piera Llodra (piera_jor@gva.es)
79
*/
80
public class ShowResultsPanel extends JPanel {
81
    public static boolean mustShowThumbnails = true;
82
    private AbstractTags tags = null;
83
    private String protocol = null;
84
    private Node node = null;
85
    private URL imageURL = null;
86
    private URL serverURL = null;
87
    private JPanel descriptionPanel = null;
88
    private JEditorPane descriptionArea = null; //  @jve:decl-index=0:
89
    private JPanel linksPanel = null;
90
    private JPanel jPanel = null;
91
    private JButton descriptionButton = null; //  @jve:decl-index=0:
92
    private JLabel jLabel = null; //  @jve:decl-index=0:
93
    private JButton mapButton = null; //  @jve:decl-index=0:
94
    private JScrollPane descriptionScroll = null; //  @jve:decl-index=0:
95
    private JPanel imagePanel = null;
96
    private JLabel jLabel1 = null;
97
    private JLabel imageLabel = null;
98
    private JPanel jPanel1 = null;
99
    private JPanel nextLastPanel = null;
100
    private JButton lastButton = null;
101
    private JLabel textLabel = null;
102
    private JButton nextButton = null;
103
    private int numRecords;
104

    
105
        private JButton closeButton = null;
106
    /**
107
     * Constaructor
108
     * @param node
109
     * Answer Node
110
     * @param protocol
111
     * Search protocol
112
     * @param numRecords
113
     * Number of records returned by the query
114
     * @param server
115
     * Server URL
116
     */
117
    public ShowResultsPanel(Node node, String protocol, int numRecords,URL serverURL) {
118
        super();
119
        this.protocol = protocol;
120
        this.node = node;
121
        this.numRecords = numRecords;
122
        this.serverURL = serverURL;
123

    
124
        initialize();
125
    }
126

    
127
    /**
128
     * This method initializes this
129
     *
130
     * @return void
131
     */
132
    private void initialize() {
133
        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
134
        this.setSize(703, 364);
135
        this.add(getNextLastPanel(), null);
136
        this.add(getJPanel1(), null);
137
        this.add(getDescriptionPanel(), null);
138
        this.add(getJPanel(), null);
139
        this.add(getLinksPanel(), null);
140
        actualizaLabel(1);
141
    }
142

    
143
    /**
144
     * Actualiza el valor de la cadena de taexto que muestra los resultados
145
     * @param number
146
     * Registro actual
147
     */
148
    public void actualizaLabel(int number) {
149
        textLabel.setText("Resultados: " + String.valueOf(number) + " de " +
150
            String.valueOf(this.numRecords));
151
    }
152

    
153
    /**
154
     * @param descripcionBoton The descripcionBoton to set.
155
     */
156
    public void setDescripcionBoton(JButton descripcionBoton) {
157
        this.descriptionButton = descripcionBoton;
158
    }
159

    
160
    /**
161
     * @param mapButton The mapButton to set.
162
     */
163
    public void setMapButton(JButton mapButton) {
164
        this.mapButton = mapButton;
165
    }
166

    
167
    /**
168
     * This method initializes jPanel
169
     *
170
     * @return javax.swing.JPanel
171
     */
172
    private JPanel getDescriptionPanel() {
173
        if (descriptionPanel == null) {
174
            jLabel1 = new JLabel();
175
            descriptionPanel = new JPanel();
176
            descriptionPanel.setLayout(new BoxLayout(descriptionPanel,
177
                    BoxLayout.X_AXIS));
178
            descriptionPanel.setPreferredSize(new java.awt.Dimension(600, 300));
179
            jLabel1.setText("");
180
            jLabel1.setPreferredSize(new java.awt.Dimension(40, 0));
181
            descriptionPanel.add(getDescriptionScroll(), null);
182

    
183
            if (mustShowThumbnails) {
184
                descriptionPanel.add(jLabel1, null);
185
                descriptionPanel.add(getImagePanel(), null);
186
            } else {
187
                descriptionPanel.setPreferredSize(new java.awt.Dimension(400,
188
                        300));
189
            }
190
        }
191

    
192
        return descriptionPanel;
193
    }
194

    
195
    /**
196
     * This method initializes jTextArea
197
     *
198
     * @return javax.swing.JTextArea
199
     */
200
    public JEditorPane getDescriptionArea() {
201
        if (descriptionArea == null) {
202
            String array = "";
203
            descriptionArea = new JEditorPane();
204
            descriptionArea.setPreferredSize(new java.awt.Dimension(400, 300));
205
            descriptionArea.setContentType("text/html");
206
            loadTextNewRecord(this.node, this.protocol);
207
        }
208

    
209
        return descriptionArea;
210
    }
211

    
212
    /**
213
     * This method initializes jPanel
214
     *
215
     * @return javax.swing.JPanel
216
     */
217
    private JPanel getLinksPanel() {
218
        if (linksPanel == null) {
219
            linksPanel = new JPanel();
220
            linksPanel.add(getDescriptionButton(), null);
221
            linksPanel.add(getJLabel(), null);
222
            linksPanel.add(getMapButton(), null);
223
            linksPanel.add(getCloseButton(), null);
224
        }
225

    
226
        return linksPanel;
227
    }
228

    
229
    /**
230
     * This method initializes jPanel
231
     *
232
     * @return javax.swing.JPanel
233
     */
234
    private JPanel getJPanel() {
235
        if (jPanel == null) {
236
            jPanel = new JPanel();
237
        }
238

    
239
        return jPanel;
240
    }
241

    
242
    /**
243
     * This method initializes jButton
244
     *
245
     * @return javax.swing.JButton
246
     */
247
    public JButton getDescriptionButton() {
248
        if (descriptionButton == null) {
249
            descriptionButton = new JButton();
250
            descriptionButton.setText("Descripcion");
251
        }
252

    
253
        return descriptionButton;
254
    }
255

    
256
    /**
257
     * This method initializes jLabel
258
     *
259
     * @return javax.swing.JLabel
260
     */
261
    private JLabel getJLabel() {
262
        if (jLabel == null) {
263
            jLabel = new JLabel();
264
        }
265

    
266
        return jLabel;
267
    }
268

    
269
    /**
270
     * This method initializes jButton 1
271
     *
272
     * @return javax.swing.JButton
273
     */
274
    public JButton getMapButton() {
275
        if (mapButton == null) {
276
            mapButton = new JButton();
277
            mapButton.setText("A?adir Capa");
278
            //mapButton.setPreferredSize(new java.awt.Dimension(102, 26));
279
        }
280

    
281
        return mapButton;
282
    }
283

    
284
    /**
285
     * This method initializes jScrollPane
286
     *
287
     * @return javax.swing.JScrollPane
288
     */
289
    public JScrollPane getDescriptionScroll() {
290
        if (descriptionScroll == null) {
291
            descriptionScroll = new JScrollPane();
292
            descriptionScroll.setViewportView(getDescriptionArea());
293
            descriptionScroll.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
294
            descriptionScroll.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
295
            descriptionScroll.setPreferredSize(new java.awt.Dimension(400, 250));
296
        }
297

    
298
        return descriptionScroll;
299
    }
300

    
301
    /**
302
     * @return Returns the tags.
303
     */
304
    public AbstractTags getTags() {
305
        return tags;
306
    }
307

    
308
    /**
309
     * @param tags The tags to set.
310
     */
311
    public void setTags(AbstractTags tags) {
312
        this.tags = tags;
313
    }
314

    
315
    public void loadTextNewRecord(Node node, String protocol) {
316
        if (protocol.equals("Z3950")) {
317
            this.setTags(new ShortTags(node,serverURL));
318
        } else if (protocol.equals("SRW")) {
319
            this.setTags(new LongTags(node));
320
        } else {
321
            this.setTags(new IndicioTags(node));
322
        }
323

    
324
        descriptionArea.setText(this.getHtml());
325
        descriptionArea.setCaretPosition(0);
326

    
327
        //setImageURL(this.getTags().getImage());
328
        if (imageLabel != null) {
329
            imageLabel.setIcon(getImgIcon(this.getTags().getImage()));
330
        }
331

    
332
        this.repaint();
333
    }
334

    
335
    private String getHtml() {
336
        StringBuffer html = new StringBuffer();
337
        html.append("<html><body>");
338
        html.append("<font COLOR=\"#0000FF\">");
339

    
340
        if (this.getTags().getTitle() != null) {
341
            html.append(this.getTags().getTitle());
342
        }
343

    
344
        html.append("<font COLOR=\"#000000\">");
345

    
346
        if ((this.getTags().getAbstract_() != null) &&
347
                (!(this.getTags().getAbstract_().equals("")))) {
348
            html.append("<br>");
349
            html.append("<br>");
350
            html.append("<b>Resumen: </b>");
351
            html.append(this.getTags().getAbstract_());
352
        }
353

    
354
        if ((this.getTags().getPurpose() != null) &&
355
                (!(this.getTags().getPurpose().equals("")))) {
356
            html.append("<br>");
357
            html.append("<br>");
358
            html.append("<b>Prop?sito: </b>");
359
            html.append(this.getTags().getPurpose());
360
        }
361

    
362
        if (this.getTags().getKeyWords() != null) {
363
            if (this.getTags().getKeyWords()[0] != null) {
364
                html.append("<br>");
365
                html.append("<br>");
366
                html.append("<b> Palabras Clave:</b>");
367
                html.append(this.getTags().getKeyWords()[0]);
368
            }
369
        }
370

    
371
        if (this.getTags().getKeyWords() != null) {
372
            for (int i = 1; i < this.getTags().getKeyWords().length; i++)
373
                if (this.getTags().getKeyWords()[i] != null) {
374
                    html.append(", " + this.getTags().getKeyWords()[i]);
375
                }
376
        }
377

    
378
        html.append("</body></html>");
379

    
380
        return html.toString();
381
    }
382

    
383
    /**
384
     * This method initializes jPanel1
385
     *
386
     * @return javax.swing.JPanel
387
     */
388
    private JPanel getImagePanel() {
389
        if (imagePanel == null) {
390
            imagePanel = new JPanel();
391
            imagePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
392
            imagePanel.setMaximumSize(new java.awt.Dimension(207, 210));
393

    
394
            JPanel borderPanel = new JPanel();
395
            borderPanel.setLayout(new BorderLayout());
396
            borderPanel.setBorder(BorderFactory.createCompoundBorder(
397
                    BorderFactory.createBevelBorder(BevelBorder.LOWERED),
398
                    BorderFactory.createEmptyBorder(5, 5, 5, 5)));
399
            imagePanel.add(borderPanel, BorderLayout.CENTER);
400
            imageLabel = new JLabel(getImgIcon(getTags().getImage()));
401
            borderPanel.add(imageLabel, BorderLayout.CENTER);
402
        }
403

    
404
        return imagePanel;
405
    }
406

    
407
    public ImageIcon getImgIcon(BufferedImage pic) {
408
        BufferedImage img = new BufferedImage(180, 180,
409
                BufferedImage.TYPE_INT_ARGB);
410
        Graphics2D g = img.createGraphics();
411

    
412
        if (pic != null) {
413
            double fw = 1.0;
414
            double fh = 1.0;
415
            if (pic.getWidth() > pic.getHeight()){
416
                fw = 180D / pic.getWidth();
417
                fh = fw; 
418
            }else{
419
                fh = 180D / pic.getHeight();
420
                fw = fh;
421
            }
422
                       
423
            AffineTransform mat = AffineTransform.getScaleInstance(fw, fh);
424
            g.drawImage(pic, mat, null);
425
        } else {
426
            
427
            g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
428
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
429
            g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
430
                RenderingHints.VALUE_FRACTIONALMETRICS_ON);
431
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
432
                RenderingHints.VALUE_ANTIALIAS_ON);
433
            g.setFont(new Font("Lucida Bright", Font.ITALIC, 30));
434
            g.rotate(-Math.PI / 4, 100D, 100D);
435

    
436
            String text = "NO PICTURE"; //DateFormat.getDateInstance(DateFormat.SHORT).format(new Date());
437
            TextLayout tl = new TextLayout(text, g.getFont(),
438
                    g.getFontRenderContext());
439
            Rectangle2D bounds = tl.getBounds();
440
            double x = ((180D - bounds.getWidth()) / 2) - bounds.getX();
441
            double y = ((180D - bounds.getHeight()) / 2) - bounds.getY();
442
            Shape outline = tl.getOutline(AffineTransform.getTranslateInstance(x +
443
                        2, y + 1));
444
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
445
                    0.3f));
446
            g.setPaint(Color.WHITE);
447
            g.draw(outline);
448
            g.setPaint(new GradientPaint(0, 0, new Color(192, 192, 255), 30,
449
                    20, new Color(255, 255, 64), true));
450
            tl.draw(g, (float) x, (float) y);
451
        }
452

    
453
        g.dispose();
454

    
455
        return new ImageIcon(img);
456
    }
457

    
458
    /**
459
     * @return Returns the imageURL.
460
     */
461
    public URL getImageURL() {
462
        return imageURL;
463
    }
464

    
465
    /**
466
     * @param imageURL The imageURL to set.
467
     */
468
    public void setImageURL(URL imageURL) {
469
        this.imageURL = imageURL;
470
    }
471

    
472
    /**
473
     * This method initializes jPanel1
474
     *
475
     * @return javax.swing.JPanel
476
     */
477
    private JPanel getJPanel1() {
478
        if (jPanel1 == null) {
479
            jPanel1 = new JPanel();
480
        }
481

    
482
        return jPanel1;
483
    }
484

    
485
    /**
486
     * This method initializes jPanel2
487
     *
488
     * @return javax.swing.JPanel
489
     */
490
    private JPanel getNextLastPanel() {
491
        if (nextLastPanel == null) {
492
            textLabel = new JLabel();
493
            nextLastPanel = new JPanel();
494
            textLabel.setText("JLabel");
495
            nextLastPanel.add(getLastButton(), null);
496
            nextLastPanel.add(textLabel, null);
497
            nextLastPanel.add(getNextButton(), null);
498
        }
499

    
500
        return nextLastPanel;
501
    }
502

    
503
    /**
504
     * This method initializes jButton
505
     *
506
     * @return javax.swing.JButton
507
     */
508
    public JButton getLastButton() {
509
        if (lastButton == null) {
510
            lastButton = new JButton();
511
            lastButton.setText("Anterior");
512
            lastButton.setEnabled(false);
513
        }
514

    
515
        return lastButton;
516
    }
517

    
518
    /**
519
     * This method initializes jButton
520
     *
521
     * @return javax.swing.JButton
522
     */
523
    public JButton getNextButton() {
524
        if (nextButton == null) {
525
            nextButton = new JButton();
526
            nextButton.setText("Siguiente");
527

    
528
            if (this.numRecords < 2) {
529
                nextButton.setEnabled(false);
530
            }
531
        }
532

    
533
        return nextButton;
534
    }
535
    
536

    
537
  
538
        /**
539
         * This method initializes jButton        
540
         *         
541
         * @return javax.swing.JButton        
542
         */    
543
        public JButton getCloseButton() {
544
                if (closeButton == null) {
545
                        closeButton = new JButton();
546
                        closeButton.setText("Cerrar");
547
                        closeButton.setPreferredSize(new java.awt.Dimension(102,26));
548
                }
549
                return closeButton;
550
        }
551
 } //  @jve:decl-index=0:visual-constraint="107,10"