diff --git a/src/main/java/nl/tudelft/ti2806/pl1/gui/Event.java b/src/main/java/nl/tudelft/ti2806/pl1/gui/Event.java
index 127bc60..5d08465 100644
--- a/src/main/java/nl/tudelft/ti2806/pl1/gui/Event.java
+++ b/src/main/java/nl/tudelft/ti2806/pl1/gui/Event.java
@@ -158,6 +158,21 @@ public void actionPerformed(final ActionEvent e) {
}
},
+ /** Reset graph to original representation. **/
+ RESET_GRAPH {
+ @Override
+ public void actionPerformed(final ActionEvent e) {
+ window.getContent().getGraphPanel().applyZoomLevel(0);
+ }
+ },
+
+ HELP {
+ @Override
+ public void actionPerformed(final ActionEvent e) {
+ window.getHelpDialog().setVisible(true);
+ }
+ },
+
/**
*
*/
@@ -175,6 +190,30 @@ public void actionPerformed(final ActionEvent e) {
@Override
public void actionPerformed(final ActionEvent e) {
}
+ },
+ /**
+ *
+ */
+ NEXTZOOMLEVEL {
+ @Override
+ public void actionPerformed(final ActionEvent e) {
+ window.getContent()
+ .getGraphPanel()
+ .applyZoomLevel(
+ window.getContent().getGraphPanel().getZoomLevel() + 1);
+ }
+ },
+ /**
+ *
+ */
+ PREVIOUSZOOMLEVEL {
+ @Override
+ public void actionPerformed(final ActionEvent e) {
+ window.getContent()
+ .getGraphPanel()
+ .applyZoomLevel(
+ window.getContent().getGraphPanel().getZoomLevel() - 1);
+ }
};
/**
@@ -260,4 +299,10 @@ public static void statusBarMid(final String message) {
window.getStatusBar().mid(message);
}
+ @Override
+ public void actionPerformed(final ActionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
}
diff --git a/src/main/java/nl/tudelft/ti2806/pl1/gui/HelpDialog.java b/src/main/java/nl/tudelft/ti2806/pl1/gui/HelpDialog.java
new file mode 100644
index 0000000..0fe025c
--- /dev/null
+++ b/src/main/java/nl/tudelft/ti2806/pl1/gui/HelpDialog.java
@@ -0,0 +1,104 @@
+package nl.tudelft.ti2806.pl1.gui;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.GridBagLayout;
+import java.io.InputStream;
+import java.util.Scanner;
+
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTabbedPane;
+
+import com.horstmann.corejava.GBC;
+
+/**
+ * @author Marissa, Maarten
+ * @since 15-6-2015
+ */
+public class HelpDialog extends JDialog {
+
+ /** The serial version UID. */
+ private static final long serialVersionUID = -4612253023180773554L;
+
+ /** The size of the help dialog. */
+ private static final Dimension SIZE = new Dimension(400, 300);
+
+ /** The file name of the source text for the 'Using DNApp' tab. */
+ private static final String USING_DNAPP_HELP_FILE = "usingDNApp.help";
+
+ /** The content panel. */
+ private JPanel content;
+
+ /** The tabs. */
+ private JTabbedPane tabs;
+
+ /**
+ * Initialize the help dialog.
+ *
+ * @param window
+ * The parent application window.
+ */
+ public HelpDialog(final Window window) {
+ super(window);
+ this.setTitle("Help");
+ setLayout(new BorderLayout());
+ setPreferredSize(SIZE);
+ setMinimumSize(SIZE);
+
+ content = new JPanel(new BorderLayout());
+
+ tabs = new JTabbedPane();
+ tabs.addTab("Using DN/App", makeUsingDNApp());
+ tabs.addTab("Keyboard shortcuts", makeShortcuts());
+
+ content.add(tabs, BorderLayout.CENTER);
+
+ add(content, BorderLayout.CENTER);
+ }
+
+ /**
+ * @return The panel with information about how to use this application.
+ */
+ private JPanel makeUsingDNApp() {
+ JPanel ret = new JPanel(new BorderLayout());
+ InputStream is = HelpDialog.class.getClassLoader().getResourceAsStream(
+ USING_DNAPP_HELP_FILE); // TODO fix...
+ Scanner sc = new Scanner(is, "UTF-8");
+ StringBuilder sb = new StringBuilder("");
+ System.out.println(sc);
+ while (sc.hasNextLine()) {
+ String line = sc.nextLine();
+ sb.append(line).append("
");
+ System.out.println("READ LINE = " + line);
+ }
+ sc.close();
+ sb.append("");
+ System.out.println(sb.toString());
+ JLabel info = new JLabel(sb.toString());
+ ret.add(info, BorderLayout.CENTER);
+ return ret;
+ }
+
+ /**
+ * @return The panel with information about the available shortcuts.
+ */
+ private JPanel makeShortcuts() {
+ JPanel ret = new JPanel(new GridBagLayout());
+
+ String[][] info = { { "Shortcuts: ", "" }, { "F1", "Help" },
+ { "CTRL + R", "Reset to default view (zoom level)" },
+ { "CTRL + C", "Close the application" },
+ { "CTRL + O", "Open a file" },
+ { "+", "Go to the next zoomlevel" },
+ { "-", "Go to the previous zoomlevel" } };
+
+ for (int i = 0; i < info.length; i++) {
+ for (int j = 0; j < info[0].length; j++) {
+ ret.add(new JLabel(info[i][j]), new GBC(j, i));
+ }
+ }
+ return ret;
+ }
+}
diff --git a/src/main/java/nl/tudelft/ti2806/pl1/gui/LoadedMenuItem.java b/src/main/java/nl/tudelft/ti2806/pl1/gui/LoadedMenuItem.java
new file mode 100644
index 0000000..99be2bb
--- /dev/null
+++ b/src/main/java/nl/tudelft/ti2806/pl1/gui/LoadedMenuItem.java
@@ -0,0 +1,51 @@
+package nl.tudelft.ti2806.pl1.gui;
+
+import javax.swing.JMenuItem;
+
+/**
+ * A menu bar item which is only enabled if a graph is loaded into the graph
+ * panel of a given window.
+ *
+ * @author Maarten
+ * @since 16-6-2015
+ *
+ * @see JMenuItem
+ * @see Window
+ */
+public class LoadedMenuItem extends JMenuItem {
+
+ /** The serial version UID. */
+ private static final long serialVersionUID = 1718870799530320365L;
+
+ /** The window. */
+ private Window window;
+
+ /**
+ * Initialize the menu item.
+ *
+ * @param w
+ * The window.
+ */
+ public LoadedMenuItem(final Window w) {
+ super();
+ this.window = w;
+ }
+
+ // @Override
+ // public boolean isEnabled() {
+ // if(window == null) {
+ // System.out.println("WIN NULL");
+ // return super.isEnabled();
+ // }
+ // return window.getContent().isGraphLoaded();
+ // }
+
+ @Override
+ public boolean isVisible() {
+ if (window == null) {
+ System.out.println("WIN NULL");
+ return super.isEnabled();
+ }
+ return window.getContent().isGraphLoaded();
+ }
+}
diff --git a/src/main/java/nl/tudelft/ti2806/pl1/gui/MenuBar.java b/src/main/java/nl/tudelft/ti2806/pl1/gui/MenuBar.java
index 4c66341..7ab51f3 100644
--- a/src/main/java/nl/tudelft/ti2806/pl1/gui/MenuBar.java
+++ b/src/main/java/nl/tudelft/ti2806/pl1/gui/MenuBar.java
@@ -1,5 +1,6 @@
package nl.tudelft.ti2806.pl1.gui;
+import java.awt.event.KeyEvent;
import java.net.URL;
import javax.swing.ImageIcon;
@@ -7,6 +8,7 @@
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
+import javax.swing.KeyStroke;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
@@ -37,6 +39,7 @@ public MenuBar(final Window w) {
this.add(fileMenu());
this.add(editMenu());
this.add(viewMenu());
+ this.add(helpMenu());
}
/**
@@ -46,11 +49,11 @@ public MenuBar(final Window w) {
*/
private JMenu fileMenu() {
JMenu ret = new JMenu("File");
- ret.add(makeMI("Import", null, 'I',
+ JMenuItem imp = new JMenuItem();
+ setMenuItem(imp, "Import", null, 'I',
"Import a sequence graph (.node.graph and .edge.graph)",
- Event.IMPORT_FILE));
- ret.add(makeMI("Open database", null, 'O',
- "Open a graph database file", Event.OPEN_GRAPH_DB));
+ Event.IMPORT_FILE);
+ ret.add(imp);
JMenu export = new JMenu("Export graph layout as...") {
/** The serial version UID. */
@@ -62,11 +65,31 @@ public boolean isEnabled() {
}
};
export.setMnemonic('E');
- JMenuItem exportDGS = makeMI("DGS format", null, 'D', null,
+ JMenuItem exportDGS = new JMenuItem();
+ setMenuItem(exportDGS, "DGS format", null, 'D', null,
Event.WRITE_TO_DGS);
export.add(exportDGS);
ret.add(export);
- ret.add(makeMI("Exit", null, 'E', "Exit the program", Event.EXIT_APP));
+
+ JMenuItem exit = new JMenuItem();
+ setMenuItem(exit, "Exit", null, 'E', "Exit the program", Event.EXIT_APP);
+ ret.add(exit);
+
+ return ret;
+ }
+
+ /**
+ * Creates and fills the info menu.
+ *
+ * @return the info menu
+ */
+ private JMenu helpMenu() {
+ JMenu ret = new JMenu("Help");
+ JMenuItem help = new JMenuItem();
+ setMenuItem(help, "Help", null, 'h', "Press to show shortcuts",
+ Event.HELP);
+ setAcc(help, KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
+ ret.add(help);
return ret;
}
@@ -77,7 +100,6 @@ public boolean isEnabled() {
*/
private JMenu editMenu() {
JMenu ret = new JMenu("Edit");
- // ret.add(makeMI("?", null, '?', "?", null));
return ret;
}
@@ -88,6 +110,38 @@ private JMenu editMenu() {
*/
private JMenu viewMenu() {
JMenu ret = new JMenu("View");
+
+ JMenuItem reset = new LoadedMenuItem(window);
+ setMenuItem(reset, "Reset view", null, 'R', "Reset to default view.",
+ Event.RESET_GRAPH);
+ setAcc(reset, KeyStroke.getKeyStroke(reset.getMnemonic(),
+ java.awt.Event.CTRL_MASK));
+ ret.add(reset);
+
+ JMenuItem zoomlevelplus = new LoadedMenuItem(window);
+ setMenuItem(zoomlevelplus, "Next zoomlevel", null, 'N',
+ "Go to next zoomlevel", Event.NEXTZOOMLEVEL);
+ setAcc(zoomlevelplus, KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS,
+ java.awt.Event.CTRL_MASK + java.awt.Event.SHIFT_MASK));
+ ret.add(zoomlevelplus);
+
+ JMenuItem zoomlevelminus = new LoadedMenuItem(window);
+ setMenuItem(zoomlevelminus, "Previous zoomlevel", null, 'P',
+ "Go to previous zoomlevel", Event.PREVIOUSZOOMLEVEL);
+ setAcc(zoomlevelminus, KeyStroke.getKeyStroke(KeyEvent.VK_MINUS,
+ java.awt.Event.CTRL_MASK));
+ ret.add(zoomlevelminus);
+
+ ret.add(makeShowToolBar());
+ ret.add(makeShowOptionPane());
+ return ret;
+ }
+
+ /**
+ * @return The show tool bar check box menu item.
+ */
+ private JCheckBoxMenuItem makeShowToolBar() {
+
final JCheckBoxMenuItem showToolBar = new JCheckBoxMenuItem(
"Show tool bar", true);
showToolBar.addChangeListener(new ChangeListener() {
@@ -97,15 +151,21 @@ public void stateChanged(final ChangeEvent e) {
window.revalidate();
}
});
- ret.add(showToolBar);
+ return showToolBar;
+ }
+
+ /**
+ * @return The show option pane check box menu item.
+ */
+ private JCheckBoxMenuItem makeShowOptionPane() {
final JCheckBoxMenuItem showOptionPane = new JCheckBoxMenuItem(
- "Show option panel", false) {
+ "Show option panel", true) {
/** The serial version UID. */
private static final long serialVersionUID = 1L;
@Override
- public boolean isEnabled() {
+ public boolean isVisible() {
return window.getContent().isGraphLoaded();
}
};
@@ -116,13 +176,15 @@ public void stateChanged(final ChangeEvent e) {
window.revalidate();
}
});
- ret.add(showOptionPane);
- return ret;
+ return showOptionPane;
}
/**
* Creates and sets up a menu item.
*
+ * @param item
+ * The menuItem we want to set properties for.
+ *
* @param text
* The text to show on the menu item.
* @param iconName
@@ -135,24 +197,33 @@ public void stateChanged(final ChangeEvent e) {
* The event name.
*
* @see Event
- * @return The menu item created.
*/
- private JMenuItem makeMI(final String text, final String iconName,
- final char mnemonic, final String toolTipText, final Event action) {
- JMenuItem ret = new JMenuItem();
- ret.setText(text);
- ret.setMnemonic(mnemonic);
- ret.setToolTipText(toolTipText);
- ret.addActionListener(action);
+ private void setMenuItem(final JMenuItem item, final String text,
+ final String iconName, final char mnemonic,
+ final String toolTipText, final Event action) {
+ item.setText(text);
+ item.setMnemonic(mnemonic);
+ item.setToolTipText(toolTipText);
+ item.addActionListener(action);
if (iconName != null) {
String imgLocation = "images/" + iconName;
URL imageURL = ToolBar.class.getResource(imgLocation);
if (imageURL != null) {
- ret.setIcon(new ImageIcon(imageURL, text));
+ item.setIcon(new ImageIcon(imageURL, text));
} else {
System.err.println("Resource not found: " + imgLocation);
}
}
- return ret;
+ }
+
+ /**
+ *
+ * @param item
+ * JMenuItem we want to add an acceleator to.
+ * @param keyStroke
+ * The set of keys it will use.
+ */
+ private void setAcc(final JMenuItem item, final KeyStroke keyStroke) {
+ item.setAccelerator(keyStroke);
}
}
diff --git a/src/main/java/nl/tudelft/ti2806/pl1/gui/Window.java b/src/main/java/nl/tudelft/ti2806/pl1/gui/Window.java
index 8a0b049..bb181fa 100644
--- a/src/main/java/nl/tudelft/ti2806/pl1/gui/Window.java
+++ b/src/main/java/nl/tudelft/ti2806/pl1/gui/Window.java
@@ -39,6 +39,9 @@ public class Window extends JFrame implements Observer, ContentLoadedObserver {
/** The status bar of the window. */
private StatusBar statusBar;
+ /** The help menu. **/
+ private HelpDialog helpDialog;
+
/**
* Initiate a new Window with default settings.
*/
@@ -68,6 +71,8 @@ public Window(final WindowSettings wSettings) {
Event.setWindow(this);
+ helpDialog = new HelpDialog(this);
+
toolBar = new ToolBar();
add(toolBar, BorderLayout.NORTH);
@@ -185,6 +190,13 @@ public final StatusBar getStatusBar() {
return statusBar;
}
+ /**
+ * @return the help menu
+ */
+ public HelpDialog getHelpDialog() {
+ return helpDialog;
+ }
+
@Override
public final String toString() {
return this.getClass().toString();
diff --git a/src/main/java/nl/tudelft/ti2806/pl1/gui/WindowSettings.java b/src/main/java/nl/tudelft/ti2806/pl1/gui/WindowSettings.java
index 5684d2f..ccb82a9 100644
--- a/src/main/java/nl/tudelft/ti2806/pl1/gui/WindowSettings.java
+++ b/src/main/java/nl/tudelft/ti2806/pl1/gui/WindowSettings.java
@@ -18,7 +18,7 @@ public class WindowSettings extends Observable {
/**
*
*/
- private static final int DEFAULT_SIZE_X = 700, DEFAULT_SIZE_Y = 500;
+ private static final int DEFAULT_SIZE_X = 900, DEFAULT_SIZE_Y = 600;
/**
*
diff --git a/src/main/java/nl/tudelft/ti2806/pl1/gui/contentpane/GraphPanel.java b/src/main/java/nl/tudelft/ti2806/pl1/gui/contentpane/GraphPanel.java
index 1f3e5a8..4edee5b 100644
--- a/src/main/java/nl/tudelft/ti2806/pl1/gui/contentpane/GraphPanel.java
+++ b/src/main/java/nl/tudelft/ti2806/pl1/gui/contentpane/GraphPanel.java
@@ -66,6 +66,9 @@ public class GraphPanel extends JSplitPane implements ContentTab {
/** The horizontal scroll increment value. */
private static final int HOR_SCROLL_INCR = 400;
+ /** How far zoomed in. **/
+ private int count = 0;
+
/**
* Threshold value for first zoom level.
*/
@@ -548,8 +551,12 @@ private String checkCollapsed(final HashSet ids) {
* The zoom level to apply.
*/
public void applyZoomLevel(final int newZoomLevel) {
- if (newZoomLevel < 0 || newZoomLevel > thresholds.length) {
+ if (newZoomLevel < 0) {
+ Event.statusBarError("There is no zoom level further from the current level");
+ zoomLevel = 0;
+ } else if (newZoomLevel > thresholds.length) {
Event.statusBarError("There is no zoom level further from the current level");
+ zoomLevel = thresholds.length;
} else if (newZoomLevel == 0) {
visualizeGraph(ConvertDGraph.convert(dgraph));
highlight();
@@ -585,11 +592,8 @@ public final String toString() {
*/
class Scrolling implements MouseWheelListener {
- /** How far we're zoomed in on the current level. **/
- private int count = 0;
-
/** How far there has to be zoomed in to get to a new zoomlevel. **/
- private static final int NEWLEVEL = 10;
+ private static final int NEWLEVEL = 3;
// /** How far one scroll zooms in. **/
// private static final double ZOOMPERCENTAGE = 1.1;
@@ -603,7 +607,7 @@ class Scrolling implements MouseWheelListener {
@Override
public void mouseWheelMoved(final MouseWheelEvent e) {
- int rotation = -1 * e.getWheelRotation();
+ int rotation = e.getWheelRotation();
if (count > NEWLEVEL) {
zoomLevel++;
upZoomlevel();
@@ -641,7 +645,7 @@ public void upZoomlevel() {
count = 0;
System.out.println("Zoom level up to = " + zoomLevel);
Event.statusBarInfo("Zoom level up to = " + zoomLevel);
- setZoomlevel(zoomLevel);
+ applyZoomLevel(zoomLevel);
}
/**
@@ -651,19 +655,7 @@ public void downZoomlevel() {
count = 0;
System.out.println("Zoom level down to = " + zoomLevel);
Event.statusBarInfo("Zoom level down to = " + zoomLevel);
- setZoomlevel(zoomLevel);
- }
-
- /**
- * Lets you go to a new zoom level.
- *
- * @param newZoomLevel
- * The new zoom level.
- */
- public void setZoomlevel(final int newZoomLevel) {
- count = 0;
- zoomLevel = newZoomLevel;
- applyZoomLevel(newZoomLevel);
+ applyZoomLevel(zoomLevel);
}
}
@@ -811,4 +803,12 @@ public void mouseClicked(final MouseEvent e) {
}
+ /**
+ * Get current zoomlevel.
+ *
+ * @return current zoomlevel.
+ */
+ public int getZoomLevel() {
+ return zoomLevel;
+ }
}
diff --git a/src/main/java/nl/tudelft/ti2806/pl1/gui/optionpane/ZoomConfigureGroup.java b/src/main/java/nl/tudelft/ti2806/pl1/gui/optionpane/ZoomConfigureGroup.java
index ef4cfe7..283e74b 100644
--- a/src/main/java/nl/tudelft/ti2806/pl1/gui/optionpane/ZoomConfigureGroup.java
+++ b/src/main/java/nl/tudelft/ti2806/pl1/gui/optionpane/ZoomConfigureGroup.java
@@ -6,6 +6,10 @@
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JSlider;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import nl.tudelft.ti2806.pl1.gui.Event;
/**
* @author Maarten
@@ -46,7 +50,16 @@ public ZoomConfigureGroup() {
*/
private void addComponents() {
for (int i = 0; i < NUM_SLIDERS; i++) {
- add(new JSlider());
+ JSlider slider = new JSlider(-10, 10);
+ slider.addChangeListener(new ChangeListener() {
+
+ @Override
+ public void stateChanged(final ChangeEvent e) {
+ Event.statusBarInfo("Slider to "
+ + ((JSlider) e.getSource()).getValue());
+ }
+ });
+ add(slider);
}
}
diff --git a/src/main/resources/usingDNApp.help b/src/main/resources/usingDNApp.help
new file mode 100644
index 0000000..e69de29