JWebBrower

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Toolkit;

import javax.swing.SwingUtilities;
import javax.swing.JFrame;

import chrriis.dj.nativeswing.ui.JWebBrowser;
import chrriis.dj.nativeswing.NativeInterfaceHandler;
import chrriis.dj.nativeswing.ui.event.WebBrowserAdapter;
import chrriis.dj.nativeswing.ui.event.WebBrowserEvent;
import chrriis.dj.nativeswing.ui.event.WebBrowserNavigationEvent;
import com.instacoll.livedocuments.oo.configuration.InstaConfig;
import com.instacoll.livedocuments.oo.exception.StringUtils;
import com.instacoll.livedocuments.oo.instasecuremanager.InstaSecureManager;
import com.instacoll.livedocuments.oo.miscellaneous.UserStateManager;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.logging.Level;
import javax.swing.ImageIcon;

public class AddDocumentProperties extends JFrame {

    private static Runnable xxx;
    final JFrame con = this;
    public static AddDocumentProperties AddDocProp = null;
    private static boolean bThreadStatus = false;
    private static String documentId;
        private String currenturl = "";
    private String prevurl = "";
    JWebBrowser webBrowser;

    public static AddDocumentProperties getInstance() {
        if (AddDocProp == null) {
            AddDocProp = new AddDocumentProperties(documentId);
        }
        return AddDocProp;
    }

    public AddDocumentProperties(String documentID) {
        super("Add Document Properties");
        Class<AddDocumentProperties> clazz = AddDocumentProperties.class;

        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setLocationByPlatform(true);
        String img = InstaConfig.TRAY_ICON_IMAGE;
        img = img.substring(0, img.lastIndexOf("/"));
        setIconImage(new ImageIcon(img + "liveimg.JPG").getImage());

        Container contentPaneF = getContentPane();
        this.setSize(900, 500);

        int x = (Toolkit.getDefaultToolkit().getScreenSize().width - this.getSize().width) / 2;
        int y = (Toolkit.getDefaultToolkit().getScreenSize().height - this.getSize().height) / 2;
        this.setBounds(x, y, this.getSize().width, this.getSize().height);

        webBrowser = new JWebBrowser() {        };
        webBrowser.setMenuBarVisible(false);
        webBrowser.setButtonBarVisible(false);
        webBrowser.setAddressBarVisible(false);
        webBrowser.setStatusBarVisible(false);
//      /instasecure/displayDocumentDetailsPage.do?docId=1230941
//    webBrowser.setURL("http://www.yahoo.com");
//        /instasecure/taskAssignPage.do?docId=1233332
//        GET /instasecure/signAssignPage.do?docId=1233342
        showPage(InstaConfig.APPLICATIONURL + "displayDocumentDetailsPage.do?docId=" + documentID);
//        webBrowser.setURL(InstaConfig.APPLICATIONURL + "displayDocumentDetailsPage.do?docId=" + documentID);
        contentPaneF.add(webBrowser, BorderLayout.CENTER);
        webBrowser.addWebBrowserListener(new WebBrowserAdapter() {

            @Override
            public void commandReceived(WebBrowserEvent e, String command) {
                JWebBrowser web = (JWebBrowser) e.getSource();
                web.getURL();
            }

            @Override
            public void urlChanged(WebBrowserNavigationEvent arg0) {
                String url = arg0.getNewURL();
                if (url.equalsIgnoreCase("about:blank")) {
                } else if (url.contains("http")) {
                    showPage(url);
                } else {
                    if (url.contains("about:blank")) {
                        url = url.substring(11);
                    } else if (url.contains("blank")) {
                        url = url.substring(5);
                    }


                    if (!url.equals("")) {
                        //url = InstaConfig.APPLICATIONURL + url;    
                        url = "http://live.instacoll.com/instasecure/" + url;
                        showPage(url);
                    }

                }
            }
        });
    }

    public AddDocumentProperties() {

    }

    private void showPage(String pageUrl) {

        String inputLine;
        try {
            String cookie = UserStateManager.getInstance().getAuthKey().trim();
            System.out.println(pageUrl);
            prevurl = currenturl;
            currenturl = pageUrl;
            URL url = new URL(pageUrl);
            URLConnection conn = url.openConnection();
            conn = url.openConnection();
            conn.setRequestProperty("Cookie", cookie);
            conn.setRequestProperty("Content-type", "text/html");

            StringBuffer answer1 = new StringBuffer();
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                answer1.append(line);
            }
            reader.close();

//             System.out.print(answer1.toString());
            webBrowser.setText(answer1.toString());
            webBrowser.setVisible(true);

        } catch (Exception ex) {
            InstaSecureManager.logger.log(Level.SEVERE, StringUtils.getStackTrace(ex));
        }
    }
    public void showAddDocProperties(final String docID) {
        documentId = docID;

        if (AddDocProp == null) {
            if (bThreadStatus == false) {
                bThreadStatus = true;
                AddDocProp = new AddDocumentProperties(documentId);
            }
//login.setVisible(true);
            initialise(true);
        } else {
            reinit();
        }
    }

    private static void initialise(boolean bVisible) {
        final boolean bShow = bVisible;
        NativeInterfaceHandler.init();
        Toolkit.getDefaultToolkit().setDynamicLayout(true);
        xxx = new Runnable() {

            public void run() {
                try {
                    javax.swing.UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
                    com.birosoft.liquid.LiquidLookAndFeel.setLiquidDecorations(true);
                } catch (Exception e) {

                }
                AddDocProp.setVisible(bShow);
            //login.setAlwaysOnTop(true);
            }
        };

        SwingUtilities.invokeLater(xxx);
            NativeInterfaceHandler.runEventPump();

    }

    private static void reinit() {
        NativeInterfaceHandler.init();
        Toolkit.getDefaultToolkit().setDynamicLayout(true);

        xxx = new Runnable() {

            public void run() {
                try {
                    javax.swing.UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
                    com.birosoft.liquid.LiquidLookAndFeel.setLiquidDecorations(true);
                } catch (Exception e) {

                }

                if (bThreadStatus == false) {
                    bThreadStatus = true;
                    AddDocProp = new AddDocumentProperties(documentId);
                }

                AddDocProp.setVisible(true);


            }
        };
        SwingUtilities.invokeLater(xxx);

    }

    public static void main(String[] args) {
        AddDocumentProperties docProp = new AddDocumentProperties();
        docProp.showAddDocProperties("11221");
    }
}

你可能感兴趣的:(java,UI,Web,swing,OO)