Exemplo n.º 1
0
 /**
  * Outputs the named style. <code>outputStyle</code> indicates whether or not a style has been
  * output yet. This will return true if a style is written.
  */
 boolean writeStyle(String name, Style style, boolean outputStyle) throws IOException {
   boolean didOutputStyle = false;
   Enumeration attributes = style.getAttributeNames();
   if (attributes != null) {
     while (attributes.hasMoreElements()) {
       Object attribute = attributes.nextElement();
       if (attribute instanceof CSS.Attribute) {
         String value = style.getAttribute(attribute).toString();
         if (value != null) {
           if (!outputStyle) {
             writeStyleStartTag();
             outputStyle = true;
           }
           if (!didOutputStyle) {
             didOutputStyle = true;
             indent();
             write(name);
             write(" {");
           } else {
             write(";");
           }
           write(' ');
           write(attribute.toString());
           write(": ");
           write(value);
         }
       }
     }
   }
   if (didOutputStyle) {
     write(" }");
     writeLineSeparator();
   }
   return didOutputStyle;
 }
Exemplo n.º 2
0
  protected void copy(EditorConfiguration src, EditorConfiguration dst) {
    dst.title = src.title;
    dst.mimeType = src.mimeType;
    Enumeration styleNames = src.styleContext.getStyleNames();
    if (src.styleContext == dst.styleContext) dst.styleContext = new StyleContext();
    while (styleNames.hasMoreElements()) {
      String sname = (String) styleNames.nextElement();
      Style style = src.styleContext.getStyle(sname);

      Style newStyle = dst.styleContext.addStyle(sname, null);
      newStyle.addAttributes(style.copyAttributes());
    }

    styleNames = dst.styleContext.getStyleNames();
    while (styleNames.hasMoreElements()) {
      String sname = (String) styleNames.nextElement();
      Style style = src.styleContext.getStyle(sname);
      AttributeSet resolveParent = style.getResolveParent();
      Style parent = (Style) resolveParent;

      if (parent != null) {
        dst.styleContext
            .getStyle(sname)
            .setResolveParent(dst.styleContext.getStyle(parent.getName()));
      }
    }
  }
Exemplo n.º 3
0
  /**
   * Update the color in the default style of the document.
   *
   * @param color the new color to use or null to remove the color attribute from the document's
   *     style
   */
  private void updateForeground(Color color) {
    StyledDocument doc = (StyledDocument) getComponent().getDocument();
    Style style = doc.getStyle(StyleContext.DEFAULT_STYLE);

    if (style == null) {
      return;
    }

    if (color == null) {
      style.removeAttribute(StyleConstants.Foreground);
    } else {
      StyleConstants.setForeground(style, color);
    }
  }
Exemplo n.º 4
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());
    }
  }
Exemplo n.º 5
0
 /**
  * Puts colored text in the JTextPane1
  *
  * @param str String to put in JTextPane
  * @param color Color chosen for the text
  * @throws BadLocationException
  */
 public void appendjTextPane1(String str, int color) throws BadLocationException {
   if (color == 1) {
     // SENDER USERNAME
     StyledDocument document = (StyledDocument) jTextPane1.getDocument();
     Style style = jTextPane1.addStyle("I'm a Style", null);
     StyleConstants.setForeground(style, Color.ORANGE);
     style.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.TRUE);
     document.insertString(document.getLength(), str, style);
   } else if (color == 0) {
     // MESSAGES
     StyledDocument document = (StyledDocument) jTextPane1.getDocument();
     Style style = jTextPane1.addStyle("I'm a Style", null);
     StyleConstants.setForeground(style, Color.black);
     document.insertString(document.getLength(), str, style);
   } else if (color == 2) {
     // RECEIVER USERNAME
     StyledDocument document = (StyledDocument) jTextPane1.getDocument();
     Style style = jTextPane1.addStyle("I'm a Style", null);
     StyleConstants.setForeground(style, Color.black);
     style.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.TRUE);
     document.insertString(document.getLength(), str, style);
   }
 }
