Exemplo n.º 1
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());
  }