001: package org.ofbiz.rules.logikus;
002:
003: // import com.sun.java.swing.*;
004: // import com.sun.java.swing.border.*;
005: import javax.swing.*;
006: import java.awt.*;
007: import org.ofbiz.rules.utensil.*;
008:
009: /**
010: * <p><b>Title:</b> Logikus IDE
011: * <p><b>Description:</b> None
012: * <p>Copyright (c) 1999 Steven J. Metsker.
013: * <p>Copyright (c) 2001 The Open For Business Project - www.ofbiz.org
014: *
015: * <p>Permission is hereby granted, free of charge, to any person obtaining a
016: * copy of this software and associated documentation files (the "Software"),
017: * to deal in the Software without restriction, including without limitation
018: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
019: * and/or sell copies of the Software, and to permit persons to whom the
020: * Software is furnished to do so, subject to the following conditions:
021: *
022: * <p>The above copyright notice and this permission notice shall be included
023: * in all copies or substantial portions of the Software.
024: *
025: * <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
026: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
027: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
028: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
029: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
030: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
031: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
032: *
033: * <br>
034: * <p>This class provides an interactive development environment
035: * for Logikus.
036: * <p>
037: * This class contains just the Swing components, and
038: * delegates responsibility for the interaction of these
039: * components to a LogikusMediator object.
040: *
041: * @author Steven J. Metsker
042: * @version 1.0
043: */
044:
045: public class LogikusIde {
046: protected LogikusMediator mediator;
047:
048: protected JTextArea programArea;
049: protected JTextArea resultsArea;
050: protected JTextArea queryArea;
051:
052: protected JButton proveNextButton;
053: protected JButton proveRestButton;
054: protected JButton haltButton;
055: protected JButton clearProgramButton;
056: protected JButton clearResultsButton;
057:
058: /**
059: * Creates and returns the box that contains all of the IDE's
060: * buttons.
061: */
062: protected Box buttonBox() {
063: Box b = Box.createHorizontalBox();
064:
065: b.add(proveButtonPanel());
066: b.add(Box.createHorizontalGlue());
067: b.add(clearButtonPanel());
068: return b;
069: }
070:
071: /**
072: * Creates and returns the panel that contains the IDE's
073: * clear buttons.
074: */
075: protected JPanel clearButtonPanel() {
076: JPanel p = new JPanel();
077:
078: p.setBorder(SwingUtensil.ideTitledBorder("Clear"));
079: p.add(clearProgramButton());
080: p.add(clearResultsButton());
081: return p;
082: }
083:
084: /**
085: * The button that clears the results area.
086: */
087: protected JButton clearProgramButton() {
088: if (clearProgramButton == null) {
089: clearProgramButton = new JButton("Program");
090: clearProgramButton.addActionListener(mediator());
091: clearProgramButton.setFont(SwingUtensil.ideFont());
092: }
093: return clearProgramButton;
094: }
095:
096: /**
097: * The button that clears the results area.
098: */
099: protected JButton clearResultsButton() {
100: if (clearResultsButton == null) {
101: clearResultsButton = new JButton("Results");
102: clearResultsButton.addActionListener(mediator());
103: clearResultsButton.setFont(SwingUtensil.ideFont());
104: }
105: return clearResultsButton;
106: }
107:
108: /**
109: * The button that halts the proof thread.
110: */
111: protected JButton haltButton() {
112: if (haltButton == null) {
113: haltButton = new JButton("Halt");
114: haltButton.setEnabled(false);
115: haltButton.addActionListener(mediator());
116: haltButton.setFont(SwingUtensil.ideFont());
117: }
118: return haltButton;
119: }
120:
121: /**
122: * Launch a Logikus interactive development environment.
123: */
124: public static void main(String[] args) {
125: SwingUtensil.launch(new LogikusIde().mainPanel(), "Logikus");
126: }
127:
128: /**
129: * Builds and returns the panel that contains all the
130: * components of the IDE.
131: */
132: protected JPanel mainPanel() {
133: JPanel p = SwingUtensil.textPanel("Program", programArea(),
134: new Dimension(600, 300), new Dimension(600, 150));
135:
136: JPanel q = SwingUtensil.textPanel("Query", queryArea(),
137: new Dimension(600, 60), new Dimension(600, 60));
138:
139: JPanel r = SwingUtensil.textPanel("Results", resultsArea(),
140: new Dimension(600, 150), new Dimension(600, 75));
141:
142: JSplitPane inner = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
143: false, q, r);
144: JSplitPane outer = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
145: false, p, inner);
146:
147: inner.setDividerSize(3);
148: outer.setDividerSize(3);
149:
150: JPanel whole = new JPanel();
151:
152: whole.setLayout(new BorderLayout());
153: whole.add(outer, "Center");
154: whole.add(buttonBox(), "South");
155: return whole;
156: }
157:
158: /**
159: * The object that controls or "mediates" the interaction
160: * of this development environment's Swing components.
161: */
162: protected LogikusMediator mediator() {
163: if (mediator == null) {
164: mediator = new LogikusMediator();
165: mediator.initialize(proveNextButton(), proveRestButton(),
166: haltButton(), clearProgramButton(),
167: clearResultsButton(), programArea(), resultsArea(),
168: queryArea());
169: }
170: return mediator;
171: }
172:
173: /**
174: * The program text area.
175: */
176: protected JTextArea programArea() {
177: if (programArea == null) {
178: programArea = SwingUtensil.ideTextArea();
179: }
180: return programArea;
181: }
182:
183: /**
184: * Creates and returns the panel that contains the IDE's
185: * proof buttons.
186: */
187: protected JPanel proveButtonPanel() {
188: JPanel p = new JPanel();
189:
190: p.setBorder(SwingUtensil.ideTitledBorder("Prove"));
191: p.add(proveNextButton());
192: p.add(proveRestButton());
193: p.add(haltButton());
194: return p;
195: }
196:
197: /**
198: * The button that starts the proof thread.
199: */
200: protected JButton proveNextButton() {
201: if (proveNextButton == null) {
202: proveNextButton = new JButton("Next");
203: proveNextButton.addActionListener(mediator());
204: proveNextButton.setFont(SwingUtensil.ideFont());
205: }
206: return proveNextButton;
207: }
208:
209: /**
210: * The button that starts the proof thread, asking it to
211: * find all remaining proofs.
212: */
213: protected JButton proveRestButton() {
214: if (proveRestButton == null) {
215: proveRestButton = new JButton("Rest");
216: proveRestButton.addActionListener(mediator());
217: proveRestButton.setFont(SwingUtensil.ideFont());
218: }
219: return proveRestButton;
220: }
221:
222: /**
223: * The query text area.
224: */
225: protected JTextArea queryArea() {
226: if (queryArea == null) {
227: queryArea = SwingUtensil.ideTextArea();
228: }
229: return queryArea;
230: }
231:
232: /**
233: * The results text area.
234: */
235: protected JTextArea resultsArea() {
236: if (resultsArea == null) {
237: resultsArea = SwingUtensil.ideTextArea();
238: }
239: return resultsArea;
240: }
241: }
|