nsew;
boolean isLatitude;
-// boolean decimalMinutes = true;
-
+ // boolean decimalMinutes = true;
+
/**
* HBox to hold decimal minutes, degrees, seconds controls.
*/
private PamHBox degHBox;
-
+
/**
* HBox to hold decimal controls
*/
private PamHBox decHBox;
-
+
+ /**
+ * The format type e.g. LatLong.FORMAT_DECIMALMINUTES.
+ */
+ private int formatType = LatLong.FORMAT_DECIMALMINUTES;
+ private Label titleLabel;
+
/**
* Construct a strip of controls to include in a larger dialog.
@@ -48,7 +54,7 @@ public class LatLongStrip extends PamBorderPane {
isLatitude = latitude;
createDialogStrip(showBorder);
}
-
+
/**
* Construct a strip of controls to include in a larger dialog.
* By default the strip will have a titled border with the
@@ -59,27 +65,33 @@ public class LatLongStrip extends PamBorderPane {
isLatitude = latitude;
createDialogStrip(true);
}
-
+
private void createDialogStrip(boolean showBorder) {
-
- String borderTitle;
- if (isLatitude) borderTitle = "Latitude";
- else borderTitle = "Longitude";
-
- Label title= new Label(borderTitle);
- PamGuiManagerFX.titleFont2style(title);
-// title.setFont(PamGuiManagerFX.titleFontSize2);
+
+ String title;
+ if (isLatitude) title = "Latitude";
+ else title = "Longitude";
+
+ // title.setFont(PamGuiManagerFX.titleFontSize2);
degrees = new TextField();
+ degrees.setEditable(true);
degrees.setPrefColumnCount(4);
minutes = new TextField();
minutes.setPrefColumnCount(3);
+ minutes.setEditable(true);
seconds = new TextField();
seconds.setPrefColumnCount(6);
+ seconds.setEditable(true);
decminutes = new TextField();
decminutes.setPrefColumnCount(6);
-
+ decminutes.setEditable(true);
+
+ decimal=new TextField();
+ decimal.setPrefColumnCount(9);
+ decimal.setEditable(true);
+
nsew = new ComboBox();
nsew.setOnAction((action)->{
double v = getValue();
@@ -91,6 +103,8 @@ public class LatLongStrip extends PamBorderPane {
ml = new Label("min.");
sl = new Label("sec.");
dml = new Label("dec min.");
+ dec = new Label("decimal deg.");
+
formattedText = new Label("Position");
if (isLatitude) {
nsew.getItems().add("N");
@@ -100,123 +114,192 @@ public class LatLongStrip extends PamBorderPane {
nsew.getItems().add("E");
nsew.getItems().add("W");
}
-
+
degrees.setOnKeyPressed((key)->{
newTypedValues(key);
});
-
+
minutes.setOnKeyPressed((key)->{
newTypedValues(key);
});
-
+
seconds.setOnKeyPressed((key)->{
newTypedValues(key);
});
-
+
decminutes.setOnKeyPressed((key)->{
newTypedValues(key);
});
-
+
+ decimal.setOnKeyPressed((key)->{
+ newTypedValues(key);
+ });
+
nsew.setOnKeyPressed((key)->{
newTypedValues(key);
});
-
+
degHBox = new PamHBox();
degHBox.setSpacing(5);
degHBox.setAlignment(Pos.CENTER_LEFT);
-
- this.setRight(nsew);
- this.setCenter(degHBox);
+
+ PamHBox holder= new PamHBox();
+ holder.setAlignment(Pos.CENTER_LEFT);
+ holder.setSpacing(5);
+ holder.getChildren().addAll(titleLabel = new Label(title), degHBox, nsew);
+
+ this.setCenter(holder);
this.setBottom(formattedText);
- showControls( LatLong.FORMAT_DECIMALMINUTES);
+ showControls(formatType);
}
private void newTypedValues(KeyEvent e) {
double v = getValue();
- // now need to put that into the fields that
- // are not currently shown so that they are
- // ready if needed.
- if (e != null) {
- sayValue(v, true);
- }
+// // now need to put that into the fields that
+// // are not currently shown so that they are
+// // ready if needed.
+//
+// if (e != null) {
+// setValue(v, true);
+// }
+
// and say the formated version
sayFormattedValue(v);
}
-
+
public void showControls(int formatStyle) {
- boolean decimal = (formatStyle == LatLong.FORMAT_DECIMALMINUTES);
+
+ if (formatType==formatStyle) {
+ return;
+ }
+
+ //important this comes before setting format style.
+ double currentValue = getValue();
+
+ this.formatType = formatStyle;
+
degHBox.getChildren().clear();
- if (decimal) {
+
+ System.out.println("FORMATSTYLE: " + formatStyle + " val " + currentValue);
+
+ switch (formatType) {
+ case LatLong.FORMAT_DECIMALMINUTES:
degHBox.getChildren().add(dl);
degHBox.getChildren().add(degrees);
degHBox.getChildren().add(dml);
degHBox.getChildren().add(decminutes);
- }
- else {
+ break;
+ case LatLong.FORMAT_MINUTESSECONDS:
degHBox.getChildren().add(dl);
degHBox.getChildren().add(degrees);
degHBox.getChildren().add(ml);
degHBox.getChildren().add(minutes);
degHBox.getChildren().add(sl);
degHBox.getChildren().add(seconds);
+ break;
+ case LatLong.FORMAT_DECIMAL:
+ degHBox.getChildren().add(dec);
+ degHBox.getChildren().add(decimal);
+ break;
+
}
- minutes.setVisible(decimal == false);
- ml.setVisible(decimal == false);
- seconds.setVisible(decimal == false);
- sl.setVisible(decimal == false);
- decminutes.setVisible(decimal);
- dml.setVisible(decimal);
+
+ setValue(currentValue);
+
sayFormattedValue(getValue());
}
-
+
/**
* Set data in the lat long dialog strip
* @param value Lat or Long in decimal degrees.
*/
- public void sayValue(double value) {
- sayValue(value, false);
+ public void setValue(double value) {
+ setValue(value, false);
}
-
- public void sayValue(double value, boolean hiddenOnly) {
+
+ public void setValue(double value, boolean hiddenOnly) {
+
+ System.out.println("Set value: " + value);
if (value >= 0) {
nsew.getSelectionModel().select(0);
}
else {
nsew.getSelectionModel().select(1);
}
-
+
double deg = LatLong.getSignedDegrees(value);
-// System.out.println("Deg: " + LatLong.getSignedDegrees(value) + " value: " +value);
-
- if (degrees.isVisible() == false || !hiddenOnly) degrees.setText(String.format("%d", (int)Math.abs(deg)));
- if (minutes.isVisible() == false || !hiddenOnly) minutes.setText(String.format("%d", LatLong.getIntegerMinutes(value)));
- if (decminutes.isVisible() == false || !hiddenOnly) decminutes.setText(String.format("%3.5f", LatLong.getDecimalMinutes(value)));
- if (seconds.isVisible() == false || !hiddenOnly) seconds.setText(String.format("%3.5f", LatLong.getSeconds(value)));
- if (nsew.isVisible() == false || !hiddenOnly) nsew.getSelectionModel().select(deg >= 0 ? 0 : 1);
+ // System.out.println("Deg: " + LatLong.getSignedDegrees(value) + " value: " +value);
+
+
+ // if (degrees.isVisible() == false || !hiddenOnly) degrees.setText(String.format("%d", (int)Math.abs(deg)));
+ // if (minutes.isVisible() == false || !hiddenOnly) minutes.setText(String.format("%d", LatLong.getIntegerMinutes(value)));
+ // if (decminutes.isVisible() == false || !hiddenOnly) decminutes.setText(String.format("%3.5f", LatLong.getDecimalMinutes(value)));
+ // if (seconds.isVisible() == false || !hiddenOnly) seconds.setText(String.format("%3.5f", LatLong.getSeconds(value)));
+ // if (nsew.isVisible() == false || !hiddenOnly) nsew.getSelectionModel().select(deg >= 0 ? 0 : 1);
+ // if (decimal.isVisible() == false || !hiddenOnly) decimal.setText(String.format("%.8f", value));
+
+ switch (formatType) {
+ case LatLong.FORMAT_DECIMALMINUTES:
+
+ degrees.setText(String.format("%d", (int)Math.abs(deg)));
+ decminutes.setText(String.format("%3.5f", LatLong.getDecimalMinutes(value)));
+
+ break;
+ case LatLong.FORMAT_MINUTESSECONDS:
+
+ degrees.setText(String.format("%d", (int)Math.abs(deg)));
+ minutes.setText(String.format("%d", LatLong.getIntegerMinutes(value)));
+ seconds.setText(String.format("%3.5f", LatLong.getSeconds(value)));
+
+ break;
+ case LatLong.FORMAT_DECIMAL:
+
+ decimal.setText(String.format("%.8f", value));
+
+ break;
+
+ }
+
sayFormattedValue(value);
}
-
+
/**
- * Get the value for the latitude and longitude
- * @return the value.
+ * Get the value for the latitude or longitude in decimal
+ * @return the value - the value in decimal
*/
public double getValue() {
+
double deg = 0;
double min = 0;
double sec = 0;
double sin = 1.;
- if (nsew.getSelectionModel().getSelectedIndex()== 1) sin = -1.;
+
+ if (nsew.getSelectionModel().getSelectedIndex() == 1) sin = -1.;
+
+
+ if (formatType == LatLong.FORMAT_DECIMAL){
+ try {
+ deg = Double.valueOf(decimal.getText());
+ return deg;
+ }
+ catch (NumberFormatException ex) {
+ return Double.NaN;
+ }
+ }
+
try {
- deg = Integer.valueOf(degrees.getText());
+ deg = Integer.valueOf(degrees.getText());
}
catch (NumberFormatException Ex) {
return Double.NaN;
}
- if (LatLong.getFormatStyle() == LatLong.FORMAT_DECIMALMINUTES){
+
+
+ if (formatType == LatLong.FORMAT_DECIMALMINUTES){
try {
min = Double.valueOf(decminutes.getText());
}
@@ -237,12 +320,13 @@ public class LatLongStrip extends PamBorderPane {
catch (NumberFormatException ex) {
return Double.NaN;
}
+
}
deg += min/60 + sec/3600;
deg *= sin;
return deg;
}
-
+
/**
* Clear the latitude/longitude data from the pane.
*/
@@ -251,9 +335,10 @@ public class LatLongStrip extends PamBorderPane {
minutes.setText("");
seconds.setText("");
decminutes.setText("");
+ decimal.setText("");
}
-
-
+
+
public void sayFormattedValue(double value) {
if (isLatitude) {
formattedText.setText(LatLong.formatLatitude(value));
@@ -262,13 +347,13 @@ public class LatLongStrip extends PamBorderPane {
formattedText.setText(LatLong.formatLongitude(value));
}
}
-// public boolean isDecimalMinutes() {
-// return decimalMinutes;
-// }
-// public void setDecimalMinutes(boolean decimalMinutes) {
-// this.decimalMinutes = decimalMinutes;
-// showControls();
-// }
+ // public boolean isDecimalMinutes() {
+ // return decimalMinutes;
+ // }
+ // public void setDecimalMinutes(boolean decimalMinutes) {
+ // this.decimalMinutes = decimalMinutes;
+ // showControls();
+ // }
/**
* Set the pane to be enabled or disabled.
@@ -281,5 +366,16 @@ public class LatLongStrip extends PamBorderPane {
seconds.setDisable(!enabled);
decminutes.setDisable(!enabled);
nsew.setDisable(!enabled);
+ decimal.setDisable(!enabled);
}
+
+ /**
+ * Get the title label.
+ * @return the title label.
+ */
+ public Label getTitleLabel() {
+ return titleLabel;
+ }
+
+
}
diff --git a/src/pamViewFX/fxNodes/utilsFX/TextUtilsFX.java b/src/pamViewFX/fxNodes/utilsFX/TextUtilsFX.java
new file mode 100644
index 00000000..d47098d7
--- /dev/null
+++ b/src/pamViewFX/fxNodes/utilsFX/TextUtilsFX.java
@@ -0,0 +1,40 @@
+package pamViewFX.fxNodes.utilsFX;
+
+import javafx.scene.text.Font;
+import javafx.scene.text.Text;
+import javafx.scene.text.TextBoundsType;
+
+public class TextUtilsFX {
+
+ static final Text helper;
+ static final double DEFAULT_WRAPPING_WIDTH;
+ static final double DEFAULT_LINE_SPACING;
+ static final String DEFAULT_TEXT;
+ static final TextBoundsType DEFAULT_BOUNDS_TYPE;
+ static {
+ helper = new Text();
+ DEFAULT_WRAPPING_WIDTH = helper.getWrappingWidth();
+ DEFAULT_LINE_SPACING = helper.getLineSpacing();
+ DEFAULT_TEXT = helper.getText();
+ DEFAULT_BOUNDS_TYPE = helper.getBoundsType();
+ }
+
+ public static double computeTextWidth(Font font, String text, double help0) {
+ // Toolkit.getToolkit().getFontLoader().computeStringWidth(field.getText(),
+ // field.getFont());
+
+ helper.setText(text);
+ helper.setFont(font);
+
+ helper.setWrappingWidth(0.0D);
+ helper.setLineSpacing(0.0D);
+ double d = Math.min(helper.prefWidth(-1.0D), help0);
+ helper.setWrappingWidth((int) Math.ceil(d));
+ d = Math.ceil(helper.getLayoutBounds().getWidth());
+
+ helper.setWrappingWidth(DEFAULT_WRAPPING_WIDTH);
+ helper.setLineSpacing(DEFAULT_LINE_SPACING);
+ helper.setText(DEFAULT_TEXT);
+ return d;
+ }
+}
\ No newline at end of file