Exemplo n.º 6
0
  public ConsoleWindow() {
    if (gui) {
      window = new JFrame("Package Tracking Console");
      window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      window.setSize((int) (screenSize.getWidth() / 4), (int) (screenSize.getHeight() / 1.5));
      window.setLocationRelativeTo(null);
      window.getContentPane().setLayout(new BorderLayout());

      menuBar = new JMenuBar();
      menuBar.add("test", new JLabel("Testing"));
      window.setJMenuBar(menuBar);

      StyleContext sc = new StyleContext();
      document = new DefaultStyledDocument(sc);

      // Styles

      send = sc.addStyle("(Send)", null);
      send.addAttribute(StyleConstants.Foreground, Color.CYAN);

      info = sc.addStyle("(Info)", null);
      info.addAttribute(StyleConstants.Foreground, Color.WHITE);

      warning = sc.addStyle("(Warning)", null);
      warning.addAttribute(StyleConstants.Foreground, Color.YELLOW);

      error = sc.addStyle("(Error)", null);
      error.addAttribute(StyleConstants.Foreground, Color.RED);
      error.addAttribute(StyleConstants.Bold, new Boolean(true));

      textArea = new JTextPane(document);
      textArea.setBackground(new Color(50, 50, 50));
      textArea.setEditable(true);
      textArea.setBorder(null);
      textArea.setForeground(Color.WHITE);

      scrollPane = new JScrollPane(textArea);
      new SmartScroller(scrollPane);

      window.getContentPane().add(scrollPane);

      input = new JTextField();
      input.setBackground(new Color(50, 50, 50));
      input.setForeground(Color.WHITE);
      input.setCaretColor(Color.WHITE);
      input.addActionListener(new test());
      window.getContentPane().add(input, BorderLayout.SOUTH);

      window.setVisible(true);
      info.addAttribute(StyleConstants.Foreground, Color.BLUE);
    }
  }
Exemplo n.º 7
0
  public void displayScriptError(ScriptExceptionContainer se) {
    errorStyle.addAttribute("ip", se.ip);
    errorStyle.addAttribute("exception", se.exception);
    errorStyleRed.addAttribute("ip", se.ip);
    errorStyleRed.addAttribute("exception", se.exception);
    errorStyleMono.addAttribute("ip", se.ip);
    errorStyleMono.addAttribute("exception", se.exception);

    addStyledText("\n", null);
    addStyledText("Error", errorStyleRed);
    addStyledText(" at ", errorStyle);
    addStyledText(se.ip, errorStyleMono);
  }
  @SuppressWarnings({"LeakingThisInConstructor", "BooleanConstructorCall"})
  public ConversationTopComponent() {
    initComponents();
    //		setName(Bundle.CTL_ConversationTopComponent());
    //		setToolTipText(Bundle.HINT_ConversationTopComponent());
    m_commandHistory = new Vector<String>();

    StyleContext sc = new StyleContext();
    commanddoc = new DefaultStyledDocument(sc);

    responseStyle = sc.addStyle("Response", null);
    responseStyle.addAttribute(StyleConstants.Foreground, Color.black);
    responseStyle.addAttribute(StyleConstants.FontSize, 16);
    responseStyle.addAttribute(StyleConstants.FontFamily, "serif");
    responseStyle.addAttribute(StyleConstants.Bold, false);

    errorStyle = sc.addStyle("Error", null);
    errorStyle.addAttribute(StyleConstants.Foreground, Color.red);
    errorStyle.addAttribute(StyleConstants.FontSize, 16);
    errorStyle.addAttribute(StyleConstants.FontFamily, "serif");
    errorStyle.addAttribute(StyleConstants.Bold, true);

    commandStyle = sc.addStyle("Command", null);
    commandStyle.addAttribute(StyleConstants.Foreground, Color.blue);
    commandStyle.addAttribute(StyleConstants.FontSize, 16);
    commandStyle.addAttribute(StyleConstants.FontFamily, "serif");
    commandStyle.addAttribute(StyleConstants.Bold, false);

    inCommandStyle = sc.addStyle("InCommand", null);
    inCommandStyle.addAttribute(StyleConstants.Foreground, Color.green);
    inCommandStyle.addAttribute(StyleConstants.FontSize, 16);
    inCommandStyle.addAttribute(StyleConstants.FontFamily, "serif");
    inCommandStyle.addAttribute(StyleConstants.Bold, false);

    warningStyle = sc.addStyle("Warning", null);
    warningStyle.addAttribute(StyleConstants.Foreground, Color.yellow);
    warningStyle.addAttribute(StyleConstants.FontSize, 16);
    warningStyle.addAttribute(StyleConstants.FontFamily, "serif");
    warningStyle.addAttribute(StyleConstants.Bold, true);

    textCommand.setDocument(commanddoc);

    try {
      commanddoc.insertString(0, "Pronto!\n\n", responseStyle);
    } catch (BadLocationException ex) {
      Exceptions.printStackTrace(ex);
    }
  }
