nl.cloudfarming.client.geoviewer.jxmap.MapViewerTopComponent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geoviewer-jxmap Show documentation
Show all versions of geoviewer-jxmap Show documentation
AgroSense geoviewer JXMap implementation. Contains a map/geoviewer TopComponent based on the JXMap classes from swingx.
/**
* Copyright (C) 2010-2012 Agrosense [email protected]
*
* 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.jxmap;
import java.awt.BorderLayout;
import java.util.logging.Logger;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.explorer.ExplorerManager;
import org.openide.explorer.ExplorerUtils;
import org.openide.util.ImageUtilities;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
/**
* Top component which displays something.
*/
@ConvertAsProperties(dtd = "-//nl.cloudfarming.client.geoviewer.jxmap//MapViewerTopComponent//EN", autostore = false)
public final class MapViewerTopComponent extends TopComponent implements ExplorerManager.Provider {
private static MapViewerTopComponent instance;
/** path to the icon used by the component and its open action */
static final String ICON_PATH = "nl/cloudfarming/client/icon/map-icon24.png";
private static final String PREFERRED_ID = "MapViewerTopComponent";
private final MapDataManager mapDataManager = new MapDataManager();
private final MapView mapView = new MapView();
public MapViewerTopComponent() {
initComponents();
setName(NbBundle.getMessage(MapViewerTopComponent.class, "CTL_MapViewerTopComponent"));
setToolTipText(NbBundle.getMessage(MapViewerTopComponent.class, "HINT_MapViewerTopComponent"));
setIcon(ImageUtilities.loadImage(ICON_PATH, true));
associateLookup(mapView.getLookup());
}
/** This method is called from within the constructor to
* initialize the form.
*/
private void initComponents() {
setLayout(new BorderLayout());
//
// add mapDataManager as LayerDropTarget to the mapView so dragged layers can be added
//
mapView.addLayerDropTarget(mapDataManager);
add(mapView, BorderLayout.CENTER);
}
/**
* 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 MapViewerTopComponent getDefault() {
if (instance == null) {
instance = new MapViewerTopComponent();
}
return instance;
}
/**
* Obtain the TestWindowTopComponent instance. Never call {@link #getDefault} directly!
*/
public static synchronized MapViewerTopComponent findInstance() {
TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
if (win == null) {
Logger.getLogger(MapViewerTopComponent.class.getName()).warning(
"Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
return getDefault();
}
if (win instanceof MapViewerTopComponent) {
return (MapViewerTopComponent) win;
}
Logger.getLogger(MapViewerTopComponent.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;
}
@Override
public ExplorerManager getExplorerManager() {
return mapDataManager.getExplorerManager();
}
// It is good idea to switch all listeners on and off when the
// component is shown or hidden. In the case of TopComponent use:
@Override
protected void componentActivated() {
ExplorerUtils.activateActions(mapDataManager.getExplorerManager(), true);
// mapDataManager.setActive(true);
}
@Override
protected void componentDeactivated() {
ExplorerUtils.activateActions(mapDataManager.getExplorerManager(), false);
// mapDataManager.setActive(false);
}
}