001    // GraphLab Project: http://graphlab.sharif.edu
002    // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
003    // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
004    
005    package graphlab.graph.ui;
006    
007    import javax.swing.*;
008    import java.awt.*;
009    import java.io.File;
010    import java.io.FileNotFoundException;
011    import java.util.Scanner;
012    
013    /**
014     * @author Ali Ershadi
015     */
016    public class GTextFileRendererComponent extends JScrollPane {
017        public GTextFileRendererComponent(File f) {
018            try {
019                JTextArea jta = new JTextArea();
020                Scanner sc = new Scanner(f);
021                String s = "";
022                JViewport jvp = new JViewport();
023    
024                while (sc.hasNextLine())
025                    s += sc.nextLine() + "\n";
026                jta.setText(s);
027                jta.setBackground(new Color(200, 200, 255));
028                jta.setEditable(false);
029                jta.setFont(new Font("Sans Roman", 0, 14));
030                jvp.add(jta);
031                this.setViewport(jvp);
032            } catch (FileNotFoundException e) {
033                e.printStackTrace();
034            }
035    
036        }
037    }