1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.magicproject.ui.component;
22
23 import java.awt.Cursor;
24 import java.awt.event.MouseEvent;
25 import java.awt.event.MouseListener;
26
27 import javax.swing.Icon;
28 import javax.swing.JLabel;
29 import javax.swing.JOptionPane;
30 import javax.swing.SwingConstants;
31
32 import net.sf.magicproject.tools.WebBrowser;
33 import net.sf.magicproject.ui.MagicUIComponents;
34 import net.sf.magicproject.ui.i18n.LanguageManager;
35
36 /***
37 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
38 * @since 0.82
39 */
40 public class JLink extends JLabel implements MouseListener {
41
42 /***
43 * Create a new instance of this class.
44 *
45 * @param link
46 * the url link.
47 * @param text
48 * the displayed text.
49 * @param allign
50 * the allignment.
51 */
52 public JLink(String link, String text, int allign) {
53 this(link, text, null, allign);
54 }
55
56 /***
57 * Create a new instance of this class.
58 *
59 * @param link
60 * the url link.
61 * @param text
62 * the displayed text.
63 */
64 public JLink(String link, String text) {
65 this(link, text, null, 0);
66 }
67
68 /***
69 * Create a new instance of this class.
70 *
71 * @param link
72 * the url link.
73 * @param icon
74 * the displayed icon.
75 * @param allign
76 * the allignment.
77 */
78 public JLink(String link, Icon icon, int allign) {
79 this(link, null, icon, allign);
80 }
81
82 /***
83 * Create a new instance of this class.
84 *
85 * @param link
86 * the url link.
87 * @param icon
88 * the displayed icon.
89 */
90 public JLink(String link, Icon icon) {
91 this(link, null, icon, 0);
92 }
93
94 /***
95 * Create a new instance of this class.
96 *
97 * @param link
98 * the url link.
99 * @param text
100 * the displayed text.
101 * @param icon
102 * the displayed icon.
103 */
104 public JLink(String link, String text, Icon icon) {
105 this(link, text, icon, 0);
106 }
107
108 /***
109 * Create a new instance of this class.
110 *
111 * @param link
112 * the url link.
113 * @param text
114 * the displayed text.
115 * @param icon
116 * the displayed icon.
117 * @param allign
118 * the allignment.
119 */
120 public JLink(String link, String text, Icon icon, int allign) {
121 super(text == null ? null : new StringBuilder("<html><a href=\"").append(
122 link).append("\">").append(text).append("<a>").toString(), icon, allign);
123 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
124 setHorizontalAlignment(SwingConstants.LEFT);
125 this.link = link;
126 addMouseListener(this);
127 }
128
129
130
131
132
133
134 public void mouseClicked(MouseEvent e) {
135 try {
136 WebBrowser.launchBrowser(link);
137 } catch (Exception ex) {
138 JOptionPane.showMessageDialog(MagicUIComponents.magicForm,
139 LanguageManager.getString("error") + " : " + ex.getMessage(),
140 LanguageManager.getString("web-pb"), JOptionPane.INFORMATION_MESSAGE,
141 null);
142 }
143 }
144
145 public void mousePressed(MouseEvent e) {
146
147 }
148
149 public void mouseReleased(MouseEvent e) {
150
151 }
152
153 public void mouseEntered(MouseEvent e) {
154
155 }
156
157 public void mouseExited(MouseEvent e) {
158
159 }
160
161 /***
162 * The link
163 */
164 private String link;
165 }