From 4cd1597d7ba16b6326cf054de32b958d0e1c010d Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Tue, 25 Apr 2017 08:24:01 +0200 Subject: [PATCH] Added a menu bar, links to various information about the program, shrunk the middle buttons, moved the live checkbox to the menu bar and added some shortcuts. --- README.md | 2 - src/net/agspace/Main.java | 93 +++++++++++++++++++++++++++-- src/net/agspace/Window.form | 65 +++----------------- src/net/agspace/Window.java | 114 ++++++++++++++++++++---------------- src/resources/clear.png | Bin 396 -> 298 bytes src/resources/toEnglish.png | Bin 354 -> 414 bytes src/resources/toTengwar.png | Bin 353 -> 426 bytes 7 files changed, 162 insertions(+), 112 deletions(-) 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 ab30f2ccee5b7790a46e088b3ee695a3c5d212e1..78276094c5918ecf2d8efe4ce76df68cfeeaa851 100644 GIT binary patch delta 246 zcmVERLtq)mWWo`VfYt`L4FH&IcV>mUOI-$BM56SLn= zbW^Wq>{`Xj-cq=$sdAony!UVA>U&(G zUEcx&4sO23HnsCx&sMEY7=F1W67?)gOtmd;<%(IZ zoeRUYR;2|dy_njyDsqZM)zU?{q|*L7R(HQHvJKy?;cU>pbm6?!HznIY*jn)3Ry`ea zwo0aNrv~rWn6uyZ$P^dWl|=8`4)nmMUlJ=~`ukhD!0+xHPBJz&<^u8=7=WC3 zpqKv>gW1^Fuo{X5|7B)oz6kV{AJ8IJAfJIjUS3{6PEJmX7%U_t$=oRFntECmY~O4F7-@+~MNlN)Qwj^`J?7;>Y7yvRceU`6MDlz~7002ov JPDHLkV1l%Kj9CBx delta 302 zcmV+}0nz@R1L6W9iBL{Q4GJ0x0000DNk~Le0000q0000V2nGNE0H_o09+4p%3c&yX z4#5Gqk!$UdMkjv&-$_J4R9Hvt)IAD=Fc`*hhfG=0(M^va1hVQ8dX(P4-pnKQ2sSBw z3S!!PDCK=a9{7VNabdC!J8}-ty)3GXMYp07*qoM6N<$g2}FX A(EtDd diff --git a/src/resources/toTengwar.png b/src/resources/toTengwar.png index d6b72765a6b053b8185546588927d2bc6c8f9cf5..70f4f12396a2e2c44832b4e4ac8f2202abe030b5 100644 GIT binary patch delta 375 zcmV--0f_$L0;&TciBL{Q4GJ0x0000DNk~Le0000Q0000G2nGNE00_}R5(v#7_@+wm)8nN@j-Yr0DOFWrmU>2TY$`eK&${3q$c3! z=QjjeupY?#3&j7Sn0gio2ngu1v$L-RGJgXx%mV6J#KXg*3AA7lkogmc(Jg>s@+|^J zvML7$$81JM#&19_HpAgqNlB?iM@Ofa7_6_auMO10z+iuDY|I6;U=q-RPcVb1j1zzu zY!NHaH-5~_%ol-N`iP!9r#ii+}Zb909?F)>{Oa`9RyBqZb_ zCnu*x43?Ld7Xa$P1cHKs{9IgI2|x?)0J)$%gUvGPC2wE`72@RN%miBa2*^dZkop-` zLPA0m7|uT>Knq_0xiAZf6Z^TI3~mmw1nv1QUHCu00000NkvXXu0mjfqh4{p