Example usage for javax.swing JEditorPane addPropertyChangeListener

List of usage examples for javax.swing JEditorPane addPropertyChangeListener

Introduction

In this page you can find the example usage for javax.swing JEditorPane addPropertyChangeListener.

Prototype

public void addPropertyChangeListener(PropertyChangeListener listener) 

Source Link

Document

Adds a PropertyChangeListener to the listener list.

Usage

From source file:ShowHTMLViews.java

public static void main(String[] args) {
    try {//from  w  ww  . j av a 2  s.c  om
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    try {
        JFrame f = new JFrame("HTML Document View Structure");
        final JEditorPane ep = new JEditorPane(args[0]);
        ep.setEditable(false);
        f.getContentPane().add(new JScrollPane(ep));
        f.setSize(400, 300);
        f.setVisible(true);

        ep.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("page")) {
                    System.out.println("Document:\n");
                    HTMLDocDisplay.displayModel(ep, System.out);
                    System.out.println("\n\nViews:\n");
                    HTMLViewDisplayer.displayViews(ep, System.out);
                }
            }
        });
    } catch (Exception e) {
        System.out.println(e);
        System.exit(1);
    }
}

From source file:EditorDropTarget3.java

public EditorDropTarget3(JEditorPane pane) {
    this.pane = pane;

    // Listen for changes in the enabled property
    pane.addPropertyChangeListener(this);

    // Save the JEditorPane's background color
    backgroundColor = pane.getBackground();

    // Create the DropTarget and register
    // it with the JEditorPane.
    dropTarget = new DropTarget(pane, DnDConstants.ACTION_COPY_OR_MOVE, this, pane.isEnabled(), null);
}

From source file:EditorDropTarget4.java

public EditorDropTarget4(JEditorPane pane) {
    this.pane = pane;

    // Listen for changes in the enabled property
    pane.addPropertyChangeListener(this);

    // Save the JEditorPane's background color
    backgroundColor = pane.getBackground();

    // Create the DropTarget and register
    // it with the JEditorPane.
    dropTarget = new DropTarget(pane, DnDConstants.ACTION_COPY_OR_MOVE, this, pane.isEnabled(), null);
}

From source file:net.yacy.cora.util.Html2Image.java

/**
 * render a html page with a JEditorPane, which can do html up to html v 3.2. No CSS supported!
 * @param url//  www  .jav  a  2  s. c o  m
 * @param size
 * @throws IOException 
 */
public static void writeSwingImage(String url, Dimension size, File destination) throws IOException {

    // set up a pane for rendering
    final JEditorPane htmlPane = new JEditorPane();
    htmlPane.setSize(size);
    htmlPane.setEditable(false);
    final HTMLEditorKit kit = new HTMLEditorKit() {

        private static final long serialVersionUID = 1L;

        @Override
        public Document createDefaultDocument() {
            HTMLDocument doc = (HTMLDocument) super.createDefaultDocument();
            doc.setAsynchronousLoadPriority(-1);
            return doc;
        }

        @Override
        public ViewFactory getViewFactory() {
            return new HTMLFactory() {
                @Override
                public View create(Element elem) {
                    View view = super.create(elem);
                    if (view instanceof ImageView) {
                        ((ImageView) view).setLoadsSynchronously(true);
                    }
                    return view;
                }
            };
        }
    };
    htmlPane.setEditorKitForContentType("text/html", kit);
    htmlPane.setContentType("text/html");
    htmlPane.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
        }
    });

    // load the page
    try {
        htmlPane.setPage(url);
    } catch (IOException e) {
        e.printStackTrace();
    }

    // render the page
    Dimension prefSize = htmlPane.getPreferredSize();
    BufferedImage img = new BufferedImage(prefSize.width, htmlPane.getPreferredSize().height,
            BufferedImage.TYPE_INT_ARGB);
    Graphics graphics = img.getGraphics();
    htmlPane.setSize(prefSize);
    htmlPane.paint(graphics);
    ImageIO.write(img, destination.getName().endsWith("jpg") ? "jpg" : "png", destination);
}

From source file:org.docx4all.swing.text.WordMLEditorKit.java

/**
 * Called when the kit is being installed into the a JEditorPane.
 * //from w ww .  ja  va 2  s.  c  om
 * @param c
 *            the JEditorPane
 */
@Override
public void install(JEditorPane c) {
    super.install(c);

    c.addCaretListener(caretListener);
    c.addCaretListener(contentControlTracker);
    c.addMouseListener(mouseListener);
    c.addMouseMotionListener(mouseListener);
    c.addPropertyChangeListener(caretListener);
    caretListener.updateCaretElement(0, 0, c);

    initKeyBindings(c);
}