当前位置: 首页>>代码示例>>Java>>正文


Java JTextPane.getStyledDocument方法代码示例

本文整理汇总了Java中javax.swing.JTextPane.getStyledDocument方法的典型用法代码示例。如果您正苦于以下问题:Java JTextPane.getStyledDocument方法的具体用法?Java JTextPane.getStyledDocument怎么用?Java JTextPane.getStyledDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTextPane的用法示例。


在下文中一共展示了JTextPane.getStyledDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mouseClicked

import javax.swing.JTextPane; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
    try {
        if (SwingUtilities.isLeftMouseButton(e)) {
            JTextPane pane = (JTextPane)e.getSource();
            StyledDocument doc = pane.getStyledDocument();
            Element elem = doc.getCharacterElement(pane.viewToModel(e.getPoint()));
            AttributeSet as = elem.getAttributes();
            Link link = (Link)as.getAttribute(LINK_ATTRIBUTE);
            if (link != null) {
                link.onClick(elem.getDocument().getText(elem.getStartOffset(), elem.getEndOffset() - elem.getStartOffset()));
            }
        }
    } catch(Exception ex) {
        Support.LOG.log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:HyperlinkSupport.java

示例2: addDate

import javax.swing.JTextPane; //导入方法依赖的package包/类
private void addDate (JTextPane pane, RevisionItem item, boolean selected, Collection<SearchHighlight> highlights) throws BadLocationException {

            LogEntry entry = item.getUserData();
            StyledDocument sd = pane.getStyledDocument();
            // clear document
            clearSD(pane, sd);

            Style selectedStyle = createSelectedStyle(pane);
            Style normalStyle = createNormalStyle(pane);
            Style style;
            if (selected) {
                style = selectedStyle;
            } else {
                style = normalStyle;
            }

            // add date
            sd.insertString(sd.getLength(), entry.getDate(), style);
        }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:SummaryCellRenderer.java

示例3: mouseMoved

import javax.swing.JTextPane; //导入方法依赖的package包/类
@Override
public void mouseMoved(MouseEvent e) {
    JTextPane pane = (JTextPane)e.getSource();
    StyledDocument doc = pane.getStyledDocument();
    Element elem = doc.getCharacterElement(pane.viewToModel(e.getPoint()));
    AttributeSet as = elem.getAttributes();
    if (StyleConstants.isUnderline(as)) {
        pane.setCursor(new Cursor(Cursor.HAND_CURSOR));
    } else {
        pane.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:HyperlinkSupport.java

示例4: register

import javax.swing.JTextPane; //导入方法依赖的package包/类
static void register(final JTextPane pane) {
    final StyledDocument doc = pane.getStyledDocument();
    String text = "";
    try {
        text = doc.getText(0, doc.getLength());
    } catch (BadLocationException ex) {
        Support.LOG.log(Level.SEVERE, null, ex);
    }
    final int[] boundaries = findBoundaries(text);
    if ((boundaries != null) && (boundaries.length != 0)) {

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                Style defStyle = StyleContext.getDefaultStyleContext()
                                 .getStyle(StyleContext.DEFAULT_STYLE);
                final Style hlStyle = doc.addStyle("regularBlue-url", defStyle);      //NOI18N
                hlStyle.addAttribute(HyperlinkSupport.URL_ATTRIBUTE, new UrlAction());
                StyleConstants.setForeground(hlStyle, UIUtils.getLinkColor());
                StyleConstants.setUnderline(hlStyle, true);
                for (int i = 0; i < boundaries.length; i+=2) {
                    doc.setCharacterAttributes(boundaries[i], boundaries[i + 1] - boundaries[i], hlStyle, true);
                }
                pane.removeMouseListener(getUrlMouseListener());
                pane.addMouseListener(getUrlMouseListener());
            }
        });
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:WebUrlHyperlinkSupport.java

示例5: setVisible

import javax.swing.JTextPane; //导入方法依赖的package包/类
@Override
public void setVisible(boolean b) {
    if (b) {
        JTextPane pane = (JTextPane) getInvoker();
        StyledDocument doc = pane.getStyledDocument();
        Element elem = doc.getCharacterElement(pane.viewToModel(clickPoint));
        Object l = elem.getAttributes().getAttribute(HyperlinkSupport.LINK_ATTRIBUTE);
        if (l != null && l instanceof AttachmentLink) {
            BugzillaIssue.Attachment attachment = ((AttachmentLink) l).attachment;
            if (attachment != null) {
                add(new JMenuItem(attachment.getOpenAction()));
                add(new JMenuItem(attachment.getSaveAction()));
                Action openInStackAnalyzerAction = attachment.getOpenInStackAnalyzerAction();
                if(openInStackAnalyzerAction != null) {
                    add(new JMenuItem(openInStackAnalyzerAction));
                }
                if (attachment.isPatch()) { 
                    Action a = attachment.getApplyPatchAction();
                    if(a != null) {
                        add(attachment.getApplyPatchAction());
                    }
                }
                super.setVisible(true);
            }
        }
    } else {
        super.setVisible(false);
        removeAll();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:CommentsPanel.java

示例6: LicenseWindow

import javax.swing.JTextPane; //导入方法依赖的package包/类
/**
 * Create the frame.
 */
public LicenseWindow(final String path) {
	
	setTitle("Coder HPMSA - [License]");
	setBounds(100, 100, 550, 550);
	setBackground(Color.decode("#066d95"));
	setLocationRelativeTo(null);
	setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
	
	this.setIconImage(Toolkit.getDefaultToolkit().
			getImage(getClass().getResource(LOGOPATH)));
	
	final JScrollPane scrollPane = new JScrollPane();
	scrollPane.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
	getContentPane().add(scrollPane, BorderLayout.CENTER);
	
	editorPane = new JTextPane();
	editorPane.setBackground(new Color(255, 255, 240));
	editorPane.setFont(new Font("Verdana", Font.PLAIN, 13));
	editorPane.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null));
	editorPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
	editorPane.setEditable(false);
	scrollPane.setViewportView(editorPane);
	
	final StyledDocument doc = editorPane.getStyledDocument();
	final SimpleAttributeSet center = new SimpleAttributeSet();
	StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
	doc.setParagraphAttributes(0, doc.getLength()-1, center, false);
	
	fillEditorPane(path);
	setVisible(true);
}
 
开发者ID:Coder-ACJHP,项目名称:Hotel-Properties-Management-System,代码行数:35,代码来源:LicenseWindow.java

示例7: initializeComponents

import javax.swing.JTextPane; //导入方法依赖的package包/类
private void initializeComponents() {
	infoPane		= new JTextPane();
	infoPane.setText("You are using version "+version+" but the current version is " +CalebKussmaul.getLatestVersion(p)+". It is strongly reccomended that you update to take advantage of the latest additions and fixes.");
	
	StyledDocument doc = infoPane.getStyledDocument();
	SimpleAttributeSet center = new SimpleAttributeSet();
	StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
	doc.setParagraphAttributes(0, doc.getLength(), center, false);
	
	infoPane.setEditable(false);
	infoPane.setOpaque(false);
	updateButton 	= new JButton("Download update...");
}
 
开发者ID:CalebKussmaul,项目名称:GIFKR,代码行数:14,代码来源:UpdateFrame.java

示例8: insert

import javax.swing.JTextPane; //导入方法依赖的package包/类
public static void insert(JTextPane interpreter, String text, Color color) {
	StyledDocument doc = interpreter.getStyledDocument();
	Style style = interpreter.addStyle("Style", null);
       StyleConstants.setForeground(style, color);
       try {
		doc.insertString(doc.getLength(), text ,style);
		//((AbstractDocument)interpreter.getDocument()).setDocumentFilter(new NonEditableLineDocumentFilter());
	} catch (BadLocationException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} 
   	//doc.insertString( doc.getEndPosition().getOffset(), "Hello you can't edit this!", null );
       
}
 
开发者ID:BlidiWajdi,项目名称:Mujeed-Arabic-Prolog,代码行数:15,代码来源:FromGui.java

示例9: removelast

import javax.swing.JTextPane; //导入方法依赖的package包/类
public static void removelast(JTextPane interpreter, int i) {
	StyledDocument doc = interpreter.getStyledDocument();
	Style style = interpreter.addStyle("Style", null);
       try { 
       	doc.remove(doc.getLength()-i, i);
       }
       catch (BadLocationException ex){}
}
 
开发者ID:BlidiWajdi,项目名称:Mujeed-Arabic-Prolog,代码行数:9,代码来源:FromGui.java

示例10: mouseMoved

import javax.swing.JTextPane; //导入方法依赖的package包/类
@Override
    public void mouseMoved(MouseEvent e) {
        JTextPane pane = (JTextPane)e.getSource();
        StyledDocument doc = pane.getStyledDocument();

        int offset = pane.viewToModel(e.getPoint());
        Element elem = doc.getCharacterElement(offset);

        Highlight h = getHighlight(pane, offset);
        Highlight prevHighlight = (Highlight) pane.getClientProperty(PREV_HIGHLIGHT_PROPERTY);
        AttributeSet prevAs = (AttributeSet) pane.getClientProperty(PREV_HIGHLIGHT_ATTRIBUTES);
//        if(h != null && h.equals(prevHighlight)) {
//            return; // nothing to do
//        } else 
        if(prevHighlight != null && prevAs != null) {
            doc.setCharacterAttributes(prevHighlight.startOffset, prevHighlight.endOffset - prevHighlight.startOffset, prevAs, true);
            pane.putClientProperty(PREV_HIGHLIGHT_PROPERTY, null);
            pane.putClientProperty(PREV_HIGHLIGHT_ATTRIBUTES, null);
        }

        int modifiers = e.getModifiers() | e.getModifiersEx();
        if ( (modifiers & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK ||
             (modifiers & InputEvent.META_DOWN_MASK) == InputEvent.META_DOWN_MASK) 
        {            
            AttributeSet as = elem.getAttributes();
            if (StyleConstants.isUnderline(as)) {
                // do not underline whats already underlined
                return;
            }

            Font font = doc.getFont(as);
            FontMetrics fontMetrics = pane.getFontMetrics(font);
            try {
                Rectangle rectangle = new Rectangle(
                        pane.modelToView(elem.getStartOffset()).x,
                        pane.modelToView(elem.getStartOffset()).y,
                        fontMetrics.stringWidth(doc.getText(elem.getStartOffset(), elem.getEndOffset() - elem.getStartOffset())),
                        fontMetrics.getHeight());

                if (h != null && offset < elem.getEndOffset() - 1 && rectangle.contains(e.getPoint())) {
                    Style hlStyle = doc.getStyle("regularBlue-findtype");               // NOI18N

                    pane.putClientProperty(PREV_HIGHLIGHT_ATTRIBUTES, as.copyAttributes());
                    doc.setCharacterAttributes(h.startOffset, h.endOffset - h.startOffset, hlStyle, true);
    //                doc.setCharacterAttributes(h.startOffset, h.endOffset - h.startOffset, as.copyAttributes(), true);
                    pane.putClientProperty(PREV_HIGHLIGHT_PROPERTY, h);
                } 
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:53,代码来源:FindTypesSupport.java

示例11: element

import javax.swing.JTextPane; //导入方法依赖的package包/类
private Element element(MouseEvent e) {
    JTextPane pane = (JTextPane)e.getSource();
    StyledDocument doc = pane.getStyledDocument();
    return doc.getCharacterElement(pane.viewToModel(e.getPoint()));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:FindTypesSupport.java

示例12: addAuthor

import javax.swing.JTextPane; //导入方法依赖的package包/类
private void addAuthor (JTextPane pane, RevisionItem item, boolean selected, Collection<SearchHighlight> highlights) throws BadLocationException {
    LogEntry entry = item.getUserData();
    StyledDocument sd = pane.getStyledDocument();
    clearSD(pane, sd);
    Style selectedStyle = createSelectedStyle(pane);
    Style normalStyle = createNormalStyle(pane);
    Style style;
    if (selected) {
        style = selectedStyle;
    } else {
        style = normalStyle;
    }
    Style authorStyle = createAuthorStyle(pane, normalStyle);
    Style hiliteStyle = createHiliteStyleStyle(pane, normalStyle, searchHiliteAttrs);
    String author = entry.getAuthor();
    AuthorLinker l = linkerSupport.getLinker(VCSHyperlinkSupport.AuthorLinker.class, id);
    if(l == null) {
        VCSKenaiAccessor.KenaiUser kenaiUser = getKenaiUser(author);
        if (kenaiUser != null) {
            l = new VCSHyperlinkSupport.AuthorLinker(kenaiUser, authorStyle, sd, author);
            linkerSupport.add(l, id);
        }
    }
    int pos = sd.getLength();
    if(l != null) {
        l.insertString(sd, selected ? style : null);
    } else {
        sd.insertString(sd.getLength(), author, style);
    }
    if (!selected) {
        for (SearchHighlight highlight : highlights) {
            if (highlight.getKind() == SearchHighlight.Kind.AUTHOR) {
                int doclen = sd.getLength();
                String highlightMessage = highlight.getSearchText();
                String authorText = sd.getText(pos, doclen - pos).toLowerCase();
                int idx = authorText.indexOf(highlightMessage);
                if (idx > -1) {
                    sd.setCharacterAttributes(doclen - authorText.length() + idx, highlightMessage.length(), hiliteStyle, false);
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:44,代码来源:SummaryCellRenderer.java

示例13: ReadLogsWindow

import javax.swing.JTextPane; //导入方法依赖的package包/类
/**
 * Create the frame.
 */
public ReadLogsWindow() {
	
	setTitle("Coder HPMSA - [Read Logs]");
	setBounds(100, 100, 660, 550);
	setBackground(Color.decode("#066d95"));
	setLocationRelativeTo(null);
	setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
	
	this.setIconImage(Toolkit.getDefaultToolkit().
			getImage(getClass().getResource(LOGOPATH)));
	
	final JScrollPane scrollPane = new JScrollPane();
	scrollPane.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
	getContentPane().add(scrollPane, BorderLayout.CENTER);
	
	editorPane = new JTextPane();
	editorPane.setBackground(new Color(255, 255, 240));
	editorPane.setFont(new Font("Verdana", Font.PLAIN, 13));
	editorPane.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null));
	editorPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
	editorPane.setEditable(false);
	scrollPane.setViewportView(editorPane);
	
	final JPanel filesPanel = new JPanel();
	filesPanel.setPreferredSize(new Dimension(200, 10));
	getContentPane().add(filesPanel, BorderLayout.EAST);
	filesPanel.setLayout(new BorderLayout(0, 0));
	
	final JScrollPane listScrollPane = new JScrollPane();
	listScrollPane.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
	listScrollPane.setViewportView(logFilesList());
	filesPanel.add(listScrollPane, BorderLayout.CENTER);
	
	final JPanel titlePanel = new JPanel();
	titlePanel.setPreferredSize(new Dimension(10, 40));
	titlePanel.setBackground(Color.decode("#066d95"));
	titlePanel.setAutoscrolls(true);
	getContentPane().add(titlePanel, BorderLayout.NORTH);
	titlePanel.setLayout(new BorderLayout(0, 0));
	
	final JLabel lblTitle = new JLabel("SYSTEM LOG RECORDS");
	lblTitle.setHorizontalTextPosition(SwingConstants.CENTER);
	lblTitle.setHorizontalAlignment(SwingConstants.CENTER);
	lblTitle.setAutoscrolls(true);
	lblTitle.setFont(new Font("Verdana", Font.BOLD, 25));
	lblTitle.setForeground(UIManager.getColor("Button.highlight"));
	titlePanel.add(lblTitle, BorderLayout.CENTER);
	
	final StyledDocument doc = editorPane.getStyledDocument();
	final SimpleAttributeSet center = new SimpleAttributeSet();
	StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
	doc.setParagraphAttributes(0, doc.getLength(), center, false);
	
	setVisible(true);
}
 
开发者ID:Coder-ACJHP,项目名称:Hotel-Properties-Management-System,代码行数:59,代码来源:ReadLogsWindow.java

示例14: centerText

import javax.swing.JTextPane; //导入方法依赖的package包/类
public static void centerText(JTextPane pane) {
	StyledDocument doc = pane.getStyledDocument();
	SimpleAttributeSet center = new SimpleAttributeSet();
	StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
	doc.setParagraphAttributes(0, doc.getLength(), center, false);
}
 
开发者ID:CalebKussmaul,项目名称:GIFKR,代码行数:7,代码来源:ViewUtils.java

示例15: LoginPanel

import javax.swing.JTextPane; //导入方法依赖的package包/类
public LoginPanel() {
	JTextPane welcome = new JTextPane();
	welcome.setEditable(false);
	welcome.setText(message);
	welcome.setBackground(this.getBackground());
	welcome.setFont(new Font("Arial", Font.BOLD, 16));
	
	//inspired by http://stackoverflow.com/questions/3213045/centering-text-in-a-jtextarea-or-jtextpane-horizontal-text-alignment
	//Centering welcome text
	StyledDocument doc = welcome.getStyledDocument();
	SimpleAttributeSet center = new SimpleAttributeSet();
	StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
	doc.setParagraphAttributes(0, doc.getLength(), center, false);
	
	this.setLayout(new BorderLayout());
	this.add(welcome, BorderLayout.NORTH);
	
	JPanel infoPanel = new JPanel();
	infoPanel.setLayout(new GridLayout(START_ROWS, START_COLUMNS));

	JPanel userPnl = new JPanel();
	JLabel userLbl = new JLabel("Username");
	userPnl.setLayout(new FlowLayout());
	userPnl.add(userLbl);
	userPnl.add(usernameTxt);
	infoPanel.add(userPnl);
	
	JPanel passPnl = new JPanel();
	JLabel passLbl = new JLabel("Password");
	passPnl.setLayout(new FlowLayout());
	passPnl.add(passLbl);
	passPnl.add(passwordTxt);
	infoPanel.add(passPnl);
	
	JPanel signInBtnPnl = new JPanel();
	signInBtnPnl.add(signInBtn);
	infoPanel.add(errorLbl);
	infoPanel.add(signInBtnPnl);
	
	infoPanel.add(new JPanel());
	
	this.add(infoPanel, BorderLayout.SOUTH);

	addImage();
}
 
开发者ID:TeamRedFox,项目名称:PointOfSale,代码行数:46,代码来源:LoginPanel.java


注:本文中的javax.swing.JTextPane.getStyledDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。