annotearenderer.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,645 行 · 第 1/4 页
JAVA
1,645 行
//The MIT License//// Copyright (c) 2004 Mindswap Research Group, University of Maryland, College Park//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions://// The above copyright notice and this permission notice shall be included in// all copies or substantial portions of the Software.//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS// IN THE SOFTWARE.package org.mindswap.swoop.annotea;import java.awt.BorderLayout;import java.awt.Container;import java.awt.Cursor;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.io.FileWriter;import java.io.IOException;import java.io.StringWriter;import java.net.Authenticator;import java.net.PasswordAuthentication;import java.net.URI;import java.net.URISyntaxException;import java.net.URL;import java.util.ArrayList;import java.util.Calendar;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import java.util.SortedSet;import java.util.StringTokenizer;import java.util.TimeZone;import java.util.TreeSet;import java.util.Properties;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JComponent;import javax.swing.JDialog;import javax.swing.JEditorPane;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JScrollPane;import javax.swing.JSplitPane;import javax.swing.JTextField;import javax.swing.JToolBar;import javax.swing.JTree;import javax.swing.event.HyperlinkEvent;import javax.swing.event.HyperlinkListener;import javax.swing.event.TreeSelectionEvent;import javax.swing.event.TreeSelectionListener;import javax.swing.table.TableColumn;import javax.swing.text.Document;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.TreePath;import org.mindswap.swoop.ModelChangeEvent;import org.mindswap.swoop.Swoop;import org.mindswap.swoop.SwoopFrame;import org.mindswap.swoop.SwoopModel;import org.mindswap.swoop.SwoopModelListener;import org.mindswap.swoop.renderer.SwoopCellRenderer;import org.mindswap.swoop.treetable.JTreeTable;import org.mindswap.swoop.utils.SwoopCache;import org.mindswap.swoop.utils.ui.BrowserControl;import org.mindswap.swoop.utils.ui.DescriptionComparator;import org.mindswap.swoop.utils.ui.SwoopIcons;import org.semanticweb.owl.model.OWLClass;import org.semanticweb.owl.model.OWLDataType;import org.semanticweb.owl.model.OWLEntity;import org.semanticweb.owl.model.OWLException;import org.semanticweb.owl.model.OWLNamedObject;import org.semanticweb.owl.model.OWLOntology;import org.semanticweb.owl.model.helper.OntologyHelper;import com.hexidec.ekit.EkitCore;import org.mindswap.swoop.utils.InstanceCreator;// add form processing:use html paneimport com.holub.ui.HTML.HTMLPane;// add javascript supportimport org.mindswap.swoop.utils.JavaScriptHandler;/** * @author Aditya Kalyanpur * */public class AnnoteaRenderer extends JPanel implements ActionListener, TreeSelectionListener, SwoopModelListener, MouseListener, HyperlinkListener, KeyListener { SwoopModel swoopModel; SwoopFrame swoopHandler; AnnoteaServerPrefs annotPrefs; JTreeTable annotTreeTable; JButton prefBtn, refreshBtn, newBtn, replyBtn, searchBtn, submitBtn, clearBtn, deleteBtn; Font tahoma = new Font("Tahoma", Font.PLAIN, 11);// Font tahoma = new Font("SansSerif", Font.PLAIN, 11); Font tahomaB = new Font("Tahoma", Font.BOLD, 10);// Font tahomaB = new Font("SansSerif", Font.BOLD, 10); JScrollPane threadTableScroll, htmlPanel; JPanel topPanel, bottomPanel, newThreadPanel, threadBar, ekitPanel, annotBodyPanel; JPanel btnPanel; JTextField authorFld, dateFld; JCheckBox displayAll; JComboBox typeBox; EkitCore ekitCore; // add form processing: change to HTMLPane //JEditorPane htmlCore; HTMLPane htmlCore; HTMLPane maxPane; // add javascript support JavaScriptHandler jsHandler = null; JLabel bodyLbl, statusLbl, autoRetLbl, newAnnotLbl, attachLbl; boolean showAuthenticator = true; JTextField subjectFld; public JFrame popupNew; JCheckBox fixContextChk; JButton showAllBtn, annotAttachBtn, myAttachBtn; List annotatedChangeSet; public SwoopCache annotationCache; Map savedDefinitions; public AnnoteaRenderer(SwoopModel swoopModel, SwoopFrame swoopHandler) { this.swoopModel = swoopModel; this.swoopHandler = swoopHandler; this.annotPrefs = new AnnoteaServerPrefs(); this.annotatedChangeSet = new ArrayList(); this.annotationCache = swoopModel.getAnnotationCache(); this.savedDefinitions = new HashMap(); setupUI(); setupPopup(); //refillAnnotTypes(); } /*** * Get the root node of the Annotation Tree * This tree will contain (as its nodes) any global annotations * downloaded from an Annotea Server pertaining to the current * selected SwoopModel Ontology/Entity */ private DefaultMutableTreeNode getTreeRoot() { // initialize annotation tree // for now set to null since no annotea server present Description root = new Description(); root.setCreated(""); root.setBody(""); root.setAuthor("[Annotations]"); DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(root); return rootNode; } /*** * Correspond to default Annotation Types in the Annotea Protocol * Also align with the static constants in Annotation.java */ private void refillAnnotTypes() { // INITIALIZATION OF ANNOTEA - for getting annotation types if (Annotea.INSTANCE==null) { Annotea.initializeAnnotea(); } typeBox.removeAllItems(); // Obtain all annotation types from Annotea.java if (Annotea.INSTANCE!=null) { Iterator iter = Annotea.INSTANCE.annotationTypes.iterator(); while (iter.hasNext()) { OWLClass annotType = (OWLClass) iter.next(); typeBox.addItem(annotType); } } } private JButton createButton(String lbl, String tooltip) { JButton btn = new JButton(lbl); btn.setFont(tahoma); btn.addActionListener(this); btn.setToolTipText(tooltip); return btn; } private JTextField createField(String lbl) { JTextField fld = new JTextField(lbl); fld.setFont(tahoma); fld.addActionListener(this); return fld; } private JPanel createBox(String txt, JComponent comp) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JLabel lbl = new JLabel(txt); //lbl.setFont(new Font("Tahoma", Font.PLAIN, 10)); lbl.setFont(new Font("SansSerif", Font.PLAIN, 10)); panel.add(lbl, "West"); panel.add(comp, "Center"); return panel; } public void clearAnnotationNodeTree() { // clear tree each time node selection changes // don't retrieve annotations since that can slow down Swoop considerably JTree annotTree = annotTreeTable.getTree(); annotTreeTable.getTree().clearSelection(); DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) annotTree.getModel().getRoot(); rootNode.removeAllChildren(); // annotTree.updateUI(); htmlCore.setText(""); annotAttachBtn.setEnabled(false); refreshUI(); this.setAnnotationNodeTree(new HashSet(), new HashSet()); } private void setupUI() { topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); ImageIcon prefIcon = null; try { prefIcon = SwoopIcons.getImageIcon("Settings.jpg"); } catch (Exception e) { System.out.println("Unable to find images/Settings.jpg"); } // global characteristics buttons prefBtn = new JButton(""); if (prefIcon!=null) prefBtn.setIcon(prefIcon); prefBtn.setToolTipText("Annotea Server Info"); prefBtn.addActionListener(this); showAllBtn = new JButton(""); if (SwoopIcons.rootIcon!=null) showAllBtn.setIcon(SwoopIcons.rootIcon); showAllBtn.setToolTipText("Highlight All Annotated Entities in Class/Property Tree"); showAllBtn.addActionListener(this); showAllBtn.setVisible(false); // local characteristics buttons refreshBtn = createButton("Update", "Retrieve Annotations pertaining to selected SWOOP Object"); newBtn = createButton("New", "Create new annotation"); deleteBtn = createButton("Delete", "Delete selected annotation"); replyBtn = createButton("Reply", "Reply to selected annotation"); searchBtn = createButton("Find", "Search/filter through for specific annotations"); searchBtn.setEnabled(false); threadBar = new JPanel(); threadBar.setLayout(new BorderLayout()); threadBar.add(prefBtn, "West"); JToolBar toolBar = new JToolBar(); //toolBar.setLayout(new GridLayout(1,4)); toolBar.add(prefBtn); toolBar.add(showAllBtn); toolBar.add(refreshBtn); toolBar.add(newBtn); toolBar.add(deleteBtn); toolBar.add(replyBtn); toolBar.add(searchBtn); threadBar.add(toolBar, "Center"); autoRetLbl = new JLabel("(Auto-Update : OFF, Ctrl-U to toggle setting)"); autoRetLbl.setFont(tahoma); displayAll = new JCheckBox("Display All"); displayAll.setToolTipText("Display Annotations on all Entities in Ontology"); displayAll.setFont(tahoma); displayAll.setVisible(true); displayAll.addActionListener(this); threadBar.add(displayAll, "South"); topPanel.add(threadBar, "North"); // create threaded-annotation UI using JTreeTable DefaultMutableTreeNode rootNode = getTreeRoot(); AnnotationTreeModel annotModel = new AnnotationTreeModel(rootNode); annotTreeTable = new JTreeTable(annotModel); annotTreeTable.setFont(tahoma); // set preferred col widths TableColumn column = null; for (int i = 0; i < annotTreeTable.getColumnCount(); i++) { column = annotTreeTable.getColumnModel().getColumn(i); switch (i) { case 0: column.setPreferredWidth(60); break; case 1: column.setPreferredWidth(80); break; case 2: column.setPreferredWidth(20); break; case 3: column.setPreferredWidth(30); break; } } // set default annotation tree params annotTreeTable.getTree().addTreeSelectionListener(this); annotTreeTable.getTree().setRootVisible(false); threadTableScroll = new JScrollPane(annotTreeTable); topPanel.add(threadTableScroll, "Center"); newThreadPanel = new JPanel(); authorFld = createField(""); dateFld = createField(""); // get system date and put it in dc:date format updatePopupDate(); bottomPanel = new JPanel(); bottomPanel.setLayout(new BorderLayout()); bodyLbl = new JLabel("Annotation Body:"); bodyLbl.setFont(tahoma); /* htmlCore = new JEditorPane(); htmlCore.setContentType("text/html"); htmlCore.setEditable(false); htmlCore.addHyperlinkListener(this); htmlCore.addMouseListener(this); htmlCore.setToolTipText("Double Click to Maximize Message"); htmlPanel = new JScrollPane(htmlCore); */ // add form processing htmlCore = new HTMLPane(); htmlCore.addActionListener(this); // javascript handler jsHandler = new JavaScriptHandler(); htmlCore.addTag("javascript", jsHandler); htmlCore.setContentType("text/html"); htmlCore.setEditable(false); htmlCore.addHyperlinkListener(this); htmlCore.addMouseListener(this); htmlCore.setToolTipText("Double Click to Maximize Message"); htmlPanel = new JScrollPane(htmlCore); btnPanel = new JPanel(); JToolBar btnBar = new JToolBar(); submitBtn = createButton("POST Annotation", "Submit new annotation to server"); clearBtn = createButton("Clear", "Clear Annotation Subject and Body"); btnBar.add(submitBtn); btnBar.add(new JLabel("")); btnBar.add(clearBtn); btnPanel.setLayout(new BorderLayout()); btnPanel.add(btnBar, "West"); JLabel linkLbl = new JLabel("[Insert Entity Hyperlink: Press CTRL-L after Word]"); linkLbl.setFont(tahoma); btnPanel.add(linkLbl, "East"); statusLbl = new JLabel("Status:"); statusLbl.setFont(tahoma); bottomPanel.add(bodyLbl, "North"); bottomPanel.add(htmlPanel, "Center"); JPanel lowestPane = new JPanel(); lowestPane.setLayout(new BorderLayout()); lowestPane.add(statusLbl,"North"); fixContextChk = new JCheckBox("LOCK"); fixContextChk.setFont(tahoma); fixContextChk.addActionListener(this); lowestPane.add(fixContextChk, "Center"); annotAttachBtn = new JButton(""); if (SwoopIcons.seeAlsoIcon!=null) annotAttachBtn.setIcon(SwoopIcons.seeAlsoIcon); annotAttachBtn.setToolTipText("View Attachment (Ontology Change Set)"); annotAttachBtn.addActionListener(this); annotAttachBtn.setEnabled(false); lowestPane.add(annotAttachBtn, "East"); bottomPanel.add(lowestPane, "South"); JSplitPane mainPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT); mainPanel.setOneTouchExpandable(true); mainPanel.setTopComponent(topPanel); JPanel bottomPanels = new JPanel(); bottomPanels.setLayout(new BorderLayout()); bottomPanels.add(bottomPanel, "Center"); bottomPanels.add(statusLbl, "South"); mainPanel.setBottomComponent(bottomPanels); setLayout(new GridLayout(1,1)); add(mainPanel); mainPanel.setDividerLocation(220); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?