001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.cleverphl.gui;
025:
026: import jacareto.cleverphl.CleverPHL;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Customization;
029: import jacareto.system.Language;
030:
031: import java.awt.Color;
032: import java.awt.GridBagConstraints;
033: import java.awt.GridBagLayout;
034:
035: import javax.swing.JLabel;
036: import javax.swing.JPanel;
037: import javax.swing.JScrollPane;
038: import javax.swing.JTextArea;
039: import javax.swing.border.LineBorder;
040: import javax.swing.border.TitledBorder;
041:
042: /**
043: * Displays general information about a structure element (name, description, ...)
044: *
045: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
046: * @version 1.01
047: */
048: public class InformationDisplay extends JPanel {
049: /** The CleverPHL instance. */
050: private CleverPHL cleverPHL;
051:
052: /** The label for the structure element's name. */
053: private JLabel nameLabel;
054:
055: /** The text area for the structure element's description. */
056: private JTextArea descriptionArea;
057:
058: /** The label for the duration. */
059: private JLabel durationLabel;
060:
061: /** The label for the duration. */
062: private JLabel procTimeLabel;
063:
064: /**
065: * Creates a new information display which displays the information of the given structure
066: * element.
067: *
068: * @param cleverPHL the CleverPHL instance
069: * @param element the structure element
070: */
071: public InformationDisplay(CleverPHL cleverPHL,
072: StructureElement element) {
073: this .cleverPHL = cleverPHL;
074:
075: Customization customization = cleverPHL.getCustomization();
076: Language language = cleverPHL.getLanguage();
077:
078: nameLabel = new JLabel("");
079: nameLabel.setFont(nameLabel.getFont().deriveFont(
080: customization.getFloat(
081: "CleverPHL.InformationDisplay.NameFontSize",
082: 15f)));
083:
084: descriptionArea = new JTextArea("");
085: descriptionArea.setLineWrap(true);
086: descriptionArea.setWrapStyleWord(true);
087: descriptionArea.setEditable(false);
088: descriptionArea.setBorder(null);
089: descriptionArea.setRows(customization.getInt(
090: "CleverPHL.InformationDisplay.Rows", 3));
091: descriptionArea.setColumns(customization.getInt(
092: "CleverPHL.InformationDisplay.Columns", 30));
093: descriptionArea.setBackground(getBackground());
094:
095: setLayout(new GridBagLayout());
096:
097: GridBagConstraints c = new GridBagConstraints();
098:
099: c.gridx = 0;
100: c.gridy = 0;
101: c.anchor = GridBagConstraints.WEST;
102: add(nameLabel, c);
103:
104: c.gridy = 1;
105:
106: JPanel infoPanel = new JPanel();
107: infoPanel.setLayout(new GridBagLayout());
108:
109: GridBagConstraints d = new GridBagConstraints();
110: d.anchor = GridBagConstraints.WEST;
111: d.gridx = 0;
112: d.gridy = 0;
113: infoPanel.add(new JScrollPane(descriptionArea,
114: JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
115: JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), d);
116: d.gridy = 1;
117: durationLabel = new JLabel();
118: infoPanel.add(durationLabel, d);
119: infoPanel.setBorder(new TitledBorder(new LineBorder(
120: Color.black, 1, true), language
121: .getString("CleverPHL.InformationDisplay.Info")));
122: d.gridy = 2;
123: procTimeLabel = new JLabel();
124: infoPanel.add(procTimeLabel, d);
125: add(infoPanel, c);
126:
127: displayElement(element);
128: }
129:
130: /**
131: * Creates a new information display which displays no structure element at the beginning.
132: *
133: * @param cleverPHL the CleverPHL instance
134: */
135: public InformationDisplay(CleverPHL cleverPHL) {
136: this (cleverPHL, null);
137: }
138:
139: /**
140: * Sets the width of the description area.
141: *
142: * @param width the new width
143: */
144: public void setDescriptionAreaWidth(int width) {
145: descriptionArea.setSize(width, descriptionArea.getHeight());
146: }
147:
148: /**
149: * Displays the structure element's information
150: *
151: * @param element the structure element
152: */
153: public void displayElement(StructureElement element) {
154: clear();
155:
156: if (element != null) {
157: Language language = cleverPHL.getLanguage();
158: nameLabel.setText(element.getElementName());
159: descriptionArea.setText(element.getElementDescription());
160: descriptionArea.setCaretPosition(0);
161:
162: long tmpDuration = element.getDuration();
163: long min = tmpDuration / 60000;
164: tmpDuration = tmpDuration % 60000;
165:
166: long sec = tmpDuration / 1000;
167: long msec = tmpDuration % 1000;
168:
169: durationLabel.setText(language
170: .getString("General.Duration")
171: + ": "
172: + min
173: + " "
174: + language.getString("General.Abbreviations.Min")
175: + " "
176: + sec
177: + " "
178: + language.getString("General.Abbreviations.Sec")
179: + " "
180: + msec
181: + " "
182: + language.getString("General.Abbreviations.Msec"));
183:
184: long tmpProcTime = element.getProcTime();
185: min = tmpProcTime / 60000;
186: tmpProcTime = tmpProcTime % 60000;
187:
188: sec = tmpProcTime / 1000;
189: msec = tmpProcTime % 1000;
190:
191: procTimeLabel.setText(language
192: .getString("General.ProcTime")
193: + ": "
194: + min
195: + " "
196: + language.getString("General.Abbreviations.Min")
197: + " "
198: + sec
199: + " "
200: + language.getString("General.Abbreviations.Sec")
201: + " "
202: + msec
203: + " "
204: + language.getString("General.Abbreviations.Msec"));
205: }
206: }
207:
208: /**
209: * Clears the information panel.
210: */
211: public void clear() {
212: nameLabel.setText("");
213: descriptionArea.setText("");
214: }
215: }
|