Search in sources :

Example 11 with AttributeSet

use of javax.swing.text.AttributeSet in project android-classyshark by google.

the class BatchDocument method appendBatchLineFeed.

public void appendBatchLineFeed(AttributeSet a) {
    batch.add(new ElementSpec(a, ElementSpec.ContentType, EOL_ARRAY, 0, 1));
    Element paragraph = getParagraphElement(0);
    AttributeSet pattern = paragraph.getAttributes();
    batch.add(new ElementSpec(null, ElementSpec.EndTagType));
    batch.add(new ElementSpec(pattern, ElementSpec.StartTagType));
}
Also used : AttributeSet(javax.swing.text.AttributeSet) Element(javax.swing.text.Element)

Example 12 with AttributeSet

use of javax.swing.text.AttributeSet in project gradle by gradle.

the class TextPaneSearchInteraction method highlightText.

/**
     * This highlights the text within the specified range
     *
     * @param startingIndex where to start the highlight
     * @param endingIndex where to end the highlight
     * @param ensureVisible true to scroll to the text
     * @param isEmphasized true to use an emphasized highlight (versus a regular highlight). Useful for showing the 'current' highlighted result.
     */
public void highlightText(int startingIndex, int endingIndex, boolean ensureVisible, boolean isEmphasized) {
    int length = endingIndex - startingIndex;
    AttributeSet style;
    if (isEmphasized) {
        style = emphasizedHighlightStyle;
    } else {
        style = highlightStyle;
    }
    ((DefaultStyledDocument) textComponentToSearch.getDocument()).setCharacterAttributes(startingIndex, length, style, true);
    if (ensureVisible) {
        Utility.scrollToText(textComponentToSearch, startingIndex, endingIndex);
        textComponentToSearch.setCaretPosition(endingIndex);
    }
    textComponentToSearch.repaint();
}
Also used : AttributeSet(javax.swing.text.AttributeSet) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument)

Example 13 with AttributeSet

use of javax.swing.text.AttributeSet in project jphp by jphp-compiler.

the class WrapHyperlinkEvent method __getAttributes.

