From: <ton...@us...> - 2008-02-02 02:17:21
|
Revision: 483 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=483&view=rev Author: tonytacker Date: 2008-02-01 18:17:19 -0800 (Fri, 01 Feb 2008) Log Message: ----------- choose now file/URI over widget in KnowledgeSourcePanel Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java trunk/src/dl-learner/org/dllearner/gui/RunPanel.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-01 07:58:29 UTC (rev 482) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-02 02:17:19 UTC (rev 483) @@ -20,18 +20,11 @@ * */ -import java.io.File; import java.util.List; - import javax.swing.*; -import javax.swing.event.*; - import java.awt.BorderLayout; -import java.awt.GridBagConstraints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.GridBagLayout; - import org.dllearner.core.KnowledgeSource; /** @@ -44,16 +37,14 @@ private static final long serialVersionUID = -7678275020058043937L; - private JFileChooser fc; - private JButton openButton, initButton; - private JTextField fileDisplay; + private JButton initButton, getInstancesButton; private String[] kbBoxItems = {}; private JComboBox cb = new JComboBox(kbBoxItems); - private JPanel centerPanel, choosePanel, initPanel; + private JPanel choosePanel = new JPanel(); + private JPanel initPanel = new JPanel(); private Config config; private int choosenClassIndex; private List<Class<? extends KnowledgeSource>> sources; - private JLabel infoLabel = new JLabel("choose local file or type URL"); private OptionPanel optionPanel; KnowledgeSourcePanel(final Config config) { @@ -62,77 +53,27 @@ this.config = config; sources = config.getComponentManager().getKnowledgeSources(); - fc = new JFileChooser(new File("examples/")); - openButton = new JButton("choose local file"); - openButton.addActionListener(this); - + getInstancesButton = new JButton("Get Instances"); + getInstancesButton.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); - - initPanel = new JPanel(); + choosePanel.add(getInstancesButton); 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); - - buildConstraints(constraints, 0, 2, 2, 1, 100, 100); - gridbag.setConstraints(initPanel, constraints); - centerPanel.add(initPanel); - optionPanel = new OptionPanel(config, config.getKnowledgeSource(), sources.get(choosenClassIndex)); add(choosePanel, BorderLayout.PAGE_START); - add(centerPanel, BorderLayout.CENTER); - add(optionPanel, BorderLayout.PAGE_END); + add(optionPanel, BorderLayout.CENTER); + add(initPanel, BorderLayout.PAGE_END); choosenClassIndex = cb.getSelectedIndex(); } @@ -140,60 +81,37 @@ 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); - } - return; - } + if (e.getSource() == getInstancesButton) + getInstances(); - // 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"); - updateOptionPanel(); - } + if (e.getSource() == initButton && config.getURI() != null) + init(); } /* - * Define GridBagConstraints + * after this, you can change widgets */ - 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; + public void getInstances() { + config.setKnowledgeSource(config.getComponentManager().knowledgeSource( + sources.get(choosenClassIndex))); + updateOptionPanel(); } - 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"); - } + /* + * after this, next tab can be used + */ + public void init() { + config.getKnowledgeSource().init(); + System.out.println("init KnowledgeSource with \n" + + sources.get(choosenClassIndex) + " and \n" + config.getURI() + + "\n"); } + /* + * update OptionPanel with new selection + */ public void updateOptionPanel() { - // update OptionPanel optionPanel.update(config.getKnowledgeSource(), sources .get(choosenClassIndex)); } Modified: trunk/src/dl-learner/org/dllearner/gui/RunPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-02-01 07:58:29 UTC (rev 482) +++ trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-02-02 02:17:19 UTC (rev 483) @@ -26,7 +26,7 @@ import javax.swing.*; -import org.dllearner.core.dl.Concept; +//import org.dllearner.core.dl.Concept; /** * OutputPanel @@ -70,8 +70,6 @@ public void actionPerformed(ActionEvent e) { if (e.getSource() == runButton && config.getLearningAlgorithm() != null) { - //config.getLearningAlgorithm().start(); - //thread = new ThreadRun(config); thread = new ThreadRun(config); thread.start(); //Concept solution = config.getLearningAlgorithm().getBestSolution(); Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java 2008-02-01 07:58:29 UTC (rev 482) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java 2008-02-02 02:17:19 UTC (rev 483) @@ -24,7 +24,9 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.Color; +import java.io.File; +import javax.swing.JFileChooser; import javax.swing.JTextField; import javax.swing.JLabel; import javax.swing.JPanel; @@ -76,6 +78,16 @@ public void actionPerformed(ActionEvent e) { if (e.getSource() == setButton) { + if (checkForFilename()) { + // file dialog + JFileChooser fc = new JFileChooser(new File("examples/")); + int returnVal = fc.showOpenDialog(this); + if (returnVal == JFileChooser.APPROVE_OPTION) { + value = fc.getSelectedFile().toString(); + stringField.setText(value); + config.setURI(value); // save variable + } + } setEntry(); } } @@ -113,6 +125,8 @@ setButton.addActionListener(this); widgetPanel.add(stringField); widgetPanel.add(setButton); + if (checkForFilename()) + setButton.setText("choose local file"); } // UNKNOWN else { @@ -144,4 +158,16 @@ s.printStackTrace(); } } + + /* + * Widget filename getName() == filename you should open a file dialog in + * ActionPerformed + */ + private Boolean checkForFilename() { + if (configOption.getName().equalsIgnoreCase("filename")) + return true; + else + return false; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |