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 com.vividsolutions.jts.util.Assert;
035:
036: import com.vividsolutions.jump.I18N;
037: import com.vividsolutions.jump.util.FileUtil;
038: import com.vividsolutions.jump.util.StringUtil;
039: import com.vividsolutions.jump.workbench.WorkbenchContext;
040: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
041: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
042: import com.vividsolutions.jump.workbench.ui.HTMLFrame;
043:
044: import java.io.BufferedReader;
045: import java.io.IOException;
046: import java.io.InputStream;
047: import java.io.InputStreamReader;
048:
049: import java.util.Iterator;
050:
051: import org.apache.log4j.Logger;
052:
053: //In the HTML file (generated by FrontPage I think), there were <TBODY> tags.
054: //These were causing the following exception (also JTextArea#setText was unnecessarily
055: //being called a second time; plus, this is happening in J2SE 1.4 -- I don't think
056: //it happens in 1.3).
057: //
058: //java.lang.ArrayIndexOutOfBoundsException: 0
059: // at javax.swing.text.BoxView.getOffset(BoxView.java:1079)
060: // at javax.swing.text.BoxView.childAllocation(BoxView.java:669)
061: // at javax.swing.text.CompositeView.getChildAllocation(CompositeView.java:215)
062: // at javax.swing.text.BoxView.getChildAllocation(BoxView.java:427)
063: // at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.calculateViewPosition(BasicTextUI.java:1850)
064: // at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.layoutContainer(BasicTextUI.java:1826)
065: // at java.awt.Container.layout(Container.java:1017)
066: // at java.awt.Container.doLayout(Container.java:1007)
067: // at java.awt.Container.validateTree(Container.java:1089)
068: //
069: //[Jon Aquino]
070: public class ShortcutKeysPlugIn extends AbstractPlugIn {
071:
072: private static Logger LOG = Logger
073: .getLogger(ShortcutKeysPlugIn.class);
074: private static String html = null;
075:
076: private HTMLFrame frame(WorkbenchContext context) {
077: String key = getClass().getName() + " - "
078: + I18N.get("ui.plugin.ShortcutKeyPlugIn.frame");
079:
080: if (context.getWorkbench().getBlackboard().get(key) == null) {
081: HTMLFrame frame = new HTMLFrame(context.getWorkbench()
082: .getFrame());
083: frame.setRecordNavigationControlVisible(false);
084: frame.createNewDocument();
085:
086: try {
087: append(frame);
088: } catch (IOException e) {
089: Assert.shouldNeverReachHere();
090: }
091:
092: frame.setTitle(I18N
093: .get("ui.plugin.ShortcutKeyPlugIn.shortcut-keys"));
094: frame.setSize(420, 290);
095: context.getWorkbench().getBlackboard().put(key, frame);
096: }
097:
098: return (HTMLFrame) context.getWorkbench().getBlackboard().get(
099: key);
100: }
101:
102: public static String html() throws IOException {
103: if (html == null) {
104: html = "";
105: LOG
106: .debug("com.vividsolutions.jump.workbench.ui.plugin.KeyboardPlugIn_"
107: + I18N.getLanguage() + ".html");
108: InputStream inputStream = ShortcutKeysPlugIn.class
109: .getResourceAsStream("KeyboardPlugIn_"
110: + I18N.getLanguage() + ".html");
111: if (inputStream == null) {
112: LOG
113: .error("No com.vividsolutions.jump.workbench.ui.plugin.KeyboardPlugIn_"
114: + I18N.getLanguage()
115: + ".html file. Use default instead.");
116: inputStream = ShortcutKeysPlugIn.class
117: .getResourceAsStream("KeyboardPlugIn_.html");
118: } else {
119: try {
120: for (Iterator i = FileUtil.getContents(inputStream)
121: .iterator(); i.hasNext();) {
122: String line = (String) i.next();
123: html += line;
124: }
125: } finally {
126: inputStream.close();
127: }
128: }
129: }
130: return html;
131: }
132:
133: private void append(HTMLFrame frame) throws IOException {
134: //I get ArrayIndexOutOfBoundsExceptions when I tried calling #append
135: //on each line separately. So #append all the HTML at once. [Jon Aquino]
136: //Remove <HTML> and </HTML> tags because #append adds them. [Jon Aquino]
137: frame.append(removeHTMLTags(html()));
138: }
139:
140: private String removeHTMLTags(String s) {
141: return StringUtil.replaceAll(StringUtil.replaceAll(s, "<html>",
142: ""), "</html>", "");
143: }
144:
145: public boolean execute(PlugInContext context) throws Exception {
146: frame(context.getWorkbenchContext()).surface();
147:
148: return true;
149: }
150: }
|