Exemplo n.º 9
0
 /** @param c */
 public void setErrorTextColor(Color c) {
   error.addAttribute(StyleConstants.Foreground, c);
 }
Exemplo n.º 10
0
 /** @param c */
 public void setWarningTextColor(Color c) {
   warning.addAttribute(StyleConstants.Foreground, c);
 }
Exemplo n.º 11
0
 /** @param c */
 public void setInfoTextColor(Color c) {
   info.addAttribute(StyleConstants.Foreground, c);
 }
Exemplo n.º 12
0
 /** @param c */
 public void setInputTextColor(Color c) {
   send.addAttribute(StyleConstants.Foreground, c);
 }
Exemplo n.º 13
0
  /*
   * (non-Javadoc)
   *
   * @see org.quiltplayer.view.components.View#getUI()
   */
  @Override
  public JComponent getUI() {

    panel = new JPanel(new MigLayout("ins 1cm 3cm 0 3cm, center, w 80%!"));
    panel.setOpaque(true);

    JEditorPane htmlPane = null;
    htmlPane =
        new JEditorPane("text/html", content) {

          /*
           * (non-Javadoc)
           *
           * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
           */
          @Override
          protected void paintComponent(Graphics g) {
            Graphics2D g2d = (Graphics2D) g;
            g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

            super.paintComponent(g);
          }
        };

    htmlPane.setOpaque(false);
    htmlPane.setDragEnabled(false);
    htmlPane.setEditable(true);
    htmlPane.setFocusable(false);
    htmlPane.setFont(FontFactory.getFont(13));
    htmlPane.setForeground(Color.white);
    htmlPane.setBounds(10, 10, panel.getWidth() - 150, panel.getHeight());

    final Font font = FontFactory.getFont(13);

    String pRule =
        "p { font-family: "
            + font.getName()
            + "; "
            + "font-size: "
            + font.getSize()
            + "pt; color: #EEEEEE; }";
    String spanRule =
        "span { font-family: "
            + font.getName()
            + "; "
            + "font-size: "
            + font.getSize()
            + "pt; color: #FFFFFF; }";
    String linkRule =
        "a { font-family: "
            + font.getName()
            + "; "
            + "font-size: "
            + font.getSize()
            + "pt;"
            + "color: #AAAAAA;}";
    String linkRule2 =
        "a:hoover { text-decoration: none; font-family: "
            + font.getFamily()
            + "; "
            + "font-size: "
            + font.getSize()
            + "pt;"
            + "color: #FFFFFF;}";

    ((HTMLDocument) htmlPane.getDocument()).getStyleSheet().addRule(linkRule);
    ((HTMLDocument) htmlPane.getDocument()).getStyleSheet().addRule(pRule);
    ((HTMLDocument) htmlPane.getDocument()).getStyleSheet().addRule(spanRule);
    ((HTMLDocument) htmlPane.getDocument()).getStyleSheet().addRule(linkRule2);

    StyleSheet styles = ((HTMLDocument) htmlPane.getDocument()).getStyleSheet();

    Enumeration<?> rules = styles.getStyleNames();
    while (rules.hasMoreElements()) {
      String name = (String) rules.nextElement();
      Style rule = styles.getStyle(name);
      System.out.println(rule.toString());
    }

    htmlPane.setCaretPosition(0);

    panel.add(htmlPane, "w 100%, h 100%");

    final QScrollPane pane = new QScrollPane(panel, ScrollDirection.VERTICAL);

    return new JXLayer<JScrollPane>(pane, new JScrollPaneLayerUI());
  }