下面列出了javax.swing.JEditorPane#addPropertyChangeListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void install(JEditorPane c) {
super.install(c);
delegateListeners = c.getHyperlinkListeners();
for (HyperlinkListener listener : delegateListeners) {
c.removeHyperlinkListener(listener);
}
resolverHyperlinkListener = new ResolverHyperlinkListener();
c.addHyperlinkListener(resolverHyperlinkListener);
// add a listener to report trace information
c.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
if ("page".equals(propertyName)) {
Msg.trace(this, "Page loaded: " + evt.getNewValue());
}
}
});
}
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);
}
/**
* Constructs a new <code>LineNumberBorder</code>.
*
* @param scrollPane The scroll pane using this border as the viewport
* border.
* @param editorPane The text component for which line numbers will be
* displayed.
* @param numberColor The color to use for the line numbers. If
* <code>null</code>, a default is used.
*/
public LineNumberBorder(JScrollPane scrollPane, JEditorPane editorPane,
Color numberColor) {
this.editorPane = editorPane;
this.scrollPane = scrollPane;
setForeground(numberColor != null ? numberColor : DEFAULT_FOREGROUND);
Color bg = editorPane.getBackground();
setBackground(bg == null ? Color.WHITE : bg);
editorPane.addCaretListener(this);
editorPane.addPropertyChangeListener(this);
scrollPane.getViewport().addChangeListener(this);
editorPane.getDocument().addDocumentListener(this);
currentLine = 1;
setFont(null); // default font.
insets = new Insets(0, 0, 0, 0);
updateCellHeights();
updateCellWidths();
}
/**
* Called when the kit is being installed into
* a JEditorPane.
*
* @param c the JEditorPane
*/
public void install(JEditorPane c) {
c.addCaretListener(inputAttributeUpdater);
c.addPropertyChangeListener(inputAttributeUpdater);
Caret caret = c.getCaret();
if (caret != null) {
inputAttributeUpdater.updateInputAttributes
(caret.getDot(), caret.getMark(), c);
}
}
/**
* Called when the kit is being installed into
* a JEditorPane.
*
* @param c the JEditorPane
*/
public void install(JEditorPane c) {
c.addCaretListener(inputAttributeUpdater);
c.addPropertyChangeListener(inputAttributeUpdater);
Caret caret = c.getCaret();
if (caret != null) {
inputAttributeUpdater.updateInputAttributes
(caret.getDot(), caret.getMark(), c);
}
}
/**
* Called when the kit is being installed into
* a JEditorPane.
*
* @param c the JEditorPane
*/
public void install(JEditorPane c) {
c.addCaretListener(inputAttributeUpdater);
c.addPropertyChangeListener(inputAttributeUpdater);
Caret caret = c.getCaret();
if (caret != null) {
inputAttributeUpdater.updateInputAttributes
(caret.getDot(), caret.getMark(), c);
}
}
/**
* Called when the kit is being installed into
* a JEditorPane.
*
* @param c the JEditorPane
*/
public void install(JEditorPane c) {
c.addCaretListener(inputAttributeUpdater);
c.addPropertyChangeListener(inputAttributeUpdater);
Caret caret = c.getCaret();
if (caret != null) {
inputAttributeUpdater.updateInputAttributes
(caret.getDot(), caret.getMark(), c);
}
}
/**
* Called when the kit is being installed into
* a JEditorPane.
*
* @param c the JEditorPane
*/
public void install(JEditorPane c) {
c.addCaretListener(inputAttributeUpdater);
c.addPropertyChangeListener(inputAttributeUpdater);
Caret caret = c.getCaret();
if (caret != null) {
inputAttributeUpdater.updateInputAttributes
(caret.getDot(), caret.getMark(), c);
}
}
/**
* Called when the kit is being installed into
* a JEditorPane.
*
* @param c the JEditorPane
*/
public void install(JEditorPane c) {
c.addCaretListener(inputAttributeUpdater);
c.addPropertyChangeListener(inputAttributeUpdater);
Caret caret = c.getCaret();
if (caret != null) {
inputAttributeUpdater.updateInputAttributes
(caret.getDot(), caret.getMark(), c);
}
}
public FoldingSideBar(JEditorPane textView, AbstractOutputPane outputPane) {
this.textView = textView;
this.lines = getLines();
textView.addPropertyChangeListener("document", //NOI18N
new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
FoldingSideBar.this.lines = getLines();
}
});
textView.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
setPreferredSize(new Dimension(BAR_WIDTH,
FoldingSideBar.this.textView.getHeight()));
repaint();
}
});
setMinimumSize(new Dimension(BAR_WIDTH, 0));
setPreferredSize(new Dimension(BAR_WIDTH, textView.getHeight()));
setMaximumSize(new Dimension(BAR_WIDTH, Integer.MAX_VALUE));
wrapped = outputPane.isWrapped();
addMouseListener(new FoldingMouseListener());
addMouseMotionListener(new FoldingMouseListener()); //TODO one is enough
}
void setPane(JEditorPane pane) {
JEditorPane origPane = getPane();
if (origPane != null) {
origPane.removePropertyChangeListener(this);
origPane.getDocument().removeDocumentListener(this);
}
assert (pane != null);
this.paneRef = new WeakReference<>(pane);
pane.addPropertyChangeListener(this);
pane.getDocument().addDocumentListener(this);
updateState();
}
/**
* Called when the kit is being installed into
* a JEditorPane.
*
* @param c the JEditorPane
*/
public void install(JEditorPane c) {
c.addCaretListener(inputAttributeUpdater);
c.addPropertyChangeListener(inputAttributeUpdater);
Caret caret = c.getCaret();
if (caret != null) {
inputAttributeUpdater.updateInputAttributes
(caret.getDot(), caret.getMark(), c);
}
}
/**
* Called when the kit is being installed into
* a JEditorPane.
*
* @param c the JEditorPane
*/
public void install(JEditorPane c) {
c.addCaretListener(inputAttributeUpdater);
c.addPropertyChangeListener(inputAttributeUpdater);
Caret caret = c.getCaret();
if (caret != null) {
inputAttributeUpdater.updateInputAttributes
(caret.getDot(), caret.getMark(), c);
}
}
/**
* Called when the kit is being installed into
* a JEditorPane.
*
* @param c the JEditorPane
*/
public void install(JEditorPane c) {
c.addCaretListener(inputAttributeUpdater);
c.addPropertyChangeListener(inputAttributeUpdater);
Caret caret = c.getCaret();
if (caret != null) {
inputAttributeUpdater.updateInputAttributes
(caret.getDot(), caret.getMark(), c);
}
}
/**
* Called when the kit is being installed into
* a JEditorPane.
*
* @param c the JEditorPane
*/
public void install(JEditorPane c) {
c.addCaretListener(inputAttributeUpdater);
c.addPropertyChangeListener(inputAttributeUpdater);
Caret caret = c.getCaret();
if (caret != null) {
inputAttributeUpdater.updateInputAttributes
(caret.getDot(), caret.getMark(), c);
}
}
/**
* Called when the kit is being installed into
* a JEditorPane.
*
* @param c the JEditorPane
*/
public void install(JEditorPane c) {
c.addCaretListener(inputAttributeUpdater);
c.addPropertyChangeListener(inputAttributeUpdater);
Caret caret = c.getCaret();
if (caret != null) {
inputAttributeUpdater.updateInputAttributes
(caret.getDot(), caret.getMark(), c);
}
}
/**
* Called when the kit is being installed into
* a JEditorPane.
*
* @param c the JEditorPane
*/
public void install(JEditorPane c) {
c.addCaretListener(inputAttributeUpdater);
c.addPropertyChangeListener(inputAttributeUpdater);
Caret caret = c.getCaret();
if (caret != null) {
inputAttributeUpdater.updateInputAttributes
(caret.getDot(), caret.getMark(), c);
}
}
/**
* Called when the kit is being installed into
* a JEditorPane.
*
* @param c the JEditorPane
*/
public void install(JEditorPane c) {
c.addCaretListener(inputAttributeUpdater);
c.addPropertyChangeListener(inputAttributeUpdater);
Caret caret = c.getCaret();
if (caret != null) {
inputAttributeUpdater.updateInputAttributes
(caret.getDot(), caret.getMark(), c);
}
}
/**
* Called when the kit is being installed into
* a JEditorPane.
*
* @param c the JEditorPane
*/
public void install(JEditorPane c) {
c.addCaretListener(inputAttributeUpdater);
c.addPropertyChangeListener(inputAttributeUpdater);
Caret caret = c.getCaret();
if (caret != null) {
inputAttributeUpdater.updateInputAttributes
(caret.getDot(), caret.getMark(), c);
}
}
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);
}
}