Revision 368 org.gvsig.hyperlink.app/trunk/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/ImgPanel.java
ImgPanel.java | ||
---|---|---|
23 | 23 |
package org.gvsig.hyperlink.app.extension.actions; |
24 | 24 |
|
25 | 25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Dimension; |
|
27 | 26 |
import java.net.MalformedURLException; |
28 | 27 |
import java.net.URI; |
29 | 28 |
|
30 |
import javax.swing.ImageIcon; |
|
31 |
import javax.swing.JLabel; |
|
32 |
|
|
33 |
import org.gvsig.andami.PluginServices; |
|
34 |
import org.gvsig.andami.messages.NotificationManager; |
|
35 | 29 |
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel; |
36 | 30 |
|
37 |
import com.sun.jimi.core.Jimi; |
|
31 |
import org.gvsig.imageviewer.ImageViewer; |
|
32 |
import org.gvsig.tools.util.ToolsUtilLocator; |
|
38 | 33 |
|
39 | 34 |
/** |
40 | 35 |
* This class extends AbstractHyperLink, and provides suppot to open images of |
... | ... | |
50 | 45 |
|
51 | 46 |
private static final long serialVersionUID = -5200841105188251551L; |
52 | 47 |
|
48 |
private ImageViewer imageViewer; |
|
53 | 49 |
/** |
54 | 50 |
* Default constructor. |
51 |
* @param doc |
|
55 | 52 |
*/ |
56 | 53 |
public ImgPanel(URI doc) { |
57 | 54 |
super(doc); |
... | ... | |
61 | 58 |
/** |
62 | 59 |
* Initializes this panel. |
63 | 60 |
*/ |
64 |
void initialize() { |
|
61 |
private void initialize() {
|
|
65 | 62 |
this.setLayout(new BorderLayout()); |
63 |
this.imageViewer = ToolsUtilLocator.getImageViewerManager().createImageViewer(); |
|
64 |
this.add(this.imageViewer.asJComponent(),BorderLayout.CENTER); |
|
66 | 65 |
showDocument(); |
67 | 66 |
// this.setSize(600, 400); |
68 | 67 |
} |
... | ... | |
74 | 73 |
if (!checkAndNormalizeURI()) { |
75 | 74 |
return; |
76 | 75 |
} |
77 |
ImageIcon image = null; |
|
78 |
String iString = document.toString(); |
|
79 |
iString = iString.toLowerCase(); |
|
80 |
|
|
81 |
if (iString.endsWith("jpg") || iString.endsWith("jpeg") |
|
82 |
|| iString.endsWith("gif") || iString.endsWith("jp2")) { |
|
83 |
// note: it seems jimi si not able to load .jp2 (jpeg2000) |
|
84 |
try { |
|
85 |
image = new ImageIcon(Jimi.getImage(document.toURL())); |
|
86 |
} catch (MalformedURLException e) { |
|
87 |
NotificationManager.addWarning(PluginServices.getText(this, |
|
88 |
"Hyperlink_linked_field_doesnot_exist"), e); |
|
89 |
} |
|
90 |
} else |
|
91 |
if (iString.endsWith("png") || iString.endsWith("tiff") |
|
92 |
|| iString.endsWith("tif") || iString.endsWith("jpg") |
|
93 |
|| iString.endsWith("ico") || iString.endsWith("xpm") |
|
94 |
|| iString.endsWith("bmp")) { |
|
95 |
// note: it seems jimi si not able to load .tiff images |
|
96 |
try { |
|
97 |
image = new ImageIcon(Jimi.getImage(document.toURL())); |
|
98 |
} catch (MalformedURLException e) { |
|
99 |
NotificationManager.addWarning(PluginServices.getText(this, |
|
100 |
"Hyperlink_linked_field_doesnot_exist"), e); |
|
101 |
} |
|
102 |
} else { |
|
103 |
try { |
|
104 |
image = new ImageIcon(document.toURL()); |
|
105 |
} catch (MalformedURLException e) { |
|
106 |
NotificationManager.addWarning(PluginServices.getText(this, |
|
107 |
"Hyperlink_linked_field_doesnot_exist"), e); |
|
108 |
} |
|
109 |
} |
|
110 |
if (image == null) |
|
111 |
; // Incluir error |
|
112 |
this.setPreferredSize(new Dimension(image.getIconWidth(), |
|
113 |
image.getIconHeight())); |
|
114 |
this.setSize(new Dimension(image.getIconWidth(), image.getIconHeight())); |
|
115 |
JLabel label = new JLabel(image); |
|
116 |
this.add(label); |
|
76 |
try { |
|
77 |
this.imageViewer.setImage(document.toURL()); |
|
78 |
} catch (MalformedURLException e) { |
|
79 |
logger.warn("Can't load image '"+document.toString()+"'.", e); |
|
80 |
} |
|
117 | 81 |
} |
118 | 82 |
|
119 | 83 |
} |
Also available in: Unified diff