diff --git a/src/net/azib/ipscan/gui/AbstractModalDialog.java b/src/net/azib/ipscan/gui/AbstractModalDialog.java index 84d77604..5e3144d4 100755 --- a/src/net/azib/ipscan/gui/AbstractModalDialog.java +++ b/src/net/azib/ipscan/gui/AbstractModalDialog.java @@ -6,11 +6,14 @@ package net.azib.ipscan.gui; import net.azib.ipscan.config.Platform; +import net.azib.ipscan.gui.util.LayoutHelper; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.List; @@ -82,6 +85,27 @@ public abstract class AbstractModalDialog { } } + /** + * Positions 2 buttons at the bottom-right part of the shell in the FormLayout. + * On MacOS also changes ok and cancel button order. + * @param okButton + * @param cancelButton + * @param control the bottom-right widget, used as a guide + */ + protected void positionButtonsInFormLayout(Button okButton, Button cancelButton, Control control) { + shell.setDefaultButton(okButton); + + if (Platform.MAC_OS) { + // Mac OS users expect button order to be reverse + Button fooButton = okButton; + okButton = cancelButton; + cancelButton = fooButton; + } + // both buttons + cancelButton.setLayoutData(LayoutHelper.formData(85, SWT.DEFAULT, null, new FormAttachment(100), new FormAttachment(control, 6), null)); + okButton.setLayoutData(LayoutHelper.formData(85, SWT.DEFAULT, null, new FormAttachment(cancelButton, -10), new FormAttachment(control, 6), null)); + } + // common listeners follow protected static class UpButtonListener implements Listener { diff --git a/src/net/azib/ipscan/gui/EditOpenersDialog.java b/src/net/azib/ipscan/gui/EditOpenersDialog.java index 4a231558..899adbdf 100755 --- a/src/net/azib/ipscan/gui/EditOpenersDialog.java +++ b/src/net/azib/ipscan/gui/EditOpenersDialog.java @@ -16,7 +16,6 @@ import net.azib.ipscan.fetchers.FetcherRegistry; import net.azib.ipscan.gui.util.LayoutHelper; import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; @@ -60,14 +59,15 @@ public class EditOpenersDialog extends AbstractModalDialog { shell = new Shell(parent, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM); shell.setText(Labels.getLabel("title.openers.edit")); - shell.setSize(new Point(405, 307)); - shell.setLayout(LayoutHelper.createLayout(10, 10, 4)); + shell.setLayout(LayoutHelper.formLayout(10, 10, 4)); Label messageLabel = new Label(shell, SWT.NONE); messageLabel.setText(Labels.getLabel("text.openers.edit")); openersList = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); - openersList.setLayoutData(LayoutHelper.createData(135, 200, null, null, new FormAttachment(messageLabel), null)); + editFieldsGroup = new Group(shell, SWT.NONE); + + openersList.setLayoutData(LayoutHelper.formData(135, 200, null, null, new FormAttachment(messageLabel), new FormAttachment(editFieldsGroup, 0, SWT.BOTTOM))); for (Iterator i = Config.getOpenersConfig().iterateNames(); i.hasNext();) { String name = (String) i.next(); openersList.add(name); @@ -90,13 +90,12 @@ public class EditOpenersDialog extends AbstractModalDialog { deleteButton.setText(Labels.getLabel("button.delete")); deleteButton.addListener(SWT.Selection, new DeleteButtonListener()); - upButton.setLayoutData(LayoutHelper.createData(new FormAttachment(openersList), new FormAttachment(deleteButton, 0, SWT.RIGHT), new FormAttachment(messageLabel), null)); - downButton.setLayoutData(LayoutHelper.createData(new FormAttachment(openersList), new FormAttachment(deleteButton, 0, SWT.RIGHT), new FormAttachment(upButton), null)); - addButton.setLayoutData(LayoutHelper.createData(new FormAttachment(openersList), new FormAttachment(deleteButton, 0, SWT.RIGHT), new FormAttachment(downButton, 16), null)); - deleteButton.setLayoutData(LayoutHelper.createData(new FormAttachment(openersList), null, new FormAttachment(addButton), null)); + upButton.setLayoutData(LayoutHelper.formData(new FormAttachment(openersList), new FormAttachment(deleteButton, 0, SWT.RIGHT), new FormAttachment(messageLabel), null)); + downButton.setLayoutData(LayoutHelper.formData(new FormAttachment(openersList), new FormAttachment(deleteButton, 0, SWT.RIGHT), new FormAttachment(upButton), null)); + addButton.setLayoutData(LayoutHelper.formData(new FormAttachment(openersList), new FormAttachment(deleteButton, 0, SWT.RIGHT), new FormAttachment(downButton, 16), null)); + deleteButton.setLayoutData(LayoutHelper.formData(new FormAttachment(openersList), null, new FormAttachment(addButton), null)); - editFieldsGroup = new Group(shell, SWT.NONE); - editFieldsGroup.setLayoutData(LayoutHelper.createData(new FormAttachment(upButton), null, new FormAttachment(messageLabel), null)); + editFieldsGroup.setLayoutData(LayoutHelper.formData(new FormAttachment(upButton, 10), null, new FormAttachment(messageLabel), null)); RowLayout rowLayout = new RowLayout(SWT.VERTICAL); rowLayout.fill = true; rowLayout.justify = true; @@ -137,7 +136,7 @@ public class EditOpenersDialog extends AbstractModalDialog { if (!Platform.MAC_OS) { Button closeButton = new Button(shell, SWT.NONE); closeButton.setText(Labels.getLabel("button.close")); - closeButton.setLayoutData(LayoutHelper.createData(85, SWT.DEFAULT, null, new FormAttachment(editFieldsGroup, 0, SWT.RIGHT), new FormAttachment(editFieldsGroup), null)); + closeButton.setLayoutData(LayoutHelper.formData(85, SWT.DEFAULT, null, new FormAttachment(editFieldsGroup, 0, SWT.RIGHT), new FormAttachment(editFieldsGroup, 6), null)); closeButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { shell.close(); diff --git a/src/net/azib/ipscan/gui/SelectFetchersDialog.java b/src/net/azib/ipscan/gui/SelectFetchersDialog.java index a1fec769..2123b938 100755 --- a/src/net/azib/ipscan/gui/SelectFetchersDialog.java +++ b/src/net/azib/ipscan/gui/SelectFetchersDialog.java @@ -13,10 +13,10 @@ import net.azib.ipscan.config.Labels; import net.azib.ipscan.fetchers.Fetcher; import net.azib.ipscan.fetchers.FetcherRegistry; import net.azib.ipscan.fetchers.IPFetcher; +import net.azib.ipscan.gui.util.LayoutHelper; import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; @@ -57,30 +57,18 @@ public class SelectFetchersDialog extends AbstractModalDialog { shell = new Shell(parent, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM); shell.setText(Labels.getLabel("title.fetchers.select")); - shell.setSize(new Point(420, 332)); - shell.setLayout(null); + shell.setLayout(LayoutHelper.formLayout(10, 10, 4)); Label messageLabel = new Label(shell, SWT.WRAP); messageLabel.setText(Labels.getLabel("text.fetchers.select")); - messageLabel.setSize(messageLabel.computeSize(420, SWT.DEFAULT)); - messageLabel.setLocation(10, 10); - Rectangle messageLabelBounds = messageLabel.getBounds(); - int topLocation = messageLabelBounds.y + messageLabelBounds.height + 10; + messageLabel.setLayoutData(LayoutHelper.formData(new FormAttachment(0), new FormAttachment(100), null, null)); Label selectedLabel = new Label(shell, SWT.NONE); selectedLabel.setText(Labels.getLabel("text.fetchers.selectedList")); - selectedLabel.setBounds(new Rectangle(10, topLocation, 155, 14)); - - Button okButton = new Button(shell, SWT.NONE); - okButton.setText(Labels.getLabel("button.OK")); - - Button cancelButton = new Button(shell, SWT.NONE); - cancelButton.setText(Labels.getLabel("button.cancel")); - - positionButtons(okButton, cancelButton); - + selectedLabel.setLayoutData(LayoutHelper.formData(null, null, new FormAttachment(messageLabel, 5), null)); + selectedFetchersList = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); - selectedFetchersList.setBounds(new Rectangle(10, topLocation + 20, 155, okButton.getLocation().y - 25 - topLocation)); + selectedFetchersList.setLayoutData(LayoutHelper.formData(140, 200, null, null, new FormAttachment(selectedLabel), null)); Iterator i = fetcherRegistry.getSelectedFetchers().iterator(); i.next(); // skip IP while (i.hasNext()) { @@ -91,30 +79,27 @@ public class SelectFetchersDialog extends AbstractModalDialog { Button upButton = new Button(shell, SWT.NONE); upButton.setText(Labels.getLabel("button.up")); - upButton.pack(); - upButton.setLocation(170, topLocation + 20); Button downButton = new Button(shell, SWT.NONE); downButton.setText(Labels.getLabel("button.down")); - downButton.pack(); - downButton.setLocation(170, topLocation + 50); Button addButton = new Button(shell, SWT.NONE); addButton.setText(Labels.getLabel("button.left")); - addButton.pack(); - addButton.setLocation(170, topLocation + 95); Button removeButton = new Button(shell, SWT.NONE); removeButton.setText(Labels.getLabel("button.right")); - removeButton.pack(); - removeButton.setLocation(170, topLocation + 125); + + upButton.setLayoutData(LayoutHelper.formData(new FormAttachment(selectedFetchersList), new FormAttachment(downButton, 0, SWT.RIGHT), new FormAttachment(selectedLabel), null)); + downButton.setLayoutData(LayoutHelper.formData(new FormAttachment(selectedFetchersList), null, new FormAttachment(upButton), null)); + addButton.setLayoutData(LayoutHelper.formData(new FormAttachment(selectedFetchersList), new FormAttachment(downButton, 0, SWT.RIGHT), new FormAttachment(downButton, 16), null)); + removeButton.setLayoutData(LayoutHelper.formData(new FormAttachment(selectedFetchersList), new FormAttachment(downButton, 0, SWT.RIGHT), new FormAttachment(addButton), null)); Label registeredLabel = new Label(shell, SWT.NONE); registeredLabel.setText(Labels.getLabel("text.fetchers.availableList")); - registeredLabel.setBounds(new Rectangle(245, topLocation, 155, 14)); + registeredLabel.setLayoutData(LayoutHelper.formData(new FormAttachment(downButton, 10), null, new FormAttachment(messageLabel, 5), null)); registeredFetchersList = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); - registeredFetchersList.setBounds(new Rectangle(245, topLocation + 20, 160, okButton.getLocation().y - 25 - topLocation)); + registeredFetchersList.setLayoutData(LayoutHelper.formData(140, 200, new FormAttachment(downButton, 10), null, new FormAttachment(registeredLabel), null)); i = fetcherRegistry.getRegisteredFetchers().iterator(); i.next(); // skip IP while (i.hasNext()) { @@ -125,6 +110,14 @@ public class SelectFetchersDialog extends AbstractModalDialog { registeredFetchersList.add(fetcherName); } + Button okButton = new Button(shell, SWT.NONE); + okButton.setText(Labels.getLabel("button.OK")); + + Button cancelButton = new Button(shell, SWT.NONE); + cancelButton.setText(Labels.getLabel("button.cancel")); + + positionButtonsInFormLayout(okButton, cancelButton, registeredFetchersList); + upButton.addListener(SWT.Selection, new UpButtonListener(selectedFetchersList)); downButton.addListener(SWT.Selection, new DownButtonListener(selectedFetchersList)); AddRemoveButtonListener addButtonListener = new AddRemoveButtonListener(registeredFetchersList, selectedFetchersList); @@ -133,6 +126,8 @@ public class SelectFetchersDialog extends AbstractModalDialog { AddRemoveButtonListener removeButtonListener = new AddRemoveButtonListener(selectedFetchersList, registeredFetchersList); removeButton.addListener(SWT.Selection, removeButtonListener); selectedFetchersList.addListener(SWT.MouseDoubleClick, removeButtonListener); + + shell.pack(); cancelButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { @@ -145,7 +140,6 @@ public class SelectFetchersDialog extends AbstractModalDialog { shell.close(); } }); - shell.setDefaultButton(okButton); } /** diff --git a/src/net/azib/ipscan/gui/util/LayoutHelper.java b/src/net/azib/ipscan/gui/util/LayoutHelper.java index 836a3fad..0262c12c 100644 --- a/src/net/azib/ipscan/gui/util/LayoutHelper.java +++ b/src/net/azib/ipscan/gui/util/LayoutHelper.java @@ -18,7 +18,7 @@ import org.eclipse.swt.layout.FormLayout; */ public class LayoutHelper { - public static FormLayout createLayout(int marginWidth, int marginHeight, int spacing) { + public static FormLayout formLayout(int marginWidth, int marginHeight, int spacing) { FormLayout formLayout = new FormLayout(); formLayout.marginWidth = marginWidth; formLayout.marginHeight = marginHeight; @@ -26,7 +26,7 @@ public class LayoutHelper { return formLayout; } - public static FormData createData(int width, int height, FormAttachment left, FormAttachment right, FormAttachment top, FormAttachment bottom) { + public static FormData formData(int width, int height, FormAttachment left, FormAttachment right, FormAttachment top, FormAttachment bottom) { FormData formData = new FormData(width, height); formData.left = left; formData.right = right; @@ -35,7 +35,7 @@ public class LayoutHelper { return formData; } - public static FormData createData(FormAttachment left, FormAttachment right, FormAttachment top, FormAttachment bottom) { - return createData(SWT.DEFAULT, SWT.DEFAULT, left, right, top, bottom); + public static FormData formData(FormAttachment left, FormAttachment right, FormAttachment top, FormAttachment bottom) { + return formData(SWT.DEFAULT, SWT.DEFAULT, left, right, top, bottom); } }