source:
java/main/src/main/java/com/framsticks/gui/MainFrame.java
@
102
Last change on this file since 102 was 102, checked in by , 11 years ago | |
---|---|
File size: 2.9 KB |
Rev | Line | |
---|---|---|
[77] | 1 | package com.framsticks.gui; |
2 | ||
3 | import java.awt.event.ActionEvent; | |
[84] | 4 | import java.awt.event.KeyEvent; |
[77] | 5 | import java.awt.event.WindowAdapter; |
6 | import java.awt.event.WindowEvent; | |
7 | ||
[97] | 8 | import javax.swing.AbstractAction; |
9 | import javax.swing.JButton; | |
10 | import javax.swing.KeyStroke; | |
11 | import javax.swing.WindowConstants; | |
12 | ||
[100] | 13 | import org.apache.logging.log4j.Logger; |
14 | import org.apache.logging.log4j.LogManager; | |
[97] | 15 | |
16 | import com.framsticks.util.swing.MenuConstructor; | |
17 | ||
[77] | 18 | /** |
19 | * Application Main Frame. | |
20 | */ | |
[84] | 21 | @SuppressWarnings("serial") |
[77] | 22 | public class MainFrame extends Frame { |
23 | ||
[100] | 24 | private final static Logger log = LogManager.getLogger(MainFrame.class.getName()); |
[77] | 25 | |
26 | JButton start, stop, step; | |
27 | ||
28 | /** | |
29 | * Builds main frame. | |
30 | */ | |
31 | public MainFrame(final Browser browser) { | |
[97] | 32 | super(browser); |
33 | setTitle("framsticks"); | |
[84] | 34 | log.debug("creating main frame"); |
[77] | 35 | |
[84] | 36 | } |
[77] | 37 | |
38 | ||
39 | @Override | |
[97] | 40 | protected void initializeGui() { |
41 | super.initializeGui(); | |
[84] | 42 | |
43 | new MenuConstructor(fileMenu) | |
44 | .add(null, new AbstractAction("Console") { | |
45 | @Override | |
46 | public void actionPerformed(ActionEvent actionEvent) { | |
[97] | 47 | // showConsoleFrame(); |
[84] | 48 | } |
49 | }) | |
50 | .add(KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.CTRL_MASK), new AbstractAction("Goto") { | |
51 | @Override | |
52 | public void actionPerformed(ActionEvent actionEvent) { | |
[102] | 53 | // browser.autoResolvePath("/simulator/genepools/groups/0", null); |
[84] | 54 | // browser.autoResolvePath("/simulator/populations/groups/0", null; |
55 | // browser.autoResolvePath("/simulator/genepools/groups/0/genotypes", null); | |
56 | // browser.autoResolvePath("/simulator/populations/groups", null); | |
57 | } | |
58 | }) | |
59 | .add(null, new AbstractAction("Disconnect") { | |
60 | @Override | |
61 | public void actionPerformed(ActionEvent actionEvent) { | |
62 | disconnect(); | |
63 | } | |
64 | }) | |
65 | .add(null, new AbstractAction("Quit") { | |
66 | @Override | |
67 | public void actionPerformed(ActionEvent actionEvent) { | |
68 | } | |
69 | }) | |
70 | ; | |
71 | ||
[77] | 72 | setFrameProperties(); |
73 | } | |
74 | ||
75 | ||
76 | /** | |
77 | * Sets frame properties. | |
78 | */ | |
79 | private void setFrameProperties() { | |
[84] | 80 | assert isActive(); |
[97] | 81 | getSwing().setMinimumSize(getSwing().getPreferredSize()); |
82 | getSwing().setSize(getSwing().getPreferredSize()); | |
83 | getSwing().setMaximumSize(screenDimension); | |
84 | getSwing().setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); | |
[77] | 85 | |
[97] | 86 | getSwing().setIconImage(ImageProvider.loadImage(ImageProvider.LOGO) |
[77] | 87 | .getImage()); |
88 | ||
89 | ||
[97] | 90 | getSwing().addWindowListener(new WindowAdapter() { |
[77] | 91 | public void windowClosing(WindowEvent e) { |
[84] | 92 | assert isActive(); |
93 | /* | |
94 | if (connection != null) { | |
[77] | 95 | connection.close(); |
96 | } | |
97 | */ | |
98 | onWindowClosing(); | |
[97] | 99 | getSwing().dispose(); |
[77] | 100 | } |
101 | }); | |
102 | } | |
103 | ||
104 | /** | |
105 | * Closes connection with manager. | |
106 | */ | |
107 | private void disconnect() { | |
[84] | 108 | assert isActive(); |
[77] | 109 | browser.clear(); |
110 | onWindowClosing(); | |
[97] | 111 | // statusBar.setText("You are disconnected"); |
[77] | 112 | } |
113 | ||
114 | /** | |
115 | * Method used while window is closing. | |
116 | */ | |
117 | private void onWindowClosing() { | |
[84] | 118 | assert isActive(); |
[77] | 119 | |
120 | } | |
121 | ||
122 | public void setRunningButtons(boolean running) { | |
[84] | 123 | assert isActive(); |
124 | step.setEnabled(!running); | |
[77] | 125 | stop.setEnabled(running); |
126 | start.setEnabled(!running); | |
127 | } | |
128 | ||
129 | } | |
130 |
Note: See TracBrowser
for help on using the repository browser.