From: <ton...@us...> - 2008-02-11 14:19:03
|
Revision: 536 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=536&view=rev Author: tonytacker Date: 2008-02-11 06:18:59 -0800 (Mon, 11 Feb 2008) Log Message: ----------- widget stringset with special for positive/negative examples Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java trunk/src/dl-learner/org/dllearner/gui/RunPanel.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/gui/CheckBoxList.java Added: trunk/src/dl-learner/org/dllearner/gui/CheckBoxList.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/CheckBoxList.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/CheckBoxList.java 2008-02-11 14:18:59 UTC (rev 536) @@ -0,0 +1,101 @@ +/** + * 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.*; + +import java.awt.BorderLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Set; + +/** + * CheckBoxList + * + * a list of CheckBoxes + * + * @author Tilo Hielscher + */ +public class CheckBoxList extends JPanel { + private static final long serialVersionUID = -7119007550662195455L; + private JPanel checkBoxPanel = new JPanel(); + private LinkedList<JCheckBox> list = new LinkedList<JCheckBox>(); + private GridBagLayout gridbag = new GridBagLayout(); + private GridBagConstraints constraints = new GridBagConstraints(); + private Set<String> selectionSet = new HashSet<String>(); + + /** + * get a JPanel + */ + public CheckBoxList() { + checkBoxPanel.setLayout(gridbag); + add(checkBoxPanel, BorderLayout.CENTER); + constraints.anchor = GridBagConstraints.WEST; + } + + /** + * add new entry + * + * @param label + */ + public void add(String label) { + list.add(new JCheckBox(label)); + update(); + } + + /** + * return a set of selected items + */ + public Set<String> getSelections() { + selectionSet.clear(); // remove all + for (int i = 0; i < list.size(); i++) { + if (list.get(i).isSelected()) + this.selectionSet.add(list.get(i).getText()); + } + return this.selectionSet; + } + + /** + * update JCheckBox's + */ + private void update() { + checkBoxPanel.removeAll(); + for (int i = 0; i < list.size(); i++) { + buildConstraints(constraints, 0, i, 1, 1, 100, 100); + gridbag.setConstraints(list.get(i), constraints); + checkBoxPanel.add(list.get(i), constraints); + } + } + + /** + * 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; + } +} \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-02-10 17:52:40 UTC (rev 535) +++ trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-02-11 14:18:59 UTC (rev 536) @@ -183,7 +183,7 @@ } public void actionPerformed(ActionEvent e) { - System.out.println("index: " + cb.getSelectedIndex()); + //System.out.println("index: " + cb.getSelectedIndex()); // read selected LearningProblemClass // choosenClassIndex = cb.getSelectedIndex(); @@ -191,7 +191,7 @@ this.choosenClassIndex = cb.getSelectedIndex(); config.setInitLearningProblem(false); setLearningProblem(); - System.out.println("new_index: " + cb.getSelectedIndex()); + //System.out.println("new_index: " + cb.getSelectedIndex()); } Modified: trunk/src/dl-learner/org/dllearner/gui/RunPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-02-10 17:52:40 UTC (rev 535) +++ trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-02-11 14:18:59 UTC (rev 536) @@ -44,6 +44,11 @@ private ThreadRun thread; + private JPanel showPanel = new JPanel(); + private JPanel infoPanel = new JPanel(); + private JPanel testPanel = new JPanel(); + + RunPanel(Config config) { super(new BorderLayout()); @@ -59,16 +64,15 @@ infoArea = new JTextArea(20, 50); JScrollPane infoScroll = new JScrollPane(infoArea); - JPanel showPanel = new JPanel(); showPanel.add(runButton); showPanel.add(stopButton); showPanel.add(testButton); - JPanel infoPanel = new JPanel(); infoPanel.add(infoScroll); add(showPanel, BorderLayout.PAGE_START); add(infoPanel, BorderLayout.CENTER); + add(testPanel, BorderLayout.PAGE_END); } public void actionPerformed(ActionEvent e) { @@ -85,9 +89,7 @@ // config.getLearningAlgorithm().stop(); thread.exit(); } - if (e.getSource() == testButton - && config.getLearningAlgorithm() != null) { - config.getLearningAlgorithm().stop(); + if (e.getSource() == testButton) { } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java 2008-02-10 17:52:40 UTC (rev 535) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java 2008-02-11 14:18:59 UTC (rev 536) @@ -42,6 +42,7 @@ import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.StringSetConfigOption; import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.core.dl.Individual; /** * WidgetPanelStringSet @@ -72,6 +73,9 @@ private JList stringList = new JList(); private DefaultListModel listModel = new DefaultListModel(); + private JButton setButton = new JButton("set"); + private CheckBoxList cBL = new CheckBoxList(); + public WidgetPanelStringSet(Config config, Component component, Class<? extends Component> componentOption, ConfigOption<?> configOption) { @@ -85,46 +89,54 @@ add(widgetPanel, BorderLayout.CENTER); showLabel(); // name of option and tooltip showThingToChange(); // textfield, setbutton - stringList.setModel(listModel); - + // ActionListeners addButton.addActionListener(this); removeButton.addActionListener(this); clearButton.addActionListener(this); + setButton.addActionListener(this); } - public JPanel getPanel() { - return this; - } - public void actionPerformed(ActionEvent e) { - Set<String> exampleSet = new HashSet<String>(); - // add to list - if (e.getSource() == addButton - && !listModel.contains(stringField.getText())) { - listModel.addElement(stringField.getText()); + if (!isSpecial()) { + // NORMAL LAYOUT + Set<String> exampleSet = new HashSet<String>(); + // add to list + if (e.getSource() == addButton + && !listModel.contains(stringField.getText())) { + listModel.addElement(stringField.getText()); + } + // remove selection + if (e.getSource() == removeButton) { + int[] selectedIndices = stringList.getSelectedIndices(); + int count = 0; // remove i.e. index 2 and 4: after delete 2, 4 + // is + // now index 3 + for (int i : selectedIndices) + listModel.remove(i - count++); + } + // clear list + if (e.getSource() == clearButton) { + listModel.clear(); + } + // update + // stringList.setModel(listModel); + for (int i = 0; i < listModel.size(); i++) { + if (!listModel.get(i).toString().equalsIgnoreCase("")) + exampleSet.add(listModel.get(i).toString()); + } + // set entry + value = exampleSet; + setEntry(); + } else { + // SPECIAL LAYOUT + // setButton + if (e.getSource() == setButton) { + value = cBL.getSelections(); + setEntry(); + } } - // remove selection - if (e.getSource() == removeButton) { - int[] selectedIndices = stringList.getSelectedIndices(); - int count = 0; // remove i.e. index 2 and 4: after delete 2, 4 is - // now index 3 - for (int i : selectedIndices) - listModel.remove(i - count++); - } - // clear list - if (e.getSource() == clearButton) { - listModel.clear(); - } - // update - // stringList.setModel(listModel); - for (int i = 0; i < listModel.size(); i++) { - if (!listModel.get(i).toString().equalsIgnoreCase("")) - exampleSet.add(listModel.get(i).toString()); - } - // set entry - value = exampleSet; - setEntry(); + } @Override @@ -150,6 +162,7 @@ value = (Set<String>) config.getComponentManager() .getConfigOptionValue(component, configOption.getName()); + // fill list if (value != null) { for (Iterator<String> iterator = value.iterator(); iterator @@ -159,35 +172,59 @@ } } } - buildConstraints(constraints, 0, 1, 1, 1, 100, 100); - gridbag.setConstraints(stringField, constraints); - widgetPanel.add(stringField, constraints); - - buildConstraints(constraints, 1, 1, 1, 1, 100, 100); - gridbag.setConstraints(addButton, constraints); - widgetPanel.add(addButton, constraints); - - // list - stringList.setModel(listModel); - stringList.setLayoutOrientation(JList.VERTICAL); - stringList.setVisibleRowCount(-1); - JScrollPane stringListScroller = new JScrollPane(stringList); - stringListScroller.setPreferredSize(new Dimension(280, 100)); - - buildConstraints(constraints, 0, 2, 1, 2, 100, 100); - gridbag.setConstraints(stringListScroller, constraints); - widgetPanel.add(stringListScroller, constraints); - - buildConstraints(constraints, 1, 2, 1, 1, 100, 100); - gridbag.setConstraints(removeButton, constraints); - widgetPanel.add(removeButton, constraints); - - buildConstraints(constraints, 1, 3, 1, 1, 100, 100); - gridbag.setConstraints(clearButton, constraints); - widgetPanel.add(clearButton, constraints); - - // widgetPanel.add(setButton); - // setButton.addActionListener(this); + if (!isSpecial()) { + // NORMAL LAYOUT + // stringField + buildConstraints(constraints, 0, 1, 1, 1, 100, 100); + gridbag.setConstraints(stringField, constraints); + widgetPanel.add(stringField, constraints); + // addButton + buildConstraints(constraints, 1, 1, 1, 1, 100, 100); + gridbag.setConstraints(addButton, constraints); + widgetPanel.add(addButton, constraints); + // list + stringList.setModel(listModel); + stringList.setLayoutOrientation(JList.VERTICAL); + stringList.setVisibleRowCount(-1); + JScrollPane stringListScroller = new JScrollPane(stringList); + stringListScroller + .setPreferredSize(new Dimension(280, 100)); + buildConstraints(constraints, 0, 2, 1, 2, 100, 100); + gridbag.setConstraints(stringListScroller, constraints); + widgetPanel.add(stringListScroller, constraints); + // removeButton + buildConstraints(constraints, 1, 2, 1, 1, 100, 100); + gridbag.setConstraints(removeButton, constraints); + widgetPanel.add(removeButton, constraints); + // clearButton + buildConstraints(constraints, 1, 3, 1, 1, 100, 100); + gridbag.setConstraints(clearButton, constraints); + widgetPanel.add(clearButton, constraints); + } else { + // SPECIAL LAYOUT + // ComboBoxList + buildConstraints(constraints, 0, 1, 1, 1, 100, 100); + gridbag.setConstraints(cBL, constraints); + widgetPanel.add(cBL, constraints); + // setButton + buildConstraints(constraints, 1, 1, 1, 1, 100, 100); + gridbag.setConstraints(setButton, constraints); + widgetPanel.add(setButton, constraints); + // DEFINE LIST + // positiveExamples or negativeExamples + if (configOption.getName().equalsIgnoreCase( + "positiveExamples") + || configOption.getName().equalsIgnoreCase( + "negativeExamples")) { + // fill lists + Set<Individual> individualsSet = config + .getReasoningService().getIndividuals(); + LinkedList<Individual> individuals = new LinkedList<Individual>( + individualsSet); + for (Individual ind : individuals) + cBL.add(ind.getName()); + } + } } // UNKNOWN else { @@ -237,4 +274,15 @@ gbc.weighty = wy; } + /** + * special layout returns true if 2nd layout should used + */ + private boolean isSpecial() { + if (configOption.getName().equalsIgnoreCase("positiveExamples") + || configOption.getName().equalsIgnoreCase("negativeExamples")) + return true; + else + return false; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |