From: <jen...@us...> - 2008-09-12 09:52:22
|
Revision: 1198 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1198&view=rev Author: jenslehmann Date: 2008-09-12 09:52:17 +0000 (Fri, 12 Sep 2008) Log Message: ----------- simplified GUI code: four panel classes merged into one Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java trunk/src/dl-learner/org/dllearner/gui/Config.java trunk/src/dl-learner/org/dllearner/gui/InitWorker.java trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java trunk/src/dl-learner/org/dllearner/gui/StartGUI.java Removed Paths: ------------- 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/ReasonerPanel.java Modified: trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java 2008-09-11 17:13:52 UTC (rev 1197) +++ trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java 2008-09-12 09:52:17 UTC (rev 1198) @@ -1,26 +1,176 @@ package org.dllearner.gui; +import java.awt.BorderLayout; import java.awt.LayoutManager; +import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.LinkedList; +import java.util.List; +import javax.swing.JButton; +import javax.swing.JComboBox; import javax.swing.JPanel; import org.dllearner.core.Component; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.LearningProblemUnsupportedException; +import org.dllearner.core.ReasonerComponent; /** * Class displaying a component (and its options). * + * @param <T> The type of the panel (KnowledgeSource, ReasonerComponent, + * LearningProblem, LearningAlgorithm). * @author Jens Lehmann * */ -public abstract class ComponentPanel<T extends Component> extends JPanel implements ActionListener { +public class ComponentPanel extends JPanel implements ActionListener { private static final long serialVersionUID = -7678275020058043937L; + private Config config; +// private StartGUI startGUI; + private List<Class<? extends Component>> selectableComponents; + private OptionPanel optionPanel; +// private Class<? extends Component> panelClass; + private Component currentComponent; + + // GUI elements + private JButton clearButton; + private JComboBox comboBox = new JComboBox(); + public ComponentPanel(LayoutManager layout) { super(layout); } - // called when panel is active - public abstract void panelActivated(); + ComponentPanel(final Config config, StartGUI startGUI, Class<? extends Component> panelClass, Class<? extends Component> defaultComponent) { + this(config, startGUI, panelClass, defaultComponent,null); + } + + ComponentPanel(final Config config, StartGUI startGUI, Class<? extends Component> panelClass, Class<? extends Component> defaultComponent, List<Class<? extends Component>> ignoredComponents) { + super(new BorderLayout()); + + this.config = config; +// this.startGUI = startGUI; +// this.panelClass = panelClass; + + // get all classes of the correct type + selectableComponents = new LinkedList<Class<? extends Component>>(); + if(panelClass == KnowledgeSource.class) { + selectableComponents.addAll(config.getComponentManager().getKnowledgeSources()); + } else if(panelClass == ReasonerComponent.class) { + selectableComponents.addAll(config.getComponentManager().getReasonerComponents()); + } else if(panelClass == LearningProblem.class) { + selectableComponents.addAll(config.getComponentManager().getLearningProblems()); + } else if(panelClass == LearningAlgorithm.class) { + selectableComponents.addAll(config.getComponentManager().getLearningAlgorithms()); + } + + // set default component class (move it to first position) + selectableComponents.remove(defaultComponent); + selectableComponents.add(0, defaultComponent); + + // remove ignored component classes + if(ignoredComponents != null) { + selectableComponents.removeAll(ignoredComponents); + } + + // create combo box + for (int i = 0; i < selectableComponents.size(); i++) { + comboBox.addItem(config.getComponentManager().getComponentName(selectableComponents.get(i))); + } + comboBox.addActionListener(this); + + clearButton = new JButton("Reset to Default Values"); + clearButton.addActionListener(this); + + // create upper panel + JPanel choosePanel = new JPanel(); + choosePanel.add(comboBox); +// choosePanel.add(new JLabel(" ")); + choosePanel.add(clearButton); + + // we create a new default component + currentComponent = newInstance(defaultComponent); + optionPanel = new OptionPanel(config, currentComponent); + + add(choosePanel, BorderLayout.NORTH); + add(optionPanel, BorderLayout.CENTER); + + } + + + + public void actionPerformed(ActionEvent e) { + if(e.getSource() == comboBox) { + // change component and update option panel + Class<? extends Component> c = selectableComponents.get(comboBox.getSelectedIndex()); + currentComponent = changeInstance(c); + updateOptionPanel(); + } else if (e.getSource() == clearButton) { + // clearing everything corresponds to changing to an unconfigured + // component of the same type + currentComponent = changeInstance(currentComponent.getClass()); + updateOptionPanel(); + } + } + + /** + * Updates the option panel. + */ + public void updateOptionPanel() { + optionPanel.rebuild(currentComponent); + } + + /** + * Method performing actions when panel is activated. + */ + public void panelActivated() { + // hook method, which does nothing yet + } + + // creates an instance of the specified component class + @SuppressWarnings("unchecked") + private Component newInstance(Class<? extends Component> clazz) { + Component newComponent = null; + if(KnowledgeSource.class.isAssignableFrom(clazz)) { + newComponent = config.newKnowledgeSource((Class<KnowledgeSource>) clazz); + } else if(ReasonerComponent.class.isAssignableFrom(clazz)) { + newComponent = config.newReasoner((Class<ReasonerComponent>) clazz); + } else if(LearningProblem.class.isAssignableFrom(clazz)) { + newComponent = config.newLearningProblem((Class<LearningProblem>) clazz); + } else if(LearningAlgorithm.class.isAssignableFrom(clazz)) { + try { + newComponent = config.newLearningAlgorithm((Class<LearningAlgorithm>) clazz); + } catch (LearningProblemUnsupportedException e) { + // TODO status message + e.printStackTrace(); + } + } + return newComponent; + } + + // changes current component to an instance of the specified class + @SuppressWarnings("unchecked") + private Component changeInstance(Class<? extends Component> clazz) { + Component newComponent = null; + if(KnowledgeSource.class.isAssignableFrom(clazz)) { + newComponent = config.changeKnowledgeSource((Class<KnowledgeSource>) clazz); + } else if(ReasonerComponent.class.isAssignableFrom(clazz)) { + newComponent = config.changeReasoner((Class<ReasonerComponent>) clazz); + } else if(LearningProblem.class.isAssignableFrom(clazz)) { + newComponent = config.changeLearningProblem((Class<LearningProblem>) clazz); + } else if(LearningAlgorithm.class.isAssignableFrom(clazz)) { + try { + newComponent = config.changeLearningAlgorithm((Class<LearningAlgorithm>) clazz); + } catch (LearningProblemUnsupportedException e) { + // TODO status message + e.printStackTrace(); + } + } + return newComponent; + } + } Modified: trunk/src/dl-learner/org/dllearner/gui/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-09-11 17:13:52 UTC (rev 1197) +++ trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-09-12 09:52:17 UTC (rev 1198) @@ -121,7 +121,7 @@ public KnowledgeSource getKnowledgeSource() { return source; } - + /** * Creates a knowledge source and makes it the active source. * @param clazz @@ -268,13 +268,8 @@ return la; } - public LearningAlgorithm changeLearningAlgorithm(Class<? extends LearningAlgorithm> clazz) { - try { - la = cm.learningAlgorithm(clazz, lp, rs); - } catch (LearningProblemUnsupportedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + public LearningAlgorithm changeLearningAlgorithm(Class<? extends LearningAlgorithm> clazz) throws LearningProblemUnsupportedException { + la = cm.learningAlgorithm(clazz, lp, rs); return la; } Modified: trunk/src/dl-learner/org/dllearner/gui/InitWorker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/InitWorker.java 2008-09-11 17:13:52 UTC (rev 1197) +++ trunk/src/dl-learner/org/dllearner/gui/InitWorker.java 2008-09-12 09:52:17 UTC (rev 1198) @@ -108,8 +108,8 @@ // the option panel (such that the user can see the existing // examples, classes etc.) if(component instanceof ReasonerComponent) { - gui.tab2.updateOptionPanel(); - gui.tab3.updateOptionPanel(); + gui.panels[2].updateOptionPanel(); + gui.panels[3].updateOptionPanel(); } return true; Deleted: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-09-11 17:13:52 UTC (rev 1197) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-09-12 09:52:17 UTC (rev 1198) @@ -1,141 +0,0 @@ -/** - * 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 java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.util.List; - -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JPanel; - -import org.dllearner.core.KnowledgeSource; -import org.dllearner.kb.OWLAPIOntology; -import org.dllearner.kb.OWLFile; - - -/** - * Knowledge source panel, tab 0. Choose source, change mandatory options and finally initialise - * knowledge source. - * - * @author Jens Lehmann - * @author Tilo Hielscher - */ -public class KnowledgeSourcePanel extends ComponentPanel<KnowledgeSource> { - - private static final long serialVersionUID = -7678275020058043937L; - - private Config config; -// private StartGUI startGUI; - private JButton clearButton; - private String[] kbBoxItems = {}; - private JComboBox cb = new JComboBox(kbBoxItems); - private JPanel choosePanel = new JPanel(); - private int choosenClassIndex; - private List<Class<? extends KnowledgeSource>> selectableSources; - private OptionPanel optionPanel; - - KnowledgeSourcePanel(final Config config, StartGUI startGUI) { - super(new BorderLayout()); - - this.config = config; -// this.startGUI = startGUI; - selectableSources = config.getComponentManager().getKnowledgeSources(); - // to set a default source, we move it to the beginning of the list - selectableSources.remove(OWLFile.class); - selectableSources.add(0, OWLFile.class); - // OWL API ontology is only useful programmatically (not in the GUI itself) - selectableSources.remove(OWLAPIOntology.class); - - clearButton = new JButton("Reset to Default Values"); - clearButton.addActionListener(this); - - // add to comboBox - for (int i = 0; i < selectableSources.size(); i++) { - cb.addItem(config.getComponentManager().getComponentName(selectableSources.get(i))); - } - cb.addActionListener(this); - - choosePanel.add(cb); -// choosePanel.add(new JLabel(" ")); - choosePanel.add(clearButton); - choosenClassIndex = cb.getSelectedIndex(); - - // whenever a component is selected, we immediately create an instance (non-initialised) - KnowledgeSource ks = config.newKnowledgeSource(selectableSources.get(cb.getSelectedIndex())); - optionPanel = new OptionPanel(config, ks); - - add(choosePanel, BorderLayout.NORTH); - add(optionPanel, BorderLayout.CENTER); - - choosenClassIndex = cb.getSelectedIndex(); - -// setSource(); -// updateAll(); - } - - public void actionPerformed(ActionEvent e) { - if (choosenClassIndex != cb.getSelectedIndex()) { - choosenClassIndex = cb.getSelectedIndex(); - // create a new knowledge source component - config.changeKnowledgeSource(selectableSources.get(choosenClassIndex)); - updateOptionPanel(); - } - - if (e.getSource() == clearButton) { -// config.setKnowledgeSource(config.getComponentManager().knowledgeSource( -// selectableSources.get(choosenClassIndex))); - updateOptionPanel(); - } - -// if (e.getSource() == initButton) { -// init(); -// } - -// if (e.getSource() == clearButton) { -// config.reInit(); -// } - } - - /** - * after this, you can change widgets - */ -// public void setSource() { -// -// } - - /** - * update OptionPanel with new selection - */ - public void updateOptionPanel() { - optionPanel.update(config.getKnowledgeSource()); - } - - /* (non-Javadoc) - * @see org.dllearner.gui.ComponentPanel#panelActivated() - */ - @Override - public void panelActivated() { - // TODO Auto-generated method stub - - } - -} Deleted: trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-09-11 17:13:52 UTC (rev 1197) +++ trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-09-12 09:52:17 UTC (rev 1198) @@ -1,202 +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 java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.util.List; - -import javax.swing.JComboBox; -import javax.swing.JPanel; - -import org.dllearner.algorithms.DBpediaNavigationSuggestor; -import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; -import org.dllearner.core.LearningAlgorithm; -import org.dllearner.core.LearningProblemUnsupportedException; - -/** - * LearningAlgorithmPanel, tab 3. Choose LearningAlgorithm, change Options and - * final initiate LearningAlgorithm. - * - * @author Tilo Hielscher - */ -public class LearningAlgorithmPanel extends ComponentPanel<LearningAlgorithm> { - - private static final long serialVersionUID = 8721490771860452959L; - - private Config config; -// private StartGUI startGUI; - private List<Class<? extends LearningAlgorithm>> selectableAlgorithms; - private JPanel choosePanel = new JPanel(); - private OptionPanel optionPanel; -// private JPanel initPanel = new JPanel(); -// private JButton initButton, autoInitButton; - private String[] cbItems = {}; - private JComboBox cb = new JComboBox(cbItems); - private int choosenClassIndex; - - public LearningAlgorithmPanel(Config config, StartGUI startGUI) { - super(new BorderLayout()); - - this.config = config; -// this.startGUI = startGUI; - selectableAlgorithms = config.getComponentManager().getLearningAlgorithms(); - // to set a default learning algorithm, we move it to the beginning of the list - selectableAlgorithms.remove(ExampleBasedROLComponent.class); - selectableAlgorithms.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) - selectableAlgorithms.remove(DBpediaNavigationSuggestor.class); - -// initButton = new JButton("Init LearingAlgorithm"); -// initButton.addActionListener(this); - // initPanel.add(initButton); -// initButton.setEnabled(true); -// autoInitButton = new JButton("Set"); -// autoInitButton.addActionListener(this); - - // add into comboBox - for (int i = 0; i < selectableAlgorithms.size(); i++) { - cb.addItem(config.getComponentManager().getComponentName(selectableAlgorithms.get(i))); - } - - choosePanel.add(cb); -// choosePanel.add(autoInitButton); - cb.addActionListener(this); - - LearningAlgorithm la = null; - try { - la = config.newLearningAlgorithm(selectableAlgorithms.get(cb.getSelectedIndex())); - } catch (LearningProblemUnsupportedException e) { - // TODO display message (or avoid selection at all) - e.printStackTrace(); - } - optionPanel = new OptionPanel(config, la); - - add(choosePanel, BorderLayout.PAGE_START); - add(optionPanel, BorderLayout.CENTER); -// add(initPanel, BorderLayout.PAGE_END); - - choosenClassIndex = cb.getSelectedIndex(); -// updateInitButtonColor(); - } - - public void actionPerformed(ActionEvent e) { - // read selected Class - if (choosenClassIndex != cb.getSelectedIndex()) { - choosenClassIndex = cb.getSelectedIndex(); - config.changeLearningAlgorithm(selectableAlgorithms.get(choosenClassIndex)); - updateOptionPanel(); -// config.setInitLearningAlgorithm(false); -// init(); - } - -// if (e.getSource() == autoInitButton) -// setLearningAlgorithm(); - -// if (e.getSource() == initButton) -// init(); - } - - /** - * after this, you can change widgets - */ -// public void setLearningAlgorithm() { -// if (config.getLearningProblem() != null && config.getReasoningService() != null) { -// try { -// config.setLearningAlgorithm(config.getComponentManager().learningAlgorithm( -// selectableAlgorithms.get(choosenClassIndex), config.getLearningProblem(), -// config.getReasoningService())); -// updateOptionPanel(); -// } catch (LearningProblemUnsupportedException e) { -// e.printStackTrace(); -// } -// } -// } - - /** - * after this, next tab can be used - */ - /* - public void init() { - setLearningAlgorithm(); - if (config.getLearningProblem() != null) { - try { - config.getLearningAlgorithm().init(); - } catch (ComponentInitException e) { - e.printStackTrace(); - } - config.setInitLearningAlgorithm(true); - System.out.println("init LearningAlgorithm"); - startGUI.updateTabColors(); - } - }*/ - - /** - * updateAll - */ - /* - public void updateAll() { - updateComboBox(); - updateOptionPanel(); - updateInitButtonColor(); - }*/ - - /** - * set ComboBox to selected class - */ - /* - public void updateComboBox() { - if (config.getLearningAlgorithm() != null) - for (int i = 0; i < selectableAlgorithms.size(); i++) - if (config.getLearningAlgorithm().getClass().equals( - config.getComponentManager().getLearningAlgorithms().get(i))) { - cb.setSelectedIndex(i); - } - this.choosenClassIndex = cb.getSelectedIndex(); - }*/ - - /** - * update OptionPanel with new selection - */ - public void updateOptionPanel() { - optionPanel.update(config.getLearningAlgorithm()); - } - - /** - * make init-button red if you have to click - */ - /* - public void updateInitButtonColor() { - if (!config.needsInitLearningAlgorithm()) { - initButton.setForeground(Color.RED); - } else - initButton.setForeground(Color.BLACK); - }*/ - - /* (non-Javadoc) - * @see org.dllearner.gui.ComponentPanel#panelActivated() - */ - @Override - public void panelActivated() { - // TODO Auto-generated method stub - - } -} Deleted: trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-09-11 17:13:52 UTC (rev 1197) +++ trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-09-12 09:52:17 UTC (rev 1198) @@ -1,181 +0,0 @@ -/** - * 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 java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.util.List; - -import javax.swing.JComboBox; -import javax.swing.JPanel; - -import org.dllearner.core.LearningProblem; - -/** - * Learning problem panel. - * - * @author Jens Lehmann - * @author Tilo Hielscher - */ -public class LearningProblemPanel extends ComponentPanel<LearningProblem> { - - private static final long serialVersionUID = -3819627680918930203L; - - private Config config; -// private StartGUI startGUI; - private List<Class<? extends LearningProblem>> lpClasses; - private String[] lpBoxItems = {}; - private JComboBox cb = new JComboBox(lpBoxItems); - private JPanel choosePanel = new JPanel(); - private OptionPanel optionPanel; - private JPanel initPanel = new JPanel(); -// private JButton setButton; - private int choosenClassIndex; - - LearningProblemPanel(final Config config, StartGUI startGUI) { - super(new BorderLayout()); - - this.config = config; -// this.startGUI = startGUI; - lpClasses = config.getComponentManager().getLearningProblems(); - -// setButton = new JButton("Set"); -// setButton.addActionListener(this); - choosePanel.add(cb); -// choosePanel.add(setButton); - cb.addActionListener(this); - - // add into comboBox - for (int i = 0; i < lpClasses.size(); i++) { - cb.addItem(config.getComponentManager().getComponentName(lpClasses.get(i))); - } - - // read choosen LearningProblem - choosenClassIndex = cb.getSelectedIndex(); - - LearningProblem lp = config.newLearningProblem(lpClasses.get(choosenClassIndex)); - optionPanel = new OptionPanel(config, lp); - - add(choosePanel, BorderLayout.PAGE_START); - add(optionPanel, BorderLayout.CENTER); - add(initPanel, BorderLayout.PAGE_END); - - choosenClassIndex = cb.getSelectedIndex(); - // setLearningProblem(); -// updateInitButtonColor(); - } - - public void actionPerformed(ActionEvent e) { - // read selected LearningProblemClass - if (choosenClassIndex != cb.getSelectedIndex()) { - this.choosenClassIndex = cb.getSelectedIndex(); - config.changeLearningProblem(lpClasses.get(choosenClassIndex)); - updateOptionPanel(); - } - -// if (e.getSource() == setButton) -// setLearningProblem(); - -// if (e.getSource() == initButton) -// init(); - } - - /** - * after this, you can change widgets - */ -// private void setLearningProblem() { -// if (config.needsInitReasoner()) { -// config.setLearningProblem(config.getComponentManager().learningProblem( -// lpClasses.get(choosenClassIndex), config.getReasoningService())); -// startGUI.updateTabs(); -// updateOptionPanel(); -// } -// } - - /** - * after this, next tab can be used - */ - /* - public void init() { - setLearningProblem(); - if (config.getReasoner() != null && config.getLearningProblem() != null - && config.isSetExample()) { - try { - config.getLearningProblem().init(); - config.setInitLearningProblem(true); - System.out.println("init LearningProblem"); - startGUI.updateTabColors(); - } catch (ComponentInitException e) { - e.printStackTrace(); - } - } - }*/ - - /** - * updateAll - */ - /* - public void updateAll() { - updateComboBox(); - updateOptionPanel(); -// updateInitButtonColor(); - }*/ - - /** - * set ComboBox to selected class - */ - /* - public void updateComboBox() { - if (config.getLearningProblem() != null) - for (int i = 0; i < lpClasses.size(); i++) - if (config.getLearningProblem().getClass().equals( - config.getComponentManager().getLearningProblems().get(i))) { - cb.setSelectedIndex(i); - } - this.choosenClassIndex = cb.getSelectedIndex(); - }*/ - - /** - * update OptionPanel with new selection - */ - public void updateOptionPanel() { - optionPanel.update(config.getLearningProblem()); - } - - /* (non-Javadoc) - * @see org.dllearner.gui.ComponentPanel#panelActivated() - */ - @Override - public void panelActivated() { - // TODO Auto-generated method stub - - } - - /** - * make init-button red if you have to click - */ - /* - public void updateInitButtonColor() { - if (!config.needsInitLearningProblem()) { - initButton.setForeground(Color.RED); - } else - initButton.setForeground(Color.BLACK); - }*/ -} Modified: trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-09-11 17:13:52 UTC (rev 1197) +++ trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-09-12 09:52:17 UTC (rev 1198) @@ -80,7 +80,7 @@ } /** update this OptionPanel */ - public void update(Component component) { + public void rebuild(Component component) { this.component = component; showWidgets(); } Deleted: trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-09-11 17:13:52 UTC (rev 1197) +++ trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-09-12 09:52:17 UTC (rev 1198) @@ -1,200 +0,0 @@ -/** - * 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 java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.util.List; - -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JPanel; - -import org.dllearner.core.ReasonerComponent; -import org.dllearner.reasoning.FastInstanceChecker; - -/** - * Panel for configuring reasoner. - * - * @author Tilo Hielscher - * @author Jens Lehmann - */ -public class ReasonerPanel extends ComponentPanel<ReasonerComponent> { - - private static final long serialVersionUID = -7678275020058043937L; - - private Config config; -// private StartGUI startGUI; - private List<Class<? extends ReasonerComponent>> selectableReasoners; - private JPanel choosePanel = new JPanel(); - private JPanel initPanel = new JPanel(); - private OptionPanel optionPanel; - private JButton initButton; - private String[] cbItems = {}; - private JComboBox cb = new JComboBox(cbItems); - private int choosenClassIndex; - - ReasonerPanel(final Config config, StartGUI startGUI) { - super(new BorderLayout()); - - this.config = config; -// this.startGUI = startGUI; - selectableReasoners = config.getComponentManager().getReasonerComponents(); - // to set a default reasoner, we move it to the beginning of the list - selectableReasoners.remove(FastInstanceChecker.class); - selectableReasoners.add(0, FastInstanceChecker.class); - - initButton = new JButton("Init Reasoner"); - initButton.addActionListener(this); - // initPanel.add(initButton); - initButton.setEnabled(true); -// setButton = new JButton("Set"); -// setButton.addActionListener(this); - - choosePanel.add(cb); - - // add into comboBox - for (int i = 0; i < selectableReasoners.size(); i++) { - cb.addItem(config.getComponentManager().getComponentName(selectableReasoners.get(i))); - } - - ReasonerComponent rc = config.newReasoner(selectableReasoners.get(cb.getSelectedIndex())); - optionPanel = new OptionPanel(config, rc); - -// choosePanel.add(setButton); - cb.addActionListener(this); - - add(choosePanel, BorderLayout.PAGE_START); - add(optionPanel, BorderLayout.CENTER); - add(initPanel, BorderLayout.PAGE_END); - - choosenClassIndex = cb.getSelectedIndex(); -// setReasoner(); -// updateInitButtonColor(); - } - - public void actionPerformed(ActionEvent e) { - // read selected Class - // choosenClassIndex = cb.getSelectedIndex(); - if (choosenClassIndex != cb.getSelectedIndex()) { - choosenClassIndex = cb.getSelectedIndex(); - // create a new knowledge source component - config.changeReasoner(selectableReasoners.get(choosenClassIndex)); - updateOptionPanel(); - } - -// if (e.getSource() == setButton) { -//// config.setInitReasoner(false); -// setReasoner(); -// } - -// if (e.getSource() == initButton) -// init(); - } - - /** - * after this, you can change widgets - */ -// public void setReasoner() { -// if (config.needsInitKnowledgeSource()) { -// config.setReasoner(config.getComponentManager().reasoner( -// reasoner.get(choosenClassIndex), config.getKnowledgeSource())); -// updateOptionPanel(); -//// startGUI.updateTabColors(); -//// config.setInitReasoner(false); -//// updateInitButtonColor(); -// } -// } - - /** - * after this, next tab can be used - */ - /* - public void init() { - setReasoner(); - if (config.getKnowledgeSource() != null && config.getReasoner() != null) { - try { - config.getReasoner().init(); - System.out.println("init Reasoner"); - // set ReasoningService - config.setReasoningService(config.getComponentManager().reasoningService( - config.getReasoner())); - System.out.println("init ReasoningService"); - config.setInitReasoner(true); - startGUI.updateTabColors(); - } catch (ComponentInitException e) { - e.printStackTrace(); - } - - } - }*/ - - /** - * updateAll - */ - /* - public void updateAll() { - updateComboBox(); - updateOptionPanel(); - updateInitButtonColor(); - } - */ - - /** - * set ComboBox to selected class - */ - /* - public void updateComboBox() { - if (config.getReasoner() != null) - for (int i = 0; i < selectableReasoners.size(); i++) - if (config.getReasoner().getClass().equals( - config.getComponentManager().getReasonerComponents().get(i))) { - cb.setSelectedIndex(i); - } - this.choosenClassIndex = cb.getSelectedIndex(); - }*/ - - /** - * update OptionPanel with new selection - */ - public void updateOptionPanel() { - optionPanel.update(config.getReasoner()); - } - - /* (non-Javadoc) - * @see org.dllearner.gui.ComponentPanel#panelActivated() - */ - @Override - public void panelActivated() { - // TODO Auto-generated method stub - - } - - /** - * make init-button red if you have to click - */ - /* - public void updateInitButtonColor() { - if (!config.needsInitReasoner()) { - initButton.setForeground(Color.RED); - } else - initButton.setForeground(Color.BLACK); - }*/ -} Modified: trunk/src/dl-learner/org/dllearner/gui/StartGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-09-11 17:13:52 UTC (rev 1197) +++ trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-09-12 09:52:17 UTC (rev 1198) @@ -28,6 +28,8 @@ import java.io.File; import java.io.FileWriter; import java.io.PrintWriter; +import java.util.LinkedList; +import java.util.List; import javax.swing.JFileChooser; import javax.swing.JFrame; @@ -45,6 +47,16 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; +import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; +import org.dllearner.core.Component; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.kb.OWLAPIOntology; +import org.dllearner.kb.OWLFile; +import org.dllearner.learningproblems.PosNegDefinitionLP; +import org.dllearner.reasoning.FastInstanceChecker; /** * This class builds the basic GUI elements and is used to start the DL-Learner @@ -64,11 +76,14 @@ private ConfigLoad configLoad = new ConfigLoad(config, this); private ConfigSave configSave = new ConfigSave(config, this); - protected KnowledgeSourcePanel tab0; - protected ReasonerPanel tab1; - protected LearningProblemPanel tab2; - protected LearningAlgorithmPanel tab3; - protected RunPanel tab4; + // the four component panels + protected ComponentPanel[] panels = new ComponentPanel[4]; + protected RunPanel runPanel; + +// protected KnowledgeSourcePanel tab0; +// protected ReasonerPanel tab1; +// protected LearningProblemPanel tab2; +// protected LearningAlgorithmPanel tab3; private JMenuBar menuBar = new JMenuBar(); private JMenu menuFile = new JMenu("File"); @@ -107,6 +122,23 @@ setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage( this.getClass().getResource("icon.gif"))); + // create panels + List<Class<? extends Component>> ignoredKnowledgeSources = new LinkedList<Class<? extends Component>>(); + ignoredKnowledgeSources.add(OWLAPIOntology.class); + panels[0] = new ComponentPanel(config, this, KnowledgeSource.class, OWLFile.class, ignoredKnowledgeSources); + panels[1] = new ComponentPanel(config, this, ReasonerComponent.class, FastInstanceChecker.class); + panels[2] = new ComponentPanel(config, this, LearningProblem.class, PosNegDefinitionLP.class); + panels[3] = new ComponentPanel(config, this, LearningAlgorithm.class, ExampleBasedROLComponent.class); + runPanel = new RunPanel(config, this); + + // add tabs for panels + tabPane.addTab("Knowledge Source", panels[0]); + tabPane.addTab("Reasoner", panels[1]); + tabPane.addTab("Learning Problem", panels[2]); + tabPane.addTab("Learning Algorithm", panels[3]); + tabPane.addTab("Run", runPanel); + + /* tab0 = new KnowledgeSourcePanel(config, this); tab1 = new ReasonerPanel(config, this); tab2 = new LearningProblemPanel(config, this); @@ -117,6 +149,7 @@ tabPane.addTab("Learning Problem", tab2); tabPane.addTab("Learning Algorithm", tab3); tabPane.addTab("Run", tab4); + */ setJMenuBar(menuBar); menuBar.add(menuFile); @@ -159,10 +192,10 @@ // send signals to panels switch(index) { - case 0: tab0.panelActivated(); break; - case 1: tab1.panelActivated(); break; - case 2: tab2.panelActivated(); break; - case 3: tab3.panelActivated(); break; + case 0: panels[0].panelActivated(); break; + case 1: panels[1].panelActivated(); break; + case 2: panels[2].panelActivated(); break; + case 3: panels[3].panelActivated(); break; } // new tab => ask user to fill in values This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |