Preparing for internationalization as well as responding to the tighter

Eclipse 3.0 code checks.
This commit is contained in:
Robert Greene 2004-07-04 23:13:21 +00:00
parent b1017674b2
commit 72cb1f2983
6 changed files with 126 additions and 68 deletions

View File

@ -33,6 +33,7 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import com.webcodepro.applecommander.ui.TextBundle;
import com.webcodepro.applecommander.ui.swt.util.ImageCanvas;
import com.webcodepro.applecommander.ui.swt.util.SwtUtil;
@ -41,6 +42,7 @@ import com.webcodepro.applecommander.ui.swt.util.SwtUtil;
* @author Rob Greene
*/
public abstract class Wizard {
private TextBundle textBundle = TextBundle.getInstance();
private Shell parent;
private Shell dialog;
private Image logo;
@ -94,46 +96,46 @@ public abstract class Wizard {
composite.setLayoutData(rowData);
composite.setLayout(new FillLayout(SWT.HORIZONTAL));
Button button = new Button(composite, SWT.PUSH);
button.setText("Cancel");
button.setText(textBundle.get("CancelButton")); //$NON-NLS-1$
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
wizardCompleted = false;
dialog.close();
setWizardCompleted(false);
getDialog().close();
}
});
backButton = new Button(composite, SWT.PUSH);
backButton.setEnabled(false);
backButton.setText("< Back");
backButton.setText(textBundle.get("BackButton")); //$NON-NLS-1$
backButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
WizardPane current = (WizardPane) wizardPanes.pop();
WizardPane previous = (WizardPane) wizardPanes.peek();
backButton.setEnabled(wizardPanes.size() > 1);
WizardPane current = (WizardPane) getWizardPanes().pop();
WizardPane previous = (WizardPane) getWizardPanes().peek();
getBackButton().setEnabled(getWizardPanes().size() > 1);
current.dispose();
previous.open();
dialog.pack();
getDialog().pack();
}
});
nextButton = new Button(composite, SWT.PUSH);
nextButton.setText("Next >");
nextButton.setText(textBundle.get("NextButton")); //$NON-NLS-1$
nextButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
WizardPane current = (WizardPane) wizardPanes.peek();
WizardPane current = (WizardPane) getWizardPanes().peek();
WizardPane next = current.getNextPane();
wizardPanes.add(next);
backButton.setEnabled(wizardPanes.size() > 1);
getWizardPanes().add(next);
getBackButton().setEnabled(getWizardPanes().size() > 1);
current.dispose();
next.open();
dialog.pack();
getDialog().pack();
}
});
finishButton = new Button(composite, SWT.PUSH);
finishButton.setEnabled(false);
finishButton.setText("Finish");
finishButton.setText(textBundle.get("FinishButton")); //$NON-NLS-1$
finishButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
wizardCompleted = true;
dialog.close();
setWizardCompleted(true);
getDialog().close();
}
});
@ -208,4 +210,22 @@ public abstract class Wizard {
public Shell getDialog() {
return dialog;
}
/**
* @return Returns the backButton.
*/
protected Button getBackButton() {
return backButton;
}
/**
* @return Returns the wizardPanes.
*/
protected Stack getWizardPanes() {
return wizardPanes;
}
/**
* @param wizardCompleted The wizardCompleted to set.
*/
protected void setWizardCompleted(boolean wizardCompleted) {
this.wizardCompleted = wizardCompleted;
}
}

View File

