Package editor

Source Code of editor.MapEditorFrame

package editor;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.AdjustmentEvent;
import editor.core.ConstantEditor;
import editor.model.GUIModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentListener;
import java.util.Observable;
import java.util.Observer;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

/**
* Fenetre principal de l'editeur
* @author mastersnes
*/
public class MapEditorFrame extends JFrame implements Observer {

    private GUIModel guiModel;
    private static final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    private static final int BARRE_DEMARRER = 50;

    /**
     * Constructeur de la fenetre
     */
    public MapEditorFrame() {
        super();
        this.setTitle(ConstantEditor.FRAME_NAME);


        ConstantEditor.setFrame(this);
        this.guiModel = new GUIModel();
        this.guiModel.addObserver(this);


        this.setSize(screenSize.width, screenSize.height - BARRE_DEMARRER);
        final JMenuBar menuBar = new JMenuBar();

        JMenu menu = new JMenu("Nouveau");
        JMenuItem item = new JMenuItem("Creer une nouvelle map");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                guiModel.initNewMap();
            }
        });
        menu.add(item);

        item = new JMenuItem("Creer un nouvel objet");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                guiModel.initNewObjet();
            }
        });
        menu.add(item);

        item = new JMenuItem("Creer un nouveau sort");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                guiModel.initNewSpell();
            }
        });
        menu.add(item);

        item = new JMenuItem("Creer une nouvelle competence");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                guiModel.initNewSkill();
            }
        });
        menu.add(item);

        item = new JMenuItem("Creer un nouveau monstre");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                guiModel.initNewMonster();
            }
        });
        menu.add(item);
        menuBar.add(menu);
       
        item = new JMenuItem("Creer un nouveau hero");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                guiModel.initNewHero();
            }
        });
        menu.add(item);
        menuBar.add(menu);

        menu = new JMenu("Edition");
        item = new JMenuItem("Sauvegarder la map en cours");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                guiModel.sauverMap();
            }
        });
        menu.add(item);
        item = new JMenuItem("Charger une map existante");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                guiModel.loadMap();
            }
        });
        menu.add(item);
        item = new JMenuItem("Redimensionner la map");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                guiModel.redimensionner();
            }
        });
        menu.add(item);
        menuBar.add(menu);

        menu = new JMenu("Couche");
        item = new JMenuItem("premier plan");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                guiModel.setCouche(1);
            }
        });
        menu.add(item);
        item = new JMenuItem("second plan");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                guiModel.setCouche(2);
            }
        });
        menu.add(item);
        item = new JMenuItem("plan superieur");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                guiModel.setCouche(3);
            }
        });
        menu.add(item);
        item = new JMenuItem("colisions");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                guiModel.setCouche(4);
            }
        });
        menu.add(item);
        menu.add(item);
        item = new JMenuItem("évenements");
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                guiModel.setCouche(5);
            }
        });
        menu.add(item);
        menuBar.add(menu);

        this.setJMenuBar(menuBar);

        final JPanel masterPanel = new JPanel();
        masterPanel.setLayout(new BoxLayout(masterPanel, BoxLayout.X_AXIS));

        final JPanel leftPanel = guiModel.getLeftPanel();
        final JPanel rightPanel = guiModel.getRightPanel();

        //initConstraints();

        masterPanel.add(leftPanel, BorderLayout.WEST);
        masterPanel.add(rightPanel, BorderLayout.EAST);

        this.setContentPane(masterPanel);
        this.setVisible(true);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);

    }

    /**
     * Methode main du programme
     * @param args
     */
    public static void main(final String[] args) {
        new MapEditorFrame();
    }

    @Override
    public void update(final Observable o, final Object arg) {
        this.guiModel = (GUIModel) o;

        final JPanel masterPanel = new JPanel();
        masterPanel.setLayout(new BoxLayout(masterPanel, BoxLayout.X_AXIS));

        final JScrollPane left = new JScrollPane(guiModel.getLeftPanel());
        left.setPreferredSize(new Dimension(screenSize.width - 200, screenSize.height));
        left.setSize(new Dimension(screenSize.width - 200, screenSize.height));
        left.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        left.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

        final AdjustmentListener listener = new AdjustmentListener() {

            @Override
            public void adjustmentValueChanged(final AdjustmentEvent e) {
                if (e.getValueIsAdjusting() == false) {
                    guiModel.getLeftPanel().repaint();
                }
            }
        };

        left.getHorizontalScrollBar().addAdjustmentListener(listener);
        left.getVerticalScrollBar().addAdjustmentListener(listener);


        final JScrollPane right = new JScrollPane(guiModel.getRightPanel());
        right.setPreferredSize(new Dimension(200, screenSize.height));
        right.setSize(new Dimension(200, screenSize.height));
        right.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        right.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

        masterPanel.add(left, BorderLayout.WEST);
        masterPanel.add(right, BorderLayout.EAST);

        this.setContentPane(masterPanel);

        masterPanel.updateUI();
    }
}
TOP

Related Classes of editor.MapEditorFrame

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.