From eae0620e02558df0967856ea86d59fcc44723c44 Mon Sep 17 00:00:00 2001 From: angryziber Date: Fri, 28 Mar 2008 23:20:09 +0000 Subject: [PATCH] controls' width now depends on the font size git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@328 375186e5-ef17-0410-b0b6-91563547dcda --- .../ipscan/gui/feeders/FileFeederGUI.java | 13 ++-- .../ipscan/gui/feeders/RandomFeederGUI.java | 65 +++++-------------- .../ipscan/gui/feeders/RangeFeederGUI.java | 11 ++-- 3 files changed, 29 insertions(+), 60 deletions(-) diff --git a/src/net/azib/ipscan/gui/feeders/FileFeederGUI.java b/src/net/azib/ipscan/gui/feeders/FileFeederGUI.java index 16101600..f9e92d41 100755 --- a/src/net/azib/ipscan/gui/feeders/FileFeederGUI.java +++ b/src/net/azib/ipscan/gui/feeders/FileFeederGUI.java @@ -7,13 +7,13 @@ package net.azib.ipscan.gui.feeders; import net.azib.ipscan.feeders.Feeder; import net.azib.ipscan.feeders.FileFeeder; +import net.azib.ipscan.gui.util.LayoutHelper; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.FileDialog; @@ -39,11 +39,7 @@ public class FileFeederGUI extends AbstractFeederGUI { protected void initialize() { feeder = new FileFeeder(); - FormLayout formLayout = new FormLayout(); - formLayout.marginWidth = 3; - formLayout.marginHeight = 3; - formLayout.spacing = 3; - setLayout(formLayout); + setLayout(LayoutHelper.formLayout(3, 3, 4)); fileNameLabel = new Label(this, SWT.NONE); fileNameText = new Text(this, SWT.BORDER); @@ -56,10 +52,13 @@ public class FileFeederGUI extends AbstractFeederGUI { formData.bottom = new FormAttachment(browseButton, 0, SWT.BOTTOM); fileNameLabel.setLayoutData(formData); - formData = new FormData(140, SWT.DEFAULT); + // some long text + fileNameText.setText("255.255.255.255.xxx.xxx"); + formData = new FormData(fileNameText.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, SWT.DEFAULT); formData.top = new FormAttachment(0); formData.left = new FormAttachment(fileNameLabel); fileNameText.setLayoutData(formData); + fileNameText.setText(""); browseButton.setText(getStringLabel("browse")); formData = new FormData(); diff --git a/src/net/azib/ipscan/gui/feeders/RandomFeederGUI.java b/src/net/azib/ipscan/gui/feeders/RandomFeederGUI.java index e4921bab..35d020c3 100755 --- a/src/net/azib/ipscan/gui/feeders/RandomFeederGUI.java +++ b/src/net/azib/ipscan/gui/feeders/RandomFeederGUI.java @@ -11,19 +11,17 @@ import java.util.logging.Logger; import net.azib.ipscan.config.Labels; import net.azib.ipscan.config.LoggerFactory; -import net.azib.ipscan.config.Platform; import net.azib.ipscan.core.InetAddressUtils; import net.azib.ipscan.feeders.Feeder; import net.azib.ipscan.feeders.RandomFeeder; import net.azib.ipscan.gui.actions.FeederActions; +import net.azib.ipscan.gui.util.LayoutHelper; import org.eclipse.swt.SWT; import org.eclipse.swt.events.TraverseEvent; import org.eclipse.swt.events.TraverseListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; @@ -62,12 +60,7 @@ public class RandomFeederGUI extends AbstractFeederGUI { protected void initialize() { feeder = new RandomFeeder(); - FormLayout formLayout = new FormLayout(); - formLayout.marginWidth = 3; - formLayout.marginHeight = 3; - formLayout.marginBottom = 2; - formLayout.spacing = 4; - setLayout(formLayout); + setLayout(LayoutHelper.formLayout(3, 3, 4)); ipPrototypeLabel = new Label(this, SWT.NONE); ipPrototypeText = new Text(this, SWT.BORDER); @@ -79,22 +72,17 @@ public class RandomFeederGUI extends AbstractFeederGUI { countLabel = new Label(this, SWT.NONE); countSpinner = new Spinner(this, SWT.BORDER); - ipPrototypeLabel.setText(getStringLabel("prototype")); - FormData formData = new FormData(); - formData.right = new FormAttachment(hostnameLabel, 0, SWT.RIGHT); - formData.top = new FormAttachment(ipPrototypeText, 0, SWT.CENTER); - ipPrototypeLabel.setLayoutData(formData); + // the longest possible IP + ipPrototypeText.setText("255.255.255.255xx"); + int textWidth = ipPrototypeText.computeSize(SWT.DEFAULT, SWT.DEFAULT).x; - formData = new FormData(105 + (Platform.MAC_OS ? 35 : 0), SWT.DEFAULT); - formData.top = new FormAttachment(0); - formData.left = new FormAttachment(ipPrototypeLabel); - ipPrototypeText.setLayoutData(formData); + ipPrototypeLabel.setText(getStringLabel("prototype")); + ipPrototypeLabel.setLayoutData(LayoutHelper.formData(null, new FormAttachment(hostnameLabel, 0, SWT.RIGHT), new FormAttachment(ipPrototypeText, 0, SWT.CENTER), null)); + + ipPrototypeText.setLayoutData(LayoutHelper.formData(textWidth, SWT.DEFAULT, new FormAttachment(ipPrototypeLabel), null, new FormAttachment(0), null)); ipMaskLabel.setText(getStringLabel("mask")); - formData = new FormData(); - formData.left = new FormAttachment(ipPrototypeText, 3); - formData.top = new FormAttachment(ipPrototypeText, 0, SWT.CENTER); - ipMaskLabel.setLayoutData(formData); + ipMaskLabel.setLayoutData(LayoutHelper.formData(new FormAttachment(ipPrototypeText, 3), null, new FormAttachment(ipPrototypeText, 0, SWT.CENTER), null)); ipMaskCombo.setVisibleItemCount(10); // Warning: IPv4 specific netmasks @@ -106,48 +94,27 @@ public class RandomFeederGUI extends AbstractFeederGUI { ipMaskCombo.add("255..0.255"); ipMaskCombo.add("255.0.0.255"); ipMaskCombo.select(3); - formData = new FormData(105 + (Platform.MAC_OS ? 35 : 0), SWT.DEFAULT); - formData.top = new FormAttachment(0); - formData.left = new FormAttachment(ipMaskLabel); - formData.bottom = new FormAttachment(ipPrototypeText, 0, SWT.BOTTOM); - ipMaskCombo.setLayoutData(formData); + ipMaskCombo.setLayoutData(LayoutHelper.formData(textWidth-15, SWT.DEFAULT, new FormAttachment(ipMaskLabel), null, new FormAttachment(0), new FormAttachment(ipPrototypeText, 0, SWT.BOTTOM))); FeederActions.HostnameButton hostnameSelectionListener = new FeederActions.HostnameButton(hostnameText, ipPrototypeText); hostnameText.addTraverseListener(hostnameSelectionListener); - formData = new FormData(105, SWT.DEFAULT); - formData.top = new FormAttachment(ipPrototypeText); - formData.left = new FormAttachment(ipPrototypeText, 0, SWT.LEFT); - hostnameText.setLayoutData(formData); + hostnameText.setLayoutData(LayoutHelper.formData(textWidth, SWT.DEFAULT, new FormAttachment(ipPrototypeText, 0, SWT.LEFT), null, new FormAttachment(ipPrototypeText), null)); hostnameLabel.setText(getStringLabel("hostname")); - formData = new FormData(); - formData.left = new FormAttachment(0); - formData.top = new FormAttachment(hostnameText, 0, SWT.CENTER); - hostnameLabel.setLayoutData(formData); + hostnameLabel.setLayoutData(LayoutHelper.formData(new FormAttachment(0), null, new FormAttachment(hostnameText, 0, SWT.CENTER), null)); ipUpButton.setImage(new Image(getDisplay(), Labels.getInstance().getImageAsStream("button.ipUp.img"))); ipUpButton.setText(Labels.getLabel("button.ipUp")); ipUpButton.addSelectionListener(hostnameSelectionListener); - formData = new FormData(); - formData.top = new FormAttachment(ipPrototypeText); - formData.left = new FormAttachment(hostnameText); - formData.bottom = new FormAttachment(hostnameText, 1, SWT.BOTTOM); - ipUpButton.setLayoutData(formData); + ipUpButton.setLayoutData(LayoutHelper.formData(new FormAttachment(hostnameText), null, new FormAttachment(ipPrototypeText), new FormAttachment(hostnameText, 1, SWT.BOTTOM))); countLabel.setText(getStringLabel("count")); - formData = new FormData(); - formData.left = new FormAttachment(ipUpButton, 3); - formData.top = new FormAttachment(hostnameLabel, 0, SWT.TOP); - countLabel.setLayoutData(formData); + countLabel.setLayoutData(LayoutHelper.formData(new FormAttachment(ipUpButton, 3), null, new FormAttachment(hostnameLabel, 0, SWT.TOP), null)); countSpinner.setSelection(100); countSpinner.setMaximum(100000); countSpinner.setMinimum(1); - formData = new FormData(); - formData.left = new FormAttachment(countLabel); - formData.top = new FormAttachment(ipUpButton, 0, SWT.CENTER); - formData.right = new FormAttachment(ipMaskCombo, 0, SWT.RIGHT); - countSpinner.setLayoutData(formData); + countSpinner.setLayoutData(LayoutHelper.formData(new FormAttachment(countLabel), new FormAttachment(ipMaskCombo, 0, SWT.RIGHT), new FormAttachment(ipUpButton, 0, SWT.CENTER), null)); countSpinner.addTraverseListener(new TraverseListener() { public void keyTraversed(TraverseEvent e) { // this due to a bug either in SWT or GTK: diff --git a/src/net/azib/ipscan/gui/feeders/RangeFeederGUI.java b/src/net/azib/ipscan/gui/feeders/RangeFeederGUI.java index e11aac0a..8ca1e30d 100755 --- a/src/net/azib/ipscan/gui/feeders/RangeFeederGUI.java +++ b/src/net/azib/ipscan/gui/feeders/RangeFeederGUI.java @@ -11,7 +11,6 @@ import java.util.logging.Logger; import net.azib.ipscan.config.Labels; import net.azib.ipscan.config.LoggerFactory; -import net.azib.ipscan.config.Platform; import net.azib.ipscan.core.InetAddressUtils; import net.azib.ipscan.feeders.Feeder; import net.azib.ipscan.feeders.FeederException; @@ -77,16 +76,20 @@ public class RangeFeederGUI extends AbstractFeederGUI { ipUpButton = new Button(this, SWT.NONE); netmaskCombo = new Combo(this, SWT.NONE); + // the longest possible IP + startIPText.setText("255.255.255.255xx"); + int textWidth = startIPText.computeSize(SWT.DEFAULT, SWT.DEFAULT).x; + ipRangeLabel.setText(getStringLabel("startIP")); ipRangeLabel.setLayoutData(LayoutHelper.formData(null, new FormAttachment(hostnameLabel, 0, SWT.RIGHT), new FormAttachment(startIPText, 0, SWT.CENTER), null)); - startIPText.setLayoutData(LayoutHelper.formData(105 + (Platform.MAC_OS ? 35 : 0), SWT.DEFAULT, new FormAttachment(ipRangeLabel), null, new FormAttachment(0), null)); + startIPText.setLayoutData(LayoutHelper.formData(textWidth, SWT.DEFAULT, new FormAttachment(ipRangeLabel), null, new FormAttachment(0), null)); startIPText.addModifyListener(new StartIPModifyListener()); toLabel.setText(getStringLabel("endIP")); toLabel.setLayoutData(LayoutHelper.formData(new FormAttachment(startIPText), null, new FormAttachment(startIPText, 0, SWT.CENTER), null)); - endIPText.setLayoutData(LayoutHelper.formData(105 + (Platform.MAC_OS ? 35 : 0), SWT.DEFAULT, new FormAttachment(toLabel), null, null, null)); + endIPText.setLayoutData(LayoutHelper.formData(textWidth, SWT.DEFAULT, new FormAttachment(toLabel), null, null, null)); endIPText.addKeyListener(new EndIPKeyListener()); FeederActions.HostnameButton hostnameListener = new FeederActions.HostnameButton(hostnameText, startIPText) { @@ -101,7 +104,7 @@ public class RangeFeederGUI extends AbstractFeederGUI { }; hostnameText.addTraverseListener(hostnameListener); - hostnameText.setLayoutData(LayoutHelper.formData(105, SWT.DEFAULT, new FormAttachment(startIPText, 0, SWT.LEFT), null, new FormAttachment(startIPText), null)); + hostnameText.setLayoutData(LayoutHelper.formData(textWidth, SWT.DEFAULT, new FormAttachment(startIPText, 0, SWT.LEFT), null, new FormAttachment(startIPText), null)); hostnameText.setToolTipText(Labels.getLabel("feeder.range.hostname.tooltip")); Listener netmaskResetListener = new NetmaskResetListener();