@ -26,6 +26,7 @@ import org.eclipse.swt.widgets.Label;
import com.webcodepro.applecommander.storage.Disk;
import com.webcodepro.applecommander.storage.FormattedDisk;
import com.webcodepro.applecommander.ui.TextBundle;
import com.webcodepro.applecommander.ui.swt.wizard.WizardPane;
import com.webcodepro.applecommander.util.AppleUtil;
@ -35,6 +36,7 @@ import com.webcodepro.applecommander.util.AppleUtil;
* @author Rob Greene
*/
public class CompareDisksResultsPane extends WizardPane {
private TextBundle textBundle = TextBundle.getInstance();
private Composite parent;
private Object layoutData;
private Composite control;
@ -71,18 +73,18 @@ public class CompareDisksResultsPane extends WizardPane {
label.setText(message);
label = new Label(control, SWT.WRAP);
label.setText("If you wish to compare more disks, click previous and start again.");
label.setText(textBundle.get("CompareDisksResultsPane.RestartText")); //$NON-NLS-1$
}
/**
* Get the next pane. A null return indicates the end of the wizard.
* @see com.webcodepro.applecommander.gui.WizardPane#getNextPane()
* @see com.webcodepro.applecommander.ui.swt.wizard.WizardPane#getNextPane()
*/
public WizardPane getNextPane() {
return null;
}
/**
* Dispose of resources.
* @see com.webcodepro.applecommander.gui.WizardPane#dispose()
* @see com.webcodepro.applecommander.ui.swt.wizard.WizardPane#dispose()
*/
public void dispose() {
control.dispose();
@ -95,41 +97,44 @@ public class CompareDisksResultsPane extends WizardPane {
try {
disk1 = new Disk(wizard.getDiskname1()).getFormattedDisks();
} catch (Throwable t) {
errorMessages.append("Unable to load disk #1: ");
errorMessages.append(t.getMessage());
errorMessages.append("\n");
errorMessages.append(textBundle.
format("CompareDisksResultsPane.UnableToLoadDiskN", //$NON-NLS-1$
new Object[] { new Integer(1), t.getLocalizedMessage() }));
}
FormattedDisk[] disk2 = null;
try {
disk2 = new Disk(wizard.getDiskname2()).getFormattedDisks();
} catch (Throwable t) {
errorMessages.append("Unable to load disk #2: ");
errorMessages.append(t.getMessage());
errorMessages.append("\n");
errorMessages.append(textBundle.
format("CompareDisksResultsPane.UnableToLoadDiskN", //$NON-NLS-1$
new Object[] { new Integer(2), t.getLocalizedMessage() }));
}
if (disk1 != null && disk2 != null) {
if (disk1.length != disk2.length) {
errorMessages.append("The two disks are of differing formats - unable to compare.\n");
errorMessages.append(textBundle.get(
"CompareDisksResultsPane.DifferentSizeError")); //$NON-NLS-1$
} else {
boolean disk1TSformat = disk1[0].isCpmFormat() || disk1[0].isDosFormat() || disk1[0].isRdosFormat();
boolean disk2TSformat = disk2[0].isCpmFormat() || disk2[0].isDosFormat() || disk2[0].isRdosFormat();
if (disk1TSformat && disk2TSformat) {
if (!AppleUtil.disksEqualByTrackAndSector(disk1[0], disk2[0])) {
errorMessages.append("The two disks do not contain the same data.\n");
errorMessages.append(textBundle.get(
"CompareDisksResultsPane.DataDiffersMessage")); //$NON-NLS-1$
}
} else if (!disk1TSformat && !disk2TSformat) {
if (!AppleUtil.disksEqualByBlock(disk1[0], disk2[0])) {
errorMessages.append("The two disks do not contain the same data.\n");
errorMessages.append(textBundle.get(
"CompareDisksResultsPane.DataDiffersMessage")); //$NON-NLS-1$
}
} else {
errorMessages.append("The two disks are not the same data format.\n");
errorMessages.append(textBundle.get(
"CompareDisksResultsPane.DifferentDataFormatError")); //$NON-NLS-1$
}
}
}
if (errorMessages.length() == 0) {
return "The disk images match.";
} else {
return errorMessages.toString();
return textBundle.get("CompareDisksResultsPane.DisksMatch"); //$NON-NLS-1$
}
return errorMessages.toString();
}
}

View File

@ -33,6 +33,7 @@ import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import com.webcodepro.applecommander.ui.TextBundle;
import com.webcodepro.applecommander.ui.swt.wizard.WizardPane;
/**
@ -41,6 +42,7 @@ import com.webcodepro.applecommander.ui.swt.wizard.WizardPane;
* @author Rob Greene
*/
public class CompareDisksStartPane extends WizardPane {
private TextBundle textBundle = TextBundle.getInstance();
private Composite parent;
private Object layoutData;
private Composite control;
@ -73,10 +75,10 @@ public class CompareDisksStartPane extends WizardPane {
layout.spacing = 3;
control.setLayout(layout);
Label label = new Label(control, SWT.WRAP);
label.setText("This wizard will compare two disk images. Please\n" + "choose the images and click the next button.\n");
label.setText(textBundle.get("CompareDisksStartPane.Description")); //$NON-NLS-1$
label = new Label(control, SWT.WRAP);
label.setText("Please select disk image #1:");
label.setText(getDiskLabel(1));
diskname1Text = new Text(control, SWT.WRAP | SWT.BORDER);
if (wizard.getDiskname1() != null) diskname1Text.setText(wizard.getDiskname1());
@ -86,27 +88,26 @@ public class CompareDisksStartPane extends WizardPane {
diskname1Text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
Text text = (Text) event.getSource();
wizard.setDiskname1(text.getText());
getWizard().setDiskname1(text.getText());
}
});
Button button = new Button(control, SWT.PUSH);
button.setText("Browse...");
button.setText(textBundle.get("BrowseButton")); //$NON-NLS-1$
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog fileDialog = new FileDialog(control.getShell());
fileDialog.setFilterPath(diskname1Text.getText());
fileDialog.setText(
"Please disk image #1");
FileDialog fileDialog = new FileDialog(getControl().getShell());
fileDialog.setFilterPath(getDiskname1Text().getText());
fileDialog.setText(getDiskLabel(1));
String filename = fileDialog.open();
if (filename != null) {
diskname1Text.setText(filename);
getDiskname1Text().setText(filename);
}
}
});
label = new Label(control, SWT.WRAP);
label.setText("Please select disk image #2:");
label.setText(getDiskLabel(2));
diskname2Text = new Text(control, SWT.WRAP | SWT.BORDER);
if (wizard.getDiskname2() != null) diskname2Text.setText(wizard.getDiskname2());
@ -115,38 +116,53 @@ public class CompareDisksStartPane extends WizardPane {
diskname2Text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
Text text = (Text) event.getSource();
wizard.setDiskname2(text.getText());
getWizard().setDiskname2(text.getText());
}
});
button = new Button(control, SWT.PUSH);
button.setText("Browse...");
button.setText(textBundle.get("BrowseButton")); //$NON-NLS-1$
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog fileDialog = new FileDialog(control.getShell());
fileDialog.setFilterPath(diskname2Text.getText());
fileDialog.setText(
"Please disk image #2");
FileDialog fileDialog = new FileDialog(getControl().getShell());
fileDialog.setFilterPath(getDiskname2Text().getText());
fileDialog.setText(getDiskLabel(2));
String filename = fileDialog.open();
if (filename != null) {
diskname2Text.setText(filename);
getDiskname2Text().setText(filename);
}
}
});
}
/**
* Get the next pane. A null return indicates the end of the wizard.
* @see com.webcodepro.applecommander.gui.WizardPane#getNextPane()
* @see com.webcodepro.applecommander.ui.swt.wizard.WizardPane#getNextPane()
*/
public WizardPane getNextPane() {
return new CompareDisksResultsPane(parent, wizard, layoutData);
}
/**
* Dispose of resources.
* @see com.webcodepro.applecommander.gui.WizardPane#dispose()
* @see com.webcodepro.applecommander.ui.swt.wizard.WizardPane#dispose()
*/
public void dispose() {
control.dispose();
control = null;
}
protected Composite getControl() {
return control;
}
protected Text getDiskname1Text() {
return diskname1Text;
}
protected Text getDiskname2Text() {
return diskname2Text;
}
protected CompareDisksWizard getWizard() {
return wizard;
}
protected String getDiskLabel(int diskNumber) {
return textBundle.format("CompareDisksStartPane.DiskNLabel", //$NON-NLS-1$
new Object[] { new Integer(diskNumber) });
}
}

