Example #1
0
  /**
   * Appends a message sent by the system
   *
   * @param text The message to append
   * @param colour The colour of the player, <code>null</code> if none
   */
  private void addSystemText(final String text, final Color colour) {
    StyleContext style = StyleContext.getDefaultStyleContext();
    AttributeSet attrs;

    final int pos0 = getDocument().getLength();
    final int pos1 = pos0 + (text + "\n").length();

    this.setEditable(true);

    attrs =
        style.addAttribute(
            SimpleAttributeSet.EMPTY,
            StyleConstants.Foreground,
            colour == null ? Color.GRAY : colour);
    attrs = style.addAttribute(attrs, StyleConstants.Italic, Boolean.TRUE);

    this.setSelectionStart(pos0);
    this.setSelectionEnd(pos0);
    this.replaceSelection(text + "\n"); // Prints the system's message
    this.setSelectionStart(pos0);
    this.setSelectionEnd(pos1);
    this.setCharacterAttributes(attrs, true);

    this.setSelectionStart(pos1);
    this.setSelectionEnd(pos1);
    this.setEditable(false);
  }
Example #2
0
 public void append(Color c, String s) {
   StyleContext sc = StyleContext.getDefaultStyleContext();
   AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
   int len = getDocument().getLength();
   setCaretPosition(len);
   setCharacterAttributes(aset, false);
   replaceSelection(s);
 }
Example #3
0
  public void appendToPane(String msg, Color c) {
    if (inputText.isEnabled()) {
      StyleContext sc = StyleContext.getDefaultStyleContext();
      AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

      textArea.setCharacterAttributes(aset, false);
      textArea.replaceSelection(msg);
      textArea.setCaretPosition(textArea.getDocument().getLength());
    }
  }
Example #4
0
  /**
   * Appends a message sent by a player
   *
   * @param text The message to append
   * @param name The player whom sent the message
   * @param colour The colour of the player
   */
  private void addUserText(final String text, final String name, final Color colour) {
    StyleContext style = StyleContext.getDefaultStyleContext();
    AttributeSet attrs;

    attrs =
        style.addAttribute(
            SimpleAttributeSet.EMPTY,
            StyleConstants.Foreground,
            colour); // Switching to player name style
    attrs = style.addAttribute(attrs, StyleConstants.Bold, Boolean.TRUE);

    final int pos0 = getDocument().getLength();
    final int pos1 = pos0 + (name + ": ").length();
    final int pos2 = pos1 + (text + "\n").length();

    this.setEditable(true);

    this.setSelectionStart(pos0);
    this.setSelectionEnd(pos0);
    this.replaceSelection(name + ": "); // Prints the player's name
    this.setSelectionStart(pos0);
    this.setSelectionEnd(pos1);
    this.setCharacterAttributes(attrs, true);

    attrs =
        style.addAttribute(
            SimpleAttributeSet.EMPTY,
            StyleConstants.Foreground,
            Color.WHITE); // Switing to message style

    this.setSelectionStart(pos1);
    this.setSelectionEnd(pos1);
    this.replaceSelection(text + "\n"); // Prints the player's message
    this.setSelectionStart(pos1);
    this.setSelectionEnd(pos2);
    this.setCharacterAttributes(attrs, true);

    this.setSelectionStart(pos2);
    this.setSelectionEnd(pos2);
    this.setEditable(false);
  }
Example #5
0
 /**
  * Add the provided text with the provided color to the GUI document
  *
  * @param text The text that will be added
  * @param color The color used to show the text
  */
 public void print(String text, Color color) {
   StyleContext sc = StyleContext.getDefaultStyleContext();
   AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);
   int len = logPane.getDocument().getLength();
   try {
     logPane.setCaretPosition(len);
     logPane.getDocument().insertString(len, text + "\n", aset);
   } catch (BadLocationException e) {
     LoggerFactory.getLogger(ProcessUIPanel.class).error("Cannot show the log message", e);
   }
   logPane.setCaretPosition(logPane.getDocument().getLength());
 }