示例#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);
  }
示例#2
0
  public static void appendToPane(JTextPane tp, String msg, Color c) {
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

    aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");
    aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);

    int len = tp.getDocument().getLength();
    tp.setCaretPosition(len);
    tp.setCharacterAttributes(aset, false);
    tp.replaceSelection(msg);
  }
示例#3
0
  public void toScreen(String s, Class module, String TYPE) {
    Color c = Color.BLACK;
    if (TYPE != null) {
      if (TYPE.contains("ERROR")) c = Color.RED;
      if (TYPE.contains("WARNING")) c = new Color(255, 106, 0);
      if (TYPE.contains("DEBUG")) c = Color.BLUE;
      if (module.toString().equalsIgnoreCase("Exception")) c = Color.RED;
    }
    StyleContext sc = StyleContext.getDefaultStyleContext();
    javax.swing.text.AttributeSet aset =
        sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
    int len = SCREEN.getDocument().getLength(); // same value as
    SCREEN.setCaretPosition(len); // place caret at the end (with no selection)
    SCREEN.setCharacterAttributes(aset, false);
    SCREEN.replaceSelection(
        "["
            + getData()
            + " - "
            + module.getSimpleName()
            + " - "
            + TYPE
            + "] "
            + s
            + "\n"); // there is no selection, so inserts at caret
    SCREEN.setFont(new Font("Monospaced", Font.PLAIN, 14));

    aggiungiRiga(s, module, TYPE);
  }
示例#4
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);
 }
示例#5
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());
    }
  }
示例#6
0
  public void append(Color c, String s) { // better implementation--uses
    // StyleContext
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

    int len = getDocument().getLength(); // same value as
    // 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
  }
示例#7
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);
  }
示例#8
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());
 }
示例#9
0
 private void changeAttribute(Color color) {
   StyleContext sc = StyleContext.getDefaultStyleContext();
   aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);
 }