positionButtons() introduced in AbstractModelDialog that hopefully positions OK/Cancel/Close buttons correctly at the bottom-right edge of the dialog.

git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk/ipscan@105 375186e5-ef17-0410-b0b6-91563547dcda
This commit is contained in:
angryziber 2007-01-02 23:36:48 +00:00
parent ce8b0f8681
commit 971382c5af
7 changed files with 109 additions and 74 deletions

View File

@ -62,8 +62,12 @@ public class AboutDialog extends AbstractModalDialog {
textLabel.addListener(SWT.Selection, new HelpActions.Website());
textLabel.pack();
Button button = new Button(shell, SWT.NONE);
button.setText(Labels.getLabel("button.close"));
positionButtons(button, null);
Text licenseText = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.WRAP);
licenseText.setBounds(60, 140, 320, 160);
licenseText.setBounds(60, 140, shell.getClientArea().width - 70, button.getLocation().y - 150);
licenseText.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
licenseText.setText("Licensed under the GNU General Public License Version 2\n\n" +
Version.NAME + " is free software; you can redistribute it and/or " +
@ -79,10 +83,6 @@ public class AboutDialog extends AbstractModalDialog {
"Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA " +
"02110-1301, USA, or visit http://www.fsf.org/");
Button button = new Button(shell, SWT.NONE);
button.setText(Labels.getLabel("button.close"));
button.setBounds(170, 305, 80, 25);
button.setFocus();
button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
shell.close();

View File

@ -3,7 +3,12 @@
*/
package net.azib.ipscan.gui;
import net.azib.ipscan.config.Platform;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.List;
@ -21,11 +26,13 @@ public abstract class AbstractModalDialog {
public void open() {
// center dialog box according to the parent window
Rectangle parentBounds = shell.getParent().getBounds();
Rectangle childBounds = shell.getBounds();
int x = parentBounds.x + (parentBounds.width - childBounds.width) / 2;
int y = parentBounds.y + (parentBounds.height - childBounds.height) / 2;
shell.setLocation(x, y);
if (shell.getParent() != null) {
Rectangle parentBounds = shell.getParent().getBounds();
Rectangle childBounds = shell.getBounds();
int x = parentBounds.x + (parentBounds.width - childBounds.width) / 2;
int y = parentBounds.y + (parentBounds.height - childBounds.height) / 2;
shell.setLocation(x, y);
}
// open the dialog box
shell.open();
@ -41,6 +48,38 @@ public abstract class AbstractModalDialog {
shell.dispose();
}
/**
* Positions 2 buttons at the bottom-right part of the shell.
* On MacOS also changes ok and cancel button order.
* @param okButton
* @param cancelButton can be null
*/
protected void positionButtons(Button okButton, Button cancelButton) {
shell.setDefaultButton(okButton);
Rectangle clientArea = shell.getClientArea();
Point size = okButton.computeSize(85, SWT.DEFAULT);
okButton.setSize(size);
if (cancelButton != null) {
cancelButton.setSize(size);
if (Platform.MAC_OS) {
// Mac OS users expect button order to be reverse
Button fooButton = okButton;
okButton = cancelButton;
cancelButton = fooButton;
}
// both buttons
cancelButton.setLocation(clientArea.width - size.x - 10, clientArea.height - size.y - 10);
okButton.setLocation(clientArea.width - size.x * 2 - 20, clientArea.height - size.y - 10);
}
else {
// only one button
okButton.setLocation(clientArea.width - size.x - 10, clientArea.height - size.y - 10);
}
}
// common listeners follow
protected static class UpButtonListener implements Listener {

View File

@ -94,8 +94,9 @@ public class EditOpenersDialog extends AbstractModalDialog {
deleteButton.addListener(SWT.Selection, new DeleteButtonListener());
Button closeButton = new Button(shell, SWT.NONE);
closeButton.setText(Labels.getLabel("button.close"));
closeButton.setBounds(new Rectangle(315, 245, 75, 25));
closeButton.setText(Labels.getLabel("button.close"));
positionButtons(closeButton, null);
editFieldsGroup = new Group(shell, SWT.NONE);
editFieldsGroup.setBounds(205, 30, 185, 200);
@ -147,7 +148,6 @@ public class EditOpenersDialog extends AbstractModalDialog {
shell.close();
}
});
shell.setDefaultButton(closeButton);
}
private void saveOpeners() {

View File

@ -50,36 +50,33 @@ public class GettingStartedDialog extends AbstractModalDialog {
shell.setImage(parent.getImage());
}
iconLabel.pack();
gettingStartedText = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.WRAP);
gettingStartedText.setBounds(60, 10, 320, 160);
gettingStartedText.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
closeButton = new Button(shell, SWT.NONE);
closeButton.setText(Labels.getLabel("button.close"));
closeButton.setBounds(110, 180, 80, 25);
closeButton.pack();
nextButton = new Button(shell, SWT.NONE);
nextButton.setText(Labels.getLabel("button.next"));
nextButton.setFocus();
positionButtons(nextButton, closeButton);
gettingStartedText = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.WRAP);
gettingStartedText.setBounds(60, 10, shell.getClientArea().width - 70, nextButton.getLocation().y - 20);
gettingStartedText.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
closeButton.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
shell.close();
shell.dispose();
}
});
nextButton = new Button(shell, SWT.NONE);
nextButton.setText(Labels.getLabel("button.next"));
nextButton.setBounds(210, 180, 80, 25);
nextButton.setFocus();
nextButton.pack();
nextButton.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
activePage++;
displayActivePage();
}
});
shell.setDefaultButton(nextButton);
displayActivePage();
}

