javax.swing.text.MutableAttributeSet.copyAttributes()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(60)

本文整理了Java中javax.swing.text.MutableAttributeSet.copyAttributes()方法的一些代码示例,展示了MutableAttributeSet.copyAttributes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MutableAttributeSet.copyAttributes()方法的具体详情如下:
包路径:javax.swing.text.MutableAttributeSet
类名称:MutableAttributeSet
方法名:copyAttributes

MutableAttributeSet.copyAttributes介绍

暂无

代码示例

代码示例来源:origin: chatty/chatty

/**
 * Retrieves a single style from the StyleServer and compares it to
 * the previously saved style.
 * 
 * @param name
 * @return true if the style has changed, false otherwise
 */
private boolean loadStyle(String name) {
  MutableAttributeSet newStyle = styleServer.getStyle(name);
  AttributeSet oldStyle = rawStyles.get(name);
  if (oldStyle != null && oldStyle.isEqual(newStyle)) {
    // Nothing in the style has changed, so nothing further to do
    return false;
  }
  // Save immutable copy of new style for next comparison
  rawStyles.put(name, newStyle.copyAttributes());
  // Add type attribute to the style, so it can be recognized when
  // refreshing the styles in the document
  newStyle.addAttribute(TYPE, name);
  styles.put(name, newStyle);
  return true;
}

代码示例来源:origin: igniterealtime/Spark

/**
 * Inserts a link into the current document.
 *
 * @param link - the link to insert( ex. http://www.javasoft.com )
 * @throws BadLocationException if the location is not available for insertion.
 */
public void insertLink( Document doc, String link ) throws BadLocationException
{
  // Create a new style, based on the style used for generic text, for the link.
  final MutableAttributeSet linkStyle = new SimpleAttributeSet( getMessageStyle().copyAttributes() );
  StyleConstants.setForeground( linkStyle, (Color) UIManager.get( "Link.foreground" ) );
  StyleConstants.setUnderline( linkStyle, true );
  linkStyle.addAttribute( "link", link );
  doc.insertString( doc.getLength(), link, linkStyle );
}

代码示例来源:origin: igniterealtime/Spark

/**
 * Inserts a network address into the current document.
 *
 * @param address - the address to insert( ex. \superpc\etc\file\ OR http://localhost/ )
 * @throws BadLocationException if the location is not available for insertion.
 */
public void insertAddress( Document doc, String address ) throws BadLocationException
{
  // Create a new style, based on the style used for generic text, for the address.
  final MutableAttributeSet addressStyle = new SimpleAttributeSet( getMessageStyle().copyAttributes() );
  StyleConstants.setForeground( addressStyle, (Color) UIManager.get( "Address.foreground" ) );
  StyleConstants.setUnderline( addressStyle, true );
  addressStyle.addAttribute( "link", address );
  doc.insertString( doc.getLength(), address, addressStyle );
}

代码示例来源:origin: beryx/text-io

public void appendToInput(String message, boolean preserveCaretPosition) {
  try {
    document.insertString(document.getLength(), message, textPane.getInputAttributes().copyAttributes());
  } catch (BadLocationException e) {
    e.printStackTrace();
  } catch (Exception e) {
    logger.error("Cannot insert input text", e);
  }
  if(!preserveCaretPosition) {
    textPane.setCaretPosition(document.getLength());
  }
}

代码示例来源:origin: igniterealtime/Spark

public MutableAttributeSet applyMessageStyle( char directive, MutableAttributeSet messageStyle )
{
  final MutableAttributeSet style = new SimpleAttributeSet( messageStyle.copyAttributes() );
  switch ( directive )
  {
    case '*':
      StyleConstants.setBold( style, true );
      break;
    case '_':
      StyleConstants.setItalic( style, true );
      break;
    case '~':
      StyleConstants.setStrikeThrough( style, true );
      break;
    case '`':
      StyleConstants.setFontFamily( style, "Monospaced" );
      break;
    case 'K': // Keyword
      StyleConstants.setForeground( style, ((Color) messageStyle.getAttribute( Foreground )).brighter().brighter().brighter() );
      break;
    default:
      Log.warning( "Cannot apply message style for unrecognized directive: " + directive );
  }
  return style;
}

代码示例来源:origin: beryx/text-io

private OffsetAttrs fixCaretPosition(int offset, AttributeSet attrs) {
  if (!isEditAllowedAt(offset) && (readMode || fakeReadMode)) {
    textPane.setCaretPosition(document.getLength());
    return new OffsetAttrs(document.getLength(), textPane.getInputAttributes().copyAttributes());
  }
  return new OffsetAttrs(offset, attrs);
}

代码示例来源:origin: beryx/text-io

public void replaceInput(String message, boolean preserveCaretPosition) {
  int oldCaretPosition = textPane.getCaretPosition();
  try {
    document.remove(startReadLen, document.getLength() - startReadLen);
    document.insertString(document.getLength(), message, textPane.getInputAttributes().copyAttributes());
  } catch (BadLocationException e) {
    e.printStackTrace();
  } catch (Exception e) {
    logger.error("Cannot insert input text", e);
  }
  int newCaretPosition = (preserveCaretPosition && oldCaretPosition <= document.getLength()) ? oldCaretPosition : document.getLength();
  textPane.setCaretPosition(newCaretPosition);
}

相关文章