Ejemplo n.º 1
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;
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
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;
  }
  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);
  }
Ejemplo n.º 5
0
  public mainWindow(Controller c, RandomEventGenerator r, Safety s) {

    // use system look and feel
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      // do nothing
    }

    view = new ElevatorSimView();
    safety = s;
    controller = c;
    randomEventGen = r;
    simStarted = false;

    JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    initComponents();

    setGUIEnabled(false);

    SimViewPanel.add(view.getCanvas(), BorderLayout.CENTER);
    this.validate();

    AlgorithmDescBox.setText(controller.getAlgorithmDesc(0));

    doc = MsgBox.getStyledDocument();

    Style style = MsgBox.addStyle("Faults", null);
    StyleConstants.setForeground(style, Color.red);
    StyleConstants.setItalic(style, true);
    StyleConstants.setBold(style, true);

    style = MsgBox.addStyle("Passengers", null);
    StyleConstants.setForeground(style, new Color(0, 204, 204));
    StyleConstants.setItalic(style, true);

    style = MsgBox.addStyle("Normal", null);

    style = MsgBox.addStyle("Elevators", null);
    StyleConstants.setForeground(style, new Color(51, 255, 0));
    StyleConstants.setBold(style, true);

    style = MsgBox.addStyle("Emergs", null);
    StyleConstants.setForeground(style, Color.red);
    StyleConstants.setBold(style, true);

    style = MsgBox.addStyle("Maintenance", null);
    StyleConstants.setForeground(style, Color.ORANGE);
    StyleConstants.setBold(style, true);

    // Hijack the keyboard manager
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(new KeyDispatcher(this));

    // add window listener
    this.addWindowListener(new mainWindowListener());
  }
Ejemplo 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);
  }
Ejemplo n.º 7
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);
  }
Ejemplo n.º 8
0
 private void initializeAttributeSets() {
   incomingMsgAttrSet = new SimpleAttributeSet();
   outgoingMsgAttrSet = new SimpleAttributeSet();
   onlineClientAttrSet = new SimpleAttributeSet();
   offlineClientAttrSet = new SimpleAttributeSet();
   eavesdropAttrSet = new SimpleAttributeSet();
   StyleConstants.setForeground(incomingMsgAttrSet, Color.BLACK);
   StyleConstants.setForeground(outgoingMsgAttrSet, Color.BLUE);
   StyleConstants.setForeground(onlineClientAttrSet, Color.GREEN);
   StyleConstants.setForeground(offlineClientAttrSet, Color.RED);
   StyleConstants.setForeground(eavesdropAttrSet, Color.lightGray);
   StyleConstants.setBold(incomingMsgAttrSet, true);
   StyleConstants.setBold(onlineClientAttrSet, true);
   StyleConstants.setBold(offlineClientAttrSet, true);
   StyleConstants.setItalic(outgoingMsgAttrSet, true);
   StyleConstants.setItalic(eavesdropAttrSet, true);
 }
Ejemplo n.º 9
0
  private void utworzStyle() {
    doc = this.poleRozmowy.getStyledDocument();
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
    regular = doc.addStyle("regular", def);

    bold = doc.addStyle("bold", regular);
    StyleConstants.setBold(bold, true);
  }
