Java Code Examples for javax.swing.JTextPane#setEditorKit()

The following examples show how to use javax.swing.JTextPane#setEditorKit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestJTextPaneHTMLRendering.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static void createTestUI(JPanel panel) {
    textPane = new JTextPane();
    panel.add(textPane, BorderLayout.CENTER);

    final EditorKit l_kit = textPane.getEditorKitForContentType("text/html");
    textPane.setEditable(false);
    textPane.setEditorKit(l_kit);
    cache = (Dictionary<URL, Image>)textPane.getDocument().getProperty("imageCache");
    if (cache==null) {
        cache=new Hashtable<URL, Image>();
        textPane.getDocument().putProperty("imageCache",cache);
    }

    URL arrowLocationUrl = TestJTextPaneHTMLRendering.class.getResource("arrow.png");
    ImageIcon imageIcon = new ImageIcon(arrowLocationUrl);
    Image image = imageIcon.getImage();
    Image scaledImage = image.getScaledInstance(24, 24, java.awt.Image.SCALE_SMOOTH);
    cache.put(urlArrow, scaledImage);
    new Thread(TestJTextPaneHTMLRendering::runTest).start();
}
 
Example 2
Source File: DomGameFrame.java    From DominionSim with MIT License 6 votes vote down vote up
private JPanel getLogPanel() {
	JPanel theLogPanel = new JPanel();
	theLogPanel.setLayout(new BorderLayout());
	myLogPane = new JTextPane();
	myLogPane.setPreferredSize(new Dimension(400,300));
	editorKit = new HTMLEditorKit();
	gameLog = (HTMLDocument) editorKit.createDefaultDocument();;
	myLogPane.setEditorKit(editorKit);
	myLogPane.setDocument(gameLog);
	myLogScroll = new JScrollPane(myLogPane);
    myLogScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
//	theScrollPane.setPreferredSize(new Dimension(400,400));
	theLogPanel.add(myLogScroll,BorderLayout.CENTER);
    Font font = new Font("Times New Roman", Font.PLAIN, 14);
    String bodyRule = "body { font-family: " + font.getFamily() + "; " +
            "font-size: " + font.getSize() + "pt; }";
    ((HTMLDocument)myLogPane.getDocument()).getStyleSheet().addRule(bodyRule);//	myLogPane.revalidate();
	return theLogPanel;
}
 
Example 3
Source File: LogPanel.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
public LogPanel(Translator translator, RobotEntity robot) {
	this.translator = translator;
	this.robot = robot;
	
	// log panel
	Log.addListener(this);

	// the log panel
	log = new JTextPane();
	log.setEditable(false);
	log.setBackground(Color.BLACK);
	kit = new HTMLEditorKit();
	doc = new HTMLDocument();
	log.setEditorKit(kit);
	log.setDocument(doc);
	DefaultCaret caret = (DefaultCaret) log.getCaret();
	caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

	JScrollPane logPane = new JScrollPane(log);

	// Now put all the parts together
	panel.setLayout(new GridBagLayout());
	GridBagConstraints con1 = new GridBagConstraints();
	con1.gridx = 0;
	con1.gridy = 0;
	con1.weightx=1;
	con1.weighty=1;
	con1.fill=GridBagConstraints.HORIZONTAL;
	con1.anchor=GridBagConstraints.NORTHWEST;
	panel.add(logPane,con1);
	con1.gridy++;


	con1.weightx=1;
	con1.weighty=0;
	panel.add(getTextInputField(),con1);
	
	// lastly, clear the log
	clearLog();
}
 
Example 4
Source File: BrowserSwing.java    From Rel with Apache License 2.0 5 votes vote down vote up
private void setEnhancedOutputStyle(JTextPane pane) {
	pane.setContentType("text/html");
	pane.setEditable(false);
	pane.setEnabled(true);
	HTMLEditorKit editorKit = new HTMLEditorKit();
	HTMLDocument defaultDocument = (HTMLDocument) editorKit.createDefaultDocument();
	pane.setEditorKit(editorKit);
	pane.setDocument(defaultDocument);
	StyleSheet css = editorKit.getStyleSheet();
	for (String entry : style.getFormattedStyle())
		css.addRule(entry);
}
 
