package com.teppefall.subpixel;

/**
 * @author janerik
 *
 * Subpixel.java
 *
 * I was replacing the old CRT's and needed something that could check for sub-pixel annomalies.
 * Sub-pixel problems are only common on very large LCD's.. (21" and larger) so there is no point in testing your Powerbook :)
 *
 * Surface and Fabric are written in the same way.
 */

import java.awt.Color;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JMenuBar;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import com.teppefall.ds.Application;
import com.teppefall.ds.StatusBar;
import com.teppefall.ds.content.Content;
import com.teppefall.ds.menu.MenuFile;
import com.teppefall.ds.menu.MenuView;
import com.teppefall.ds.menu.MenuHelp;
import com.teppefall.ds.util.Do;
import com.teppefall.surface.SurfacePanel;

public class Subpixel extends Application {

    private StatusBar status;
    private static final String NAME = "Subpixel", VERSION = "1.2", BUILD = "2007.04";
    private JMenuBar menubar;
    private MenuHelp help;
    private MenuView view;
    private SurfacePanel surface;
    private JToolBar toolbar;
    private JCheckBox split, gradient, info;

    public Subpixel(String[] args) {
    	/*
    	 * Application setup. Name, arguments and size.
    	 *
    	 * State is stored in ~/.$COMPANY/application.$NAME.properties
    	 * Icon is /images/$COMPANY.png. The URL is used by Sparks (Help->Add Serial->Send VM info to...)
    	 * Version and build is used by the About dialog.
    	 */
        super(NAME, "Teppefall", "http://installer.teppefall.com", args, new Dimension(736, 504));
		setVersion(VERSION);
		setBuild(BUILD);
		/*
		 * Layout.
		 */
        getApplicationFrame().getContentPane().setLayout(new BorderLayout());
        getApplicationFrame().getContentPane().add(status = new StatusBar(), BorderLayout.SOUTH);
        /*
         * Menu.
         */
        menubar = new JMenuBar();
        menubar.add(new MenuFile(this));
        menubar.add(view = new MenuView(this, false));
        menubar.add(help = new MenuHelp(this));
        getApplicationFrame().setJMenuBar(menubar);
        /*
         * Paint surface.
         */
        getApplicationFrame().getContentPane().add(surface = new SurfacePanel(), BorderLayout.CENTER);
        surface.getDarkstar().setRenderer(new SubpixelRenderer());
        /*
         * Toolbar. Notice the use of Actions and Icons. No bitmaps required.
         */
        toolbar = new JToolBar();
        toolbar.setBorderPainted(false);
        toolbar.add(new JButton(new ColorAction(surface.getDarkstar(), Color.BLACK)));
        toolbar.add(new JButton(new ColorAction(surface.getDarkstar(), Color.WHITE)));
        toolbar.add(new JButton(new ColorAction(surface.getDarkstar(), Color.RED)));
        toolbar.add(new JButton(new ColorAction(surface.getDarkstar(), Color.GREEN)));
        toolbar.add(new JButton(new ColorAction(surface.getDarkstar(), Color.BLUE)));
        toolbar.add(new JButton(new ColorAction(surface.getDarkstar())));
        //toolbar.add(new JToolBar.Separator());
        toolbar.add(split = new JCheckBox(new PaintAction(surface.getDarkstar(), PaintAction.SPLIT)));
        toolbar.add(gradient = new JCheckBox(new PaintAction(surface.getDarkstar(), PaintAction.GRADIENT)));
        toolbar.add(info = new JCheckBox(new PaintAction(surface.getDarkstar(), PaintAction.INFO)));

        /*
         * Internationalization (there is a bug here)
         */
        split.setText(Content.getString(PaintAction.SPLIT));
        gradient.setText(Content.getString(PaintAction.GRADIENT));
        info.setText(Content.getString(PaintAction.INFO));
        split.setName(PaintAction.SPLIT);
        gradient.setName(PaintAction.GRADIENT);
        info.setName(PaintAction.INFO);
        info.setSelected(true);

        /*
         * Don't paint the button borders.
         */
        Do.borderPainted(toolbar, false);
        /*
         * Add main component
         */
        getApplicationFrame().getContentPane().add(toolbar, BorderLayout.NORTH);
        /*
         * Visual sync. Move app to x/y, show/hide statusbar/toolbar/tooltips/menubar, set language and make the primary frame visible.
         */
        showApplication();
    }

    public void setMenuToolbarVisible(boolean visible) {
    	menubar.setVisible(visible);
    	toolbar.setVisible(visible);
	}

    public void setSurface(SurfacePanel surface) {
		this.surface = surface;
        getApplicationFrame().getContentPane().add(surface, BorderLayout.CENTER);
	}

    public SurfacePanel getSurface() {
		return surface;
	}

	public StatusBar getStatusbar() {
		return status;
	}

	public MenuView getMenuView() {
    	return view;
    }

    public static void main(String[] args) {
        Application.launch(Subpixel.class, args);
    }

}