Ejemplo n.º 10
0
  public static void main(String[] args) {

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JBubblePanel bubblePanel = new JBubblePanel();
    JTextPane textPane = new JTextPane();
    bubblePanel.setLayout(new BorderLayout());
    bubblePanel.add(textPane, BorderLayout.CENTER);

    Font normalFont = new Font("Arial", Font.PLAIN, 12);
    Font boldFont = new Font("Arial", Font.BOLD, 12);

    SimpleAttributeSet normal = new SimpleAttributeSet();
    SimpleAttributeSet bold = new SimpleAttributeSet();
    StyleConstants.setBold(bold, true);

    try {
      textPane
          .getDocument()
          .insertString(textPane.getDocument().getLength(), "Your connection to ", normal);
      textPane
          .getDocument()
          .insertString(textPane.getDocument().getLength(), "cvs.dev.java.net ", bold);
      textPane
          .getDocument()
          .insertString(
              textPane.getDocument().getLength(),
              "failed. Here are a few possible reasons.\n\n",
              normal);
      textPane
          .getDocument()
          .insertString(
              textPane.getDocument().getLength(),
              " Your computer is may not be connected to the network.\n"
                  + "* The CVS server name may be entered incorrectly.\n\n",
              normal);
      textPane
          .getDocument()
          .insertString(
              textPane.getDocument().getLength(),
              "If you still can not connect, please contact support at ",
              normal);
      textPane
          .getDocument()
          .insertString(textPane.getDocument().getLength(), "*****@*****.**", bold);
      textPane.getDocument().insertString(textPane.getDocument().getLength(), ".", normal);
    } catch (BadLocationException ex) {
      ex.printStackTrace();
    }

    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(bubblePanel, BorderLayout.CENTER);

    frame.setBounds(200, 300, 400, 360);
    frame.setVisible(true);
  }
Ejemplo n.º 11
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);
  }
Ejemplo n.º 12
0
  /** 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);
  }
Ejemplo n.º 13
0
  // Update the box that shows current actions.
  public void updateGUI(String message) {
    StyledDocument text = updateBox.getStyledDocument();
    SimpleAttributeSet currentWords = new SimpleAttributeSet();
    StyleConstants.setBold(currentWords, true);
    SimpleAttributeSet pastWords = new SimpleAttributeSet();
    StyleConstants.setBold(pastWords, false);

    try {
      text.setCharacterAttributes(0, text.getLength(), pastWords, true);
      text.insertString(0, message + "\n", currentWords);
    } catch (BadLocationException e) {
      // TODO Auto-generated catch block
      System.err.println("Bad location exception while styling updateBox.");
      e.printStackTrace();
    }

    updateBox.setCaretPosition(0);
  }
Ejemplo n.º 14
0
  // Positionnement des élements de l'interface
  // Création des styles
  private void createInterface() {
    L_PortBr.setBounds(10, 10, 50, 20);
    TF_Port.setBounds(40, 10, 120, 20);
    B_ToggleConnect.setBounds(170, 10, 150, 20);
    SP_ScrollRooms.setBounds(10, 40, 150, 430);
    SP_ScrollPeople.setBounds(170, 40, 150, 430);
    L_Info.setBounds(10, 480, 310, 20);

    StyleConstants.setBold(SAS_bold, true);
    StyleConstants.setItalic(SAS_info, true);
    StyleConstants.setBold(SAS_info_bold, true);
    StyleConstants.setForeground(SAS_info_bold, Color.GREEN);
    StyleConstants.setForeground(SAS_info, Color.GREEN);
    StyleConstants.setItalic(SAS_error, true);
    StyleConstants.setBold(SAS_error_bold, true);
    StyleConstants.setForeground(SAS_error_bold, Color.RED);
    StyleConstants.setForeground(SAS_error, Color.RED);
  }
Ejemplo n.º 15
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;
 }
Ejemplo n.º 16
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);
 }
Ejemplo n.º 17
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);
 }
Ejemplo n.º 18
0
 /**
  * 返回属性集
  *
  * @return
  */
 public SimpleAttributeSet getAttrSet() {
   attrSet = new SimpleAttributeSet();
   if (name != null) StyleConstants.setFontFamily(attrSet, name);
   if (style == FontAttrib.GENERAL) {
     StyleConstants.setBold(attrSet, false);
     StyleConstants.setItalic(attrSet, false);
   } else if (style == FontAttrib.BOLD) {
     StyleConstants.setBold(attrSet, true);
     StyleConstants.setItalic(attrSet, false);
   } else if (style == FontAttrib.ITALIC) {
     StyleConstants.setBold(attrSet, false);
     StyleConstants.setItalic(attrSet, true);
   } else if (style == FontAttrib.BOLD_ITALIC) {
     StyleConstants.setBold(attrSet, true);
     StyleConstants.setItalic(attrSet, true);
   }
   StyleConstants.setFontSize(attrSet, size);
   if (color != null) StyleConstants.setForeground(attrSet, color);
   if (backColor != null) StyleConstants.setBackground(attrSet, backColor);
   return attrSet;
 }