@Signature
protected Memory __getAttributes(Environment env, Memory... args) {
    AttributeSet attrs = event.getSourceElement().getAttributes();
    List<?> keys = Collections.list(attrs.getAttributeNames());
    ArrayMemory result = new ArrayMemory();
    for (Object key : keys) {
        result.put(key.toString(), new StringMemory(attrs.getAttribute(key).toString()));
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) AttributeSet(javax.swing.text.AttributeSet) StringMemory(php.runtime.memory.StringMemory) Signature(php.runtime.annotation.Reflection.Signature)

Example 14 with AttributeSet

use of javax.swing.text.AttributeSet in project jadx by skylot.

the class LineNumbers method getOffsetY.

private int getOffsetY(int rowStartOffset, FontMetrics fontMetrics) throws BadLocationException {
    Rectangle r = codeArea.modelToView(rowStartOffset);
    if (r == null) {
        throw new BadLocationException("Can't get Y offset", rowStartOffset);
    }
    int lineHeight = fontMetrics.getHeight();
    int y = r.y + r.height;
    int descent = 0;
    if (r.height == lineHeight) {
        descent = fontMetrics.getDescent();
    } else {
        if (fonts == null) {
            fonts = new HashMap<String, FontMetrics>();
        }
        Element root = codeArea.getDocument().getDefaultRootElement();
        int index = root.getElementIndex(rowStartOffset);
        Element line = root.getElement(index);
        for (int i = 0; i < line.getElementCount(); i++) {
            Element child = line.getElement(i);
            AttributeSet as = child.getAttributes();
            String fontFamily = (String) as.getAttribute(StyleConstants.FontFamily);
            Integer fontSize = (Integer) as.getAttribute(StyleConstants.FontSize);
            String key = fontFamily + fontSize;
            FontMetrics fm = fonts.get(key);
            if (fm == null) {
                Font font = new Font(fontFamily, Font.PLAIN, fontSize);
                fm = codeArea.getFontMetrics(font);
                fonts.put(key, fm);
            }
            descent = Math.max(descent, fm.getDescent());
        }
    }
    return y - descent;
}
Also used : AttributeSet(javax.swing.text.AttributeSet) FontMetrics(java.awt.FontMetrics) Element(javax.swing.text.Element) Rectangle(java.awt.Rectangle) BadLocationException(javax.swing.text.BadLocationException) Point(java.awt.Point) Font(java.awt.Font)

Example 15 with AttributeSet

use of javax.swing.text.AttributeSet in project intellij-community by JetBrains.

the class UnusedDeclarationPresentation method getCustomPreviewPanel.

@Override
public JComponent getCustomPreviewPanel(RefEntity entity) {
    final Project project = entity.getRefManager().getProject();
    JEditorPane htmlView = new JEditorPane() {

        @Override
        public String getToolTipText(MouseEvent evt) {
            int pos = viewToModel(evt.getPoint());
            if (pos >= 0) {
                HTMLDocument hdoc = (HTMLDocument) getDocument();
                javax.swing.text.Element e = hdoc.getCharacterElement(pos);
                AttributeSet a = e.getAttributes();
                SimpleAttributeSet value = (SimpleAttributeSet) a.getAttribute(HTML.Tag.A);
                if (value != null) {
                    String objectPackage = (String) value.getAttribute("qualifiedname");
                    if (objectPackage != null) {
                        return objectPackage;
                    }
                }
            }
            return null;
        }
    };
    htmlView.setContentType(UIUtil.HTML_MIME);
    htmlView.setEditable(false);
    htmlView.setOpaque(false);
    htmlView.setBackground(UIUtil.getLabelBackground());
    htmlView.addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        protected void hyperlinkActivated(HyperlinkEvent e) {
            URL url = e.getURL();
            if (url == null) {
                return;
            }
            @NonNls String ref = url.getRef();
            int offset = Integer.parseInt(ref);
            String fileURL = url.toExternalForm();
            fileURL = fileURL.substring(0, fileURL.indexOf('#'));
            VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(fileURL);
            if (vFile == null) {
                vFile = VfsUtil.findFileByURL(url);
            }
            if (vFile != null) {
                final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vFile, offset);
                FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
            }
        }
    });
    final StyleSheet css = ((HTMLEditorKit) htmlView.getEditorKit()).getStyleSheet();
    css.addRule("p.problem-description-group {text-indent: " + JBUI.scale(9) + "px;font-weight:bold;}");
    css.addRule("div.problem-description {margin-left: " + JBUI.scale(9) + "px;}");
    css.addRule("ul {margin-left:" + JBUI.scale(10) + "px;text-indent: 0}");
    css.addRule("code {font-family:" + UIUtil.getLabelFont().getFamily() + "}");
    final StringBuffer buf = new StringBuffer();
    getComposer().compose(buf, entity, false);
    final String text = buf.toString();
    SingleInspectionProfilePanel.readHTML(htmlView, SingleInspectionProfilePanel.toHTML(htmlView, text, false));
    return ScrollPaneFactory.createScrollPane(htmlView, true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MouseEvent(java.awt.event.MouseEvent) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HTMLDocument(javax.swing.text.html.HTMLDocument) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) URL(java.net.URL) SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) Project(com.intellij.openapi.project.Project) StyleSheet(javax.swing.text.html.StyleSheet) AttributeSet(javax.swing.text.AttributeSet) SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) HyperlinkAdapter(com.intellij.ui.HyperlinkAdapter)

Aggregations

AttributeSet (javax.swing.text.AttributeSet)19 Element (javax.swing.text.Element)6 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)6 HTMLDocument (javax.swing.text.html.HTMLDocument)5 BadLocationException (javax.swing.text.BadLocationException)4 Point (java.awt.Point)3 Color (java.awt.Color)2 Font (java.awt.Font)2 FontMetrics (java.awt.FontMetrics)2 Rectangle (java.awt.Rectangle)2 URL (java.net.URL)2 DefaultStyledDocument (javax.swing.text.DefaultStyledDocument)2 Document (javax.swing.text.Document)2 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)2 FormattedCharacterBuffer (com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 HyperlinkAdapter (com.intellij.ui.HyperlinkAdapter)1 Dimension (java.awt.Dimension)1