本文整理汇总了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);
}
}
示例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);
}
示例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));
}
}
示例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());
}
});
}
}
示例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();
}
}
示例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);
}
示例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...");
}
示例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 );
}
示例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){}
}
示例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);
}
}
}
示例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()));
}
示例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);
}
}
}
}
}
示例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);
}
示例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);
}
示例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();
}