View File

@ -21,6 +21,7 @@ package com.webcodepro.applecommander.ui.swt.wizard.comparedisks;
import org.eclipse.swt.widgets.Shell;
import com.webcodepro.applecommander.ui.TextBundle;
import com.webcodepro.applecommander.ui.swt.util.ImageManager;
import com.webcodepro.applecommander.ui.swt.wizard.Wizard;
import com.webcodepro.applecommander.ui.swt.wizard.WizardPane;
@ -37,11 +38,12 @@ public class CompareDisksWizard extends Wizard {
* Constructor for ExportWizard.
*/
public CompareDisksWizard(Shell parent, ImageManager imageManager) {
super(parent, imageManager.get(ImageManager.LOGO_COMPARE_IMAGE_WIZARD), "Compare Disks Wizard");
super(parent, imageManager.get(ImageManager.LOGO_COMPARE_IMAGE_WIZARD),
TextBundle.getInstance().get("CompareDisksTitle")); //$NON-NLS-1$
}
/**
* Create the initial display used in the wizard.
* @see com.webcodepro.applecommander.ui.swt.Wizard#createInitialWizardPane()
* @see com.webcodepro.applecommander.ui.swt.wizard.Wizard#createInitialWizardPane()
*/
public WizardPane createInitialWizardPane() {
return new CompareDisksStartPane(getContentPane(), this, null);

View File

@ -33,6 +33,7 @@ import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import com.webcodepro.applecommander.ui.TextBundle;
import com.webcodepro.applecommander.ui.swt.wizard.WizardPane;
/**
@ -42,6 +43,7 @@ import com.webcodepro.applecommander.ui.swt.wizard.WizardPane;
* @author Rob Greene
*/
public class CompileFileStartPane extends WizardPane {
private TextBundle textBundle = TextBundle.getInstance();
private Composite parent;
private Object layoutData;
private Composite control;
@ -73,12 +75,10 @@ public class CompileFileStartPane extends WizardPane {
layout.spacing = 3;
control.setLayout(layout);
Label label = new Label(control, SWT.WRAP);
label.setText("Please note that the current compiler is \n"
+ "very BETA and simply builds an assembly program \n"
+ "and stores it on your harddisk...");
label.setText(textBundle.get("CompileFileWarning")); //$NON-NLS-1$
label = new Label(control, SWT.WRAP);
label.setText("Please indicate the destination for the files:");
label.setText(textBundle.get("CompileFileDestinationPrompt")); //$NON-NLS-1$
directoryText = new Text(control, SWT.WRAP | SWT.BORDER);
if (wizard.getDirectory() != null) directoryText.setText(wizard.getDirectory());
@ -88,38 +88,51 @@ public class CompileFileStartPane extends WizardPane {
directoryText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
Text text = (Text) event.getSource();
wizard.setDirectory(text.getText());
getWizard().setDirectory(text.getText());
}
});
Button button = new Button(control, SWT.PUSH);
button.setText("Browse...");
button.setText(textBundle.get("BrowseButton")); //$NON-NLS-1$
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
DirectoryDialog directoryDialog = new DirectoryDialog(control.getShell());
directoryDialog.setFilterPath(directoryText.getText());
directoryDialog.setMessage(
"Please choose the directory to which exported files will be written");
DirectoryDialog directoryDialog = new DirectoryDialog(
getControl().getShell());
directoryDialog.setFilterPath(getDirectoryText().getText());
directoryDialog.setMessage(TextBundle.getInstance().
get("CompileFileDirectoryPrompt")); //$NON-NLS-1$
String directory = directoryDialog.open();
if (directory != null) {
directoryText.setText(directory);
getDirectoryText().setText(directory);
}
}
});
}
/**
* Get the next pane. A null return indicates the end of the wizard.
* @see com.webcodepro.applecommander.gui.WizardPane#getNextPane()
* @see com.webcodepro.applecommander.ui.swt.wizard.WizardPane#getNextPane()
*/
public WizardPane getNextPane() {
return null;
}
/**
* Dispose of resources.
* @see com.webcodepro.applecommander.gui.WizardPane#dispose()
* @see com.webcodepro.applecommander.ui.swt.wizard.WizardPane#dispose()
*/
public void dispose() {
control.dispose();
control = null;
}
protected Composite getControl() {
return control;
}
protected Text getDirectoryText() {
return directoryText;
}
protected CompileWizard getWizard() {
return wizard;
}
}

