/** Get tooltip text for the mouse position */ // TODO: does not work for asynchronous tooltip texts public String getToolTipText(MouseEvent e) { int line = (int) ((float) e.getY() / (float) lineHeight); if (annos.getNumberOfAnnotations(line) == 0) return null; if (isMouseOverCycleButton(e) && annos.getNumberOfAnnotations(line) > 1) { return java.text.MessageFormat.format(LocaleSupport.getString("cycling-glyph_tooltip"), // NOI18N new Object[] { new Integer(annos.getNumberOfAnnotations(line)) }); } else if (isMouseOverGlyph(e)) { return annos.getActiveAnnotation(line).getShortDescription(); } else return null; }
/** Returns object which represent list of annotations which are * attached to this document. * @return object which represent attached annotations */ public Annotations getAnnotations() { synchronized (annotationsLock) { if (annotations == null) { annotations = new Annotations(this); } return annotations; } }
/** Creates popup menu with all actions for the given line. */ public JMenu createMenu(BaseKit kit, int line) { boolean bkgInit = menuInitialized; menuInitialized = true; return createMenu(kit, line, !bkgInit); }
public void propertyChange (PropertyChangeEvent evt) { if (evt.getPropertyName() == AnnotationDesc.PROP_ANNOTATION_TYPE) { AnnotationDesc anno = (AnnotationDesc)evt.getSource(); LineAnnotations lineAnnos = (LineAnnotations)lineAnnotationsByMark.get(anno.getMark()); lineAnnos.refreshAnnotations(); refreshLine(lineAnnos.getLine()); } if (evt.getPropertyName() == AnnotationDesc.PROP_MOVE_TO_FRONT) { AnnotationDesc anno = (AnnotationDesc)evt.getSource(); frontAnnotation(anno); } } };
int lineWithAnno = annos.getNextLineWithAnnotation(line); int count = annos.getNumberOfAnnotations(line); AnnotationDesc anno = annos.getActiveAnnotation(line); lineWithAnno = annos.getNextLineWithAnnotation(line + 1);
if (isMouseOverCycleButton(e)) { int line = (int) ((float) e.getY() / (float) lineHeight); annos.activateNextAnnotation(line); int line = (int) ((float) e.getY() / (float) lineHeight); int offset; if (annos.getActiveAnnotation(line) != null) offset = annos.getActiveAnnotation(line).getOffset(); else offset = Utilities.getRowStartFromLineOffset(doc, line); JumpList.checkAddEntry(); editorUI.getComponent().getCaret().setDot(offset); JPopupMenu pm = annos.createPopupMenu(Utilities.getKit(editorUI.getComponent()), line); if (pm != null) { pm.show(GlyphGutter.this, e.getX(), e.getY());
int line = getLineFromMouseEvent(e); int offset; if (annos.getActiveAnnotation(line) != null) offset = annos.getActiveAnnotation(line).getOffset(); else offset = Utilities.getRowStartFromLineOffset(doc, line); JumpList.checkAddEntry(); editorUI.getComponent().getCaret().setDot(offset); JPopupMenu pm = annos.createPopupMenu(Utilities.getKit(editorUI.getComponent()), line); if (pm != null) { pm.show(GlyphGutter.this, e.getX(), e.getY());
@Override public void run() { try { int line = Utilities.getLineOffset((BaseDocument) doc, currentPosition); int startOffset = Utilities.getRowStartFromLineOffset((BaseDocument) doc, line); int endOffset = Utilities.getRowEnd((BaseDocument) doc, startOffset); AnnotationDesc desc = annotations.getActiveAnnotation(line); if (desc == null) { return ; } Collection<BaseAnnotation> annos; if (COMBINED_TYPES.contains(desc.getAnnotationType())) { annos = findAnnotations(comp, startOffset, endOffset); } else { annos = Collections.singletonList(findAnnotation(comp, desc, startOffset, endOffset)); } for (BaseAnnotation a : annos) { if (a != null) { anno.set(a); point.set(comp.modelToView(startOffset).getLocation()); break; } } } catch (BadLocationException ex) { ex.printStackTrace(); } } });
LineAnnotations annos = getLineAnnotations(line); Map types = new HashMap(AnnotationTypes.getTypes().getVisibleAnnotationTypeNamesCount() * 4 / 3); if (actions != null) { for (int i = 0; i < actions.length; i++) { pm.add(createMenuItem(actions[i])); subMenu = new JMenu(pasiveAnnos[i].getAnnotationTypeInstance().getDescription()); for (int j = 0; j < actions.length; j++) subMenu.add(createMenuItem(actions[j])); if (separator) { separator = false; subMenu = new JMenu(type.getDescription()); for (int j = 0; j < actions.length; j++) subMenu.add(createMenuItem(actions[j])); if (separator) { separator = false;
AnnotationDesc anno = doc.getAnnotations().getActiveAnnotation(mark); if (anno == null) { AnnotationDesc activeAnno = doc.getAnnotations().getLineActiveAnnotation(mark); if (activeAnno == null) return false;
/** Checks the number of inserted lines and recalculate * LineAnnotations.line property */ public void insertUpdate(DocumentEvent e) { BaseDocumentEvent be = (BaseDocumentEvent)e; int countOfInsertedLines = be.getLFCount(); if (countOfInsertedLines == 0) return; /* #33165 - line in line-annotations handled in a different way int changedLine = be.getLine(); LineAnnotations annos; LineAnnotations current = null; for (int i=0; i<lineAnnotationsArray.size(); i++) { annos = (LineAnnotations)lineAnnotationsArray.get(i); if (annos.getLine() == changedLine && annos.getActive().getOffset() > e.getOffset()) current = annos; if (annos.getLine() > changedLine) annos.setLine(annos.getLine()+countOfInsertedLines); } if (current != null) current.setLine(current.getLine()+countOfInsertedLines); */ // fire event to AnnotationsListeners that everything should be redraw fireChangedAll(); }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { try { Caret caret = target.getCaret(); BaseDocument doc = Utilities.getDocument(target); int caretLine = Utilities.getLineOffset(doc, caret.getDot()); AnnotationDesc aDesc = doc.getAnnotations().activateNextAnnotation(caretLine); } catch (BadLocationException e) { e.printStackTrace(); } } } }
/** Notify view that it is necessary to redraw the line of the document */ protected void refreshLine(int line) { fireChangedLine(line); int start = Utilities.getRowStartFromLineOffset(doc, line); int end = Utilities.getRowStartFromLineOffset(doc, line + 1); if (end == -1) end = doc.getLength(); doc.repaintBlock(start, end); }
public GlyphGutter(EditorUI editorUI) { super(); this.editorUI = editorUI; init = false; doc = editorUI.getDocument(); annos = doc.getAnnotations(); // Annotations class is model for this view, so the listener on changes // in // Annotations must be added here annos.addAnnotationsListener(this); // do initialization init(); update(); }
int line = rootElem.getElementIndex(view.getStartOffset()); int lineWithAnno = annos.getNextLineWithAnnotation(line); int count = annos.getNumberOfAnnotations(line); AnnotationDesc anno = annos.getActiveAnnotation(line); lineWithAnno = annos.getNextLineWithAnnotation(line+1);
@Override public void run() { int dot = comp.getCaret().getDot(); Annotations annotations = ((BaseDocument) document).getAnnotations(); Line line = NbEditorUtilities.getLine(document, dot, false); if (line == null) { return ; } int lineNumber = line.getLineNumber(); AnnotationDesc desc = annotations.getActiveAnnotation(lineNumber); values[0] = lineNumber; values[1] = desc; } });
public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName() == AnnotationDesc.PROP_ANNOTATION_TYPE) { AnnotationDesc anno = (AnnotationDesc) evt.getSource(); LineAnnotations lineAnnos = (LineAnnotations) lineAnnotationsByMark.get(anno.getMark()); lineAnnos.refreshAnnotations(); refreshLine(lineAnnos.getLine()); } if (evt.getPropertyName() == AnnotationDesc.PROP_MOVE_TO_FRONT) { AnnotationDesc anno = (AnnotationDesc) evt.getSource(); frontAnnotation(anno); } } };
private void initMenu(JMenu pm, BaseKit kit, int line){ LineAnnotations annos = getLineAnnotations(line); Map types = new HashMap(AnnotationTypes.getTypes().getVisibleAnnotationTypeNamesCount() * 4/3); subMenu = new JMenu(anno.getAnnotationTypeInstance().getDescription()); for (int j=0; j<actions.length; j++) subMenu.add(createMenuItem(actions[j], kit)); subMenu = new JMenu(pasiveAnnos[i].getAnnotationTypeInstance().getDescription()); for (int j=0; j<actions.length; j++) subMenu.add(createMenuItem(actions[j], kit)); if (separator) { separator = false; subMenu = new JMenu(type.getDescription()); for (int j=0; j<actions.length; j++) subMenu.add(createMenuItem(actions[j], kit)); if (separator) { separator = false;
public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName() == AnnotationTypes.PROP_COMBINE_GLYPHS) { LineAnnotations lineAnnos; for (Iterator it = lineAnnotationsArray.iterator(); it.hasNext();) { lineAnnos = (LineAnnotations) it.next(); lineAnnos.refreshAnnotations(); } } if (evt.getPropertyName() == AnnotationTypes.PROP_ANNOTATION_TYPES) { LineAnnotations lineAnnos; for (Iterator it = lineAnnotationsArray.iterator(); it.hasNext();) { lineAnnos = (LineAnnotations) it.next(); for (Iterator it2 = lineAnnos.getAnnotations(); it2.hasNext();) { AnnotationDesc anno = (AnnotationDesc) it2.next(); anno.updateAnnotationType(); } } } fireChangedAll(); } });
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { try { Caret caret = target.getCaret(); BaseDocument doc = Utilities.getDocument(target); int caretLine = Utilities.getLineOffset(doc, caret.getDot()); AnnotationDesc aDesc = doc.getAnnotations().activateNextAnnotation(caretLine); } catch (BadLocationException e) { e.printStackTrace(); } } } }