annotearenderer.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,645 行 · 第 1/4 页
JAVA
1,645 行
/*** * Refresh UI to display either a threaded interface with existing * annotations or a form to fill in details of a new annotation * */ private void refreshUI() { topPanel.add(threadTableScroll, "Center"); bottomPanel.add(htmlPanel, "Center"); topPanel.updateUI(); bottomPanel.updateUI(); } /** * Create UI of popup for new annotea annotation * */ public void setupPopup() { popupNew = new JFrame(); Container content = popupNew.getContentPane(); content.setLayout(new GridLayout(1,1)); // create new-annotation panel newThreadPanel.setLayout(new BorderLayout()); newAnnotLbl = new JLabel(" Creating New Annotation: "); newAnnotLbl.setFont(tahoma); newThreadPanel.add(newAnnotLbl, "North"); JPanel infoPanel = new JPanel(); infoPanel.setLayout(new GridLayout(5,1)); newThreadPanel.add(infoPanel, "Center"); infoPanel.add(new JLabel("")); infoPanel.add(createBox(" Author:", authorFld)); infoPanel.add(createBox(" Date:", dateFld)); // create annotation type box typeBox = new JComboBox(); typeBox.setFont(tahoma); typeBox.setRenderer(new SwoopCellRenderer(swoopModel)); infoPanel.add(createBox(" Type:", typeBox)); // setup Ekit ekitPanel = new JPanel(); ekitPanel.setLayout(new BorderLayout()); ekitCore = new EkitCore(null, null, null, null, false, true, true, null, null, false, false); ekitCore.getTextPane().addHyperlinkListener(this); ekitCore.getTextPane().addKeyListener(this); JPanel ekitTopPanel = new JPanel(); ekitTopPanel.setLayout(new GridLayout(2,1)); ekitTopPanel.add(ekitCore.getMenuBar()); ekitTopPanel.add(ekitCore.getToolBar(true)); ekitPanel.add(ekitTopPanel, "North"); ekitPanel.add(ekitCore, "Center"); // setup annotation message panel annotBodyPanel = new JPanel(); annotBodyPanel.setLayout(new BorderLayout()); subjectFld = new JTextField(); subjectFld.setFont(tahoma); JPanel annotHeadPanel = new JPanel(); annotHeadPanel.setLayout(new GridLayout(2,1)); annotHeadPanel.add(createBox("Subject:", subjectFld)); myAttachBtn = new JButton("Attach Change Set:"); if (SwoopIcons.seeAlsoIcon!=null) myAttachBtn.setIcon(SwoopIcons.seeAlsoIcon); myAttachBtn.setToolTipText("Attach Ontology Change Set"); myAttachBtn.addActionListener(this); myAttachBtn.setFont(tahoma); JPanel attachPanel = new JPanel(); attachPanel.setLayout(new BorderLayout()); JPanel leftAttachPane = new JPanel(); leftAttachPane.setLayout(new BorderLayout()); leftAttachPane.add(myAttachBtn, "West"); attachLbl = new JLabel("None"); attachLbl.setFont(tahoma); leftAttachPane.add(attachLbl, "Center"); attachPanel.add(leftAttachPane, "West"); annotHeadPanel.add(attachPanel); annotBodyPanel.add(annotHeadPanel, "North"); annotBodyPanel.add(ekitPanel, "Center"); JPanel tPanel = new JPanel(); tPanel.setLayout(new BorderLayout()); tPanel.add(newThreadPanel, "Center"); JPanel bPanel = new JPanel(); bPanel.setLayout(new BorderLayout()); bPanel.add(bodyLbl, "North"); bPanel.add(annotBodyPanel, "Center"); bPanel.add(btnPanel, "South"); JSplitPane mainPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT); mainPanel.setOneTouchExpandable(true); mainPanel.setTopComponent(tPanel); mainPanel.setBottomComponent(bPanel); content.add(mainPanel); popupNew.setLocation(300,100); popupNew.setSize(550,600); popupNew.setTitle("New Annotea Annotation"); popupNew.hide(); } public String getSubject(Description annot) { String subject = ""; if (annot.getBody()!=null) { subject = annot.getBody().trim(); if (subject.indexOf("<head>")>=0) { subject = subject.substring(subject.indexOf("<head>")+6, subject.indexOf("</head>")).trim(); } } return subject; } public void actionPerformed(ActionEvent e) { if (e.getSource()==newBtn) { // new-thread button clicked popupAnnotation(new ArrayList()); } if (e.getSource()==replyBtn) { //TODO make this the standard Annotea reply // currently its the mail style reply // get current selected description' subject if (annotTreeTable.getTree().getSelectionPath()==null) return; DefaultMutableTreeNode selNode = (DefaultMutableTreeNode) annotTreeTable.getTree().getSelectionPath().getLastPathComponent(); Description selAnnot = (Description) selNode.getUserObject(); String subject = this.getSubject(selAnnot); String REsubject = "Re: "+subject; subjectFld.setText(REsubject); this.refillAnnotTypes(); ekitCore.getTextPane().setText(htmlCore.getText()); ekitCore.getTextPane().setCaretPosition(0); popupNew.show(); updatePopupDate(); statusLbl.setText("Status: Replying to annotation"); } if (e.getSource()==prefBtn) { // preferences button annotPrefs.show(); } if (e.getSource()==displayAll) { // toggle display all annotated entities this.displayAnnotations(); } if (e.getSource()==submitBtn) { Cursor currentCursor = this.getCursor(); this.setCursor(new Cursor(Cursor.WAIT_CURSOR)); postAnnotation(); // post annotation to annotea server this.setCursor(currentCursor); } if (e.getSource()==refreshBtn && refreshBtn.getText().equals("Update")) { // retrieve all annotations retrieveAnnotations(); } if (e.getSource()==clearBtn) { // clear annotation body clearBody(); } if (e.getSource()==deleteBtn) { // delete selected annotation if (annotTreeTable.getTree().getSelectionPath()==null) return; DefaultMutableTreeNode selNode = (DefaultMutableTreeNode) annotTreeTable.getTree().getSelectionPath().getLastPathComponent(); Description selAnnot = (Description) selNode.getUserObject(); if (selAnnot==null) { statusLbl.setText("Status: ERROR - need to select annotation"); return; // displ } deleteAnnotation(selAnnot); } if (e.getSource()==fixContextChk) { // fix context checkbox clicked if (fixContextChk.isSelected()) { this.toggleButtonEnable(false); try { statusLbl.setText("Status: "+swoopModel.shortForm(swoopModel.selectedOWLObject.getURI())+" LOCKED"); } catch (OWLException e1) { e1.printStackTrace(); } } else { this.toggleButtonEnable(true); statusLbl.setText("Status: Context Dynamic - Need to Update"); } } if (e.getSource()==annotAttachBtn) { popupAttachment(AnnoteaAttachment.ANNOTATION_ATTACHMENT); } if (e.getSource()==myAttachBtn) { popupAttachment(AnnoteaAttachment.MY_ATTACHMENT); } if (e.getSource()==searchBtn) { // TEMPORARY HACK REMOVE } // add form processing if (e.getSource() == htmlCore || e.getSource() == maxPane){ HTMLPane.FormActionEvent act = (HTMLPane.FormActionEvent)e; System.out.println("Form output"); System.out.println("method " + act.method()); System.out.println("action " + act.action()); System.out.println("name " + act.name()); act.data().list(System.out); System.out.println("End of form output"); // javascript handlering String[] n3 = invokeJavaScript(act.name(), act.data()); try{ InstanceCreator c = new InstanceCreator(); c.createInstances(popupNew, n3, swoopModel); } catch (Exception ex){ JOptionPane.showMessageDialog(htmlCore, ex.getMessage(), "Instance Creation Error", JOptionPane.ERROR_MESSAGE); //ex.printStackTrace(); } } } // javascript handlering private String[] invokeJavaScript(String formName, Properties data){ boolean verified = true; try{ verified = jsHandler.verify(formName, data); } catch (Exception e){ JOptionPane.showMessageDialog(htmlCore, e.getMessage(), "Javascript Error", JOptionPane.ERROR_MESSAGE); //e.printStackTrace(); return new String[0]; } if (! verified){ JOptionPane.showMessageDialog(htmlCore, jsHandler.getErrorMsg(), "Form Error", JOptionPane.ERROR_MESSAGE); return new String[0]; } System.out.println("Javascript verification result is " + verified); String[] n3 = null; try{ n3 = jsHandler.generateN3(); for (int i=0;i<n3.length;i++){ System.out.println(n3[i]); } return n3; } catch (Exception e){ JOptionPane.showMessageDialog(htmlCore, e.getMessage(), "Javascript Error", JOptionPane.ERROR_MESSAGE); //e.printStackTrace(); return new String[0]; } } private void toggleButtonEnable(boolean mode) { this.refreshBtn.setEnabled(mode); this.newBtn.setEnabled(mode); this.deleteBtn.setEnabled(mode); this.replyBtn.setEnabled(mode); } /** * Check if an entityURI is present in the ontology * @param ont - ontology to check * @param entityURI - URI of the entity * @return */ private boolean isEntityPresent(OWLOntology ont, URI entityURI) { try { if (ont.getClass(entityURI)!=null || ont.getDataProperty(entityURI)!=null || ont.getObjectProperty(entityURI)!=null || ont.getIndividual(entityURI)!=null) { return true; } } catch (OWLException e) { e.printStackTrace(); } return false; } /** * Popup Annotation Frame, initialize its UI */ public void popupAnnotation(List changes) { this.refillAnnotTypes(); this.annotatedChangeSet = new ArrayList(changes); attachLbl.setText(" None"); String owlObj = ""; try { if (swoopModel.selectedOWLObject!=null) { owlObj = swoopModel.shortForm(swoopModel.selectedOWLObject.getURI()); } } catch (OWLException ex) { ex.printStackTrace(); } newAnnotLbl.setText(" Creating New Annotation : " + owlObj); // also set popup annotation change set if any if (changes.size()>0) attachLbl.setText(" Ontology Change Set attached (size:"+annotatedChangeSet.size()+")"); else attachLbl.setText("None"); popupNew.show(); updatePopupDate(); statusLbl.setText("Status: Posting new annotation"); } /** * Popup window showing attachment (change set) details. * attachType determines whether its the current SWOOP change set * or change set attached to annotea annotation * @param attachType */ protected void popupAttachment(int attachType) { switch (attachType) { case AnnoteaAttachment.MY_ATTACHMENT : // obtain current active change set List changeSet = new ArrayList(swoopModel.getCommittedChanges()); // create modal dialog - attachment AnnoteaAttachment putAttachment = new AnnoteaAttachment(swoopHandler.changeLog, changeSet, attachType, annotatedChangeSet); annotatedChangeSet = (ArrayList) putAttachment.selectedChangeSet; if (annotatedChangeSet!=null && annotatedChangeSet.size()>0) { attachLbl.setText(" Ontology Change Set attached (size:"+annotatedChangeSet.size()+")"); } else attachLbl.setText(" None"); break; case AnnoteaAttachment.ANNOTATION_ATTACHMENT : // get selected description node if (annotTreeTable.getTree().getSelectionPath()==null) { statusLbl.setText("Status: ERROR - select row in table"); return; } DefaultMutableTreeNode selNode = (DefaultMutableTreeNode) annotTreeTable.getTree().getSelectionPath().getLastPathComponent(); Description selAnnot = (Description) selNode.getUserObject(); AnnoteaAttachment viewAttachment = new AnnoteaAttachment(swoopHandler.changeLog, selAnnot.getOntologyChangeSet(), attachType, new ArrayList()); break; } } /** * Clear annotation body and summary */ public void clearBody() { subjectFld.setText(""); ekitCore.getTextPane().setText(""); } private void clearOntAnnotationCache(OWLOntology ont) { try { Set entities = ont.getClasses(); entities.addAll(ont.getDataProperties()); entities.addAll(ont.getObjectProperties()); entities.addAll(ont.getIndividuals()); // finally add ontology itself for checking entities.add(ont); for (Iterator iter = entities.iterator(); iter.hasNext(); ) { URI owlObjURI = ((OWLNamedObject) iter.next()).getURI(); annotationCache.putAnnotationSet(owlObjURI, new HashSet()); swoopModel.getAnnotatedObjectURIs().remove(owlObjURI); } } catch (Exception e) { e.printStackTrace(); } } /** * Obtain all annotations from Annotea server * pertaining to current selected OWL entity * */ public void retrieveAnnotations() { // check if entity is selected first if (swoopModel.selectedOWLObject==null) { statusLbl.setText("Status: ERROR retrieving annotations - need to select OWL ontology / entity"); return; } Cursor currentCursor = this.getCursor(); this.setCursor(new Cursor(Cursor.WAIT_CURSOR)); // INITIALIZATION OF ANNOTEA DURING FIRST POST/UPDATE
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?