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).

1  
/* Copyright (c) 2004 Joshua Marinacci */
2  
3  
import java.awt.Dimension;
4  
import java.awt.Toolkit;
5  
import java.awt.event.ActionEvent;
6  
import java.awt.event.ActionListener;
7  
import java.io.File;
8  
import java.net.MalformedURLException;
9  
import java.net.URL;
10  
11  
import javax.swing.JButton;
12  
import javax.swing.JDialog;
13  
import javax.swing.JFrame;
14  
import javax.swing.JScrollBar;
15  
import javax.swing.JScrollPane;
16  
17  
import org.xhtmlrenderer.simple.XHTMLPanel;
18  
import org.xhtmlrenderer.util.Uu;
19  
20  
/**
21  
 * Description of the Class
22  
 *
23  
 * @author empty
24  
 */
25  
public class main extends JDialog implements Runnable {
26  
    private static final long serialVersionUID = 1L;
27  
    
28  
    /**
29  
     * Description of the Field
30  
     */
31  
    JScrollPane scroll;
32  
    /**
33  
     * Description of the Field
34  
     */
35  
    JButton close_button;
36  
    /**
37  
     * Description of the Field
38  
     */
39  
    boolean go = false;
40  
41  
    /**
42  
     * Description of the Field
43  
     */
44  
    Thread thread;
45  
46  
    /**
47  
     * Constructor for the AboutBox object
48  
     *
49  
     * @param text PARAM
50  
     * @param url  PARAM
51  
     */
52  
    public main(String text, String url) {
53  
        super();
54  
        Uu.p("starting the about box");
55  
        setTitle(text);
56  
        XHTMLPanel panel = new XHTMLPanel(new DemoUserAgent());
57  
        int w = 400;
58  
        int h = 500;
59  
        panel.setPreferredSize(new Dimension(w, h));
60  
61  
        scroll = new JScrollPane(panel);
62  
        scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
63  
        scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
64  
        scroll.setPreferredSize(new Dimension(w, h));
65  
        //panel.setViewportComponent(scroll);
66  
        //panel.setJScrollPane(scroll);
67  
        getContentPane().add(scroll, "Center");
68  
        close_button = new JButton("Close");
69  
        getContentPane().add(close_button, "South");
70  
        close_button.addActionListener(new ActionListener() {
71  
            public void actionPerformed(ActionEvent evt) {
72  
                setVisible(false);
73  
                go = false;
74  
            }
75  
        });
76  
77  
        try {
78  
            loadPage(url, panel);
79  
        } catch (Exception ex) {
80  
            Uu.p(ex);
81  
        }
82  
        pack();
83  
        setSize(w, h);
84  
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
85  
        setLocation((screen.width - w) / 2, (screen.height - h) / 2);
86  
    }
87  
88  
    /**
89  
     * Description of the Method
90  
     *
91  
     * @param url_text PARAM
92  
     * @param panel    PARAM
93  
     */
94  
    public void loadPage(String url_text, XHTMLPanel panel) throws MalformedURLException {
95  
URL ref = null;
96  
97  
if (url_text.startsWith("demo:")) {
98  
    Uu.p("starts with demo");
99  
    DemoMarker marker = new DemoMarker();
100  
    Uu.p("url text = " + url_text);
101  
    String short_url = url_text.substring(5);
102  
    if (!short_url.startsWith("/")) {
103  
        short_url = "/" + short_url;
104  
    }
105  
    Uu.p("short url = " + short_url);
106  
    ref = marker.getClass().getResource(short_url);
107  
    Uu.p("ref = " + ref);
108  
    panel.setDocument(ref.toExternalForm());
109  
} else if (url_text.startsWith("http")) {
110  
    panel.setDocument(url_text);
111  
} else {
112  
    ref = new File(url_text).toURL();
113  
    panel.setDocument(ref.toExternalForm());
114  
}
115  
Uu.p("ref = " + ref);
116  
Uu.p("url_text = " + url_text);
117  
}
118  
119  
    /**
120  
     * Description of the Method
121  
     */
122  
    public void startScrolling() {
123  
        go = true;
124  
        thread = new Thread(this);
125  
        thread.start();
126  
    }
127  
128  
    /**
129  
     * Main processing method for the AboutBox object
130  
     */
131  
    public void run() {
132  
        while (go) {
133  
            try {
134  
                Thread.sleep(100);
135  
            } catch (Exception ex) {
136  
                Uu.p(ex);
137  
            }
138  
            JScrollBar sb = scroll.getVerticalScrollBar();
139  
            sb.setValue(sb.getValue() + 1);
140  
        }
141  
    }
142  
143  
    /**
144  
     * Sets the visible attribute of the AboutBox object
145  
     *
146  
     * @param vis The new visible value
147  
     */
148  
    public void setVisible(boolean vis) {
149  
        super.setVisible(vis);
150  
        if (vis == true) {
151  
            startScrolling();
152  
        }
153  
    }
154  
155  
    /**
156  
     * The main program for the AboutBox class
157  
     *
158  
     * @param args The command line arguments
159  
     */
160  
    public static void main(String[] args) {
161  
        JFrame frame = new JFrame("About Box Test");
162  
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
163  
        JButton launch = new JButton("Show About Box");
164  
        frame.getContentPane().add(launch);
165  
        frame.pack();
166  
        frame.setVisible(true);
167  
168  
        launch.addActionListener(new ActionListener() {
169  
            public void actionPerformed(ActionEvent evt) {
170  
                main ab = new main("About Flying Saucer", "demo:demos/index.xhtml");
171  
                ab.setVisible(true);
172  
            }
173  
        });
174  
    }
175  
}

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: 561 / 539
Referenced in: [show references]