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.main;
017
018 import java.awt.GridLayout;
019
020 import javax.swing.BorderFactory;
021 import javax.swing.JPanel;
022 import javax.swing.JTabbedPane;
023
024 import org.qedeq.base.trace.Trace;
025 import org.qedeq.gui.se.control.SelectionListener;
026 import org.qedeq.gui.se.control.SelectionListenerList;
027 import org.qedeq.gui.se.pane.HtmlPane;
028 import org.qedeq.gui.se.pane.ModulePropertiesPane;
029 import org.qedeq.gui.se.pane.QedeqPane;
030 import org.qedeq.kernel.bo.common.QedeqBo;
031 import org.qedeq.kernel.se.common.SourceFileException;
032
033
034 /**
035 * Upper tabbed pane view.
036 *
037 * @version $Revision: 1.6 $
038 * @author Michael Meyling
039 */
040 public final class UpperTabbedView extends JPanel implements SelectionListener {
041
042 /** This class. */
043 private static final Class CLASS = UpperTabbedView.class;
044
045 /** Holds all tabs. */
046 private JTabbedPane tabbedPane = new JTabbedPane();
047
048 /** Source view of QEDEQ module. */
049 private QedeqPane qedeqPane;
050
051 /** HTML display of QEDEQ module. */
052 private HtmlPane htmlPane;
053
054 /** Currently active module properties. */
055 private QedeqBo prop;
056
057 /** Show properties and status of QEDEQ module. */
058 private ModulePropertiesPane propertiesPane;
059
060 /** Flag for showing the HTML pane. */
061 private boolean viewHtml = false;
062
063
064 /**
065 * Constructor.
066 *
067 * @param listener This listener gets all selection events.
068 */
069 public UpperTabbedView(final SelectionListenerList listener) {
070 try {
071 propertiesPane = new ModulePropertiesPane();
072 qedeqPane = new QedeqPane();
073 // add this instance as error selection listener
074 listener.addListener(qedeqPane);
075
076 htmlPane = new HtmlPane();
077 tabbedPane.addTab("State", null, propertiesPane, "Shows Status of Module");
078 tabbedPane.addTab("QEDEQ", null, qedeqPane, "Shows Module in QEDEQ Syntax");
079 /*
080 if (viewHtml) {
081 addTab("Html", icon, Factory.createStrippedScrollPane(htmlPane),
082 "Shows Module in Html-View");
083 }
084 */
085 setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
086 } catch (RuntimeException e) {
087 Trace.trace(CLASS, this, "constructor", e);
088 throw e;
089 }
090 // setSelectedIndex(0);
091
092 // Add the tabbed pane to this panel.
093 add(tabbedPane);
094 setLayout(new GridLayout(1, 1));
095 }
096
097 public final void setHtmlView(final boolean enable) {
098 viewHtml = enable;
099 if (enable) {
100 tabbedPane.addTab("Html", null, htmlPane, "Shows Module in Html-View");
101 htmlPane.updateView();
102 } else {
103 tabbedPane.remove(htmlPane);
104 }
105 }
106
107 public boolean getHtmlView() {
108 return viewHtml;
109 }
110
111 public void setQedeqModel(final QedeqBo model) {
112 propertiesPane.setModel(model);
113 qedeqPane.setModel(model);
114 htmlPane.setModel(model);
115 if (prop != model) {
116 prop = model;
117 updateView();
118 }
119 }
120
121 public QedeqBo getQedeqModel() {
122 return prop;
123 }
124
125
126 public final void updateView() {
127 propertiesPane.updateView();
128 qedeqPane.updateView();
129 if (viewHtml) {
130 htmlPane.updateView();
131 }
132 }
133
134
135 public void setLineWrap(final boolean wrap) {
136 qedeqPane.setLineWrap(wrap);
137 }
138
139 public boolean getLineWrap() {
140 return qedeqPane.getLineWrap();
141 }
142
143 /**
144 * Get edited QEDEQ text, if text is editable.
145 *
146 * @return QEDEQ text.
147 * @throws IllegalStateException QEDEQ text is not editable.
148 */
149 public String getEditedQedeq() {
150 return qedeqPane.getEditedQedeq();
151 }
152
153 public void selectError(final int number, final SourceFileException sf) {
154 tabbedPane.setSelectedComponent(qedeqPane);
155 }
156
157 public void selectWarning(final int number, final SourceFileException sf) {
158 tabbedPane.setSelectedComponent(qedeqPane);
159 }
160
161 }
|