Search in sources :

Example 1 with ExtendedHTMLEditorKit

use of gmgen.gui.ExtendedHTMLEditorKit in project pcgen by PCGen.

the class NotesView method insertLocalImage.

//Image insertion methods
/**
	 *  Method for inserting an image from a file
	 *
	 *@param  whatImage                 pointer to file
	 *@exception  IOException           if the file can't be read
	 *@exception  BadLocationException  if the file does not exist
	 *@exception  RuntimeException      cause
	 */
private void insertLocalImage(File whatImage) throws IOException, BadLocationException, RuntimeException {
    File image = whatImage;
    if (whatImage == null) {
        File dir = getCurrentDir();
        File newImage = getImageFromChooser(dir.getPath(), extsIMG, "Image File");
        //null possible if user cancelled
        if (newImage != null && newImage.exists()) {
            image = new File(dir.getAbsolutePath() + File.separator + newImage.getName());
            if (!image.exists()) {
                MiscUtilities.copy(newImage, image);
            }
        }
    }
    if (image != null) {
        int caretPos = editor.getCaretPosition();
        ExtendedHTMLEditorKit htmlKit = (ExtendedHTMLEditorKit) editor.getEditorKit();
        ExtendedHTMLDocument htmlDoc = (ExtendedHTMLDocument) editor.getStyledDocument();
        htmlKit.insertHTML(htmlDoc, caretPos, "<IMG SRC=\"" + image + "\">", 0, 0, HTML.Tag.IMG);
        editor.setCaretPosition(caretPos + 1);
    }
}
Also used : ExtendedHTMLDocument(gmgen.gui.ExtendedHTMLDocument) ExtendedHTMLEditorKit(gmgen.gui.ExtendedHTMLEditorKit) File(java.io.File) Point(java.awt.Point)

Example 2 with ExtendedHTMLEditorKit

use of gmgen.gui.ExtendedHTMLEditorKit in project pcgen by PCGen.

the class NotesTreeNode method getTextPane.

/**
	 * Gets a JTextPane that contains the content of the "data.html" in this
	 * directory (or the modified document if it has been modified), or is empty
	 * if that file does not exist. This function caches the JTextPan so that the
	 * speed doesn't suck.
	 *
	 * @return The populated JTextPane
	 */
public JTextPane getTextPane() {
    boolean repopulate = false;
    cacheCounter = 10;
    if (pane == null) {
        pane = new JTextPane();
        repopulate = true;
        ExtendedHTMLEditorKit htmlKit = new ExtendedHTMLEditorKit();
        pane.setEditorKit(htmlKit);
        notesDoc = (ExtendedHTMLDocument) (htmlKit.createDefaultDocument());
        notesDoc.putProperty(DOCROOT, dir.getAbsolutePath() + File.separator + DATA_HTML);
    }
    pane.setDocument(notesDoc);
    if (repopulate) {
        File notes = new File(dir.getAbsolutePath() + File.separator + DATA_HTML);
        if (notes.exists()) {
            try {
                BufferedReader br = new BufferedReader(new FileReader(notes));
                StringBuilder sb = new StringBuilder();
                String newLine;
                do {
                    newLine = br.readLine();
                    if (newLine != null) {
                        sb.append(newLine).append(Constants.LINE_SEPARATOR);
                    }
                } while (newLine != null);
                br.close();
                pane.setText(sb.toString());
            } catch (Exception e) {
                Logging.errorPrint(e.getMessage(), e);
            }
        }
        pane.setCaretPosition(0);
        notesDoc.addDocumentListener(this);
    }
    return pane;
}
Also used : JTextPane(javax.swing.JTextPane) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ExtendedHTMLEditorKit(gmgen.gui.ExtendedHTMLEditorKit) File(java.io.File) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with ExtendedHTMLEditorKit

use of gmgen.gui.ExtendedHTMLEditorKit in project pcgen by PCGen.

the class NotesTreeNode method getTextPane.

/**
	 * Gets a JTextPane that contains the content of the "data.html" in this
	 * directory (or the modified document if it has been modified), or is empty
	 * if that file does not exist. This function takes in an external JTextPan
	 * that it populates in excruciatingly slow speed.
	 *
	 * @param editor
	 *          Editor pane you want to populate
	 * @return The populated Pane
	 */
public JTextPane getTextPane(JTextPane editor) {
    boolean repopulate = false;
    cacheCounter = 10;
    if (notesDoc != null) {
        //setDocument causes an event to fire, which makes the document dirty -
        // these semaphores prevent that
        ignoreUpdateSemaphore = true;
    }
    if (pane == null) {
        pane = editor;
        repopulate = true;
        ExtendedHTMLEditorKit htmlKit = new ExtendedHTMLEditorKit();
        pane.setEditorKit(htmlKit);
        notesDoc = (ExtendedHTMLDocument) (htmlKit.createDefaultDocument());
        notesDoc.putProperty(DOCROOT, dir.getAbsolutePath() + File.separator + DATA_HTML);
    }
    pane.setDocument(notesDoc);
    if (repopulate) {
        File notes = new File(dir.getAbsolutePath() + File.separator + DATA_HTML);
        if (notes.exists()) {
            try {
                BufferedReader br = new BufferedReader(new FileReader(notes));
                StringBuilder sb = new StringBuilder();
                String newLine;
                do {
                    newLine = br.readLine();
                    if (newLine != null) {
                        sb.append(newLine).append(Constants.LINE_SEPARATOR);
                    }
                } while (newLine != null);
                br.close();
                pane.setText(sb.toString());
            } catch (Exception e) {
                Logging.errorPrint(e.getMessage(), e);
            }
        }
        notesDoc.addDocumentListener(this);
    }
    return pane;
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ExtendedHTMLEditorKit(gmgen.gui.ExtendedHTMLEditorKit) File(java.io.File) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

ExtendedHTMLEditorKit (gmgen.gui.ExtendedHTMLEditorKit)3 File (java.io.File)3 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 NoSuchElementException (java.util.NoSuchElementException)2 ExtendedHTMLDocument (gmgen.gui.ExtendedHTMLDocument)1 Point (java.awt.Point)1 JTextPane (javax.swing.JTextPane)1