From: <Jen...@us...> - 2008-08-21 14:23:05
|
Revision: 1120 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1120&view=rev Author: JensLehmann Date: 2008-08-21 14:23:00 +0000 (Thu, 21 Aug 2008) Log Message: ----------- intermediate commit (fixing GUI code for several hours) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java trunk/src/dl-learner/org/dllearner/core/ComponentPool.java trunk/src/dl-learner/org/dllearner/gui/Config.java trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java trunk/src/dl-learner/org/dllearner/gui/StartGUI.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDefault.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDouble.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringTupleList.java trunk/src/dl-learner/org/dllearner/test/junit/ExampleTests.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/gui/AboutWindow.java trunk/src/dl-learner/org/dllearner/gui/AbstractWidgetPanel.java trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java trunk/src/dl-learner/org/dllearner/gui/TutorialWindow.java trunk/src/dl-learner/org/dllearner/gui/dl-learner.gif Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelAbstract.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -74,6 +74,10 @@ return problems; } + public static String getName() { + return "DBpedia Navigation Suggestor"; + } + public DBpediaNavigationSuggestor(PosOnlyDefinitionLP learningProblem, ReasoningService rs) { System.out.println("test1"); } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentPool.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentPool.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/core/ComponentPool.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -39,8 +39,7 @@ */ public final class ComponentPool { - private static Logger logger = Logger - .getLogger(ComponentPool.class); + private static Logger logger = Logger.getLogger(ComponentPool.class); // stores all components, which are live (components which are // no longer used have to be deregistered) Added: trunk/src/dl-learner/org/dllearner/gui/AboutWindow.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/AboutWindow.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/AboutWindow.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -0,0 +1,32 @@ +package org.dllearner.gui; + +import javax.swing.JFrame; + +/** + * Window displaying some information about DL-Learner and DL-Learner GUI. + * + * @author Jens Lehmann + * + */ +public class AboutWindow extends JFrame { + + private static final long serialVersionUID = -5448814141333659068L; + + public AboutWindow() { + setTitle("About"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLocationByPlatform(true); + setSize(300, 300); + + // display icon + + // display build version + + // display authors of GUI + + // display DL-Learner contributors + + setVisible(true); + } + +} Copied: trunk/src/dl-learner/org/dllearner/gui/AbstractWidgetPanel.java (from rev 1115, trunk/src/dl-learner/org/dllearner/gui/WidgetPanelAbstract.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/AbstractWidgetPanel.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/AbstractWidgetPanel.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -0,0 +1,76 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.gui; + +import javax.swing.JLabel; +import javax.swing.JPanel; + +import org.dllearner.core.Component; +import org.dllearner.core.config.ConfigOption; + +/** + * Abstract superclass of all widgets. Each widget has an associated component and configuration option, + * for which it allows modification by the user. + * + * @author Jens Lehmann + */ +public abstract class AbstractWidgetPanel<T> extends JPanel { + + protected ConfigOption<T> configOption; + protected Config config; + protected Component component; + + /** + * Constructs a widget. + * @param config The status of all components and options (which may be updated by this widget). + * @param component The component potentially changed by this widget. + * @param optionOption The config option of the specified component, which is potentially changed by this widget. + */ + public AbstractWidgetPanel(Config config, Component component, ConfigOption<T> optionOption) { + this.config = config; + this.component = component; + this.configOption = optionOption; + + if(configOption == null || component == null || config == null) { + System.out.println("| " + component + ", " + configOption + ", " + config + " |"); + throw new Error("Parameters must not be null."); + } + + buildWidgetPanel(); + } + + // convenience method + protected JLabel getLabel() { + JLabel nameLabel = new JLabel(configOption.getName()); + nameLabel.setToolTipText(configOption.getDescription()); + return nameLabel; + } + + // subclasses should call this method if a configuration option has changed + public void fireValueChanged(T value) { + // TODO notify config that an option has changed + // (component manager should be accessed in config only, such that we can intelligently decide which + // panels to initialise) + } + + // subclasses should use this method to build the graphical representation of the widgets + public abstract void buildWidgetPanel(); + +} Added: trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -0,0 +1,24 @@ +package org.dllearner.gui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JPanel; + +import org.dllearner.core.Component; + +/** + * Class displaying a component (and its options). + * + * @author Jens Lehmann + * + */ +public class ComponentPanel<T extends Component> extends JPanel implements ActionListener { + + private static final long serialVersionUID = -7678275020058043937L; + + public void actionPerformed(ActionEvent arg0) { + // TODO Auto-generated method stub + } + +} Modified: trunk/src/dl-learner/org/dllearner/gui/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -20,12 +20,16 @@ package org.dllearner.gui; +import org.dllearner.core.Component; import org.dllearner.core.ComponentManager; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningProblem; +import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.ReasoningService; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.config.ConfigEntry; +import org.dllearner.core.config.ConfigOption; // import org.dllearner.core.Component; @@ -37,28 +41,32 @@ * @author Tilo Hielscher */ public class Config { + private ComponentManager cm = ComponentManager.getInstance(); + + // the components currently active private KnowledgeSource source; - private KnowledgeSource oldSource; private ReasonerComponent reasoner; - private ReasonerComponent oldReasoner; private ReasoningService rs; private LearningProblem lp; - private LearningProblem oldLearningProblem; private LearningAlgorithm la; - private LearningAlgorithm oldLearningAlgorithm; + private boolean[] isInit = new boolean[4]; + // stores whether a component needs to be initialised ("previous" components have changed configuration values) +// private boolean[] needsInit = new boolean[4]; + + // learning algorithm status private Boolean threadIsRunning = false; private Long algorithmRunStartTime = null; private Long algorithmRunStopTime = null; - + /** * Get ComponentManager. * * @return ComponentManager */ public ComponentManager getComponentManager() { - return this.cm; + return cm; } /** @@ -80,8 +88,7 @@ * @param knowledgeSource */ public void setKnowledgeSource(KnowledgeSource knowledgeSource) { - this.oldSource = this.source; - this.source = knowledgeSource; + source = knowledgeSource; } /** @@ -94,21 +101,21 @@ } /** - * Get old KnowledgeSource. - * - * @return old KnowledgeSource + * Creates a knowledge source and makes it the active source. + * @param clazz + * @return */ - public KnowledgeSource getOldKnowledgeSource() { - return this.oldSource; + public KnowledgeSource newKnowledgeSource(Class<? extends KnowledgeSource> clazz) { + source = cm.knowledgeSource(clazz); + return source; } - + /** * Set Reasoner. * * @param reasoner */ public void setReasoner(ReasonerComponent reasoner) { - this.oldReasoner = this.reasoner; this.reasoner = reasoner; } @@ -121,16 +128,14 @@ return this.reasoner; } + // creates reasoner + reasoning service and makes it active + public ReasonerComponent newReasoner(Class<? extends ReasonerComponent> clazz) { + reasoner = cm.reasoner(clazz, source); + rs = cm.reasoningService(reasoner); + return reasoner; + } + /** - * Get old Reasoner as a set. - * - * @return oldReasonerSet. - */ - public ReasonerComponent getOldReasonerSet() { - return this.oldReasoner; - } - - /** * Set ReasoningService. * * @param reasoningService @@ -154,7 +159,6 @@ * @param learningProblem */ public void setLearningProblem(LearningProblem learningProblem) { - this.oldLearningProblem = this.lp; this.lp = learningProblem; } @@ -167,22 +171,17 @@ return this.lp; } - /** - * Get old LearningProblem as a set. - * - * @return old learningProblemSet. - */ - public LearningProblem getOldLearningProblem() { - return this.oldLearningProblem; + public LearningProblem newLearningProblem(Class<? extends LearningProblem> clazz) { + lp = cm.learningProblem(clazz, rs); + return lp; } - + /** * Set LearningAlgorithm. * * @param learningAlgorithm */ public void setLearningAlgorithm(LearningAlgorithm learningAlgorithm) { - this.oldLearningAlgorithm = this.la; this.la = learningAlgorithm; } @@ -195,16 +194,12 @@ return this.la; } + public LearningAlgorithm newLearningAlgorithm(Class<? extends LearningAlgorithm> clazz) throws LearningProblemUnsupportedException { + la = cm.learningAlgorithm(clazz, lp, rs); + return la; + } + /** - * Get old LearningAlgorithmSet. - * - * @return old LearningAlgorithmSet - */ - public LearningAlgorithm getOldLearningAlgorithm() { - return this.oldLearningAlgorithm; - } - - /** * KnowledgeSource.init has run? * * @return true, if init was made, false if not @@ -331,23 +326,28 @@ return false; } - /** - * reInit ComponentManager. - */ public void reInit() { cm = ComponentManager.getInstance(); source = null; - oldSource = null; reasoner = null; - oldReasoner = null; rs = null; lp = null; - oldLearningProblem = null; la = null; - oldLearningAlgorithm = null; isInit = new boolean[4]; threadIsRunning = false; algorithmRunStartTime = null; algorithmRunStopTime = null; } + + // applies a configuration option - used as delegate method, which invalidates components + public <T> void applyConfigEntry(Component component, ConfigEntry<T> entry) { + cm.applyConfigEntry(component, entry); + // invalidate components + } + + // delegate method for getting + public <T> T getConfigOptionValue(Component component, ConfigOption<T> option) { + return cm.getConfigOptionValue(component, option); + } + } Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -1,5 +1,3 @@ -package org.dllearner.gui; - /** * Copyright (C) 2007-2008, Jens Lehmann * @@ -19,18 +17,21 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ +package org.dllearner.gui; -import java.util.List; -import javax.swing.*; import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.List; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JPanel; + import org.dllearner.core.ComponentInitException; import org.dllearner.core.KnowledgeSource; -// import org.dllearner.kb.*; /** * KnowledgeSourcePanel, tab 0. Choose Source, change Options and final initiate @@ -80,9 +81,12 @@ choosePanel.add(setButton); choosenClassIndex = cb.getSelectedIndex(); - optionPanel = new OptionPanel(config, config.getKnowledgeSource(), config - .getOldKnowledgeSource(), sources.get(choosenClassIndex)); - initPanel.add(initButton); + // whenever a component is selected, we immediately create an instance (non-initialised) + KnowledgeSource ks = config.newKnowledgeSource(sources.get(cb.getSelectedIndex())); + optionPanel = new OptionPanel(config, ks); + +// optionPanel = new OptionPanel(config, config.getKnowledgeSource(), sources.get(choosenClassIndex)); + // initPanel.add(initButton); add(choosePanel, BorderLayout.PAGE_START); add(optionPanel, BorderLayout.CENTER); @@ -167,8 +171,8 @@ * update OptionPanel with new selection */ public void updateOptionPanel() { - optionPanel.update(config.getKnowledgeSource(), config.getOldKnowledgeSource(), sources - .get(choosenClassIndex)); + // TODO implement properly !! +// optionPanel.update(config.getKnowledgeSource(), sources.get(choosenClassIndex)); } /** Modified: trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -19,14 +19,18 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -import javax.swing.*; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JPanel; + +import org.dllearner.algorithms.DBpediaNavigationSuggestor; +import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblemUnsupportedException; @@ -52,16 +56,22 @@ private JComboBox cb = new JComboBox(cbItems); private int choosenClassIndex; - LearningAlgorithmPanel(Config config, StartGUI startGUI) { + public LearningAlgorithmPanel(Config config, StartGUI startGUI) { super(new BorderLayout()); this.config = config; this.startGUI = startGUI; learner = config.getComponentManager().getLearningAlgorithms(); + // to set a default learning algorithm, we move it to the beginning of the list + learner.remove(ExampleBasedROLComponent.class); + learner.add(0, ExampleBasedROLComponent.class); + // we also remove the DBpedia Navigation Suggestor (maybe shouldn't be declared as a learning algorithm at all; + // at least it is not doing anything useful at the moment) + learner.remove(DBpediaNavigationSuggestor.class); initButton = new JButton("Init LearingAlgorithm"); initButton.addActionListener(this); - initPanel.add(initButton); + // initPanel.add(initButton); initButton.setEnabled(true); autoInitButton = new JButton("Set"); autoInitButton.addActionListener(this); @@ -75,8 +85,14 @@ choosePanel.add(autoInitButton); cb.addActionListener(this); - optionPanel = new OptionPanel(config, config.getLearningAlgorithm(), config - .getOldLearningAlgorithm(), learner.get(choosenClassIndex)); + LearningAlgorithm la = null; + try { + la = config.newLearningAlgorithm(learner.get(cb.getSelectedIndex())); + } catch (LearningProblemUnsupportedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + optionPanel = new OptionPanel(config, la); add(choosePanel, BorderLayout.PAGE_START); add(optionPanel, BorderLayout.CENTER); @@ -161,8 +177,8 @@ */ public void updateOptionPanel() { // update OptionPanel - optionPanel.update(config.getLearningAlgorithm(), config.getOldLearningAlgorithm(), learner - .get(choosenClassIndex)); + // TODO implement properly !! +// optionPanel.update(config.getLearningAlgorithm(), learner.get(choosenClassIndex)); } /** Modified: trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -60,7 +60,7 @@ initButton = new JButton("Init LearningProblem"); initButton.addActionListener(this); - initPanel.add(initButton); + // initPanel.add(initButton); initButton.setEnabled(true); setButton = new JButton("Set"); setButton.addActionListener(this); @@ -76,8 +76,8 @@ // read choosen LearningProblem choosenClassIndex = cb.getSelectedIndex(); - optionPanel = new OptionPanel(config, config.getLearningProblem(), config - .getOldLearningProblem(), problem.get(choosenClassIndex)); + LearningProblem lp = config.newLearningProblem(problem.get(choosenClassIndex)); + optionPanel = new OptionPanel(config, lp); add(choosePanel, BorderLayout.PAGE_START); add(optionPanel, BorderLayout.CENTER); @@ -160,8 +160,8 @@ */ private void updateOptionPanel() { // update OptionPanel - optionPanel.update(config.getLearningProblem(), config.getOldLearningProblem(), problem - .get(choosenClassIndex)); +// TODO: implement properly !! +// optionPanel.update(config.getLearningProblem(), problem.get(choosenClassIndex)); } /** Modified: trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -1,5 +1,3 @@ -package org.dllearner.gui; - /** * Copyright (C) 2007-2008, Jens Lehmann * @@ -19,6 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ +package org.dllearner.gui; import java.awt.BorderLayout; import java.awt.Dimension; @@ -39,31 +38,26 @@ * here. * * @author Tilo Hielscher + * @author Jens Lehmann * */ public class OptionPanel extends JPanel { private static final long serialVersionUID = -3053205578443575240L; + private Config config; - private Class<? extends Component> componentOption; - private List<ConfigOption<?>> optionList; +// private Class<? extends Component> componentClass; private JPanel centerPanel = new JPanel(); private Component component; - private Component oldComponent; private GridBagLayout gridBagLayout = new GridBagLayout(); private GridBagConstraints constraints = new GridBagConstraints(); - public OptionPanel(Config config, Component component, Component oldComponent, - Class<? extends Component> componentOption) { + public OptionPanel(Config config, Component component) { super(new BorderLayout()); - + this.config = config; this.component = component; - this.oldComponent = oldComponent; - this.componentOption = componentOption; - optionList = ComponentManager.getConfigOptions(componentOption); - // define GridBagLayout centerPanel.setLayout(gridBagLayout); constraints.anchor = GridBagConstraints.NORTHWEST; @@ -78,47 +72,40 @@ } /** update this OptionPanel */ - public void update(Component component, Component oldComponent, - Class<? extends Component> componentOption) { + public void update(Component component) { this.component = component; - this.oldComponent = oldComponent; - this.componentOption = componentOption; showWidgets(); - } /** * Define here what core.config.class is what type of widget. * WidgetPanelDefault is for none defined classes. */ + @SuppressWarnings("unchecked") private void showWidgets() { + // clear panel + centerPanel.removeAll(); + JPanel widgetPanel; - optionList = ComponentManager.getConfigOptions(componentOption); - centerPanel.removeAll(); // clear panel + List<ConfigOption<?>> optionList = ComponentManager.getConfigOptions(component.getClass()); + for (int i = 0; i < optionList.size(); i++) { buildConstraints(constraints, 0, i, 1, 1, 0, 0); - if (optionList.get(i).getClass().toString().contains("IntegerConfigOption")) { - widgetPanel = new WidgetPanelInteger(config, component, oldComponent, - componentOption, optionList.get(i)); - } else if (optionList.get(i).getClass().toString().contains("BooleanConfigOption")) { - widgetPanel = new WidgetPanelBoolean(config, component, oldComponent, - componentOption, optionList.get(i)); - } else if (optionList.get(i).getClass().toString().contains("DoubleConfigOption")) { - widgetPanel = new WidgetPanelDouble(config, component, oldComponent, - componentOption, optionList.get(i)); - } else if (optionList.get(i).getClass().toString().contains("StringConfigOption")) { - widgetPanel = new WidgetPanelString(config, component, oldComponent, - componentOption, optionList.get(i)); - } else if (optionList.get(i).getClass().toString().contains("StringSetConfigOption")) { - widgetPanel = new WidgetPanelStringSet(config, component, oldComponent, - componentOption, optionList.get(i)); - } else if (optionList.get(i).getClass().toString().contains( - "StringTupleListConfigOption")) { - widgetPanel = new WidgetPanelStringTupleList(config, component, oldComponent, - componentOption, optionList.get(i)); + ConfigOption option = optionList.get(i); + if (option instanceof IntegerConfigOption) { + widgetPanel = new WidgetPanelInteger(config, component, (IntegerConfigOption) option); + } else if (option instanceof BooleanConfigOption) { + widgetPanel = new WidgetPanelBoolean(config, component, (BooleanConfigOption) option); + } else if (option instanceof DoubleConfigOption) { + widgetPanel = new WidgetPanelDouble(config, component, (DoubleConfigOption) option); + } else if (option instanceof StringConfigOption) { + widgetPanel = new WidgetPanelString(config, component, (StringConfigOption) option); + } else if (option instanceof StringSetConfigOption) { + widgetPanel = new WidgetPanelStringSet(config, component, (StringSetConfigOption) option); + } else if (option instanceof StringTupleListConfigOption) { + widgetPanel = new WidgetPanelStringTupleList(config, component, (StringTupleListConfigOption) option); } else { - widgetPanel = new WidgetPanelDefault(config, component, - /* oldComponent, */componentOption, optionList.get(i)); + widgetPanel = new WidgetPanelDefault(config, component, option); } gridBagLayout.setConstraints(widgetPanel, constraints); centerPanel.add(widgetPanel); Modified: trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -26,10 +26,13 @@ import java.awt.event.ActionListener; import java.util.List; -import javax.swing.*; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JPanel; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ReasonerComponent; +import org.dllearner.reasoning.OWLAPIReasoner; /** * ReasonerPanel, tab 1. Choose Resoner, change Options and final initiate @@ -58,10 +61,13 @@ this.config = config; this.startGUI = startGUI; reasoner = config.getComponentManager().getReasonerComponents(); + // to set a default reasoner, we move it to the beginning of the list + reasoner.remove(OWLAPIReasoner.class); + reasoner.add(0, OWLAPIReasoner.class); initButton = new JButton("Init Reasoner"); initButton.addActionListener(this); - initPanel.add(initButton); + // initPanel.add(initButton); initButton.setEnabled(true); setButton = new JButton("Set"); setButton.addActionListener(this); @@ -73,8 +79,8 @@ cb.addItem(config.getComponentManager().getComponentName(reasoner.get(i))); } - optionPanel = new OptionPanel(config, config.getReasoner(), config.getOldReasonerSet(), - reasoner.get(choosenClassIndex)); + ReasonerComponent rc = config.newReasoner(reasoner.get(cb.getSelectedIndex())); + optionPanel = new OptionPanel(config, rc); choosePanel.add(setButton); cb.addActionListener(this); @@ -168,8 +174,8 @@ * update OptionPanel with new selection */ public void updateOptionPanel() { - optionPanel.update(config.getReasoner(), config.getOldReasonerSet(), reasoner - .get(choosenClassIndex)); +// TODO: implement properly !! +// optionPanel.update(config.getReasoner(), reasoner.get(choosenClassIndex)); } /** Modified: trunk/src/dl-learner/org/dllearner/gui/StartGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -1,5 +1,3 @@ -package org.dllearner.gui; - /** * Copyright (C) 2007-2008, Jens Lehmann * @@ -19,6 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ +package org.dllearner.gui; import javax.swing.*; import javax.swing.event.*; @@ -38,9 +37,10 @@ import javax.swing.filechooser.FileFilter; /** - * StartGUI + * This class builds the basic GUI elements and is used to start the DL-Learner GUI. * * @author Tilo Hielscher + * @author Jens Lehmann */ public class StartGUI extends JFrame implements ActionListener { @@ -49,9 +49,10 @@ private JTabbedPane tabPane = new JTabbedPane(); private Config config = new Config(); - private ConfigLoad configLoad = new ConfigLoad(config, this);; - private ConfigSave configSave = new ConfigSave(config, this);; + private ConfigLoad configLoad = new ConfigLoad(config, this); + private ConfigSave configSave = new ConfigSave(config, this); + private KnowledgeSourcePanel tab0; private ReasonerPanel tab1; private LearningProblemPanel tab2; @@ -60,19 +61,23 @@ private JMenuBar menuBar = new JMenuBar(); private JMenu menuFile = new JMenu("File"); - private JMenuItem openItem = new JMenuItem("Open Config"); - private JMenuItem saveItem = new JMenuItem("Save As Config"); + private JMenuItem openItem = new JMenuItem("Open Conf File ..."); + private JMenuItem saveItem = new JMenuItem("Save As Conf File ..."); + private JMenuItem exitItem = new JMenuItem("Exit"); + private JMenu menuHelp = new JMenu("Help"); + private JMenuItem aboutItem = new JMenuItem("About"); + private JMenuItem tutorialItem = new JMenuItem("Tutorial"); public StartGUI() { this(null); } - + public StartGUI(File file) { - this.setTitle("DL-Learner"); + this.setTitle("DL-Learner GUI"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationByPlatform(true); this.setSize(800, 600); - + // set icon if (this.getClass().getResource("icon.gif") != null) setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage( @@ -89,15 +94,22 @@ tabPane.addTab("Learning Algorithm", tab3); tabPane.addTab("Run", tab4); - this.setJMenuBar(menuBar); + setJMenuBar(menuBar); menuBar.add(menuFile); menuFile.add(openItem); openItem.addActionListener(this); menuFile.add(saveItem); saveItem.addActionListener(this); + menuFile.add(exitItem); + exitItem.addActionListener(this); + menuBar.add(menuHelp); + menuHelp.add(tutorialItem); + tutorialItem.addActionListener(this); + menuHelp.add(aboutItem); + aboutItem.addActionListener(this); - this.add(tabPane); - this.setVisible(true); + add(tabPane); + setVisible(true); updateTabColors(); // Register a change listener @@ -107,8 +119,8 @@ init(); } }); - - if(file != null) { + + if (file != null) { configLoad.openFile(file); configLoad.startParser(); } @@ -132,10 +144,10 @@ logger.setLevel(Level.INFO); File file = null; - if(args.length > 0) + if (args.length > 0) file = new File(args[args.length - 1]); - new StartGUI(file); + new StartGUI(file); } public void actionPerformed(ActionEvent e) { @@ -162,9 +174,8 @@ configLoad.openFile(fc.getSelectedFile()); configLoad.startParser(); } - } // save as config file - if (e.getSource() == saveItem) { + } else if (e.getSource() == saveItem) { JFileChooser fc = new JFileChooser(new File("examples/")); // FileFilter only *.conf fc.addChoosableFileFilter(new FileFilter() { @@ -194,6 +205,15 @@ } } System.out.println("config file saved"); + // exit + } else if (e.getSource() == exitItem) { + dispose(); + // tutorial + } else if (e.getSource() == tutorialItem) { + new TutorialWindow(); + // about + } else if (e.getSource() == aboutItem) { + new AboutWindow(); } } Added: trunk/src/dl-learner/org/dllearner/gui/TutorialWindow.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/TutorialWindow.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/TutorialWindow.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -0,0 +1,26 @@ +package org.dllearner.gui; + +import javax.swing.JFrame; + +/** + * Window displaying a tutorial for the DL-Learner GUI. + * + * @author Jens Lehmann + * + */ +public class TutorialWindow extends JFrame { + + private static final long serialVersionUID = 9152567539729126842L; + + public TutorialWindow() { + setTitle("Quick Tutorial"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLocationByPlatform(true); + setSize(300, 500); + + // display tutorial text + + setVisible(true); + } + +} Deleted: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelAbstract.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelAbstract.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelAbstract.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -1,47 +0,0 @@ -package org.dllearner.gui; - -/** - * Copyright (C) 2007-2008, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -import javax.swing.JPanel; - -/** - * WidgetPanelAbstract defines all Widgets in an abstract way. - * - * @author Tilo Hielscher - */ -public abstract class WidgetPanelAbstract extends JPanel { - - /** - * Show label and tooltip. - */ - public abstract void showLabel(); - - /** - * Show textfield, setbutton and so on, make layout. - */ - public abstract void showThingToChange(); - - /** - * Set entry you got from showThingToChange(). - */ - public abstract void setEntry(); - -} Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -1,5 +1,3 @@ -package org.dllearner.gui; - /** * Copyright (C) 2007-2008, Jens Lehmann * @@ -19,53 +17,35 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ +package org.dllearner.gui; -import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.Color; import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JPanel; import org.dllearner.core.Component; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.BooleanConfigOption; +import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.InvalidConfigOptionValueException; /** * Panel for option Boolean, defined in * org.dllearner.core.config.BooleanConfigOption. * + * @author Jens Lehmann * @author Tilo Hielscher */ -public class WidgetPanelBoolean extends WidgetPanelAbstract implements ActionListener { +public class WidgetPanelBoolean extends AbstractWidgetPanel<Boolean> implements ActionListener { private static final long serialVersionUID = -4800583253223939928L; - private Config config; - private ConfigOption<?> configOption; - private JLabel nameLabel; - private JPanel widgetPanel = new JPanel(); - private Component component; - private Component oldComponent; - private Class<? extends Component> componentOption; + private Boolean value; - private String[] kbBoxItems = { "false", "true" }; - private JComboBox cb = new JComboBox(kbBoxItems); +// private String[] kbBoxItems; // = { "false", "true" }; + private JComboBox cb; // = new JComboBox(kbBoxItems); - public WidgetPanelBoolean(Config config, Component component, Component oldComponent, - Class<? extends Component> componentOption, ConfigOption<?> configOption) { - this.config = config; - this.configOption = configOption; - this.component = component; - this.oldComponent = oldComponent; - this.componentOption = componentOption; - - showLabel(); // name of option and tooltip - showThingToChange(); // textfield, setbutton - add(widgetPanel, BorderLayout.CENTER); + public WidgetPanelBoolean(Config config, Component component, BooleanConfigOption configOption) { + super(config, component, configOption); } public void actionPerformed(ActionEvent e) { @@ -73,76 +53,27 @@ value = false; else value = true; - setEntry(); - } - - @Override - public void showLabel() { - nameLabel = new JLabel(configOption.getName()); - nameLabel.setToolTipText(configOption.getDescription()); - widgetPanel.add(nameLabel); - } - - @Override - public void showThingToChange() { - if (component != null) { - // BooleanConfigOption - if (configOption.getClass().toString().contains("BooleanConfigOption")) { - // previous set value - if (configOption != null) { - value = (Boolean) config.getComponentManager().getConfigOptionValue(component, - configOption.getName()); - } - // previous set value from old - if (component != null && oldComponent != null) { - if (oldComponent.getClass().equals(component.getClass())) { - value = (Boolean) config.getComponentManager().getConfigOptionValue( - oldComponent, configOption.getName()); - if (value == null) - value = false; - else - setEntry(); - // set cb-index - if (!value) - cb.setSelectedIndex(0); - else - cb.setSelectedIndex(1); - } - } - // default value - else if (value != null && configOption.getDefaultValue() != null) { - value = (Boolean) configOption.getDefaultValue(); - } - // value == null? - if (value == null) { - value = false; - } - // set cb-index - if (!value) - cb.setSelectedIndex(0); - else - cb.setSelectedIndex(1); - cb.addActionListener(this); - widgetPanel.add(cb); + + BooleanConfigOption specialOption; + specialOption = (BooleanConfigOption) config.getComponentManager().getConfigOption( + component.getClass(), configOption.getName()); + if (specialOption.isValidValue(value)) { + try { + ConfigEntry<Boolean> specialEntry = new ConfigEntry<Boolean>(specialOption, value); + config.getComponentManager().applyConfigEntry(component, specialEntry); + // System.out.println("set Boolean: " + configOption.getName() + + // " = " + value); + } catch (InvalidConfigOptionValueException s) { + s.printStackTrace(); } - // UNKNOWN - else { - JLabel notImplementedLabel = new JLabel("not a boolean"); - notImplementedLabel.setForeground(Color.RED); - widgetPanel.add(notImplementedLabel); - } - } else { // configOption == NULL - JLabel noConfigOptionLabel = new JLabel("no init (Boolean)"); - noConfigOptionLabel.setForeground(Color.MAGENTA); - widgetPanel.add(noConfigOptionLabel); - } + } else + System.out.println("Boolean: not valid value"); } - @Override public void setEntry() { BooleanConfigOption specialOption; specialOption = (BooleanConfigOption) config.getComponentManager().getConfigOption( - componentOption, configOption.getName()); + component.getClass(), configOption.getName()); if (specialOption.isValidValue(value)) { try { ConfigEntry<Boolean> specialEntry = new ConfigEntry<Boolean>(specialOption, value); @@ -156,4 +87,28 @@ System.out.println("Boolean: not valid value"); } + @Override + public void buildWidgetPanel() { + add(getLabel()); + + value = config.getConfigOptionValue(component, configOption); + + if (value == null) + value = false; + else + setEntry(); + + // set cb-index + String[] kbBoxItems = { "false", "true" }; + cb = new JComboBox(kbBoxItems); + if (!value) + cb.setSelectedIndex(0); + else + cb.setSelectedIndex(1); + + cb.addActionListener(this); + add(cb); + + } + } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDefault.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDefault.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDefault.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -1,5 +1,3 @@ -package org.dllearner.gui; - /** * Copyright (C) 2007-2008, Jens Lehmann * @@ -19,12 +17,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ +package org.dllearner.gui; -import java.awt.BorderLayout; import java.awt.Color; import javax.swing.JLabel; -import javax.swing.JPanel; import org.dllearner.core.Component; import org.dllearner.core.config.ConfigOption; @@ -35,42 +32,20 @@ * @author Tilo Hielscher * */ -public class WidgetPanelDefault extends WidgetPanelAbstract { +public class WidgetPanelDefault extends AbstractWidgetPanel<Object> { private static final long serialVersionUID = 4059515858894036769L; - private ConfigOption<?> configOption; - private JLabel nameLabel; - private JPanel widgetPanel = new JPanel(); - - public WidgetPanelDefault(Config config, Component component, - Class<? extends Component> componentOption, ConfigOption<?> configOption) { - - this.configOption = configOption; - - showLabel(); - showThingToChange(); - add(widgetPanel, BorderLayout.CENTER); + public WidgetPanelDefault(Config config, Component component, ConfigOption<Object> configOption) { + super(config, component, configOption); } @Override - public void showLabel() { - nameLabel = new JLabel(configOption.getName()); - nameLabel.setToolTipText(configOption.getDescription()); - widgetPanel.add(nameLabel); - } - - @Override - public void showThingToChange() { + public void buildWidgetPanel() { JLabel notImplementedLabel = new JLabel(configOption.getClass().getSimpleName() + " not implemented"); notImplementedLabel.setForeground(Color.RED); - - widgetPanel.add(notImplementedLabel); + add(notImplementedLabel); } - @Override - public void setEntry() { - } - } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDouble.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDouble.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDouble.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -20,55 +20,37 @@ * */ -import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.Color; -import javax.swing.JTextField; -import javax.swing.JLabel; -import javax.swing.JPanel; import javax.swing.JButton; +import javax.swing.JTextField; import org.dllearner.core.Component; import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.DoubleConfigOption; import org.dllearner.core.config.InvalidConfigOptionValueException; /** * Panel for option Double, defined in - * org.dllearner.core.config.DoubleConfigOption. + * {@link org.dllearner.core.config.DoubleConfigOption}. * * @author Tilo Hielscher * */ -public class WidgetPanelDouble extends WidgetPanelAbstract implements ActionListener { +public class WidgetPanelDouble extends AbstractWidgetPanel<Double> implements ActionListener { private static final long serialVersionUID = 5238903690721116289L; - private Config config; - private ConfigOption<?> configOption; - private JLabel nameLabel; - private JPanel widgetPanel = new JPanel(); + private JButton setButton = new JButton("Set"); - private Component component; - private Component oldComponent; - private Class<? extends Component> componentOption; +// private Class<? extends Component> componentOption; + private Double value; private JTextField doubleField = new JTextField(5); - public WidgetPanelDouble(Config config, Component component, Component oldComponent, - Class<? extends Component> componentOption, ConfigOption<?> configOption) { - this.config = config; - this.configOption = configOption; - this.component = component; - this.oldComponent = oldComponent; - this.componentOption = componentOption; - - showLabel(); // name of option and tooltip - showThingToChange(); // textfield, setbutton - add(widgetPanel, BorderLayout.CENTER); + public WidgetPanelDouble(Config config, Component component, DoubleConfigOption configOption) { + super(config, component, configOption); } public void actionPerformed(ActionEvent e) { @@ -77,69 +59,11 @@ } } - @Override - public void showLabel() { - nameLabel = new JLabel(configOption.getName()); - nameLabel.setToolTipText(configOption.getDescription()); - widgetPanel.add(nameLabel); - } - - @Override - public void showThingToChange() { - if (component != null) { - // DoubleConfigOption - if (configOption.getClass().toString().contains("DoubleConfigOption")) { - // previous set value - if (configOption != null) { - value = (Double) config.getComponentManager().getConfigOptionValue(component, - configOption.getName()); - } - // previous set value from old - if (component != null && oldComponent != null) { - if (oldComponent.getClass().equals(component.getClass())) { - value = (Double) config.getComponentManager().getConfigOptionValue( - oldComponent, configOption.getName()); - if (value == null) - value = 0.0; - else { - doubleField.setText(value.toString()); - setEntry(); - } - } - } - // default value - else if (configOption.getDefaultValue() != null) { - value = (Double) configOption.getDefaultValue(); - } - // value == null - if (value == null) { - value = 0.0; - } - doubleField.setText(value.toString()); - doubleField.setToolTipText(configOption.getAllowedValuesDescription()); - setButton.addActionListener(this); - widgetPanel.add(doubleField); - widgetPanel.add(setButton); - } - // UNKNOWN - else { - JLabel notImplementedLabel = new JLabel("not a double"); - notImplementedLabel.setForeground(Color.RED); - widgetPanel.add(notImplementedLabel); - } - } else { // configOption == NULL - JLabel noConfigOptionLabel = new JLabel("no instance (Double)"); - noConfigOptionLabel.setForeground(Color.MAGENTA); - widgetPanel.add(noConfigOptionLabel); - } - } - - @Override public void setEntry() { DoubleConfigOption specialOption; value = Double.parseDouble(doubleField.getText()); // get from input specialOption = (DoubleConfigOption) config.getComponentManager().getConfigOption( - componentOption, configOption.getName()); + component.getClass(), configOption.getName()); if (specialOption.isValidValue(value)) { try { ConfigEntry<Double> specialEntry = new ConfigEntry<Double>(specialOption, value); @@ -152,4 +76,27 @@ } else System.out.println("Double: not valid value"); } + + @Override + public void buildWidgetPanel() { + add(getLabel()); + + value = config.getConfigOptionValue(component, configOption); + + setButton = new JButton("Set"); + doubleField = new JTextField(5); + if (value == null) + value = 0.0; + else { + doubleField.setText(value.toString()); + setEntry(); + } + + doubleField.setText(value.toString()); + doubleField.setToolTipText(configOption.getAllowedValuesDescription()); + setButton.addActionListener(this); + add(doubleField); + add(setButton); + + } } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -20,19 +20,14 @@ * */ -import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.Color; -import javax.swing.JTextField; -import javax.swing.JLabel; -import javax.swing.JPanel; import javax.swing.JButton; +import javax.swing.JTextField; import org.dllearner.core.Component; import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerConfigOption; import org.dllearner.core.config.InvalidConfigOptionValueException; @@ -43,33 +38,17 @@ * @author Tilo Hielscher * */ -public class WidgetPanelInteger extends WidgetPanelAbstract implements ActionListener { +public class WidgetPanelInteger extends AbstractWidgetPanel<Integer> implements ActionListener { private static final long serialVersionUID = -1802111225835164644L; - private Config config; - private ConfigOption<?> configOption; - private JLabel nameLabel; - private JPanel widgetPanel = new JPanel(); private JButton setButton = new JButton("Set"); - private Component component; - private Component oldComponent; - private Class<? extends Component> componentOption; private Integer value; private JTextField integerField = new JTextField(3); - public WidgetPanelInteger(Config config, Component component, Component oldComponent, - Class<? extends Component> componentOption, ConfigOption<?> configOption) { - this.config = config; - this.configOption = configOption; - this.component = component; - this.oldComponent = oldComponent; - this.componentOption = componentOption; - - showLabel(); // name of option and tooltip - showThingToChange(); // textfield, setbutton - add(widgetPanel, BorderLayout.CENTER); + public WidgetPanelInteger(Config config, Component component, IntegerConfigOption configOption) { + super(config, component, configOption); } public void actionPerformed(ActionEvent e) { @@ -78,69 +57,11 @@ } } - @Override - public void showLabel() { - nameLabel = new JLabel(configOption.getName()); - nameLabel.setToolTipText(configOption.getDescription()); - widgetPanel.add(nameLabel); - } - - @Override - public void showThingToChange() { - if (component != null) { - // IntegerConfigOption - if (configOption.getClass().toString().contains("IntegerConfigOption")) { - // previous set value - if (configOption != null) { - value = (Integer) config.getComponentManager().getConfigOptionValue(component, - configOption.getName()); - } - // previous set value from old - if (component != null && oldComponent != null) { - if (oldComponent.getClass().equals(component.getClass())) { - value = (Integer) config.getComponentManager().getConfigOptionValue( - oldComponent, configOption.getName()); - if (value == null) - value = 0; - else { - integerField.setText(value.toString()); - setEntry(); - } - } - } - // default value - else if (configOption.getDefaultValue() != null) { - value = (Integer) configOption.getDefaultValue(); - } - // value == null - if (value == null) { - value = 0; - } - integerField.setText(value.toString()); - integerField.setToolTipText(configOption.getAllowedValuesDescription()); - setButton.addActionListener(this); - widgetPanel.add(integerField); - widgetPanel.add(setButton); - } - // UNKNOWN - else { - JLabel notImplementedLabel = new JLabel("not an integer"); - notImplementedLabel.setForeground(Color.RED); - widgetPanel.add(notImplementedLabel); - } - } else { // configOption == NULL - JLabel noConfigOptionLabel = new JLabel("no instance (Integer)"); - noConfigOptionLabel.setForeground(Color.MAGENTA); - widgetPanel.add(noConfigOptionLabel); - } - } - - @Override public void setEntry() { IntegerConfigOption specialOption; value = Integer.parseInt(integerField.getText()); // get from input specialOption = (IntegerConfigOption) config.getComponentManager().getConfigOption( - componentOption, configOption.getName()); + component.getClass(), configOption.getName()); if (specialOption.isValidValue(value)) { try { ConfigEntry<Integer> specialEntry = new ConfigEntry<Integer>(specialOption, value); @@ -153,4 +74,26 @@ } else System.out.println("Integer: not valid value"); } + + @Override + public void buildWidgetPanel() { + add(getLabel()); + + value = config.getConfigOptionValue(component, configOption); + + setButton = new JButton("Set"); + integerField = new JTextField(3); + if (value == null) + value = 0; + else { + integerField.setText(value.toString()); + setEntry(); + } + + integerField.setText(value.toString()); + integerField.setToolTipText(configOption.getAllowedValuesDescription()); + setButton.addActionListener(this); + add(integerField); + add(setButton); + } } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -1,5 +1,3 @@ -package org.dllearner.gui; - /** * Copyright (C) 2007-2008, Jens Lehmann * @@ -19,58 +17,43 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ +package org.dllearner.gui; -import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.Color; import java.io.File; +import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JTextField; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JButton; import org.dllearner.core.Component; import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.core.config.StringConfigOption; /** * Panel for option String, defined in - * org.dllearner.core.config.StringConfigOption. + * {@link org.dllearner.core.config.StringConfigOption}. * + * @author Jens Lehmann * @author Tilo Hielscher * */ -public class WidgetPanelString extends WidgetPanelAbstract implements ActionListener { +public class WidgetPanelString extends AbstractWidgetPanel<String> implements ActionListener { private static final long serialVersionUID = -2169739820989891226L; - private Config config; - private ConfigOption<?> configOption; - private JLabel nameLabel; - private JPanel widgetPanel = new JPanel(); - private JButton setButton = new JButton("Set"); - private Component component; - private Component oldComponent; + +// private JPanel widgetPanel = new JPanel(); + private JButton setButton; // = new JButton("Set"); + private Class<? extends Component> componentOption; private String value; - private JTextField stringField = new JTextField(35); + private JTextField stringField; // = new JTextField(35); - public WidgetPanelString(Config config, Component component, Component oldComponent, - Class<? extends Component> componentOption, ConfigOption<?> configOption) { - this.config = config; - this.configOption = configOption; - this.component = component; - this.oldComponent = oldComponent; - this.componentOption = componentOption; - - showLabel(); // name of option and tooltip - showThingToChange(); // textfield, setbutton - add(widgetPanel, BorderLayout.CENTER); + public WidgetPanelString(Config config, Component component, StringConfigOption configOption) { + super(config, component, configOption); } public void actionPerformed(ActionEvent e) { @@ -92,64 +75,6 @@ } } - @Override - public void showLabel() { - nameLabel = new JLabel(configOption.getName()); - nameLabel.setToolTipText(configOption.getDescription()); - widgetPanel.add(nameLabel); - } - - @Override - public void showThingToChange() { - if (component != null) { - // StringConfigOption - if (configOption.getClass().toString().contains("StringConfigOption")) { - // previous set value - if (configOption != null) { - value = (String) config.getComponentManager().getConfigOptionValue(component, - configOption.getName()); - } - // previous set value from old - if (component != null && oldComponent != null) { - if (oldComponent.getClass().equals(component.getClass())) { - value = (String) config.getComponentManager().getConfigOptionValue( - oldComponent, configOption.getName()); - if (value != null) { - stringField.setText(value.toString()); - setEntry(); - } - } - } - // default value - else if (configOption.getDefaultValue() != null) { - value = (String) configOption.getDefaultValue(); - } - // value == null - if (value == null) { - value = ""; - } - stringField.setText(value.toString()); - stringField.setToolTipText(configOption.getAllowedValuesDescription()); - setButton.addActionListener(this); - widgetPanel.add(stringField); - widgetPanel.add(setButton); - if (checkForFilename()) - setButton.setText("choose local file"); - } - // UNKNOWN - else { - JLabel notImplementedLabel = new JLabel("not a string"); - notImplementedLabel.setForeground(Color.RED); - widgetPanel.add(notImplementedLabel); - } - } else { // configOption == NULL - JLabel noConfigOptionLabel = new JLabel("no instance (String)"); - noConfigOptionLabel.setForeground(Color.MAGENTA); - widgetPanel.add(noConfigOptionLabel); - } - } - - @Override public void setEntry() { StringConfigOption specialOption; value = stringField.getText(); // get from input @@ -176,4 +101,32 @@ return configOption.getName().equalsIgnoreCase("filename"); } + @Override + public void buildWidgetPanel() { + add(getLabel()); + + // get current value of this option for the given component + value = config.getConfigOptionValue(component, configOption); + // default values can be null, so we interpret this as empty string + if (value == null) { + value = ""; + } + + // text field for strings + stringField = new JTextField(35); + stringField.setText(value); + stringField.setToolTipText(configOption.getAllowedValuesDescription()); + + // set button (value is only updated when this button is pressed => would better without set) + setButton = new JButton("Set"); + setButton.addActionListener(this); + + add(stringField); + add(setButton); + + if (checkForFilename()) + setButton.setText("choose local file"); + + } + } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java 2008-08-21 11:59:44 UTC (rev 1119) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java 2008-08-21 14:23:00 UTC (rev 1120) @@ -1,5 +1,3 @@ -package org.dllearner.gui; - /** * Copyright (C) 2007-2008, Jens Lehmann * @@ -19,6 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ +package org.dllearner.gui; import java.awt.BorderLayout; import java.awt.Dimension; @@ -26,24 +25,24 @@ import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.Color; -import java.util.*; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Set; import javax.swing.DefaultListModel; -import javax.swing.JLabel; +import javax.swing.JButton; import javax.swing.JList; import javax.swing.JPanel; -import javax.swing.JButton; import javax.swing.JScrollPane; import javax.swing.JTextField; import org.dllearner.core.Component; import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.StringSetConfigOption; import org.dllearner.core.config.InvalidConfigOpti... [truncated message content] |