/** 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);
 }
  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);
  }
  private void updateTemplateFromEditor(PrintfTemplate template) {
    ArrayList params = new ArrayList();
    String format = null;
    int text_length = editorPane.getDocument().getLength();
    try {
      format = editorPane.getDocument().getText(0, text_length);
    } catch (BadLocationException ex1) {
    }
    Element section_el = editorPane.getDocument().getDefaultRootElement();
    // Get number of paragraphs.
    int num_para = section_el.getElementCount();
    for (int p_count = 0; p_count < num_para; p_count++) {
      Element para_el = section_el.getElement(p_count);
      // Enumerate the content elements
      int num_cont = para_el.getElementCount();
      for (int c_count = 0; c_count < num_cont; c_count++) {
        Element content_el = para_el.getElement(c_count);
        AttributeSet attr = content_el.getAttributes();
        // Get the name of the style applied to this content element; may be null
        String sn = (String) attr.getAttribute(StyleConstants.NameAttribute);
        // Check if style name match
        if (sn != null && sn.startsWith("Parameter")) {
          // we extract the label.
          JLabel l = (JLabel) StyleConstants.getComponent(attr);
          if (l != null) {
            params.add(l.getName());
          }
        }
      }
    }

    template.setFormat(format);
    template.setTokens(params);
  }
  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");
  }
  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);
  }
Exemple #6
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);
   }
 }
  private void populateRemark() {
    txtTextField.setText("");
    txtRemark.setText("");
    SimpleAttributeSet BLUE = new SimpleAttributeSet();
    SimpleAttributeSet BLACK = new SimpleAttributeSet();
    StyleConstants.setForeground(BLUE, Color.BLUE);
    StyleConstants.setForeground(BLACK, Color.BLACK);

    Document rmkDoc = txtRemark.getDocument();

    for (int i = remarkslist.size() - 1; i >= 0; i--) {
      RemarkSummary prmk = remarkslist.get(i);
      try {
        if (prmk.getCreatedBy() == null) {
          rmkDoc.insertString(rmkDoc.getLength(), "" + "" + "" + "", BLUE);
        } else {
          rmkDoc.insertString(
              rmkDoc.getLength(), prmk.getDateTime() + " : " + prmk.getCreatedBy() + " : ", BLUE);
        }
        rmkDoc.insertString(rmkDoc.getLength(), prmk.getText() + '\n', BLACK);
      } catch (BadLocationException e) {
        System.out.println("Exception in pnr remark: " + e);
      }
    }
  }
  // ----------------------------------------------------------------------------
  public AttributeSet getAttributes() {
    if (attributes_ != null) {
      StyleConstants.setFontFamily(attributes_, font_names_.getSelected());
      StyleConstants.setFontSize(attributes_, font_sizes_.getSelectedInt());
    }

    return attributes_;
  }
Exemple #9
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);
  }
 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();
 }
Exemple #11
0
 public static void addStyle(JTextPane pane, String name, Color foreground, Color background) {
   StyledDocument doc = pane.getStyledDocument();
   StyleContext context = StyleContext.getDefaultStyleContext();
   Style defaultStyle = context.getStyle(StyleContext.DEFAULT_STYLE);
   Style style = doc.addStyle(name, defaultStyle);
   StyleConstants.setForeground(style, foreground);
   StyleConstants.setBackground(style, background);
 }
Exemple #12
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;
 }
  // ----------------------------------------------------------------------------
  public void setAttributes(AttributeSet a) {
    attributes_ = new SimpleAttributeSet(a);
    String name = StyleConstants.getFontFamily(a);
    font_names_.setSelected(name);
    int size = StyleConstants.getFontSize(a);
    font_sizes_.setSelectedInt(size);

    updatePreview();
  }
  /**
   * 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);
  }
  /** Inits the Styles bold and regular */
  private void initStyles() {
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

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

    Style s = this.addStyle("bold", regular);
    StyleConstants.setBold(s, true);
  }
Exemple #16
0
 public static void addStyle(
     JTextPane textPane, String name, Color foreground, Color background, boolean bold) {
   StyledDocument doc = textPane.getStyledDocument();
   StyleContext context = StyleContext.getDefaultStyleContext();
   Style def = context.getStyle(StyleContext.DEFAULT_STYLE);
   Style style = doc.addStyle(name, def);
   if (foreground != null) StyleConstants.setForeground(style, foreground);
   if (background != null) StyleConstants.setBackground(style, background);
   StyleConstants.setBold(style, bold);
 }
 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");
 }
 public void actionPerformed(ActionEvent actionEvent) {
   JEditorPane editor = getEditor(actionEvent);
   if (editor != null) {
     MutableAttributeSet mutableAttributeSet = getStyledEditorKit(editor).getInputAttributes();
     SimpleAttributeSet simpleAttributeSet = new SimpleAttributeSet();
     StyleConstants.setStrikeThrough(
         simpleAttributeSet, !StyleConstants.isStrikeThrough(mutableAttributeSet));
     setCharacterAttributes(editor, simpleAttributeSet, false);
   }
 }
