X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Ffunction%2Fedit%2FPointNameEditor.java;h=53e1f834b962fa8a098a9fc9345934dbdac3003f;hb=7f5ed2be62905bd37717376dc22d09e5ea7edb4d;hp=19edfbb80ba37c3f35ae291089a22079f0040693;hpb=54b9d8bc8f0025ccf97a67d9dd217ef1f9cf082f;p=GpsPrune.git diff --git a/tim/prune/function/edit/PointNameEditor.java b/tim/prune/function/edit/PointNameEditor.java index 19edfbb..53e1f83 100644 --- a/tim/prune/function/edit/PointNameEditor.java +++ b/tim/prune/function/edit/PointNameEditor.java @@ -8,26 +8,25 @@ import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JDialog; -import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import tim.prune.App; +import tim.prune.GenericFunction; import tim.prune.I18nManager; import tim.prune.data.DataPoint; import tim.prune.data.Field; /** - * Class to manage the display and editing of waypoint names + * Function to manage the display and editing of waypoint names */ -public class PointNameEditor +public class PointNameEditor extends GenericFunction { - private App _app = null; - private JFrame _parentFrame = null; private JDialog _dialog = null; private DataPoint _point = null; private JTextField _nameField = null; @@ -37,25 +36,26 @@ public class PointNameEditor /** * Constructor * @param inApp application object to inform of success - * @param inParentFrame parent frame */ - public PointNameEditor(App inApp, JFrame inParentFrame) + public PointNameEditor(App inApp) { - _app = inApp; - _parentFrame = inParentFrame; + super(inApp); } + /** Get the name key */ + public String getNameKey() { + return "function.editwaypointname"; + } /** - * Show the edit point name dialog - * @param inPoint point to edit + * Begin the function by showing the edit point name dialog */ - public void showDialog(DataPoint inPoint) + public void begin() { - _point = inPoint; + _point = _app.getTrackInfo().getCurrentPoint(); if (_dialog == null) { - _dialog = new JDialog(_parentFrame, I18nManager.getText("dialog.pointnameedit.title"), true); + _dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()), true); _dialog.setLocationRelativeTo(_parentFrame); // Create Gui and show it _dialog.getContentPane().add(makeDialogComponents()); @@ -78,7 +78,8 @@ public class PointNameEditor panel.setLayout(new BorderLayout()); // Create GUI layout for point name editor JPanel centrePanel = new JPanel(); - centrePanel.add(new JLabel(I18nManager.getText("dialog.pointnameedit.name") + ":")); + centrePanel.setLayout(new BorderLayout(8, 8)); + centrePanel.add(new JLabel(I18nManager.getText("dialog.pointnameedit.name") + ": "), BorderLayout.WEST); // Make listener to react to ok being pressed ActionListener okActionListener = new ActionListener() { public void actionPerformed(ActionEvent e) @@ -102,8 +103,13 @@ public class PointNameEditor } }); _nameField.addActionListener(okActionListener); - centrePanel.add(_nameField); - panel.add(centrePanel); + centrePanel.add(_nameField, BorderLayout.CENTER); + // holder panel to stop the text box from being stretched + JPanel holderPanel = new JPanel(); + holderPanel.setLayout(new BorderLayout()); + holderPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); + holderPanel.add(centrePanel, BorderLayout.NORTH); + panel.add(holderPanel, BorderLayout.CENTER); JPanel rightPanel = new JPanel(); rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS)); JButton upperButton = new JButton(I18nManager.getText("dialog.pointnameedit.uppercase")); @@ -126,16 +132,16 @@ public class PointNameEditor } }); rightPanel.add(lowerButton); - JButton sentenceButton = new JButton(I18nManager.getText("dialog.pointnameedit.sentencecase")); - sentenceButton.addActionListener(new ActionListener() { + JButton titleButton = new JButton(I18nManager.getText("dialog.pointnameedit.titlecase")); + titleButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - _nameField.setText(sentenceCase(_nameField.getText())); + _nameField.setText(titleCase(_nameField.getText())); _okButton.setEnabled(true); _nameField.requestFocus(); } }); - rightPanel.add(sentenceButton); + rightPanel.add(titleButton); panel.add(rightPanel, BorderLayout.EAST); // Bottom panel for OK, cancel buttons JPanel lowerPanel = new JPanel(); @@ -168,11 +174,11 @@ public class PointNameEditor } /** - * Turn a String into sentence case by capitalizing each word + * Turn a String into title case by capitalizing each word * @param inString String to convert * @return capitalized String */ - private static String sentenceCase(String inString) + private static String titleCase(String inString) { // Check first for empty strings if (inString == null || inString.equals(""))