Exemplo n.º 1
1
  public JWrapLabel(String txt) {
    super();
    setEditable(false);
    setText(txt);

    SimpleAttributeSet set = new SimpleAttributeSet();
    StyleConstants.setAlignment(set, StyleConstants.ALIGN_CENTER);
    StyleConstants.setFontFamily(set, "Arial");
    StyleConstants.setFontSize(set, 13);
    setParagraphAttributes(set, true);
  }
Exemplo n.º 2
0
 @Override
 public void path(Timing timing, String path, String s) {
   sText = "";
   if (sPath.equals("/CM/CY") && timing == Timing.CHARACTERS) {
     attributeSet = new SimpleAttributeSet(attributeSet0);
     StyleConstants.setFontSize(attributeSet, 48);
     sText = "【" + s + "】\n";
   } else if (sPath.equals("/CM/CMSY/GL") && timing == Timing.CHARACTERS) {
     attributeSet = new SimpleAttributeSet(attributeSet0);
     StyleConstants.setFontSize(attributeSet, 24);
     sText = s + "\n";
   } else if (sPath.equals("/CM/CMSY/SYLB") && timing == Timing.START) {
     attributeSet = null;
     sText = "\n";
   } else if (sPath.equals("/CM/CMSY/SYLB/XH") && timing == Timing.CHARACTERS) {
     attributeSet = null;
     sText = "(" + s + ") ";
   } else if (sPath.equals("/CM/CMSY/SYLB/SY") && timing == Timing.CHARACTERS) {
     attributeSet = null;
     sText = s + "\n";
   } else if (sPath.equals("/CM/CMSY/SYLB/LZ") && timing == Timing.CHARACTERS) {
     attributeSet = new SimpleAttributeSet(attributeSet0);
     StyleConstants.setFontSize(attributeSet, 24);
     sText = s + "\n";
   } else if (sPath.equals("/CM/CMSY") && timing == Timing.END) {
     attributeSet = null;
     sText = "\n";
   }
   if (sText != null) {
     insertString(sText, attributeSet == null ? attributeSet0 : attributeSet);
   }
 }
Exemplo n.º 3
0
  /**
   * Returns StyledDocument object containing preformatted LEM Class description, followed by the
   * list of attributes that the Class has.
   *
   * @return the StyledDocument of the ClassNode.
   */
  public StyledDocument getStyledDocument() {
    StyledDocument doc = new StyledDocument();
    SimpleAttributeSet s = new SimpleAttributeSet();
    StyleConstants.setFontFamily(s, "Times New Roman");
    StyleConstants.setFontSize(s, 14);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.blue);
    StyledElement element = new StyledElement(toString() + "\n", s);
    doc.addStyle(element);

    SimpleAttributeSet s1 = new SimpleAttributeSet();
    StyleConstants.setFontFamily(s1, "Times New Roman");
    StyleConstants.setFontSize(s1, 14);
    StyleConstants.setBold(s1, false);
    StyleConstants.setForeground(s1, Color.black);
    StyledElement element1 = new StyledElement(getDescription(), s1);
    doc.addStyle(element1);

    StyledElement element2 =
        new StyledElement("\n-------------- Attributes ----------------\n", s1);
    doc.addStyle(element2);

    doc.append(attributeListing);
    return doc;
  }
  public void addStylesToDocument(StyledDocument doc) {
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
    Style regular = doc.addStyle("regular", def);
    StyleConstants.setFontFamily(def, "Norasi");

    Style s = doc.addStyle("black", regular);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.BLACK);
    StyleConstants.setFontSize(s, 15);

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

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

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

    s = doc.addStyle("magenta", regular);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.MAGENTA);
    StyleConstants.setFontSize(s, 14);
  }
Exemplo n.º 5
0
  private void initAttributeSets() {
    conRegular = new SimpleAttributeSet();
    StyleConstants.setFontFamily(conRegular, prefs.mainFont);
    StyleConstants.setFontSize(conRegular, prefs.statusFontSize);
    StyleConstants.setForeground(conRegular, Color.white);

    conIrregular = new SimpleAttributeSet();
    StyleConstants.setFontFamily(conIrregular, prefs.mainFont);
    StyleConstants.setFontSize(conIrregular, prefs.statusFontSize);
    StyleConstants.setForeground(conIrregular, Color.white);
    StyleConstants.setBold(conIrregular, true);
  }
