|
| 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 | +} |
0 commit comments