summaryrefslogtreecommitdiff
path: root/src/unitConverter/converterGUI/UnitConverterGUI.java
diff options
context:
space:
mode:
authorAdrien Hopkins <adrien.p.hopkins@gmail.com>2019-02-01 09:13:39 -0500
committerAdrien Hopkins <adrien.p.hopkins@gmail.com>2019-02-01 09:13:39 -0500
commita3dfff2c1a3a906fa2c3cb3f4cec1a150c5bf795 (patch)
treeb45241f4c56a055148f4a15a47d2d6ff04fd382a /src/unitConverter/converterGUI/UnitConverterGUI.java
parent8ff06e8e5661645c00656c40d15c8d13db665b57 (diff)
parenta6a66e6fb11675e0ea738ad8d0b5a9ba7d2fac2b (diff)
Merge v0.1.0 into develop
Diffstat (limited to 'src/unitConverter/converterGUI/UnitConverterGUI.java')
-rwxr-xr-xsrc/unitConverter/converterGUI/UnitConverterGUI.java95
1 files changed, 90 insertions, 5 deletions
diff --git a/src/unitConverter/converterGUI/UnitConverterGUI.java b/src/unitConverter/converterGUI/UnitConverterGUI.java
index 0068312..b54e0da 100755
--- a/src/unitConverter/converterGUI/UnitConverterGUI.java
+++ b/src/unitConverter/converterGUI/UnitConverterGUI.java
@@ -52,6 +52,7 @@ import unitConverter.unit.UnitPrefix;
/**
* @author Adrien Hopkins
* @since 2018-12-27
+ * @since v0.1.0
*/
final class UnitConverterGUI {
private static class Presenter {
@@ -83,6 +84,7 @@ final class UnitConverterGUI {
* @param view
* presenter's associated view
* @since 2018-12-27
+ * @since v0.1.0
*/
Presenter(final View view) {
this.view = view;
@@ -141,6 +143,17 @@ final class UnitConverterGUI {
AbstractUnit.getBaseUnitCount());
}
+ /**
+ * Runs whenever the convert button is pressed.
+ *
+ * <p>
+ * Reads and parses a unit expression from the from and to boxes, then converts {@code from} to {@code to}. Any
+ * errors are shown in JOptionPanes.
+ * </p>
+ *
+ * @since 2019-01-26
+ * @since v0.1.0
+ */
public final void convert() {
final String fromUnitString = this.view.getFromText();
final String toUnitString = this.view.getToText();
@@ -196,6 +209,7 @@ final class UnitConverterGUI {
* @param filter
* filter to use
* @since 2019-01-15
+ * @since v0.1.0
*/
private final void filterFilteredPrefixModel(final Predicate<String> filter) {
this.prefixNamesFiltered.clear();
@@ -212,6 +226,7 @@ final class UnitConverterGUI {
* @param filter
* filter to use
* @since 2019-01-15
+ * @since v0.1.0
*/
private final void filterFilteredUnitModel(final Predicate<String> filter) {
this.unitNamesFiltered.clear();
@@ -225,11 +240,21 @@ final class UnitConverterGUI {
/**
* @return a list model of all of the unit keys
* @since 2019-01-14
+ * @since v0.1.0
*/
public final ListModel<String> keyListModel() {
return this.unitNamesFiltered;
}
+ /**
+ * Runs whenever the prefix filter is changed.
+ * <p>
+ * Filters the prefix list then sorts it using a {@code FilterComparator}.
+ * </p>
+ *
+ * @since 2019-01-15
+ * @since v0.1.0
+ */
public final void prefixFilterUpdated() {
final String filter = this.view.getPrefixFilterText();
if (filter.equals("")) {
@@ -241,13 +266,22 @@ final class UnitConverterGUI {
}
/**
- * @return a list model of all fo the prefix names
+ * @return a list model of all of the prefix names
* @since 2019-01-15
*/
public final ListModel<String> prefixNameListModel() {
return this.prefixNamesFiltered;
}
+ /**
+ * Runs whenever a prefix is selected in the viewer.
+ * <p>
+ * Shows its information in the text box to the right.
+ * </p>
+ *
+ * @since 2019-01-15
+ * @since v0.1.0
+ */
public final void prefixSelected() {
final int index = this.view.getPrefixListSelection();
if (index == -1)
@@ -269,6 +303,15 @@ final class UnitConverterGUI {
this.significantFigures = significantFigures;
}
+ /**
+ * Runs whenever the unit filter is changed.
+ * <p>
+ * Filters the unit list then sorts it using a {@code FilterComparator}.
+ * </p>
+ *
+ * @since 2019-01-15
+ * @since v0.1.0
+ */
public final void unitFilterUpdated() {
final String filter = this.view.getUnitFilterText();
if (filter.equals("")) {
@@ -280,8 +323,13 @@ final class UnitConverterGUI {
}
/**
+ * Runs whenever a unit is selected in the viewer.
+ * <p>
+ * Shows its information in the text box to the right.
+ * </p>
*
* @since 2019-01-15
+ * @since v0.1.0
*/
public void unitNameSelected() {
final int index = this.view.getUnitListSelection();
@@ -302,26 +350,37 @@ final class UnitConverterGUI {
/** The view's associated presenter. */
private final Presenter presenter;
+ /** The list of unit names in the unit viewer */
private final JList<String> unitNameList;
+ /** The list of prefix names in the prefix viewer */
private final JList<String> prefixNameList;
+ /** The unit search box in the unit viewer */
private final JTextField unitFilterEntry;
+ /** The text box for unit data in the unit viewer */
private final JTextArea unitTextBox;
+ /** The prefix search box in the prefix viewer */
private final JTextField prefixFilterEntry;
+ /** The text box for prefix data in the prefix viewer */
private final JTextArea prefixTextBox;
+ /** The "From" entry in the conversion panel */
private final JTextField fromEntry;
+ /** The "To" entry in the conversion panel */
private final JTextField toEntry;
+ /** The output area in the conversion panel */
private final JTextArea output;
/**
* Creates the {@code View}.
*
* @since 2019-01-14
+ * @since v0.1.0
*/
public View() {
this.presenter = new Presenter(this);
this.frame = new JFrame("Unit Converter");
this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ // create the components
this.unitNameList = new JList<>(this.presenter.keyListModel());
this.prefixNameList = new JList<>(this.presenter.prefixNameListModel());
this.unitFilterEntry = new JTextField();
@@ -332,11 +391,17 @@ final class UnitConverterGUI {
this.toEntry = new JTextField();
this.output = new JTextArea(2, 32);
+ // create more components
this.initComponents();
this.frame.pack();
}
+ /**
+ * @return text in "From" box in converter panel
+ * @since 2019-01-15
+ * @since v0.1.0
+ */
public String getFromText() {
return this.fromEntry.getText();
}
@@ -344,6 +409,7 @@ final class UnitConverterGUI {
/**
* @return text in prefix filter
* @since 2019-01-15
+ * @since v0.1.0
*/
public String getPrefixFilterText() {
return this.prefixFilterEntry.getText();
@@ -352,11 +418,17 @@ final class UnitConverterGUI {
/**
* @return index of selected prefix
* @since 2019-01-15
+ * @since v0.1.0
*/
public int getPrefixListSelection() {
return this.prefixNameList.getSelectedIndex();
}
+ /**
+ * @return text in "To" box in converter panel
+ * @since 2019-01-26
+ * @since v0.1.0
+ */
public String getToText() {
return this.toEntry.getText();
}
@@ -372,6 +444,7 @@ final class UnitConverterGUI {
/**
* @return index of selected unit
* @since 2019-01-15
+ * @since v0.1.0
*/
public int getUnitListSelection() {
return this.unitNameList.getSelectedIndex();
@@ -381,6 +454,7 @@ final class UnitConverterGUI {
* Starts up the application.
*
* @since 2018-12-27
+ * @since v0.1.0
*/
public final void init() {
this.frame.setVisible(true);
@@ -390,6 +464,7 @@ final class UnitConverterGUI {
* Initializes the view's components.
*
* @since 2018-12-27
+ * @since v0.1.0
*/
private final void initComponents() {
final JPanel masterPanel = new JPanel();
@@ -451,7 +526,7 @@ final class UnitConverterGUI {
}
}
- {
+ { // panel for specifying precision
final JPanel sigDigPanel = new JPanel();
convertPanel.add(sigDigPanel);
@@ -485,7 +560,7 @@ final class UnitConverterGUI {
listPanel.setLayout(new BorderLayout());
- {
+ { // unit search box
listPanel.add(this.unitFilterEntry, BorderLayout.PAGE_START);
this.unitFilterEntry.addCaretListener(e -> this.presenter.unitFilterUpdated());
}
@@ -512,13 +587,13 @@ final class UnitConverterGUI {
prefixLookupPanel.setLayout(new GridLayout(1, 2));
- {
+ { // panel for listing and seaching
final JPanel prefixListPanel = new JPanel();
prefixLookupPanel.add(prefixListPanel);
prefixListPanel.setLayout(new BorderLayout());
- {
+ { // prefix search box
prefixListPanel.add(this.prefixFilterEntry, BorderLayout.PAGE_START);
this.prefixFilterEntry.addCaretListener(e -> this.presenter.prefixFilterUpdated());
}
@@ -540,6 +615,14 @@ final class UnitConverterGUI {
}
}
+ /**
+ * Sets the text in the output of the conversion panel.
+ *
+ * @param text
+ * text to set
+ * @since 2019-01-15
+ * @since v0.1.0
+ */
public void setOutputText(final String text) {
this.output.setText(text);
}
@@ -550,6 +633,7 @@ final class UnitConverterGUI {
* @param text
* text to set
* @since 2019-01-15
+ * @since v0.1.0
*/
public void setPrefixTextBoxText(final String text) {
this.prefixTextBox.setText(text);
@@ -574,6 +658,7 @@ final class UnitConverterGUI {
* @param message
* message in dialog
* @since 2019-01-14
+ * @since v0.1.0
*/
public void showErrorDialog(final String title, final String message) {
JOptionPane.showMessageDialog(this.frame, message, title, JOptionPane.ERROR_MESSAGE);