Java Code Examples for javax.swing.JEditorPane#setPage()

The following examples show how to use javax.swing.JEditorPane#setPage() . 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: HTMLPrintable.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
public void loadPage(String url, final ActionListener listener)
        throws IOException {
    this.url = url;
    pane = new JEditorPane();
    pane.setContentType("text/html");
    pane.addPropertyChangeListener("page", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            generate(0);
            if (listener != null)
                listener.actionPerformed(new ActionEvent(
                        HTMLPrintable.this, 0, "PageLoaded"));
        }
    });
    pane.setPage(url);
}
 
Example 2
Source File: FuzzyDemo.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 6 votes vote down vote up
private JComponent createHtmlPanel(String url) {

		JScrollPane scroll = new JScrollPane();

		JEditorPane editorPane = new JEditorPane();
		editorPane.setEditable(false);
		java.net.URL helpURL = this.getClass().getResource(url);
		if (helpURL != null) {
			try {
				editorPane.setPage(helpURL);
			} catch (IOException e) {
				System.err.println("Attempted to read a bad URL: " + helpURL);
			}
		} else {
			System.err.println("Couldn't find file:" + helpURL);
		}

		scroll.setViewportView(editorPane);
		return scroll;

	}
 
Example 3
Source File: ManualHandler.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
  if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
    JEditorPane pane = (JEditorPane) e.getSource();
    if (e instanceof HTMLFrameHyperlinkEvent) {
      HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
      HTMLDocument doc = (HTMLDocument) pane.getDocument();
      doc.processHTMLFrameHyperlinkEvent(evt);
    } else {
      try {
        pane.setPage(e.getURL());
      } catch (Throwable t) {
        t.printStackTrace();
      }
    }
  }
}
 
Example 4
Source File: UpdatePanel.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
UpdatePanel(SuppliesTrackerPanel suppliesTrackerPanel)
{
	this.panel = suppliesTrackerPanel;
	setBorder(new EmptyBorder(6, 6, 6, 6));
	setBackground(ColorScheme.DARK_GRAY_COLOR);
	setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
	JEditorPane editorPane = new JEditorPane();
	editorPane.setEditable(false);
	java.net.URL helpURL = UpdatePanel.class.getResource(
		"Info.html");

	if (helpURL != null)
	{
		try
		{
			editorPane.setPage(helpURL);
		}
		catch (IOException e)
		{
			throw new IllegalStateException("File not found");
		}
	}

	JButton close = new JButton("Close info");
	close.addActionListener(e ->
	{
		this.setVisible(false);
		panel.updateOverall();
		panel.getInfo().setVisible(true);
		panel.getLogsContainer().setVisible(true);
	});
	this.add(close);
	this.add(editorPane);

}
 
Example 5
Source File: Main.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public Main() {
  setLayout(new BorderLayout());

  JTabbedPane tabs = new JTabbedPane();
  add("Center", tabs);

  addDemo(tabs, "JButtonBar", "ButtonBarMain");
  addDemo(tabs, "JDirectoryChooser", "ChooseDirectory");
  addDemo(tabs, "JFontChooser", "ChooseFont");
  addDemo(tabs, "JOutlookBar", "OutlookBarMain");
  addDemo(tabs, "JTaskPane", "TaskPaneMain");
  addDemo(tabs, "PropertySheet", "PropertySheetMain");
  addDemo(tabs, "JTipOfTheDay", "TOTDTest");
  
  try {
    JEditorPane pane = new JEditorPane("text/html", "<html>") {
      protected void paintComponent(java.awt.Graphics g) {
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
          RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        super.paintComponent(g);
      }
    };
    pane.setPage(Main.class.getResource("demo.html"));
    pane.setBackground(Color.white);
    pane.setEditable(false);
    pane.setOpaque(true);
    add("South", pane);
  } catch (Exception e) {
  }
}
 
