Statistics
| Revision:

svn-gvsig-desktop / tags / Root_v06 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / ui / showResults / ShowResultsPanel.java @ 4811

History | View | Annotate | Download (17.2 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.Dimension;
52
import java.awt.FlowLayout;
53
import java.awt.Font;
54
import java.awt.GradientPaint;
55
import java.awt.Graphics2D;
56
import java.awt.RenderingHints;
57
import java.awt.Shape;
58
import java.awt.font.TextLayout;
59
import java.awt.geom.AffineTransform;
60
import java.awt.geom.Rectangle2D;
61
import java.awt.image.BufferedImage;
62
import java.net.URL;
63
import javax.swing.BorderFactory;
64
import javax.swing.BoxLayout;
65
import javax.swing.ImageIcon;
66
import javax.swing.JButton;
67
import javax.swing.JEditorPane;
68
import javax.swing.JLabel;
69
import javax.swing.JPanel;
70
import javax.swing.JScrollPane;
71
import javax.swing.border.BevelBorder;
72

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
385
/**
386
 * This method initializes jButton 1
387
 * 
388
 * 
389
 * @return javax.swing.JButton
390
 */
391
    public JButton getMapButton() {        
392
        if (mapButton == null) {
393
            mapButton = new JButton();
394
            mapButton.setText(Translator.getText(translator,"addLayer"));
395
            mapButton.setActionCommand("layer");
396
            mapButton.setPreferredSize(new Dimension(95, 23));
397
        }
398
        return mapButton;
399
    } 
400

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

    
418
/**
419
 * 
420
 * 
421
 * 
422
 * @return Returns the tags.
423
 */
424
    public Record getTags() {        
425
        return tags;
426
    } 
427

    
428
/**
429
 * 
430
 * 
431
 * 
432
 * @param tags The tags to set.
433
 */
434
    public void setTags(Record tags) {        
435
        this.tags = tags;
436
    } 
437

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

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

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

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

    
579
/**
580
 * 
581
 * 
582
 * 
583
 * @return Returns the imageURL.
584
 */
585
    public URL getImageURL() {        
586
        return imageURL;
587
    } 
588

    
589
/**
590
 * 
591
 * 
592
 * 
593
 * @param imageURL The imageURL to set.
594
 */
595
    public void setImageURL(URL imageURL) {        
596
        this.imageURL = imageURL;
597
    } 
598

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

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

    
630
/**
631
 * This method initializes jButton
632
 * 
633
 * 
634
 * @return javax.swing.JButton
635
 */
636
    public JButton getLastButton() {        
637
        if (lastButton == null) {
638
            lastButton = new JButton();
639
            lastButton.setText(Translator.getText(translator,"last"));
640
            lastButton.setActionCommand("last");
641
            lastButton.setEnabled(false);
642
            lastButton.setPreferredSize(new Dimension(95, 23));
643
        }
644
        return lastButton;
645
    } 
646

    
647
/**
648
 * This method initializes jButton
649
 * 
650
 * 
651
 * @return javax.swing.JButton
652
 */
653
    public JButton getNextButton() {        
654
        if (nextButton == null) {
655
            nextButton = new JButton();
656
            nextButton.setText(Translator.getText(translator,"next"));
657
            nextButton.setActionCommand("next");
658
              nextButton.setPreferredSize(new Dimension(95, 23));
659
            if (this.numRecords < 2) {
660
                nextButton.setEnabled(false);
661
            }
662
        }
663
        return nextButton;
664
    } 
665

    
666
/**
667
 * This method initializes jButton
668
 * 
669
 * 
670
 * @return javax.swing.JButton
671
 */
672
    public JButton getCloseButton() {        
673
                if (closeButton == null) {
674
                        closeButton = new JButton();
675
                        closeButton.setText(Translator.getText(translator,"close"));
676
                        closeButton.setActionCommand("close");
677
                        closeButton.setPreferredSize(new Dimension(80, 23));
678
                }
679
                return closeButton;
680
    } 
681
 }
682
//  @jve:decl-index=0:visual-constraint="107,10"