Revision: 5299 http://sourceforge.net/p/jump-pilot/code/5299 Author: edso Date: 2016-12-29 18:54:16 +0000 (Thu, 29 Dec 2016) Log Message: ----------- reformatting, removed tabs scale is a double value now, same as internally some beautification of the dialog
Modified Paths: -------------- core/trunk/src/language/jump.properties core/trunk/src/org/openjump/core/ui/plugin/view/ZoomToScalePlugIn.java Modified: core/trunk/src/language/jump.properties =================================================================== --- core/trunk/src/language/jump.properties 2016-12-29 18:42:56 UTC (rev 5298) +++ core/trunk/src/language/jump.properties 2016-12-29 18:54:16 UTC (rev 5299) @@ -1727,7 +1727,7 @@ org.openjump.core.ui.plugin.view.ViewOptionsPlugIn.Date-format = Date format org.openjump.core.ui.plugin.view.ViewOptionsPlugIn.Selection-synchronization = Synchronization of Selection between the Attribute Table and the Map org.openjump.core.ui.plugin.view.ViewOptionsPlugIn.Synchronize = Synchronize -org.openjump.core.ui.plugin.view.ZoomToScalePlugIn.actual-scale-in-horizontal-direction = Actual Scale in Horizontal Direction +org.openjump.core.ui.plugin.view.ZoomToScalePlugIn.actual-scale-in-horizontal-direction = Current Scale in Horizontal Direction org.openjump.core.ui.plugin.view.ZoomToScalePlugIn.scale = scale org.openjump.core.ui.plugin.view.ZoomToScalePlugIn.set-new-scale-to-zoom = Set New Scale to Zoom org.openjump.core.ui.plugin.view.ZoomToScalePlugIn.zoom-to-scale = Zoom to Scale Modified: core/trunk/src/org/openjump/core/ui/plugin/view/ZoomToScalePlugIn.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/view/ZoomToScalePlugIn.java 2016-12-29 18:42:56 UTC (rev 5298) +++ core/trunk/src/org/openjump/core/ui/plugin/view/ZoomToScalePlugIn.java 2016-12-29 18:54:16 UTC (rev 5299) @@ -37,6 +37,10 @@ package org.openjump.core.ui.plugin.view; +import java.text.DecimalFormat; + +import javax.swing.JTextField; + import org.openjump.core.ui.util.ScreenScale; import com.vividsolutions.jts.geom.Coordinate; @@ -54,7 +58,6 @@ import com.vividsolutions.jump.workbench.ui.MultiInputDialog; import com.vividsolutions.jump.workbench.ui.Viewport; - /** * Zooms to a given map scale, received from a input dialog * @@ -62,88 +65,96 @@ */ public class ZoomToScalePlugIn extends AbstractPlugIn { - private String T1 = "scale"; //[sstein] this string is not used anymore - int scale = 25000; - double oldHorizontalScale = 0; // is calculated for panel-width (not heigth!!) - double modelWidth = 0; - double panelWidth = 0; - String text =I18N.get("org.openjump.core.ui.plugin.view.ZoomToScalePlugIn.set-new-scale-to-zoom") + ": 1 : "; + private String T1 = "scale"; // [sstein] this string is not used anymore + double scale = 25000; + double oldHorizontalScale = 0; // is calculated for panel-width (not heigth!!) + double modelWidth = 0; + double panelWidth = 0; + String text = I18N + .get("org.openjump.core.ui.plugin.view.ZoomToScalePlugIn.set-new-scale-to-zoom") + + " 1:"; - public void initialize(PlugInContext context) throws Exception { - - this.T1 = I18N.get("org.openjump.core.ui.plugin.view.ZoomToScalePlugIn.scale") + ": "; - context.getFeatureInstaller().addMainMenuItem(this, - new String[] - {MenuNames.VIEW}, - I18N.get("org.openjump.core.ui.plugin.view.ZoomToScalePlugIn.zoom-to-scale")+"{pos:9}", - false, - null, - createEnableCheck(context.getWorkbenchContext())); - } - - public static MultiEnableCheck createEnableCheck( - WorkbenchContext workbenchContext) { - EnableCheckFactory checkFactory = new EnableCheckFactory( - workbenchContext); + public void initialize(PlugInContext context) throws Exception { - return new MultiEnableCheck().add(checkFactory - .createAtLeastNLayerablesMustExistCheck(1)); + this.T1 = I18N + .get("org.openjump.core.ui.plugin.view.ZoomToScalePlugIn.scale") + ": "; + context + .getFeatureInstaller() + .addMainMenuItem( + this, + new String[] { MenuNames.VIEW }, + I18N.get("org.openjump.core.ui.plugin.view.ZoomToScalePlugIn.zoom-to-scale") + + "{pos:9}", false, null, + createEnableCheck(context.getWorkbenchContext())); + } + + public static MultiEnableCheck createEnableCheck( + WorkbenchContext workbenchContext) { + EnableCheckFactory checkFactory = new EnableCheckFactory(workbenchContext); + + return new MultiEnableCheck().add(checkFactory + .createAtLeastNLayerablesMustExistCheck(1)); + } + + public boolean execute(PlugInContext context) throws Exception { + + Viewport port = context.getLayerViewPanel().getViewport(); + this.oldHorizontalScale = ScreenScale.getHorizontalMapScale(port); + + MultiInputDialog dialog = new MultiInputDialog( + context.getWorkbenchFrame(), + I18N.get("org.openjump.core.ui.plugin.view.ZoomToScalePlugIn.zoom-to-scale"), + true); + setDialogValues(dialog, context); + GUIUtil.centreOnWindow(dialog); + dialog.setVisible(true); + if (!dialog.wasOKPressed()) { + return false; } - - - public boolean execute(PlugInContext context) throws Exception{ - - Viewport port = context.getLayerViewPanel().getViewport(); - this.oldHorizontalScale = ScreenScale.getHorizontalMapScale(port); - - MultiInputDialog dialog = new MultiInputDialog( - context.getWorkbenchFrame(), - I18N.get("org.openjump.core.ui.plugin.view.ZoomToScalePlugIn.zoom-to-scale"), - true); - setDialogValues(dialog, context); - GUIUtil.centreOnWindow(dialog); - dialog.setVisible(true); - if (! dialog.wasOKPressed()) { return false; } - getDialogValues(dialog); - - zoomToNewScale(context); - - return true; - } - - public void zoomToNewScale(PlugInContext context) throws Exception { - Viewport port = context.getLayerViewPanel().getViewport(); - this.oldHorizontalScale = ScreenScale.getHorizontalMapScale(port); - - //-- get zoom factor - double factor = this.scale/this.oldHorizontalScale; + getDialogValues(dialog); - //--calculating new screen using the envelope of the corner LineString - Envelope oldEnvelope = port.getEnvelopeInModelCoordinates(); + zoomToNewScale(context); - double xc = 0.5*(oldEnvelope.getMaxX() + oldEnvelope.getMinX()); - double yc = 0.5*(oldEnvelope.getMaxY() + oldEnvelope.getMinY()); - double xmin = xc - 1/2.0 * factor * oldEnvelope.getWidth(); - double xmax = xc + 1/2.0 * factor * oldEnvelope.getWidth(); - double ymin = yc - 1/2.0 * factor * oldEnvelope.getHeight(); - double ymax = yc + 1/2.0 * factor * oldEnvelope.getHeight(); - Coordinate[] coords = new Coordinate[]{ - new Coordinate(xmin,ymin), new Coordinate(xmax,ymax)}; - Geometry g1 = new GeometryFactory().createLineString(coords); - port.zoom(g1.getEnvelopeInternal()); - } - - private void setDialogValues(MultiInputDialog dialog, PlugInContext context) { - dialog.addLabel(I18N.get("org.openjump.core.ui.plugin.view.ZoomToScalePlugIn.actual-scale-in-horizontal-direction") + " 1 : " +(int)this.oldHorizontalScale); - dialog.addIntegerField(text, scale, 7, text); - } + return true; + } - private void getDialogValues(MultiInputDialog dialog) { - this.scale = dialog.getInteger(text); - } - - public void setScale(double scale) { - this.scale = (int)scale; - } - + public void zoomToNewScale(PlugInContext context) throws Exception { + Viewport port = context.getLayerViewPanel().getViewport(); + this.oldHorizontalScale = ScreenScale.getHorizontalMapScale(port); + + // -- get zoom factor + double factor = this.scale / this.oldHorizontalScale; + + // --calculating new screen using the envelope of the corner LineString + Envelope oldEnvelope = port.getEnvelopeInModelCoordinates(); + + double xc = 0.5 * (oldEnvelope.getMaxX() + oldEnvelope.getMinX()); + double yc = 0.5 * (oldEnvelope.getMaxY() + oldEnvelope.getMinY()); + double xmin = xc - 1 / 2.0 * factor * oldEnvelope.getWidth(); + double xmax = xc + 1 / 2.0 * factor * oldEnvelope.getWidth(); + double ymin = yc - 1 / 2.0 * factor * oldEnvelope.getHeight(); + double ymax = yc + 1 / 2.0 * factor * oldEnvelope.getHeight(); + Coordinate[] coords = new Coordinate[] { new Coordinate(xmin, ymin), + new Coordinate(xmax, ymax) }; + Geometry g1 = new GeometryFactory().createLineString(coords); + port.zoom(g1.getEnvelopeInternal()); + } + + private void setDialogValues(MultiInputDialog dialog, PlugInContext context) { + dialog + .addLabel(I18N + .get("org.openjump.core.ui.plugin.view.ZoomToScalePlugIn.actual-scale-in-horizontal-direction") + + " 1:" + new DecimalFormat("#").format(oldHorizontalScale)); + JTextField field = dialog.addDoubleField(text, Math.floor(oldHorizontalScale), 12, text); + field.setHorizontalAlignment(JTextField.LEFT); + } + + private void getDialogValues(MultiInputDialog dialog) { + this.scale = dialog.getDouble(text); + } + + public void setScale(double scale) { + this.scale = scale; + } + } ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel