summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent COUVERT <vincent.couvert@scilab.org>2010-05-19 16:59:00 +0200
committerPierre MARECHAL <pierre.marechal@scilab.org>2010-05-19 17:49:47 +0200
commitc8750984274b190ff9ebdc96b1696e6e309f9fcd (patch)
tree965d61b69594a2db331d61c05920b8695daeab13
parent6a3c35502c602bde383f624eaaf5aa04f86fedfc (diff)
downloadscilab-c8750984274b190ff9ebdc96b1696e6e309f9fcd.zip
scilab-c8750984274b190ff9ebdc96b1696e6e309f9fcd.tar.gz
Bug 5216 fiex: URLs are now active in uicontrol of style "text". Used in ATOMS GUI. (JLabel component replaced by a JTextPane component and alignment properties management rewritten).
Change-Id: Id830879bb9e8792eba24c61c5d68eabafe627363
-rw-r--r--scilab/CHANGES_5.3.X3
-rw-r--r--scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/label/SwingScilabLabel.java125
-rw-r--r--scilab/modules/gui/tests/nonreg_tests/bug_5216.tst23
3 files changed, 142 insertions, 9 deletions
diff --git a/scilab/CHANGES_5.3.X b/scilab/CHANGES_5.3.X
index 85f78d0..0be55c3 100644
--- a/scilab/CHANGES_5.3.X
+++ b/scilab/CHANGES_5.3.X
@@ -385,6 +385,9 @@ Bug fixes:
385 385
386* bug 5149 fixed - test_run(): Calls to exec() were no more logged by diary(). 386* bug 5149 fixed - test_run(): Calls to exec() were no more logged by diary().
387 387
388* bug 5216 fixed - URLs are now active in uicontrols of style "text". This
389 feature is used in ATOMS GUI (modules description).
390
388* bug 5432 fixed - a link to http://www.tcl.tk/doc/ added in help files about 391* bug 5432 fixed - a link to http://www.tcl.tk/doc/ added in help files about
389 Tcl/Tk. 392 Tcl/Tk.
390 393
diff --git a/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/label/SwingScilabLabel.java b/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/label/SwingScilabLabel.java
index 1416fb1..dc35862 100644
--- a/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/label/SwingScilabLabel.java
+++ b/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/label/SwingScilabLabel.java
@@ -1,7 +1,8 @@
1/* 1/*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007 - INRIA - Vincent Couvert 3 * Copyright (C) 2007 - INRIA - Vincent COUVERT
4 * Copyright (C) 2007 - INRIA - Marouane BEN JELLOUL 4 * Copyright (C) 2007 - INRIA - Marouane BEN JELLOUL
5 * Copyright (C) 2010 - DIGITEO - Vincent COUVERT
5 * 6 *
6 * This file must be used under the terms of the CeCILL. 7 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which 8 * This source file is licensed as described in the file COPYING, which
@@ -14,10 +15,17 @@ package org.scilab.modules.gui.bridge.label;
14 15
15import java.awt.Color; 16import java.awt.Color;
16import java.awt.Font; 17import java.awt.Font;
18import java.awt.GridBagConstraints;
19import java.awt.GridBagLayout;
17 20
18import javax.swing.BorderFactory; 21import javax.swing.BorderFactory;
19import javax.swing.JLabel; 22import javax.swing.JPanel;
20import javax.swing.JScrollPane; 23import javax.swing.JScrollPane;
24import javax.swing.JTextPane;
25import javax.swing.SwingConstants;
26import javax.swing.event.HyperlinkEvent;
27import javax.swing.event.HyperlinkListener;
28import javax.swing.text.html.HTMLEditorKit;
21 29
22import org.scilab.modules.gui.events.callback.CallBack; 30import org.scilab.modules.gui.events.callback.CallBack;
23import org.scilab.modules.gui.label.SimpleLabel; 31import org.scilab.modules.gui.label.SimpleLabel;
@@ -30,6 +38,7 @@ import org.scilab.modules.gui.utils.ScilabAlignment;
30import org.scilab.modules.gui.utils.ScilabRelief; 38import org.scilab.modules.gui.utils.ScilabRelief;
31import org.scilab.modules.gui.utils.ScilabSwingUtilities; 39import org.scilab.modules.gui.utils.ScilabSwingUtilities;
32import org.scilab.modules.gui.utils.Size; 40import org.scilab.modules.gui.utils.Size;
41import org.scilab.modules.gui.utils.WebBrowser;
33 42
34/** 43/**
35 * Swing implementation for Scilab Labels in GUIs 44 * Swing implementation for Scilab Labels in GUIs
@@ -40,17 +49,26 @@ public class SwingScilabLabel extends JScrollPane implements SimpleLabel {
40 49
41 private static final long serialVersionUID = 7177323379068859441L; 50 private static final long serialVersionUID = 7177323379068859441L;
42 51
43 private JLabel label; 52 private JTextPane label;
44 53
54 private String horizontalAlignment = "left"; /* Horizontal alignment property */
55
56 private String verticalAlignment = "middle"; /* Vertical alignment property */
57
58 private JPanel alignmentPanel; /* Used for alignment */
59
45 /** 60 /**
46 * Constructor 61 * Constructor
47 */ 62 */
48 public SwingScilabLabel() { 63 public SwingScilabLabel() {
49 super(); 64 super();
50 getViewport().add(getLabel()); 65 getViewport().add(getAlignmentPanel());
51 setBorder(BorderFactory.createEmptyBorder()); 66 setBorder(BorderFactory.createEmptyBorder());
52 setViewportBorder(BorderFactory.createEmptyBorder()); 67 setViewportBorder(BorderFactory.createEmptyBorder());
53 setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 68 setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
69
70 // Initialize display
71 setAlignment();
54 } 72 }
55 73
56 /** 74 /**
@@ -90,6 +108,7 @@ public class SwingScilabLabel extends JScrollPane implements SimpleLabel {
90 * @param color the Color 108 * @param color the Color
91 */ 109 */
92 public void setBackground(Color color) { 110 public void setBackground(Color color) {
111 getAlignmentPanel().setBackground(color);
93 getLabel().setBackground(color); 112 getLabel().setBackground(color);
94 } 113 }
95 114
@@ -206,7 +225,8 @@ public class SwingScilabLabel extends JScrollPane implements SimpleLabel {
206 * @param alignment the value for the alignment (See ScilabAlignment.java) 225 * @param alignment the value for the alignment (See ScilabAlignment.java)
207 */ 226 */
208 public void setHorizontalAlignment(String alignment) { 227 public void setHorizontalAlignment(String alignment) {
209 getLabel().setHorizontalAlignment(ScilabAlignment.toSwingAlignment(alignment)); 228 horizontalAlignment = alignment;
229 setAlignment();
210 } 230 }
211 231
212 /** 232 /**
@@ -214,7 +234,8 @@ public class SwingScilabLabel extends JScrollPane implements SimpleLabel {
214 * @param alignment the value for the alignment (See ScilabAlignment.java) 234 * @param alignment the value for the alignment (See ScilabAlignment.java)
215 */ 235 */
216 public void setVerticalAlignment(String alignment) { 236 public void setVerticalAlignment(String alignment) {
217 getLabel().setVerticalAlignment(ScilabAlignment.toSwingAlignment(alignment)); 237 verticalAlignment = alignment;
238 setAlignment();
218 } 239 }
219 240
220 /** 241 /**
@@ -254,10 +275,22 @@ public class SwingScilabLabel extends JScrollPane implements SimpleLabel {
254 * Create/Return the label Java object 275 * Create/Return the label Java object
255 * @return the label 276 * @return the label
256 */ 277 */
257 private JLabel getLabel() { 278 private JTextPane getLabel() {
258 if (label == null) { 279 if (label == null) {
259 label = new JLabel(); 280 label = new JTextPane();
260 label.setOpaque(true); 281 label.setContentType("text/html");
282 label.setOpaque(false);
283 label.setBorder(null);
284 label.setEditable(false);
285 ((HTMLEditorKit) label.getEditorKit()).setAutoFormSubmission(false);
286 /* Add a listener to make hyperlinks active */
287 label.addHyperlinkListener(new HyperlinkListener() {
288 public void hyperlinkUpdate(HyperlinkEvent event) {
289 if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
290 WebBrowser.openUrl(event.getURL().toString());
291 }
292 }
293 });
261 } 294 }
262 return label; 295 return label;
263 296
@@ -281,4 +314,78 @@ public class SwingScilabLabel extends JScrollPane implements SimpleLabel {
281 getLabel().setText(newText); 314 getLabel().setText(newText);
282 } 315 }
283 316
317 /**
318 * Set alignment of the text component
319 */
320 private void setAlignment() {
321
322 getAlignmentPanel().remove(getLabel());
323
324 GridBagConstraints gbc = new GridBagConstraints();
325
326 gbc.gridx = 0;
327 gbc.gridy = 0;
328 gbc.weightx = 1;
329 gbc.weighty = 1;
330 gbc.gridwidth = 1;
331 gbc.gridheight = 1;
332
333 switch (ScilabAlignment.toSwingAlignment(horizontalAlignment)) {
334 case SwingConstants.LEFT:
335 switch (ScilabAlignment.toSwingAlignment(verticalAlignment)) {
336 case SwingConstants.TOP:
337 gbc.anchor = GridBagConstraints.NORTHWEST;
338 break;
339 case SwingConstants.CENTER:
340 gbc.anchor = GridBagConstraints.WEST;
341 break;
342 default: // SwingConstants.BOTTOM
343 gbc.anchor = GridBagConstraints.SOUTHWEST;
344 break;
345 }
346 break;
347 case SwingConstants.CENTER:
348 switch (ScilabAlignment.toSwingAlignment(verticalAlignment)) {
349 case SwingConstants.TOP:
350 gbc.anchor = GridBagConstraints.NORTH;
351 break;
352 case SwingConstants.CENTER:
353 gbc.anchor = GridBagConstraints.CENTER;
354 break;
355 default: // SwingConstants.BOTTOM
356 gbc.anchor = GridBagConstraints.SOUTH;
357 break;
358 }
359 break;
360 default: // SwingConstants.RIGHT
361 switch (ScilabAlignment.toSwingAlignment(verticalAlignment)) {
362 case SwingConstants.TOP:
363 gbc.anchor = GridBagConstraints.NORTHEAST;
364 break;
365 case SwingConstants.CENTER:
366 gbc.anchor = GridBagConstraints.EAST;
367 break;
368 default: // SwingConstants.BOTTOM
369 gbc.anchor = GridBagConstraints.SOUTHEAST;
370 break;
371 }
372 break;
373 }
374
375 getAlignmentPanel().add(getLabel(), gbc);
376
377 }
378
379 /**
380 * Get/Create the panel used for alignment management
381 * @return the panel
382 */
383 private JPanel getAlignmentPanel() {
384 if (alignmentPanel == null) {
385 alignmentPanel = new JPanel(new GridBagLayout());
386 }
387
388 return alignmentPanel;
389 }
390
284} 391}
diff --git a/scilab/modules/gui/tests/nonreg_tests/bug_5216.tst b/scilab/modules/gui/tests/nonreg_tests/bug_5216.tst
new file mode 100644
index 0000000..f2d94d9
--- /dev/null
+++ b/scilab/modules/gui/tests/nonreg_tests/bug_5216.tst
@@ -0,0 +1,23 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2010 - DIGITEO - Vincent COUVERT
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7
8// <-- Non-regression test for bug 5216 -->
9// <-- INTERACTIVE TEST -->
10//
11// <-- Bugzilla URL -->
12// http://bugzilla.scilab.org/show_bug.cgi?id=5216
13//
14// <-- Short Description -->
15// In ATOMS GUI, it would be nice to be able to click on link or at least to copy/paste the URL.
16
17
18h = uicontrol("style","text",..
19 "string", "<a href=""http://www.scilab.org/"">Visit Scilab website...</a>",..
20 "position",[20 20 200 200], ...
21 "fontsize", 15)
22
23// Click on the link and check that a web browser is opened \ No newline at end of file