Bug fix: don't truncate file/volume name in create wizard.

This commit is contained in:
John B. Matthews 2008-08-24 01:16:47 +00:00
parent 4fd53b91e1
commit e0b0cb5d8b
2 changed files with 44 additions and 25 deletions

View File

@ -40,7 +40,7 @@ import com.webcodepro.applecommander.util.TextBundle;
* @author Rob Greene * @author Rob Greene
*/ */
public class AppleCommander { public class AppleCommander {
public static final String VERSION = "1.3.5.1"; //$NON-NLS-1$ public static final String VERSION = "1.3.5.2"; //$NON-NLS-1$
private static TextBundle textBundle = UiBundle.getInstance(); private static TextBundle textBundle = UiBundle.getInstance();
/** /**
* Launch AppleCommander. * Launch AppleCommander.

View File

@ -20,12 +20,12 @@
package com.webcodepro.applecommander.ui.swt.wizard.diskimage; package com.webcodepro.applecommander.ui.swt.wizard.diskimage;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.layout.RowData; import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import com.webcodepro.applecommander.ui.UiBundle; import com.webcodepro.applecommander.ui.UiBundle;
@ -37,7 +37,7 @@ import com.webcodepro.applecommander.util.TextBundle;
* volume name, if appropriate. * volume name, if appropriate.
* <br> * <br>
* Created on Dec 16, 2002. * Created on Dec 16, 2002.
* @author Rob Greene * @author Rob Greene, John B. Matthews
*/ */
public class DiskImageNamePane extends WizardPane { public class DiskImageNamePane extends WizardPane {
private TextBundle textBundle = UiBundle.getInstance(); private TextBundle textBundle = UiBundle.getInstance();
@ -61,6 +61,9 @@ public class DiskImageNamePane extends WizardPane {
} }
/** /**
* Create the wizard pane. * Create the wizard pane.
* Listen for Verify events on the Text widgets.
* Require upper case for optional volume name.
* Preserve names when navigating among panes.
* @see com.webcodepro.applecommander.ui.swt.wizard.WizardPane#open() * @see com.webcodepro.applecommander.ui.swt.wizard.WizardPane#open()
*/ */
public void open() { public void open() {
@ -78,50 +81,66 @@ public class DiskImageNamePane extends WizardPane {
Label label = new Label(control, SWT.WRAP); Label label = new Label(control, SWT.WRAP);
label.setText( label.setText(
textBundle.get("DiskImageNamePrompt")); //$NON-NLS-1$ textBundle.get("DiskImageNamePrompt")); //$NON-NLS-1$
final Text filename = new Text(control, SWT.BORDER); final Text fileName = new Text(control, SWT.BORDER);
filename.setFocus(); fileName.setFocus();
RowData rowData = new RowData(); RowData rowData = new RowData();
rowData.width = parent.getClientArea().width - 50; rowData.width = parent.getClientArea().width - 50;
filename.setLayoutData(rowData); fileName.setLayoutData(rowData);
filename.setText(wizard.getFileName()); fileName.setText(wizard.getFileName());
filename.addKeyListener(new KeyAdapter() { setButtonStatus();
public void keyPressed(KeyEvent event) { fileName.addListener(SWT.Verify, new Listener() {
getWizard().setFileName(filename.getText()); public void handleEvent(Event e) {
setButtonStatus(); String s = edit(fileName.getText(), e);
wizard.setFileName(s);
setButtonStatus();
} }
}); });
if (wizard.isFormatProdos() || wizard.isFormatPascal()) { if (wizard.isFormatProdos() || wizard.isFormatPascal()) {
int maxLength = wizard.isFormatProdos() ? 15 : 7; int maxLength = wizard.isFormatProdos() ? 15 : 7;
label = new Label(control, SWT.WRAP); label = new Label(control, SWT.WRAP);
Object[] objects = new Object[2]; Object[] objects = new Object[2];
objects[0] = wizard.isFormatProdos() ? textBundle.get("Prodos") //$NON-NLS-1$ objects[0] = wizard.isFormatProdos()
? textBundle.get("Prodos") //$NON-NLS-1$
: textBundle.get("Pascal"); //$NON-NLS-1$ : textBundle.get("Pascal"); //$NON-NLS-1$
objects[1] = new Integer(maxLength); objects[1] = new Integer(maxLength);
label.setText(textBundle.format( label.setText(textBundle.format(
"DiskImageNameLengthText", objects)); //$NON-NLS-1$ "DiskImageNameLengthText", objects)); //$NON-NLS-1$
final Text volumename = new Text(control, SWT.BORDER); final Text volumeName = new Text(control, SWT.BORDER);
volumename.setText(wizard.getVolumeName()); volumeName.setText(wizard.getVolumeName());
volumename.setTextLimit(maxLength); volumeName.setTextLimit(maxLength);
volumename.addKeyListener(new KeyAdapter() { volumeName.addListener(SWT.Verify, new Listener() {
public void keyPressed(KeyEvent event) { public void handleEvent(Event e) {
getWizard().setVolumeName(volumename.getText().toUpperCase()); e.text = e.text.toUpperCase();
setButtonStatus(); String s = edit(volumeName.getText(), e);
wizard.setVolumeName(s);
setButtonStatus();
} }
}); });
} }
} }
/**
* Edit a name in response to a Verify event.
* @param name the existing name
* @param e the verification event
* @return the modified name
*/
private String edit(String name, Event e) {
if (e.character != '\b') return name + e.text;
else return name.substring(0, name.length() - 1);
}
/** /**
* Enable the Next button when data has been entered into all fields. * Enable the Next button when data has been entered into all fields.
*/ */
protected void setButtonStatus() { protected void setButtonStatus() {
String volumeName = wizard.getVolumeName(); String vName = wizard.getVolumeName();
String fileName = wizard.getFileName(); String fName = wizard.getFileName();
if (wizard.isFormatProdos() || wizard.isFormatPascal()) { if (wizard.isFormatProdos() || wizard.isFormatPascal()) {
wizard.enableNextButton( wizard.enableNextButton(
fileName != null && fileName.length() > 0 fName != null && fName.length() > 0
&& volumeName != null && volumeName.length() > 0); && vName != null && vName.length() > 0
&& vName.charAt(0) >= 'A' && vName.charAt(0) <= 'Z');
} else { } else {
wizard.enableNextButton(fileName != null && fileName.length() > 0); wizard.enableNextButton(fName != null && fName.length() > 0);
} }
} }
/** /**