Example 6
Source File: DemoPanel.java    From littleluck with Apache License 2.0 5 votes vote down vote up
private static JComponent createDescriptionArea(URL descriptionURL) {
    JEditorPane descriptionPane = new HTMLPanel();
    descriptionPane.setEditable(false);
    descriptionPane.setMargin(margin);
    descriptionPane.setOpaque(true);
    try {
        descriptionPane.setPage(descriptionURL);
    } catch (IOException e) {
        System.err.println("couldn't load description from URL:" + descriptionURL);
    }
    return descriptionPane;
}
 
Example 7
Source File: DemoPanel.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
private static JComponent createDescriptionArea(URL descriptionURL) {
    JEditorPane descriptionPane = new HTMLPanel();
    descriptionPane.setEditable(false);
    descriptionPane.setMargin(margin);
    descriptionPane.setOpaque(true);
    try {
        descriptionPane.setPage(descriptionURL);
    } catch (IOException e) {
        System.err.println("couldn't load description from URL:" + descriptionURL);
    }
    return descriptionPane;
}
 
Example 8
Source File: CommonHelpDialog.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a help dialog for the given <code>parentFrame</code> by reading
 * from the indicated <code>File</code>.
 */
public CommonHelpDialog(JFrame parentFrame, File helpfile) {
    super(parentFrame);

    setLayout(new BorderLayout());
    JEditorPane helpPane = new JEditorPane();
    helpPane.setEditable(false);

    // Get the help content file if possible
    try {
        helpPane.setPage(helpfile.toURI().toURL());
        setTitle(Messages.getString("CommonHelpDialog.helpFile") + helpfile.getName()); //$NON-NLS-1$
    } catch (Exception exc) {
        helpPane.setText(Messages.getString("CommonHelpDialog.errorReading") //$NON-NLS-1$
                + exc.getMessage());
        setTitle(Messages.getString("CommonHelpDialog.noHelp.title")); //$NON-NLS-1$
        exc.printStackTrace();
    }

    // Close Button
    JButton butClose = new ButtonEsc(new CloseAction(this));

    // Add all to the dialog
    getContentPane().add(new JScrollPane(helpPane), BorderLayout.CENTER);
    getContentPane().add(butClose, BorderLayout.SOUTH);
    
    // Make the window half the screensize and center on screen
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    Dimension windowSize = new Dimension(gd.getDisplayMode().getWidth() / 2,
            gd.getDisplayMode().getHeight() / 2);
    pack();
    setSize(windowSize);
    setLocationRelativeTo(null);
}
 
Example 9
Source File: DefaultHyperlinkHandler.java    From SwingBox with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Loads given page as HyperlinkEvent.
 * 
 * @param pane
 *            the pane
 * @param evt
 *            the event
 */
protected void loadPage(JEditorPane pane, HyperlinkEvent evt)
{
    // if some security, or other interaction is needed, override this
    // method
    try
    {
        pane.setPage(evt.getURL());
    } catch (IOException e)
    {
        System.err.println(e.getLocalizedMessage());
    }
}
 
