// GraphTea Project: http://github.com/graphtheorysoftware/GraphTea
// Copyright (C) 2012 Graph Theory Software Foundation: http://GraphTheorySoftware.com
// Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
// Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/

package graphtea.graph.ui;
import graphtea.platform.core.exception.ExceptionHandler;

import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * @author Ali Ershadi
 */
public class GTextFileRendererComponent extends JScrollPane {
    public GTextFileRendererComponent(File f) {
        try {
            JTextArea jta = new JTextArea();
            JViewport jvp = new JViewport();
            StringBuilder sb = new StringBuilder();
            try (Scanner sc = new Scanner(f)) {
                while (sc.hasNextLine())
                    sb.append(sc.nextLine()).append('\n');
            }
            jta.setText(sb.toString());
            jta.setBackground(new Color(200, 200, 255));
            jta.setEditable(false);
            jta.setFont(new Font("Sans Roman", 0, 14));
            jvp.add(jta);
            this.setViewport(jvp);
        } catch (FileNotFoundException e) {
            ExceptionHandler.catchException(e);
        }

    }
}
