Exemplo n.º 1
0
  protected void addStylesToDocument(final StyledDocument doc) {
    // Initialize some styles.
    final Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

    final Style regular = doc.addStyle("regular", def);
    StyleConstants.setFontFamily(def, "SansSerif");

    Style s = doc.addStyle("entailment", regular);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.blue);

    s = doc.addStyle("color_blue", regular);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.BLUE);

    s = doc.addStyle("color_red", regular);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.RED);

    s = doc.addStyle("color_green", regular);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.GREEN);

    s = doc.addStyle("color_cyan", regular);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.CYAN);

    s = doc.addStyle("color_dark_gray", regular);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.DARK_GRAY);

    s = doc.addStyle("color_pink", regular);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.PINK);

    s = doc.addStyle("color_yellow", regular);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.YELLOW);

    s = doc.addStyle("color_magenta", regular);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.MAGENTA);

    s = doc.addStyle("color_orange", regular);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.ORANGE);

    s = doc.addStyle("unknown", regular);
    StyleConstants.setBold(s, true);
    StyleConstants.setUnderline(s, true);

    s = doc.addStyle("system", regular);
    StyleConstants.setBold(s, true);
  }
Exemplo n.º 2
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);
  }
Exemplo n.º 3
0
  public void initializeTextPane(JTextPane text_pane) {
    text_pane.removeStyle("normal");
    Style normal = text_pane.addStyle("normal", base_style);
    text_pane.removeStyle("alternate");
    Style alternate = text_pane.addStyle("alternate", normal);

    int[] rgb = new int[3];
    try {
      String rgb_str =
          settings_manager.getString("/gui/text windows/alternate background colour", "");

      if (rgb_str != "") {
        rgb = Util.getRGB(rgb_str);
        StyleConstants.setBackground(alternate, new Color(rgb[0], rgb[1], rgb[2]));
      }
    } catch (NumberFormatException e) {
    }

    String format;
    for (int i = 0; i < style_names.length; i++) {
      format = style_names[i];
      int len = format.length();
      boolean valid_format = true;

      // Duplicate the base style, and adjust the new copy to create the new style.
      text_pane.removeStyle(format);
      Style style = text_pane.addStyle(format, normal);
      for (int c = 0; c < len; ) {
        if (c > len - 2) {
          valid_format = false;
          break;
        } else {

          String arg;
          String code = format.substring(c, c + 2);
          c += 2;
          if (code.equals(STYLE_FOREGROUND)) {
            if (c > len - 6) {
              valid_format = false;
              break;
            }

            arg = format.substring(c, c + 6);
            c += 6;
            rgb[0] = 0xff;
            rgb[1] = 0xff;
            rgb[2] = 0xff;
            try {
              rgb = Util.getRGB(arg);
            } catch (NumberFormatException e) {
              valid_format = false;
              break;
            }

            StyleConstants.setForeground(style, new Color(rgb[0], rgb[1], rgb[2]));
          } else if (code.equals(STYLE_BACKGROUND)) {
            if (c > len - 6) {
              valid_format = false;
              break;
            }

            arg = format.substring(c, c + 6);
            c += 6;
            rgb[0] = 0;
            rgb[1] = 0;
            rgb[2] = 0;
            try {
              rgb = Util.getRGB(arg);
            } catch (NumberFormatException e) {
              valid_format = false;
              break;
            }

            StyleConstants.setBackground(style, new Color(rgb[0], rgb[1], rgb[2]));
          } else if (code.equals(STYLE_BOLD)) {
            StyleConstants.setBold(style, true);
          } else if (code.equals(STYLE_ITALIC)) {
            StyleConstants.setItalic(style, true);
          } else if (code.equals(STYLE_UNDERLINE)) {
            StyleConstants.setUnderline(style, true);
          }
        }
      }

      if (!valid_format) {
        System.err.println(i18n_manager.getString("bad format", new Object[] {style_names[i]}));
      }
    }
  }