001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * JUMP is Copyright (C) 2003 Vivid Solutions
006: *
007: * This program implements extensions to JUMP and is
008: * Copyright (C) 2004 Integrated Systems Analysts, Inc.
009: *
010: * This program is free software; you can redistribute it and/or
011: * modify it under the terms of the GNU General Public License
012: * as published by the Free Software Foundation; either version 2
013: * of the License, or (at your option) any later version.
014: *
015: * This program is distributed in the hope that it will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: * GNU General Public License for more details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with this program; if not, write to the Free Software
022: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
023: *
024: * For more information, contact:
025: *
026: * Integrated Systems Analysts, Inc.
027: * 630C Anchors St., Suite 101
028: * Fort Walton Beach, Florida 32548
029: * USA
030: *
031: * (850)862-7321
032: * www.ashs.isa.com
033: */
034:
035: package org.openjump.core.ui.plugin.layer;
036:
037: import java.io.File;
038: import java.util.ArrayList;
039: import java.util.Collection;
040: import java.util.List;
041: import javax.swing.JFileChooser;
042: import javax.swing.filechooser.FileFilter;
043:
044: import org.openjump.io.SIDLayer;
045:
046: import com.vividsolutions.jump.I18N;
047: import com.vividsolutions.jump.workbench.WorkbenchContext;
048: import com.vividsolutions.jump.workbench.model.StandardCategoryNames;
049: import com.vividsolutions.jump.workbench.model.UndoableCommand;
050: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
051: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
052: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
053: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
054: import com.vividsolutions.jump.workbench.ui.GUIUtil;
055: import com.vividsolutions.jump.workbench.ui.MenuNames;
056: import com.vividsolutions.wms.MapLayer;
057:
058: //modeled after the AddWMSQueryPlugIn
059: public class AddSIDLayerPlugIn extends AbstractPlugIn {
060: final static String sAddMrSIDLayer = I18N
061: .get("org.openjump.core.ui.plugin.layer.AddSIDLayerPlugIn.Add-MrSID-Layer");
062: final static String sErrorSeeOutputWindow = I18N
063: .get("org.openjump.core.ui.plugin.layer.AddSIDLayerPlugIn.Error-See-Output-Window");
064: final static String sNotInstalled = I18N
065: .get("org.openjump.core.ui.plugin.layer.AddSIDLayerPlugIn.not-installed");
066: final static String sOpenMrSIDFile = I18N
067: .get("org.openjump.core.ui.plugin.layer.AddSIDLayerPlugIn.open-MrSID-file");
068: final static String sFiles = I18N
069: .get("org.openjump.core.ui.plugin.layer.AddSIDLayerPlugIn.files");
070:
071: public static String WORKING_DIR;
072: public static String ETC_PATH;
073: public static String TMP_PATH;
074: public static String MRSIDDECODE;
075: public static String MRSIDINFO;
076:
077: public void initialize(PlugInContext context) throws Exception {
078: context.getFeatureInstaller().addMainMenuItemWithJava14Fix(
079: this , new String[] { MenuNames.LAYER },
080: sAddMrSIDLayer + "{pos:3}", false, null,
081: this .createEnableCheck(context.getWorkbenchContext()));
082: File empty = new File("");
083: String sep = File.separator;
084: WORKING_DIR = empty.getAbsoluteFile().getParent() + sep;
085: ETC_PATH = WORKING_DIR + "etc" + sep;
086: TMP_PATH = WORKING_DIR + "tmp" + sep;
087: MRSIDDECODE = ETC_PATH + "mrsiddecode.exe";
088: MRSIDINFO = ETC_PATH + "mrsidinfo.exe";
089: }
090:
091: public boolean execute(final PlugInContext context)
092: throws Exception {
093: reportNothingToUndoYet(context);
094: try {
095: context.getWorkbenchFrame().getOutputFrame()
096: .createNewDocument();
097:
098: if (!new File(MRSIDDECODE).exists()) {
099: context.getWorkbenchFrame().warnUser(
100: sErrorSeeOutputWindow);
101: context.getWorkbenchFrame().getOutputFrame().addText(
102: MRSIDDECODE + " " + sNotInstalled);
103: return false;
104: }
105:
106: if (!new File(MRSIDINFO).exists()) {
107: context.getWorkbenchFrame().warnUser(
108: sErrorSeeOutputWindow);
109: context.getWorkbenchFrame().getOutputFrame().addText(
110: MRSIDINFO + " " + sNotInstalled);
111: return false;
112: }
113:
114: JFileChooser fileChooser = new JFileChooser();
115: fileChooser = GUIUtil
116: .createJFileChooserWithExistenceChecking();
117: fileChooser.setDialogTitle(sOpenMrSIDFile);
118: fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
119: fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
120: fileChooser.setMultiSelectionEnabled(true);
121: GUIUtil.removeChoosableFileFilters(fileChooser);
122: FileFilter fileFilter = GUIUtil.createFileFilter("MrSID "
123: + sFiles, new String[] { "sid" });
124: fileChooser.addChoosableFileFilter(fileFilter);
125: fileChooser.setFileFilter(fileFilter);
126:
127: if (JFileChooser.APPROVE_OPTION == fileChooser
128: .showOpenDialog(context.getWorkbenchFrame())) {
129: List imageFilenames = new ArrayList();
130: File[] files = fileChooser.getSelectedFiles();
131: for (int i = 0; i < files.length; i++) {
132: String filename = files[i].getCanonicalPath();
133: imageFilenames.add(filename);
134: }
135:
136: final SIDLayer layer = new SIDLayer(context,
137: imageFilenames);
138: execute(new UndoableCommand(getName()) {
139: public void execute() {
140: Collection selectedCategories = context
141: .getLayerNamePanel()
142: .getSelectedCategories();
143: context
144: .getLayerManager()
145: .addLayerable(
146: selectedCategories.isEmpty() ? StandardCategoryNames.WORKING
147: : selectedCategories
148: .iterator()
149: .next()
150: .toString(),
151: layer);
152: }
153:
154: public void unexecute() {
155: context.getLayerManager().remove(layer);
156: }
157: }, context);
158:
159: return true;
160: } else {
161: return false;
162: }
163: }
164:
165: catch (Exception e) {
166: context.getWorkbenchFrame().warnUser(sErrorSeeOutputWindow);
167: context.getWorkbenchFrame().getOutputFrame().addText(
168: "AddSIDLayerPlugIn Exception:" + e.toString());
169: return false;
170: }
171: }
172:
173: public MultiEnableCheck createEnableCheck(
174: final WorkbenchContext workbenchContext) {
175: EnableCheckFactory checkFactory = new EnableCheckFactory(
176: workbenchContext);
177: return new MultiEnableCheck().add(checkFactory
178: .createTaskWindowMustBeActiveCheck());
179: }
180: }
|