Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / ui / showResults / ShowResultsPanel.java @ 3613

History | View | Annotate | Download (16.9 KB)

1

    
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
*
4
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
*
20
* For more information, contact:
21
*
22
*  Generalitat Valenciana
23
*   Conselleria d'Infraestructures i Transport
24
*   Av. Blasco Ib??ez, 50
25
*   46010 VALENCIA
26
*   SPAIN
27
*
28
*      +34 963862235
29
*   gvsig@gva.es
30
*      www.gvsig.gva.es
31
*
32
*    or
33
*
34
*   IVER T.I. S.A
35
*   Salamanca 50
36
*   46005 Valencia
37
*   Spain
38
*
39
*   +34 963163400
40
*   dac@iver.es
41
*/
42
package es.gva.cit.catalogClient.ui.showResults;
43
import es.gva.cit.catalogClient.metadataXML.XMLNode;
44
import es.gva.cit.catalogClient.schemas.discoverer.DiscovererFormat;
45
import es.gva.cit.catalogClient.schemas.discoverer.Record;
46
import es.gva.cit.catalogClient.traductor.ITranslator;
47
import es.gva.cit.catalogClient.traductor.Translator;
48
import java.awt.AlphaComposite;
49
import java.awt.BorderLayout;
50
import java.awt.Color;
51
import java.awt.FlowLayout;
52
import java.awt.Font;
53
import java.awt.GradientPaint;
54
import java.awt.Graphics2D;
55
import java.awt.RenderingHints;
56
import java.awt.Shape;
57
import java.awt.font.TextLayout;
58
import java.awt.geom.AffineTransform;
59
import java.awt.geom.Rectangle2D;
60
import java.awt.image.BufferedImage;
61
import java.net.URL;
62
import javax.swing.BorderFactory;
63
import javax.swing.BoxLayout;
64
import javax.swing.ImageIcon;
65
import javax.swing.JButton;
66
import javax.swing.JEditorPane;
67
import javax.swing.JLabel;
68
import javax.swing.JPanel;
69
import javax.swing.JScrollPane;
70
import javax.swing.border.BevelBorder;
71

    
72
/**
73
 * 
74
 * 
75
 * 
76
 * @author Jorge Piera Llodra (piera_jor@gva.es)
77
 */
