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