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.

This commit is contained in:
Andrew Lalis 2017-04-25 08:24:01 +02:00
parent 613abdb7ca
commit 4cd1597d7b
7 changed files with 162 additions and 112 deletions

View File

@ -17,8 +17,6 @@ Since Tengwar is inherently a phonetic script, converting english to Tengwar wou
### To-Do List ### 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. * Implement s-curls.
* Find a way to display the PDF manual in the UI. * Find a way to display the PDF manual in the UI.

View File

@ -1,10 +1,13 @@
package net.agspace; package net.agspace;
import sun.font.TrueTypeFont;
import sun.plugin.dom.exception.InvalidStateException;
import javax.swing.*; import javax.swing.*;
import java.awt.*; 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 * @author Andrew Lalis
@ -17,8 +20,90 @@ public class Main {
public static void main(String[] args){ public static void main(String[] args){
JFrame f = new JFrame(TITLE); JFrame f = new JFrame(TITLE);
Window window = new Window();
//Set application icon.
f.setIconImage(Toolkit.getDefaultToolkit().createImage(ClassLoader.getSystemResource(ICON_PATH))); 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.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try { try {

View File

@ -6,7 +6,7 @@
<xy x="20" y="20" width="786" height="461"/> <xy x="20" y="20" width="786" height="461"/>
</constraints> </constraints>
<properties> <properties>
<preferredSize width="640" height="480"/> <preferredSize width="720" height="480"/>
</properties> </properties>
<border type="none"/> <border type="none"/>
<children> <children>
@ -18,7 +18,7 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<grid id="9f3fe" binding="tengwarPanelTop" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="9f3fe" binding="tengwarPanelTop" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
@ -30,32 +30,13 @@
<children> <children>
<component id="3d5ee" class="javax.swing.JLabel" binding="tengwarPanelLabel"> <component id="3d5ee" class="javax.swing.JLabel" binding="tengwarPanelLabel">
<constraints> <constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="0" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<font name="Tengwar Annatar" size="18" style="0"/> <font name="Tengwar Annatar" size="18" style="0"/>
<text value="1b$y6D"/> <text value="1b$y6D"/>
</properties> </properties>
</component> </component>
<grid id="f21a7" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="48468" class="javax.swing.JButton" binding="saveButton" custom-create="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Save"/>
<toolTipText value="Saves the tengwar text to a file."/>
</properties>
</component>
</children>
</grid>
</children> </children>
</grid> </grid>
<scrollpane id="ad3c8"> <scrollpane id="ad3c8">
@ -88,7 +69,7 @@
</properties> </properties>
<border type="none"/> <border type="none"/>
<children> <children>
<grid id="f5158" binding="inputPanelTop" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="f5158" binding="inputPanelTop" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
@ -106,25 +87,6 @@
<text value="English"/> <text value="English"/>
</properties> </properties>
</component> </component>
<grid id="a3b48" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="4" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="1682d" class="javax.swing.JButton" binding="importButton" custom-create="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Import"/>
<toolTipText value="Import text from a file to be translated."/>
</properties>
</component>
</children>
</grid>
</children> </children>
</grid> </grid>
<scrollpane id="36b2e"> <scrollpane id="36b2e">
@ -146,7 +108,7 @@
</scrollpane> </scrollpane>
</children> </children>
</grid> </grid>
<grid id="5da94" binding="translateButtonPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="5da94" binding="translateButtonPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="30" left="0" bottom="0" right="0"/> <margin top="30" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="1" anchor="1" fill="1" indent="0" use-parent-layout="false"/> <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="1" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
@ -156,7 +118,7 @@
<children> <children>
<component id="8f5c7" class="javax.swing.JButton" binding="toTengwarButton" custom-create="true"> <component id="8f5c7" class="javax.swing.JButton" binding="toTengwarButton" custom-create="true">
<constraints> <constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="2" fill="1" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="2" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<icon value="resources/toTengwar.png"/> <icon value="resources/toTengwar.png"/>
@ -167,7 +129,7 @@
</component> </component>
<component id="1097" class="javax.swing.JButton" binding="toEnglishButton" custom-create="true"> <component id="1097" class="javax.swing.JButton" binding="toEnglishButton" custom-create="true">
<constraints> <constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="1" fill="1" indent="0" use-parent-layout="false"/> <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<icon value="resources/toEnglish.png"/> <icon value="resources/toEnglish.png"/>
@ -176,20 +138,9 @@
<toolTipText value="Translate to english"/> <toolTipText value="Translate to english"/>
</properties> </properties>
</component> </component>
<component id="1ba7d" class="javax.swing.JCheckBox" binding="liveCheckBox" custom-create="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<hideActionText value="false"/>
<label value="Live"/>
<text value="Live"/>
<toolTipText value="Enable translate-as-you-type"/>
</properties>
</component>
<component id="59b28" class="javax.swing.JButton" binding="clearButton" custom-create="true"> <component id="59b28" class="javax.swing.JButton" binding="clearButton" custom-create="true">
<constraints> <constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<icon value="resources/clear.png"/> <icon value="resources/clear.png"/>

View File

@ -15,12 +15,9 @@ import java.nio.file.Files;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
/**
* Created by Andrew's Computer on 22-Apr-17.
*/
public class Window { public class Window {
public static final List<String> OPEN_FILE_EXTENSIONS = new ArrayList<String>(); public static final List<String> OPEN_FILE_EXTENSIONS = new ArrayList<>();
static { static {
OPEN_FILE_EXTENSIONS.add("txt"); OPEN_FILE_EXTENSIONS.add("txt");
@ -28,20 +25,17 @@ public class Window {
private JPanel mainPanel; private JPanel mainPanel;
private JPanel tengwarPanel; private JPanel tengwarPanel;
private JPanel inputPanel;
private JLabel inputPanelLabel;
private JPanel inputPanelTop;
private JTextArea inputTextArea;
private JPanel tengwarPanelTop; private JPanel tengwarPanelTop;
private JTextArea tengwarTextArea;
private JLabel tengwarPanelLabel; 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 toTengwarButton;
private JButton toEnglishButton; private JButton toEnglishButton;
private JPanel translateButtonPanel;
private JCheckBox liveCheckBox;
private JButton clearButton; private JButton clearButton;
private JButton importButton;
private JButton saveButton;
private boolean isLive = false; private boolean isLive = false;
@ -65,23 +59,6 @@ public class Window {
tengwarTextArea.setText(Translator.translateToTengwar(inputTextArea.getText())); 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. //Clear both text areas.
clearButton.addActionListener(new ActionListener() { clearButton.addActionListener(new ActionListener() {
@Override @Override
@ -90,20 +67,6 @@ public class Window {
inputTextArea.setText(null); 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. //Translate tengwar to english.
toEnglishButton.addActionListener(new ActionListener() { toEnglishButton.addActionListener(new ActionListener() {
@Override @Override
@ -134,11 +97,8 @@ public class Window {
this.tengwarTextArea = new JTextArea(); this.tengwarTextArea = new JTextArea();
this.toTengwarButton = new JButton(); this.toTengwarButton = new JButton();
this.toEnglishButton = new JButton(); this.toEnglishButton = new JButton();
this.liveCheckBox = new JCheckBox();
this.clearButton = new JButton(); this.clearButton = new JButton();
this.importButton = new JButton();
this.inputTextArea.requestFocus(); this.inputTextArea.requestFocus();
this.saveButton = new JButton();
} }
public JPanel getMainPanel(){ public JPanel getMainPanel(){
@ -150,10 +110,28 @@ public class Window {
tengwarTextArea.setText(Translator.translateToTengwar(inputTextArea.getText())); 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. * What to do if the user clicks the 'import' button.
*/ */
private void onImportClicked(){ public void onImportClicked(){
JFileChooser fileChooser = new JFileChooser(System.getProperty("user.documents")); JFileChooser fileChooser = new JFileChooser(System.getProperty("user.documents"));
fileChooser.setFileFilter(new FileFilter() { fileChooser.setFileFilter(new FileFilter() {
@Override @Override
@ -193,7 +171,7 @@ public class Window {
/** /**
* What to do when the user wants to save their document. * 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")); JFileChooser fileChooser = new JFileChooser(System.getProperty("user.documents"));
int result = fileChooser.showSaveDialog(this.mainPanel); int result = fileChooser.showSaveDialog(this.mainPanel);
if (result == JFileChooser.APPROVE_OPTION){ 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();
}
}
}
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 396 B

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 354 B

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 353 B

After

Width:  |  Height:  |  Size: 426 B