<��������(2006ǯ06��25��) ��������(2006ǯ07��02��)> �ǿ� �Խ�

���ڹ��������������

�ܼ� �Ϥ���� Ϣ����:[email protected]
ˬ��Կ� ����: 1528   ����: 1942

2006ǯ07��01��

�� �ʰ�Web�֥饦���� winnytp:// �ץ��ȥ���ϥ�ɥ���Ȥ߹���Ǥߤ�

javax.swing.JEditorPane��Ȥäƴʰץ֥饦�����ä������ܥ���ȥ�����ɥܥ�����դ��������ޤ��ե�����ν����� text/html �ʳ���Content-Type�ν������ʤ���

����ˡ��轵��������Java�ѡ�winnytp://�ץץ��ȥ���ϥ�ɥ���äƤߤ����ñ�ˤǤ����פǺ�ä��ϥ�ɥ�ե����ȥ�򥻥åȤ��Ƥߤ��Ȥ��������Τޤ�ư������

��1: ���ޥ��4�ȥ��ޥ��13�μ�������¾�Υ����ȤؤΥ�󥯽���ɽ�������ͻ�

��2: ���ޥ��13�μ������餳�Υ����Ȥ�����֤��Υե������������ǽ�Ǥ��פȼ�ĥ���Ƥ����Τ�ɽ�������ͻ�

�ե�����Υ�󥯤򥯥�å�����Ȥ��Υ����Ȥ��餽������������ɤ���ųݤ��ˤʤäƤ��롣���������ץ��ȥ���ϥ�ɥ餬����������ɵ�ǽ���б����Ƥ��ʤ���

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.net.*;
public class Nyzilla extends TinyWebBrowser {
    public static void main(String[] args) {
        URL.setURLStreamHandlerFactory(new WinnytpURLStreamHandlerFactory());
        new Nyzilla();
    }
    protected String getDefaultPage() {
        return "winnytp://";
    }
    protected String getWindowTitle() {
        return "Nyzilla 0.2";
    }
}
class TinyWebBrowser {
    public static void main(String[] args) {
        new TinyWebBrowser();
    }
    TinyWebBrowser() {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
    protected String getDefaultPage() {
        return "http://www.yahoo.co.jp/";
    }
    protected String getWindowTitle() {
        return "TinyWebBrowser 0.2";
    }
    protected Dimension getDefaultWindowSize() {
        return new Dimension(750, 800);
    }
    JPanel browserPanel;
    JTextField addressField = new JTextField();
    JButton backButton = new JButton("Back");
    JButton reloadButton = new JButton("Reload");
    JLabel statusArea = new JLabel(" ");
    Cursor waitCursor = new Cursor(Cursor.WAIT_CURSOR);
    Page currentPage = null;
    java.util.Stack pageStack = new java.util.Stack();
    static final Font font = new Font("SansSerif", Font.PLAIN, 14);
    private void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
        }
        JFrame f = new JFrame(getWindowTitle());
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        browserPanel = new JPanel();
        browserPanel.setOpaque(true);
        browserPanel.setLayout(new BorderLayout());
        JPanel addressBar = new JPanel(new BorderLayout());
        JLabel l = new JLabel("Address (URL): ");
        l.setFont(font);
        addressBar.add(l, BorderLayout.LINE_START);
        addressField.setFont(font);
        setAddress(getDefaultPage());
        addressField.addActionListener(new AddressEnterAction());
        addressBar.add(addressField, BorderLayout.CENTER);
        JPanel buttonPanel = new JPanel(new FlowLayout());
        backButton.addActionListener(new BackButtonAction());
        backButton.setEnabled(false);
        buttonPanel.add(backButton);
        reloadButton.addActionListener(new ReloadButtonAction());
        buttonPanel.add(reloadButton);
        addressBar.add(buttonPanel, BorderLayout.LINE_END);
        browserPanel.add(addressBar, BorderLayout.PAGE_START);
        statusArea.setFont(font);
        browserPanel.add(statusArea, BorderLayout.PAGE_END);
        f.setContentPane(browserPanel);
        f.setSize(getDefaultWindowSize());
        f.setVisible(true);
    }
    class Page {
        JScrollPane pane;
        JEditorPane editor;
        Page() {
            editor = new JEditorPane();
            editor.setEditable(false);
            editor.setContentType("text/html");
            pane = new JScrollPane(editor);
            pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
            editor.addHyperlinkListener(new HyperlinkAction());
        }
        void setPage(String url) throws IOException {
            if (url == null || url.length() == 0) return;
            try {
                browserPanel.setCursor(waitCursor);
                editor.setPage(url);
                setAddress(editor.getPage().toString());
            } catch (IOException e) {
                showAccessError(e);
                throw e;
            } finally {
                browserPanel.setCursor(Cursor.getDefaultCursor());
            }
        }
    }
    class HyperlinkAction implements HyperlinkListener {
        public void hyperlinkUpdate(HyperlinkEvent v) {
            HyperlinkEvent.EventType t = v.getEventType();
            if (t == HyperlinkEvent.EventType.ACTIVATED) {
                String url = v.getURL().toString();
                statusArea.setText(" ");
                replaceLocation(url);
            } else if (t == HyperlinkEvent.EventType.ENTERED) {
                String url = v.getURL().toString();
                statusArea.setText(url);
            } else if (t == HyperlinkEvent.EventType.EXITED) {
                statusArea.setText(" ");
            }
        }
    }
    class AddressEnterAction implements ActionListener {
        public void actionPerformed(ActionEvent v) {
            String url = addressField.getText();
            replaceLocation(url);
        }
    }
    private void replaceLocation(String url) {
        try {
            Page newPage = new Page();
            newPage.setPage(url);
            if (currentPage != null) {
                pageStack.push(currentPage);
                backButton.setEnabled(true);
                browserPanel.remove(currentPage.pane);
            }
            currentPage = newPage;
            browserPanel.add(newPage.pane, BorderLayout.CENTER);
            refresh();
            setAddress(newPage.editor.getPage().toString());
        } catch (IOException e) {
        }
    }
    class BackButtonAction implements ActionListener {
        public void actionPerformed(ActionEvent v) {
            if (pageStack.isEmpty()) return;
            backButton.setEnabled(false);
            Page prevPage = (Page)pageStack.pop(); 
            browserPanel.remove(currentPage.pane);
            currentPage = prevPage;
            browserPanel.add(currentPage.pane, BorderLayout.CENTER);
            refresh();
            if (!pageStack.isEmpty()) {
                backButton.setEnabled(true);
            }
        }
    }
    class ReloadButtonAction implements ActionListener {
        public void actionPerformed(ActionEvent v) {
            String url = currentPage.editor.getPage().toString();
            try {
                reloadButton.setEnabled(false);
                Page newPage = new Page();
                newPage.setPage(url);
                browserPanel.remove(currentPage.pane);
                currentPage = newPage;
                browserPanel.add(newPage.pane, BorderLayout.CENTER);
                refresh();
                setAddress(newPage.editor.getPage().toString());
            } catch (IOException e) {
            } finally {
                reloadButton.setEnabled(true);
            }
        }
    }
    private void refresh() {
        browserPanel.validate();
        browserPanel.repaint();
    }
    private void setAddress(String url) {
        addressField.setText(url);
        addressField.setCaretPosition(0);
    }
    private void showAccessError(Exception e) {
        JOptionPane.showMessageDialog(
            browserPanel, 
            e.toString(), 
            "Access Error", 
            JOptionPane.ERROR_MESSAGE
        );
    }
}

javax.swing.JEditorPane���Ѥ����ʰ�Web�֥饦������

������TrackBacks(��2��) [TrackBack URL: http://takagi-hiromitsu.jp/diary/tb.rb/20060701]

http://takagi-hiromitsu.jp/diary/20060701.html#p01 ���Υġ����Ȥ��м�ʬ�����󥿥ޥ����륹�˴������뤳�Ȥʤ�¾�ͤ�ή�о���������õ�����Ȥ��Ǥ��뤾��

�ݥ��ƥ��֥��󥭥󥰤Ф���Ǥϡ�����Ȥ���̵�������ۤ��ä��֤��Ƹ��줬��뵤��

����

<��������(2006ǯ06��25��) ��������(2006ǯ07��02��)> �ǿ� �Խ�

�Ƕ�Υ����ȥ�

2024ǯ12��22��

2024ǯ12��07��

2024ǯ12��02��

2024ǯ11��24��

2024ǯ11��11��

2024ǯ07��28��

2024ǯ07��27��

2024ǯ07��07��

2024ǯ04��07��

2024ǯ04��01��

2024ǯ03��23��

2024ǯ03��19��

2024ǯ03��16��

2024ǯ03��13��

2024ǯ03��11��

2023ǯ03��27��

2022ǯ12��30��

2022ǯ12��25��

2022ǯ06��09��

2022ǯ04��01��

2022ǯ01��19��

2021ǯ12��26��

2021ǯ10��06��

2021ǯ08��23��

2021ǯ07��12��

2020ǯ09��14��

2020ǯ08��01��

2019ǯ10��05��

2019ǯ08��03��

2019ǯ07��08��

2019ǯ06��25��

2019ǯ06��09��

2019ǯ05��19��

2019ǯ05��12��

2019ǯ03��19��

2019ǯ03��16��

2019ǯ03��09��

2019ǯ03��07��

2019ǯ02��19��

2019ǯ02��11��

2018ǯ12��26��

2018ǯ10��31��

2018ǯ06��17��

2018ǯ06��10��

2018ǯ05��19��

2018ǯ05��04��

2018ǯ03��07��

2017ǯ12��29��

2017ǯ10��29��

2017ǯ10��22��

2017ǯ07��22��

2017ǯ06��04��

2017ǯ05��13��

2017ǯ05��05��

2017ǯ04��08��

2017ǯ03��10��

2017ǯ03��05��

2017ǯ02��18��

2017ǯ01��08��

2017ǯ01��04��

2016ǯ12��30��

2016ǯ12��04��

2016ǯ11��29��

2016ǯ11��23��

2016ǯ11��05��

2016ǯ10��25��

2016ǯ10��10��

2016ǯ08��23��

2016ǯ07��23��

2016ǯ07��16��

2016ǯ07��02��

2016ǯ06��12��

2016ǯ06��03��

2016ǯ04��23��

2016ǯ04��06��

2016ǯ03��27��

2016ǯ03��14��

2016ǯ03��06��

2016ǯ02��24��

2016ǯ02��20��

2016ǯ02��11��

2016ǯ02��05��

2016ǯ01��31��

2015ǯ12��12��

2015ǯ12��06��

2015ǯ11��23��

2015ǯ11��21��

2015ǯ11��07��

2015ǯ10��20��

2015ǯ07��02��

2015ǯ06��14��

2015ǯ03��15��

2015ǯ03��10��

2015ǯ03��08��

2015ǯ01��05��

2014ǯ12��27��

2014ǯ11��12��

2014ǯ09��07��

2014ǯ07��18��

2014ǯ04��23��

2014ǯ04��22��

2000|01|
2003|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|05|06|07|08|09|10|11|12|
2012|02|03|04|05|06|07|08|09|
2013|01|02|03|04|05|06|07|
2014|01|04|07|09|11|12|
2015|01|03|06|07|10|11|12|
2016|01|02|03|04|06|07|08|10|11|12|
2017|01|02|03|04|05|06|07|10|12|
2018|03|05|06|10|12|
2019|02|03|05|06|07|08|10|
2020|08|09|
2021|07|08|10|12|
2022|01|04|06|12|
2023|03|
2024|03|04|07|11|12|
<��������(2006ǯ06��25��) ��������(2006ǯ07��02��)> �ǿ� �Խ