Ejemplo n.º 19
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);
  }
  private synchronized void append(LogRecord record) {
    Document doc = textArea.getStyledDocument();
    String formatted = formatter.format(record);

    if (record.getLevel().intValue() >= Level.SEVERE.intValue()) {
      StyleConstants.setForeground(attributeSet, COLOR_ERROR);
      StyleConstants.setBold(attributeSet, true);
    } else if (record.getLevel().intValue() >= Level.WARNING.intValue()) {
      StyleConstants.setForeground(attributeSet, COLOR_WARNING);
      StyleConstants.setBold(attributeSet, true);
    } else if (record.getLevel().intValue() >= Level.INFO.intValue()) {
      StyleConstants.setForeground(attributeSet, COLOR_INFO);
      StyleConstants.setBold(attributeSet, false);
    } else {
      StyleConstants.setForeground(attributeSet, COLOR_DEFAULT);
      StyleConstants.setBold(attributeSet, false);
    }

    try {
      doc.insertString(doc.getLength(), formatted, attributeSet);
    } catch (BadLocationException e) {
      // cannot happen
      // rather dump to stderr than logging and having this method called back
      e.printStackTrace();
    }

    if (maxRows >= 0) {
      int removeLength = 0;
      while (lineLengths.size() > maxRows) {
        removeLength += lineLengths.removeFirst();
      }
      try {
        doc.remove(0, removeLength);
      } catch (BadLocationException e) {
        SwingTools.showSimpleErrorMessage("error_during_logging", e);
      }
    }
    textArea.setCaretPosition(textArea.getDocument().getLength());
  }
Ejemplo n.º 21
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.º 22
0
  private void prepareStyles() {
    StyledDocument doc = parent.getStyledDocument();
    plainStyle = doc.addStyle("PLAIN_STYLE", null);
    StyleConstants.setItalic(plainStyle, false);
    StyleConstants.setBold(plainStyle, false);

    boldStyle = doc.addStyle("BOLD_STYLE", null);
    StyleConstants.setBold(boldStyle, true);
    StyleConstants.setForeground(boldStyle, new Color(38, 128, 2));

    nonBoldStyle = doc.addStyle("NON_BOLD_STYLE", null);
    StyleConstants.setBold(nonBoldStyle, false);

    fontSizeStyle = doc.addStyle("FONT_SIZE", null);
    StyleConstants.setFontSize(fontSizeStyle, 40);

    black = new SimpleAttributeSet();
    black.addAttribute(StyleConstants.CharacterConstants.Foreground, Color.black);

    brackets = new SimpleAttributeSet();
    brackets.addAttribute(StyleConstants.CharacterConstants.Foreground, Color.BLACK);
  }
Ejemplo n.º 23
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();
  }
Ejemplo n.º 24
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);
    }
  }
Ejemplo n.º 25
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);
  }
 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;
 }
 public void colorationPolicyScript(String text, final StyledDocument doc) {
   Pattern p = Pattern.compile("(GraphOScript)");
   Matcher m = p.matcher(text);
   while (m.find() == true) {
     MutableAttributeSet attri = new SimpleAttributeSet();
     StyleConstants.setForeground(attri, Color.orange);
     StyleConstants.setBold(attri, true);
     final int start = m.start(0);
     final int end = m.end(0);
     final int length = end - start;
     final MutableAttributeSet style = attri;
     SwingUtilities.invokeLater(
         new Runnable() {
           public void run() {
             doc.setCharacterAttributes(start, length, style, true);
           }
         });
   }
 }
Ejemplo n.º 29
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);
  }
Ejemplo n.º 30
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());
    }
  }