javax.swing.JTextPane#setEditorKit ( )源码实例Demo

下面列出了javax.swing.JTextPane#setEditorKit ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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();
}
 
源代码2 项目: DominionSim   文件: DomGameFrame.java
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;
}
 
源代码3 项目: Robot-Overlord-App   文件: LogPanel.java
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();
}
 
源代码4 项目: Rel   文件: BrowserSwing.java
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);
}
 
源代码5 项目: lizzie   文件: GtpConsolePane.java
/** 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));
}
 
源代码6 项目: lizzie   文件: CommentPane.java
/** 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);
}
 
源代码7 项目: org.alloytools.alloy   文件: SimpleGUI.java
/**
 * 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;
}