1 package org.woehlke.computer.kurzweil.mandelbrot.view;
2
3 import org.woehlke.computer.kurzweil.mandelbrot.config.Config;
4 import org.woehlke.computer.kurzweil.mandelbrot.control.ControllerThread;
5 import org.woehlke.computer.kurzweil.mandelbrot.model.ApplicationModel;
6 import org.woehlke.computer.kurzweil.mandelbrot.model.helper.Point;
7
8 import javax.accessibility.Accessible;
9 import javax.swing.*;
10 import java.awt.*;
11 import java.awt.event.*;
12 import java.awt.image.ImageObserver;
13 import java.io.Serializable;
14
15
16
17
18
19
20
21
22 public class ApplicationFrame extends JFrame implements ImageObserver,
23 MenuContainer,
24 Serializable,
25 Accessible,
26 WindowListener,
27 MouseListener {
28
29 private volatile ControllerThread controllerThread;
30 private volatile ApplicationCanvas canvas;
31 private volatile ApplicationModel applicationModel;
32 private volatile Rectangle rectangleBounds;
33 private volatile Dimension dimensionSize;
34
35 public ApplicationFrame(Config config) {
36 super(config.getTitle());
37 this.applicationModel = new ApplicationModel(config,this);
38 BoxLayout layout = new BoxLayout(rootPane, BoxLayout.PAGE_AXIS);
39 this.canvas = new ApplicationCanvas(applicationModel);
40 this.controllerThread = new ControllerThread(applicationModel, this);
41 PanelButtonselbrot/view/PanelButtons.html#PanelButtons">PanelButtons panelButtons = new PanelButtons(this.applicationModel);
42 PanelSubtitlebrot/view/PanelSubtitle.html#PanelSubtitle">PanelSubtitle panelSubtitle = new PanelSubtitle(config.getSubtitle());
43 PanelCopyrightot/view/PanelCopyright.html#PanelCopyright">PanelCopyright panelCopyright = new PanelCopyright(config.getCopyright());
44 JSeparator separator = new JSeparator();
45 rootPane.setLayout(layout);
46 rootPane.add(panelSubtitle);
47 rootPane.add(canvas);
48 rootPane.add(panelCopyright);
49 rootPane.add(separator);
50 rootPane.add(panelButtons);
51 addWindowListener(this);
52 this.canvas.addMouseListener( this);
53 showMeInit();
54 setModeSwitch();
55 this.controllerThread.start();
56 }
57
58 public void windowOpened(WindowEvent e) {
59 showMe();
60 }
61
62 public void windowClosing(WindowEvent e) {
63 this.controllerThread.exit();
64 }
65
66 public void windowClosed(WindowEvent e) {
67 this.controllerThread.exit();
68 }
69
70 public void windowIconified(WindowEvent e) {}
71
72 public void windowDeiconified(WindowEvent e) {
73 showMe();
74 }
75
76 public void windowActivated(WindowEvent e) {
77 showMe();
78 }
79
80 public void windowDeactivated(WindowEvent e) {}
81
82
83 @Override
84 public void mouseClicked(MouseEvent e) {
85 Pointuter/kurzweil/mandelbrot/model/helper/Point.html#Point">Point c = new Point(e.getX(), e.getY());
86 this.applicationModel.click(c);
87 showMe();
88 }
89
90 @Override
91 public void mousePressed(MouseEvent e) {}
92
93 @Override
94 public void mouseReleased(MouseEvent e) {}
95
96 @Override
97 public void mouseEntered(MouseEvent e) {}
98
99 @Override
100 public void mouseExited(MouseEvent e) {}
101
102 public void showMeInit() {
103 pack();
104 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
105 double width = this.rootPane.getWidth();
106 double height = this.canvas.getHeight() + 180;
107 double startX = (screenSize.getWidth() - width) / 2d;
108 double startY = (screenSize.getHeight() - height) / 2d;
109 int myheight = Double.valueOf(height).intValue();
110 int mywidth = Double.valueOf(width).intValue();
111 int mystartX = Double.valueOf(startX).intValue();
112 int mystartY = Double.valueOf(startY).intValue();
113 this.rectangleBounds = new Rectangle(mystartX, mystartY, mywidth, myheight);
114 this.dimensionSize = new Dimension(mywidth, myheight);
115 this.setBounds(this.rectangleBounds);
116 this.setSize(this.dimensionSize);
117 this.setPreferredSize(this.dimensionSize);
118 this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
119 setVisible(true);
120 toFront();
121 }
122
123
124
125
126 public void showMe() {
127 this.pack();
128 this.setBounds(this.rectangleBounds);
129 this.setSize(this.dimensionSize);
130 this.setPreferredSize(this.dimensionSize);
131 this.setVisible(true);
132 this.toFront();
133 }
134
135 public void setModeSwitch() {
136 canvas.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
137 }
138
139 public void setModeZoom() {
140 canvas.setCursor(new Cursor(Cursor.HAND_CURSOR));
141 }
142
143 public ApplicationCanvas getCanvas() {
144 return canvas;
145 }
146 }