/** Creates the error area component. */
 private void initErrorArea() {
   SimpleAttributeSet attribs = new SimpleAttributeSet();
   StyleConstants.setAlignment(attribs, StyleConstants.ALIGN_RIGHT);
   StyleConstants.setFontFamily(attribs, errorPane.getFont().getFamily());
   StyleConstants.setForeground(attribs, Color.RED);
   errorPane.setParagraphAttributes(attribs, true);
   errorPane.setPreferredSize(new Dimension(100, 50));
   errorPane.setMinimumSize(new Dimension(100, 50));
   errorPane.setOpaque(false);
 }
Ejemplo n.º 2
0
 private void initializeStyles() {
   errorStyle =
       doc.addStyle(
           "errorStyle",
           StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE));
   errorStyleRed = doc.addStyle("errorStyleRed", errorStyle);
   StyleConstants.setForeground(errorStyleRed, Color.RED);
   errorStyleMono = doc.addStyle("errorStyleMono", errorStyle);
   StyleConstants.setFontFamily(errorStyleMono, "Monospaced");
 }
Ejemplo n.º 3
0
    private void loadStyles(StyledDocument doc) {
      Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
      StyleConstants.setFontFamily(def, "Courier New");

      // Add normal style
      Style normal = doc.addStyle("normal", def);
      StyleConstants.setForeground(def, Color.LIGHT_GRAY);

      // Add highlighted style from normal
      Style red = doc.addStyle("red", normal);
      StyleConstants.setForeground(red, Color.RED);
    }
Ejemplo n.º 4
0
  private void _applyFontStyleForSelection(Font font) {
    StyledDocument doc = mTextEditor.getStyledDocument();
    MutableAttributeSet attrs = mTextEditor.getInputAttributes();
    StyleConstants.setFontFamily(attrs, font.getFamily());
    StyleConstants.setFontSize(attrs, font.getSize());
    StyleConstants.setBold(attrs, ((font.getStyle() & Font.BOLD) != 0));
    StyleConstants.setItalic(attrs, ((font.getStyle() & Font.ITALIC) != 0));
    StyleConstants.setUnderline(attrs, ((font.getStyle() & Font.CENTER_BASELINE) != 0));

    int start = mTextEditor.getSelectionStart();
    int end = mTextEditor.getSelectionEnd();
    doc.setCharacterAttributes(start, (end - start), attrs, false);
  }
Ejemplo n.º 5
0
  /** Creates the text area. */
  private void initTextArea() {
    textArea.setOpaque(false);
    textArea.setEditable(false);
    StyledDocument doc = textArea.getStyledDocument();

    MutableAttributeSet standard = new SimpleAttributeSet();
    StyleConstants.setAlignment(standard, StyleConstants.ALIGN_CENTER);
    StyleConstants.setFontFamily(standard, textArea.getFont().getFamily());
    StyleConstants.setFontSize(standard, 12);
    doc.setParagraphAttributes(0, 0, standard, true);

    parentWindow.addSearchFieldListener(this);
  }
Ejemplo n.º 6
0
  static {
    DEFAULT_NORMAL = new SimpleAttributeSet();
    StyleConstants.setForeground(DEFAULT_NORMAL, Color.BLACK);
    StyleConstants.setFontFamily(DEFAULT_NORMAL, DEFAULT_FONT_FAMILY);
    StyleConstants.setFontSize(DEFAULT_NORMAL, DEFAULT_FONT_SIZE);

    DEFAULT_COMMENT = new SimpleAttributeSet();
    StyleConstants.setForeground(DEFAULT_COMMENT, Color.GRAY);
    StyleConstants.setFontFamily(DEFAULT_COMMENT, DEFAULT_FONT_FAMILY);
    StyleConstants.setFontSize(DEFAULT_COMMENT, DEFAULT_FONT_SIZE);

    DEFAULT_STRING = new SimpleAttributeSet();
    StyleConstants.setForeground(DEFAULT_STRING, Color.RED);
    StyleConstants.setFontFamily(DEFAULT_STRING, DEFAULT_FONT_FAMILY);
    StyleConstants.setFontSize(DEFAULT_STRING, DEFAULT_FONT_SIZE);

    // default style for new keyword types
    DEFAULT_KEYWORD = new SimpleAttributeSet();
    StyleConstants.setForeground(DEFAULT_KEYWORD, Color.BLUE);
    StyleConstants.setBold(DEFAULT_KEYWORD, false);
    StyleConstants.setFontFamily(DEFAULT_KEYWORD, DEFAULT_FONT_FAMILY);
    StyleConstants.setFontSize(DEFAULT_KEYWORD, DEFAULT_FONT_SIZE);
  }
  void finishInit() {
    // Create 3 styles associated with the text panes
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
    StyleConstants.setFontFamily(def, "SansSerif");

    Style regular0 = jTextPane.addStyle("regular", def);
    Style regular1 = commentPane.addStyle("regular", def);

    Style s0 = jTextPane.addStyle("old", regular0);
    Style s1 = commentPane.addStyle("old", regular1);
    StyleConstants.setBackground(s0, Color.yellow);
    StyleConstants.setBackground(s1, Color.yellow);

    s0 = jTextPane.addStyle("new", regular0);
    StyleConstants.setBackground(s0, Color.pink);
    s1 = commentPane.addStyle("new", regular1);
    StyleConstants.setBackground(s1, Color.pink);
  }
  private void applyFontSize() {
    Document document = myEditorPane.getDocument();
    if (!(document instanceof StyledDocument)) {
      return;
    }

    StyledDocument styledDocument = (StyledDocument) document;
    if (myFontSizeStyle == null) {
      myFontSizeStyle = styledDocument.addStyle("active", null);
    }

    EditorColorsManager colorsManager = EditorColorsManager.getInstance();
    EditorColorsScheme scheme = colorsManager.getGlobalScheme();
    StyleConstants.setFontSize(myFontSizeStyle, scheme.getQuickDocFontSize().getSize());
    if (Registry.is("documentation.component.editor.font")) {
      StyleConstants.setFontFamily(myFontSizeStyle, scheme.getEditorFontName());
    }
    styledDocument.setCharacterAttributes(0, document.getLength(), myFontSizeStyle, false);
  }
