public String getTextForGesture(long parId, Point topLeft, Point bottomRight) { try { Paragraph p = lockManager.getParFromId(parId); int parY = documentPanel.textPane.modelToView(p.getOffset()).y; topLeft.y = topLeft.y + parY; bottomRight.y = bottomRight.y + parY; int startOffset = documentPanel.textPane.viewToModel(topLeft); int endOffset = documentPanel.textPane.viewToModel(bottomRight); while (startOffset > 0 && Character.isLetterOrDigit((document.getText(startOffset - 1, 1).charAt(0)))) startOffset--; while (endOffset < document.getLength() && Character.isLetterOrDigit((document.getText(endOffset, 1).charAt(0)))) endOffset++; String text = document.getText(startOffset, endOffset - startOffset); return text; } catch (Exception e) { System.out.println("EditorClient: addGestureAction. error identifying text"); e.printStackTrace(); return ""; } // return "PLACEBO"; }
/** * Formats paragraphs that were generated as a result of rendering an annotation value with global * formatting such as tab count and margins. This ensures that all paragraphs representing * annotation values have the correct indentation etc. * * @param valueRenderingParagraphs The paragraphs to be formatted. */ private void applyGlobalFormattingToAnnotationValueParagraphs( List<Paragraph> valueRenderingParagraphs) { for (Paragraph paragraph : valueRenderingParagraphs) { paragraph.setTabCount(0); paragraph.setMarginBottom(2); } }
public long getParIdForGesture(long startParId, int y) { Paragraph startPar = lockManager.getParFromId(startParId); int startParY = documentPanel.getYValueFromOffset(startPar.getOffset()); int offset = documentPanel.getOffsetFromPoint(new Point(25, startParY + y)); return lockManager.getParFromOffset(offset).getID(); }
/** * Renderes a set of entities as an annotation value. The idea is that the annotation value is an * IRI that corresponds to the IRI of entities in the imports closure of the active ontology. * * @param page The page that the entities will be rendered into. * @param entities The entities. * @return A list of paragraphs that represents the rendering of the entities. */ private List<Paragraph> renderEntities(Page page, Set<OWLEntity> entities) { List<Paragraph> paragraphs = new ArrayList<>(); for (OWLEntity entity : entities) { Icon icon = getIcon(entity); OWLModelManager modelManager = editorKit.getOWLModelManager(); Paragraph paragraph = new Paragraph(modelManager.getRendering(entity), new OWLEntityLink(editorKit, entity)); paragraph.setIcon(icon); page.add(paragraph); paragraphs.add(paragraph); } return paragraphs; }
public void sendHighlights() { // send highlights to everybody try { Iterator i = highlights.getHighlights().iterator(); while (i.hasNext()) { Highlights.Highlight h = (Highlights.Highlight) i.next(); Paragraph sPar = lockManager.getParFromOffset(h.getStart()); Paragraph ePar = lockManager.getParFromOffset(h.getEnd()); if (EditorServer_Debug) { System.out.println("StartPar: " + sPar.toString()); System.out.println("EndPar: " + ePar.toString()); } Message.HighlightAddMsg msg = new Message.HighlightAddMsg( -1, h.getId(), h.getType().getId(), sPar.getID(), ePar.getID(), h.getStart() - sPar.getOffset(), h.getEnd() - ePar.getOffset()); textChannel.sendToOthers(client, new Data(msg)); } } catch (Exception e) { System.err.println("EditorServer: sendHighlights: error sending msg"); if (EditorServer_Debug) e.printStackTrace(); } }
/** * Renders the annotation property into a paragraph in the page. * * @param page The page to insert the paragraph into. * @param annotation The annotation containing the property to be rendered. * @param defaultForeground The default foreground color. * @param defaultBackground The default background color. * @param isSelected Specifies whether the associated cell is selected or not. */ private Paragraph renderAnnotationProperty( Page page, OWLAnnotation annotation, Color defaultForeground, Color defaultBackground, boolean isSelected) { OWLAnnotationProperty property = annotation.getProperty(); String rendering = editorKit.getOWLModelManager().getRendering(property); Paragraph paragraph = page.addParagraph(rendering); Color foreground = getAnnotationPropertyForeground(defaultForeground, isSelected); paragraph.setForeground(foreground); // if (isReferenceOntologyActive()) { // paragraph.setBold(true); // } if (annotation.getValue() instanceof OWLLiteral) { OWLLiteral literalValue = (OWLLiteral) annotation.getValue(); paragraph.append(" ", foreground); appendTag(paragraph, literalValue, foreground, isSelected); } switch (annotationRenderingStyle) { case COMFORTABLE: paragraph.setMarginBottom(4); break; case COSY: paragraph.setMarginBottom(2); break; case COMPACT: paragraph.setMarginBottom(1); break; } return paragraph; }
/** * Renders an annotation value that is an OWLLiteral. * * @param page The page that the value will be rendered into. * @param literal The literal to be rendered. * @param foreground The default foreground. * @param background The default background. * @param isSelected Whether or not the cell containing the annotation value is selected. * @return A list of paragraphs that represent the rendering of the literal. */ private List<Paragraph> renderLiteral( Page page, OWLLiteral literal, Color foreground, Color background, boolean isSelected) { String rendering = EscapeUtils.unescapeString(literal.getLiteral()).trim(); List<Paragraph> result = new ArrayList<>(); if (rendering.length() > 0) { List<LinkSpan> linkSpans = extractLinks(rendering); Paragraph literalParagraph = new Paragraph(rendering, linkSpans); literalParagraph.setForeground(foreground); page.add(literalParagraph); result.add(literalParagraph); Paragraph tagParagraph = literalParagraph; // new Paragraph(""); tagParagraph.append(" ", foreground); page.add(tagParagraph); result.add(tagParagraph); tagParagraph.setMarginTop(2); tagParagraph.setTabCount(2); // appendTag(tagParagraph, literal, foreground, isSelected); } return result; }
private void appendTag( Paragraph tagParagraph, OWLLiteral literal, Color foreground, boolean isSelected) { Color tagColor = isSelected ? foreground : Color.GRAY; Color tagValueColor = isSelected ? foreground : Color.GRAY; if (literal.hasLang()) { tagParagraph.append("[language: ", tagColor); tagParagraph.append(literal.getLang(), tagValueColor); tagParagraph.append("]", tagColor); } else if (datatypeRendering == RENDER_DATATYPE_INLINE && !literal.isRDFPlainLiteral()) { tagParagraph.append("[type: ", tagColor); tagParagraph.append( editorKit.getOWLModelManager().getRendering(literal.getDatatype()), tagValueColor); tagParagraph.append("]", tagColor); } // if (ontology != null) { // tagParagraph.append(" ", foreground); // tagParagraph.append("[in: ", tagColor); // String ontologyRendering = editorKit.getOWLModelManager().getRendering(ontology); // tagParagraph.append(ontologyRendering, tagColor); // tagParagraph.append("]", tagColor); // } }
/** * Renders an annotation value that is an anonymous individual. * * @param page The page that the individual should be rendered into. * @param individual The individual. * @return A list of paragraphs that represent the rendering of the individual. */ private List<Paragraph> renderAnonymousIndividual(Page page, OWLAnonymousIndividual individual) { String rendering = editorKit.getOWLModelManager().getRendering(individual); Paragraph paragraph = page.addParagraph(rendering); paragraph.setIcon(getIcon(individual)); return Arrays.asList(paragraph); }