Exemple #19
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;
 }
 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();
   }
 }
    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);
    }
  /** 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);
  }
  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);
  }
  /**
   * 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;
  }
Exemple #25
0
 public void insertString(String sText, SimpleAttributeSet attributeSet) {
   int i = sText.indexOf("<u");
   if (i < 0) {
     i = sText.indexOf("<a");
     if (i < 0) {
       try {
         document.insertString(document.getLength(), sText, attributeSet);
       } catch (BadLocationException e) {
         e.printStackTrace();
       }
       return;
     } else {
       // <a>
       if (i > 0) {
         insertString(sText.substring(0, i), attributeSet);
         sText = sText.substring(i);
       }
       i = sText.indexOf("'");
       sText = sText.substring(i + 1);
       i = sText.indexOf("'");
       String sLink = sText.substring(0, i);
       i = sText.indexOf(">");
       sText = sText.substring(i + 1);
       i = sText.indexOf("</a>");
       SimpleAttributeSet attributeSet2 = new SimpleAttributeSet(attributeSet);
       StyleConstants.setForeground(attributeSet2, Color.BLUE);
       StyleConstants.setUnderline(attributeSet2, true);
       attributeSet2.addAttribute("link", sLink);
       insertString(sText.substring(0, i), attributeSet2);
       sText = sText.substring(i + "</a>".length());
       if (sText.length() > 0) {
         insertString(sText, attributeSet);
       }
     }
   } else {
     // <u>
     if (i > 0) {
       insertString(sText.substring(0, i), attributeSet);
       sText = sText.substring(i);
     }
     i = sText.indexOf("</u>");
     SimpleAttributeSet attributeSet2 = new SimpleAttributeSet(attributeSet);
     StyleConstants.setForeground(attributeSet2, Color.RED);
     insertString(sText.substring("<u>".length(), i), attributeSet2);
     sText = sText.substring(i + "</u>".length());
     if (sText.length() > 0) {
       insertString(sText, attributeSet);
     }
   }
 }
Exemple #26
0
  public JConsole() {
    super();

    setBackground(new Color(70, 70, 70));
    setForeground(Color.WHITE);
    text = new MyJTextPane();

    text.setAutoscrolls(true);
    final Font lFont = new Font("Monospaced", Font.PLAIN, 15);
    text.setText("");
    text.setFont(lFont);
    text.setMargin(new Insets(5, 3, 5, 3));
    text.addKeyListener(new MyKeyListener());
    setViewportView(text);

    contextMenu = new JPopupMenu();
    final ActionListener lActionListener = new MyActionListener();
    contextMenu.add(new JMenuItem(CMD_CUT)).addActionListener(lActionListener);
    contextMenu.add(new JMenuItem(CMD_COPY)).addActionListener(lActionListener);
    contextMenu.add(new JMenuItem(CMD_PASTE)).addActionListener(lActionListener);
    text.addMouseListener(new MyMouseListener());

    MutableAttributeSet attr = new SimpleAttributeSet();
    StyleConstants.setForeground(attr, Color.BLACK);

    attr = new SimpleAttributeSet();
    StyleConstants.setForeground(attr, Color.WHITE);
    attrOut = attr;

    attr = new SimpleAttributeSet();
    StyleConstants.setForeground(attr, Color.RED);
    StyleConstants.setItalic(attr, true);
    StyleConstants.setBold(attr, true);
    attrError = attr;

    try {
      fromConsoleStream = new PipedOutputStream();
      in = new PipedInputStream((PipedOutputStream) fromConsoleStream);

      final PipedOutputStream lOutPipe = new PipedOutputStream();
      out = new PrintStream(lOutPipe);

      final PipedOutputStream lErrPipe = new PipedOutputStream();
      err = new PrintStream(lErrPipe);

    } catch (IOException e) {
      e.printStackTrace();
    }
    requestFocus();
  }
 public void coloration() {
   String text = editor.getTextPaneEditor().getText().replaceAll("\n", " ");
   final StyledDocument doc = editor.getTextPaneEditor().getStyledDocument();
   final MutableAttributeSet normal = new SimpleAttributeSet();
   StyleConstants.setForeground(normal, Color.black);
   StyleConstants.setBold(normal, false);
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           doc.setCharacterAttributes(0, doc.getLength(), normal, true);
         }
       });
   colorationPrimitives(text, doc);
   colorationPolicyScript(text, doc);
 }
 public StyledTextList getContent(AttributeSet atts) {
   StyledTextList list = new StyledTextList();
   if (text != null) list.add(text + " - ", atts);
   SimpleAttributeSet italicAtts =
       (atts == null ? new SimpleAttributeSet() : new SimpleAttributeSet(atts));
   StyleConstants.setItalic(italicAtts, true);
   String bookName = Books.getCanon().getBook(book).getTitle();
   list.add(bookName, italicAtts);
   list.add(" ", atts);
   SimpleAttributeSet boldAtts =
       (atts == null ? new SimpleAttributeSet() : new SimpleAttributeSet(atts));
   StyleConstants.setBold(boldAtts, true);
   list.add(section, boldAtts);
   return list;
 }
Exemple #29
0
  {
    StyleContext context = new StyleContext();
    document = new DefaultStyledDocument(context);

    Style style = context.getStyle(StyleContext.DEFAULT_STYLE);
    StyleConstants.setAlignment(style, StyleConstants.ALIGN_LEFT);
  }
  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);
  }