78
public class ShowResultsPanel extends JPanel {
79

    
80
/**
81
 * 
82
 * 
83
 */
84
    public static boolean mustShowThumbnails = true;
85
/**
86
 * 
87
 * 
88
 */
89
    private Record tags = null;
90

    
91
/**
92
 * 
93
 * 
94
 */
95
    private String protocol = null;
96
/**
97
 * 
98
 * 
99
 */
100
    private XMLNode node = null;
101

    
102
/**
103
 * 
104
 * 
105
 */
106
    private URL imageURL = null;
107
/**
108
 * 
109
 * 
110
 */
111
    private JPanel descriptionPanel = null;
112
/**
113
 * 
114
 * 
115
 */
116
    private JEditorPane descriptionArea = null;
117
//  @jve:decl-index=0:
118
/**
119
 * 
120
 * 
121
 */
122
    private JPanel linksPanel = null;
123
/**
124
 * 
125
 * 
126
 */
127
    private JPanel jPanel = null;
128
/**
129
 * 
130
 * 
131
 */
132
    private JButton descriptionButton = null;
133
//  @jve:decl-index=0:
134
/**
135
 * 
136
 * 
137
 */
138
    private JLabel jLabel = null;
139
//  @jve:decl-index=0:
140
/**
141
 * 
142
 * 
143
 */
144
    private JButton mapButton = null;
145
//  @jve:decl-index=0:
146
/**
147
 * 
148
 * 
149
 */
150
    private JScrollPane descriptionScroll = null;
151
//  @jve:decl-index=0:
152
/**
153
 * 
154
 * 
155
 */
156
    private JPanel imagePanel = null;
157
/**
158
 * 
159
 * 
160
 */
161
    private JLabel jLabel1 = null;
162
/**
163
 * 
164
 * 
165
 */
166
    private JLabel imageLabel = null;
167
/**
168
 * 
169
 * 
170
 */
171
    private JPanel jPanel1 = null;
172
/**
173
 * 
174
 * 
175
 */
176
    private JPanel nextLastPanel = null;
177
/**
178
 * 
179
 * 
180
 */
181
    private JButton lastButton = null;
182
/**
183
 * 
184
 * 
185
 */
186
    private JLabel textLabel = null;
187
/**
188
 * 
189
 * 
190
 */
191
    private JButton nextButton = null;
192

    
193
/**
194
 * 
195
 * 
196
 */
197
    private int numRecords;
198
/**
199
 * 
200
 * 
201
 */
202
    private DiscovererFormat discoverer = null;
203
/**
204
 * 
205
 * 
206
 */
207
    private JButton closeButton = null;
208
/**
209
 * 
210
 * 
211
 */
212
    private ITranslator translator = null;
213

    
214
/**
215
 * Constaructor
216
 * 
217
 * @param server Server URL
218
 * 
219
 * @param node Answer Node
220
 * @param protocol Search protocol
221
 * @param numRecords Number of records returned by the query
222
 * @param serverURL 
223
 * @param translator 
224
 */
225
    public  ShowResultsPanel(XMLNode node, String protocol, int numRecords, URL serverURL, ITranslator translator) {        
226
        super();
227
        this.protocol = protocol;
228
        this.node = node;
229
        this.numRecords = numRecords;
230
        this.translator = translator;
231
        discoverer = new DiscovererFormat(protocol,serverURL);
232
        initialize();
233
    } 
234

    
235
/**
236
 * This method initializes this
237
 * 
238
 */
239
    private void initialize() {        
240
        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
241
        this.setSize(703, 364);
242
        this.add(getNextLastPanel(), null);
243
        this.add(getJPanel1(), null);
244
        this.add(getDescriptionPanel(), null);
245
        this.add(getJPanel(), null);
246
        this.add(getLinksPanel(), null);
247
        actualizaLabel(1);
248
    } 
249

    
250
/**
251
 * Actualiza el valor de la cadena de taexto que muestra los resultados
252
 * 
253
 * 
254
 * @param number Registro actual
255
 */
256
    public void actualizaLabel(int number) {        
257
        textLabel.setText(Translator.getText(translator,"results") + ": " + String.valueOf(number) + " " + Translator.getText(translator,"of") + " " +
258
            String.valueOf(this.numRecords));
259
    } 
260

    
261
/**
262
 * 
263
 * 
264
 * 
265
 * @param descripcionBoton The descripcionBoton to set.
266
 */
267
    public void setDescripcionBoton(JButton descripcionBoton) {        
268
        this.descriptionButton = descripcionBoton;
269
    } 
270

    
271
/**
272
 * 
273
 * 
274
 * 
275
 * @param mapButton The mapButton to set.
276
 */
277
    public void setMapButton(JButton mapButton) {        
278
        this.mapButton = mapButton;
279
    } 
280

    
281
/**
282
 * This method initializes jPanel
283
 * 
284
 * 
285
 * @return javax.swing.JPanel
286
 */
287
    private JPanel getDescriptionPanel() {        
288
        if (descriptionPanel == null) {
289
            jLabel1 = new JLabel();
290
            descriptionPanel = new JPanel();
291
            descriptionPanel.setLayout(new BoxLayout(descriptionPanel,
292
                    BoxLayout.X_AXIS));
293
            descriptionPanel.setPreferredSize(new java.awt.Dimension(600, 300));
294
            jLabel1.setText("");
295
            jLabel1.setPreferredSize(new java.awt.Dimension(40, 0));
296
            descriptionPanel.add(getDescriptionScroll(), null);
297
            if (mustShowThumbnails) {
298
                descriptionPanel.add(jLabel1, null);
299
                descriptionPanel.add(getImagePanel(), null);
300
            } else {
301
                descriptionPanel.setPreferredSize(new java.awt.Dimension(400,
302
                        300));
303
            }
304
        }
305
        return descriptionPanel;
306
    } 
307

    
308
/**
309
 * This method initializes jTextArea
310
 * 
311
 * 
312
 * @return javax.swing.JTextArea
313
 */
314
    public JEditorPane getDescriptionArea() {        
315
        if (descriptionArea == null) {
316
            descriptionArea = new JEditorPane();
317
            descriptionArea.setPreferredSize(new java.awt.Dimension(400, 300));
318
            descriptionArea.setContentType("text/html");
319
            loadTextNewRecord(this.node, this.protocol);
320
        }
321
        return descriptionArea;
322
    } 
323

    
324
/**
325
 * This method initializes jPanel
326
 * 
327
 * 
328
 * @return javax.swing.JPanel
329
 */
330
    private JPanel getLinksPanel() {        
331
        if (linksPanel == null) {
332
            linksPanel = new JPanel();
333
            linksPanel.add(getDescriptionButton(), null);
334
            linksPanel.add(getJLabel(), null);
335
            linksPanel.add(getMapButton(), null);
336
            linksPanel.add(getCloseButton(), null);
337
        }
338
        return linksPanel;
339
    } 
340

    
341
/**
342
 * This method initializes jPanel
343
 * 
344
 * 
345
 * @return javax.swing.JPanel
346
 */
347
    private JPanel getJPanel() {        
348
        if (jPanel == null) {
349
            jPanel = new JPanel();
350
        }
351
        return jPanel;
352
    } 
353

    
354
/**
355
 * This method initializes jButton
356
 * 
357
 * 
358
 * @return javax.swing.JButton
359
 */
360
    public JButton getDescriptionButton() {        
361
        if (descriptionButton == null) {
362
            descriptionButton = new JButton();
363
            descriptionButton.setText(Translator.getText(translator,"description"));
364
            descriptionButton.setActionCommand("description");
365
        }
366
        return descriptionButton;
367
    } 
368

    
369
/**
370
 * This method initializes jLabel
371
 * 
372
 * 
373
 * @return javax.swing.JLabel
374
 */
375
    private JLabel getJLabel() {        
376
        if (jLabel == null) {
377
            jLabel = new JLabel();
378
        }
379
        return jLabel;
380
    } 
381

    
382
/**
383
 * This method initializes jButton 1
384
 * 
385
 * 
386
 * @return javax.swing.JButton
387
 */
388
    public JButton getMapButton() {        
389
        if (mapButton == null) {
390
            mapButton = new JButton();
391
            mapButton.setText(Translator.getText(translator,"layer"));
392
            mapButton.setActionCommand("layer");
393
        }
394
        return mapButton;
395
    } 
396

    
397
/**
398
 * This method initializes jScrollPane
399
 * 
400
 * 
401
 * @return javax.swing.JScrollPane
402
 */
403
    public JScrollPane getDescriptionScroll() {        
404
        if (descriptionScroll == null) {
405
            descriptionScroll = new JScrollPane();
406
            descriptionScroll.setViewportView(getDescriptionArea());
407
            descriptionScroll.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
408
            descriptionScroll.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
409
            descriptionScroll.setPreferredSize(new java.awt.Dimension(400, 250));
410
        }
411
        return descriptionScroll;
412
    } 
413

    
414
/**
415
 * 
416
 * 
417
 * 
418
 * @return Returns the tags.
419
 */
420
    public Record getTags() {        
421
        return tags;
422
    } 
423

    
424
/**
425
 * 
426
 * 
427
 * 
428
 * @param tags The tags to set.
429
 */
430
    public void setTags(Record tags) {        
431
        this.tags = tags;
432
    } 
433

    
434
/**
435
 * 
436
 * 
437
 * 
438
 * @param node 
439
 * @param protocol 
440
 */
441
    public void loadTextNewRecord(XMLNode node, String protocol) {        
442
        setTags(discoverer.DiscoverAndParse(node));
443
        
444
        descriptionArea.setText(this.getHtml());
445
        descriptionArea.setCaretPosition(0);
446
        //setImageURL(this.getTags().getImage());
447
        if (imageLabel != null) {
448
            imageLabel.setIcon(getImgIcon(this.getTags().getImage()));
449
        }
450
        this.repaint();
451
    } 
452

    
453
/**
454
 * 
455
 * 
456
 * 
457
 * @return 
458
 */
459
    private String getHtml() {        
460
        StringBuffer html = new StringBuffer();
461
        html.append("<html><body>");
462
        html.append("<font COLOR=\"#0000FF\">");
463
        if (this.getTags().getTitle() != null) {
464
            html.append(this.getTags().getTitle());
465
        }
466
        html.append("<font COLOR=\"#000000\">");
467
        if ((this.getTags().getAbstract_() != null) &&
468
                (!(this.getTags().getAbstract_().equals("")))) {
469
            html.append("<br>");
470
            html.append("<br>");
471
            html.append("<b>" + Translator.getText(translator,"abstract") + ": </b>");
472
            html.append(this.getTags().getAbstract_());
473
        }
474
        if ((this.getTags().getPurpose() != null) &&
475
                (!(this.getTags().getPurpose().equals("")))) {
476
            html.append("<br>");
477
            html.append("<br>");
478
            html.append("<b>" + Translator.getText(translator,"purpose") +": </b>");
479
            html.append(this.getTags().getPurpose());
480
        }
481
        if (this.getTags().getKeyWords() != null) {
482
            if (this.getTags().getKeyWords()[0] != null) {
483
                html.append("<br>");
484
                html.append("<br>");
485
                html.append("<b>" + Translator.getText(translator,"keyWords") + ":</b>");
486
                html.append(this.getTags().getKeyWords()[0]);
487
            }
488
        }
489
        if (this.getTags().getKeyWords() != null) {
490
            for (int i = 1; i < this.getTags().getKeyWords().length; i++)
491
                if (this.getTags().getKeyWords()[i] != null) {
492
                    html.append(", " + this.getTags().getKeyWords()[i]);
493
                }
494
        }
495
        html.append("</body></html>");
496
        return html.toString();
497
    } 
498

    
499
/**
500
 * This method initializes jPanel1
501
 * 
502
 * 
503
 * @return javax.swing.JPanel
504
 */
505
    private JPanel getImagePanel() {        
506
        if (imagePanel == null) {
507
            imagePanel = new JPanel();
508
            imagePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
509
            imagePanel.setMaximumSize(new java.awt.Dimension(207, 210));
510
            JPanel borderPanel = new JPanel();
511
            borderPanel.setLayout(new BorderLayout());
512
            borderPanel.setBorder(BorderFactory.createCompoundBorder(
513
                    BorderFactory.createBevelBorder(BevelBorder.LOWERED),
514
                    BorderFactory.createEmptyBorder(5, 5, 5, 5)));
515
            imagePanel.add(borderPanel, BorderLayout.CENTER);
516
            imageLabel = new JLabel(getImgIcon(getTags().getImage()));
517
            borderPanel.add(imageLabel, BorderLayout.CENTER);
518
        }
519
        return imagePanel;
520
    } 
521

    
522
/**
523
 * 
524
 * 
525
 * 
526
 * @return 
527
 * @param pic 
528
 */
529
    public ImageIcon getImgIcon(BufferedImage pic) {        
530
        BufferedImage img = new BufferedImage(180, 180,
531
                BufferedImage.TYPE_INT_ARGB);
532
        Graphics2D g = img.createGraphics();
533
        if (pic != null) {
534
            double fw =         1.0;
535
            double fh =         1.0;
536
            if (pic.getWidth() > pic.getHeight()){
537
                fw = 180D / pic.getWidth();
538
                fh = fw; 
539
            }else{
540
                fh = 180D / pic.getHeight();
541
                fw = fh;
542
            }
543
                       
544
            AffineTransform mat = AffineTransform.getScaleInstance(fw, fh);
545
            g.drawImage(pic, mat, null);
546
        } else {
547
            
548
            g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
549
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
550
            g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
551
                RenderingHints.VALUE_FRACTIONALMETRICS_ON);
552
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
553
                RenderingHints.VALUE_ANTIALIAS_ON);
554
            g.setFont(new Font("Lucida Bright", Font.ITALIC, 30));
555
            g.rotate(-Math.PI / 4, 100D, 100D);
556
            String text = "NO PICTURE"; //DateFormat.getDateInstance(DateFormat.SHORT).format(new Date());
557
            TextLayout tl = new TextLayout(text, g.getFont(),
558
                    g.getFontRenderContext());
559
            Rectangle2D bounds = tl.getBounds();
560
            double x = (( 180D - bounds.getWidth()) / 2) - bounds.getX();
561
            double y = (( 180D - bounds.getHeight()) / 2) - bounds.getY();
562
            Shape outline = tl.getOutline(AffineTransform.getTranslateInstance(x +
563
                        2, y + 1));
564
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));
565
            g.setPaint(Color.WHITE);
