root/graph/JavaPopWeb/src/jp/ac/nime/computer/grpsimulator/DocumentPanel.java

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. DocumentPanel
  2. DocumentFrame
  3. setDocumentPage
  4. initComponents
  5. setPageFile

package jp.ac.nime.computer.grpsimulator;

import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import javax.swing.*;

/** DocumentPanelクラスは解説のためのHTMLドキュメントを表示する
 * JPanelの派生クラスです。
 *
 * @author igarashi
 */
public class DocumentPanel extends JPanel {
        
        class DocumentFrame extends JFrame {
                JEditorPane jEditorPane_;
                DocumentFrame() {
                        setTitle(GrpSim.res_.getString("DocumentFrameCaption"));
                        addWindowListener(new WindowAdapter() {
                                public void windowClosing(WindowEvent evt) {
                                        docFrame_ = null;
                                }
                        });
                        JScrollPane jScrollPane = new JScrollPane();
                        getContentPane().add(jScrollPane, BorderLayout.CENTER);
                        jEditorPane_ = new JEditorPane();
                        jEditorPane_.setBorder(null);
                        jEditorPane_.setEditable(false);
                        jScrollPane.setViewportView(jEditorPane_);
                        pack();
                }
                void setDocumentPage(URL url) {
                        try {
                                jEditorPane_.setPage(url);
                        } catch(java.io.IOException e) {
                                jEditorPane_.setText("Can't load document ("+url+")");
                        }
                }
        }
        
        private JEditorPane jEditorPane_;
        private DocumentFrame docFrame_;
        
        /** DocumentPanelを構築します
         */
        public DocumentPanel() {
                initComponents();
        }
        
        private void initComponents() {
                setLayout(new BorderLayout());
                setPreferredSize(new Dimension(100,200));
                
                jEditorPane_ = new JEditorPane();
                jEditorPane_.setBorder(null);
                jEditorPane_.setEditable(false);
                
                JScrollPane jScrollPane = new JScrollPane();
                jScrollPane.setViewportView(jEditorPane_);
                
                add(jScrollPane, BorderLayout.CENTER);
                
                JPanel subPanel = new JPanel();
                subPanel.setLayout(new FlowLayout(FlowLayout.RIGHT,1,1));
                add(subPanel, BorderLayout.SOUTH);
                
                JButton viewBtn = new JButton();
                viewBtn.setText(GrpSim.res_.getString("DocumentViewButton"));
                //viewBtn.setFont(new Font("Dialog",Font.PLAIN,10)); // MacやSolalisだと化けるらしい
                viewBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                if (docFrame_ == null) {
                                        docFrame_ = new DocumentFrame();
                                } else {
                                        docFrame_.setState(Frame.NORMAL);
                                }
                                docFrame_.setDocumentPage(jEditorPane_.getPage());
                                Dimension siz = jEditorPane_.getSize();
                                docFrame_.setSize( siz.width+100, siz.height+100 );
                                docFrame_.setLocation( jEditorPane_.getLocationOnScreen() );
                                docFrame_.show();
                        }
                });
                subPanel.add(viewBtn);
        }
        
        /** ドキュメントを記したファイルを設定して表示します
         * @param filePath 表示するドキュメントファイルのファイル名
         */
        public void setPageFile(String fileName) {
                boolean bSuccess = false;
                try{
                        URL url = getClass().getResource("../../../../../html/" + fileName);
                        //URL url = getClass().getResource("html/" + fileName);
                        if (url!=null) {
                                jEditorPane_.setPage(url);
                                if (docFrame_ != null) docFrame_.setDocumentPage(url);
                                bSuccess = true;
                        }
                } catch(java.io.IOException e) {}
                if (!bSuccess) {
                        jEditorPane_.setText("Can't find document ("+fileName+")");
                }
        }
}

/* [<][>][^][v][top][bottom][index][help] */