Ejemplo n.º 9
0
  /**
   * Sets the reason of a call failure if one occurs. The renderer should display this reason to the
   * user.
   *
   * @param reason the reason to display
   */
  public void setErrorReason(final String reason) {
    if (!SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              setErrorReason(reason);
            }
          });
      return;
    }

    if (errorMessageComponent == null) {
      errorMessageComponent = new JTextPane();

      JTextPane textPane = (JTextPane) errorMessageComponent;
      textPane.setEditable(false);
      textPane.setOpaque(false);

      StyledDocument doc = textPane.getStyledDocument();

      MutableAttributeSet standard = new SimpleAttributeSet();
      StyleConstants.setAlignment(standard, StyleConstants.ALIGN_CENTER);
      StyleConstants.setFontFamily(standard, textPane.getFont().getFamily());
      StyleConstants.setFontSize(standard, 12);
      doc.setParagraphAttributes(0, 0, standard, true);

      GridBagConstraints constraints = new GridBagConstraints();
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.gridx = 0;
      constraints.gridy = 4;
      constraints.weightx = 1;
      constraints.weighty = 0;
      constraints.insets = new Insets(5, 0, 0, 0);

      add(errorMessageComponent, constraints);
      this.revalidate();
    }

    errorMessageComponent.setText(reason);

    if (isVisible()) errorMessageComponent.repaint();
  }
Ejemplo n.º 10
0
  private void setTabSize(int charactersPerTab) {
    FontMetrics fm = this.getFontMetrics(this.getFont());
    int charWidth = fm.charWidth('w');
    int tabWidth = charWidth * charactersPerTab;

    TabStop[] tabs = new TabStop[10];

    for (int j = 0; j < tabs.length; j++) {
      int tab = j + 1;
      tabs[j] = new TabStop(tab * tabWidth);
    }

    TabSet tabSet = new TabSet(tabs);
    SimpleAttributeSet attributes = new SimpleAttributeSet();
    StyleConstants.setFontSize(attributes, 18);
    StyleConstants.setFontFamily(attributes, "Osaka-Mono");
    StyleConstants.setTabSet(attributes, tabSet);
    int length = getDocument().getLength();
    getStyledDocument().setParagraphAttributes(0, length, attributes, true);
  }
Ejemplo n.º 11
0
  /**
   * Update the font in the default style of the document.
   *
   * @param font the new font to use or null to remove the font attribute from the document's style
   */
  private void updateFont(Font font) {
    StyledDocument doc = (StyledDocument) getComponent().getDocument();
    Style style = doc.getStyle(StyleContext.DEFAULT_STYLE);

    if (style == null) {
      return;
    }

    if (font == null) {
      style.removeAttribute(StyleConstants.FontFamily);
      style.removeAttribute(StyleConstants.FontSize);
      style.removeAttribute(StyleConstants.Bold);
      style.removeAttribute(StyleConstants.Italic);
    } else {
      StyleConstants.setFontFamily(style, font.getName());
      StyleConstants.setFontSize(style, font.getSize());
      StyleConstants.setBold(style, font.isBold());
      StyleConstants.setItalic(style, font.isItalic());
    }
  }
Ejemplo n.º 12
0
 /**
  * sets the current font family (affects all built-in styles).
  *
  * @param fontName the font name
  */
 public void setFontName(String fontName) {
   m_FontName = fontName;
   StyleConstants.setFontFamily(DEFAULT_NORMAL, fontName);
   StyleConstants.setFontFamily(DEFAULT_STRING, fontName);
   StyleConstants.setFontFamily(DEFAULT_COMMENT, fontName);
 }
Ejemplo n.º 13
0
 /**
  * Sets the font of the specified attribute.
  *
  * @param attr attribute to apply this font to
  * @param f the font to use
  */
 public static void setAttributeFont(MutableAttributeSet attr, Font f) {
   StyleConstants.setBold(attr, f.isBold());
   StyleConstants.setItalic(attr, f.isItalic());
   StyleConstants.setFontFamily(attr, f.getFamily());
   StyleConstants.setFontSize(attr, f.getSize());
 }
Ejemplo n.º 14
0
 static {
   StyleConstants.setForeground(PLAIN_ATTR, Color.black);
   StyleConstants.setBold(PLAIN_ATTR, false);
   StyleConstants.setFontFamily(PLAIN_ATTR, "Helvetica");
   StyleConstants.setFontSize(PLAIN_ATTR, 14);
 }