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: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032: package com.vividsolutions.jump.workbench.ui.plugin;
033:
034: import java.awt.event.ComponentAdapter;
035: import java.awt.event.ComponentEvent;
036: import java.awt.event.ComponentListener;
037: import java.io.File;
038:
039: import org.apache.log4j.Logger;
040:
041: import com.vividsolutions.jump.I18N;
042: import com.vividsolutions.jump.workbench.JUMPWorkbench;
043: import com.vividsolutions.jump.workbench.WorkbenchContext;
044: import com.vividsolutions.jump.workbench.WorkbenchException;
045: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
046: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
047:
048: /**
049: * Opens a TaskFrame when the Workbench starts up
050: */
051: public class FirstTaskFramePlugIn extends OpenProjectPlugIn {//AbstractPlugIn {
052:
053: private static Logger LOG = Logger
054: .getLogger(FirstTaskFramePlugIn.class);
055:
056: public FirstTaskFramePlugIn() {
057: }
058:
059: private ComponentListener componentListener;
060:
061: public void initialize(final PlugInContext context)
062: throws Exception {
063:
064: componentListener = new ComponentAdapter() {
065: public void componentShown(ComponentEvent e) {
066: //Two reasons wait until the frame is shown before adding the task frame:
067: //(1) Otherwise the task frame won't be selected (2) Otherwise GUIUtil.setLocation
068: //will throw an IllegalComponentStateException. [Jon Aquino]
069: //UT skip this; see 1st if there is a filename available
070: // if so, load it
071: String filename = (String) context
072: .getWorkbenchContext().getBlackboard().get(
073: JUMPWorkbench.INITIAL_PROJECT_FILE);
074:
075: if (filename == null) {//create empty task
076: context.getWorkbenchFrame().addTaskFrame();
077: } else {
078:
079: LOG.info("Found initial project file: " + filename);
080:
081: File f = new File(filename);
082:
083: try {
084: open(f, context.getWorkbenchFrame());
085: initialize(context);
086: run(null, context);
087: } catch (Exception ex) {
088: String mesg = "Could not load initial file";
089: LOG.error(mesg);
090: context.getWorkbenchFrame().warnUser(mesg);
091: context.getWorkbenchFrame().addTaskFrame();
092: }
093: }
094:
095: context.getWorkbenchFrame().removeComponentListener(
096: componentListener);
097: }
098: };
099: context.getWorkbenchFrame().addComponentListener(
100: componentListener);
101: }
102: }
|