本文整理匯總了Java中org.eclipse.swt.widgets.FileDialog.setFileName方法的典型用法代碼示例。如果您正苦於以下問題:Java FileDialog.setFileName方法的具體用法?Java FileDialog.setFileName怎麽用?Java FileDialog.setFileName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.swt.widgets.FileDialog
的用法示例。
在下文中一共展示了FileDialog.setFileName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: importText
import org.eclipse.swt.widgets.FileDialog; //導入方法依賴的package包/類
protected void importText() {
if (!textEditor.isDisposed()) {
FileDialog fd = new FileDialog(shell, SWT.OPEN);
fd.setText("Open");
String[] filterExt = { "*.txt;*.TXT" };
String[] filterNames = { "TXT files" };
fd.setFilterExtensions(filterExt);
fd.setFilterNames(filterNames);
String lastPath = Config.getInstance().getString(Config.LAST_OPEN_TEXT_PATH);
if (lastPath != null && !lastPath.isEmpty())
fd.setFileName(lastPath);
String selected = fd.open();
if (selected != null) {
importTextFile(new File(selected));
Config.getInstance().putValue(Config.LAST_OPEN_TEXT_PATH, selected);
try {
Config.getInstance().save();
} catch (IOException e) {
// The user do not NEED to know about this...
}
}
}
}
示例2: openNewAudio
import org.eclipse.swt.widgets.FileDialog; //導入方法依賴的package包/類
protected void openNewAudio() {
FileDialog fd = new FileDialog(shell, SWT.OPEN);
fd.setText("Select the audio file");
String[] filterExt = { "*.wav;*.WAV;*.mp3;*.MP3", "*.*" };
String[] filterNames = { "WAV and MP3 files", "All files" };
fd.setFilterExtensions(filterExt);
fd.setFilterNames(filterNames);
String lastPath = Config.getInstance().getString(Config.LAST_OPEN_AUDIO_PATH);
if (lastPath != null && lastPath.isEmpty())
fd.setFileName(lastPath);
String selected = fd.open();
if (selected != null) {
closePlayer();
openAudioFile(new File(selected));
Config.getInstance().putValue(Config.LAST_OPEN_AUDIO_PATH, selected);
try {
Config.getInstance().save();
} catch (IOException e) {
// The user do not NEED to know about this...
}
}
}
示例3: openTranscription
import org.eclipse.swt.widgets.FileDialog; //導入方法依賴的package包/類
public void openTranscription() {
if (!textEditor.isDisposed()) {
FileDialog fd = new FileDialog(shell, SWT.OPEN);
fd.setText("Select the transcription file");
String[] filterExt = { "*.xpmt;*.XPMT" };
String[] filterNames = { "pmTrans transcription files" };
fd.setFilterExtensions(filterExt);
fd.setFilterNames(filterNames);
String lastPath = Config.getInstance().getString(Config.LAST_OPEN_TEXT_PATH);
if (lastPath != null && !lastPath.isEmpty())
fd.setFileName(lastPath);
String selected = fd.open();
if (selected != null) {
openTranscriptionFile(new File(selected));
Config.getInstance().putValue(Config.LAST_OPEN_TEXT_PATH, selected);
try {
Config.getInstance().save();
} catch (IOException e) {
// The user do not NEED to know about this...
}
}
}
}
示例4: exportTextFile
import org.eclipse.swt.widgets.FileDialog; //導入方法依賴的package包/類
protected void exportTextFile() {
boolean done = false;
while (!done)
if (!textEditor.isDisposed()) {
FileDialog fd = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
fd.setFilterNames(new String[] { "Plain text file (*.txt)", "All Files (*.*)" });
fd.setFilterExtensions(new String[] { "*.txt", "*.*" });
String lastPath = Config.getInstance().getString(Config.LAST_EXPORT_TRANSCRIPTION_PATH);
if (lastPath != null && !lastPath.isEmpty())
fd.setFileName(lastPath);
String file = fd.open();
try {
if (file != null) {
Config.getInstance().putValue(Config.LAST_EXPORT_TRANSCRIPTION_PATH, file);
File destFile = new File(file);
boolean overwrite = true;
if (destFile.exists())
overwrite = MessageDialog.openConfirm(shell, "Overwrite current file?",
"Would you like to overwrite " + destFile.getName() + "?");
if (overwrite) {
textEditor.exportText(new File(file));
done = true;
}
} else
done = true;
} catch (Exception e) {
e.printStackTrace();
MessageBox diag = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
diag.setMessage("Unable to export to file " + transcriptionFile.getPath());
diag.open();
}
}
}
示例5: selectFile
import org.eclipse.swt.widgets.FileDialog; //導入方法依賴的package包/類
protected void selectFile ()
{
final FileDialog dlg = new FileDialog ( getShell (), SWT.OPEN );
dlg.setFilterExtensions ( new String[] { "*.oscar", "*.json", "*.*" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dlg.setFilterNames ( new String[] { Messages.LocalDataPage_OSCARFilterDescription, Messages.LocalDataPage_JSONFilterDescription, Messages.LocalDataPage_AllFilterDescription } );
if ( this.fileName.getText ().length () > 0 )
{
dlg.setFileName ( this.fileName.getText () );
}
dlg.setFilterIndex ( 0 );
final String file = dlg.open ();
if ( file != null )
{
this.fileName.setText ( file );
loadFile ();
}
}
示例6: handleLoadLocal
import org.eclipse.swt.widgets.FileDialog; //導入方法依賴的package包/類
protected void handleLoadLocal ()
{
final FileDialog dlg = new FileDialog ( getShell (), SWT.OPEN );
dlg.setFilterExtensions ( new String[] { "*.oscar", "*.json", "*.*" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dlg.setFilterNames ( new String[] { Messages.LocalDataPage_OSCARFilterDescription, Messages.LocalDataPage_JSONFilterDescription, Messages.LocalDataPage_AllFilterDescription } );
final String selectedFileName = getWizard ().getDialogSettings ().get ( "localDataPage.file" ); //$NON-NLS-1$
if ( selectedFileName != null && selectedFileName.length () > 0 )
{
dlg.setFileName ( selectedFileName );
}
dlg.setFilterIndex ( 0 );
final String file = dlg.open ();
if ( file != null )
{
getWizard ().getDialogSettings ().put ( "localDataPage.file", file ); //$NON-NLS-1$
loadFromLocalFile ( file );
}
}
示例7: handleSelectFile
import org.eclipse.swt.widgets.FileDialog; //導入方法依賴的package包/類
protected void handleSelectFile ()
{
final FileDialog dlg = new FileDialog ( getShell (), SWT.SAVE );
dlg.setFilterExtensions ( new String[] { "*.oscar", "*.*" } ); //$NON-NLS-1$ //$NON-NLS-2$
dlg.setFilterNames ( new String[] { Messages.FileNamePage_OSCARFileType, Messages.FileNamePage_AllTypes } );
if ( this.fileName.getText ().length () > 0 )
{
dlg.setFileName ( this.fileName.getText () );
}
dlg.setFilterIndex ( 0 );
final String file = dlg.open ();
if ( file != null )
{
this.fileName.setText ( file );
getWizard ().getDialogSettings ().put ( "fileNamePage.file", file ); //$NON-NLS-1$
}
}
示例8: saveAs
import org.eclipse.swt.widgets.FileDialog; //導入方法依賴的package包/類
/**
* Handle SaveAs.
*/
protected void saveAs() {
FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
fileDialog.setFilterPath(userPreferences.getSaveDirectory());
fileDialog.setFileName(Host.getFileName(disks[0].getFilename()));
fileDialog.setText(textBundle.get("SaveDiskImageAsPrompt")); //$NON-NLS-1$
String fullpath = fileDialog.open();
userPreferences.setSaveDirectory(fileDialog.getFilterPath());
if (fullpath == null) {
return; // user pressed cancel
}
try {
disks[0].saveAs(fullpath);
diskWindow.setStandardWindowTitle();
saveToolItem.setEnabled(disks[0].hasChanged());
} catch (IOException ex) {
showSaveError(ex);
}
}
示例9: exportBookList
import org.eclipse.swt.widgets.FileDialog; //導入方法依賴的package包/類
public void exportBookList() {
try {
String ext = "*.csv";
String name = "CSV (Excel) File";
FileDialog dialog = new FileDialog(shell, SWT.SAVE);
dialog.setFilterNames(new String[]{name});
dialog.setFilterExtensions(new String[]{ext});
dialog.setFileName("books.csv");
String path = dialog.open();
if (path != null) {
File f = new File(path);
audibleGUI.audible.export(f);
if (f.exists())
logger.info("exported books to: "+f.getAbsolutePath());
}
} catch (Exception e) {
MessageBoxFactory.showError(shell, e.getMessage());
}
}
示例10: exportBookJSON
import org.eclipse.swt.widgets.FileDialog; //導入方法依賴的package包/類
public void exportBookJSON() {
try {
String ext = "*.json";
String name = "JSON File";
FileDialog dialog = new FileDialog(shell, SWT.SAVE);
dialog.setFilterNames(new String[]{name});
dialog.setFilterExtensions(new String[]{ext});
dialog.setFileName("books.json");
String path = dialog.open();
if (path != null) {
File f = new File(path);
audibleGUI.audible.export(f);
if (f.exists())
logger.info("exported books to: "+f.getAbsolutePath());
}
} catch (Exception e) {
MessageBoxFactory.showError(shell, e.getMessage());
}
}
示例11: run
import org.eclipse.swt.widgets.FileDialog; //導入方法依賴的package包/類
public void run(){
try {
FileDialog fileDialog = new FileDialog(view.getSite().getShell(), SWT.SAVE);
fileDialog.setFileName("http4e.jmx");
fileDialog.setFilterNames(new String[] { "JMeter File *.jmx (Run the script with \"jmeter-t.cmd\")" });
fileDialog.setFilterExtensions(new String[] { "*.jmx" });
fileDialog.setText("Save As JMeter script (Run the script with \"jmeter-t.cmd\")");
fileDialog.setFilterPath(getUserHomeDir());
String path = fileDialog.open();
if (path != null) {
HdViewPart hdView = (HdViewPart) view;
BaseUtils.writeJMX(path, hdView.getFolderView().getModel());
updateUserHomeDir(path);
}
} catch (Exception e) {
ExceptionHandler.handle(e);
}
}
示例12: run
import org.eclipse.swt.widgets.FileDialog; //導入方法依賴的package包/類
public void run(){
try {
FileDialog fileDialog = new FileDialog(view.getSite().getShell(), SWT.SAVE);
fileDialog.setFileName("sessions.http4e");
fileDialog.setFilterNames(new String[] { "HTTP4e File *.http4e (HTTP4e all tab sessions)" });
fileDialog.setFilterExtensions(new String[] { "*.http4e" });
fileDialog.setText("Save As HTTP4e replay script");
fileDialog.setFilterPath(getUserHomeDir());
String path = fileDialog.open();
if (path != null) {
HdViewPart hdView = (HdViewPart) view;
BaseUtils.writeHttp4eSessions(path, hdView.getFolderView().getModel());
updateUserHomeDir(path);
}
} catch (Exception e) {
ExceptionHandler.handle(e);
}
}
示例13: saveImage
import org.eclipse.swt.widgets.FileDialog; //導入方法依賴的package包/類
private void saveImage() {
if (canSaveImage()) {
final FileDialog saveDialog = new FileDialog(canvas.getShell(), SWT.SAVE);
saveDialog.setFilterExtensions(new String[] { "*.JPG;*.jpg" });
saveDialog.setFileName(guid.toLowerCase() + ".jpg");
saveDialog.setOverwrite(true);
final String fileName = saveDialog.open();
if (fileName != null && fileName.trim().isEmpty()) {
try {
Files.write(Paths.get(fileName), cache.get(guid).getBytes());
}
catch (final Exception e) {
final String message = Messages.get("err.image.save", fileName);
logger.log(Level.WARNING, message, e);
EnhancedErrorDialog.openError(canvas.getShell(), Messages.get("lbl.window.title"), message, IStatus.WARNING, e, Images.getMainIcons());
}
}
}
}
示例14: getFile
import org.eclipse.swt.widgets.FileDialog; //導入方法依賴的package包/類
private File[] getFile(File startingDirectory) {
int style = SWT.OPEN;
if (multiple) {
style |= SWT.MULTI;
}
final FileDialog dialog = new FileDialog(getShell(), style);
if (startingDirectory != null) {
dialog.setFileName(startingDirectory.getPath());
}
if (extensions != null) {
dialog.setFilterExtensions(extensions);
}
dialog.open();
final String[] fileNames = dialog.getFileNames();
if (fileNames.length > 0) {
final File[] files = new File[fileNames.length];
for (int i = 0; i < fileNames.length; i++) {
files[i] = new File(dialog.getFilterPath(), fileNames[i]);
}
return files;
}
return null;
}
示例15: onSelectBrowseFile
import org.eclipse.swt.widgets.FileDialog; //導入方法依賴的package包/類
private void onSelectBrowseFile() {
final String fileExtension = _exportExtensionPoint.getFileExtension();
final FileDialog dialog = new FileDialog(_dlgContainer.getShell(), SWT.SAVE);
dialog.setText(Messages.dialog_export_file_dialog_text);
dialog.setFilterPath(getExportPathName());
dialog.setFilterExtensions(new String[] { fileExtension });
dialog.setFileName("*." + fileExtension);//$NON-NLS-1$
final String selectedFilePath = dialog.open();
if (selectedFilePath != null) {
setErrorMessage(null);
_comboFile.setText(new Path(selectedFilePath).toFile().getName());
}
}