Refine search
public static void setStatusText(JTextComponent c, String text) { StatusBar sb = getEditorUI(c).getStatusBar(); if (sb != null) { sb.setText(StatusBar.CELL_MAIN, text); } }
/** * Makes the bar visible and sensitive to * LogOutoutListener events that should deliver * actual content to be displayed. */ public void annotate() { annotated = true; elementAnnotations = Collections.<Element, AnnotateLine>emptyMap(); doc.addDocumentListener(this); textComponent.addComponentListener(this); editorUI.addPropertyChangeListener(this); revalidate(); // resize the component }
public boolean expandString(char typedChar, String expandStr, ActionEvent evt) throws BadLocationException { if (expandString(expandStr, evt)) { if (addTypedAcceptor.accept(typedChar)) { int dotPos = editorUI.getComponent().getCaret().getDot(); editorUI.getDocument().insertString(dotPos, String.valueOf(typedChar), null); } return true; } return false; }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { EditorUI editorUI = Utilities.getEditorUI(target); Rectangle bounds = editorUI.getExtentBounds(); bounds.y -= editorUI.getLineHeight(); bounds.x += editorUI.getTextMargin().left; editorUI.scrollRectToVisible(bounds, EditorUI.SCROLL_SMALLEST); } }
void checkLineLimit() { BaseDocument doc = getDocument(); if (doc != null) { Integer lineLimit = (Integer) doc.getProperty(BaseDocument.LINE_LIMIT_PROP); if (lineLimit != null) { if (component != null) { // Not using FM cache - could be called too early FontMetrics fm = component.getFontMetrics(getDefaultColoring().getFont()); if (fm != null) { int charWidth = fm.stringWidth("A"); updateVirtualWidth(charWidth * lineLimit.intValue() + lineNumberWidth); } } } } }
/** Called when UI is being installed into JTextComponent */ public void install(JTextComponent c) { component = c; component.addPropertyChangeListener(this); focusListener = new FocusHandler(this); component.addFocusListener(focusListener); component.addMouseListener(this); component.addMouseMotionListener(this); EditorUI editorUI = Utilities.getEditorUI(component); editorUI.addLayer(new DrawLayerFactory.CaretLayer(), DrawLayerFactory.CARET_LAYER_VISIBILITY); caretMark.setEditorUI(editorUI); selectionMark.setEditorUI(editorUI); editorUI.addPropertyChangeListener(this); BaseDocument doc = Utilities.getDocument(c); if (doc != null) { modelChanged(null, doc); } if (component.hasFocus()) { focusGained(null); // emulate focus gained if (debugCaretFocus) { System.err.println("Component has focus, calling focusGained() on doc=" + component.getDocument().getProperty(Document.TitleProperty)); } } }
boolean back = (b != null && b.booleanValue()); if (back) { pos = doc.find(finder, dot, 0); // !!! handle wrap pos = doc.find(finder, dot, -1); // !!! handle wrap BaseTextUI ui = (BaseTextUI) c.getUI(); EditorUI editorUI = ui.getEditorUI(); DrawLayerFactory.IncSearchLayer incLayer = (DrawLayerFactory.IncSearchLayer) editorUI.findLayer(DrawLayerFactory.INC_SEARCH_LAYER_NAME); if (incLayer == null) { incLayer = new DrawLayerFactory.IncSearchLayer(); if (!editorUI.addLayer(incLayer, DrawLayerFactory.INC_SEARCH_LAYER_VISIBILITY)) { return false; // couldn't add layer incLayer.setEnabled(false); try { editorUI.repaintOffset(incLayer.getOffset()); } catch (BadLocationException e) { if (Boolean.getBoolean("netbeans.debug.exceptions")) { // NOI18N Rectangle r = (Rectangle) ui.modelToView(c, pos + len, null); r.add(r0); editorUI.repaintOffset(pos); editorUI.scrollRectToVisible(r, EditorUI.SCROLL_DEFAULT); } catch (BadLocationException e) { if (Boolean.getBoolean("netbeans.debug.exceptions")) { // NOI18N
Utilities.annotateLoggable(e); return false; BaseTextUI ui = (BaseTextUI)c.getUI(); EditorUI editorUI = ui.getEditorUI(); DrawLayerFactory.IncSearchLayer incLayer = (DrawLayerFactory.IncSearchLayer)editorUI.findLayer( DrawLayerFactory.INC_SEARCH_LAYER_NAME); if (incLayer == null) { incLayer = new DrawLayerFactory.IncSearchLayer(); if (!editorUI.addLayer(incLayer, DrawLayerFactory.INC_SEARCH_LAYER_VISIBILITY) ) { incLayer.setEnabled(false); try { editorUI.repaintOffset(incLayer.getOffset()); } catch (BadLocationException e) { Utilities.annotateLoggable(e); Rectangle r = (Rectangle)ui.modelToView(c, pos + len, null); r.add(r0); editorUI.repaintOffset(pos);
public boolean isActive(DrawContext ctx, MarkFactory.DrawMark mark) { boolean active; if (mark != null) { active = mark.activateLayer; } else { JTextComponent c = ctx.getEditorUI().getComponent(); active = (c != null) && c.getCaret().isSelectionVisible() && ctx.getFragmentOffset() >= c.getSelectionStart() && ctx.getFragmentOffset() < c.getSelectionEnd(); } return active; }
annos.activateNextAnnotation(line); } else { Action actions[] = ImplementationProvider.getDefault().getGlyphGutterActions(editorUI.getComponent()); if (actions != null && actions.length >0) { Action a = actions[0]; //TODO - create GUI chooser if (line == -1) return; try { currentLine = Utilities.getLineOffset(doc, editorUI.getComponent().getCaret().getDot()); } catch (BadLocationException ex) { return; int offset = Utilities.getRowStartFromLineOffset(doc, line); JumpList.checkAddEntry(); editorUI.getComponent().getCaret().setDot(offset); a.actionPerformed(new ActionEvent(editorUI.getComponent(), 0, "")); repaint();
/** Expand abbreviation on current caret position. * Remove characters back to the word start and insert expanded abbreviation. * @return whether the typed character should be added to the abbreviation or not */ public boolean expandString(String expandStr, ActionEvent evt) throws BadLocationException { boolean expanded = false; BaseDocument doc = editorUI.getDocument(); doc.atomicLock(); try { Caret caret = editorUI.getComponent().getCaret(); int pos = caret.getDot() - expandStr.length(); doc.remove(pos, expandStr.length()); expanded = doExpansion(pos, expandStr, evt); } finally { if (expanded) { reset(); } else { doc.breakAtomicLock(); } doc.atomicUnlock(); } return expanded; }
public String getExpandString() { BaseDocument doc = (BaseDocument) editorUI.getDocument(); String abbrevStr = getAbbrevString(); int abbrevStrLen = abbrevStr.length(); Object expansion = translateAbbrev(abbrevStr); Caret caret = editorUI.getComponent().getCaret(); int dotPos = caret.getDot(); if (abbrevStr != null && expansion != null && dotPos >= abbrevStrLen) { if (checkDocText) { try { String prevChars = doc.getText(dotPos - abbrevStrLen, abbrevStrLen); if (prevChars.equals(abbrevStr)) { // abbrev chars really // match text if (!checkTextDelimiter || dotPos == abbrevStrLen || resetAcceptor.accept(doc.getChars(dotPos - abbrevStrLen - 1, 1)[0])) { return abbrevStr; } } } catch (BadLocationException e) { } } } return null; }
public JMenuItem getPopupMenuItem(JTextComponent target) { EditorUI ui = Utilities.getEditorUI(target); try { return ui.getDocument().getAnnotations().createMenu(Utilities.getKit(target), Utilities.getLineOffset(ui.getDocument(),target.getCaret().getDot())); } catch (BadLocationException ex) { return null; } }
offset = annos.getActiveAnnotation(line).getOffset(); else offset = Utilities.getRowStartFromLineOffset(doc, line); if (editorUI.getComponent().getCaret().getDot() != offset) 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());
/** Called when the <tt>BaseTextUI</tt> is being uninstalled * from the component. */ protected void uninstallUI(JTextComponent c) { synchronized (getComponentLock()) { // fix for issue 12996 if (component != null) { // stop listening on caret Caret caret = component.getCaret(); if (caret != null) { caret.removeChangeListener(this); } // stop listening on component component.removePropertyChangeListener(this); component.removeFocusListener(focusL); } BaseDocument doc = getDocument(); if (doc != null) { modelChanged(doc, null); } component = null; putProperty(COMPONENT_PROPERTY, null); // Clear the font-metrics cache FontMetricsCache.clear(); } }
protected boolean doExpansion(int dotPos, String expandStr, ActionEvent evt) throws BadLocationException { Object expansion = translateAbbrev(expandStr); boolean expanded = false; if (expansion instanceof String) { // expand to string BaseDocument doc = editorUI.getDocument(); String ins = (String) expansion; int offset = ins.indexOf('|'); if (offset >= 0) { if (offset > 0) doc.insertString(dotPos, ins.substring(0, offset), null); if (offset + 1 < ins.length()) doc.insertString(dotPos + offset, ins.substring(offset + 1), null); Caret caret = editorUI.getComponent().getCaret(); caret.setDot(dotPos + offset); } else { doc.insertString(dotPos, ins, null); } expanded = true; } else if (expansion instanceof Action) { ((Action) expansion).actionPerformed(evt); expanded = true; } return expanded; }
public void actionPerformed(ActionEvent evt) { Caret c = caret; JTextComponent component = editorUI.getComponent(); if (component != null) { if (c != null) { BaseDocument doc = Utilities.getDocument(editorUI.getComponent()); if (doc != null) { int pos = c.getDot(); String s = Utilities.debugPosition(doc, pos); setText(CELL_POSITION, s); } } Boolean b = (Boolean) editorUI.getProperty(EditorUI.OVERWRITE_MODE_PROPERTY); boolean om = (b != null && b.booleanValue()); if (om != overwriteModeDisplayed) { overwriteModeDisplayed = om; setText(CELL_TYPING_MODE, overwriteModeDisplayed ? ovrText : insText); } } }
StatusBar statusBar = editorUI.getStatusBar(); recentStatusMessage = loc.getString("CTL_StatusBar_WaitFetchAnnotation"); // NOI18N statusBar.setText(StatusBar.CELL_MAIN, recentStatusMessage); int offset = caret.getDot(); try { line = Utilities.getLineOffset(doc, offset); } catch (BadLocationException ex) { Mercurial.LOG.log(Level.SEVERE, "Can not get line for caret at offset ", offset); // NOI18N
/** * Creates new instance initializing final fields. */ public AnnotationBar(JTextComponent target) { this.textComponent = target; this.editorUI = Utilities.getEditorUI(target); this.foldHierarchy = FoldHierarchy.get(editorUI.getComponent()); this.doc = editorUI.getDocument(); this.caret = textComponent.getCaret(); setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); elementAnnotationsSubstitute = ""; //NOI18N if (textComponent instanceof JEditorPane) { String mimeType = org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(textComponent); FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class); renderingHints = (Map) fcs.getFontColors(FontColorNames.DEFAULT_COLORING).getAttribute(EditorStyleConstants.RenderingHints); } else { renderingHints = null; } }
private int getLineFromMouseEvent(MouseEvent e){ int line = -1; if (editorUI != null) { try{ JTextComponent component = editorUI.getComponent(); BaseTextUI textUI = (BaseTextUI)component.getUI(); int clickOffset = textUI.viewToModel(component, new Point(0, e.getY())); line = Utilities.getLineOffset(doc, clickOffset); }catch (BadLocationException ble){ } } return line; }