Package semestralkaGUI

Source Code of semestralkaGUI.MainFrame

package semestralkaGUI;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import semestralka.Application;

/**
* Application main window.
* @author frantisek
*/
public class MainFrame extends JFrame{

    Application app;
    LogPanel log;
    JTextField input;
    JScrollPane cvs;
   
    public MainFrame(String title) throws HeadlessException {
        super(title);
        this.setBounds(200, 200, 640, 480);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setLayout(new BorderLayout());
       
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                try{
                    app.graphvizer().getTmpImage().delete();
               
                }catch(Exception ex){}
                System.exit(0);
            }
        });
       
        app = new Application();
       
        /*Initialize items*/
        this.log = new LogPanel();
        this.input = new JTextField();
        this.cvs = new JScrollPane(new ImageHolder());
        JButton run = new JButton("Run");
        JPanel top = new JPanel();
        JPanel content = new JPanel();
        JScrollPane right = new JScrollPane(log);
       
        /*Initialize menus*/
        JMenuBar menu = new JMenuBar();
        JMenu mm = new JMenu("Menu");
        JMenu am = new JMenu("Automat");
       
        mm.add(new LogExport("Save log to txt",log));
        mm.add(new DotSourceExport("Save dot source",this));
        mm.add(new AutomatImageExport("Save to png",this));
       
        am.add(new ClearLogAction("Clear log",this));
        am.add(new StringMatcher("Evaluate word",this));
        am.add(new SaveAutomatAction("Save automat",this));
        am.add(new LoadAutomatAction("Load Automat",this));
        am.add(new ShowConfigAction("Settings",this));
        menu.add(mm);
        menu.add(am);
       
        /*Deploy items in panels*/
        top.setLayout(new BorderLayout());
        top.add(input,BorderLayout.CENTER);
        top.add(menu,BorderLayout.PAGE_START);
        run.addActionListener(new RunButtonListener(this));
        top.add(run,BorderLayout.LINE_END);
        content.setLayout(new GridLayout(1,2));
        content.add(cvs);
        content.add(right);
       
       
        this.add(top,BorderLayout.NORTH);
        this.add(content,BorderLayout.CENTER);
        this.setVisible(true);
       
       

    }
   
    public void setCanvasImage(File f){
        ImageHolder hld = new ImageHolder();
        hld.openImg(f);
        cvs.setViewportView(hld);
        cvs.getViewport().setPreferredSize(new Dimension(this.getWidth()/2,this.getHeight()));
    }
   
}
TOP

Related Classes of semestralkaGUI.MainFrame

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.