]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.editors/src/org/simantics/editors/BrowserInput.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.editors / src / org / simantics / editors / BrowserInput.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.editors;\r
13 \r
14 import java.net.URL;\r
15 \r
16 import org.eclipse.jface.resource.ImageDescriptor;\r
17 import org.eclipse.swt.SWT;\r
18 import org.eclipse.ui.IEditorInput;\r
19 import org.eclipse.ui.IPersistableElement;\r
20 \r
21 /**\r
22  * EditorInput for the Browser component.\r
23  * \r
24  * \r
25  * @author Marko Luukkainen <Marko.Luukkainen@vtt.fi>\r
26  * @author Tuukka Lehtonen\r
27  */\r
28 public class BrowserInput implements IEditorInput {\r
29 \r
30     private URL           url;\r
31     private String        name;\r
32     private final boolean showControls;\r
33     private final boolean fullscreen;\r
34     private int           browserStyle = SWT.NONE;\r
35 \r
36     /**\r
37      * Creates an input for a browser that has visible controls.\r
38      * \r
39      * @param url the url that browser opens.\r
40      */\r
41     public BrowserInput(URL url) {\r
42         this.url = url;\r
43         this.showControls = true;\r
44         this.fullscreen = false;\r
45     }\r
46 \r
47     /**\r
48      * Creates an input for a browser that has visible controls.\r
49      * \r
50      * @param url the url that browser opens.\r
51      */\r
52     public BrowserInput(URL url, String name) {\r
53         this.url = url;\r
54         this.showControls = true;\r
55         this.fullscreen = false;\r
56     }\r
57 \r
58     /**\r
59      * Creates an input for a browser.\r
60      * \r
61      * @param url the url that browser opens.\r
62      * @param showControls visibility flag of controls\r
63      */\r
64     public BrowserInput(URL url, boolean showControls) {\r
65         this.url = url;\r
66         this.showControls = showControls;\r
67         this.fullscreen = false;\r
68     }\r
69 \r
70     public BrowserInput(URL url, boolean showControls, boolean fullscreen) {\r
71         this.url = url;\r
72         this.showControls = showControls;\r
73         this.fullscreen = fullscreen;\r
74     }\r
75 \r
76     public BrowserInput(URL url, boolean showControls, boolean fullscreen, int style) {\r
77         this(url, null, showControls, fullscreen, style);\r
78     }\r
79 \r
80     public BrowserInput(URL url, String name, boolean showControls, boolean fullscreen, int style) {\r
81         this.url = url;\r
82         this.name = name;\r
83         this.showControls = showControls;\r
84         this.fullscreen = fullscreen;\r
85         this.browserStyle = style;\r
86     }\r
87 \r
88     public void setUrl(URL url) {\r
89         this.url = url;\r
90     }\r
91 \r
92     public URL getUrl() {\r
93         return url;\r
94     }\r
95 \r
96     public boolean isShowControls() {\r
97         return showControls;\r
98     }\r
99 \r
100     @Override\r
101     public boolean exists() {\r
102         return false;\r
103     }\r
104 \r
105     @Override\r
106     public ImageDescriptor getImageDescriptor() {\r
107         return null;\r
108     }\r
109 \r
110     public void setName(String name) {\r
111         this.name = name;\r
112     }\r
113 \r
114     @Override\r
115     public String getName() {\r
116         if (name != null)\r
117             return name;\r
118         return url.toString();\r
119     }\r
120 \r
121     @Override\r
122     public IPersistableElement getPersistable() {\r
123         return null;\r
124     }\r
125 \r
126     @Override\r
127     public String getToolTipText() {\r
128         //return getName();\r
129         return getUrl().toString();\r
130     }\r
131 \r
132     public boolean isFullscreen() {\r
133         return fullscreen;\r
134     }\r
135 \r
136     public int getBrowserStyle() {\r
137         return browserStyle;\r
138     }\r
139 \r
140     @SuppressWarnings({ "rawtypes" })\r
141     @Override\r
142     public Object getAdapter(Class adapter) {\r
143         return null;\r
144     }\r
145 \r
146     @Override\r
147     public int hashCode() {\r
148         final int prime = 31;\r
149         int result = 1;\r
150         result = prime * result + browserStyle;\r
151         result = prime * result + (fullscreen ? 1231 : 1237);\r
152         result = prime * result + (showControls ? 1231 : 1237);\r
153         result = prime * result + ((url == null) ? 0 : url.hashCode());\r
154         return result;\r
155     }\r
156 \r
157     @Override\r
158     public boolean equals(Object obj) {\r
159         if (this == obj)\r
160             return true;\r
161         if (obj == null)\r
162             return false;\r
163         if (getClass() != obj.getClass())\r
164             return false;\r
165         BrowserInput other = (BrowserInput) obj;\r
166         if (browserStyle != other.browserStyle)\r
167             return false;\r
168         if (fullscreen != other.fullscreen)\r
169             return false;\r
170         if (showControls != other.showControls)\r
171             return false;\r
172         if (url == null) {\r
173             if (other.url != null)\r
174                 return false;\r
175         } else if (!url.equals(other.url))\r
176             return false;\r
177         return true;\r
178     }\r
179 \r
180 }\r