From: <ton...@us...> - 2008-01-26 01:41:05
|
Revision: 427 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=427&view=rev Author: tonytacker Date: 2008-01-25 17:40:55 -0800 (Fri, 25 Jan 2008) Log Message: ----------- commit for me: panel to set IntegerConfigOption works, but not safe 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/WidgetPanelInteger.java Modified: trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-01-24 12:52:57 UTC (rev 426) +++ trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-01-26 01:40:55 UTC (rev 427) @@ -47,7 +47,7 @@ private Config config; private List<Class<? extends LearningAlgorithm>> learners; private JPanel choosePanel = new JPanel(); - private OptionPanel centerPanel; + private OptionPanel optionPanel; private JPanel initPanel = new JPanel(); private JButton initButton; private String[] cbItems = {}; @@ -77,26 +77,27 @@ } cb.addActionListener(this); + + optionPanel = new OptionPanel(config, config.getLearningAlgorithm(), learners.get(choosenClassIndex)); + updateOptionPanel(); + - centerPanel = new OptionPanel(config, learners.get(choosenClassIndex)); - add(choosePanel, BorderLayout.PAGE_START); - add(centerPanel, BorderLayout.CENTER); + add(optionPanel, BorderLayout.CENTER); add(initPanel, BorderLayout.PAGE_END); - } public void actionPerformed(ActionEvent e) { // read selected Class choosenClassIndex = cb.getSelectedIndex(); - - // update OptionPanel - centerPanel.setClass(learners.get(choosenClassIndex)); - + + updateOptionPanel(); + // init if (e.getSource() == initButton) { if (config.getStatus(6)) { + updateOptionPanel(); config.setLearningAlgorithm(config.getComponentManager().learningAlgorithm(learners.get(choosenClassIndex), config.getLearningProblem(), config.getReasoningService())); config.getLearningAlgorithm().init(); } @@ -106,4 +107,9 @@ } } + public void updateOptionPanel() { + // update OptionPanel + optionPanel.setComponent(config.getLearningAlgorithm()); + optionPanel.setComponentOption(learners.get(choosenClassIndex)); + } } Modified: trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-01-24 12:52:57 UTC (rev 426) +++ trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-01-26 01:40:55 UTC (rev 427) @@ -32,8 +32,7 @@ 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.*; /** * OptionPanel @@ -45,20 +44,23 @@ private static final long serialVersionUID = -3053205578443575240L; private Config config; - private Class<? extends Component> componentClass; + private Class<? extends Component> componentOption; private List<ConfigOption<?>> optionList; private JButton tableButton; private JButton normalButton; + private JButton readOptionsButton; private DefaultTableModel optionModel = new DefaultTableModel(); private JTable optionTable = new JTable(optionModel); private JPanel startPanel = new JPanel(); private JPanel centerPanel = new JPanel(); + private Component component; - public OptionPanel(Config config, Class<? extends Component> componentClass) { + public OptionPanel(Config config, Component component, Class<? extends Component> componentOption) { super(new BorderLayout()); this.config = config; - this.componentClass = componentClass; + this.component = component; + this.componentOption = componentOption; tableButton = new JButton("show options as table"); tableButton.addActionListener(this); @@ -66,10 +68,14 @@ normalButton = new JButton("show normal"); normalButton.addActionListener(this); - optionList = ComponentManager.getConfigOptions(componentClass); + readOptionsButton = new JButton("read set option"); + readOptionsButton.addActionListener(this); + + optionList = ComponentManager.getConfigOptions(componentOption); startPanel.add(tableButton); startPanel.add(normalButton); + startPanel.add(readOptionsButton); add(startPanel, BorderLayout.PAGE_START); add(centerPanel, BorderLayout.CENTER); @@ -87,17 +93,11 @@ public void actionPerformed(ActionEvent e) { // show as table if (e.getSource() == tableButton) { - optionList = ComponentManager.getConfigOptions(componentClass); + optionList = ComponentManager.getConfigOptions(componentOption); // clear centerPanel.removeAll(); -/* - System.out.println("name: " + optionList.get(i).getName()); // name - System.out.println("default value: " + optionList.get(i).getDefaultValue()); // default value - System.out.println("class: " + optionList.get(i).getClass()); // class - System.out.println("description: " + optionList.get(i).getDescription()); // description - System.out.println("allowed value description: " + optionList.get(i).getAllowedValuesDescription()); // allowed value description -*/ + // clear JTable for (int i=optionModel.getRowCount()-1; i>0; i--) { // from last to first optionModel.removeRow(i); @@ -113,35 +113,32 @@ } // show normal if (e.getSource() == normalButton) { - optionList = ComponentManager.getConfigOptions(componentClass); // get class for options -/* for (int i=0; i<optionList.size(); i++) { - System.out.println("option: " + optionList.get(i)); - } -*/ + optionList = ComponentManager.getConfigOptions(componentOption); // get class for options + // clear centerPanel.removeAll(); - //get a WidgetPanel TEST - WidgetPanelInteger firstPanel = new WidgetPanelInteger(config, optionList.get(0)); + //get a WidgetPanel Example + // optionList is the list of possible options for componentOption + // each option can be type of IntegerConfigOption, StringConfigOption and so on + WidgetPanelInteger firstPanel = new WidgetPanelInteger(config, component, componentOption, optionList.get(0)); centerPanel.add(firstPanel); - //ConfigEntry(ConfigOption<T> option, T value); - - - - // PROBLEM - //ConfigEntry testEntry = new ConfigEntry(optionList.get(0), (int)10); - - - - + // update graphic centerPanel.updateUI(); - - } + // read set options + if (e.getSource() == readOptionsButton) { + System.out.println("setOptions: " + config.getComponentManager().getConfigOption(componentOption, optionList.get(0).getName())); + } } - - public void setClass (Class<? extends Component> componentClass) { - this.componentClass = componentClass; + + public void setComponent (Component component) { + this.component = component; } + + public void setComponentOption (Class<? extends Component> componentOption) { + this.componentOption = componentOption; + } + } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java 2008-01-24 12:52:57 UTC (rev 426) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java 2008-01-26 01:40:55 UTC (rev 427) @@ -24,18 +24,18 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.Color; -//import java.util.List; import javax.swing.JTextField; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JButton; -//import javax.swing.JTable; -//import javax.swing.table.DefaultTableModel; - - +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; /** @@ -48,17 +48,22 @@ private static final long serialVersionUID = -1802111225835164644L; - //private Config config; + private Config config; private ConfigOption<?> configOption; private JLabel nameLabel; private JPanel centerPanel = new JPanel(); private JButton setButton = new JButton("Set"); - - - public WidgetPanelInteger(Config config, ConfigOption<?> configOption) { - //this.config = config; + 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; + System.out.println("1st: " + component); + // default nameLabel = new JLabel(configOption.getName()); setButton.addActionListener(this); @@ -91,9 +96,30 @@ public void actionPerformed(ActionEvent e) { if (e.getSource() == setButton) { - int number = 10; - System.out.println(number); - System.out.println(configOption); + // INTEGER + Integer value = 10; + IntegerConfigOption specialOption; + String name = configOption.getName(); + //Component component = config.getLearningAlgorithm(); + System.out.println("name: " + name + " & value: " + value); + specialOption = (IntegerConfigOption) config.getComponentManager().getConfigOption(componentOption, name); + try { + ConfigEntry<Integer> specialEntry = new ConfigEntry<Integer>(specialOption, value); + System.out.println("TEST specialEntry: " + specialEntry); + System.out.println("TEST component: " + component); + config.getComponentManager().applyConfigEntry(component, specialEntry); + } + catch (InvalidConfigOptionValueException s) { + s.printStackTrace(); + } } } + + public void setComponent (Component component) { + this.component = component; + } + + public void setComponentOption (Class<? extends Component> componentOption) { + this.componentOption = componentOption; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |