001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2014, 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.BorderLayout;
019 import java.awt.Dimension;
020 import java.awt.event.ActionEvent;
021 import java.awt.event.ActionListener;
022 import java.io.IOException;
023 import java.util.ArrayList;
024 import java.util.Iterator;
025 import java.util.List;
026
027 import javax.swing.BorderFactory;
028 import javax.swing.ButtonGroup;
029 import javax.swing.JButton;
030 import javax.swing.JCheckBox;
031 import javax.swing.JComponent;
032 import javax.swing.JDialog;
033 import javax.swing.JFrame;
034 import javax.swing.JOptionPane;
035 import javax.swing.JPanel;
036 import javax.swing.JRadioButton;
037 import javax.swing.JTabbedPane;
038 import javax.swing.JTextArea;
039 import javax.swing.JTextField;
040 import javax.swing.border.CompoundBorder;
041 import javax.swing.border.EmptyBorder;
042
043 import org.qedeq.base.io.Parameters;
044 import org.qedeq.base.trace.Trace;
045 import org.qedeq.gui.se.util.GuiHelper;
046 import org.qedeq.kernel.bo.logic.model.FourDynamicModel;
047 import org.qedeq.kernel.bo.logic.model.SixDynamicModel;
048 import org.qedeq.kernel.bo.logic.model.ThreeDynamicModel;
049 import org.qedeq.kernel.bo.logic.model.UnaryDynamicModel;
050 import org.qedeq.kernel.bo.service.basis.ModuleServicePlugin;
051 import org.qedeq.kernel.bo.service.heuristic.DynamicHeuristicCheckerPlugin;
052 import org.qedeq.kernel.bo.service.latex.Qedeq2LatexPlugin;
053 import org.qedeq.kernel.bo.service.logic.SimpleProofFinderPlugin;
054 import org.qedeq.kernel.bo.service.unicode.Qedeq2UnicodeTextPlugin;
055 import org.qedeq.kernel.bo.service.unicode.Qedeq2Utf8Plugin;
056 import org.qedeq.kernel.se.common.ModuleService;
057
058 import com.jgoodies.forms.builder.ButtonBarBuilder;
059 import com.jgoodies.forms.builder.DefaultFormBuilder;
060 import com.jgoodies.forms.layout.FormLayout;
061
062 /**
063 * Configures the plugin parameters.
064 *
065 * @author Michael Meyling
066 */
067
068 public class PluginPreferencesDialog extends JDialog {
069
070 /** This class. */
071 private static final Class CLASS = PluginPreferencesDialog.class;
072
073 /** Text field for default language of QEDEQ to UTF-8 show plugin. */
074 private JTextField qedeq2Utf8ShowLanguageTF;
075
076 /** Checkbox for info parameter of QEDEQ to UTF-8 show plugin. */
077 private JCheckBox qedeq2Utf8ShowInfoCB;
078
079 /** Text field for maximum column of QEDEQ to UTF-8 show plugin. */
080 private JTextField qedeq2Utf8ShowMaximumColumnTF;
081
082 /** Checkbox for info parameter of QEDEQ to LaTeX plugin. */
083 private JCheckBox qedeq2LatexInfoCB;
084
085 /** Checkbox for brief parameter of QEDEQ to LaTeX plugin. */
086 private JCheckBox qedeq2LatexBriefCB;
087
088 /** Checkbox for info parameter of QEDEQ to UTF-8 plugin. */
089 private JCheckBox qedeq2Utf8InfoCB;
090
091 /** Text field for maximum column of QEDEQ to UTF-8 plugin. */
092 private JTextField qedeq2Utf8MaximumColumnTF;
093
094 /** Checkbox for brief parameter of QEDEQ to UTF-8 plugin. */
095 private JCheckBox qedeq2Utf8BriefCB;
096
097 /** Plugin for converting QEDEQ modules into LaTeX. */
098 private final Qedeq2LatexPlugin qedeq2latex;
099
100 /** Plugin for converting QEDEQ modules into UTF-8 text. */
101 private final Qedeq2Utf8Plugin qedeq2utf8;
102
103 /** Plugin for showing QEDEQ modules as UTF-8 text. */
104 private final Qedeq2UnicodeTextPlugin qedeq2utf8Show;
105
106 /** Plugin for finding simple propositional calculus proofs. */
107 private final SimpleProofFinderPlugin proofFinder;
108
109 /** Plugin for checking formulas with the help of a dynamically calculated static model. */
110 private DynamicHeuristicCheckerPlugin dynamicHeuristicChecker;
111
112 /** Class string for dynamic static model. */
113 private String dynamicHeuristicCheckerModel = "";
114
115 /** Text field for maximum proof length of proof finder plugin. */
116 private JTextField proofFinderMaximumProofLengthTF;
117
118 /** Text field for number of additional propositional variables for substitution. */
119 private JTextField proofFinderExtraVarsTF;
120
121 /** Text field for number for order of substitution. */
122 private JTextField proofFinderPropositionVariableOrderTF;
123
124 /** Text field for number for weight of substitution. */
125 private JTextField proofFinderPropositionVariableWeightTF;
126
127 /** Text field for number for order of substitution. */
128 private JTextField proofFinderPartFormulaOrderTF;
129
130 /** Text field for number for weight of substitution. */
131 private JTextField proofFinderPartFormulaWeightTF;
132
133 /** Text field for number for order of substitution. */
134 private JTextField proofFinderDisjunctionOrderTF;
135
136 /** Text field for number for weight of substitution. */
137 private JTextField proofFinderDisjunctionWeightTF;
138
139 /** Text field for number for order of substitution. */
140 private JTextField proofFinderImplicationOrderTF;
141
142 /** Text field for number for weight of substitution. */
143 private JTextField proofFinderImplicationWeightTF;
144
145 /** Text field for number for order of substitution. */
146 private JTextField proofFinderNegationOrderTF;
147
148 /** Text field for number for weight of substitution. */
149 private JTextField proofFinderNegationWeightTF;
150
151 /** Text field for number for order of substitution. */
152 private JTextField proofFinderConjunctionOrderTF;
153
154 /** Text field for number for weight of substitution. */
155 private JTextField proofFinderConjunctionWeightTF;
156
157 /** Text field for number for order of substitution. */
158 private JTextField proofFinderEquivalenceOrderTF;
159
160 /** Text field for number for weight of substitution. */
161 private JTextField proofFinderEquivalenceWeightTF;
162
163 /** Text field for number of new proof lines before a new log entry. */
164 private JTextField proofFinderLogFrequenceTF;
165
166 /** Text field for sequence of formula numbers we want to skip. */
167 private JTextField proofFinderSkipFormulasTF;
168
169 /** Here are the tabs. */
170 private JTabbedPane tabbedPane;
171
172 /** Here are the creators of class {@link PluginGuiPreferencesCreator}. */
173 private List creators;
174
175 /**
176 * Creates new Panel.
177 *
178 * @param parent Parent frame.
179 */
180 public PluginPreferencesDialog(final JFrame parent) {
181 super(parent, "Plugin Preferences");
182 final String method = "Constructor";
183 Trace.begin(CLASS, this, method);
184 try {
185 qedeq2latex = new Qedeq2LatexPlugin();
186 qedeq2utf8 = new Qedeq2Utf8Plugin();
187 qedeq2utf8Show = new Qedeq2UnicodeTextPlugin();
188 dynamicHeuristicChecker = new DynamicHeuristicCheckerPlugin();
189 proofFinder = new SimpleProofFinderPlugin();
190 creators = new ArrayList();
191 setModal(true);
192 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
193 setupView();
194 updateView();
195 } catch (RuntimeException e) {
196 Trace.fatal(CLASS, this, "Initalization of PreferencesDialog failed.", method, e);
197 throw e;
198 } finally {
199 Trace.end(CLASS, this, method);
200 }
201 }
202
203 /**
204 * Assembles the GUI components of the panel.
205 */
206 public final void setupView() {
207 final JPanel content = new JPanel(new BorderLayout());
208 getContentPane().add(content);
209
210 tabbedPane = new JTabbedPane();
211 tabbedPane.setOpaque(false);
212 creators.add(qedeq2Utf8ShowConfig(qedeq2utf8Show));
213 creators.add(qedeq2LatexConfig(qedeq2latex));
214 creators.add(qedeq2Utf8Config(qedeq2utf8));
215 // creators.add(heuristicCheckerConfig(heuristicChecker));
216 creators.add(dynamicHeuristicCheckerConfig(dynamicHeuristicChecker));
217 creators.add(proofFinderConfig(proofFinder));
218 final Iterator iter = creators.iterator();
219 while (iter.hasNext()) {
220 PluginGuiPreferencesCreator creator = (PluginGuiPreferencesCreator) iter.next();
221 tabbedPane.addTab(creator.getName(), creator.create(QedeqGuiConfig.getInstance()
222 .getServiceEntries(creator.getPlugin())));
223 }
224
225 // tabbedPane.setBorder(GuiHelper.getEmptyBorder());
226 tabbedPane.setBorder(new CompoundBorder(new EmptyBorder(0, 10, 10, 10),
227 tabbedPane.getBorder()));
228 content.add(tabbedPane, BorderLayout.CENTER);
229
230 content.add(GuiHelper.addSpaceAndAlignRight(buildButtonPanel()), BorderLayout.SOUTH);
231
232 // let the container calculate the ideal size
233 this.pack();
234
235 final Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
236 int width = getWidth();
237 if (2 * width < screenSize.width) {
238 width = 2 * width;
239 }
240 setBounds((screenSize.width - getWidth()) / 2, (screenSize.height - getHeight()) / 2,
241 width, getHeight());
242 }
243
244 /**
245 * Assembles settings for {@link Qedeq2LatexPlugin}.
246 *
247 * @param plugin The transformation plugin.
248 * @return Created panel.
249 */
250 private PluginGuiPreferencesCreator qedeq2LatexConfig(final ModuleServicePlugin plugin) {
251 return new PluginGuiPreferencesCreator(plugin) {
252 JComponent create(final Parameters parameters) {
253 FormLayout layout = new FormLayout(
254 "left:pref, 5dlu, fill:pref:grow"); // columns
255
256 DefaultFormBuilder builder = new DefaultFormBuilder(layout);
257 builder.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
258 builder.getPanel().setOpaque(false);
259
260 qedeq2LatexInfoCB = new JCheckBox(" Also write reference labels (makes it easier for authors)",
261 parameters.getBoolean("info"));
262 builder.append(qedeq2LatexInfoCB);
263
264 builder.nextLine();
265 qedeq2LatexBriefCB = new JCheckBox(" Leave out main text entries. Creates a very brief document.",
266 parameters.getBoolean("brief"));
267 builder.append(qedeq2LatexBriefCB);
268
269 return GuiHelper.addSpaceAndTitle(builder.getPanel(), plugin.getServiceDescription());
270 }
271 };
272 }
273
274 /**
275 * Assembles settings for {@link Qedeq2Utf8Plugin}.
276 *
277 * @param plugin The transformation plugin.
278 * @return Created panel.
279 */
280 private PluginGuiPreferencesCreator qedeq2Utf8Config(final ModuleServicePlugin plugin) {
281 return new PluginGuiPreferencesCreator(plugin) {
282 JComponent create(final Parameters parameters) {
283 FormLayout layout = new FormLayout(
284 "left:pref, 5dlu, fill:50dlu, fill:pref:grow"); // columns
285
286 DefaultFormBuilder builder = new DefaultFormBuilder(layout);
287 builder.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
288 builder.getPanel().setOpaque(false);
289
290 qedeq2Utf8InfoCB = new JCheckBox(" Also write reference labels (makes it easier for authors)",
291 parameters.getBoolean("info"));
292 builder.append(qedeq2Utf8InfoCB, 4);
293
294 builder.nextLine();
295 builder.append("Maximum row length");
296 qedeq2Utf8MaximumColumnTF = new JTextField(parameters.getString(
297 "maximumColumn"));
298 qedeq2Utf8MaximumColumnTF.setToolTipText("After this character number the line is broken."
299 + "0 means no break at all.");
300 builder.append(qedeq2Utf8MaximumColumnTF);
301
302 builder.nextLine();
303 qedeq2Utf8BriefCB = new JCheckBox(" Leave out main text entries. Creates a very brief document.",
304 parameters.getBoolean("brief"));
305 builder.append(qedeq2Utf8BriefCB);
306
307 return GuiHelper.addSpaceAndTitle(builder.getPanel(), plugin.getServiceDescription());
308 }
309 };
310 }
311
312 /**
313 * Assembles settings for {@link Qedeq2Utf8TextPlugin}.
314 *
315 * @param plugin The transformation plugin.
316 * @return Created panel.
317 */
318 private PluginGuiPreferencesCreator qedeq2Utf8ShowConfig(final ModuleServicePlugin plugin) {
319 return new PluginGuiPreferencesCreator(plugin) {
320 JComponent create(final Parameters parameters) {
321 FormLayout layout = new FormLayout(
322 "left:pref, 5dlu, fill:50dlu, fill:pref:grow"); // columns
323
324 DefaultFormBuilder builder = new DefaultFormBuilder(layout);
325 builder.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
326 builder.getPanel().setOpaque(false);
327
328 builder.append("Default language");
329 qedeq2Utf8ShowLanguageTF = new JTextField(parameters.getString(
330 "language"));
331 qedeq2Utf8ShowLanguageTF.setToolTipText("Default language for showing module contents.");
332 builder.append(qedeq2Utf8ShowLanguageTF);
333
334 builder.nextLine();
335 qedeq2Utf8ShowInfoCB = new JCheckBox(" Also write reference labels (makes it easier for authors)",
336 parameters.getBoolean("info"));
337 builder.append(qedeq2Utf8ShowInfoCB, 4);
338
339 builder.nextLine();
340 builder.append("Maximum row length");
341 qedeq2Utf8ShowMaximumColumnTF = new JTextField(parameters.getString(
342 "maximumColumn"));
343 qedeq2Utf8ShowMaximumColumnTF.setToolTipText("After this character number the line is broken."
344 + "0 means no break at all.");
345 builder.append(qedeq2Utf8ShowMaximumColumnTF);
346
347 return GuiHelper.addSpaceAndTitle(builder.getPanel(), plugin.getServiceDescription());
348 }
349 };
350 }
351
352
353 /**
354 * Assembles settings for {@link DynamicHeuristicCheckerPlugin}.
355 *
356 * @param plugin The transformation plugin.
357 * @return Created panel.
358 */
359 private PluginGuiPreferencesCreator dynamicHeuristicCheckerConfig(final ModuleServicePlugin plugin) {
360 return new PluginGuiPreferencesCreator(plugin) {
361 JComponent create(final Parameters parameters) {
362 FormLayout layout = new FormLayout(
363 "left:pref, 5dlu, fill:pref:grow", // columns
364 "top:pref:grow, top:pref:grow, top:pref:grow"); // rows
365
366 DefaultFormBuilder builder = new DefaultFormBuilder(layout);
367 builder.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
368 builder.getPanel().setOpaque(false);
369
370 final ThreeDynamicModel modelThree = new ThreeDynamicModel();
371 final FourDynamicModel modelFour = new FourDynamicModel();
372 final SixDynamicModel modelSix = new SixDynamicModel();
373
374 final ButtonGroup dynamicHeuristicCheckerModelBG = new ButtonGroup();
375
376 final UnaryDynamicModel modelOne = new UnaryDynamicModel();
377 dynamicHeuristicCheckerModel = parameters.getString(
378 "model");
379 final ActionListener modelSelectionListener = new ActionListener() {
380 public void actionPerformed(final ActionEvent e) {
381 dynamicHeuristicCheckerModel = e.getActionCommand();
382 }
383 };
384
385 // model with one element
386 {
387 final JRadioButton dynamicHeuristicCheckerOneModelRB = new JRadioButton("One");
388 if (dynamicHeuristicCheckerModel.equals(modelOne.getClass().getName())) {
389 dynamicHeuristicCheckerOneModelRB.setSelected(true);
390 }
391 dynamicHeuristicCheckerOneModelRB.setActionCommand(modelOne.getClass().getName());
392 dynamicHeuristicCheckerOneModelRB.addActionListener(modelSelectionListener);
393 dynamicHeuristicCheckerModelBG.add(dynamicHeuristicCheckerOneModelRB);
394 builder.append(dynamicHeuristicCheckerOneModelRB);
395 builder.append(getDescription(modelOne.getDescription()));
396 }
397
398 // model with three elements
399 {
400 final JRadioButton dynamicHeuristicCheckerThreeModelRB = new JRadioButton("Three");
401 if (dynamicHeuristicCheckerModel.equals(modelThree.getClass().getName())) {
402 dynamicHeuristicCheckerThreeModelRB.setSelected(true);
403 }
404 dynamicHeuristicCheckerThreeModelRB.setActionCommand(modelThree.getClass().getName());
405 dynamicHeuristicCheckerThreeModelRB.addActionListener(modelSelectionListener);
406 dynamicHeuristicCheckerModelBG.add(dynamicHeuristicCheckerThreeModelRB);
407 builder.append(dynamicHeuristicCheckerThreeModelRB);
408 builder.append(getDescription(modelThree.getDescription()));
409 }
410
411 // model with four elements
412 {
413 final JRadioButton dynamicHeuristicCheckerFourModelRB = new JRadioButton("Four");
414 if (dynamicHeuristicCheckerModel.equals(modelFour.getClass().getName())) {
415 dynamicHeuristicCheckerFourModelRB.setSelected(true);
416 }
417 dynamicHeuristicCheckerFourModelRB.setActionCommand(modelFour.getClass().getName());
418 dynamicHeuristicCheckerFourModelRB.addActionListener(modelSelectionListener);
419 dynamicHeuristicCheckerModelBG.add(dynamicHeuristicCheckerFourModelRB);
420 builder.append(dynamicHeuristicCheckerFourModelRB);
421 builder.append(getDescription(modelFour.getDescription()));
422 }
423
424 // model with five elements
425 {
426 final JRadioButton dynamicHeuristicCheckerSixModelRB = new JRadioButton("Six");
427 if (dynamicHeuristicCheckerModel.equals(modelSix.getClass().getName())) {
428 dynamicHeuristicCheckerSixModelRB.setSelected(true);
429 }
430 dynamicHeuristicCheckerSixModelRB.setActionCommand(modelSix.getClass().getName());
431 dynamicHeuristicCheckerSixModelRB.addActionListener(modelSelectionListener);
432 dynamicHeuristicCheckerModelBG.add(dynamicHeuristicCheckerSixModelRB);
433 builder.append(dynamicHeuristicCheckerSixModelRB);
434 builder.append(getDescription(modelSix.getDescription()));
435 }
436
437 return GuiHelper.addSpaceAndTitle(builder.getPanel(), plugin.getServiceDescription());
438 }
439 };
440 }
441
442 /**
443 * Assembles settings for {@link ProofFinderPlugin}.
444 *
445 * @param plugin The transformation plugin.
446 * @return Created panel.
447 */
448 private PluginGuiPreferencesCreator proofFinderConfig(final ModuleServicePlugin plugin) {
449 return new PluginGuiPreferencesCreator(plugin) {
450 JComponent create(final Parameters parameters) {
451 FormLayout layout = new FormLayout(
452 "left:pref, 5dlu, fill:50dlu, 5dlu, fill:50dlu, fill:pref:grow"); // columns
453
454 DefaultFormBuilder builder = new DefaultFormBuilder(layout);
455 builder.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
456 builder.getPanel().setOpaque(false);
457
458 builder.append("Maximum proof lines");
459 proofFinderMaximumProofLengthTF = new JTextField(parameters.getString(
460 "maximumProofLines"));
461 proofFinderMaximumProofLengthTF.setToolTipText("After this proof line number we abandom."
462 + " the search. This is not the maximum proof line length of the final proof but the"
463 + " but the maximum number of all generated proof lines.");
464 builder.append(proofFinderMaximumProofLengthTF);
465 builder.nextLine();
466
467 builder.append("Log frequence");
468 proofFinderLogFrequenceTF = new JTextField(parameters.getString(
469 "logFrequence"));
470 proofFinderLogFrequenceTF.setToolTipText("After this number of new proof lines we"
471 + " create a logging output.");
472 builder.append(proofFinderLogFrequenceTF);
473 builder.nextLine();
474
475 builder.append("Skip formulas");
476 proofFinderSkipFormulasTF = new JTextField(parameters.getString(
477 "skipFormulas"));
478 proofFinderSkipFormulasTF.setToolTipText("Skip these list of formula numbers (see log output)."
479 + " This a comma separated list of numbers.");
480 builder.append(proofFinderSkipFormulasTF);
481 builder.nextLine();
482
483 proofFinderExtraVarsTF = new JTextField(parameters.getString(
484 "extraVars"));
485 builder.append("Extra proposition variables");
486 builder.append(proofFinderExtraVarsTF);
487 proofFinderExtraVarsTF.setToolTipText("We use these number of extra proposition variables"
488 + " beside the ones we have in our initial formulas and the goal formula.");
489 builder.nextLine();
490
491 builder.appendSeparator();
492 builder.append("Operator");
493 builder.append("Order");
494 builder.append("Weight");
495 builder.nextLine();
496
497 builder.append("Proposition variable");
498 proofFinderPropositionVariableOrderTF = new JTextField(parameters.getString(
499 "propositionVariableOrder"));
500 builder.append(proofFinderPropositionVariableOrderTF);
501 proofFinderPropositionVariableWeightTF = new JTextField(parameters.getString(
502 "propositionVariableWeight"));
503 builder.append(proofFinderPropositionVariableWeightTF);
504 builder.nextLine();
505
506 builder.append("Part formula");
507 proofFinderPartFormulaOrderTF = new JTextField(parameters.getString(
508 "partFormulaOrder"));
509 builder.append(proofFinderPartFormulaOrderTF);
510 proofFinderPartFormulaWeightTF = new JTextField(parameters.getString(
511 "partFormulaWeight"));
512 builder.append(proofFinderPartFormulaWeightTF);
513 builder.nextLine();
514
515 builder.append("Disjunction");
516 proofFinderDisjunctionOrderTF = new JTextField(parameters.getString(
517 "disjunctionOrder"));
518 builder.append(proofFinderDisjunctionOrderTF);
519 proofFinderDisjunctionWeightTF = new JTextField(parameters.getString(
520 "disjunctionWeight"));
521 builder.append(proofFinderDisjunctionWeightTF);
522 builder.nextLine();
523
524 builder.append("Implication");
525 proofFinderImplicationOrderTF = new JTextField(parameters.getString(
526 "implicationOrder"));
527 builder.append(proofFinderImplicationOrderTF);
528 proofFinderImplicationWeightTF = new JTextField(parameters.getString(
529 "implicationWeight"));
530 builder.append(proofFinderImplicationWeightTF);
531 builder.nextLine();
532
533 builder.append("Negation");
534 proofFinderNegationOrderTF = new JTextField(parameters.getString(
535 "negationOrder"));
536 builder.append(proofFinderNegationOrderTF);
537 proofFinderNegationWeightTF = new JTextField(parameters.getString(
538 "negationWeight"));
539 builder.append(proofFinderNegationWeightTF);
540 builder.nextLine();
541
542 builder.append("Conjunction");
543 proofFinderConjunctionOrderTF = new JTextField(parameters.getString(
544 "conjunctionOrder"));
545 builder.append(proofFinderConjunctionOrderTF);
546 proofFinderConjunctionWeightTF = new JTextField(parameters.getString(
547 "conjunctionWeight"));
548 builder.append(proofFinderConjunctionWeightTF);
549 builder.nextLine();
550
551 builder.append("Equivalence");
552 proofFinderEquivalenceOrderTF = new JTextField(parameters.getString(
553 "equivalenceOrder"));
554 builder.append(proofFinderEquivalenceOrderTF);
555 proofFinderEquivalenceWeightTF = new JTextField(parameters.getString(
556 "equivalenceWeight"));
557 builder.append(proofFinderEquivalenceWeightTF);
558 builder.nextLine();
559
560 return GuiHelper.addSpaceAndTitle(builder.getPanel(), plugin.getServiceDescription());
561 }
562 };
563 }
564
565 private JTextArea getDescription(final String text) {
566 JTextArea description = new JTextArea(text);
567 description.setEditable(false);
568 description.setLineWrap(true);
569 description.setWrapStyleWord(true);
570 return description;
571 }
572
573 /**
574 * Create button panel with "OK" and "Cancel".
575 *
576 * @return Button panel.
577 */
578 private JPanel buildButtonPanel() {
579 ButtonBarBuilder bbuilder = ButtonBarBuilder.createLeftToRightBuilder();
580
581 JButton def = new JButton("Default");
582 def.addActionListener(new ActionListener() {
583 public void actionPerformed(final ActionEvent actionEvent) {
584 final int i = tabbedPane.getSelectedIndex();
585 PluginGuiPreferencesCreator creator = (PluginGuiPreferencesCreator) creators.get(i);
586 tabbedPane.setComponentAt(i, creator.createDefault());
587 }
588 });
589 def.setToolTipText("Reset to default values for plugin currently displayed.");
590
591 JButton ok = new JButton("OK");
592 ok.addActionListener(new ActionListener() {
593 public void actionPerformed(final ActionEvent actionEvent) {
594 PluginPreferencesDialog.this.save();
595 PluginPreferencesDialog.this.dispose();
596 }
597 });
598
599 JButton cancel = new JButton("Cancel");
600 cancel.addActionListener(new ActionListener() {
601 public void actionPerformed(final ActionEvent actionEvent) {
602 PluginPreferencesDialog.this.dispose();
603 }
604 });
605 bbuilder.addGriddedButtons(new JButton[]{def});
606 bbuilder.addUnrelatedGap();
607 bbuilder.addUnrelatedGap();
608 bbuilder.addGriddedButtons(new JButton[]{cancel, ok});
609
610 final JPanel buttons = bbuilder.getPanel();
611 return buttons;
612 }
613
614 /**
615 * Update from model.
616 */
617 public void updateView() {
618 invalidate();
619 repaint();
620 }
621
622 void save() {
623 try {
624 {
625 final ModuleService plugin = qedeq2utf8Show;
626 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "language",
627 qedeq2Utf8ShowLanguageTF.getText());
628 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "info", qedeq2Utf8ShowInfoCB.isSelected());
629 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "maximumColumn",
630 qedeq2Utf8ShowMaximumColumnTF.getText());
631 }
632 {
633 final ModuleService plugin = qedeq2latex;
634 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "info", qedeq2LatexInfoCB.isSelected());
635 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "brief", qedeq2LatexBriefCB.isSelected());
636 }
637 {
638 final ModuleService plugin = qedeq2utf8;
639 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "info", qedeq2Utf8InfoCB.isSelected());
640 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "maximumColumn",
641 qedeq2Utf8MaximumColumnTF.getText());
642 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "brief", qedeq2Utf8BriefCB.isSelected());
643 }
644 {
645 final ModuleService plugin = dynamicHeuristicChecker;
646 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "model", dynamicHeuristicCheckerModel);
647 }
648 {
649 final ModuleService plugin = proofFinder;
650 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "maximumProofLines",
651 proofFinderMaximumProofLengthTF.getText());
652 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "logFrequence",
653 proofFinderLogFrequenceTF.getText());
654 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "skipFormulas",
655 proofFinderSkipFormulasTF.getText());
656 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "extraVars",
657 proofFinderExtraVarsTF.getText());
658 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "propositionVariableOrder",
659 proofFinderPropositionVariableOrderTF.getText());
660 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "propositionVariableWeight",
661 proofFinderPropositionVariableWeightTF.getText());
662 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "partFormulaOrder",
663 proofFinderPartFormulaOrderTF.getText());
664 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "partFormulaWeight",
665 proofFinderPartFormulaWeightTF.getText());
666 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "disjunctionOrder",
667 proofFinderDisjunctionOrderTF.getText());
668 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "disjunctionWeight",
669 proofFinderDisjunctionWeightTF.getText());
670 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "implicationOrder",
671 proofFinderImplicationOrderTF.getText());
672 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "implicationWeight",
673 proofFinderImplicationWeightTF.getText());
674 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "negationOrder",
675 proofFinderNegationOrderTF.getText());
676 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "negationWeight",
677 proofFinderNegationWeightTF.getText());
678 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "conjunctionOrder",
679 proofFinderConjunctionOrderTF.getText());
680 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "conjunctionWeight",
681 proofFinderConjunctionWeightTF.getText());
682 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "equivalenceOrder",
683 proofFinderEquivalenceOrderTF.getText());
684 QedeqGuiConfig.getInstance().setServiceKeyValue(plugin, "equivalenceWeight",
685 proofFinderEquivalenceWeightTF.getText());
686 }
687 } catch (RuntimeException e) {
688 Trace.fatal(CLASS, this, "save", "couldn't save preferences", e);
689 JOptionPane.showMessageDialog(this, e.toString(), "Error",
690 JOptionPane.ERROR_MESSAGE);
691 }
692 try {
693 QedeqGuiConfig.getInstance().store();
694 } catch (IOException e) {
695 Trace.fatal(CLASS, this, "save", "couldn't save preferences", e);
696 JOptionPane.showMessageDialog(this, "Couldn't save preferences", "Error", JOptionPane.ERROR_MESSAGE);
697 }
698 }
699
700 /**
701 * This class is a basic creator for tabbed content.
702 */
703 private abstract class PluginGuiPreferencesCreator {
704
705 /** We work for this plugin. */
706 private final ModuleServicePlugin plugin;
707
708 /**
709 * Constructor.
710 *
711 * @param plugin Plugin we work for.
712 */
713 PluginGuiPreferencesCreator(final ModuleServicePlugin plugin) {
714 this.plugin = plugin;
715 }
716
717 /**
718 * Get plugin we work for.
719 *
720 * @return Plugin.
721 */
722 public ModuleServicePlugin getPlugin() {
723 return plugin;
724 }
725
726 /**
727 * Get plugin action name.
728 *
729 * @return Plugin action name.
730 */
731 public String getName() {
732 return plugin.getServiceAction();
733 }
734
735 /**
736 * Get default plugin values.
737 *
738 * @return Default values.
739 */
740 private Parameters getDefaultPluginValues() {
741 final Parameters parameters = new Parameters();
742 plugin.setDefaultValuesForEmptyPluginParameters(parameters);
743 return parameters;
744 }
745
746 JComponent createDefault() {
747 return create(getDefaultPluginValues());
748 }
749
750 abstract JComponent create(Parameters parameters);
751
752 }
753
754 }
|