popupaddclass.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,635 行 · 第 1/5 页
JAVA
1,635 行
package org.mindswap.swoop.popup;import java.awt.BorderLayout;import java.awt.Component;import java.awt.Container;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.net.URI;import java.net.URISyntaxException;import java.util.ArrayList;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Set;import java.util.TreeSet;import javax.swing.Box;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JSplitPane;import javax.swing.JTabbedPane;import javax.swing.JTextField;import javax.swing.ListModel;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import org.mindswap.swoop.SwoopModel;import org.mindswap.swoop.reasoner.SwoopReasoner;import org.mindswap.swoop.renderer.CellRenderer;import org.mindswap.swoop.renderer.ClassExprRenderer;import org.mindswap.swoop.renderer.SwoopCellRenderer;import org.mindswap.swoop.renderer.entity.ConciseFormat;import org.mindswap.swoop.utils.DataValueChecker;import org.mindswap.swoop.utils.change.BooleanElementChange;import org.mindswap.swoop.utils.ui.AddCloseBar;import org.mindswap.swoop.utils.ui.EntityComparator;import org.mindswap.swoop.utils.ui.OntologyComparator;import org.semanticweb.owl.io.vocabulary.RDFVocabularyAdapter;import org.semanticweb.owl.model.OWLAnd;import org.semanticweb.owl.model.OWLClass;import org.semanticweb.owl.model.OWLDataFactory;import org.semanticweb.owl.model.OWLDataProperty;import org.semanticweb.owl.model.OWLDataRange;import org.semanticweb.owl.model.OWLDataType;import org.semanticweb.owl.model.OWLDataValue;import org.semanticweb.owl.model.OWLDescription;import org.semanticweb.owl.model.OWLDisjointClassesAxiom;import org.semanticweb.owl.model.OWLEntity;import org.semanticweb.owl.model.OWLEnumeration;import org.semanticweb.owl.model.OWLException;import org.semanticweb.owl.model.OWLIndividual;import org.semanticweb.owl.model.OWLNot;import org.semanticweb.owl.model.OWLObjectProperty;import org.semanticweb.owl.model.OWLOntology;import org.semanticweb.owl.model.OWLOr;import org.semanticweb.owl.model.OWLProperty;import org.semanticweb.owl.model.OWLRestriction;import org.semanticweb.owl.model.OWLSubClassAxiom;import org.semanticweb.owl.model.change.AddClassAxiom;import org.semanticweb.owl.model.change.AddDataPropertyRange;import org.semanticweb.owl.model.change.AddDomain;import org.semanticweb.owl.model.change.AddEquivalentClass;import org.semanticweb.owl.model.change.AddForeignEntity;import org.semanticweb.owl.model.change.AddIndividualClass;import org.semanticweb.owl.model.change.AddObjectPropertyRange;import org.semanticweb.owl.model.change.AddSuperClass;import org.semanticweb.owl.model.change.OntologyChange;import org.semanticweb.owl.model.change.RemoveEntity;import org.xngr.browser.editor.XmlEditorPane;/** * @author Aditya This class pops up whenever the user needs to specify an OWL * Class/Restriction in an Ontology Change (For example: adding a * superclass, intersection class, domain/range for a property, or type * for an instance) * */public class PopupAddClass extends JFrame implements ActionListener, ItemListener, ListSelectionListener, KeyListener { /* * Global UI Objects */ SwoopReasoner reasoner; String type, fillType; int typeIntCode; Font tahoma = new Font("Tahoma", Font.PLAIN, 11); Font tahomaB = new Font("Tahoma", Font.BOLD, 11); Font tahomaI = new Font("Tahoma", Font.ITALIC, 11); //JButton applyClassBtn, applyResBtn, addClassBtn, addRestrictionBtn, applyCEBtn, addCEBtn, cancelBtn3, // cancelBtn, cancelBtn2; // many cancel btns is bad JButton addCEBtn, cancelBtn3; AddCloseBar classBar, restrictionBar, ceBar; JComboBox simpleClassOntologyCombo, restrPropOntologyCombo, restrClassOntologyCombo, classBox, resClassBox, resDTypeBox, resPropBox, resNameCombo, propTypeBox; JList ontList, classList, dtypeList, propList, valList, ceList; JComboBox ontPropBox, ontValBox, valChooser; JTextField newClassFld, newPropFld, newValFld, dataFld; JButton clearSelBtn1, clearSelBtn2, clearSelBtn3; JTabbedPane mainTab; XmlEditorPane rdfArea; JTextField resDTypeFld; JPanel dTypePanel, resClassPanel; JLabel objResLbl; SwoopModel swoopModel; public List changes; JButton someBtn, allBtn, equBtn, maxBtn, minBtn, intBtn, uniBtn, negBtn, oneBtn; final int SOME = 0; final int ALL = 1; final int EQU = 2; final int MIN = 3; final int MAX = 4; final int INT = 5; final int UNI = 6; final int ONE = 7; final int NEG = 8; OWLDescription currClassExpr = null; List dataTypes = null, dataTypeURIs = null; // list of all XSD datatypes JLabel ceStatusLbl; OWLDescription lhsGCI = null; // LHS class expr. of GCI private static final String ADD_RESTRICTION = "ADDR"; /* * overloading constructor to pass LHS of GCI */ public PopupAddClass(SwoopReasoner reas, String type, SwoopModel swoopModel, OWLDescription lhsGCI) { this.lhsGCI = lhsGCI; this.reasoner = reas; this.type = getFullType(type); this.swoopModel = swoopModel; changes = new ArrayList(); fillType = ""; init(); setupUI(); } // we directly pass the changes so it can be examined here // for deleted stuff and add the new changes directly public PopupAddClass(SwoopReasoner reas, String type, SwoopModel swoopModel) { // setModal(true); this.reasoner = reas; this.type = getFullType(type); this.swoopModel = swoopModel; changes = new ArrayList(); fillType = ""; init(); setupUI(); } private void init() { // create datatypes list String xmls = "http://www.w3.org/2001/XMLSchema#"; String[] datatypes = {"anyURI", "base64Binary", "boolean", "byte", "date", "dateTime", "double", "decimal", "float", "gDay", "gMonth", "gMonthDay", "gYear", "gYearMonth", "hexBinary", "int", "integer", "language", "long", "Name", "normalizedString", "NCName", "NMTOKEN", "negativeInteger","nonNegativeInteger", "nonPositiveInteger", "positiveInteger", "short", "string", "time", "token", "unsignedLong", "unsignedInt", "unsignedShort", "unsignedByte"}; dataTypes = new ArrayList(); dataTypeURIs = new ArrayList(); try { for (int i = 0; i < datatypes.length; i++) { String dataURI = xmls + datatypes[i]; OWLDataType dt = swoopModel.getSelectedOntology().getOWLDataFactory().getOWLConcreteDataType(new URI(dataURI)); dataTypes.add(i, dt); dataTypeURIs.add(i, dataURI); } // finally add RDF XMLLiteral dataTypes.add(datatypes.length, swoopModel.getSelectedOntology().getOWLDataFactory().getOWLConcreteDataType(new URI(RDFVocabularyAdapter.RDF + "XMLLiteral"))); } catch (Exception e) { e.printStackTrace(); } } /** * Accept a class-related-change type code and return the full type string * * @param type - * abbreviated type * @return */ private String getFullType(String type) { // get full string type from type code if (type.equals("GCI-LEFT")) { typeIntCode = -1; return "GENERAL CONCEPT INCLUSION AXIOM (LHS)"; } else if (type.equals("GCI-RIGHT")) { typeIntCode = -2; return "GENERAL CONCEPT INCLUSION AXIOM (RHS)"; } else if (type.equals("EQU") || type.equals("EQUIVALENT CLASS")) { typeIntCode = 0; return "EQUIVALENT CLASS"; } else if (type.equals("SUB") || type.equals("SUPER-CLASS")) { typeIntCode = 1; return "SUPER-CLASS"; } else if (type.equals("SUP") || type.equals("SUP-CLASS")) { typeIntCode = 2; return "SUB-CLASS"; } else if (type.equals("DIS") || type.equals("DISJOINT CLASS")) { typeIntCode = 3; return "DISJOINT CLASS"; } else if (type.equals("INT") || type.equals("INTERSECTION ELEMENT")) { typeIntCode = 4; return "INTERSECTION ELEMENT"; } else if (type.equals("UNI") || type.equals("UNION ELEMENT")) { typeIntCode = 5; return "UNION ELEMENT"; } else if (type.equals("HASDOM") || type.equals("DOMAIN CLASS")) { typeIntCode = 6; return "DOMAIN CLASS"; } else if (type.equals("HASRAN") || type.equals("RANGE CLASS")) { typeIntCode = 7; return "RANGE CLASS"; } else if (type.equals("TYP") || type.equals("INSTANCE TYPE")) { typeIntCode = 8; return "INSTANCE TYPE"; } else // added later if (type.equals("NOT") || type.equals("COMPLEMENT CLASS")) { typeIntCode = 9; return "COMPLEMENT CLASS"; } return ""; } /* * Setup UI for Popup - add Class, Restriction and CE tabs */ private void setupUI() { // create tabbedpane mainTab = new JTabbedPane(); mainTab.setFont(tahoma); // tab1 - defined classes JPanel tab1 = new JPanel(); tab1.setLayout(new BorderLayout()); simpleClassOntologyCombo = new JComboBox(); simpleClassOntologyCombo.addItemListener(this); simpleClassOntologyCombo.setFont(tahoma); ontList = new JList(); ontList.setFont(tahoma); ontList.setCellRenderer(new CellRenderer()); classBox = new JComboBox(); classBox.setFont(tahoma); classBox.setEditable(true); classBox.setRenderer(new CellRenderer()); classList = new JList(); classList.setFont(tahoma); classList.addKeyListener(this); classList.setCellRenderer(new SwoopCellRenderer(swoopModel)); //classList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); classBar = new AddCloseBar(); classBar.addActionListener(this); tab1.setLayout(new BorderLayout()); JLabel ontLbl = new JLabel("Select Ontology:"); ontLbl.setFont(tahoma); JLabel classLbl = new JLabel("Select Class:"); classLbl.setFont(tahoma); JPanel tab1W = new JPanel(); tab1W.setLayout(new BorderLayout()); tab1W.add(ontLbl, "North"); tab1W.add(new JScrollPane(ontList), "Center"); JPanel tab1E = new JPanel(); tab1E.setLayout(new BorderLayout()); tab1E.add(classLbl, "North"); tab1E.add(new JScrollPane(classList), "Center"); JSplitPane tab1Split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); tab1Split.setOneTouchExpandable(true); tab1Split.setLeftComponent(tab1W); tab1Split.setRightComponent(tab1E); newClassFld = new JTextField(); newClassFld.setFont(tahoma); newClassFld.addKeyListener(this); JPanel newPanel = new JPanel(); newPanel.setLayout(new BorderLayout()); JLabel newLbl = new JLabel("OR Specify New Term/URI: "); newLbl.setFont(tahoma); newPanel.add(newLbl, "West"); newPanel.add(newClassFld, "Center"); JPanel tab1C = new JPanel(); tab1C.setLayout(new BorderLayout()); tab1C.add(tab1Split, "Center"); tab1C.add(newPanel, "South"); tab1.add(tab1C, "Center");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?