From: <ton...@us...> - 2008-01-29 03:12:07
|
Revision: 446 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=446&view=rev Author: tonytacker Date: 2008-01-28 19:12:04 -0800 (Mon, 28 Jan 2008) Log Message: ----------- add AbstractWidgetPanel for all WidgetPanels to set options, add tooltip on each widgetlabel, add WidgetPanelBoolean, removed a small bug Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.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/WidgetPanelDefault.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/gui/AbstractWidgetPanel.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/gui/Startgui$1.class trunk/src/dl-learner/org/dllearner/gui/Startgui.class Added: trunk/src/dl-learner/org/dllearner/gui/AbstractWidgetPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/AbstractWidgetPanel.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/AbstractWidgetPanel.java 2008-01-29 03:12:04 UTC (rev 446) @@ -0,0 +1,49 @@ +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; + +/** + * AbstractWidgetPanel + * + * @author Tilo Hielscher + * + */ +public abstract class AbstractWidgetPanel extends JPanel { + + + /* + * show label and tooltip + */ + protected abstract void showLabel(); + + /* + * show textfield, setbutton and so on + */ + protected abstract void showThingToChange(); + + /* + * set entry you got from showThingToChange() + */ + protected abstract void setEntry(); + +} Modified: trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-01-28 23:32:48 UTC (rev 445) +++ trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-01-29 03:12:04 UTC (rev 446) @@ -81,9 +81,7 @@ public void actionPerformed(ActionEvent e) { // read selected Class choosenClassIndex = cb.getSelectedIndex(); - updateOptionPanel(); - // init if (e.getSource() == initButton && config.getLearningProblem() != null) { config.setLearningAlgorithm(config.getComponentManager() @@ -91,6 +89,7 @@ config.getLearningProblem(), config.getReasoningService())); updateOptionPanel(); + System.out.println("init LearningAlgorithm"); config.getLearningAlgorithm().init(); } } Modified: trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-01-28 23:32:48 UTC (rev 445) +++ trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-01-29 03:12:04 UTC (rev 446) @@ -42,85 +42,95 @@ */ public class OptionPanel extends JPanel { - private static final long serialVersionUID = -3053205578443575240L; - private Config config; - private Class<? extends Component> componentOption; - private List<ConfigOption<?>> optionList; - private JPanel centerPanel = new JPanel(); - private Component component; - private GridBagLayout gridBagLayout = new GridBagLayout(); - private GridBagConstraints constraints = new GridBagConstraints(); + private static final long serialVersionUID = -3053205578443575240L; + private Config config; + private Class<? extends Component> componentOption; + private List<ConfigOption<?>> optionList; + private JPanel centerPanel = new JPanel(); + private Component component; + private GridBagLayout gridBagLayout = new GridBagLayout(); + private GridBagConstraints constraints = new GridBagConstraints(); - public OptionPanel(Config config, Component component, Class<? extends Component> componentOption) { - super(new BorderLayout()); - - this.config = config; - this.component = component; - this.componentOption = componentOption; - - optionList = ComponentManager.getConfigOptions(componentOption); - - // define GridBagLayout - centerPanel.setLayout(gridBagLayout); - constraints.anchor = GridBagConstraints.NORTHWEST; + public OptionPanel(Config config, Component component, + Class<? extends Component> componentOption) { + super(new BorderLayout()); - // add scrollPane - JScrollPane centerScroller = new JScrollPane(centerPanel); - centerScroller.setPreferredSize(new Dimension(400, 200)); - - // add Panels - add(centerScroller, BorderLayout.CENTER); - - showWidgets(); + this.config = config; + this.component = component; + this.componentOption = componentOption; - System.out.println("AAA: " + ComponentManager.getConfigOptions(componentOption)); + optionList = ComponentManager.getConfigOptions(componentOption); + // define GridBagLayout + centerPanel.setLayout(gridBagLayout); + constraints.anchor = GridBagConstraints.NORTHWEST; + + // add scrollPane + JScrollPane centerScroller = new JScrollPane(centerPanel); + centerScroller.setPreferredSize(new Dimension(400, 200)); + + // add Panels + add(centerScroller, BorderLayout.CENTER); + + showWidgets(); + + System.out.println("AAA: " + + ComponentManager.getConfigOptions(componentOption)); + + } + + public void setComponent(Component component) { + this.component = component; + showWidgets(); + } + + public void setComponentOption(Class<? extends Component> componentOption) { + this.componentOption = componentOption; + showWidgets(); + } + + /* + * define here what core.config.class is what type of widget + * WidgetPanelDefault is for none defined classes + */ + private void showWidgets() { + JPanel widgetPanel; + optionList = ComponentManager.getConfigOptions(componentOption); // get + // class + // for + // options + centerPanel.removeAll(); // clear panel + 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, + componentOption, optionList.get(i)); + } else if (optionList.get(i).getClass().toString().contains( + "BooleanConfigOption")) { + widgetPanel = new WidgetPanelBoolean(config, component, + componentOption, optionList.get(i)); + } else { + widgetPanel = new WidgetPanelDefault(config, component, + componentOption, optionList.get(i)); + } + gridBagLayout.setConstraints(widgetPanel, constraints); + centerPanel.add(widgetPanel); } - - public void setComponent (Component component) { - this.component = component; - showWidgets(); - } - - public void setComponentOption (Class<? extends Component> componentOption) { - this.componentOption = componentOption; - showWidgets(); - } - - /* - * define here what core.config.class is what type of widget - * WidgetPanelDefault is for none defined classes - */ - private void showWidgets() { - JPanel widgetPanel; - optionList = ComponentManager.getConfigOptions(componentOption); // get class for options - centerPanel.removeAll(); // clear panel - 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, componentOption, optionList.get(i)); - } - else if (false) { - } - else { - widgetPanel = new WidgetPanelDefault(config, component, componentOption, optionList.get(i)); - } - gridBagLayout.setConstraints(widgetPanel, constraints); - centerPanel.add(widgetPanel); - } - centerPanel.updateUI(); // update graphic - } - - /* - * 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; - } - + centerPanel.updateUI(); // update graphic + } + + /* + * 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; + } + } Modified: trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-01-28 23:32:48 UTC (rev 445) +++ trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-01-29 03:12:04 UTC (rev 446) @@ -86,6 +86,8 @@ // set ReasoningService config.setReasoningService(config.getComponentManager() .reasoningService(config.getReasoner())); + + System.out.println("init Reasoner"); } } } Deleted: trunk/src/dl-learner/org/dllearner/gui/Startgui$1.class =================================================================== (Binary files differ) Deleted: trunk/src/dl-learner/org/dllearner/gui/Startgui.class =================================================================== (Binary files differ) Added: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java 2008-01-29 03:12:04 UTC (rev 446) @@ -0,0 +1,145 @@ +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 java.awt.Color; + +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JButton; + +import org.dllearner.core.Component; // import +// org.dllearner.core.ComponentManager; +import org.dllearner.core.config.ConfigEntry; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.BooleanConfigOption; +import org.dllearner.core.config.InvalidConfigOptionValueException; + +/** + * WidgetPanelInteger + * + * @author Tilo Hielscher + * + */ +public class WidgetPanelBoolean extends AbstractWidgetPanel implements + ActionListener { + + private static final long serialVersionUID = -4800583253223939928L; + private Config config; + private ConfigOption<?> configOption; + private JLabel nameLabel; + private JPanel widgetPanel = new JPanel(); + private JButton setButton = new JButton("Set"); + private Component component; + private Class<? extends Component> componentOption; + + private Boolean value; + private String[] kbBoxItems = { "true", "false" }; + private JComboBox cb = new JComboBox(kbBoxItems); + + public WidgetPanelBoolean(Config config, Component component, + Class<? extends Component> componentOption, + ConfigOption<?> configOption) { + this.config = config; + this.configOption = configOption; + this.component = component; + this.componentOption = componentOption; + + showLabel(); // name of option and tooltip + showThingToChange(); // textfield, setbutton + add(widgetPanel, BorderLayout.CENTER); + } + + public JPanel getPanel() { + return this; + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource() == setButton) { + setEntry(); + } + } + + protected void showLabel() { + nameLabel = new JLabel(configOption.getName()); + nameLabel.setToolTipText(configOption.getDescription()); + widgetPanel.add(nameLabel); + } + + protected void showThingToChange() { + if (component != null) { + // IntegerConfigOption + if (configOption.getClass().toString().contains( + "BooleanConfigOption")) { + // default value + if (configOption.getDefaultValue() != null) { + value = (Boolean) configOption.getDefaultValue(); + } + // then false + else { + value = false; + } + // cb.setText(value.toString()); + if (value == false) + cb.setSelectedIndex(0); + else + cb.setSelectedIndex(1); + setButton.addActionListener(this); + widgetPanel.add(cb); + widgetPanel.add(setButton); + } + // 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 at moment (Boolean)"); + noConfigOptionLabel.setForeground(Color.RED); + widgetPanel.add(noConfigOptionLabel); + } + } + + protected void setEntry() { + BooleanConfigOption specialOption; + if (cb.getSelectedIndex() == 0) + value = true; + else + value = false; + specialOption = (BooleanConfigOption) config.getComponentManager() + .getConfigOption(componentOption, configOption.getName()); + 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(); + } + } +} Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDefault.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDefault.java 2008-01-28 23:32:48 UTC (rev 445) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDefault.java 2008-01-29 03:12:04 UTC (rev 446) @@ -29,33 +29,47 @@ import org.dllearner.core.Component; import org.dllearner.core.config.ConfigOption; - /** * WidgetPanelDefault * * @author Tilo Hielscher * */ -public class WidgetPanelDefault extends JPanel { +public class WidgetPanelDefault extends AbstractWidgetPanel { - private static final long serialVersionUID = 4059515858894036769L; - private JLabel nameLabel; - private JPanel centerPanel = new JPanel(); - - public WidgetPanelDefault(Config config, Component component, Class<? extends Component> componentOption, ConfigOption<?> configOption) { - - // default - nameLabel = new JLabel(configOption.getName()); + private static final long serialVersionUID = 4059515858894036769L; - // text - nameLabel = new JLabel(configOption.getName()); - JLabel notImplementedLabel = new JLabel(configOption.getClass().getSimpleName() + " not implemented"); - notImplementedLabel.setForeground(Color.RED); - centerPanel.add(nameLabel); - centerPanel.add(notImplementedLabel); - - // default - add(centerPanel, BorderLayout.CENTER); - } - + 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); + } + + protected void showLabel() { + nameLabel = new JLabel(configOption.getName()); + nameLabel.setToolTipText(configOption.getDescription()); + widgetPanel.add(nameLabel); + } + + protected void showThingToChange() { + JLabel notImplementedLabel = new JLabel(configOption.getClass() + .getSimpleName() + + " not implemented"); + notImplementedLabel.setForeground(Color.RED); + + widgetPanel.add(notImplementedLabel); + } + + protected void setEntry() { + } + } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java 2008-01-28 23:32:48 UTC (rev 445) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java 2008-01-29 03:12:04 UTC (rev 446) @@ -30,126 +30,109 @@ import javax.swing.JPanel; import javax.swing.JButton; -import org.dllearner.core.Component; -//import org.dllearner.core.ComponentManager; +import org.dllearner.core.Component; // import +// org.dllearner.core.ComponentManager; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerConfigOption; import org.dllearner.core.config.InvalidConfigOptionValueException; - /** * WidgetPanelInteger * * @author Tilo Hielscher * */ -public class WidgetPanelInteger extends JPanel implements ActionListener { +public class WidgetPanelInteger extends AbstractWidgetPanel implements + ActionListener { - private static final long serialVersionUID = -1802111225835164644L; + private static final long serialVersionUID = -1802111225835164644L; - private Config config; - private ConfigOption<?> configOption; - private JLabel nameLabel; - private JPanel centerPanel = new JPanel(); - private JButton setButton = new JButton("Set"); - private Component component; - private Class<? extends Component> componentOption; - - private Integer value; - private JTextField integerField = new JTextField(3); + private Config config; + private ConfigOption<?> configOption; + private JLabel nameLabel; + private JPanel widgetPanel = new JPanel(); + private JButton setButton = new JButton("Set"); + private Component component; + private Class<? extends Component> componentOption; - - public WidgetPanelInteger(Config config, Component component, Class<? extends Component> componentOption, ConfigOption<?> configOption) { - this.config = config; - this.configOption = configOption; - this.component = component; - this.componentOption = componentOption; - - showLabel(); // name of option and tooltip - showThingToChange(); // textfield, setbutton - add(centerPanel, BorderLayout.CENTER); + private Integer value; + private JTextField integerField = new JTextField(3); + + public WidgetPanelInteger(Config config, Component component, + Class<? extends Component> componentOption, + ConfigOption<?> configOption) { + this.config = config; + this.configOption = configOption; + this.component = component; + this.componentOption = componentOption; + + showLabel(); // name of option and tooltip + showThingToChange(); // textfield, setbutton + add(widgetPanel, BorderLayout.CENTER); + } + + public JPanel getPanel() { + return this; + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource() == setButton) { + setEntry(); } - - public JPanel getPanel() { - return this; - } - - public void actionPerformed(ActionEvent e) { - if (e.getSource() == setButton) { - setEntry(); - } - } - - private void showLabel() { - nameLabel = new JLabel(configOption.getName()); - centerPanel.add(nameLabel); - } - - - private void showThingToChange () { - if (component != null) { - System.out.println("show set Integer config.getComponentManager().getConfigOptionValue(component, name): " + config.getComponentManager().getConfigOptionValue(component, configOption.getName())); + } - // IntegerConfigOption - if (configOption.getClass().toString().contains("IntegerConfigOption")) { - // seted value - if (config.getComponentManager().getConfigOptionValue(component, configOption.getName()) != null) { - value = (Integer) config.getComponentManager().getConfigOptionValue(component, configOption.getName()); - System.out.println("value readed: " + value); - } - // default value - else if (configOption.getDefaultValue() != null) { - System.out.println("default value null"); - value = (Integer) configOption.getDefaultValue(); - } - // then 0 - else { - value = 0; - System.out.println("default value not null"); - } - System.out.println("value: " + value); - integerField.setText(value.toString()); - System.out.println("configOption.getDefaultValue(): " + configOption.getDefaultValue()); - setButton.addActionListener(this); - centerPanel.add(integerField); - centerPanel.add(setButton); - } - // UNKNOWN - else { - nameLabel = new JLabel(configOption.getName()); - JLabel notImplementedLabel = new JLabel("not an integer"); - notImplementedLabel.setForeground(Color.RED); - centerPanel.add(nameLabel); - centerPanel.add(notImplementedLabel); - } + protected void showLabel() { + nameLabel = new JLabel(configOption.getName()); + nameLabel.setToolTipText(configOption.getDescription()); + widgetPanel.add(nameLabel); + } + + protected void showThingToChange() { + if (component != null) { + // IntegerConfigOption + if (configOption.getClass().toString().contains( + "IntegerConfigOption")) { + // default value + if (configOption.getDefaultValue() != null) { + value = (Integer) configOption.getDefaultValue(); } - else { // configOption == NULL - JLabel noConfigOptionLabel = new JLabel("no init at moment"); - noConfigOptionLabel.setForeground(Color.RED); - centerPanel.add(noConfigOptionLabel); + // then 0 + else { + value = 0; } + integerField.setText(value.toString()); + 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 init at moment (Integer)"); + noConfigOptionLabel.setForeground(Color.RED); + widgetPanel.add(noConfigOptionLabel); } - - private void setEntry() { - // INTEGER - IntegerConfigOption specialOption; - value = Integer.parseInt(integerField.getText()); - System.out.println("set Integer: " + configOption.getName() + " = " + value); - specialOption = (IntegerConfigOption) config.getComponentManager().getConfigOption(componentOption, configOption.getName()); - try { - ConfigEntry<Integer> specialEntry = new ConfigEntry<Integer>(specialOption, value); - //System.out.println("set Integer specialEntry: " + specialEntry); - System.out.println("set Integer component: " + component); - //System.out.println("set Integer componentOption: " + componentOption); - //System.out.println("set Integer config.getComponentManager().getConfigOptionValue(component, name): " + config.getComponentManager().getConfigOptionValue(component, name)); - config.getComponentManager().applyConfigEntry(component, specialEntry); - // update this - System.out.println("set Integer config.getComponentManager().getConfigOptionValue(component, name): " + config.getComponentManager().getConfigOptionValue(component, configOption.getName())); - System.out.println("seted value: " + this.value); - } - catch (InvalidConfigOptionValueException s) { - s.printStackTrace(); - } + } + + protected void setEntry() { + IntegerConfigOption specialOption; + value = Integer.parseInt(integerField.getText()); // get from input + specialOption = (IntegerConfigOption) config.getComponentManager() + .getConfigOption(componentOption, configOption.getName()); + try { + ConfigEntry<Integer> specialEntry = new ConfigEntry<Integer>( + specialOption, value); + config.getComponentManager().applyConfigEntry(component, + specialEntry); + System.out.println("set Integer: " + configOption.getName() + " = " + + value); + } catch (InvalidConfigOptionValueException s) { + s.printStackTrace(); } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |