Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

175
LINES

< > BotCompany Repo | #1000873 // FlyingSaucer HTML renderer test (AboutBox), developing

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Compilation Failed (176L/2K).

/* Copyright (c) 2004 Joshua Marinacci */

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;

import org.xhtmlrenderer.simple.XHTMLPanel;
import org.xhtmlrenderer.util.Uu;

/**
 * Description of the Class
 *
 * @author empty
 */
public class main extends JDialog implements Runnable {
    private static final long serialVersionUID = 1L;
    
    /**
     * Description of the Field
     */
    JScrollPane scroll;
    /**
     * Description of the Field
     */
    JButton close_button;
    /**
     * Description of the Field
     */
    boolean go = false;

    /**
     * Description of the Field
     */
    Thread thread;

    /**
     * Constructor for the AboutBox object
     *
     * @param text PARAM
     * @param url  PARAM
     */
    public main(String text, String url) {
        super();
        Uu.p("starting the about box");
        setTitle(text);
        XHTMLPanel panel = new XHTMLPanel(new DemoUserAgent());
        int w = 400;
        int h = 500;
        panel.setPreferredSize(new Dimension(w, h));

        scroll = new JScrollPane(panel);
        scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        scroll.setPreferredSize(new Dimension(w, h));
        //panel.setViewportComponent(scroll);
        //panel.setJScrollPane(scroll);
        getContentPane().add(scroll, "Center");
        close_button = new JButton("Close");
        getContentPane().add(close_button, "South");
        close_button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                setVisible(false);
                go = false;
            }
        });

        try {
            loadPage(url, panel);
        } catch (Exception ex) {
            Uu.p(ex);
        }
        pack();
        setSize(w, h);
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation((screen.width - w) / 2, (screen.height - h) / 2);
    }

    /**
     * Description of the Method
     *
     * @param url_text PARAM
     * @param panel    PARAM
     */
    public void loadPage(String url_text, XHTMLPanel panel) throws MalformedURLException {
URL ref = null;

if (url_text.startsWith("demo:")) {
    Uu.p("starts with demo");
    DemoMarker marker = new DemoMarker();
    Uu.p("url text = " + url_text);
    String short_url = url_text.substring(5);
    if (!short_url.startsWith("/")) {
        short_url = "/" + short_url;
    }
    Uu.p("short url = " + short_url);
    ref = marker.getClass().getResource(short_url);
    Uu.p("ref = " + ref);
    panel.setDocument(ref.toExternalForm());
} else if (url_text.startsWith("http")) {
    panel.setDocument(url_text);
} else {
    ref = new File(url_text).toURL();
    panel.setDocument(ref.toExternalForm());
}
Uu.p("ref = " + ref);
Uu.p("url_text = " + url_text);
}

    /**
     * Description of the Method
     */
    public void startScrolling() {
        go = true;
        thread = new Thread(this);
        thread.start();
    }

    /**
     * Main processing method for the AboutBox object
     */
    public void run() {
        while (go) {
            try {
                Thread.sleep(100);
            } catch (Exception ex) {
                Uu.p(ex);
            }
            JScrollBar sb = scroll.getVerticalScrollBar();
            sb.setValue(sb.getValue() + 1);
        }
    }

    /**
     * Sets the visible attribute of the AboutBox object
     *
     * @param vis The new visible value
     */
    public void setVisible(boolean vis) {
        super.setVisible(vis);
        if (vis == true) {
            startScrolling();
        }
    }

    /**
     * The main program for the AboutBox class
     *
     * @param args The command line arguments
     */
    public static void main(String[] args) {
        JFrame frame = new JFrame("About Box Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JButton launch = new JButton("Show About Box");
        frame.getContentPane().add(launch);
        frame.pack();
        frame.setVisible(true);

        launch.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                main ab = new main("About Flying Saucer", "demo:demos/index.xhtml");
                ab.setVisible(true);
            }
        });
    }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1000873
Snippet name: FlyingSaucer HTML renderer test (AboutBox), developing
Eternal ID of this version: #1000873/1
Text MD5: 96ba795222ccecee05491a9ca286f1c1
Transpilation MD5: 96ba795222ccecee05491a9ca286f1c1
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-05-15 13:45:57
Source code size: 4897 bytes / 175 lines
Pitched / IR pitched: No / No
Views / Downloads: 621 / 616
Referenced in: #3000190 - Answer for stefanreich(>> t 20 questions)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)