1 /******************************************************************
2 * Copyright (c) 2003, Mario Hochreiter, Student of
3 * Software Engineering at FH-Hagenberg, Austria.
4 * Project member of the isac team at the Institute for
5 * Software-Technologie, Graz University of Technology, Austria.
7 * Use is subject to license terms.
8 ******************************************************************/
10 package isac.gui.calcheadviews;
12 import isac.util.formulae.CalcHead;
14 import java.awt.BorderLayout;
15 import java.util.Locale;
16 import java.util.ResourceBundle;
18 import javax.swing.BorderFactory;
19 import javax.swing.JPanel;
21 import org.apache.log4j.Logger;
24 * @author Mario Hochreiter
25 * @author Manuel Koschuch
29 public class CalcHeadView extends JPanel implements ICalcHeadView {
32 * Constant used for serialization (@see corresponding API Documentation)
34 private static final long serialVersionUID = 1L;
36 private static final Logger logger = Logger.getLogger(CalcHeadView.class
39 private static final int HEADLINE_PANEL_INDEX = 0;
41 private static final int MODEL_PANEL_INDEX = 1;
43 private static final int SPECIFICATION_PANEL_INDEX = 2;
45 private ResourceBundle res_bundle_;
47 private ModelPanel model_panel_;
49 private SpecificationPanel specification_panel_;
51 private HeadLinePanel head_line_panel_;
53 private int current_panel_index_;
56 * Creates a new CalcHeadView, consisting of 3 Panels: a HeadLinePanel,
57 * presenting the CalcHead's Headline, a ModelPanel, presenting the
58 * CalcHead's Model, a SpecificationPanel, presenting the CalcHead's
61 * depending on the selected Viewstyle in the supplied CalcHead all or some
62 * of these panels are drawn
66 public CalcHeadView(CalcHead ch) {
67 res_bundle_ = ResourceBundle.getBundle("CalcHeadPanel");
68 model_panel_ = new ModelPanel(ch.getModel(), res_bundle_);
69 specification_panel_ = new SpecificationPanel(ch.getSpecification(),
71 head_line_panel_ = new HeadLinePanel(ch.getHeadLine());
72 current_panel_index_ = 0;
74 this.fillTextFieldsFromCalcHead(ch);
77 private void init(CalcHead ch) {
78 this.layoutComponents(ch);
81 private void layoutComponents(CalcHead ch) {
82 this.setLayout(new BorderLayout());
83 this.add(head_line_panel_, BorderLayout.NORTH);
84 if (ch.getBelongsTo().equals("Met")) {
87 buildProblemLayout(ch);
94 * CalcHead to wich the data read from the text fields is written
96 public void fillCalcHeadFromTextFields(CalcHead ch) {
97 model_panel_.fillModelFromTextFields(ch.getModel());
98 specification_panel_.fillSpecificationFromTextFields(ch
100 ch.setBelongsTo(specification_panel_.getBelongsTo());
105 * CalcHead from wich the data is read to fill out the text
108 public void fillTextFieldsFromCalcHead(CalcHead ch) {
109 if (logger.isDebugEnabled())
110 logger.debug(ch.getModel().getGiven() + " "
111 + ch.getModel().getFind());
114 head_line_panel_.fillHeadLinePanelFromFormula(ch.getHeadLine());
115 model_panel_.fillTextFieldsFromModel(ch.getModel(), true);
116 specification_panel_.fillTextFieldsFromSpecification(ch
117 .getSpecification(), ch.getBelongsTo());
120 private void buildMethodLayout() {
121 // FIXME find better representation?
122 specification_panel_.highlightLabel(SpecificationPanel.LABEL_METHOD);
123 buildFullLayout("Guard");
126 private void buildProblemLayout(CalcHead ch) {
127 specification_panel_.highlightLabel(SpecificationPanel.LABEL_PROBLEM);
128 switch (ch.getViewstyle()) {
129 case CalcHead.VIEWSTYLE_FULL:
130 buildFullLayout("Model");
132 case CalcHead.VIEWSTYLE_MODEL:
135 case CalcHead.VIEWSTYLE_SPECIFICATION:
136 buildSpecificationLayout();
139 buildFullLayout("Model");
144 * Builds ModelPanel and SpecificationPanel, the ModelPanel is titled with
145 * the supplied string (either Model or Guard)
148 * title for the ModelPanel
151 private void buildFullLayout(String title) {
152 this.add(model_panel_, BorderLayout.CENTER);
153 model_panel_.setBorder(BorderFactory.createTitledBorder(title));
155 this.add(specification_panel_, BorderLayout.SOUTH);
156 specification_panel_.setBorder(BorderFactory
157 .createTitledBorder("Specification"));
162 * Build only ModelPanel
166 private void buildModelLayout() {
167 this.add(model_panel_, BorderLayout.CENTER);
168 model_panel_.setBorder(BorderFactory.createTitledBorder("Model"));
173 * Build only SpecificationPanel
177 private void buildSpecificationLayout() {
178 this.add(specification_panel_, BorderLayout.CENTER);
179 specification_panel_.setBorder(BorderFactory
180 .createTitledBorder("Specification"));
184 public ModelPanel getModelPanel() {
188 public SpecificationPanel getSpecificationPanel() {
189 return specification_panel_;
196 public void reset() {
197 current_panel_index_ = 0;
198 head_line_panel_.reset();
199 model_panel_.reset();
200 specification_panel_.reset();
205 * Fills Textfields stepwise
208 * CalcHead to fill TextFields from
209 * @return false, when Textfields left to fill, true otherwise
210 * @deprecated was misunderstanding
213 public boolean next(CalcHead ch) {
214 switch (current_panel_index_) {
215 case HEADLINE_PANEL_INDEX:
216 if (head_line_panel_.next(ch.getHeadLine())) {
217 current_panel_index_++;
220 current_panel_index_++;
223 case MODEL_PANEL_INDEX:
224 if (model_panel_.next(ch.getModel())) {
225 current_panel_index_++;
230 case SPECIFICATION_PANEL_INDEX:
231 if (specification_panel_.next(ch.getSpecification())) {
232 current_panel_index_++;