Example 5
Source File: GtpConsolePane.java    From lizzie with GNU General Public License v3.0 4 votes vote down vote up
/** Creates a Gtp Console Window */
public GtpConsolePane(Window owner) {
  super(owner);
  setTitle("Gtp Console");

  JSONArray pos = WindowPosition.gtpWindowPos();
  if (pos != null) {
    this.setBounds(pos.getInt(0), pos.getInt(1), pos.getInt(2), pos.getInt(3));
  } else {
    Insets oi = owner.getInsets();
    setBounds(
        0,
        owner.getY() - oi.top,
        Math.max(owner.getX() - oi.left, 400),
        Math.max(owner.getHeight() + oi.top + oi.bottom, 300));
  }

  htmlKit = new LizziePane.HtmlKit();
  htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
  htmlStyle = htmlKit.getStyleSheet();
  htmlStyle.addRule(Lizzie.config.gtpConsoleStyle);

  console = new JTextPane();
  console.setBorder(BorderFactory.createEmptyBorder());
  console.setEditable(false);
  console.setEditorKit(htmlKit);
  console.setDocument(htmlDoc);
  scrollPane = new JScrollPane();
  scrollPane.setBorder(BorderFactory.createEmptyBorder());
  txtCommand.setBackground(Color.DARK_GRAY);
  txtCommand.setForeground(Color.WHITE);
  lblCommand.setFont(new Font("Tahoma", Font.BOLD, 11));
  lblCommand.setOpaque(true);
  lblCommand.setBackground(Color.DARK_GRAY);
  lblCommand.setForeground(Color.WHITE);
  lblCommand.setText(Lizzie.leelaz == null ? "GTP>" : Lizzie.leelaz.currentShortWeight() + ">");
  pnlCommand.setLayout(new BorderLayout(0, 0));
  pnlCommand.add(lblCommand, BorderLayout.WEST);
  pnlCommand.add(txtCommand);
  getContentPane().add(scrollPane, BorderLayout.CENTER);
  getContentPane().add(pnlCommand, BorderLayout.SOUTH);
  scrollPane.setViewportView(console);
  getRootPane().setBorder(BorderFactory.createEmptyBorder());
  getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);

  txtCommand.addActionListener(e -> postCommand(e));
}
 
Example 6
Source File: CommentPane.java    From lizzie with GNU General Public License v3.0 4 votes vote down vote up
/** Creates a window */
public CommentPane(LizzieMain owner) {
  super(owner);
  setLayout(new BorderLayout(0, 0));

  htmlKit = new LizziePane.HtmlKit();
  htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
  htmlStyle = htmlKit.getStyleSheet();
  String style =
      "body {background:#"
          + String.format(
              "%02x%02x%02x",
              Lizzie.config.commentBackgroundColor.getRed(),
              Lizzie.config.commentBackgroundColor.getGreen(),
              Lizzie.config.commentBackgroundColor.getBlue())
          + "; color:#"
          + String.format(
              "%02x%02x%02x",
              Lizzie.config.commentFontColor.getRed(),
              Lizzie.config.commentFontColor.getGreen(),
              Lizzie.config.commentFontColor.getBlue())
          + "; font-family:"
          + Lizzie.config.fontName
          + ", Consolas, Menlo, Monaco, 'Ubuntu Mono', monospace;"
          + (Lizzie.config.commentFontSize > 0
              ? "font-size:" + Lizzie.config.commentFontSize
              : "")
          + "}";
  htmlStyle.addRule(style);

  commentPane = new JTextPane();
  commentPane.setBorder(BorderFactory.createEmptyBorder());
  commentPane.setEditorKit(htmlKit);
  commentPane.setDocument(htmlDoc);
  commentPane.setText("");
  commentPane.setEditable(false);
  commentPane.setFocusable(false);
  commentPane.addMouseListener(
      new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
          Lizzie.frame.getFocus();
        }
      });
  scrollPane = new JScrollPane();
  scrollPane.setBorder(BorderFactory.createEmptyBorder());
  scrollPane.setVerticalScrollBarPolicy(
      javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
  add(scrollPane);
  scrollPane.setViewportView(commentPane);
  setVisible(false);

  //    mouseMotionAdapter = new MouseMotionAdapter() {
  //      @Override
  //      public void mouseDragged(MouseEvent e) {
  //        System.out.println("Mouse Dragged");
  //        owner.dispatchEvent(e);
  //      }
  //    };
  //    commentPane.addMouseMotionListener(mouseMotionAdapter);
}
 
Example 7
Source File: SimpleGUI.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/**
 * This method displays the about box.
 */
