diff options
author | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2019-02-20 20:57:06 -0500 |
---|---|---|
committer | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2019-02-20 20:57:06 -0500 |
commit | f21b9678ddc7bb6b59f0f076bb978a6993890548 (patch) | |
tree | da62e677e687b79b00167e2daff2edcf281d9331 | |
parent | a3dfff2c1a3a906fa2c3cb3f4cec1a150c5bf795 (diff) |
Created a GUI for a planned dimension-based converter.
The GUI does not do anything right now, but the idea is that the user
will select a dimension (length, mass, energy) and then select units
to convert from a searchable list.
-rwxr-xr-x | src/unitConverter/converterGUI/UnitConverterGUI.java | 124 |
1 files changed, 115 insertions, 9 deletions
diff --git a/src/unitConverter/converterGUI/UnitConverterGUI.java b/src/unitConverter/converterGUI/UnitConverterGUI.java index b54e0da..cf78ea8 100755 --- a/src/unitConverter/converterGUI/UnitConverterGUI.java +++ b/src/unitConverter/converterGUI/UnitConverterGUI.java @@ -21,6 +21,7 @@ import java.awt.GridLayout; import java.io.File; import java.math.BigDecimal; import java.math.MathContext; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -28,7 +29,10 @@ import java.util.function.Predicate; import javax.swing.BorderFactory; import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFormattedTextField; import javax.swing.JFrame; +import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -476,15 +480,117 @@ final class UnitConverterGUI { final JTabbedPane masterPane = new JTabbedPane(); masterPanel.add(masterPane, BorderLayout.CENTER); - { // panel for unit conversion - final JPanel convertPanel = new JPanel(); - masterPane.addTab("Convert Units", convertPanel); + { // a panel for unit conversion using a selector + final JPanel convertUnitPanel = new JPanel(); + masterPane.addTab("Convert Units", convertUnitPanel); - convertPanel.setLayout(new GridLayout(5, 1)); + convertUnitPanel.setLayout(new BorderLayout()); + + { // panel for input part + final JPanel inputPanel = new JPanel(); + convertUnitPanel.add(inputPanel, BorderLayout.CENTER); + + inputPanel.setLayout(new GridLayout(1, 3)); + + { // panel for From things + final JPanel fromPanel = new JPanel(); + inputPanel.add(fromPanel); + + fromPanel.setLayout(new BorderLayout()); + + { // search box for from + final JTextField fromSearch = new JTextField("Search..."); + fromPanel.add(fromSearch, BorderLayout.PAGE_START); + } + + { // list for From units + final JList<String> fromList = new JList<>(); + fromPanel.add(fromList, BorderLayout.CENTER); + } + } + + { // for dimension selector and arrow that represents conversion + final JPanel inBetweenPanel = new JPanel(); + inputPanel.add(inBetweenPanel); + + inBetweenPanel.setLayout(new BorderLayout()); + + { // dimension selector + final JComboBox<String> dimensionSelector = new JComboBox<>( + new String[] {"Select dimension..."}); + inBetweenPanel.add(dimensionSelector, BorderLayout.PAGE_START); + } + + { // the arrow in the middle + final JLabel arrowLabel = new JLabel("->"); + inBetweenPanel.add(arrowLabel, BorderLayout.CENTER); + } + } + + { // panel for To things + final JPanel toPanel = new JPanel(); + inputPanel.add(toPanel); + + toPanel.setLayout(new BorderLayout()); + + { // search box for to + final JTextField toSearch = new JTextField("Search..."); + toPanel.add(toSearch, BorderLayout.PAGE_START); + } + + { // list for To units + final JList<String> toList = new JList<>(); + toPanel.add(toList, BorderLayout.CENTER); + } + } + + } + + { // panel for submit and output, and also value entry + final JPanel outputPanel = new JPanel(); + convertUnitPanel.add(outputPanel, BorderLayout.PAGE_END); + + outputPanel.setLayout(new GridLayout(3, 1)); + + { // unit input + final JPanel valueInputPanel = new JPanel(); + outputPanel.add(valueInputPanel); + + valueInputPanel.setLayout(new BorderLayout()); + + { // prompt + final JLabel valuePrompt = new JLabel("Value to convert: "); + valueInputPanel.add(valuePrompt, BorderLayout.LINE_START); + } + + { // value to convert + final JTextField valueInput = new JFormattedTextField( + new DecimalFormat("###############0.################")); + valueInputPanel.add(valueInput, BorderLayout.CENTER); + } + } + + { // button to convert + final JButton convertButton = new JButton("Convert"); + outputPanel.add(convertButton); + } + + { // output of conversion + final JLabel outputLabel = new JLabel(); + outputPanel.add(outputLabel); + } + } + } + + { // panel for unit conversion using expressions + final JPanel convertExpressionPanel = new JPanel(); + masterPane.addTab("Convert Unit Expressions", convertExpressionPanel); + + convertExpressionPanel.setLayout(new GridLayout(5, 1)); { // panel for units to convert from final JPanel fromPanel = new JPanel(); - convertPanel.add(fromPanel); + convertExpressionPanel.add(fromPanel); fromPanel.setBorder(BorderFactory.createTitledBorder("From")); fromPanel.setLayout(new GridLayout(1, 1)); @@ -496,7 +602,7 @@ final class UnitConverterGUI { { // panel for units to convert to final JPanel toPanel = new JPanel(); - convertPanel.add(toPanel); + convertExpressionPanel.add(toPanel); toPanel.setBorder(BorderFactory.createTitledBorder("To")); toPanel.setLayout(new GridLayout(1, 1)); @@ -508,14 +614,14 @@ final class UnitConverterGUI { { // button to convert final JButton convertButton = new JButton("Convert!"); - convertPanel.add(convertButton); + convertExpressionPanel.add(convertButton); convertButton.addActionListener(e -> this.presenter.convert()); } { // output of conversion final JPanel outputPanel = new JPanel(); - convertPanel.add(outputPanel); + convertExpressionPanel.add(outputPanel); outputPanel.setBorder(BorderFactory.createTitledBorder("Output")); outputPanel.setLayout(new GridLayout(1, 1)); @@ -528,7 +634,7 @@ final class UnitConverterGUI { { // panel for specifying precision final JPanel sigDigPanel = new JPanel(); - convertPanel.add(sigDigPanel); + convertExpressionPanel.add(sigDigPanel); sigDigPanel.setBorder(BorderFactory.createTitledBorder("Significant Digits")); |