]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java
Added a length scaling factor for adding components
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / dialog / ComponentSelectionDialog.java
index 95b22512b7b06e534fe810a4ec37e195c179f930..35e761ccfa6eb436071352e6721b192e67255f76 100644 (file)
@@ -7,6 +7,7 @@ import java.util.Set;
 
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IDialogSettings;
 import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.jface.resource.JFaceResources;
@@ -49,6 +50,12 @@ import org.simantics.utils.ui.ExceptionUtils;
 
 public class ComponentSelectionDialog extends Dialog implements ISelectionChangedListener {
 
+       private static final String DIALOG = "ComponentSelectionDialog"; //$NON-NLS-1$
+
+       private IDialogSettings dialogSettings;
+       
+       private double lengthFactor = 1.0;
+
        private ResourceManager resourceManager;
 
        private String libUri;
@@ -74,7 +81,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
        private Text lengthText;
        // Turn component
        private Text angleText;
-       // Rotated In-line, or turn conponent.
+       // Rotated In-line, or turn component.
        private Text rotationAngleText;
 
        // Input for new PipeRun
@@ -113,8 +120,24 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                this.libUri = libUri;
 
                usedNames = new HashSet<>();
+
+               setShellStyle(getShellStyle() | SWT.RESIZE);
+
+               IDialogSettings settings = Activator.getDefault().getDialogSettings();
+               dialogSettings = settings.getSection(DIALOG);
+               if (dialogSettings == null)
+                       dialogSettings = settings.addNewSection(DIALOG);
        }
        
+       public void setLengthFactor(double lengthFactor) {
+               this.lengthFactor = lengthFactor;
+       }
+
+       @Override
+       protected IDialogSettings getDialogBoundsSettings() {
+               return dialogSettings;
+       }
+
        @Override
        protected void configureShell(Shell newShell) {
                super.configureShell(newShell);
@@ -179,7 +202,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                turns = P3DUtil.filterUserComponents(turns);
                inlines = P3DUtil.filterUserComponents(inlines);
 
-               ExpandBar expandBar = new ExpandBar(composite, SWT.NONE);
+               ExpandBar expandBar = new ExpandBar(composite, SWT.V_SCROLL);
 
                ExpandItem inlineItem = new ExpandItem(expandBar, SWT.NONE);
                inlineItem.setText("Inline");
@@ -216,7 +239,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                endViewer.addSelectionChangedListener(this);
 
                GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(expandBar);
-               GridDataFactory.fillDefaults().minSize(500, 500).hint(500, 500).applyTo(composite);
+               GridDataFactory.fillDefaults().grab(true, true).minSize(500, 500).hint(500, 500).applyTo(composite);
 
                Label label = new Label(composite, SWT.NONE);
                label.setText("Position");
@@ -300,7 +323,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                        @Override
                        public void keyReleased(KeyEvent e) {
                                try {
-                                       length = Double.parseDouble(lengthText.getText());
+                                       length = Double.parseDouble(lengthText.getText()) / lengthFactor;
                                } catch (NumberFormatException err) {
                                        length = null;
                                }
@@ -336,7 +359,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                        @Override
                        public void keyReleased(KeyEvent e) {
                                try {
-                                       diameter = Double.parseDouble(diameterText.getText());
+                                       diameter = Double.parseDouble(diameterText.getText()) / lengthFactor;
                                } catch (NumberFormatException err) {
                                        diameter = null;
                                }
@@ -348,7 +371,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                        @Override
                        public void keyReleased(KeyEvent e) {
                                try {
-                                       turnRadius = Double.parseDouble(turnRadiusText.getText());
+                                       turnRadius = Double.parseDouble(turnRadiusText.getText()) / lengthFactor;
                                } catch (NumberFormatException err) {
                                        turnRadius = null;
                                }