001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings;
014:
015: import org.wings.plaf.AnchorCG;
016:
017: import java.net.URL;
018:
019: /**
020: * Container used to force a HTML Link.
021: * <p/>
022: * Creates a 'normal'
023: * <a href="http://whatever/">...</a>
024: * HTML link around some components that are stored in the container.
025: *
026: * @author <a href="mailto:H.Zeller@acm.org">Henner Zeller</a>
027: */
028: public class SAnchor extends SContainer {
029:
030: /**
031: * the URL to link to.
032: */
033: protected SimpleURL url;
034:
035: /**
036: * the target frame/window.
037: */
038: protected String target;
039:
040: /**
041: * creates an anchor with emtpy URL and target.
042: */
043: public SAnchor() {
044: this (new SimpleURL("#"), null);
045: }
046:
047: /**
048: * create an anchor that points to the URL url.
049: *
050: * @param url the url to point to.
051: */
052: public SAnchor(String url) {
053: this (url, null);
054: }
055:
056: /**
057: * creates an anchor that points to the URL and is openend
058: * in the frame or window named target.
059: *
060: * @param url the url to link to.
061: * @param target the target window or frame.
062: */
063: public SAnchor(String url, String target) {
064: setURL(url);
065: setTarget(target);
066: }
067:
068: /**
069: * creates an anchor that points to the URL and is openend
070: * in the frame or window named target.
071: *
072: * @param url the url to link to.
073: * @param target the target window or frame.
074: */
075: public SAnchor(SimpleURL url, String target) {
076: setURL(url);
077: setTarget(target);
078: }
079:
080: /**
081: * set the url this anchor points to.
082: *
083: * @param ref the url.
084: */
085: public void setURL(URL ref) {
086: if (ref != null) {
087: setURL(ref.toString());
088: } else {
089: setURL((SimpleURL) null);
090: }
091: }
092:
093: /**
094: * set the url this anchor points to.
095: *
096: * @param r the url.
097: */
098: public void setURL(SimpleURL r) {
099: SimpleURL oldURL = url;
100: url = r;
101: if (url == null && oldURL != null
102: || (url != null && !url.equals(oldURL))) {
103: reload();
104: }
105: }
106:
107: /**
108: * set the url this anchor points to.
109: *
110: * @param url the url.
111: */
112: public void setURL(String url) {
113: setURL(new SimpleURL(url));
114: }
115:
116: /**
117: * set the name of the target frame/window.
118: */
119: public void setTarget(String t) {
120: target = t;
121: }
122:
123: /**
124: * get the name of the target frame/window.
125: */
126: public String getTarget() {
127: return target;
128: }
129:
130: /**
131: * get the url the anchor points to.
132: */
133: public SimpleURL getURL() {
134: return url;
135: }
136:
137: public void setCG(AnchorCG cg) {
138: super.setCG(cg);
139: }
140: }
|