Exemplo n.º 6
0
  private void initStyles() {
    sc = new StyleContext();
    Style parent = sc.getStyle(StyleContext.DEFAULT_STYLE);

    StyleConstants.setFontFamily(parent, "courier");
    StyleConstants.setFontSize(parent, 13);

    styleElementName = sc.addStyle("elementName", parent);
    StyleConstants.setForeground(styleElementName, new Color(128, 0, 0));

    styleAttribtuteName = sc.addStyle("attributeName", parent);
    StyleConstants.setForeground(styleAttribtuteName, Color.RED);

    styleAttribtuteValue = sc.addStyle("attributeValue", parent);

    styleContent = sc.addStyle("content", parent);
    StyleConstants.setBackground(styleContent, new Color(200, 255, 100));

    styleOperator = sc.addStyle("operator", parent);
    StyleConstants.setForeground(styleOperator, Color.BLUE);
    StyleConstants.setBold(styleOperator, true);

    styleComments = sc.addStyle("comments", parent);
    StyleConstants.setForeground(styleComments, new Color(128, 128, 128)); // Hooker's green

    styleCData = sc.addStyle("cdata", parent);
    StyleConstants.setForeground(styleCData, new Color(30, 30, 0));
    StyleConstants.setBackground(styleCData, new Color(250, 250, 240));

    styleProcessingInstructions = sc.addStyle("processingIntruction", parent);
    styleDOCTYPE = sc.addStyle("doctype", styleComments);
  }
  public void displayAllClassesNames(List<String> classNames) {
    long start = System.currentTimeMillis();

    displayDataState = DisplayDataState.CLASSES_LIST;
    StyleConstants.setFontSize(style, 18);
    StyleConstants.setForeground(style, ColorScheme.FOREGROUND_CYAN);

    clearText();

    BatchDocument blank = new BatchDocument();
    jTextPane.setDocument(blank);

    for (String className : classNames) {
      blank.appendBatchStringNoLineFeed(className, style);
      blank.appendBatchLineFeed(style);
    }

    try {
      blank.processBatchUpdates(0);
    } catch (BadLocationException e) {
      e.printStackTrace();
    }

    jTextPane.setDocument(blank);

    System.out.println("UI update " + (System.currentTimeMillis() - start) + " ms");
  }
Exemplo n.º 8
0
  public SimpleAttributeSet getAttrSet() {
    attrSet = new SimpleAttributeSet();
    if (fontName != null) {
      StyleConstants.setFontFamily(attrSet, fontName);
    }

    switch (fontStyle) {
      case MessageWithAttrib.GENERAL:
        StyleConstants.setBold(attrSet, false);
        StyleConstants.setItalic(attrSet, false);
        break;
      case MessageWithAttrib.BOLD:
        StyleConstants.setBold(attrSet, true);
        StyleConstants.setItalic(attrSet, false);
        break;
      case MessageWithAttrib.ITALIC:
        StyleConstants.setBold(attrSet, false);
        StyleConstants.setItalic(attrSet, true);
        break;
      case MessageWithAttrib.BOLD_ITALIC:
        StyleConstants.setBold(attrSet, true);
        StyleConstants.setItalic(attrSet, true);
        break;
    }

    StyleConstants.setFontSize(attrSet, fontSize);
    if (fontColor != null) {
      StyleConstants.setForeground(attrSet, fontColor);
    }
    return attrSet;
  }
Exemplo n.º 9
0
  public SimpleAttributeSet getAttributeSet() {
    if (fontName != null && !"".equals(fontName)) {
      StyleConstants.setFontFamily(attrSet, fontName);
    }
    if (fontStyle == 0) { // 常规
      StyleConstants.setBold(attrSet, false);
      StyleConstants.setItalic(attrSet, false);
    } else if (fontStyle == 1) { // 粗体
      StyleConstants.setBold(attrSet, true);
      StyleConstants.setItalic(attrSet, false);
    } else if (fontStyle == 2) { // 斜体
      StyleConstants.setBold(attrSet, false);
      StyleConstants.setItalic(attrSet, true);
    } else if (fontStyle == 3) { // 粗体 斜体
      StyleConstants.setBold(attrSet, true);
      StyleConstants.setItalic(attrSet, true);
    }
    if (foreColor != null) { // 背景色
      StyleConstants.setForeground(attrSet, foreColor);
    }
    if (backColor != null) { // 前景色
      StyleConstants.setBackground(attrSet, backColor);
    }
    if (fontSize != -1) {
      StyleConstants.setFontSize(attrSet, fontSize);
    }

    return attrSet;
  }