public Runner doAbout() {
    if (wrap)
        return wrapMe();

    // Old about message
    // OurDialog.showmsg("About Alloy Analyzer " + Version.version(), OurUtil.loadIcon("images/logo.gif"), "Alloy Analyzer " + Version.version(), "Build date: " + " git: " + Version.commit, " ", "Lead developer: Felix Chang", "Engine developer: Emina Torlak", "Graphic design: Julie Pelaez", "Project lead: Daniel Jackson", " ", "Please post comments and questions to the Alloy Community Forum at http://alloy.mit.edu/", " ", "Thanks to: Ilya Shlyakhter, Manu Sridharan, Derek Rayside, Jonathan Edwards, Gregory Dennis,", "Robert Seater, Edmond Lau, Vincent Yeung, Sam Daitch, Andrew Yip, Jongmin Baek, Ning Song,", "Arturo Arizpe, Li-kuo (Brian) Lin, Joseph Cohen, Jesse Pavel, Ian Schechter, and Uriel Schafer.");

    HTMLEditorKit kit = new HTMLEditorKit();
    StyleSheet styleSheet = kit.getStyleSheet();
    styleSheet.addRule("body {color:#000; font-family:Verdana, Trebuchet MS,Geneva, sans-serif; font-size: 10px; margin: 4px; }");
    styleSheet.addRule("h1 {color: blue;}");
    styleSheet.addRule("h2 {color: #ff0000;}");
    styleSheet.addRule("pre {font : 10px monaco; color : black; background-color: #C0C0C0; padding: 4px; margin: 4px; }");
    styleSheet.addRule("th {text-align:left;}");

    JTextPane ta = new JTextPane();
    ta.setEditorKit(kit);
    ta.setContentType("text/html");
    ta.setBackground(null);
    ta.setBorder(null);
    ta.setFont(new JLabel().getFont());
    // @formatter:off
    ta.setText("<html><h1>Alloy Analyzer " + Version.getShortversion() + "</h1>"
    + "<br/>"
    + "<html>"
    + "<tr><th>Project Lead</th><td>Daniel Jackson</td></tr>"
    + "<tr><th>Chief Developer</th><td>Aleksandar Milicevic</td></tr>"
    + "<tr><th>Kodkod Engine</th><td>Emina Torlak</td></tr>"
    + "<tr><th>Open Source</th><td>Peter Kriens</td></tr>"
    + "</table><br/>"
    + "<p>For more information about Alloy, <a href='http://alloytools.org'>http://alloytools.org</a></p>"
    + "<p>Questions and comments about Alloy are welcome at the community forum:</p>"
    + "<p>Alloy Community Forum: <a href='https://groups.google.com/forum/#!forum/alloytools'>https://groups.google.com/forum/#!forum/alloytools</a></p>"
    + "<p>Alloy experts also respond to <a href='https://stackoverflow.com/questions/tagged/alloy'>https://stackoverflow.com</a> questions tagged <code>alloy</code>.</p>"
    + "<p>Major contributions to earlier versions of Alloy were made by: Felix Chang (v4);<br/>"
    + "Jonathan Edwards, Eunsuk Kang, Joe Near, Robert Seater, Derek Rayside, Greg Dennis,<br/>"
    + "Ilya Shlyakhter, Mana Taghdiri, Mandana Vaziri, Sarfraz Khurshid (v3); Manu Sridharan<br/>"
    + "(v2); Edmond Lau, Vincent Yeung, Sam Daitch, Andrew Yip, Jongmin Baek, Ning Song,<br/>"
    + "Arturo Arizpe, Li-kuo (Brian) Lin, Joseph Cohen, Jesse Pavel, Ian Schechter, Uriel<br/>"
    + "Schafer (v1).</p>"
    + "<p>The development of Alloy was funded by part by the National Science Foundation under<br/>"
    + "Grant Nos. 0325283, 0541183, 0438897 and 0707612; by the Air Force Research Laboratory<br/>"
    + "(AFRL/IF) and the Disruptive Technology Office (DTO) in the National Intelligence<br/>"
    + "Community Information Assurance Research (NICIAR) Program; and by the Nokia<br/>"
    + "Corporation as part of a collaboration between Nokia Research and MIT CSAIL.</p>"
    + "<br/><pre>"
    + "Build Date: " + Version.buildDate() + "<br/>"
    + "Git Commit: " + Version.commit
    + "</pre>");
    // @formatter:on
    ta.setEditable(false);
    ta.addHyperlinkListener((e) -> {
        if (e.getEventType() == EventType.ACTIVATED) {
            if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
                try {
                    Desktop.getDesktop().browse(e.getURL().toURI());
                } catch (IOException | URISyntaxException e1) {
                    // ignore
                }
            }
        }
    });
    OurDialog.showmsg("About Alloy Analyzer " + Version.version(), ta);

    return null;
}