001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
004 *
005 * "Hilbert II" is free software; you can redistribute
006 * it and/or modify it under the terms of the GNU General Public
007 * License as published by the Free Software Foundation; either
008 * version 2 of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 */
015
016 package org.qedeq.gui.se.pane;
017
018 import java.awt.BorderLayout;
019 import java.awt.Font;
020 import java.awt.event.ComponentAdapter;
021 import java.awt.event.ComponentEvent;
022 import java.io.IOException;
023
024 import javax.swing.DebugGraphics;
025 import javax.swing.JEditorPane;
026 import javax.swing.JPanel;
027 import javax.swing.JScrollPane;
028 import javax.swing.JViewport;
029 import javax.swing.event.HyperlinkEvent;
030 import javax.swing.event.HyperlinkListener;
031 import javax.swing.text.html.HTMLDocument;
032 import javax.swing.text.html.HTMLFrameHyperlinkEvent;
033
034 import org.qedeq.base.trace.Trace;
035 import org.qedeq.kernel.bo.common.QedeqBo;
036 import org.qedeq.kernel.se.common.LoadingState;
037 import org.qedeq.kernel.se.common.ModuleAddress;
038
039 /**
040 * HTML view for module.
041 *
042 * TODO mime 20070606: not implemented yet
043 *
044 * @deprecated Not ready for usage.
045 * @author Michael Meyling
046 */
047
048 public class HtmlPane extends JPanel {
049
050 /** This class. */
051 private static final Class CLASS = HtmlPane.class;
052
053 /** Module properties for selected module. */
054 private QedeqBo prop;
055
056 // private JEditorPane html = new JEditorPane();
057 // TODO test example:
058 /** The HTML pane. */
059 private JEditorPane html = new JEditorPane("text/html", "\u1200");
060
061 /** View blocked? */
062 private boolean blocked = false;
063
064 /** Current module address. */
065 private ModuleAddress currentAddress = null;
066
067 /** Current loading state. */
068 private LoadingState currentState;
069
070
071 /**
072 * Creates new Panel.
073 */
074 public HtmlPane() {
075 super(false);
076 this.prop = null;
077 this.currentAddress = null;
078 this.currentState = null;
079 setupView();
080 updateView();
081 }
082
083
084 /**
085 * Assembles the gui components of the panel.
086 */
087 private final void setupView() {
088 html.setDragEnabled(true);
089 html.setAutoscrolls(true);
090 html.setCaretPosition(0);
091 html.setEditable(false);
092 html.getCaret().setVisible(false);
093 html.setFocusable(true);
094 html.setDebugGraphicsOptions(DebugGraphics.LOG_OPTION);
095 // TODO work out:
096 // html.addHyperlinkListener(createHyperLinkListener());
097 final JScrollPane scroller = new JScrollPane();
098 final JViewport vp = scroller.getViewport();
099 vp.add(html);
100 this.setLayout(new BorderLayout(1, 1));
101 this.add(scroller);
102
103 this.addComponentListener(new ComponentAdapter() {
104 public void componentHidden(final ComponentEvent e) {
105 Trace.trace(CLASS, this, "componentHidden", e);
106 }
107 public void componentShown(final ComponentEvent e) {
108 Trace.trace(CLASS, this, "componentHidden", e);
109 }
110 });
111
112 }
113
114
115 /**
116 * Set new model. To make the new model visible {@link #updateView} must be called.
117 *
118 * @param prop QEDEQ module.
119 */
120 public synchronized void setModel(final QedeqBo prop) {
121 Trace.trace(CLASS, this, "setModel", prop);
122 this.prop = prop;
123 }
124
125 /**
126 * Get current model.
127 *
128 * @return Model.
129 */
130 public synchronized QedeqBo getModel() {
131 return this.prop;
132 }
133
134 /**
135 * Update from model.
136 */
137 public synchronized void updateView() {
138 Trace.begin(CLASS, this, "updateView");
139 boolean refresh = false;
140 if (prop == null && this.currentAddress != null) {
141 refresh = true;
142 }
143 if (prop != null && !prop.getModuleAddress().equals(this.currentAddress)) {
144 this.currentAddress = prop.getModuleAddress();
145 refresh = true;
146 }
147 if (prop != null && this.currentState != prop.getLoadingState()) {
148 this.currentState = prop.getLoadingState();
149 refresh = true;
150 }
151 if (refresh && this.prop != null && (this.prop.getLoadingState()
152 == LoadingState.STATE_LOADED) && !this.blocked) {
153 this.blocked = true;
154 try {
155 // final Module2JHtml converter = new Module2JHtml(prop.getModuleAddress());
156 // converter.writeModule();
157 html.setFont(new Font("Lucida Bright", Font.PLAIN, 12));
158 html.setText("<html><body>"
159 + "\u2227 Hallo \u2227 Werter \u2227 \u2227 \u2227"
160 + "<br>"
161 + "<table>"
162 + "<tr><td>Hei</td><td>ho</td></tr>"
163 + "<tr><td>Ostern</td><td>weihnacht</td></tr>"
164 + "</table>"
165 + "</body></html>");
166 // html.setPage(converter.getGeneratedUrl());
167 // html.setText(converter.getText());
168
169 } catch (Exception e) {
170 Trace.trace(CLASS, this, "updateView", e);
171 html.setText("");
172 }
173 this.blocked = false;
174 } else {
175 html.setText("");
176 }
177 this.repaint();
178 Trace.end(CLASS, this, "updateView");
179 }
180
181 public HyperlinkListener createHyperLinkListener() {
182 return new HyperlinkListener() {
183 public void hyperlinkUpdate(final HyperlinkEvent e) {
184 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
185 if (e instanceof HTMLFrameHyperlinkEvent) {
186 ((HTMLDocument) html.getDocument()).processHTMLFrameHyperlinkEvent(
187 (HTMLFrameHyperlinkEvent) e);
188 } else {
189 try {
190 html.setPage(e.getURL());
191 } catch (IOException ioe) {
192 Trace.fatal(CLASS, this, "createHyperLinkListener",
193 "page not found", ioe);
194 }
195 }
196 }
197 }
198 };
199 }
200
201 }
|