Exemplo n.º 10
0
  // ----------------------------------------------------------------------------
  public AttributeSet getAttributes() {
    if (attributes_ != null) {
      StyleConstants.setFontFamily(attributes_, font_names_.getSelected());
      StyleConstants.setFontSize(attributes_, font_sizes_.getSelectedInt());
    }

    return attributes_;
  }
Exemplo n.º 11
0
  private void setTextAttribute() {
    BOLD_BLACK = new SimpleAttributeSet();

    StyleConstants.setForeground(BOLD_BLACK, Color.red);
    StyleConstants.setBold(BOLD_BLACK, true);
    StyleConstants.setFontFamily(BOLD_BLACK, "Helvetica");
    StyleConstants.setFontSize(BOLD_BLACK, 20);
  }
Exemplo n.º 12
0
 private void resetStyles() {
   doc.setParagraphAttributes(0, doc.getLength(), plainStyle, true);
   StyleConstants.setFontSize(fontSizeStyle, 14);
   Font f = plainFont;
   StyleConstants.setFontFamily(fontSizeStyle, f.getFamily());
   doc.setParagraphAttributes(0, doc.getLength(), fontSizeStyle, false);
   setupFont();
 }
Exemplo n.º 13
0
 /**
  * Generate an attribute set for links.
  *
  * @param action the action to perform
  * @return the attribute set
  */
 public static SimpleAttributeSet getActionStyle(ActionListener action) {
   SimpleAttributeSet style = new SimpleAttributeSet();
   StyleConstants.setForeground(style, Color.blue);
   StyleConstants.setUnderline(style, true);
   StyleConstants.setFontFamily(style, font);
   StyleConstants.setFontSize(style, fontSize);
   style.addAttribute(ACTION_ATTRIBUTE, action);
   return style;
 }
Exemplo n.º 14
0
  /**
   * Constructor. Sets up the styles and add the strings to be highlighted into the corresponding
   * vectors.
   */
  public ConsoleCodeDocument() {
    super(false);

    putProperty(DefaultEditorKit.EndOfLineStringProperty, "\n");

    StyleConstants.setForeground(pythonPromptAttr, Color.LIGHT_GRAY);
    StyleConstants.setBold(pythonPromptAttr, true);
    StyleConstants.setFontSize(pythonPromptAttr, 13);
  }
Exemplo n.º 15
0
  /**
   * Constructor that takes an ID from a Conversation, and creates a window to display it.
   *
   * @param ID The Conversation object's ID.
   */
  public ChatWindow(int ID) {
    setLayout(new BorderLayout());
    this.ID = ID;
    textPane = new JTextPane();
    scrollPane = new JScrollPane(textPane);

    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

    StyleConstants.setForeground(chatFont, Color.BLACK);
    StyleConstants.setFontSize(chatFont, 20);

    StyleConstants.setForeground(nameFont, Color.BLACK);
    StyleConstants.setFontSize(nameFont, 20);
    StyleConstants.setBold(nameFont, true);

    add(scrollPane, BorderLayout.CENTER);
    textPane.setEditable(false);
  }
Exemplo n.º 16
0
 /**
  * Create an attribute set for stylish text.
  *
  * @param color the color
  * @param italic whether the text should be slanted
  * @param bold whether the text should be bold
  * @param fontName the name of the font to use
  * @param fontSize the font size to use
  * @return the attribute set
  */
 public static SimpleAttributeSet getStyle(
     Color color, boolean italic, boolean bold, String fontName, int fontSize) {
   SimpleAttributeSet style = new SimpleAttributeSet();
   StyleConstants.setForeground(style, color);
   StyleConstants.setItalic(style, italic);
   StyleConstants.setBold(style, bold);
   StyleConstants.setFontFamily(style, fontName);
   StyleConstants.setFontSize(style, fontSize);
   return style;
 }
Exemplo n.º 17
0
 /** Set default value for all the attributes */
 protected static void useDefaultStyle() {
   defaultStyle = true;
   StyleConstants.setForeground(fontColorAttribute, defaultForeground);
   // StyleConstants.setBackground(fontColorAttribute, defaultBackground);
   StyleConstants.setFontFamily(fontColorAttribute, defaultFamily);
   StyleConstants.setFontSize(fontColorAttribute, defaultSize);
   StyleConstants.setBold(fontColorAttribute, false);
   StyleConstants.setItalic(fontColorAttribute, false);
   StyleConstants.setUnderline(fontColorAttribute, false);
 }
