krysalis-jplugin/src/java/org/krysalis/jplugin/components/sheets/html HtmlEditorSheet.java,NONE,1.1 HtmlSheet.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/krysalis-jplugin/src/java/org/krysalis/jplugin/components/sheets/html
In directory sc8-pr-cvs1:/tmp/cvs-serv15221/java/org/krysalis/jplugin/components/sheets/html

Added Files:
	HtmlEditorSheet.java HtmlSheet.java 
Log Message:
Move swallowtail.* packages under jplugin.components thus elominating the 
package with a confusing name,

--- NEW FILE: HtmlEditorSheet.java ---
/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Software       *
 * License version 1.1_01, a copy of which has been included  with this      *
 * distribution in the LICENSE file.                                         *
 *****************************************************************************/
package  org.krysalis.jplugin.components.sheets.html;

import java.awt.Component;

import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.text.html.HTMLEditorKit;

import org.krysalis.jplugin.components.sheets.AbstractSaveableComponentSheet;



/**
 *@author     <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
 *@created    June 20, 2001
 *@version    1.0
 */
public class HtmlEditorSheet extends AbstractSaveableComponentSheet {

    private JEditorPane jEditorPane;
    private JComponent jComponent;


    /**
     *  Constructor for the HtmlEditorSheet object
     */
    public HtmlEditorSheet() {
        jEditorPane = new JEditorPane();
        jComponent = new JScrollPane(jEditorPane);
    }


    /**
     *  Sets the content attribute of the HtmlEditorSheet object
     *
     *@param  content   The new content value
     *@param  mimeType  The new content value
     */
    public void setContent(String content, String mimeType) {
        try {
            java.io.StringReader reader = new java.io.StringReader(content);
            HTMLEditorKit hek = new HTMLEditorKit();
            jEditorPane.setEditorKit(hek);
            hek.read(reader, jEditorPane.getDocument(), 0);
            jEditorPane.getCaret().setDot(0);

        } catch (Exception ioe) {
            System.out.println(ioe);
        }
    }


    /**
     *  Gets the name attribute of the HtmlEditorSheet object
     *
     *@return    The name value
     */
    public String getName() {
        return "JEditorPane";
    }


    /**
     *  Gets the component attribute of the HtmlEditorSheet object
     *
     *@return    The component value
     */
    public Component getComponent() {
        return jComponent;
    }


    /**
     *  Gets the content attribute of the HtmlEditorSheet object
     *
     *@return    The content value
     */
    public String getContent() {
        return jEditorPane.getText();
    }
}

--- NEW FILE: HtmlSheet.java ---
/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Software       *
 * License version 1.1_01, a copy of which has been included  with this      *
 * distribution in the LICENSE file.                                         *
 *****************************************************************************/
package  org.krysalis.jplugin.components.sheets.html;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Panel;
import java.io.IOException;
import java.net.URL;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import org.krysalis.jplugin.framework.sheets.Sheet;
import org.krysalis.jplugin.framework.storage.StoreEntity;
import org.krysalis.swingx.LinkEnabledJEditorPane;

/**
 *@author     <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
 *@created    June 20, 2001
 *@version    1.0
 */
public class HtmlSheet extends Panel
         implements Sheet {

    private DataHandler dh;
    private String contentType = "text/html";
    private LinkEnabledJEditorPane jEditorPane;
    private JComponent jComponent;


    /**
     *  Constructor for the HtmlSheet object
     */
    public HtmlSheet() {
        super();
        jComponent = new JPanel();
        jComponent.setLayout(new BorderLayout());
    }


    /**
     *  Sets the commandContext attribute of the HtmlSheet object
     *
     *@param  s                The new commandContext value
     *@param  dh               The new commandContext value
     *@exception  IOException  Description of Exception
     */
    public void setCommandContext(String s, DataHandler dh) throws IOException {
        this.removeAll();
        this.setLayout(new BorderLayout());
        Component component = getComponent();
        this.add(component, BorderLayout.CENTER);
        this.dh = dh;
        DataSource ds = dh.getDataSource();

        this.contentType = ds.getContentType();
        this.setVisible(false);

        //FIXME?
        URL dataUrl = ((StoreEntity) ds).getURL();

        try {

            jEditorPane = new LinkEnabledJEditorPane(dataUrl);

            jComponent.removeAll();
            jComponent.add(new JScrollPane(jEditorPane));

        } catch (Exception e) {
            throw new IOException(e.toString());
        }
        this.setVisible(true);
    }


    /**
     *  Gets the contentType attribute of the HtmlSheet object
     *
     *@return    The contentType value
     */
    public String getContentType() {
        return contentType;
    }


    /**
     *  Gets the component attribute of the HtmlSheet object
     *
     *@return    The component value
     */
    protected Component getComponent() {
        return jComponent;
    }

}




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.