566
            g.draw(outline);
567
            g.setPaint(new GradientPaint(0, 0, new Color(192, 192, 255), 30,
568
                    20, new Color(255, 255, 64), true));
569
            tl.draw(g, (float) x, (float) y);
570
        }
571
        g.dispose();
572
        return new ImageIcon(img);
573
    } 
574

    
575
/**
576
 * 
577
 * 
578
 * 
579
 * @return Returns the imageURL.
580
 */
581
    public URL getImageURL() {        
582
        return imageURL;
583
    } 
584

    
585
/**
586
 * 
587
 * 
588
 * 
589
 * @param imageURL The imageURL to set.
590
 */
591
    public void setImageURL(URL imageURL) {        
592
        this.imageURL = imageURL;
593
    } 
594

    
595
/**
596
 * This method initializes jPanel1
597
 * 
598
 * 
599
 * @return javax.swing.JPanel
600
 */
601
    private JPanel getJPanel1() {        
602
        if (jPanel1 == null) {
603
            jPanel1 = new JPanel();
604
        }
605
        return jPanel1;
606
    } 
607

    
608
/**
609
 * This method initializes jPanel2
610
 * 
611
 * 
612
 * @return javax.swing.JPanel
613
 */
614
    private JPanel getNextLastPanel() {        
615
        if (nextLastPanel == null) {
616
            textLabel = new JLabel();
617
            nextLastPanel = new JPanel();
618
            textLabel.setText("JLabel");
619
            nextLastPanel.add(getLastButton(), null);
620
            nextLastPanel.add(textLabel, null);
621
            nextLastPanel.add(getNextButton(), null);
622
        }
623
        return nextLastPanel;
624
    } 
