Skip to content
Merged

Gui #49

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/main/java/nl/tudelft/ti2806/pl1/gui/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},

/**
*
*/
Expand All @@ -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);
}
};

/**
Expand Down Expand Up @@ -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

}

}
104 changes: 104 additions & 0 deletions src/main/java/nl/tudelft/ti2806/pl1/gui/HelpDialog.java
Original file line number Diff line number Diff line change
@@ -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("<html>");
System.out.println(sc);
while (sc.hasNextLine()) {
String line = sc.nextLine();
sb.append(line).append("<br>");
System.out.println("READ LINE = " + line);
}
sc.close();
sb.append("</html>");
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;
}
}
51 changes: 51 additions & 0 deletions src/main/java/nl/tudelft/ti2806/pl1/gui/LoadedMenuItem.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading