Skip to content

Commit fc3c639

Browse files
committed
Merge pull request #49 from maartentbm/gui
Gui
2 parents 6148e69 + 18ee5d6 commit fc3c639

9 files changed

Lines changed: 340 additions & 44 deletions

File tree

src/main/java/nl/tudelft/ti2806/pl1/gui/Event.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,21 @@ public void actionPerformed(final ActionEvent e) {
158158
}
159159
},
160160

161+
/** Reset graph to original representation. **/
162+
RESET_GRAPH {
163+
@Override
164+
public void actionPerformed(final ActionEvent e) {
165+
window.getContent().getGraphPanel().applyZoomLevel(0);
166+
}
167+
},
168+
169+
HELP {
170+
@Override
171+
public void actionPerformed(final ActionEvent e) {
172+
window.getHelpDialog().setVisible(true);
173+
}
174+
},
175+
161176
/**
162177
*
163178
*/
@@ -175,6 +190,30 @@ public void actionPerformed(final ActionEvent e) {
175190
@Override
176191
public void actionPerformed(final ActionEvent e) {
177192
}
193+
},
194+
/**
195+
*
196+
*/
197+
NEXTZOOMLEVEL {
198+
@Override
199+
public void actionPerformed(final ActionEvent e) {
200+
window.getContent()
201+
.getGraphPanel()
202+
.applyZoomLevel(
203+
window.getContent().getGraphPanel().getZoomLevel() + 1);
204+
}
205+
},
206+
/**
207+
*
208+
*/
209+
PREVIOUSZOOMLEVEL {
210+
@Override
211+
public void actionPerformed(final ActionEvent e) {
212+
window.getContent()
213+
.getGraphPanel()
214+
.applyZoomLevel(
215+
window.getContent().getGraphPanel().getZoomLevel() - 1);
216+
}
178217
};
179218

180219
/**
@@ -260,4 +299,10 @@ public static void statusBarMid(final String message) {
260299
window.getStatusBar().mid(message);
261300
}
262301

302+
@Override
303+
public void actionPerformed(final ActionEvent e) {
304+
// TODO Auto-generated method stub
305+
306+
}
307+
263308
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package nl.tudelft.ti2806.pl1.gui;
2+
3+
import java.awt.BorderLayout;
4+
import java.awt.Dimension;
5+
import java.awt.GridBagLayout;
6+
import java.io.InputStream;
7+
import java.util.Scanner;
8+
9+
import javax.swing.JDialog;
10+
import javax.swing.JLabel;
11+
import javax.swing.JPanel;
12+
import javax.swing.JTabbedPane;
13+
14+
import com.horstmann.corejava.GBC;
15+
16+
/**
17+
* @author Marissa, Maarten
18+
* @since 15-6-2015
19+
*/
20+
public class HelpDialog extends JDialog {
21+
22+
/** The serial version UID. */
23+
private static final long serialVersionUID = -4612253023180773554L;
24+
25+
/** The size of the help dialog. */
26+
private static final Dimension SIZE = new Dimension(400, 300);
27+
28+
/** The file name of the source text for the 'Using DNApp' tab. */
29+
private static final String USING_DNAPP_HELP_FILE = "usingDNApp.help";
30+
31+
/** The content panel. */
32+
private JPanel content;
33+
34+
/** The tabs. */
35+
private JTabbedPane tabs;
36+
37+
/**
38+
* Initialize the help dialog.
39+
*
40+
* @param window
41+
* The parent application window.
42+
*/
43+
public HelpDialog(final Window window) {
44+
super(window);
45+
this.setTitle("Help");
46+
setLayout(new BorderLayout());
47+
setPreferredSize(SIZE);
48+
setMinimumSize(SIZE);
49+
50+
content = new JPanel(new BorderLayout());
51+
52+
tabs = new JTabbedPane();
53+
tabs.addTab("Using DN/App", makeUsingDNApp());
54+
tabs.addTab("Keyboard shortcuts", makeShortcuts());
55+
56+
content.add(tabs, BorderLayout.CENTER);
57+
58+
add(content, BorderLayout.CENTER);
59+
}
60+
61+
/**
62+
* @return The panel with information about how to use this application.
63+
*/
64+
private JPanel makeUsingDNApp() {
65+
JPanel ret = new JPanel(new BorderLayout());
66+
InputStream is = HelpDialog.class.getClassLoader().getResourceAsStream(
67+
USING_DNAPP_HELP_FILE); // TODO fix...
68+
Scanner sc = new Scanner(is, "UTF-8");
69+
StringBuilder sb = new StringBuilder("<html>");
70+
System.out.println(sc);
71+
while (sc.hasNextLine()) {
72+
String line = sc.nextLine();
73+
sb.append(line).append("<br>");
74+
System.out.println("READ LINE = " + line);
75+
}
76+
sc.close();
77+
sb.append("</html>");
78+
System.out.println(sb.toString());
79+
JLabel info = new JLabel(sb.toString());
80+
ret.add(info, BorderLayout.CENTER);
81+
return ret;
82+
}
83+
84+
/**
85+
* @return The panel with information about the available shortcuts.
86+
*/
87+
private JPanel makeShortcuts() {
88+
JPanel ret = new JPanel(new GridBagLayout());
89+
90+
String[][] info = { { "Shortcuts: ", "" }, { "F1", "Help" },
91+
{ "CTRL + R", "Reset to default view (zoom level)" },
92+
{ "CTRL + C", "Close the application" },
93+
{ "CTRL + O", "Open a file" },
94+
{ "+", "Go to the next zoomlevel" },
95+
{ "-", "Go to the previous zoomlevel" } };
96+
97+
for (int i = 0; i < info.length; i++) {
98+
for (int j = 0; j < info[0].length; j++) {
99+
ret.add(new JLabel(info[i][j]), new GBC(j, i));
100+
}
101+
}
102+
return ret;
103+
}
104+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package nl.tudelft.ti2806.pl1.gui;
2+
3+
import javax.swing.JMenuItem;
4+
5+
/**
6+
* A menu bar item which is only enabled if a graph is loaded into the graph
7+
* panel of a given window.
8+
*
9+
* @author Maarten
10+
* @since 16-6-2015
11+
*
12+
* @see JMenuItem
13+
* @see Window
14+
*/
15+
public class LoadedMenuItem extends JMenuItem {
16+
17+
/** The serial version UID. */
18+
private static final long serialVersionUID = 1718870799530320365L;
19+
20+
/** The window. */
21+
private Window window;
22+
23+
/**
24+
* Initialize the menu item.
25+
*
26+
* @param w
27+
* The window.
28+
*/
29+
public LoadedMenuItem(final Window w) {
30+
super();
31+
this.window = w;
32+
}
33+
34+
// @Override
35+
// public boolean isEnabled() {
36+
// if(window == null) {
37+
// System.out.println("WIN NULL");
38+
// return super.isEnabled();
39+
// }
40+
// return window.getContent().isGraphLoaded();
41+
// }
42+
43+
@Override
44+
public boolean isVisible() {
45+
if (window == null) {
46+
System.out.println("WIN NULL");
47+
return super.isEnabled();
48+
}
49+
return window.getContent().isGraphLoaded();
50+
}
51+
}

0 commit comments

Comments
 (0)