View File

@ -22,6 +22,7 @@ package com.webcodepro.applecommander.ui.swt.wizard.compilefile;
import org.eclipse.swt.widgets.Shell;
import com.webcodepro.applecommander.storage.FormattedDisk;
import com.webcodepro.applecommander.ui.TextBundle;
import com.webcodepro.applecommander.ui.swt.util.ImageManager;
import com.webcodepro.applecommander.ui.swt.wizard.Wizard;
import com.webcodepro.applecommander.ui.swt.wizard.WizardPane;
@ -39,7 +40,8 @@ public class CompileWizard extends Wizard {
* Constructor for ExportWizard.
*/
public CompileWizard(Shell parent, ImageManager imageManager, FormattedDisk disk) {
super(parent, imageManager.get(ImageManager.LOGO_COMPILE_WIZARD), "Compile Wizard");
super(parent, imageManager.get(ImageManager.LOGO_COMPILE_WIZARD),
TextBundle.getInstance().get("CompileWizardTitle")); //$NON-NLS-1$
this.disk = disk;
}
/**
@ -50,7 +52,7 @@ public class CompileWizard extends Wizard {
}
/**
* Create the initial display used in the wizard.
* @see com.webcodepro.applecommander.ui.swt.Wizard#createInitialWizardPane()
* @see com.webcodepro.applecommander.ui.swt.wizard.Wizard#createInitialWizardPane()
*/
public WizardPane createInitialWizardPane() {
return new CompileFileStartPane(getContentPane(), this, null);