Exemplo n.º 18
0
 private void insertDocument(String text, Color textColor) {
   SimpleAttributeSet set = new SimpleAttributeSet();
   StyleConstants.setForeground(set, textColor);
   StyleConstants.setFontSize(set, 12);
   Document doc = progressArea.getStyledDocument();
   try {
     doc.insertString(doc.getLength(), text, set);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 19
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);
  }
Exemplo n.º 20
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.º 21
0
  /**
   * Change default attributes with user option
   *
   * @param fontFamily Text Font Family (Helvetica, Times etc.)
   * @param fontType Text Font Type (Plain, Bold, Italic etc.)
   * @param fontSize Text Font Size (8 ... 24)
   * @param fgColor Text foreground color
   * @param bgColor Text background color
   */
  protected static void changeStyle(
      String fontFamily, String fontType, int fontSize, Color fgColor, Color bgColor) {
    defaultStyle = false;

    StyleConstants.setForeground(fontColorAttribute, fgColor);
    // StyleConstants.setBackground(fontColorAttribute, bgColor);
    StyleConstants.setFontFamily(fontColorAttribute, fontFamily);
    StyleConstants.setFontSize(fontColorAttribute, fontSize);
    if (fontType != null) {
      if (fontType.equals("Italic")) StyleConstants.setItalic(fontColorAttribute, true);
      else if (fontType.equals("Bold")) StyleConstants.setBold(fontColorAttribute, true);
      else if (fontType.equals("Underline")) StyleConstants.setUnderline(fontColorAttribute, true);
    }
  }
Exemplo n.º 22
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);
  }
Exemplo n.º 23
0
  private void setStyles() {

    doc = helpPanel.getjTextPane1().getStyledDocument();

    style = helpPanel.getjTextPane1().addStyle("I'm a Style", null);
    StyleConstants.setAlignment(style, StyleConstants.ALIGN_CENTER);
    StyleConstants.setForeground(style, Color.PINK);
    StyleConstants.setFontSize(style, 20);
    StyleConstants.setFontFamily(style, "cambria");
    StyleConstants.setBold(style, true);
    StyleConstants.setSpaceAbove(style, 4);

    style2 = helpPanel.getjTextPane1().addStyle("I'm a Style", null);
    StyleConstants.setFontFamily(style2, "cambria");
    StyleConstants.setForeground(style2, Color.BLUE);
    StyleConstants.setBold(style2, true);
    StyleConstants.setAlignment(style2, StyleConstants.ALIGN_JUSTIFIED);
    StyleConstants.setFontSize(style2, 12);

    styleW = helpPanel.getjTextPane1().addStyle("I'm a Style", null);
    StyleConstants.setFontFamily(styleW, "cambria");
    StyleConstants.setAlignment(styleW, StyleConstants.ALIGN_JUSTIFIED);
    StyleConstants.setFontSize(styleW, 12);

    styleWB = helpPanel.getjTextPane1().addStyle("I'm a Style", null);
    StyleConstants.setFontFamily(styleWB, "cambria");
    StyleConstants.setBold(styleWB, true);
    StyleConstants.setAlignment(styleWB, StyleConstants.ALIGN_JUSTIFIED);
    StyleConstants.setFontSize(styleWB, 12);

    styleP = helpPanel.getjTextPane1().addStyle("I'm a Style", null);
    StyleConstants.setFontFamily(styleP, "cambria");
    StyleConstants.setForeground(styleP, Color.MAGENTA);
    StyleConstants.setBold(styleP, true);
    StyleConstants.setAlignment(styleP, StyleConstants.ALIGN_JUSTIFIED);
    StyleConstants.setFontSize(styleP, 12);
  }
