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.Component;
019 import java.awt.Dimension;
020 import java.awt.GridLayout;
021
022 import javax.swing.BorderFactory;
023 import javax.swing.JComponent;
024 import javax.swing.JPanel;
025 import javax.swing.JScrollPane;
026 import javax.swing.JTextArea;
027 import javax.swing.JTextField;
028 import javax.swing.ScrollPaneConstants;
029
030 import org.qedeq.gui.se.util.GuiHelper;
031 import org.qedeq.kernel.bo.common.QedeqBo;
032 import org.qedeq.kernel.se.common.Plugin;
033
034 import com.jgoodies.forms.builder.DefaultFormBuilder;
035 import com.jgoodies.forms.layout.FormLayout;
036
037 /**
038 * View for {@link QedeqBo}s.
039 *
040 * @author Michael Meyling
041 */
042
043 public class ModulePropertiesPane extends JPanel {
044
045 /** Reference to module properties. */
046 private QedeqBo prop;
047
048 /** State of module. */
049 private JTextField state;
050
051 /** Currently running plugin. */
052 private JTextField plugin;
053
054 /** Module name. */
055 private JTextField name;
056
057 /** Module rule version. */
058 private JTextField ruleVersion;
059
060 /** URL of module. */
061 private JTextArea url;
062
063 /** Module errors and warnings. */
064 private JTextField errorsAndWarnings;
065
066
067 /**
068 * Creates new Panel.
069 */
070 public ModulePropertiesPane() {
071 super();
072 this.prop = null;
073 setupView();
074 updateView();
075 }
076
077 private JComponent buildTestPanel() {
078 FormLayout layout = new FormLayout(
079 "right:pref, 5dlu, fill:50dlu:grow"); // columns
080 // + "pref, 3dlu, pref"); // rows
081
082 DefaultFormBuilder builder = new DefaultFormBuilder(layout);
083 builder.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
084 builder.getPanel().setOpaque(false);
085 builder.setDefaultDialogBorder();
086
087 builder.append("State");
088 state = createTextField("", false);
089 builder.append(state);
090
091 builder.append("Name");
092 name = createTextField("", false);
093 builder.append(name);
094
095 builder.append("Rule Version");
096 ruleVersion = createTextField("", false);
097 builder.append(ruleVersion);
098
099 builder.append("URL");
100 url = new JTextArea();
101 url.setEditable(false);
102 url.setLineWrap(false);
103 builder.append(wrapWithScrollPane(url));
104
105 builder.append("Running");
106 plugin = createTextField("", false);
107 builder.append(plugin);
108
109 builder.append("Problems");
110 errorsAndWarnings = createTextField("", false);
111 builder.append(errorsAndWarnings);
112
113 return builder.getPanel();
114 }
115
116 /**
117 * Assembles the GUI components of the panel.
118 */
119 public final void setupView() {
120 this.setLayout(new GridLayout(1, 1));
121 this.add(buildTestPanel());
122 this.setPreferredSize(new Dimension(200, 200));
123 }
124
125 public void setModel(final QedeqBo prop) {
126 this.prop = prop;
127 updateView();
128 }
129
130 public QedeqBo getModel() {
131 return this.prop;
132 }
133
134
135
136 /**
137 * Update from model.
138 */
139 public void updateView() {
140
141 if (prop != null) {
142 state.setText(prop.getStateDescription());
143 name.setText(prop.getName());
144 ruleVersion.setText(prop.getRuleVersion());
145 url.setText(prop.getUrl().toString());
146 final Plugin p = prop.getCurrentlyRunningPlugin();
147 if (p != null) {
148 plugin.setText(p.getPluginActionName());
149 plugin.setToolTipText(GuiHelper.getToolTipText(p.getPluginDescription()));
150 } else {
151 plugin.setText("");
152 plugin.setToolTipText("");
153 }
154 errorsAndWarnings.setText(prop.getErrors().size() + " errors, " + prop.getWarnings().size() + " warnings");
155 } else {
156 state.setText("");
157 name.setText("");
158 ruleVersion.setText("");
159 url.setText("");
160 plugin.setText("");
161 errorsAndWarnings.setText("");
162 }
163 invalidate();
164 repaint();
165 }
166
167 private JTextField createTextField(final String selectedText, final boolean editable) {
168 JTextField combo = new JTextField(selectedText);
169 combo.setEditable(editable);
170 return combo;
171 }
172
173 private Component wrapWithScrollPane(final Component c) {
174 return new JScrollPane(
175 c,
176 ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
177 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
178 }
179
180
181
182 }
|