diff --git a/src/main/java/nl/andrewlalis/erme/control/actions/AboutAction.java b/src/main/java/nl/andrewlalis/erme/control/actions/AboutAction.java new file mode 100644 index 0000000..333023f --- /dev/null +++ b/src/main/java/nl/andrewlalis/erme/control/actions/AboutAction.java @@ -0,0 +1,36 @@ +package nl.andrewlalis.erme.control.actions; + +import nl.andrewlalis.erme.EntityRelationMappingEditor; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; + +public class AboutAction extends AbstractAction { + private static AboutAction instance; + + public static AboutAction getInstance() { + if (instance == null) instance = new AboutAction(); + return instance; + } + + public AboutAction() { + super("About"); + this.putValue(SHORT_DESCRIPTION, "Show some information about this program."); + } + + @Override + public void actionPerformed(ActionEvent e) { + JOptionPane.showMessageDialog( + (Component) e.getSource(), + "Entity-Relation Mapping Editor\n" + + "by Andrew Lalis\n" + + "Version " + EntityRelationMappingEditor.VERSION + "\n" + + "To report bugs or make suggestions, please visit the GitHub\n" + + "repository for this application and create a new issue.\n\n" + + "Thank you for using the ERME!", + "About ERME", + JOptionPane.INFORMATION_MESSAGE + ); + } +} diff --git a/src/main/java/nl/andrewlalis/erme/control/actions/InstructionsAction.java b/src/main/java/nl/andrewlalis/erme/control/actions/InstructionsAction.java new file mode 100644 index 0000000..1233cad --- /dev/null +++ b/src/main/java/nl/andrewlalis/erme/control/actions/InstructionsAction.java @@ -0,0 +1,83 @@ +package nl.andrewlalis.erme.control.actions; + +import javax.swing.*; +import javax.swing.event.HyperlinkEvent; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.io.*; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.Files; + +public class InstructionsAction extends AbstractAction { + private static InstructionsAction instance; + + public static InstructionsAction getInstance() { + if (instance == null) instance = new InstructionsAction(); + return instance; + } + + public InstructionsAction() { + super("Instructions"); + this.putValue(SHORT_DESCRIPTION, "Instructions for how to use this program."); + } + + @Override + public void actionPerformed(ActionEvent e) { + JDialog dialog = new JDialog(SwingUtilities.getWindowAncestor((Component) e.getSource()), "Instructions", Dialog.ModalityType.APPLICATION_MODAL); + JTextPane textPane = new JTextPane(); + textPane.setEditable(false); + textPane.setContentType("text/html"); + try { + textPane.setText(this.readFile()); + textPane.addHyperlinkListener(event -> { + if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + if (!Desktop.isDesktopSupported()) { + JOptionPane.showMessageDialog(dialog, "Desktop API not supported. You may still visit the link manually:\n" + event.getURL(), "Desktop API Not Supported", JOptionPane.WARNING_MESSAGE); + } else { + Desktop desktop = Desktop.getDesktop(); + try { + desktop.browse(event.getURL().toURI()); + } catch (IOException | URISyntaxException ex) { + ex.printStackTrace(); + JOptionPane.showMessageDialog(dialog, "An error occurred and the URL could not be opened:\n" + event.getURL(), "URL Could Not Open", JOptionPane.ERROR_MESSAGE); + } + } + } + }); + } catch (IOException ex) { + ex.printStackTrace(); + JOptionPane.showMessageDialog( + (Component) e.getSource(), + "An error occured:\n" + ex.getMessage(), + "Error", + JOptionPane.ERROR_MESSAGE + ); + textPane.setContentType("text/plain"); + textPane.setText("Unable to load content."); + } + JScrollPane scrollPane = new JScrollPane(textPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + dialog.setContentPane(scrollPane); + dialog.setMaximumSize(new Dimension(600, 800)); + dialog.setPreferredSize(new Dimension(600, 800)); + dialog.pack(); + dialog.setLocationRelativeTo(null); + dialog.setVisible(true); + } + + private String readFile() throws IOException { + InputStream is = getClass().getClassLoader().getResourceAsStream("html/instructions.html"); + if (is == null) { + throw new IOException("Could not get stream for instructions.html."); + } + StringBuilder sb = new StringBuilder(); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) { + String line = reader.readLine(); + while (line != null) { + sb.append(line).append('\n'); + line = reader.readLine(); + } + } + return sb.toString(); + } +} diff --git a/src/main/java/nl/andrewlalis/erme/view/EditorMenuBar.java b/src/main/java/nl/andrewlalis/erme/view/EditorMenuBar.java index 0d290a2..60df1d6 100644 --- a/src/main/java/nl/andrewlalis/erme/view/EditorMenuBar.java +++ b/src/main/java/nl/andrewlalis/erme/view/EditorMenuBar.java @@ -1,6 +1,5 @@ package nl.andrewlalis.erme.view; -import nl.andrewlalis.erme.EntityRelationMappingEditor; import nl.andrewlalis.erme.control.actions.*; import nl.andrewlalis.erme.control.actions.edits.AddAttributeAction; import nl.andrewlalis.erme.control.actions.edits.AddRelationAction; @@ -8,9 +7,6 @@ import nl.andrewlalis.erme.control.actions.edits.RemoveAttributeAction; import nl.andrewlalis.erme.control.actions.edits.RemoveRelationAction; import javax.swing.*; -import java.awt.*; -import java.io.IOException; -import java.net.URI; /** * The menu bar that's visible atop the application. @@ -48,28 +44,8 @@ public class EditorMenuBar extends JMenuBar { private JMenu buildHelpMenu() { JMenu menu = new JMenu("Help"); - JMenuItem instructionsItem = new JMenuItem("GitHub (Instructions)"); - instructionsItem.addActionListener(e -> { - try { - Desktop.getDesktop().browse(URI.create("https://github.com/andrewlalis/EntityRelationMappingEditor")); - } catch (IOException ioException) { - ioException.printStackTrace(); - } - }); - menu.add(instructionsItem); - JMenuItem aboutItem = new JMenuItem("About"); - aboutItem.addActionListener(e -> JOptionPane.showMessageDialog( - (Component) e.getSource(), - "Entity-Relation Mapping Editor\n" + - "by Andrew Lalis\n" + - "Version " + EntityRelationMappingEditor.VERSION + "\n" + - "To report bugs or make suggestions, please visit the GitHub\n" + - "repository for this application and create a new issue.\n\n" + - "Thank you for using the ERME!", - "About ERME", - JOptionPane.INFORMATION_MESSAGE - )); - menu.add(aboutItem); + menu.add(InstructionsAction.getInstance()); + menu.add(AboutAction.getInstance()); return menu; } } diff --git a/src/main/resources/html/instructions.html b/src/main/resources/html/instructions.html new file mode 100644 index 0000000..edb7a05 --- /dev/null +++ b/src/main/resources/html/instructions.html @@ -0,0 +1,56 @@ + + +
+ +Created by @andrewlalis
+ +A simple UI for editing entity-relation mapping diagrams.
+ ++ Have you noticed any unexpected behavior? Is there something you thing would make a good addition to this application? + Create a new issue on GitHub! +
+ ++ The interface and menus should be pretty self-explanatory, so they'll just be covered here in light detail. +
++ The main focus of the application is the Diagram Panel where all of the editing actually takes place. This is where any relations you create, or attributes you create, appear; this is what is rendered when you select the option to export your model to an image. +
+