From: <ton...@us...> - 2008-01-28 23:32:53
|
Revision: 445 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=445&view=rev Author: tonytacker Date: 2008-01-28 15:32:48 -0800 (Mon, 28 Jan 2008) Log Message: ----------- renamed OutputPanel to RunPanel, formated code, removed variable status Modified Paths: -------------- 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/ReasonerPanel.java trunk/src/dl-learner/org/dllearner/gui/StartGUI.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/gui/RunPanel.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/gui/OutputPanel.java Modified: trunk/src/dl-learner/org/dllearner/gui/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-01-28 22:16:24 UTC (rev 444) +++ trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-01-28 23:32:48 UTC (rev 445) @@ -21,7 +21,6 @@ */ import java.util.HashSet; -import java.util.List; import java.util.Set; import org.dllearner.core.ComponentManager; @@ -30,9 +29,7 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningService; -import org.dllearner.core.config.ConfigOption; - /** * config * @@ -43,117 +40,86 @@ */ public class Config { - private ComponentManager cm = ComponentManager.getInstance(); - private KnowledgeSource source; - private String uri; - private ReasonerComponent reasoner; - private ReasoningService rs; - private Set<String> posExampleSet = new HashSet<String>(); - private Set<String> negExampleSet = new HashSet<String>(); - private LearningProblem lp; - private LearningAlgorithm la; - - private List<ConfigOption<?>> optionLearningAlgorithm ; - - /** - * status should show witch variables are set - * status[0] ... cm - * status[1] ... KnowledgeSource - * status[2] ... URI - * status[3] ... Resoner - * status[4] ... ReasoningService - * status[5] ... ExampleSet - * status[6] ... LearningProblem - */ - protected static boolean[] status = new boolean[8]; - - protected boolean getStatus(int position) { - if (status[position]) - return true; - else - return false; - } + private ComponentManager cm = ComponentManager.getInstance(); + private KnowledgeSource source; + private String uri; + private ReasonerComponent reasoner; + private ReasoningService rs; + private Set<String> posExampleSet = new HashSet<String>(); + private Set<String> negExampleSet = new HashSet<String>(); + private LearningProblem lp; + private LearningAlgorithm la; - protected ComponentManager getComponentManager() { - return cm; - } - - protected void setComponentManager (ComponentManager input) { - cm = input; - } + protected ComponentManager getComponentManager() { + return cm; + } - protected String getURI () { - return uri; - } - - protected void setURI (String input) { - status[2] = true; - uri = input; - } - - protected ReasonerComponent getReasoner () { - return reasoner; - } + protected void setComponentManager(ComponentManager input) { + cm = input; + } - protected void setReasoner (ReasonerComponent input) { - status[3] = true; - reasoner = input; - } - - - protected ReasoningService getReasoningService () { - return rs; - } - - protected void setReasoningService (ReasoningService input) { - status[4] = true; - rs = input; - } - - protected KnowledgeSource getKnowledgeSource() { - return source; - } + protected String getURI() { + return uri; + } - protected void setKnowledgeSource(KnowledgeSource input) { - status[1] = true; - source = input; - } + protected void setURI(String input) { + uri = input; + } - protected void setPosExampleSet(Set<String> posExampleSet) { - status[5] = true; - this.posExampleSet = posExampleSet; - } - - protected Set<String> getPosExampleSet () { - return this.posExampleSet; - } - - protected void setNegExampleSet(Set<String> negExampleSet) { - status[5] = true; - this.negExampleSet = negExampleSet; - } - - protected Set<String> getNegExampleSet () { - return this.negExampleSet; - } + protected ReasonerComponent getReasoner() { + return reasoner; + } - protected void setLearningProblem (LearningProblem input) { - status[6] = true; - lp = input; - } - - protected LearningProblem getLearningProblem () { - return lp; - } - - protected void setLearningAlgorithm (LearningAlgorithm input) { - status[6] = true; - la = input; - } - - protected LearningAlgorithm getLearningAlgorithm () { - return la; - } + protected void setReasoner(ReasonerComponent input) { + reasoner = input; + } - + protected ReasoningService getReasoningService() { + return rs; + } + + protected void setReasoningService(ReasoningService input) { + rs = input; + } + + protected KnowledgeSource getKnowledgeSource() { + return source; + } + + protected void setKnowledgeSource(KnowledgeSource input) { + source = input; + } + + protected void setPosExampleSet(Set<String> posExampleSet) { + this.posExampleSet = posExampleSet; + } + + protected Set<String> getPosExampleSet() { + return this.posExampleSet; + } + + protected void setNegExampleSet(Set<String> negExampleSet) { + this.negExampleSet = negExampleSet; + } + + protected Set<String> getNegExampleSet() { + return this.negExampleSet; + } + + protected void setLearningProblem(LearningProblem input) { + lp = input; + } + + protected LearningProblem getLearningProblem() { + return lp; + } + + protected void setLearningAlgorithm(LearningAlgorithm input) { + la = input; + } + + protected LearningAlgorithm getLearningAlgorithm() { + return la; + } + } Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-28 22:16:24 UTC (rev 444) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-28 23:32:48 UTC (rev 445) @@ -34,7 +34,6 @@ import org.dllearner.core.KnowledgeSource; - /** * KnowledgeSourcePanel * @@ -42,138 +41,146 @@ * */ public class KnowledgeSourcePanel extends JPanel implements ActionListener { - - private static final long serialVersionUID = -7678275020058043937L; - - private JFileChooser fc; - private JButton openButton, initButton; - private JTextField fileDisplay; + + private static final long serialVersionUID = -7678275020058043937L; + + private JFileChooser fc; + private JButton openButton, initButton; + private JTextField fileDisplay; private String[] kbBoxItems = {}; - private JComboBox cb = new JComboBox(kbBoxItems); - private JPanel centerPanel, choosePanel, initPanel; - private Config config; - private int choosenClassIndex; - private List<Class<? extends KnowledgeSource>> sources; - private JLabel infoLabel = new JLabel("choose local file or type URL"); - - KnowledgeSourcePanel(final Config config) { - super(new BorderLayout()); - - this.config = config; - sources = config.getComponentManager().getKnowledgeSources(); - - fc = new JFileChooser(new File("examples/")); - openButton = new JButton("choose local file"); - openButton.addActionListener(this); - - initButton = new JButton("Init KnowledgeSource"); - initButton.addActionListener(this); - - fileDisplay = new JTextField(35); - fileDisplay.setEditable(true); - - // update config if textfield fileDisplay changed - fileDisplay.getDocument().addDocumentListener(new DocumentListener() { - public void insertUpdate(DocumentEvent e) { - config.setURI(fileDisplay.getText()); - } - public void removeUpdate(DocumentEvent e) { - config.setURI(fileDisplay.getText()); - } - public void changedUpdate(DocumentEvent e) { - config.setURI(fileDisplay.getText()); - } - }); - - // add to comboBox - for (int i=0; i<sources.size(); i++) { - // cb.addItem(sources.get(i).getSimpleName()); - cb.addItem(config.getComponentManager().getComponentName(sources.get(i))); - } - - cb.addActionListener(this); - - choosePanel = new JPanel(); - choosePanel.add(cb); + private JComboBox cb = new JComboBox(kbBoxItems); + private JPanel centerPanel, choosePanel, initPanel; + private Config config; + private int choosenClassIndex; + private List<Class<? extends KnowledgeSource>> sources; + private JLabel infoLabel = new JLabel("choose local file or type URL"); - initPanel = new JPanel(); - initPanel.add(initButton); + KnowledgeSourcePanel(final Config config) { + super(new BorderLayout()); - centerPanel = new JPanel(); - - // define GridBag - GridBagLayout gridbag = new GridBagLayout(); - centerPanel.setLayout(gridbag); - GridBagConstraints constraints = new GridBagConstraints(); - constraints.fill = GridBagConstraints.BOTH; - constraints.anchor = GridBagConstraints.CENTER; + this.config = config; + sources = config.getComponentManager().getKnowledgeSources(); - buildConstraints(constraints, 0, 0, 1, 1, 100, 100); - gridbag.setConstraints(infoLabel, constraints); - centerPanel.add(infoLabel); + fc = new JFileChooser(new File("examples/")); + openButton = new JButton("choose local file"); + openButton.addActionListener(this); - buildConstraints(constraints, 0, 1, 1, 1, 100, 100); - gridbag.setConstraints(fileDisplay, constraints); - centerPanel.add(fileDisplay); - - buildConstraints(constraints, 1, 1, 1, 1, 100, 100); - gridbag.setConstraints(openButton, constraints); - centerPanel.add(openButton); - - add(choosePanel, BorderLayout.PAGE_START); - add(centerPanel, BorderLayout.CENTER); - add(initPanel, BorderLayout.PAGE_END); - - choosenClassIndex = cb.getSelectedIndex(); + initButton = new JButton("Init KnowledgeSource"); + initButton.addActionListener(this); + + fileDisplay = new JTextField(35); + fileDisplay.setEditable(true); + + // update config if textfield fileDisplay changed + fileDisplay.getDocument().addDocumentListener(new DocumentListener() { + public void insertUpdate(DocumentEvent e) { + config.setURI(fileDisplay.getText()); + } + + public void removeUpdate(DocumentEvent e) { + config.setURI(fileDisplay.getText()); + } + + public void changedUpdate(DocumentEvent e) { + config.setURI(fileDisplay.getText()); + } + }); + + // add to comboBox + for (int i = 0; i < sources.size(); i++) { + // cb.addItem(sources.get(i).getSimpleName()); + cb.addItem(config.getComponentManager().getComponentName( + sources.get(i))); } - - public void actionPerformed(ActionEvent e) { - // read selected KnowledgeSourceClass - choosenClassIndex = cb.getSelectedIndex(); - checkIfSparql(); - - // open File - if (e.getSource() == openButton) { - int returnVal = fc.showOpenDialog(KnowledgeSourcePanel.this); - if (returnVal == JFileChooser.APPROVE_OPTION) { - String URI = "file://"; - URI = URI.concat(fc.getSelectedFile().toString()); // make "file://" before local URI - config.setURI(URI); //save variable - fileDisplay.setText(URI); - } - return; + + cb.addActionListener(this); + + choosePanel = new JPanel(); + choosePanel.add(cb); + + initPanel = new JPanel(); + initPanel.add(initButton); + + centerPanel = new JPanel(); + + // define GridBag + GridBagLayout gridbag = new GridBagLayout(); + centerPanel.setLayout(gridbag); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.fill = GridBagConstraints.BOTH; + constraints.anchor = GridBagConstraints.CENTER; + + buildConstraints(constraints, 0, 0, 1, 1, 100, 100); + gridbag.setConstraints(infoLabel, constraints); + centerPanel.add(infoLabel); + + buildConstraints(constraints, 0, 1, 1, 1, 100, 100); + gridbag.setConstraints(fileDisplay, constraints); + centerPanel.add(fileDisplay); + + buildConstraints(constraints, 1, 1, 1, 1, 100, 100); + gridbag.setConstraints(openButton, constraints); + centerPanel.add(openButton); + + add(choosePanel, BorderLayout.PAGE_START); + add(centerPanel, BorderLayout.CENTER); + add(initPanel, BorderLayout.PAGE_END); + + choosenClassIndex = cb.getSelectedIndex(); + } + + public void actionPerformed(ActionEvent e) { + // read selected KnowledgeSourceClass + choosenClassIndex = cb.getSelectedIndex(); + checkIfSparql(); + + // open File + if (e.getSource() == openButton) { + int returnVal = fc.showOpenDialog(KnowledgeSourcePanel.this); + if (returnVal == JFileChooser.APPROVE_OPTION) { + String URI = "file://"; + // make "file://" before local URI + URI = URI.concat(fc.getSelectedFile().toString()); + config.setURI(URI); // save variable + fileDisplay.setText(URI); } - - // init - if (e.getSource() == initButton && config.getStatus(2)) { - config.setKnowledgeSource(config.getComponentManager().knowledgeSource(sources.get(choosenClassIndex))); - config.getComponentManager().applyConfigEntry(config.getKnowledgeSource(), "url", config.getURI()); - config.getKnowledgeSource().init(); - System.out.println("init KnowledgeSource with \n" + sources.get(choosenClassIndex) + " and \n" + config.getURI() + "\n"); - } + return; } - - /* - * Define GridBagConstraints - */ - private void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy) { - gbc.gridx = gx; - gbc.gridy = gy; - gbc.gridwidth = gw; - gbc.gridheight = gh; - gbc.weightx = wx; - gbc.weighty = wy; + + // init + if (e.getSource() == initButton && config.getURI() != null) { + config.setKnowledgeSource(config.getComponentManager() + .knowledgeSource(sources.get(choosenClassIndex))); + config.getComponentManager().applyConfigEntry( + config.getKnowledgeSource(), "url", config.getURI()); + config.getKnowledgeSource().init(); + System.out.println("init KnowledgeSource with \n" + + sources.get(choosenClassIndex) + " and \n" + + config.getURI() + "\n"); } - - private void checkIfSparql() { - if (sources.get(choosenClassIndex).toString().contains("Sparql")) { - openButton.setEnabled(false); - infoLabel.setText("type URL"); - } - else { - openButton.setEnabled(true); - infoLabel.setText("choose local file or type URL"); - } + } + + /* + * Define GridBagConstraints + */ + private void buildConstraints(GridBagConstraints gbc, int gx, int gy, + int gw, int gh, int wx, int wy) { + gbc.gridx = gx; + gbc.gridy = gy; + gbc.gridwidth = gw; + gbc.gridheight = gh; + gbc.weightx = wx; + gbc.weighty = wy; + } + + private void checkIfSparql() { + if (sources.get(choosenClassIndex).toString().contains("Sparql")) { + openButton.setEnabled(false); + infoLabel.setText("type URL"); + } else { + openButton.setEnabled(true); + infoLabel.setText("choose local file or type URL"); } - + } + } Modified: trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-01-28 22:16:24 UTC (rev 444) +++ trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-01-28 23:32:48 UTC (rev 445) @@ -35,72 +35,69 @@ * */ public class LearningAlgorithmPanel extends JPanel implements ActionListener { - - private static final long serialVersionUID = 8721490771860452959L; + + private static final long serialVersionUID = 8721490771860452959L; private Config config; private List<Class<? extends LearningAlgorithm>> learners; - private JPanel choosePanel = new JPanel(); - private OptionPanel optionPanel; - private JPanel initPanel = new JPanel(); + private JPanel choosePanel = new JPanel(); + private OptionPanel optionPanel; + private JPanel initPanel = new JPanel(); private JButton initButton; private String[] cbItems = {}; - private JComboBox cb = new JComboBox(cbItems); - private int choosenClassIndex; + private JComboBox cb = new JComboBox(cbItems); + private int choosenClassIndex; - - LearningAlgorithmPanel(Config config) { - super(new BorderLayout()); + LearningAlgorithmPanel(Config config) { + super(new BorderLayout()); - this.config = config; - - initButton = new JButton("Init LearingAlgorithm"); - initButton.addActionListener(this); - - initPanel.add(initButton); + this.config = config; - choosePanel.add(cb); - - // add into comboBox - learners = config.getComponentManager().getLearningAlgorithms(); - for (int i=0; i<learners.size(); i++) { - cb.addItem(config.getComponentManager().getComponentName(learners.get(i))); - } - - cb.addActionListener(this); - - optionPanel = new OptionPanel(config, config.getLearningAlgorithm(), learners.get(choosenClassIndex)); - updateOptionPanel(); + initButton = new JButton("Init LearingAlgorithm"); + initButton.addActionListener(this); - - add(choosePanel, BorderLayout.PAGE_START); - add(initPanel, BorderLayout.CENTER); - add(optionPanel, BorderLayout.PAGE_END); - - } - + initPanel.add(initButton); - public void actionPerformed(ActionEvent e) { - // read selected Class - choosenClassIndex = cb.getSelectedIndex(); + choosePanel.add(cb); - updateOptionPanel(); - - // init - if (e.getSource() == initButton) { - if (config.getStatus(6)) { - config.setLearningAlgorithm(config.getComponentManager().learningAlgorithm(learners.get(choosenClassIndex), config.getLearningProblem(), config.getReasoningService())); - updateOptionPanel(); - config.getLearningAlgorithm().init(); - } - if (config.getStatus(5)) { // examples are set - System.out.println("LearningAlgorithm: " + config.getLearningAlgorithm() + "\n"); - } - } + // add into comboBox + learners = config.getComponentManager().getLearningAlgorithms(); + for (int i = 0; i < learners.size(); i++) { + cb.addItem(config.getComponentManager().getComponentName( + learners.get(i))); } - public void updateOptionPanel() { - // update OptionPanel - optionPanel.setComponent(config.getLearningAlgorithm()); - optionPanel.setComponentOption(learners.get(choosenClassIndex)); + cb.addActionListener(this); + + optionPanel = new OptionPanel(config, config.getLearningAlgorithm(), + learners.get(choosenClassIndex)); + updateOptionPanel(); + + add(choosePanel, BorderLayout.PAGE_START); + add(initPanel, BorderLayout.CENTER); + add(optionPanel, BorderLayout.PAGE_END); + + } + + public void actionPerformed(ActionEvent e) { + // read selected Class + choosenClassIndex = cb.getSelectedIndex(); + + updateOptionPanel(); + + // init + if (e.getSource() == initButton && config.getLearningProblem() != null) { + config.setLearningAlgorithm(config.getComponentManager() + .learningAlgorithm(learners.get(choosenClassIndex), + config.getLearningProblem(), + config.getReasoningService())); + updateOptionPanel(); + config.getLearningAlgorithm().init(); } + } + + public void updateOptionPanel() { + // update OptionPanel + optionPanel.setComponent(config.getLearningAlgorithm()); + optionPanel.setComponentOption(learners.get(choosenClassIndex)); + } } Modified: trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-01-28 22:16:24 UTC (rev 444) +++ trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-01-28 23:32:48 UTC (rev 445) @@ -42,170 +42,175 @@ * LearningProblemPanel * * @author Tilo Hielscher - * */ - public class LearningProblemPanel extends JPanel implements ActionListener { - - private static final long serialVersionUID = -3819627680918930203L; - private List<Class<? extends LearningProblem>> problems; + private static final long serialVersionUID = -3819627680918930203L; + + private List<Class<? extends LearningProblem>> problems; private String[] lpBoxItems = {}; - private JComboBox cb = new JComboBox(lpBoxItems); - private JPanel choosePanel = new JPanel(); - private JPanel centerPanel = new JPanel(); - private JPanel lpPanel = new JPanel(); - private JLabel posLabel = new JLabel("positive Examples"); - private JLabel negLabel = new JLabel("negative Examples"); + private JComboBox cb = new JComboBox(lpBoxItems); + private JPanel choosePanel = new JPanel(); + private JPanel centerPanel = new JPanel(); + private JPanel lpPanel = new JPanel(); + private JLabel posLabel = new JLabel("positive Examples"); + private JLabel negLabel = new JLabel("negative Examples"); private JButton initButton, readListButton; - private int choosenClassIndex; + private int choosenClassIndex; private List<Individual> individuals; private JList posList = new JList(); private JList negList = new JList(); - + private Config config; - - LearningProblemPanel(final Config config) { - super(new BorderLayout()); - this.config = config; - - initButton = new JButton("Init LearningProblem"); - initButton.addActionListener(this); - - readListButton = new JButton("Read List"); - readListButton.addActionListener(this); - - choosePanel.add(cb); - choosePanel.add(readListButton); - lpPanel.add(initButton); - add(choosePanel, BorderLayout.PAGE_START); - add(centerPanel, BorderLayout.CENTER); - add(lpPanel, BorderLayout.PAGE_END); - - problems = config.getComponentManager().getLearningProblems(); - - // add into comboBox - for (int i=0; i<problems.size(); i++) { - //cb.addItem(problems.get(i).getSimpleName()); - cb.addItem(config.getComponentManager().getComponentName(problems.get(i))); - } - - // read choosen LearningProblem - choosenClassIndex = cb.getSelectedIndex(); - - // create a scrollable list of positive examples - posList = new JList(); - posList.setLayoutOrientation(JList.VERTICAL); - posList.setVisibleRowCount(-1); - JScrollPane posListScroller = new JScrollPane(posList); - posListScroller.setPreferredSize(new Dimension(300, 200)); - - // create a scrollable list of negative examples - negList = new JList(); - negList.setLayoutOrientation(JList.VERTICAL); - negList.setVisibleRowCount(-1); - JScrollPane negListScroller = new JScrollPane(negList); - negListScroller.setPreferredSize(new Dimension(300, 200)); - - // define GridBag - GridBagLayout gridbag = new GridBagLayout(); - centerPanel.setLayout(gridbag); - GridBagConstraints constraints = new GridBagConstraints(); - constraints.fill = GridBagConstraints.BOTH; - constraints.anchor = GridBagConstraints.CENTER; + LearningProblemPanel(final Config config) { + super(new BorderLayout()); - buildConstraints(constraints, 0, 0, 1, 1, 100, 100); - gridbag.setConstraints(posLabel, constraints); - centerPanel.add(posLabel); + this.config = config; - buildConstraints(constraints, 1, 0, 1, 1, 100, 100); - gridbag.setConstraints(negLabel, constraints); - centerPanel.add(negLabel); + initButton = new JButton("Init LearningProblem"); + initButton.addActionListener(this); - buildConstraints(constraints, 0, 1, 1, 1, 100, 100); - gridbag.setConstraints(posListScroller, constraints); - centerPanel.add(posListScroller); - - buildConstraints(constraints, 1, 1, 1, 1, 100, 100); - gridbag.setConstraints(negListScroller, constraints); - centerPanel.add(negListScroller); + readListButton = new JButton("Read List"); + readListButton.addActionListener(this); - add(centerPanel, BorderLayout.CENTER); - - // listener for posList - posList.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(ListSelectionEvent evt) { - if (evt.getValueIsAdjusting()) - return; - // detect witch examples have been selected - Set<String> posExampleSet = new HashSet<String>(); - int[] selectedIndices = posList.getSelectedIndices(); - for(int i : selectedIndices) - posExampleSet.add(individuals.get(i).toString()); - config.setPosExampleSet(posExampleSet); - System.out.println("posList: " + config.getPosExampleSet() ); - } - }); - - // listener for negList - negList.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(ListSelectionEvent evt) { - if (evt.getValueIsAdjusting()) - return; - // detect witch examples have been selected - Set<String> negExampleSet = new HashSet<String>(); - int[] selectedIndices = negList.getSelectedIndices(); - for(int i : selectedIndices) - negExampleSet.add(individuals.get(i).toString()); - config.setNegExampleSet(negExampleSet); - System.out.println("negList: " + config.getNegExampleSet() ); - } - }); + choosePanel.add(cb); + choosePanel.add(readListButton); + lpPanel.add(initButton); + add(choosePanel, BorderLayout.PAGE_START); + add(centerPanel, BorderLayout.CENTER); + add(lpPanel, BorderLayout.PAGE_END); + + problems = config.getComponentManager().getLearningProblems(); + + // add into comboBox + for (int i = 0; i < problems.size(); i++) { + // cb.addItem(problems.get(i).getSimpleName()); + cb.addItem(config.getComponentManager().getComponentName( + problems.get(i))); } - - public void actionPerformed(ActionEvent e) { - // read selected LearningProblemClass - choosenClassIndex = cb.getSelectedIndex(); - - // get list after reasoner init - if (e.getSource() == readListButton) { - // fill lists - if (config.getStatus(4)) { // only with a reasoner - Set<Individual> individualsSet = config.getReasoningService().getIndividuals(); - individuals = new LinkedList<Individual>(individualsSet); - DefaultListModel listModel = new DefaultListModel(); - for(Individual ind : individuals) { - listModel.addElement(ind); - } - posList.setModel(listModel); - negList.setModel(listModel); - } - } - - //init - if (e.getSource() == initButton) { - if (config.getStatus(5)) { - config.setLearningProblem(config.getComponentManager().learningProblem(problems.get(choosenClassIndex), config.getReasoningService())); - config.getComponentManager().applyConfigEntry(config.getLearningProblem(), "positiveExamples", config.getPosExampleSet()); - config.getComponentManager().applyConfigEntry(config.getLearningProblem(), "negativeExamples", config.getNegExampleSet()); - config.getLearningProblem().init(); - System.out.println("init LearningProblem with \n" + problems.get(choosenClassIndex) + "\nand " + "\nposExample: " - + config.getPosExampleSet() + "\nand negExample: " + config.getNegExampleSet()); - } - } + + // read choosen LearningProblem + choosenClassIndex = cb.getSelectedIndex(); + + // create a scrollable list of positive examples + posList = new JList(); + posList.setLayoutOrientation(JList.VERTICAL); + posList.setVisibleRowCount(-1); + JScrollPane posListScroller = new JScrollPane(posList); + posListScroller.setPreferredSize(new Dimension(300, 200)); + + // create a scrollable list of negative examples + negList = new JList(); + negList.setLayoutOrientation(JList.VERTICAL); + negList.setVisibleRowCount(-1); + JScrollPane negListScroller = new JScrollPane(negList); + negListScroller.setPreferredSize(new Dimension(300, 200)); + + // define GridBag + GridBagLayout gridbag = new GridBagLayout(); + centerPanel.setLayout(gridbag); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.fill = GridBagConstraints.BOTH; + constraints.anchor = GridBagConstraints.CENTER; + + buildConstraints(constraints, 0, 0, 1, 1, 100, 100); + gridbag.setConstraints(posLabel, constraints); + centerPanel.add(posLabel); + + buildConstraints(constraints, 1, 0, 1, 1, 100, 100); + gridbag.setConstraints(negLabel, constraints); + centerPanel.add(negLabel); + + buildConstraints(constraints, 0, 1, 1, 1, 100, 100); + gridbag.setConstraints(posListScroller, constraints); + centerPanel.add(posListScroller); + + buildConstraints(constraints, 1, 1, 1, 1, 100, 100); + gridbag.setConstraints(negListScroller, constraints); + centerPanel.add(negListScroller); + + add(centerPanel, BorderLayout.CENTER); + + // listener for posList + posList.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent evt) { + if (evt.getValueIsAdjusting()) + return; + // detect witch examples have been selected + Set<String> posExampleSet = new HashSet<String>(); + int[] selectedIndices = posList.getSelectedIndices(); + for (int i : selectedIndices) + posExampleSet.add(individuals.get(i).toString()); + config.setPosExampleSet(posExampleSet); + } + }); + + // listener for negList + negList.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent evt) { + if (evt.getValueIsAdjusting()) + return; + // detect witch examples have been selected + Set<String> negExampleSet = new HashSet<String>(); + int[] selectedIndices = negList.getSelectedIndices(); + for (int i : selectedIndices) + negExampleSet.add(individuals.get(i).toString()); + config.setNegExampleSet(negExampleSet); + } + }); + } + + public void actionPerformed(ActionEvent e) { + // read selected LearningProblemClass + choosenClassIndex = cb.getSelectedIndex(); + + // get list after reasoner init + if (e.getSource() == readListButton + && config.getReasoningService() != null) { + // fill lists + Set<Individual> individualsSet = config.getReasoningService() + .getIndividuals(); + individuals = new LinkedList<Individual>(individualsSet); + DefaultListModel listModel = new DefaultListModel(); + for (Individual ind : individuals) { + listModel.addElement(ind); + } + posList.setModel(listModel); + negList.setModel(listModel); } - - /* - * Define GridBagConstraints - */ - private void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy) { - gbc.gridx = gx; - gbc.gridy = gy; - gbc.gridwidth = gw; - gbc.gridheight = gh; - gbc.weightx = wx; - gbc.weighty = wy; + + // init + if (e.getSource() == initButton + && config.getReasoningService() != null + && (config.getPosExampleSet().size() > 0 || config + .getNegExampleSet().size() > 0)) { + config.setLearningProblem(config.getComponentManager() + .learningProblem(problems.get(choosenClassIndex), + config.getReasoningService())); + config.getComponentManager().applyConfigEntry( + config.getLearningProblem(), "positiveExamples", + config.getPosExampleSet()); + config.getComponentManager().applyConfigEntry( + config.getLearningProblem(), "negativeExamples", + config.getNegExampleSet()); + config.getLearningProblem().init(); + System.out.println("init LearningProblem"); } - + + } + + /* + * Define GridBagConstraints + */ + private void buildConstraints(GridBagConstraints gbc, int gx, int gy, + int gw, int gh, int wx, int wy) { + gbc.gridx = gx; + gbc.gridy = gy; + gbc.gridwidth = gw; + gbc.gridheight = gh; + gbc.weightx = wx; + gbc.weighty = wy; + } + } Deleted: trunk/src/dl-learner/org/dllearner/gui/OutputPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/OutputPanel.java 2008-01-28 22:16:24 UTC (rev 444) +++ trunk/src/dl-learner/org/dllearner/gui/OutputPanel.java 2008-01-28 23:32:48 UTC (rev 445) @@ -1,100 +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.awt.event.ActionListener; - -import javax.swing.*; - -import org.dllearner.core.dl.Concept; - -/** - * OutputPanel - * - * @author Tilo Hielscher - * - */ -public class OutputPanel extends JPanel implements ActionListener { - - private static final long serialVersionUID = 1643304576470046636L; - - private JButton showButton; - private JButton runButton; - private JTextArea infoArea; - private Config config; - - OutputPanel(Config config) { - super(new BorderLayout()); - - this.config = config; - - showButton = new JButton("Show Variables"); - showButton.addActionListener(this); - - runButton = new JButton("Run"); - runButton.addActionListener(this); - - infoArea = new JTextArea(20, 50); - JScrollPane infoScroll = new JScrollPane(infoArea); - - JPanel showPanel = new JPanel(); - showPanel.add(showButton); - showPanel.add(runButton); - JPanel infoPanel = new JPanel(); - infoPanel.add(infoScroll); - - add(showPanel, BorderLayout.PAGE_START); - add(infoPanel, BorderLayout.CENTER); - } - - public void actionPerformed(ActionEvent e) { - if (e.getSource() == showButton) { - infoArea.setText(""); - if (config.getStatus(1)) { // kb is set - infoArea.append("SourceClass: " + config.getKnowledgeSource().toString() + "\n"); - } - if (config.getStatus(2)) { // file is set - infoArea.append("URI: " + config.getURI() + "\n"); - } - if (config.getStatus(3)) { // Reasoner is set - infoArea.append("Reasoner: " + config.getReasoner() + "\n"); - } - if (config.getStatus(4)) { // ReasoningServic is set - infoArea.append("ReasoningService: " + config.getReasoningService() + "\n"); - } - if (false) { - for (int i = 0; i<8; i++) { // show status-vars - infoArea.append("i: " + config.getStatus(i) + "\n"); - } - } - } - - if (e.getSource() == runButton) { - if (config.getStatus(6)) { - config.getLearningAlgorithm().start(); - Concept solution = config.getLearningAlgorithm().getBestSolution(); - infoArea.setText(solution.toString()); - } - } - } -} Modified: trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-01-28 22:16:24 UTC (rev 444) +++ trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-01-28 23:32:48 UTC (rev 445) @@ -29,7 +29,6 @@ import org.dllearner.core.ReasonerComponent; - /** * ReasonerPanel * @@ -37,60 +36,56 @@ * */ public class ReasonerPanel extends JPanel implements ActionListener { - - private static final long serialVersionUID = -7678275020058043937L; - private List<Class<? extends ReasonerComponent>> reasoners; - private JPanel choosePanel = new JPanel(); - private JPanel initPanel = new JPanel(); + private static final long serialVersionUID = -7678275020058043937L; + + private List<Class<? extends ReasonerComponent>> reasoners; + private JPanel choosePanel = new JPanel(); + private JPanel initPanel = new JPanel(); private JButton initButton; private Config config; private String[] cbItems = {}; - private JComboBox cb = new JComboBox(cbItems); - private int choosenClassIndex; - - ReasonerPanel(final Config config) { - super(new BorderLayout()); - - this.config = config; - - initButton = new JButton("Init Reasoner"); - initButton.addActionListener(this); - initPanel.add(initButton); - - choosePanel.add(cb); - - add(choosePanel, BorderLayout.PAGE_START); - add(initPanel, BorderLayout.PAGE_END); - - // add into comboBox - reasoners = config.getComponentManager().getReasonerComponents(); - for (int i=0; i<reasoners.size(); i++) { - //cb.addItem(reasoners.get(i).getSimpleName()); - cb.addItem(config.getComponentManager().getComponentName(reasoners.get(i))); - } + private JComboBox cb = new JComboBox(cbItems); + private int choosenClassIndex; + ReasonerPanel(final Config config) { + super(new BorderLayout()); + + this.config = config; + + initButton = new JButton("Init Reasoner"); + initButton.addActionListener(this); + initPanel.add(initButton); + + choosePanel.add(cb); + + add(choosePanel, BorderLayout.PAGE_START); + add(initPanel, BorderLayout.PAGE_END); + + // add into comboBox + reasoners = config.getComponentManager().getReasonerComponents(); + for (int i = 0; i < reasoners.size(); i++) { + // cb.addItem(reasoners.get(i).getSimpleName()); + cb.addItem(config.getComponentManager().getComponentName( + reasoners.get(i))); } - - public void actionPerformed(ActionEvent e) { - // read selected Class - choosenClassIndex = cb.getSelectedIndex(); - - if (e.getSource() == initButton) { - if (config.getStatus(2)) { // no check if button initKnowledgeSource was pressed - // set reasoner - config.setReasoner(config.getComponentManager().reasoner(reasoners.get(choosenClassIndex), config.getKnowledgeSource())); - config.getReasoner().init(); - - // set ReasoningService - config.setReasoningService(config.getComponentManager().reasoningService(config.getReasoner())); - } - if (config.getStatus(3)) { // Reasoner is set - System.out.println("Reasoner: " + config.getReasoner()); - } - if (config.getStatus(4)) { // ReasoningServic is set - System.out.println("ReasoningService: " + config.getReasoningService()); - } - } + + } + + public void actionPerformed(ActionEvent e) { + // read selected Class + choosenClassIndex = cb.getSelectedIndex(); + + if (e.getSource() == initButton && config.getKnowledgeSource() != null) { + // set reasoner + config.setReasoner(config.getComponentManager().reasoner( + reasoners.get(choosenClassIndex), + config.getKnowledgeSource())); + config.getReasoner().init(); + + // set ReasoningService + config.setReasoningService(config.getComponentManager() + .reasoningService(config.getReasoner())); } + } } Added: trunk/src/dl-learner/org/dllearner/gui/RunPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/RunPanel.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-01-28 23:32:48 UTC (rev 445) @@ -0,0 +1,72 @@ +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.awt.event.ActionListener; + +import javax.swing.*; + +import org.dllearner.core.dl.Concept; + +/** + * OutputPanel + * + * @author Tilo Hielscher + * + */ +public class RunPanel extends JPanel implements ActionListener { + + private static final long serialVersionUID = 1643304576470046636L; + + private JButton runButton; + private JTextArea infoArea; + private Config config; + + RunPanel(Config config) { + super(new BorderLayout()); + + this.config = config; + + runButton = new JButton("Run"); + runButton.addActionListener(this); + + infoArea = new JTextArea(20, 50); + JScrollPane infoScroll = new JScrollPane(infoArea); + + JPanel showPanel = new JPanel(); + showPanel.add(runButton); + JPanel infoPanel = new JPanel(); + infoPanel.add(infoScroll); + + add(showPanel, BorderLayout.PAGE_START); + add(infoPanel, BorderLayout.CENTER); + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource() == runButton && config.getLearningAlgorithm() != null) { + config.getLearningAlgorithm().start(); + Concept solution = config.getLearningAlgorithm().getBestSolution(); + infoArea.setText(solution.toString()); + } + } +} Modified: trunk/src/dl-learner/org/dllearner/gui/StartGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-01-28 22:16:24 UTC (rev 444) +++ trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-01-28 23:32:48 UTC (rev 445) @@ -35,52 +35,51 @@ */ public class StartGUI extends JFrame { - - private static final long serialVersionUID = -739265982906533775L; - - public JTabbedPane tabPane = new JTabbedPane(); - - private JPanel tab1 = new JPanel(); - private JPanel tab2 = new JPanel(); - private JPanel tab3 = new JPanel(); - private JPanel tab4 = new JPanel(); - private JPanel tab5 = new JPanel(); - public StartGUI() { - Config config = new Config(); - this.setTitle("DL-Learner GUI"); - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - this.setLocationByPlatform(true); - this.setSize(800, 600); - tab1.add(new KnowledgeSourcePanel(config)); - tab2.add(new ReasonerPanel(config)); - tab3.add(new LearningProblemPanel(config)); - tab4.add(new LearningAlgorithmPanel(config)); - tab5.add(new OutputPanel(config)); - tabPane.addTab("Knowledge Source", tab1); - tabPane.addTab("Reasoner", tab2); - tabPane.addTab("Learning Problem", tab3); - tabPane.addTab("Learning Algorithm", tab4); - tabPane.addTab("Output", tab5); - this.add(tabPane); - this.setVisible(true); - } - - public static void main(String[] args) { - // create GUI logger - SimpleLayout layout = new SimpleLayout(); - ConsoleAppender consoleAppender = new ConsoleAppender(layout); - Logger logger = Logger.getRootLogger(); - logger.removeAllAppenders(); - logger.addAppender(consoleAppender); - logger.setLevel(Level.INFO); - - new StartGUI(); - } - - protected void renew() { - tabPane.repaint(); - } + private static final long serialVersionUID = -739265982906533775L; + public JTabbedPane tabPane = new JTabbedPane(); + private JPanel tab1 = new JPanel(); + private JPanel tab2 = new JPanel(); + private JPanel tab3 = new JPanel(); + private JPanel tab4 = new JPanel(); + private JPanel tab5 = new JPanel(); + + public StartGUI() { + Config config = new Config(); + this.setTitle("DL-Learner GUI"); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.setLocationByPlatform(true); + this.setSize(800, 600); + tab1.add(new KnowledgeSourcePanel(config)); + tab2.add(new ReasonerPanel(config)); + tab3.add(new LearningProblemPanel(config)); + tab4.add(new LearningAlgorithmPanel(config)); + tab5.add(new RunPanel(config)); + tabPane.addTab("Knowledge Source", tab1); + tabPane.addTab("Reasoner", tab2); + tabPane.addTab("Learning Problem", tab3); + tabPane.addTab("Learning Algorithm", tab4); + tabPane.addTab("Run", tab5); + this.add(tabPane); + this.setVisible(true); + } + + public static void main(String[] args) { + // create GUI logger + SimpleLayout layout = new SimpleLayout(); + ConsoleAppender consoleAppender = new ConsoleAppender(layout); + Logger logger = Logger.getRootLogger(); + logger.removeAllAppenders(); + logger.addAppender(consoleAppender); + logger.setLevel(Level.INFO); + + new StartGUI(); + } + + protected void renew() { + tabPane.repaint(); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |