nl.cloudfarming.client.geoviewer.edit.GeoEditorTopComponent Maven / Gradle / Ivy
/**
* Copyright (C) 2011 Agrosense
*
* Licensed under the Eclipse Public License - v 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.cloudfarming.client.geoviewer.edit;
import java.awt.BorderLayout;
import java.util.logging.Logger;
import javax.swing.JScrollPane;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.util.ImageUtilities;
/**
* Top component which displays something.
*/
@ConvertAsProperties(dtd = "-//nl.cloudfarming.client.geoviewer//GeoEditor//EN",
autostore = false)
public final class GeoEditorTopComponent extends TopComponent {
private final GeoEditorController controller = new GeoEditorController();
private static GeoEditorTopComponent instance;
/** path to the icon used by the component and its open action */
static final String ICON_PATH = "nl/cloudfarming/client/icon/map-edit-icon24.png";
private static final String PREFERRED_ID = "GeoEditorTopComponent";
public GeoEditorTopComponent() {
setLayout(new BorderLayout());
setName(NbBundle.getMessage(GeoEditorTopComponent.class, "CTL_GeoEditorTopComponent"));
setToolTipText(NbBundle.getMessage(GeoEditorTopComponent.class, "HINT_GeoEditorTopComponent"));
setIcon(ImageUtilities.loadImage(ICON_PATH, true));
JScrollPane scrollPane = new JScrollPane();
add(scrollPane);
scrollPane.setViewportView(controller.getView());
}
/**
* Gets default instance. Do not use directly: reserved for *.settings files only,
* i.e. deserialization routines; otherwise you could get a non-deserialized instance.
* To obtain the singleton instance, use {@link #findInstance}.
*/
public static synchronized GeoEditorTopComponent getDefault() {
if (instance == null) {
instance = new GeoEditorTopComponent();
}
return instance;
}
/**
* Obtain the GeoEditorTopComponent instance. Never call {@link #getDefault} directly!
*/
public static synchronized GeoEditorTopComponent findInstance() {
TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
if (win == null) {
Logger.getLogger(GeoEditorTopComponent.class.getName()).warning(
"Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
return getDefault();
}
if (win instanceof GeoEditorTopComponent) {
return (GeoEditorTopComponent) win;
}
Logger.getLogger(GeoEditorTopComponent.class.getName()).warning(
"There seem to be multiple components with the '" + PREFERRED_ID
+ "' ID. That is a potential source of errors and unexpected behavior.");
return getDefault();
}
@Override
public int getPersistenceType() {
return TopComponent.PERSISTENCE_ALWAYS;
}
void writeProperties(java.util.Properties p) {
// better to version settings since initial version as advocated at
// http://wiki.apidesign.org/wiki/PropertyFiles
p.setProperty("version", "1.0");
}
Object readProperties(java.util.Properties p) {
if (instance == null) {
instance = this;
}
instance.readPropertiesImpl(p);
return instance;
}
private void readPropertiesImpl(java.util.Properties p) {
String version = p.getProperty("version");
}
@Override
protected String preferredID() {
return PREFERRED_ID;
}
}