View Javadoc
1   package org.woehlke.computer.kurzweil.tabs.mandelbrot2julia;
2   
3   import org.woehlke.computer.kurzweil.application.ComputerKurzweilProperties;
4   import org.woehlke.computer.kurzweil.commons.ui.PanelCopyright;
5   import org.woehlke.computer.kurzweil.commons.ui.PanelSubtitle;
6   import org.woehlke.computer.kurzweil.commons.model.turing.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   * (C) 2006 - 2013 Thomas Woehlke.
17   * https://thomas-woehlke.blogspot.com/2016/01/mandelbrot-set-drawn-by-turing-machine.html
18   * @author Thomas Woehlke
19   * Date: 04.02.2006
20   * Time: 18:47:46
21   */
22  public class Mandelbrot2JuliaTab extends JFrame implements ImageObserver,
23          MenuContainer,
24          Serializable,
25          Accessible,
26          WindowListener,
27          MouseListener {
28  
29      private volatile Mandelbrot2JuliaController mandelbrotController;
30      private volatile Mandelbrot2JuliaCanvas canvas;
31      private volatile Mandelbrot2JuliaModel mandelbrotModel;
32      private volatile Rectangle rectangleBounds;
33      private volatile Dimension dimensionSize;
34  
35      public Mandelbrot2JuliaTab(ComputerKurzweilProperties properties) {
36          super(properties.getMandelbrot().getView().getTitle());
37          this.mandelbrotModel = new Mandelbrot2JuliaModel(properties,this);
38          BoxLayout layout = new BoxLayout(rootPane, BoxLayout.PAGE_AXIS);
39          this.canvas = new Mandelbrot2JuliaCanvas(mandelbrotModel);
40          this.mandelbrotController = new Mandelbrot2JuliaController(mandelbrotModel, this);
41          PanelSubtitles/ui/PanelSubtitle.html#PanelSubtitle">PanelSubtitle panelSubtitle = new PanelSubtitle(properties.getMandelbrot().getView().getSubtitle());
42          PanelCopyrightui/PanelCopyright.html#PanelCopyright">PanelCopyright panelCopyright = new PanelCopyright(properties.getAllinone().getView().getCopyright());
43          JSeparator separator = new JSeparator();
44          rootPane.setLayout(layout);
45          rootPane.add(panelSubtitle);
46          rootPane.add(canvas);
47          rootPane.add(panelCopyright);
48          addWindowListener(this);
49          this.canvas.addMouseListener(   this);
50          showMeInit();
51          setModeSwitch();
52          this.mandelbrotController.start();
53      }
54  
55      public void windowOpened(WindowEvent e) {
56          showMe();
57      }
58  
59      public void windowClosing(WindowEvent e) {
60          this.mandelbrotController.exit();
61      }
62  
63      public void windowClosed(WindowEvent e) {
64          this.mandelbrotController.exit();
65      }
66  
67      public void windowIconified(WindowEvent e) {}
68  
69      public void windowDeiconified(WindowEvent e) {
70          showMe();
71      }
72  
73      public void windowActivated(WindowEvent e) {
74          showMe();
75      }
76  
77      public void windowDeactivated(WindowEvent e) {}
78  
79  
80      @Override
81      public void mouseClicked(MouseEvent e) {
82          Pointuter/kurzweil/commons/model/turing/Point.html#Point">Point c = new Point(e.getX(), e.getY());
83          this.mandelbrotModel.click(c);
84          showMe();
85      }
86  
87      @Override
88      public void mousePressed(MouseEvent e) {}
89  
90      @Override
91      public void mouseReleased(MouseEvent e) {}
92  
93      @Override
94      public void mouseEntered(MouseEvent e) {}
95  
96      @Override
97      public void mouseExited(MouseEvent e) {}
98  
99      public void showMeInit() {
100         pack();
101         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
102         double width = this.rootPane.getWidth();
103         double height  = this.canvas.getHeight() + 90;
104         double startX = (screenSize.getWidth() - width) / 2d;
105         double startY = (screenSize.getHeight() - height) / 2d;
106         int myheight = Double.valueOf(height).intValue();
107         int mywidth = Double.valueOf(width).intValue();
108         int mystartX = Double.valueOf(startX).intValue();
109         int mystartY = Double.valueOf(startY).intValue();
110         this.rectangleBounds = new Rectangle(mystartX, mystartY, mywidth, myheight);
111         this.dimensionSize = new Dimension(mywidth, myheight);
112         this.setBounds(this.rectangleBounds);
113         this.setSize(this.dimensionSize);
114         this.setPreferredSize(this.dimensionSize);
115         this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
116         setVisible(true);
117         toFront();
118     }
119 
120     /**
121      * TODO write doc.
122      */
123     public void showMe() {
124         this.pack();
125         this.setBounds(this.rectangleBounds);
126         this.setSize(this.dimensionSize);
127         this.setPreferredSize(this.dimensionSize);
128         this.setVisible(true);
129         this.toFront();
130     }
131 
132     public void setModeSwitch() {
133         canvas.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
134     }
135 
136     /*
137     public void setModeZoom() {
138         canvas.setCursor(new Cursor(Cursor.HAND_CURSOR));
139     }
140 */
141     public Mandelbrot2JuliaCanvas getCanvas() {
142         return canvas;
143     }
144 }