/** 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);
 }
  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);
      }
    }
  }
  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 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);
  }
  /**
   * 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 #6
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());
  }
Exemple #7
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);
  }
    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);
    }
Exemple #9
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);
  }
Exemple #10
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();
  }
Exemple #11
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 #12
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;
  }
  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");
  }
Exemple #14
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;
  }
Exemple #15
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);
 }
 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);
 }
Exemple #17
0
 private void addString(ColorString cs) {
   if (cs.color != null) {
     StyleConstants.setForeground(conIrregular, cs.color);
     addString(cs.string, conIrregular);
   } else {
     addString(cs.string, conRegular);
   }
 }
Exemple #18
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);
  }
  /**
   * Construct the frame.
   *
   * @param numLines number of lines to show at a time
   * @param colorEnabled true to enable a colored console
   * @param trackProc process to track
   * @param killProcess true to kill the process on console close
   */
  public ConsoleFrame(
      int numLines, boolean colorEnabled, final Process trackProc, final boolean killProcess) {
    super("Spoutcraft Console");
    this.numLines = numLines;
    this.colorEnabled = colorEnabled;
    this.trackProc = trackProc;

    this.highlightedAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(highlightedAttributes, Color.BLACK);
    StyleConstants.setBackground(highlightedAttributes, Color.YELLOW);

    this.errorAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(errorAttributes, new Color(200, 0, 0));
    this.infoAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(infoAttributes, new Color(200, 0, 0));
    this.debugAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(debugAttributes, Color.DARK_GRAY);

    setSize(new Dimension(650, 400));
    buildUI();

    Compatibility.setIconImage(
        this, Toolkit.getDefaultToolkit().getImage(LoginFrame.spoutcraftIcon));

    if (trackProc != null) {
      track(trackProc);
    }

    addMouseListener(this);

    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent event) {
            if (trackProc != null && killProcess) {
              trackProc.destroy();
              if (loggerHandler != null) {
                rootLogger.removeHandler(loggerHandler);
              }
              event.getWindow().dispose();
            }
          }
        });
  }
  /**
   * 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);
  }
Exemple #21
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);
  }
Exemple #22
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;
 }
Exemple #23
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);
 }
Exemple #24
0
  public void appendNaive(Color c, String s) { // naive implementation
    // bad: instiantiates a new AttributeSet object on each call
    SimpleAttributeSet aset = new SimpleAttributeSet();
    StyleConstants.setForeground(aset, c);

    int len = getText().length();
    setCaretPosition(len); // place caret at the end (with no selection)
    setCharacterAttributes(aset, false);
    replaceSelection(s); // there is no selection, so inserts at caret
  }
Exemple #25
0
 public void addPlayerAction(Player player, String line) {
   try {
     StyleConstants.setForeground(actionStyle, player.getColor().getColor());
     text.insertString(text.getEndPosition().getOffset(), "* " + line + " *\n", actionStyle);
     // The pane auto-scrolls with each new response added
     textPane.setCaretPosition(text.getEndPosition().getOffset() - 1);
   } catch (BadLocationException e) {
     e.printStackTrace();
   }
 }
 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");
 }
 /*
  * append(String s, Color color){...}
  * This method is the same as append(String s) except
  * that this method also changes the color of the
  * indicated text instead of defaulting to white.
  */
 public static void append(String s, Color color) {
   style = tPane.addStyle("Styles", null);
   StyleConstants.setForeground(style, color);
   try {
     doc.insertString(doc.getLength(), s, style);
   } catch (BadLocationException ex) {
     System.out.println("BadLocationException ex caught.");
   }
   tPane.setCaretPosition(tPane.getDocument().getLength());
 }
Exemple #28
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);
  }
Exemple #29
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;
 }
Exemple #30
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);
 }