Example 10
Source File: CompoundDemoFrame.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected JComponent createDescriptionTextPane(final URL url)
{
  final JEditorPane editorPane = new JEditorPane();
  editorPane.setEditable(false);
  editorPane.setPreferredSize(new Dimension(400, 200));
  if (url != null)
  {
    try
    {
      editorPane.setPage(url);
    }
    catch (IOException e)
    {
      logger.error("Failed to load demo description", e);
      editorPane.setText("Unable to load the demo description. Error: " + e
          .getMessage());
    }
  }
  else
  {
    editorPane.setText(
        "Unable to load the demo description. No such resource.");
  }

  return new JScrollPane(editorPane,
      JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
      JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
}
 
Example 11
Source File: SimpleDemoFrame.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected JComponent createDefaultContentPane()
{
  final JPanel content = new JPanel(new BorderLayout());
  content.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

  final InternalDemoHandler demoHandler = getDemoHandler();
  final JEditorPane editorPane = new JEditorPane();
  final URL url = demoHandler.getDemoDescriptionSource();
  editorPane.setEditable(false);
  editorPane.setPreferredSize(new Dimension(400, 200));
  if (url != null)
  {
    try
    {
      editorPane.setPage(url);
    }
    catch (IOException e)
    {
      editorPane.setText("Unable to load the demo description. Error: " + e.getMessage());
    }
  }
  else
  {
    editorPane.setText("Unable to load the demo description. No such resource.");
  }

  final JScrollPane scroll = new JScrollPane(editorPane,
      JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

  final JButton previewButton = new JButton(getPreviewAction());

  final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
  splitPane.setTopComponent(scroll);
  splitPane.setBottomComponent(demoHandler.getPresentationComponent());
  content.add(splitPane, BorderLayout.CENTER);
  content.add(previewButton, BorderLayout.SOUTH);
  return content;
}
 
Example 12
Source File: UpdateProgressBar.java    From stendhal with GNU General Public License v2.0 4 votes vote down vote up
private void initializeComponents() {
	JPanel contentPane = (JPanel) this.getContentPane();

	contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
	contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

	if (fromVersion == null) {
		contentPane.add(new JLabel("Please wait while " + ClientGameConfiguration.get("GAME_NAME") + " is downloaded..."));
	} else {
		contentPane.add(new JLabel("Downloading updates..."));
	}
	contentPane.add(Box.createVerticalStrut(5));

	progressBar = new JProgressBar(0, max);
	progressBar.setStringPainted(false);
	progressBar.setValue(0);
	contentPane.add(progressBar);
	contentPane.add(Box.createVerticalStrut(5));

	if (urlBase != null) {
		// Set up page display.
		browser = new JEditorPane();
		browser.setContentType("text/html");
		browser.setEditable(false);
		Dimension dim = new Dimension(600, 440);
		browser.setPreferredSize(dim);
		browser.addPropertyChangeListener("page", new UpdateProgressBarMetaRefreshSupport());
		browser.addHyperlinkListener(new UpdateProgressBarHyperLinkListener());

		Dimension windowSize = new Dimension(640, 480);
		setPreferredSize(windowSize);
		// TODO: load page async?
		try {
			browser.setPage(urlBase + fromVersion + "/" + toVersion + ".html");
		} catch (IOException e) {
			System.out.println(e);
		}

		// Gige the page scroll bars if it needs them
		final JScrollPane scrollPane = new JScrollPane(browser);
		contentPane.add(scrollPane);
	}
}
 
Example 13
Source File: AboutGrammarVizDialog.java    From grammarviz2_src with GNU General Public License v2.0 4 votes vote down vote up
public AboutGrammarVizDialog(JFrame parentFrame) {

    super(parentFrame, true);
    if (parentFrame != null) {
      Dimension parentSize = parentFrame.getSize();
      Point p = parentFrame.getLocation();
      setLocation(p.x + parentSize.width / 4, p.y + parentSize.height / 4);
    }

    JEditorPane aboutTextPane = new JEditorPane();

    aboutTextPane.setEditable(false);
    java.net.URL helpURL = AboutGrammarVizDialog.class.getResource("/AboutText.html");
    if (helpURL != null) {
      try {
        aboutTextPane.setPage(helpURL);
      }
      catch (IOException e) {
        System.err.println("Attempted to read a bad URL: " + helpURL);
      }
    }
    else {
      System.err.println("Couldn't find file: AboutText.html");
    }

    // Put the editor pane in a scroll pane.
    JScrollPane editorScrollPane = new JScrollPane(aboutTextPane);
    editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    MigLayout mainFrameLayout = new MigLayout("fill", "[grow,center]", "[grow]5[]");

    getContentPane().setLayout(mainFrameLayout);

    getContentPane().add(editorScrollPane, "h 200:300:,w 400:500:,growx,growy,wrap");

    JPanel buttonPane = new JPanel();
    JButton okButton = new JButton(OK_BUTTON_TEXT);

    buttonPane.add(okButton);
    okButton.addActionListener(this);

    getContentPane().add(buttonPane, "wrap");

    pack();
    setVisible(true);

  }