View File

@ -43,27 +43,28 @@ public class InputDialog extends AbstractModalDialog {
Shell parent = currentDisplay != null ? currentDisplay.getActiveShell() : null;
shell = new Shell(parent, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
shell.setSize(new Point(300, 112));
shell.setSize(new Point(310, 125));
shell.setLayout(null);
messageLabel = new Label(shell, SWT.NONE);
messageLabel.setBounds(new Rectangle(3, 5, 282, 14));
text = new Text(shell, SWT.BORDER);
text.setBounds(new Rectangle(5, 24, 281, 24));
messageLabel.setBounds(new Rectangle(10, 10, 282, 14));
okButton = new Button(shell, SWT.NONE);
okButton.setLocation(new Point(57, 55));
okButton.setSize(new Point(70, 25));
okButton.setText(Labels.getLabel("button.OK"));
cancelButton = new Button(shell, SWT.NONE);
cancelButton.setText(Labels.getLabel("button.cancel"));
positionButtons(okButton, cancelButton);
text = new Text(shell, SWT.BORDER);
text.setBounds(new Rectangle(10, 28, shell.getClientArea().width - 20, 24));
okButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
message = text.getText();
shell.dispose();
}
});
shell.setDefaultButton(okButton);
cancelButton = new Button(shell, SWT.NONE);
cancelButton.setLocation(new Point(155, 55));
cancelButton.setSize(new Point(70, 25));
cancelButton.setText(Labels.getLabel("button.cancel"));
cancelButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
message = null;

View File

@ -8,23 +8,23 @@ import net.azib.ipscan.config.GlobalConfig;
import net.azib.ipscan.config.Labels;
import net.azib.ipscan.core.net.PingerRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
/**
* Options Dialog
@ -69,24 +69,23 @@ public class OptionsDialog extends AbstractModalDialog {
*/
private void createShell() {
Display currentDisplay = Display.getCurrent();
shell = new Shell(currentDisplay != null ? currentDisplay.getActiveShell() : null, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
shell.setText(Labels.getLabel("title.options"));
createTabFolder();
shell.setSize(new Point(350, 423));
shell.setLayout(null);
shell.setSize(new Point(380, 423));
okButton = new Button(shell, SWT.NONE);
okButton.setLocation(175, 365);
//okButton.setBounds(new Rectangle(175, 365, 75, 25));
okButton.setText("OK");
okButton.pack();
shell.setDefaultButton(okButton);
okButton.setText(Labels.getLabel("button.OK"));
cancelButton = new Button(shell, SWT.NONE);
cancelButton.setLocation(260, 365);
//cancelButton.setBounds(new Rectangle(260, 365, 75, 25));
cancelButton.setText("Cancel");
cancelButton.pack();
cancelButton.setText(Labels.getLabel("button.cancel"));
positionButtons(okButton, cancelButton);
createTabFolder();
Rectangle clientArea = shell.getClientArea();
tabFolder.setBounds(new Rectangle(10, 10, clientArea.width - 20, okButton.getLocation().y - 20));
okButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
saveOptions();
@ -109,7 +108,6 @@ public class OptionsDialog extends AbstractModalDialog {
createDisplayTab();
createFetchersTab();
createPortsTab();
tabFolder.setBounds(new Rectangle(5, 5, 330, 355));
TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
tabItem.setText(Labels.getLabel("title.options.scanning"));
tabItem.setControl(scanningTab);

View File

@ -66,8 +66,16 @@ public class SelectFetchersDialog extends AbstractModalDialog {
selectedLabel.setText(Labels.getLabel("text.fetchers.selectedList"));
selectedLabel.setBounds(new Rectangle(10, 35, 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);
selectedFetchersList = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
selectedFetchersList.setBounds(new Rectangle(10, 55, 155, 200));
selectedFetchersList.setBounds(new Rectangle(10, 55, 155, okButton.getLocation().y - 65));
Iterator i = fetcherRegistry.getSelectedFetchers().iterator();
i.next(); // skip IP
while (i.hasNext()) {
@ -97,7 +105,7 @@ public class SelectFetchersDialog extends AbstractModalDialog {
registeredLabel.setBounds(new Rectangle(230, 35, 155, 14));
registeredFetchersList = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
registeredFetchersList.setBounds(new Rectangle(230, 55, 160, 200));
registeredFetchersList.setBounds(new Rectangle(230, 55, 160, okButton.getLocation().y - 65));
i = fetcherRegistry.getRegisteredFetchers().iterator();
i.next(); // skip IP
while (i.hasNext()) {
@ -112,14 +120,6 @@ public class SelectFetchersDialog extends AbstractModalDialog {
downButton.addListener(SWT.Selection, new DownButtonListener(selectedFetchersList));
addButton.addListener(SWT.Selection, new AddRemoveButtonListener(registeredFetchersList, selectedFetchersList));
removeButton.addListener(SWT.Selection, new AddRemoveButtonListener(selectedFetchersList, registeredFetchersList));
Button okButton = new Button(shell, SWT.NONE);
okButton.setText(Labels.getLabel("button.OK"));
okButton.setBounds(new Rectangle(220, 270, 80, 25));
Button cancelButton = new Button(shell, SWT.NONE);
cancelButton.setText(Labels.getLabel("button.cancel"));
cancelButton.setBounds(new Rectangle(310, 270, 80, 25));
cancelButton.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {