001/*
002 * Copyright (c) 2004-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: welker $'
006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 
007 * '$Revision: 24234 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.kepler.gis.display;
031
032import ptolemy.actor.TypedAtomicActor;
033import ptolemy.actor.TypedIOPort;
034import ptolemy.data.StringToken;
035import ptolemy.data.type.BaseType;
036import ptolemy.kernel.CompositeEntity;
037import ptolemy.kernel.util.IllegalActionException;
038import ptolemy.kernel.util.NameDuplicationException;
039
040/**
041 * Name: JumpSHPDisplayer.java Purpose:The actor serves as a proxy to invoke a
042 * frame window to display ESRI shape file. Knwon problem: the actor currently
043 * only takes local file (no "file://" prefix is needed). Directly read remote
044 * file and/or use URI is planned. Author: Jianting Zhang Date: August, 2005
045 */
046public class JumpSHPDisplayer extends TypedAtomicActor {
047        // input port: file name of the shapefile to display
048        /** Description of the Field */
049        public TypedIOPort SHPFileNamePort = new TypedIOPort(this,
050                        "SHPFileNamePort", true, false);
051
052        /**
053         * Constructor for the JumpSHPDisplayer object
054         * 
055         *@param container
056         *            Description of the Parameter
057         *@param name
058         *            Description of the Parameter
059         *@exception NameDuplicationException
060         *                Description of the Exception
061         *@exception IllegalActionException
062         *                Description of the Exception
063         */
064        public JumpSHPDisplayer(CompositeEntity container, String name)
065                        throws NameDuplicationException, IllegalActionException {
066
067                super(container, name);
068                SHPFileNamePort.setTypeEquals(BaseType.STRING);
069
070                _attachText(
071                                "_iconDescription",
072                                "<svg>\n"
073                                                + "<rect x=\"-20\" y=\"-15\" "
074                                                + "width=\"40\" height=\"30\" "
075                                                + "style=\"fill:lightGrey\"/>\n"
076                                                + "<rect x=\"-15\" y=\"-10\" "
077                                                + "width=\"30\" height=\"20\" "
078                                                + "style=\"fill:white\"/>\n"
079                                                + "<line x1=\"-13\" y1=\"-6\" x2=\"-4\" y2=\"-6\" "
080                                                + "style=\"stroke:grey\"/>\n"
081                                                + "<line x1=\"-13\" y1=\"-2\" x2=\"0\" y2=\"-2\" "
082                                                + "style=\"stroke:grey\"/>\n"
083                                                + "<line x1=\"-13\" y1=\"2\" x2=\"-8\" y2=\"2\" "
084                                                + "style=\"stroke:grey\"/>\n"
085                                                + "<line x1=\"-13\" y1=\"6\" x2=\"4\" y2=\"6\" "
086                                                + "style=\"stroke:grey\"/>\n"
087                                                + "<text x=\"-10\" y=\"-10\" font-size=\"10\" fill=\"blue\">Shape</text>"
088                                                + "</svg>\n");
089        }
090
091        /**
092         *@exception IllegalActionException
093         *                Description of the Exception
094         */
095        public void initialize() throws IllegalActionException {
096        }
097
098        /**
099         *@return Description of the Return Value
100         *@exception IllegalActionException
101         *                Description of the Exception
102         */
103        public boolean prefire() throws IllegalActionException {
104                return super.prefire();
105        }
106
107        /**
108         *@exception IllegalActionException
109         *                Description of the Exception
110         */
111        public void fire() throws IllegalActionException {
112                // System.out.println("firing JumpSHPDisplayer");
113                super.fire();
114
115                StringToken SHPFileNameToken = (StringToken) SHPFileNamePort.get(0);
116                String SHPFileName = SHPFileNameToken.stringValue();
117                // note: URI prefix like "file://" is not handling here
118
119                System.out.println(SHPFileName);
120                try {
121                        JumpFrame frame = new JumpFrame(this.getName());
122                        frame.setVisible(true);
123                        frame.addSHPLayer(SHPFileName, this.getName());
124                } catch (Exception e) {
125                        e.printStackTrace();
126                }
127        }
128
129        /**
130         * The main program for the JumpSHPDisplayer class
131         * 
132         *@param args
133         *            The command line arguments
134         *@exception Exception
135         *                Description of the Exception
136         */
137        public static void main(String[] args) throws Exception {
138                JumpSHPDisplayer d = new JumpSHPDisplayer(null, "");
139                d.fire();
140        }
141}