I implemented the focused cells changing color, still a lots of work :)
[puzzles.git] / src / com / github / puzzles / gui / MainWindow.java
blobd84b9876a01ca8ec5c3dc9a7cbf65a31ddd3e2d9
1 package com.github.puzzles.gui;
3 import java.awt.EventQueue;
4 import java.awt.FlowLayout;
5 import java.awt.event.MouseAdapter;
6 import java.awt.event.MouseEvent;
8 import javax.swing.BoxLayout;
9 import javax.swing.JDialog;
10 import javax.swing.JFrame;
11 import javax.swing.JMenu;
12 import javax.swing.JMenuBar;
13 import javax.swing.JMenuItem;
14 import javax.swing.JPanel;
16 import com.github.puzzles.core.FlippingPuzzle;
17 import com.github.puzzles.core.SlidingPuzzle;
19 public class MainWindow {
21 private JFrame frame;
22 private FlippingPuzzle flippingPuzzle;
23 private SlidingPuzzle sliddingPuzzle;
24 private JPanel mainPanel;
25 private JPanel puzzlePanel;
27 /**
28 * Launch the application.
30 public static void main(String[] args) {
31 EventQueue.invokeLater(new Runnable() {
32 public void run() {
33 try {
34 MainWindow window = new MainWindow();
35 window.frame.setVisible(true);
36 } catch (Exception e) {
37 e.printStackTrace();
40 });
43 /**
44 * Create the application.
46 public MainWindow() {
47 initialize();
50 /**
51 * Initialize the contents of the frame.
53 private void initialize() {
55 frame = new JFrame();
56 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
58 frame.setBounds(0, 0, 800, 600);
60 JMenuBar topMenuBar = new JMenuBar();
61 frame.setJMenuBar(topMenuBar);
63 JMenu menuFile = new JMenu("File");
64 topMenuBar.add(menuFile);
66 JMenu newPuzzleMenu = new JMenu("New puzzle");
67 menuFile.add(newPuzzleMenu);
69 JMenuItem flippingPuzzle = new JMenuItem("Flipping Puzzle");
70 flippingPuzzle.addMouseListener(new MouseAdapter() {
71 @Override
72 public void mouseReleased(MouseEvent e) {
74 JDialog flippingPuzzleDialog = new FlippingPuzzleDialog(
75 MainWindow.this);
76 flippingPuzzleDialog
77 .setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
78 flippingPuzzleDialog.setAlwaysOnTop(true);
79 flippingPuzzleDialog.setModal(true);
80 flippingPuzzleDialog.setVisible(true);
83 * if(MainWindow.this.flippingPuzzle != null){
84 * puzzlePanel.add(new FlippingPuzzlePanel(MainWindow.this));
86 * frame.revalidate(); frame.repaint(); } //
89 });
90 newPuzzleMenu.add(flippingPuzzle);
92 JMenuItem slidingPuzzle = new JMenuItem("Sliding Puzzle");
93 slidingPuzzle.addMouseListener(new MouseAdapter() {
94 @Override
95 public void mouseReleased(MouseEvent e) {
96 JDialog slidingPuzzleDialog = new SlidingPuzzleDialog(
97 MainWindow.this);
98 slidingPuzzleDialog
99 .setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
100 slidingPuzzleDialog.setAlwaysOnTop(true);
101 slidingPuzzleDialog.setModal(true);
102 slidingPuzzleDialog.setVisible(true);
106 newPuzzleMenu.add(slidingPuzzle);
108 JMenu helpMenu = new JMenu("Help");
109 topMenuBar.add(helpMenu);
111 JMenuItem aboutMenu = new JMenuItem("About me");
112 aboutMenu.addMouseListener(new MouseAdapter() {
113 @Override
114 public void mouseReleased(MouseEvent e) {
115 JDialog aboutMeDialog = new AboutMeDialog();
116 aboutMeDialog.setAlwaysOnTop(true);
117 aboutMeDialog.setModal(true);
118 aboutMeDialog.setVisible(true);
121 helpMenu.add(aboutMenu);
122 frame.getContentPane().setLayout(
123 new FlowLayout(FlowLayout.CENTER, 5, 5));
125 mainPanel = new JPanel();
126 frame.getContentPane().add(mainPanel);
127 mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
129 puzzlePanel = new JPanel();
130 mainPanel.add(puzzlePanel);
131 puzzlePanel.setLayout(new BoxLayout(puzzlePanel, BoxLayout.PAGE_AXIS));
135 public void reset() {
136 flippingPuzzle = null;
137 sliddingPuzzle = null;
138 // frame.remove(puzzlePanel);
139 // frame.removeAll();
140 puzzlePanel.removeAll();
141 frame.revalidate();
142 frame.repaint();
143 System.gc();
146 public FlippingPuzzle getFlippingPuzzle() {
147 return flippingPuzzle;
150 public void setFlippingPuzzle(FlippingPuzzle flippingPuzzle) {
151 this.flippingPuzzle = flippingPuzzle;
154 public SlidingPuzzle getSliddingPuzzle() {
155 return sliddingPuzzle;
158 public void setSliddingPuzzle(SlidingPuzzle sliddingPuzzle) {
159 this.sliddingPuzzle = sliddingPuzzle;
162 public JPanel getMainPanel() {
163 return mainPanel;
166 public JPanel getPanel() {
167 return puzzlePanel;
170 public JPanel getPuzzlePanel() {
171 return puzzlePanel;
174 public void setPuzzlePanel(JPanel puzzlePanel) {
175 this.puzzlePanel = puzzlePanel;
178 public JFrame getFrame() {
179 return frame;