|
From: Elmer G. <ega...@us...> - 2004-08-21 00:23:33
|
Update of /cvsroot/javaowl/JavaOWL/src/org/javaowl/editor/swing/pe In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6871/src/org/javaowl/editor/swing/pe Added Files: DefaultPropertyEditorPagelet.java StringPropertyEditorPagelet.java DurationPropertyEditorPagelet.java BooleanPropertyEditorPagelet.java NumericPropertyEditorPagelet.java CalendarPropertyEditorPagelet.java Log Message: Moe work on refactoring --- NEW FILE: StringPropertyEditorPagelet.java --- /* * StringPropertyEditorPagelet.java Copyright (C) 2004 Elmer Garduno Hernandez * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.javaowl.editor.swing.pe; import java.awt.BorderLayout; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JTextField; import org.javaowl.editor.swing.EditPage; import org.javaowl.editor.swing.PropertyEditorPagelet; import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntResource; import com.hp.hpl.jena.rdf.model.Resource; public class StringPropertyEditorPagelet implements PropertyEditorPagelet { private JTextField textField = new JTextField(30); private JPanel textPanel = new JPanel(); private final JPanel component; private EditPage editPage; private OntResource rangeType; public StringPropertyEditorPagelet() { component = new JPanel(new BorderLayout()); JPanel buttonPanel = new JPanel(); JButton ok = new JButton("Set property"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setValue(false); } }); buttonPanel.add(ok); JButton cancel = new JButton("Cancel"); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setValue(true); } }); buttonPanel.add(cancel); textPanel.add(textField); component.add(buttonPanel, BorderLayout.SOUTH); } public void setValues(Resource[] o, Resource value, OntClass clazz) { } public void setValue(String o) { textField.setText(o); component.add(textPanel, BorderLayout.CENTER); } private void setValue(boolean cancel) { if (cancel) { editPage.cancel(); } else if (!textField.getText().equals("")) { editPage.setProperty(textField.getText(), rangeType); } else { editPage.cancel(); } } public void setRangeType(OntResource rangeType) { this.rangeType = rangeType; } public void setEditPage(EditPage editPage) { this.editPage = editPage; } public Component getComponent() { return component; } } --- NEW FILE: DurationPropertyEditorPagelet.java --- /* * DurationPropertyEditorPagelet.java Copyright (C) 2004 Elmer Garduno Hernandez * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.javaowl.editor.swing.pe; public class DurationPropertyEditorPagelet extends StringPropertyEditorPagelet { } --- NEW FILE: CalendarPropertyEditorPagelet.java --- /* * CalendarPropertyEditorPagelet.java Copyright (C) 2004 Elmer Garduno Hernandez * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.javaowl.editor.swing.pe; public class CalendarPropertyEditorPagelet extends StringPropertyEditorPagelet { } --- NEW FILE: NumericPropertyEditorPagelet.java --- /* * NumericPropertyEditorPagelet.java Copyright (C) 2004 Elmer Garduno Hernandez * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.javaowl.editor.swing.pe; public class NumericPropertyEditorPagelet extends StringPropertyEditorPagelet { } --- NEW FILE: BooleanPropertyEditorPagelet.java --- /* * BooleanPropertyEditorPagelet.java Copyright (C) 2004 Elmer Garduno Hernandez * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.javaowl.editor.swing.pe; public class BooleanPropertyEditorPagelet extends StringPropertyEditorPagelet { } --- NEW FILE: DefaultPropertyEditorPagelet.java --- /* * DefaultPropertyEditorPagelet.java Copyright (C) 2004 Elmer Garduno Hernandez * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.javaowl.editor.swing.pe; import java.awt.BorderLayout; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.ListCellRenderer; import org.javaowl.editor.swing.EditPage; import org.javaowl.editor.swing.LabelListCellRenderer; import org.javaowl.editor.swing.PropertyEditorPagelet; import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntResource; import com.hp.hpl.jena.rdf.model.Resource; public class DefaultPropertyEditorPagelet implements PropertyEditorPagelet { private JTextField textField = new JTextField(30); private JComboBox comboBox = new JComboBox(); private JPanel textPanel = new JPanel(); private JPanel comboPanel = new JPanel(); private OntClass clazz; private final JPanel component; private EditPage editPage; private OntResource rangeType; public DefaultPropertyEditorPagelet() { ListCellRenderer renderer = new LabelListCellRenderer(); comboBox.setRenderer(renderer); component = new JPanel(new BorderLayout()); JPanel buttonPanel = new JPanel(); JButton ok = new JButton("Set property"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setValue(false); } }); buttonPanel.add(ok); JButton cancel = new JButton("Cancel"); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setValue(true); } }); buttonPanel.add(cancel); textPanel.add(textField); comboPanel.add(comboBox); JButton create = new JButton("Create resource"); create.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { editPage.notifyCreateResource(clazz); } }); comboPanel.add(create); component.add(buttonPanel, BorderLayout.SOUTH); } public void setValues(Resource[] o, Resource value, OntClass clazz) { this.clazz = clazz; textField.setText(null); comboBox.removeAllItems(); if (o != null) { for (int i = 0; i < o.length; i++) comboBox.addItem(o[i]); } else comboBox.addItem(value); comboBox.setSelectedItem(value); component.remove(textPanel); component.add(comboPanel, BorderLayout.CENTER); } public void setValue(String o) { comboBox.removeAllItems(); textField.setText(o); component.remove(comboPanel); component.add(textPanel, BorderLayout.CENTER); } private void setValue(boolean cancel) { if (cancel) { editPage.cancel(); } else if (comboBox.getItemCount() == 0 && !textField.getText().equals("")) { editPage.setProperty(textField.getText(), rangeType); } else if (textField.getText().equals("") && comboBox.getItemCount() != 0) { editPage.setProperty((Resource) comboBox.getSelectedItem()); } else { editPage.cancel(); } } public void setRangeType(OntResource rangeType) { this.rangeType = rangeType; } public void setEditPage(EditPage editPage) { this.editPage = editPage; } public Component getComponent() { return component; } } |