Exemplo n.º 24
0
  private void setupStyle() {
    Document document = myHTMLViewer.getDocument();
    if (!(document instanceof StyledDocument)) {
      return;
    }

    StyledDocument styledDocument = (StyledDocument) document;

    EditorColorsManager colorsManager = EditorColorsManager.getInstance();
    EditorColorsScheme scheme = colorsManager.getGlobalScheme();

    Style style = styledDocument.addStyle("active", null);
    StyleConstants.setFontFamily(style, scheme.getEditorFontName());
    StyleConstants.setFontSize(style, scheme.getEditorFontSize());
    styledDocument.setCharacterAttributes(0, document.getLength(), style, false);
  }
  public void displaySharkey() {
    displayDataState = DisplayDataState.SHARKEY;
    clearText();
    style = jTextPane.addStyle("STYLE", null);
    Document doc = jTextPane.getStyledDocument();

    try {
      StyleConstants.setForeground(style, ColorScheme.FOREGROUND_YELLOW);
      StyleConstants.setFontSize(style, 13);
      StyleConstants.setFontFamily(style, "Menlo");

      doc.insertString(doc.getLength(), SharkBG.SHARKEY, style);
    } catch (BadLocationException e) {
      e.printStackTrace();
    }

    jTextPane.setDocument(doc);
  }
  public void displayClass(List<Translator.ELEMENT> elements) {
    displayDataState = DisplayDataState.INSIDE_CLASS;
    clearText();
    StyleConstants.setFontSize(style, 18);

    Document doc = new DefaultStyledDocument();

    try {
      for (Translator.ELEMENT e : elements) {
        switch (e.tag) {
          case MODIFIER:
            StyleConstants.setForeground(style, ColorScheme.FOREGROUND_ORANGE);
            break;
          case DOCUMENT:
            StyleConstants.setForeground(style, ColorScheme.FOREGROUND_YELLOW);
            break;
          case IDENTIFIER:
            StyleConstants.setForeground(style, ColorScheme.FOREGROUND_CYAN);
            break;
          case ANNOTATION:
            StyleConstants.setForeground(style, ColorScheme.FOREGROUND_YELLOW_ANNOTATIONS);
            break;
          case XML_TAG:
            StyleConstants.setForeground(style, ColorScheme.FOREGROUND_YELLOW);
            break;
          case XML_ATTR_NAME:
            StyleConstants.setForeground(style, ColorScheme.FOREGROUND_CYAN);
            break;
          case XML_ATTR_VALUE:
            StyleConstants.setForeground(style, ColorScheme.FOREGROUND_YELLOW_ANNOTATIONS);
            break;
          default:
            StyleConstants.setForeground(style, Color.LIGHT_GRAY);
        }
        doc.insertString(doc.getLength(), e.text, style);
      }
    } catch (BadLocationException e) {
      e.printStackTrace();
    }

    StyleConstants.setForeground(style, ColorScheme.FOREGROUND_CYAN);

    jTextPane.setDocument(doc);
  }
  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);
  }
  public void displayReducedClassesNames(List<String> classNamesToShow, String inputText) {
    displayDataState = DisplayDataState.CLASSES_LIST;

    clearText();

    int matchIndex;

    String beforeMatch = "";
    String match;
    String afterMatch = "";

    StyleConstants.setFontSize(style, 18);
    StyleConstants.setForeground(style, ColorScheme.FOREGROUND_CYAN);

    Document doc = jTextPane.getDocument();

    for (String className : classNamesToShow) {
      matchIndex = className.indexOf(inputText);

      if (matchIndex > -1) {
        beforeMatch = className.substring(0, matchIndex);
        match = className.substring(matchIndex, matchIndex + inputText.length());
        afterMatch = className.substring(matchIndex + inputText.length(), className.length());
      } else {
        // we are here by camel match
        // i.e. 2-3 letters that fits
        // to class name
        match = className;
      }

      try {
        doc.insertString(doc.getLength(), beforeMatch, style);
        StyleConstants.setBackground(style, ColorScheme.SELECTION_BG);
        doc.insertString(doc.getLength(), match, style);
        StyleConstants.setBackground(style, ColorScheme.BACKGROUND);
        doc.insertString(doc.getLength(), afterMatch + "\n", style);
      } catch (BadLocationException e) {
        e.printStackTrace();
      }
    }

    jTextPane.setDocument(doc);
  }
Exemplo n.º 29
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();
  }
Exemplo n.º 30
0
  private void displayCenteredText(String text) {
    textArea.setText("");
    text = "\n\n\n" + text;
    SimpleAttributeSet attribs = new SimpleAttributeSet();
    float fnt = sd.getFontSize();
    StyledDocument doc = (StyledDocument) textArea.getDocument();
    Style style = doc.getStyle(StyleContext.DEFAULT_STYLE); // doc.addStyle("MyStyle",null);
    StyleConstants.setFontSize(style, (int) fnt);
    StyleConstants.setLineSpacing(attribs, 0.5f);
    StyleConstants.setFontFamily(style, "Segoe UI");
    StyleConstants.setAlignment(attribs, StyleConstants.ALIGN_CENTER);
    textArea.setParagraphAttributes(attribs, true);

    try {
      doc.insertString(doc.getLength(), text, style);
      doc.setParagraphAttributes(0, doc.getLength() - 1, attribs, false);
    } catch (BadLocationException ex) {
      Logger.getLogger(DylematorUI.class.getName()).log(Level.SEVERE, null, ex);
    }
  }