001: /*
002: #IFNDEF ALT_LICENSE
003: ThinWire(R) RIA Ajax Framework
004: Copyright (C) 2003-2007 Custom Credit Systems
005:
006: This library is free software; you can redistribute it and/or modify it under
007: the terms of the GNU Lesser General Public License as published by the Free
008: Software Foundation; either version 2.1 of the License, or (at your option) any
009: later version.
010:
011: This library is distributed in the hope that it will be useful, but WITHOUT ANY
012: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
013: PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
014:
015: You should have received a copy of the GNU Lesser General Public License along
016: with this library; if not, write to the Free Software Foundation, Inc., 59
017: Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:
019: Users who would rather have a commercial license, warranty or support should
020: contact the following company who invented, built and supports the technology:
021:
022: Custom Credit Systems, Richardson, TX 75081, USA.
023: email: info@thinwire.com ph: +1 (888) 644-6405
024: http://www.thinwire.com
025: #ENDIF
026: [ v1.2_RC2 ]
027: */
028: package thinwire.ui;
029:
030: import java.io.File;
031:
032: import thinwire.render.web.WebApplication;
033:
034: /**
035: * A <code>Hyperlink</code> is a screen component that acts like a standard
036: * hyperlink.
037: * <p>
038: * <b>Example:</b> <br>
039: * <img src="doc-files/Hyperlink-1.png"> <br>
040: *
041: * <pre>
042: * Hyperlink hl = new Hyperlink("Custom Credit Systems Home Page",
043: * "http://www.customcreditsystems.com");
044: * hl.setBounds(25, 25, 175, 20);
045: * MessageBox.confirm("", "Hyperlink Test", hl, "OK");
046: * </pre>
047: *
048: * </p>
049: * <p>
050: * <b>Keyboard Navigation:</b><br>
051: * <table border="1">
052: * <tr>
053: * <td>KEY</td>
054: * <td>RESPONSE</td>
055: * <td>NOTE</td>
056: * </tr>
057: * <tr>
058: * <td>Enter</td>
059: * <td>Fires Action( Action = Hyperlink.ACTION_CLICK )</td>
060: * <td>Only if the component has focus.</td>
061: * </tr>
062: * </table>
063: * </p>
064: *
065: * @author Joshua J. Gertzen
066: */
067: public class Hyperlink extends AbstractTextComponent {
068: private static Application.Local<Integer> targetId = new Application.Local<Integer>() {
069: protected Integer initialValue() {
070: return 0;
071: }
072: };
073:
074: public static final String PROPERTY_LOCATION = "location";
075:
076: public static void openLocation(String location) {
077: openLocation(location, null);
078: }
079:
080: public static void openLocation(String location, String target) {
081: if (target == null || target.length() < 1) {
082: Integer id = targetId.get();
083: targetId.set(id + 1);
084: target = "olhl" + id;
085: }
086:
087: location = Application.current().getQualifiedURL(location);
088:
089: ((WebApplication) WebApplication.current())
090: .clientSideMethodCallWaitForReturn("tw_Hyperlink",
091: "openLocation", location, target);
092:
093: Application.current().removeFileFromMap(location);
094: }
095:
096: private String location = "";
097:
098: public Hyperlink() {
099: }
100:
101: /**
102: * Constructs a new Hyperlink displaying the specified text. If the text is
103: * a valid URL, the location property is also set.
104: *
105: * @param text
106: */
107: public Hyperlink(String text) {
108: this (text, Application.validateURL(text) ? text : null);
109: }
110:
111: public Hyperlink(String text, String location) {
112: this .setText(text);
113: this .setLocation(location);
114: }
115:
116: public void setLocation(String location) {
117: String oldLocation = this .location;
118: location = location == null ? "" : location;
119: this .location = location;
120: firePropertyChange(this , PROPERTY_LOCATION, oldLocation,
121: location);
122: }
123:
124: public String getLocation() {
125: return this.location;
126: }
127: }
|