diff --git a/README.md b/README.md index b7454e4..1b01721 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,6 @@ Since Tengwar is inherently a phonetic script, converting english to Tengwar wou ### To-Do List -* R placed after vowel must be checked to determine if it should be a vowel or consonant R. -* Implement scanning for double-consonants and use of double-bar. * Implement s-curls. * Find a way to display the PDF manual in the UI. diff --git a/src/net/agspace/Main.java b/src/net/agspace/Main.java index 11f874a..f5c5f13 100644 --- a/src/net/agspace/Main.java +++ b/src/net/agspace/Main.java @@ -1,10 +1,13 @@ package net.agspace; -import sun.font.TrueTypeFont; -import sun.plugin.dom.exception.InvalidStateException; - import javax.swing.*; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import java.io.IOException; /** * @author Andrew Lalis @@ -17,8 +20,90 @@ public class Main { public static void main(String[] args){ JFrame f = new JFrame(TITLE); + Window window = new Window(); + //Set application icon. f.setIconImage(Toolkit.getDefaultToolkit().createImage(ClassLoader.getSystemResource(ICON_PATH))); - f.setContentPane(new Window().getMainPanel()); + //Set the main panel as the content pane. + f.setContentPane(window.getMainPanel()); + //Create a menu bar. + JMenuBar menuBar = new JMenuBar(); + //File Menu. + JMenu fileMenu = new JMenu("File"); + //Save Item. + JMenuItem saveItem = new JMenuItem("Save"); + saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); + saveItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + window.onSaveClicked(); + } + }); + fileMenu.add(saveItem); + //Import Item. + JMenuItem importItem = new JMenuItem("Import"); + importItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + window.onImportClicked(); + } + }); + fileMenu.add(importItem); + //Exit Item. + JMenuItem exitItem = new JMenuItem("Exit"); + exitItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + f.dispose(); + } + }); + fileMenu.add(exitItem); + menuBar.add(fileMenu); + //Edit menu. + JMenu editMenu = new JMenu("Edit"); + //Live checkbox + JCheckBoxMenuItem liveCheckBox = new JCheckBoxMenuItem("Live"); + liveCheckBox.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.CTRL_MASK)); + liveCheckBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + window.onLiveToggled(e); + } + }); + editMenu.add(liveCheckBox); + menuBar.add(editMenu); + //About Menu. + JMenu aboutMenu = new JMenu("About"); + //Tengwar Item. + JMenuItem tengwarItem = new JMenuItem("Tengwar"); + tengwarItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + window.onTengwarAboutClicked(); + } + }); + aboutMenu.add(tengwarItem); + //English Mode. + JMenuItem englishModeItem = new JMenuItem("English Mode"); + englishModeItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + window.onEnglishModeAboutClicked(); + } + }); + aboutMenu.add(englishModeItem); + //About the author. + JMenuItem aboutMeItem = new JMenuItem("About the Author"); + aboutMeItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + window.onAboutMeClicked(); + } + }); + aboutMenu.add(aboutMeItem); + menuBar.add(aboutMenu); + + + f.setJMenuBar(menuBar); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try { diff --git a/src/net/agspace/Window.form b/src/net/agspace/Window.form index 7054076..1cf4680 100644 --- a/src/net/agspace/Window.form +++ b/src/net/agspace/Window.form @@ -6,7 +6,7 @@ - + @@ -18,7 +18,7 @@ - + @@ -30,32 +30,13 @@ - + - - - - - - - - - - - - - - - - - - - @@ -88,7 +69,7 @@ - + @@ -106,25 +87,6 @@ - - - - - - - - - - - - - - - - - - - @@ -146,7 +108,7 @@ - + @@ -156,7 +118,7 @@ - + @@ -167,7 +129,7 @@ - + @@ -176,20 +138,9 @@ - - - - - - - - - + diff --git a/src/net/agspace/Window.java b/src/net/agspace/Window.java index 9037f19..ae458b0 100644 --- a/src/net/agspace/Window.java +++ b/src/net/agspace/Window.java @@ -15,12 +15,9 @@ import java.nio.file.Files; import java.util.List; import java.util.ArrayList; -/** - * Created by Andrew's Computer on 22-Apr-17. - */ public class Window { - public static final List OPEN_FILE_EXTENSIONS = new ArrayList(); + public static final List OPEN_FILE_EXTENSIONS = new ArrayList<>(); static { OPEN_FILE_EXTENSIONS.add("txt"); @@ -28,20 +25,17 @@ public class Window { private JPanel mainPanel; private JPanel tengwarPanel; - private JPanel inputPanel; - private JLabel inputPanelLabel; - private JPanel inputPanelTop; - private JTextArea inputTextArea; private JPanel tengwarPanelTop; - private JTextArea tengwarTextArea; private JLabel tengwarPanelLabel; + private JTextArea tengwarTextArea; + private JPanel inputPanel; + private JPanel inputPanelTop; + private JLabel inputPanelLabel; + private JTextArea inputTextArea; + private JPanel translateButtonPanel; private JButton toTengwarButton; private JButton toEnglishButton; - private JPanel translateButtonPanel; - private JCheckBox liveCheckBox; private JButton clearButton; - private JButton importButton; - private JButton saveButton; private boolean isLive = false; @@ -65,23 +59,6 @@ public class Window { tengwarTextArea.setText(Translator.translateToTengwar(inputTextArea.getText())); } }); - //Toggle live translation, and activation/deactivation of other buttons. - liveCheckBox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (liveCheckBox.isSelected()){ - //Deactivate buttons, set live to true. - toTengwarButton.setEnabled(false); - toEnglishButton.setEnabled(false); - isLive = true; - } else { - //Activate buttons, set live to false. - toTengwarButton.setEnabled(true); - toEnglishButton.setEnabled(true); - isLive = false; - } - } - }); //Clear both text areas. clearButton.addActionListener(new ActionListener() { @Override @@ -90,20 +67,6 @@ public class Window { inputTextArea.setText(null); } }); - //Import text from a file. - importButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - onImportClicked(); - } - }); - //Save text to a file. - saveButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - onSaveClicked(); - } - }); //Translate tengwar to english. toEnglishButton.addActionListener(new ActionListener() { @Override @@ -134,11 +97,8 @@ public class Window { this.tengwarTextArea = new JTextArea(); this.toTengwarButton = new JButton(); this.toEnglishButton = new JButton(); - this.liveCheckBox = new JCheckBox(); this.clearButton = new JButton(); - this.importButton = new JButton(); this.inputTextArea.requestFocus(); - this.saveButton = new JButton(); } public JPanel getMainPanel(){ @@ -150,10 +110,28 @@ public class Window { tengwarTextArea.setText(Translator.translateToTengwar(inputTextArea.getText())); } + /** + * Toggle the live button and disable translate buttons if needed. + * @param e event generated by the check box. + */ + public void onLiveToggled(ActionEvent e){ + if (((JCheckBoxMenuItem) e.getSource()).getState()){ + //Deactivate buttons, set live to true. + toTengwarButton.setEnabled(false); + toEnglishButton.setEnabled(false); + isLive = true; + } else { + //Activate buttons, set live to false. + toTengwarButton.setEnabled(true); + toEnglishButton.setEnabled(true); + isLive = false; + } + } + /** * What to do if the user clicks the 'import' button. */ - private void onImportClicked(){ + public void onImportClicked(){ JFileChooser fileChooser = new JFileChooser(System.getProperty("user.documents")); fileChooser.setFileFilter(new FileFilter() { @Override @@ -193,7 +171,7 @@ public class Window { /** * What to do when the user wants to save their document. */ - private void onSaveClicked(){ + public void onSaveClicked(){ JFileChooser fileChooser = new JFileChooser(System.getProperty("user.documents")); int result = fileChooser.showSaveDialog(this.mainPanel); if (result == JFileChooser.APPROVE_OPTION){ @@ -205,4 +183,42 @@ public class Window { } } + /** + * Attempt to open the pdf in the browser. + */ + public void onEnglishModeAboutClicked(){ + if (Desktop.isDesktopSupported()){ + try { + Desktop.getDesktop().open(new File(this.getClass().getClassLoader().getResource("resources/EnglishOnetoOneTengwarV2-1.pdf").getFile())); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + } + + /** + * Attempt to open Tengwar wikipedia page. + */ + public void onTengwarAboutClicked(){ + if (Desktop.isDesktopSupported()){ + try{ + Desktop.getDesktop().browse(new URI("https://en.wikipedia.org/wiki/Tengwar")); + } catch (URISyntaxException | IOException e){ + e.printStackTrace(); + } + } + } + + /** + * Attempt to open my github page. + */ + public void onAboutMeClicked(){ + if (Desktop.isDesktopSupported()){ + try{ + Desktop.getDesktop().browse(new URI("https://github.com/andrewlalis")); + } catch (URISyntaxException | IOException e){ + e.printStackTrace(); + } + } + } } diff --git a/src/resources/clear.png b/src/resources/clear.png index ab30f2c..7827609 100644 Binary files a/src/resources/clear.png and b/src/resources/clear.png differ diff --git a/src/resources/toEnglish.png b/src/resources/toEnglish.png index 6ab6501..b6984a3 100644 Binary files a/src/resources/toEnglish.png and b/src/resources/toEnglish.png differ diff --git a/src/resources/toTengwar.png b/src/resources/toTengwar.png index d6b7276..70f4f12 100644 Binary files a/src/resources/toTengwar.png and b/src/resources/toTengwar.png differ