625

    
626
/**
627
 * This method initializes jButton
628
 * 
629
 * 
630
 * @return javax.swing.JButton
631
 */
632
    public JButton getLastButton() {        
633
        if (lastButton == null) {
634
            lastButton = new JButton();
635
            lastButton.setText(Translator.getText(translator,"last"));
636
            lastButton.setActionCommand("last");
637
            lastButton.setEnabled(false);
638
        }
639
        return lastButton;
640
    } 
641

    
642
/**
643
 * This method initializes jButton
644
 * 
645
 * 
646
 * @return javax.swing.JButton
647
 */
648
    public JButton getNextButton() {        
649
        if (nextButton == null) {
650
            nextButton = new JButton();
651
            nextButton.setText(Translator.getText(translator,"next"));
652
            nextButton.setActionCommand("next");
653
            
654
            if (this.numRecords < 2) {
655
                nextButton.setEnabled(false);
656
            }
657
        }
658
        return nextButton;
659
    } 
660

    
661
/**
662
 * This method initializes jButton
663
 * 
664
 * 
665
 * @return javax.swing.JButton
666
 */
667
    public JButton getCloseButton() {        
668
                if (closeButton == null) {
669
                        closeButton = new JButton();
670
                        closeButton.setText(Translator.getText(translator,"close"));
671
                        closeButton.setActionCommand("close");
672
                        closeButton.setPreferredSize(new java.awt.Dimension(102,26));
673
                }
674
                return closeButton;
675
    } 
676
 }
677
//  @jve:decl-index=0:visual-constraint="107,10"