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:
033: package com.vividsolutions.jump.workbench.ui;
034:
035: import java.awt.BorderLayout;
036: import java.awt.GridBagConstraints;
037: import java.awt.GridBagLayout;
038: import java.awt.Insets;
039:
040: import javax.swing.JEditorPane;
041: import javax.swing.JInternalFrame;
042: import javax.swing.JPanel;
043: import javax.swing.JScrollPane;
044: import javax.swing.UIManager;
045:
046: import org.apache.log4j.Logger;
047:
048: public class TextFrame extends JInternalFrame {
049: private static Logger LOG = Logger.getLogger(TextFrame.class);
050: BorderLayout borderLayout1 = new BorderLayout();
051: private OKCancelPanel okCancelPanel = new OKCancelPanel();
052: protected JPanel scrollPanePanel = new JPanel();
053: JScrollPane scrollPane = new JScrollPane();
054: GridBagLayout gridBagLayout = new GridBagLayout();
055: private JEditorPane editorPane = new JEditorPane();
056: private ErrorHandler errorHandler;
057:
058: public TextFrame(ErrorHandler errorHandler) {
059: this (false, errorHandler);
060: }
061:
062: public TextFrame(boolean showingButtons, ErrorHandler errorHandler) {
063: this .errorHandler = errorHandler;
064:
065: try {
066: jbInit();
067: okCancelPanel.setVisible(showingButtons);
068: } catch (Exception e) {
069: errorHandler.handleThrowable(e);
070: }
071: }
072:
073: public OKCancelPanel getOKCancelPanel() {
074: return okCancelPanel;
075: }
076:
077: private void jbInit() throws Exception {
078: this .getContentPane().setLayout(borderLayout1);
079: this .setResizable(true);
080: this .setClosable(true);
081: this .setMaximizable(true);
082: this .setIconifiable(true);
083: this .setSize(500, 300);
084: scrollPanePanel.setLayout(gridBagLayout);
085: editorPane.setBackground(UIManager
086: .getColor("inactiveCaptionBorder"));
087: editorPane.setText("jEditorPane1");
088: editorPane.setContentType("text/html");
089: getContentPane().add(getOKCancelPanel(), BorderLayout.SOUTH);
090: this .getContentPane().add(scrollPanePanel, BorderLayout.CENTER);
091: scrollPanePanel.add(scrollPane, new GridBagConstraints(0, 0,
092: GridBagConstraints.REMAINDER, 1, 1.0, 1.0,
093: GridBagConstraints.CENTER, GridBagConstraints.BOTH,
094: new Insets(0, 0, 0, 0), 0, 0));
095: scrollPane.getViewport().add(editorPane, null);
096: }
097:
098: public void clear() {
099: setText("");
100: }
101:
102: public void setText(final String s) {
103: try {
104: editorPane.setText(s);
105: editorPane.setCaretPosition(0);
106: } catch (Throwable t) {
107: LOG.error(s);
108: errorHandler.handleThrowable(t);
109: }
110: }
111:
112: public String getText() {
113: return editorPane.getText();
114: }
115: }
|