From: <ton...@us...> - 2008-01-28 02:38:42
|
Revision: 430 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=430&view=rev Author: tonytacker Date: 2008-01-27 18:38:38 -0800 (Sun, 27 Jan 2008) Log Message: ----------- WidgetPanelInteger works, but you have init it twice (its a small bug), after you can then set integers Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDefault.java Modified: trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-01-26 19:25:33 UTC (rev 429) +++ trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-01-28 02:38:38 UTC (rev 430) @@ -21,14 +21,14 @@ */ import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; + import java.util.List; -import javax.swing.JButton; import javax.swing.JPanel; -import javax.swing.JTable; -import javax.swing.table.DefaultTableModel; +import javax.swing.JScrollPane; import org.dllearner.core.Component; import org.dllearner.core.ComponentManager; @@ -40,20 +40,16 @@ * @author Tilo Hielscher * */ -public class OptionPanel extends JPanel implements ActionListener { +public class OptionPanel extends JPanel { private static final long serialVersionUID = -3053205578443575240L; private Config config; 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; + private GridBagLayout gridBagLayout = new GridBagLayout(); + private GridBagConstraints constraints = new GridBagConstraints(); public OptionPanel(Config config, Component component, Class<? extends Component> componentOption) { super(new BorderLayout()); @@ -62,83 +58,66 @@ this.component = component; this.componentOption = componentOption; - tableButton = new JButton("show options as table"); - tableButton.addActionListener(this); - - normalButton = new JButton("show normal"); - normalButton.addActionListener(this); - - 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); + // define GridBagLayout + centerPanel.setLayout(gridBagLayout); + constraints.anchor = GridBagConstraints.NORTHWEST; - // set JTable - optionModel.addColumn("name"); - optionModel.addColumn("default"); - optionModel.addColumn("class"); - optionModel.addRow(new Object[] {"name","default","class"}); // header - optionTable.setSize(400, 400); - optionTable.updateUI(); + // add scrollPane + JScrollPane centerScroller = new JScrollPane(centerPanel); + centerScroller.setPreferredSize(new Dimension(400, 200)); + // add Panels + add(centerScroller, BorderLayout.CENTER); + + showWidgets(); } - public void actionPerformed(ActionEvent e) { - // show as table - if (e.getSource() == tableButton) { - optionList = ComponentManager.getConfigOptions(componentOption); - - // clear - centerPanel.removeAll(); - - // clear JTable - for (int i=optionModel.getRowCount()-1; i>0; i--) { // from last to first - optionModel.removeRow(i); - } - // new JTable - for (int i=0; i<optionList.size(); i++) { - optionModel.addRow(new Object[] {optionList.get(i).getName(), optionList.get(i).getDefaultValue(), - optionList.get(i).getClass().getSimpleName()}); - } - // update graphic - centerPanel.add(optionTable); - centerPanel.updateUI(); - } - // show normal - if (e.getSource() == normalButton) { - optionList = ComponentManager.getConfigOptions(componentOption); // get class for options - - // clear - centerPanel.removeAll(); - - //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); - - // 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 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; + } + } Added: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDefault.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDefault.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDefault.java 2008-01-28 02:38:38 UTC (rev 430) @@ -0,0 +1,61 @@ +package org.dllearner.gui; + +/** + * Copyright (C) 2007, 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.Color; + +import javax.swing.JLabel; +import javax.swing.JPanel; + +import org.dllearner.core.Component; +import org.dllearner.core.config.ConfigOption; + + +/** + * WidgetPanelDefault + * + * @author Tilo Hielscher + * + */ +public class WidgetPanelDefault extends JPanel { + + 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()); + + // 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); + } + +} Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java 2008-01-26 19:25:33 UTC (rev 429) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java 2008-01-28 02:38:38 UTC (rev 430) @@ -39,7 +39,7 @@ /** - * WidgetPanel + * WidgetPanelInteger * * @author Tilo Hielscher * @@ -55,38 +55,19 @@ private JButton setButton = new JButton("Set"); private Component component; private Class<? extends Component> componentOption; - + + 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; - System.out.println("1st: " + component); - - // default - nameLabel = new JLabel(configOption.getName()); - setButton.addActionListener(this); - - // IntegerConfigOption - if (configOption.toString().contains("IntegerConfigOption")) { - JTextField integerField = new JTextField(3); - integerField.setText("100"); - System.out.println(configOption.getDefaultValue()); - centerPanel.add(nameLabel); - 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); - } - - // default + showLabel(); // name of option and tooltip + showThingToChange(); // textfield, setbutton add(centerPanel, BorderLayout.CENTER); } @@ -96,30 +77,79 @@ public void actionPerformed(ActionEvent e) { if (e.getSource() == setButton) { - // 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); + 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); } - catch (InvalidConfigOptionValueException s) { - s.printStackTrace(); + // UNKNOWN + else { + nameLabel = new JLabel(configOption.getName()); + JLabel notImplementedLabel = new JLabel("not an integer"); + notImplementedLabel.setForeground(Color.RED); + centerPanel.add(nameLabel); + centerPanel.add(notImplementedLabel); } } + else { // configOption == NULL + JLabel noConfigOptionLabel = new JLabel("no init at moment"); + noConfigOptionLabel.setForeground(Color.RED); + centerPanel.add(noConfigOptionLabel); + } } - public void setComponent (Component component) { - this.component = component; + 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(); + } } - - 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. |