KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > core > WindowOpenJavascriptLink


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.core;
21
22 import java.awt.Rectangle JavaDoc;
23
24 import com.sslexplorer.boot.Util;
25
26
27 /**
28  * Constructs a fragment of JavaScript to open a link in a new Window with
29  * parameters.
30  *
31  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
32  */

33 public class WindowOpenJavascriptLink implements JavascriptLink {
34     
35     // Private instance variables
36
private String JavaDoc uri;
37     private String JavaDoc windowId;
38     private Rectangle JavaDoc bounds;
39     private boolean resizable;
40     private boolean menuBar;
41     private boolean toolBar;
42     private boolean scrollBars;
43     private boolean location;
44
45     /**
46      * Construct a new link that does nothing.
47      *
48      */

49     public WindowOpenJavascriptLink() {
50         this(null, null, null, false, false, false, false, false);
51     }
52     
53     /**
54      * Constructor.
55      *
56      * @param uri uri to open (must be encoded)
57      * @param windowId ID to give window
58      * @param bounds window bounds
59      * @param resizable resizable
60      * @param menuBar show menu bar
61      * @param toolBar show tool bar
62      * @param scrollBars show scroll bars
63      * @param location show location bar
64      *
65      */

66     public WindowOpenJavascriptLink(String JavaDoc uri, String JavaDoc windowId, Rectangle JavaDoc bounds,
67                           boolean resizable, boolean menuBar, boolean toolBar, boolean scrollBars, boolean location) {
68         this.uri = uri;
69         this.windowId = windowId;
70         this.bounds = bounds;
71         this.resizable = resizable;
72         this.menuBar = menuBar;
73         this.toolBar = toolBar;
74         this.scrollBars = scrollBars;
75         this.location = location;
76     }
77     
78     /**
79      * Get the URI
80      *
81      * @return uri
82      */

83     public String JavaDoc getURI() {
84         return uri;
85     }
86     
87     /**
88      * Generate the Javascript fragment.
89      *
90      * @return javascript fragement to open the window
91      */

92     public String JavaDoc toJavascript() {
93         if(uri == null) {
94             return "void();";
95         }
96         
97         StringBuffer JavaDoc openBuf = new StringBuffer JavaDoc();
98         openBuf.append("windowRef = window.open('");
99         openBuf.append(Util.escapeForJavascriptString(uri));
100         openBuf.append("','");
101         openBuf.append(windowId);
102         openBuf.append("','");
103         if(bounds != null) {
104             openBuf.append("top=");
105             openBuf.append(bounds.y);
106             openBuf.append(",left=");
107             openBuf.append(bounds.x);
108             openBuf.append(",width=");
109             openBuf.append(bounds.width);
110             openBuf.append(",height=");
111             openBuf.append(bounds.height);
112             openBuf.append(",");
113         }
114         openBuf.append("location=");
115         openBuf.append(location ? 1 : 0);
116         openBuf.append(",resizable=");
117         openBuf.append(resizable ? 1 : 0);
118         openBuf.append(",toolbar=");
119         openBuf.append(toolBar ? 1 : 0);
120         openBuf.append(",menubar=");
121         openBuf.append(menuBar ? 1 : 0);
122         openBuf.append(",scrollbars=");
123         openBuf.append(scrollBars ? 1 : 0);
124         openBuf.append("'); ");
125         
126         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
127         buf.append("this.blur(); ");
128         buf.append(openBuf.toString());
129         buf.append("if(windowRef==null || typeof(windowRef)=='undefined') { ");
130         buf.append(" if(setPopupBlocked) { setPopupBlocked(); }");
131         buf.append("} else { windowRef.focus(); }");
132         return buf.toString();
133     }
134 }
135
Popular Tags