root / trunk / applications / appCatalogAndGazetteerClient / src / es / gva / cit / catalog / ui / showresults / ShowResultsPanel.java @ 15558
History | View | Annotate | Download (15.1 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.catalog.ui.showresults; |
43 |
import java.awt.AlphaComposite; |
44 |
import java.awt.BorderLayout; |
45 |
import java.awt.Color; |
46 |
import java.awt.Dimension; |
47 |
import java.awt.FlowLayout; |
48 |
import java.awt.Font; |
49 |
import java.awt.GradientPaint; |
50 |
import java.awt.Graphics2D; |
51 |
import java.awt.RenderingHints; |
52 |
import java.awt.Shape; |
53 |
import java.awt.font.TextLayout; |
54 |
import java.awt.geom.AffineTransform; |
55 |
import java.awt.geom.Rectangle2D; |
56 |
import java.awt.image.BufferedImage; |
57 |
import java.net.URL; |
58 |
|
59 |
import javax.swing.BorderFactory; |
60 |
import javax.swing.BoxLayout; |
61 |
import javax.swing.ImageIcon; |
62 |
import javax.swing.JButton; |
63 |
import javax.swing.JEditorPane; |
64 |
import javax.swing.JLabel; |
65 |
import javax.swing.JPanel; |
66 |
import javax.swing.JScrollPane; |
67 |
import javax.swing.border.BevelBorder; |
68 |
|
69 |
import org.gvsig.i18n.Messages; |
70 |
|
71 |
import es.gva.cit.catalog.CatalogClient; |
72 |
import es.gva.cit.catalog.metadataxml.XMLNode; |
73 |
import es.gva.cit.catalog.schemas.Record; |
74 |
import es.gva.cit.catalog.utils.ImageRetriever; |
75 |
|
76 |
/**
|
77 |
*
|
78 |
*
|
79 |
*
|
80 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
81 |
*/
|
82 |
public class ShowResultsPanel extends JPanel { |
83 |
public static boolean mustShowThumbnails = true; |
84 |
private Record record = null; |
85 |
private CatalogClient client = null; |
86 |
private URL imageURL = null; |
87 |
private JPanel descriptionPanel = null; |
88 |
private JEditorPane descriptionArea = null; |
89 |
private JPanel linksPanel = null; |
90 |
private JPanel jPanel = null; |
91 |
private JButton descriptionButton = null; |
92 |
private JLabel jLabel = null; |
93 |
private JButton mapButton = null; |
94 |
private JScrollPane descriptionScroll = null; |
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 |
private JButton closeButton = null; |
105 |
|
106 |
/**
|
107 |
* Constaructor
|
108 |
*
|
109 |
* @param server Server URL
|
110 |
*
|
111 |
* @param node Answer Node
|
112 |
* @param protocol Search protocol
|
113 |
* @param numRecords Number of records returned by the query
|
114 |
* @param serverURL
|
115 |
* @param translator
|
116 |
*/
|
117 |
public ShowResultsPanel(CatalogClient client, int numRecords) { |
118 |
super();
|
119 |
this.client = client;
|
120 |
this.numRecords = numRecords;
|
121 |
initialize(); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* This method initializes this
|
126 |
*
|
127 |
*/
|
128 |
private void initialize() { |
129 |
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
130 |
this.setSize(703, 364); |
131 |
this.add(getNextLastPanel(), null); |
132 |
this.add(getJPanel1(), null); |
133 |
this.add(getDescriptionPanel(), null); |
134 |
this.add(getJPanel(), null); |
135 |
this.add(getLinksPanel(), null); |
136 |
actualizaLabel(1);
|
137 |
} |
138 |
|
139 |
/**
|
140 |
* Actualiza el valor de la cadena de taexto que muestra los resultados
|
141 |
*
|
142 |
*
|
143 |
* @param number Registro actual
|
144 |
*/
|
145 |
public void actualizaLabel(int number) { |
146 |
textLabel.setText(Messages.getText("results") + ": " + String.valueOf(number) + " " + Messages.getText("of") + " " + |
147 |
String.valueOf(this.numRecords)); |
148 |
} |
149 |
|
150 |
/**
|
151 |
* @param descripcionBoton The descripcionBoton to set.
|
152 |
*/
|
153 |
public void setDescripcionBoton(JButton descripcionBoton) { |
154 |
this.descriptionButton = descripcionBoton;
|
155 |
} |
156 |
|
157 |
/**
|
158 |
* @param mapButton The mapButton to set.
|
159 |
*/
|
160 |
public void setMapButton(JButton mapButton) { |
161 |
this.mapButton = mapButton;
|
162 |
} |
163 |
|
164 |
/**
|
165 |
* This method initializes jPanel
|
166 |
* @return javax.swing.JPanel
|
167 |
*/
|
168 |
private JPanel getDescriptionPanel() { |
169 |
if (descriptionPanel == null) { |
170 |
jLabel1 = new JLabel(); |
171 |
descriptionPanel = new JPanel(); |
172 |
descriptionPanel.setLayout(new BoxLayout(descriptionPanel, |
173 |
BoxLayout.X_AXIS));
|
174 |
descriptionPanel.setPreferredSize(new java.awt.Dimension(600, 300)); |
175 |
jLabel1.setText("");
|
176 |
jLabel1.setPreferredSize(new java.awt.Dimension(40, 0)); |
177 |
descriptionPanel.add(getDescriptionScroll(), null);
|
178 |
if (mustShowThumbnails) {
|
179 |
descriptionPanel.add(jLabel1, null);
|
180 |
descriptionPanel.add(getImagePanel(), null);
|
181 |
} else {
|
182 |
descriptionPanel.setPreferredSize(new java.awt.Dimension(400, |
183 |
300));
|
184 |
} |
185 |
} |
186 |
return descriptionPanel;
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* This method initializes jTextArea
|
191 |
* @return javax.swing.JTextArea
|
192 |
*/
|
193 |
public JEditorPane getDescriptionArea() { |
194 |
if (descriptionArea == null) { |
195 |
descriptionArea = new JEditorPane(); |
196 |
descriptionArea.setPreferredSize(new java.awt.Dimension(400, 300)); |
197 |
descriptionArea.setContentType("text/html");
|
198 |
} |
199 |
return descriptionArea;
|
200 |
} |
201 |
|
202 |
/**
|
203 |
* This method initializes jPanel
|
204 |
* @return javax.swing.JPanel
|
205 |
*/
|
206 |
private JPanel getLinksPanel() { |
207 |
if (linksPanel == null) { |
208 |
FlowLayout flowLayout = new FlowLayout(); |
209 |
flowLayout.setAlignment(flowLayout.RIGHT); |
210 |
linksPanel = new JPanel(flowLayout); |
211 |
linksPanel.add(getDescriptionButton(), null);
|
212 |
linksPanel.add(getMapButton(), null);
|
213 |
linksPanel.add(getCloseButton(), null);
|
214 |
} |
215 |
return linksPanel;
|
216 |
} |
217 |
|
218 |
/**
|
219 |
* This method initializes jPanel
|
220 |
* @return javax.swing.JPanel
|
221 |
*/
|
222 |
private JPanel getJPanel() { |
223 |
if (jPanel == null) { |
224 |
jPanel = new JPanel(); |
225 |
} |
226 |
return jPanel;
|
227 |
} |
228 |
|
229 |
/**
|
230 |
* This method initializes jButton
|
231 |
* @return javax.swing.JButton
|
232 |
*/
|
233 |
public JButton getDescriptionButton() { |
234 |
if (descriptionButton == null) { |
235 |
descriptionButton = new JButton(); |
236 |
descriptionButton.setText(Messages.getText("description"));
|
237 |
descriptionButton.setActionCommand("description");
|
238 |
descriptionButton.setPreferredSize(new Dimension(95, 23)); |
239 |
} |
240 |
return descriptionButton;
|
241 |
} |
242 |
|
243 |
/**
|
244 |
* This method initializes jLabel
|
245 |
* @return javax.swing.JLabel
|
246 |
*/
|
247 |
private JLabel getJLabel() { |
248 |
if (jLabel == null) { |
249 |
jLabel = new JLabel(); |
250 |
} |
251 |
return jLabel;
|
252 |
} |
253 |
|
254 |
/**
|
255 |
* This method initializes mapButton
|
256 |
* @return javax.swing.JButton
|
257 |
*/
|
258 |
public JButton getMapButton() { |
259 |
if (mapButton == null) { |
260 |
mapButton = new JButton(); |
261 |
mapButton.setText(Messages.getText("addLayer"));
|
262 |
mapButton.setActionCommand("layer");
|
263 |
mapButton.setPreferredSize(new Dimension(95, 23)); |
264 |
} |
265 |
return mapButton;
|
266 |
} |
267 |
|
268 |
/**
|
269 |
* This method initializes descriptionScroll
|
270 |
* @return javax.swing.JScrollPane
|
271 |
*/
|
272 |
public JScrollPane getDescriptionScroll() { |
273 |
if (descriptionScroll == null) { |
274 |
descriptionScroll = new JScrollPane(); |
275 |
descriptionScroll.setViewportView(getDescriptionArea()); |
276 |
descriptionScroll.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
277 |
descriptionScroll.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); |
278 |
descriptionScroll.setPreferredSize(new java.awt.Dimension(400, 250)); |
279 |
} |
280 |
return descriptionScroll;
|
281 |
} |
282 |
|
283 |
/**
|
284 |
* @return Returns the record.
|
285 |
*/
|
286 |
public Record getRecord() {
|
287 |
return record;
|
288 |
} |
289 |
|
290 |
/**
|
291 |
* @param record The Record to set.
|
292 |
*/
|
293 |
public void setRecord(Record record) { |
294 |
this.record = record;
|
295 |
} |
296 |
|
297 |
/**
|
298 |
* @param node
|
299 |
* @param protocol
|
300 |
*/
|
301 |
public void loadTextNewRecord(Record record) { |
302 |
setRecord(record); |
303 |
descriptionArea.setText(this.getHtml());
|
304 |
descriptionArea.setCaretPosition(0);
|
305 |
if (getRecord() != null){ |
306 |
if (getRecord().getImage() == null){ |
307 |
imageLabel.setIcon(getImgIcon(null));
|
308 |
//DOWNLOAD the image
|
309 |
new ImageThread();
|
310 |
}else{
|
311 |
imageLabel.setIcon(getImgIcon(getRecord().getImage())); |
312 |
} |
313 |
} |
314 |
this.repaint();
|
315 |
} |
316 |
|
317 |
/**
|
318 |
* @return the HTML code to show
|
319 |
*/
|
320 |
private String getHtml() { |
321 |
StringBuffer html = new StringBuffer(); |
322 |
html.append("<html><body>");
|
323 |
if(getRecord() == null){ |
324 |
html.append("Error");
|
325 |
html.append("</body></html>");
|
326 |
return html.toString();
|
327 |
} |
328 |
if ((getRecord().getNode() != null) && (getRecord().getNode().getName() != null)){ |
329 |
if (getRecord().getNode().getName().equals(XMLNode.ISNOTXML)){
|
330 |
html.append(getRecord().getNode().getText()); |
331 |
html.append("</body></html>");
|
332 |
return html.toString();
|
333 |
} |
334 |
} |
335 |
html.append("<font COLOR=\"#0000FF\">");
|
336 |
if (this.getRecord().getTitle() != null) { |
337 |
html.append(this.getRecord().getTitle());
|
338 |
} |
339 |
html.append("<font COLOR=\"#000000\">");
|
340 |
if ((this.getRecord().getAbstract_() != null) && |
341 |
(!(this.getRecord().getAbstract_().equals("")))) { |
342 |
html.append("<br>");
|
343 |
html.append("<br>");
|
344 |
html.append("<b>" + Messages.getText("abstract") + ": </b>"); |
345 |
html.append(this.getRecord().getAbstract_());
|
346 |
} |
347 |
if ((this.getRecord().getPurpose() != null) && |
348 |
(!(this.getRecord().getPurpose().equals("")))) { |
349 |
html.append("<br>");
|
350 |
html.append("<br>");
|
351 |
html.append("<b>" + Messages.getText("purpose") +": </b>"); |
352 |
html.append(this.getRecord().getPurpose());
|
353 |
} |
354 |
if (this.getRecord().getKeyWords() != null) { |
355 |
if (this.getRecord().getKeyWords()[0] != null) { |
356 |
html.append("<br>");
|
357 |
html.append("<br>");
|
358 |
html.append("<b>" + Messages.getText("keyWords") + ":</b>"); |
359 |
html.append(this.getRecord().getKeyWords()[0]); |
360 |
} |
361 |
} |
362 |
if (this.getRecord().getKeyWords() != null) { |
363 |
for (int i = 1; i < this.getRecord().getKeyWords().length; i++) |
364 |
if (this.getRecord().getKeyWords()[i] != null) { |
365 |
html.append(", " + this.getRecord().getKeyWords()[i]); |
366 |
} |
367 |
} |
368 |
html.append("</body></html>");
|
369 |
return html.toString();
|
370 |
} |
371 |
|
372 |
/**
|
373 |
* This method initializes imagePanel
|
374 |
* @return javax.swing.JPanel
|
375 |
*/
|
376 |
private JPanel getImagePanel() { |
377 |
if (imagePanel == null) { |
378 |
imagePanel = new JPanel(); |
379 |
imagePanel.setLayout(new FlowLayout(FlowLayout.CENTER)); |
380 |
imagePanel.setMaximumSize(new java.awt.Dimension(207, 210)); |
381 |
JPanel borderPanel = new JPanel(); |
382 |
borderPanel.setLayout(new BorderLayout()); |
383 |
borderPanel.setBorder(BorderFactory.createCompoundBorder(
|
384 |
BorderFactory.createBevelBorder(BevelBorder.LOWERED), |
385 |
BorderFactory.createEmptyBorder(5, 5, 5, 5))); |
386 |
imagePanel.add(borderPanel, BorderLayout.CENTER);
|
387 |
imageLabel = new JLabel(getImgIcon(null)); |
388 |
borderPanel.add(imageLabel, BorderLayout.CENTER);
|
389 |
} |
390 |
return imagePanel;
|
391 |
} |
392 |
|
393 |
/**
|
394 |
* @return
|
395 |
* @param pic
|
396 |
*/
|
397 |
public ImageIcon getImgIcon(BufferedImage pic) { |
398 |
BufferedImage img = new BufferedImage(180, 180, |
399 |
BufferedImage.TYPE_INT_ARGB);
|
400 |
Graphics2D g = img.createGraphics();
|
401 |
if (pic != null) { |
402 |
double fw = 1.0; |
403 |
double fh = 1.0; |
404 |
if (pic.getWidth() > pic.getHeight()){
|
405 |
fw = 180D / pic.getWidth();
|
406 |
fh = fw; |
407 |
}else{
|
408 |
fh = 180D / pic.getHeight();
|
409 |
fw = fh; |
410 |
} |
411 |
|
412 |
AffineTransform mat = AffineTransform.getScaleInstance(fw, fh); |
413 |
g.drawImage(pic, mat, null);
|
414 |
} else {
|
415 |
|
416 |
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
417 |
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
418 |
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
|
419 |
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
420 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
421 |
RenderingHints.VALUE_ANTIALIAS_ON);
|
422 |
g.setFont(new Font("Lucida Bright", Font.ITALIC, 30)); |
423 |
g.rotate(-Math.PI / 4, 100D, 100D); |
424 |
String text = "NO PICTURE"; //DateFormat.getDateInstance(DateFormat.SHORT).format(new Date()); |
425 |
TextLayout tl = new TextLayout(text, g.getFont(), |
426 |
g.getFontRenderContext()); |
427 |
Rectangle2D bounds = tl.getBounds();
|
428 |
double x = (( 180D - bounds.getWidth()) / 2) - bounds.getX(); |
429 |
double y = (( 180D - bounds.getHeight()) / 2) - bounds.getY(); |
430 |
Shape outline = tl.getOutline(AffineTransform.getTranslateInstance(x + |
431 |
2, y + 1)); |
432 |
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f)); |
433 |
g.setPaint(Color.WHITE);
|
434 |
g.draw(outline); |
435 |
g.setPaint(new GradientPaint(0, 0, new Color(192, 192, 255), 30, |
436 |
20, new Color(255, 255, 64), true)); |
437 |
tl.draw(g, (float) x, (float) y); |
438 |
} |
439 |
g.dispose(); |
440 |
return new ImageIcon(img); |
441 |
} |
442 |
|
443 |
/**
|
444 |
* @return Returns the imageURL.
|
445 |
*/
|
446 |
public URL getImageURL() { |
447 |
return imageURL;
|
448 |
} |
449 |
|
450 |
/**
|
451 |
* @param imageURL The imageURL to set.
|
452 |
*/
|
453 |
public void setImageURL(URL imageURL) { |
454 |
this.imageURL = imageURL;
|
455 |
} |
456 |
|
457 |
/**
|
458 |
* This method initializes jPanel1
|
459 |
* @return javax.swing.JPanel
|
460 |
*/
|
461 |
private JPanel getJPanel1() { |
462 |
if (jPanel1 == null) { |
463 |
jPanel1 = new JPanel(); |
464 |
} |
465 |
return jPanel1;
|
466 |
} |
467 |
|
468 |
/**
|
469 |
* This method initializes jPanel2
|
470 |
* @return javax.swing.JPanel
|
471 |
*/
|
472 |
private JPanel getNextLastPanel() { |
473 |
if (nextLastPanel == null) { |
474 |
textLabel = new JLabel(); |
475 |
nextLastPanel = new JPanel(); |
476 |
textLabel.setText("JLabel");
|
477 |
nextLastPanel.add(getLastButton(), null);
|
478 |
nextLastPanel.add(textLabel, null);
|
479 |
nextLastPanel.add(getNextButton(), null);
|
480 |
} |
481 |
return nextLastPanel;
|
482 |
} |
483 |
|
484 |
/**
|
485 |
* This method initializes jButton
|
486 |
*
|
487 |
*
|
488 |
* @return javax.swing.JButton
|
489 |
*/
|
490 |
public JButton getLastButton() { |
491 |
if (lastButton == null) { |
492 |
lastButton = new JButton(); |
493 |
lastButton.setText(Messages.getText("last"));
|
494 |
lastButton.setActionCommand("last");
|
495 |
lastButton.setEnabled(false);
|
496 |
lastButton.setPreferredSize(new Dimension(95, 23)); |
497 |
} |
498 |
return lastButton;
|
499 |
} |
500 |
|
501 |
/**
|
502 |
* This method initializes jButton
|
503 |
* @return javax.swing.JButton
|
504 |
*/
|
505 |
public JButton getNextButton() { |
506 |
if (nextButton == null) { |
507 |
nextButton = new JButton(); |
508 |
nextButton.setText(Messages.getText("next"));
|
509 |
nextButton.setActionCommand("next");
|
510 |
nextButton.setPreferredSize(new Dimension(95, 23)); |
511 |
if (this.numRecords < 2) { |
512 |
nextButton.setEnabled(false);
|
513 |
} |
514 |
} |
515 |
return nextButton;
|
516 |
} |
517 |
|
518 |
/**
|
519 |
* This method initializes jButton
|
520 |
* @return javax.swing.JButton
|
521 |
*/
|
522 |
public JButton getCloseButton() { |
523 |
if (closeButton == null) { |
524 |
closeButton = new JButton(); |
525 |
closeButton.setText(Messages.getText("close"));
|
526 |
closeButton.setActionCommand("close");
|
527 |
closeButton.setPreferredSize(new Dimension(80, 23)); |
528 |
} |
529 |
return closeButton;
|
530 |
} |
531 |
|
532 |
/**
|
533 |
* This thread is used to download the image
|
534 |
* @author jorpiell
|
535 |
*
|
536 |
*/
|
537 |
private class ImageThread implements Runnable { |
538 |
volatile Thread myThread = null; |
539 |
|
540 |
public ImageThread() {
|
541 |
myThread = new Thread(this); |
542 |
myThread.start(); |
543 |
} |
544 |
|
545 |
public void stop() { |
546 |
myThread.stop(); |
547 |
} |
548 |
|
549 |
/*
|
550 |
* (non-Javadoc)
|
551 |
* @see java.lang.Runnable#run()
|
552 |
*/
|
553 |
public void run() { |
554 |
BufferedImage img = ImageRetriever.getImageUrl(getRecord());
|
555 |
imageLabel.setIcon(getImgIcon(img)); |
556 |
} |
557 |
} |
558 |
|
559 |
} |
560 |
//@jve:decl-index=0:visual-constraint="107,10"
|