本文整理匯總了Java中javax.swing.text.Element.getAttributes方法的典型用法代碼示例。如果您正苦於以下問題:Java Element.getAttributes方法的具體用法?Java Element.getAttributes怎麽用?Java Element.getAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.text.Element
的用法示例。
在下文中一共展示了Element.getAttributes方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mouseClicked
import javax.swing.text.Element; //導入方法依賴的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: setElementProperties
import javax.swing.text.Element; //導入方法依賴的package包/類
void setElementProperties(Element el, String id, String cls, String sty) {
ElementDialog dlg = new ElementDialog(null);
//dlg.setLocation(linkActionB.getLocationOnScreen());
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = this.getSize();
Point loc = this.getLocationOnScreen();
dlg.setLocation(
(frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.setTitle(Local.getString("Object properties"));
dlg.idField.setText(id);
dlg.classField.setText(cls);
dlg.styleField.setText(sty);
// Uncommented, returns a simple p into the header... fix needed ?
//dlg.header.setText(el.getName());
dlg.setVisible(true);
if (dlg.CANCELLED)
return;
SimpleAttributeSet attrs = new SimpleAttributeSet(el.getAttributes());
if (dlg.idField.getText().length() > 0)
attrs.addAttribute(HTML.Attribute.ID, dlg.idField.getText());
if (dlg.classField.getText().length() > 0)
attrs.addAttribute(HTML.Attribute.CLASS, dlg.classField.getText());
if (dlg.styleField.getText().length() > 0)
attrs.addAttribute(HTML.Attribute.STYLE, dlg.styleField.getText());
document.setParagraphAttributes(el.getStartOffset(), 0, attrs, true);
}
示例3: mouseMoved
import javax.swing.text.Element; //導入方法依賴的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: setElementProperties
import javax.swing.text.Element; //導入方法依賴的package包/類
void setElementProperties(Element el, String id, String cls, String sty) {
ElementDialog dlg = new ElementDialog(null);
//dlg.setLocation(linkActionB.getLocationOnScreen());
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = this.getSize();
Point loc = this.getLocationOnScreen();
dlg.setLocation(
(frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.setTitle(Local.getString("Object properties"));
dlg.idField.setText(id);
dlg.classField.setText(cls);
dlg.styleField.setText(sty);
// Uncommented, returns a simple p into the header... fix needed ?
//dlg.header.setText(el.getName());
dlg.setVisible(true);
if (dlg.CANCELLED)
return;
SimpleAttributeSet attrs = new SimpleAttributeSet(el.getAttributes());
if (dlg.idField.getText().length() > 0)
attrs.addAttribute(HTML.Attribute.ID, dlg.idField.getText());
if (dlg.classField.getText().length() > 0)
attrs.addAttribute(HTML.Attribute.CLASS, dlg.classField.getText());
if (dlg.styleField.getText().length() > 0)
attrs.addAttribute(HTML.Attribute.STYLE, dlg.styleField.getText());
document.setParagraphAttributes(el.getStartOffset(), 0, attrs, true);
}
示例5: emptyTag
import javax.swing.text.Element; //導入方法依賴的package包/類
/**
* Writes out all empty elements (all tags that have no
* corresponding end tag).
*
* @param elem an Element
* @exception IOException on any I/O error
* @exception BadLocationException if pos represents an invalid
* location within the document.
*/
protected void emptyTag(Element elem) throws BadLocationException, IOException {
if (!inContent && !inPre) {
indent();
}
AttributeSet attr = elem.getAttributes();
closeOutUnwantedEmbeddedTags(attr);
writeEmbeddedTags(attr);
if (matchNameAttribute(attr, HTML.Tag.CONTENT)) {
inContent = true;
text(elem);
}
else if (matchNameAttribute(attr, HTML.Tag.COMMENT)) {
comment(elem);
}
else {
boolean isBlock = isBlockTag(elem.getAttributes());
if (inContent && isBlock) {
writeLineSeparator();
indent();
}
Object nameTag = (attr != null) ? attr.getAttribute(StyleConstants.NameAttribute) : null;
Object endTag = (attr != null) ? attr.getAttribute(HTML.Attribute.ENDTAG) : null;
boolean outputEndTag = false;
// If an instance of an UNKNOWN Tag, or an instance of a
// tag that is only visible during editing
//
if (nameTag != null && endTag != null && (endTag instanceof String) && ((String) endTag).equals("true")) {
outputEndTag = true;
}
if (completeDoc && matchNameAttribute(attr, HTML.Tag.HEAD)) {
if (outputEndTag) {
// Write out any styles.
writeStyles(((HTMLDocument) getDocument()).getStyleSheet());
}
wroteHead = true;
}
write('<');
if (outputEndTag) {
write('/');
}
write(elem.getName());
writeAttributes(attr);
write('>');
if (matchNameAttribute(attr, HTML.Tag.TITLE) && !outputEndTag) {
Document doc = elem.getDocument();
String title = (String) doc.getProperty(Document.TitleProperty);
write(title);
}
else if (!inContent || isBlock) {
writeLineSeparator();
if (isBlock && inContent) {
indent();
}
}
}
}
示例6: emptyTag
import javax.swing.text.Element; //導入方法依賴的package包/類
/**
* Writes out all empty elements (all tags that have no
* corresponding end tag).
*
* @param elem an Element
* @exception IOException on any I/O error
* @exception BadLocationException if pos represents an invalid
* location within the document.
*/
protected void emptyTag(Element elem) throws BadLocationException, IOException {
if (!inContent && !inPre) {
indent();
}
AttributeSet attr = elem.getAttributes();
closeOutUnwantedEmbeddedTags(attr);
writeEmbeddedTags(attr);
if (attr != null && matchNameAttribute(attr, HTML.Tag.CONTENT)) {
inContent = true;
text(elem);
}
else if (attr != null && matchNameAttribute(attr, HTML.Tag.COMMENT)) {
comment(elem);
}
else {
boolean isBlock = isBlockTag(elem.getAttributes());
if (inContent && isBlock) {
writeLineSeparator();
indent();
}
Object nameTag = (attr != null) ? attr.getAttribute(StyleConstants.NameAttribute) : null;
Object endTag = (attr != null) ? attr.getAttribute(HTML.Attribute.ENDTAG) : null;
boolean outputEndTag = false;
// If an instance of an UNKNOWN Tag, or an instance of a
// tag that is only visible during editing
//
if (nameTag != null && endTag != null && (endTag instanceof String) && ((String) endTag).equals("true")) {
outputEndTag = true;
}
if (completeDoc && matchNameAttribute(attr, HTML.Tag.HEAD)) {
if (outputEndTag) {
// Write out any styles.
writeStyles(((HTMLDocument) getDocument()).getStyleSheet());
}
wroteHead = true;
}
write('<');
if (outputEndTag) {
write('/');
}
write(elem.getName());
writeAttributes(attr);
write('>');
if (attr != null && matchNameAttribute(attr, HTML.Tag.TITLE) && !outputEndTag) {
Document doc = elem.getDocument();
String title = (String) doc.getProperty(Document.TitleProperty);
write(title);
}
else if (!inContent || isBlock) {
writeLineSeparator();
if (isBlock && inContent) {
indent();
}
}
}
}
示例7: setFontProperties
import javax.swing.text.Element; //導入方法依賴的package包/類
String setFontProperties(Element el, String text) {
FontDialog dlg = new FontDialog(null);
//dlg.setLocation(editor.getLocationOnScreen());
Dimension dlgSize = dlg.getSize();
Dimension frmSize = this.getSize();
Point loc = this.getLocationOnScreen();
dlg.setLocation(
(frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
AttributeSet ea = el.getAttributes();
/*
* if (ea.isDefined(HTML.Tag.FONT)) { String[] param =
* ea.getAttribute(HTML.Tag.FONT).toString().split(" "); for (int i = 0;
* i < param.length; i++) if (param[i].startsWith("face="))
* dlg.fontFamilyCB.setSelectedItem(param[i].split("=")[1]); else if
* (param[i].startsWith("size="))
* dlg.fontSizeCB.setSelectedItem(param[i].split("=")[1]); else if
* (param[i].startsWith("color=")) {
* dlg.colorField.setText(param[i].split("=")[1]);
* Util.setColorField(dlg.colorField); }
*/
if (ea.isDefined(StyleConstants.FontFamily))
dlg.fontFamilyCB.setSelectedItem(
ea.getAttribute(StyleConstants.FontFamily).toString());
if (ea.isDefined(HTML.Tag.FONT)) {
String s = ea.getAttribute(HTML.Tag.FONT).toString();
String size =
s.substring(s.indexOf("size=") + 5, s.indexOf("size=") + 6);
dlg.fontSizeCB.setSelectedItem(size);
}
if (ea.isDefined(StyleConstants.Foreground)) {
dlg.colorField.setText(
Util.encodeColor(
(Color) ea.getAttribute(StyleConstants.Foreground)));
Util.setColorField(dlg.colorField);
dlg.sample.setForeground(
(Color) ea.getAttribute(StyleConstants.Foreground));
}
if (text != null)
dlg.sample.setText(text);
dlg.setVisible(true);
if (dlg.CANCELLED)
return null;
String attrs = "";
if (dlg.fontSizeCB.getSelectedIndex() > 0)
attrs += "size=\"" + dlg.fontSizeCB.getSelectedItem() + "\"";
if (dlg.fontFamilyCB.getSelectedIndex() > 0)
attrs += "face=\"" + dlg.fontFamilyCB.getSelectedItem() + "\"";
if (dlg.colorField.getText().length() > 0)
attrs += "color=\"" + dlg.colorField.getText() + "\"";
if (attrs.length() > 0)
return " " + attrs;
else
return null;
}
示例8: getOffsetY
import javax.swing.text.Element; //導入方法依賴的package包/類
private int getOffsetY(int rowStartOffset, FontMetrics fontMetrics)
throws BadLocationException
{
// Get the bounding rectangle of the row
Rectangle r = component.modelToView( rowStartOffset );
int lineHeight = fontMetrics.getHeight();
int y = r.y + r.height;
int descent = 0;
// The text needs to be positioned above the bottom of the bounding
// rectangle based on the descent of the font(s) contained on the row.
if (r.height == lineHeight) // default font is being used
{
descent = fontMetrics.getDescent();
}
else // We need to check all the attributes for font changes
{
if (fonts == null)
fonts = new HashMap<String, FontMetrics>();
Element root = component.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 = component.getFontMetrics( font );
fonts.put(key, fm);
}
descent = Math.max(descent, fm.getDescent());
}
}
return y - descent;
}