本文整理匯總了Java中org.eclipse.swt.widgets.FileDialog類的典型用法代碼示例。如果您正苦於以下問題:Java FileDialog類的具體用法?Java FileDialog怎麽用?Java FileDialog使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FileDialog類屬於org.eclipse.swt.widgets包,在下文中一共展示了FileDialog類的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: updateFile
import org.eclipse.swt.widgets.FileDialog; //導入依賴的package包/類
protected void updateFile ()
{
final FileDialog dlg = new FileDialog ( getShell (), SWT.APPLICATION_MODAL | SWT.SAVE );
dlg.setFilterExtensions ( new String[] { Messages.FileSelectionPage_FilterExtension } );
dlg.setFilterNames ( new String[] { Messages.FileSelectionPage_FilterName } );
dlg.setOverwrite ( true );
dlg.setText ( Messages.FileSelectionPage_FileDialog_Text );
final String fileName = dlg.open ();
if ( fileName == null )
{
setFile ( null );
update ();
}
else
{
setFile ( new File ( fileName ) );
update ();
}
}
示例3: 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...
}
}
}
示例4: 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...
}
}
}
}
示例5: 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();
}
}
}
示例6: importTextFile
import org.eclipse.swt.widgets.FileDialog; //導入依賴的package包/類
protected void importTextFile(File f) {
if (!textEditor.isDisposed()) {
FileDialog fd = new FileDialog(shell, SWT.OPEN);
fd.setText("Import text");
fd.setFilterExtensions(new String[] { "*.txt;*.TXT" });
fd.setFilterNames(new String[] { "Plain text files (*.txt)" });
String selected = fd.open();
if (selected != null) {
try {
textEditor.importText(new File(selected));
} catch (IOException e) {
e.printStackTrace();
MessageBox diag = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
diag.setMessage("Unable to open file " + transcriptionFile.getPath());
diag.open();
}
}
}
}
示例7: 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 ();
}
}
示例8: 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 );
}
}
示例9: 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$
}
}
示例10: handleAdd
import org.eclipse.swt.widgets.FileDialog; //導入依賴的package包/類
protected void handleAdd ()
{
final FileDialog dlg = new FileDialog ( getShell (), SWT.OPEN );
final String result = dlg.open ();
if ( result != null )
{
try
{
this.factory.addFile ( result );
}
catch ( final Exception e )
{
ErrorDialog.openError ( getShell (), "Error", "Failed to add file", StatusHelper.convertStatus ( Activator.PLUGIN_ID, e ) );
}
}
}
示例11: chooseFile
import org.eclipse.swt.widgets.FileDialog; //導入依賴的package包/類
protected void chooseFile ()
{
final FileDialog dlg = new FileDialog ( getShell (), SWT.OPEN | SWT.MULTI );
dlg.setFilterExtensions ( new String[] { "*.xml", "*.*" } );
dlg.setFilterNames ( new String[] { "Eclipse NeoSCADA Exporter Files", "All files" } );
final String result = dlg.open ();
if ( result != null )
{
final File base = new File ( dlg.getFilterPath () );
for ( final String name : dlg.getFileNames () )
{
this.fileText.setText ( new File ( base, name ).getAbsolutePath () );
}
makeDirty ();
}
}
示例12: getSaveFilePath
import org.eclipse.swt.widgets.FileDialog; //導入依賴的package包/類
private static String getSaveFilePath(IEditorPart editorPart, GraphicalViewer viewer, int format) {
FileDialog fileDialog = new FileDialog(editorPart.getEditorSite().getShell(), SWT.SAVE);
String[] filterExtensions = new String[] { "*.jpeg",
"*.bmp"/*
* , "*.ico" , "*.png", "*.gif"
*/ };
if (format == SWT.IMAGE_BMP)
filterExtensions = new String[] { "*.bmp" };
else if (format == SWT.IMAGE_JPEG)
filterExtensions = new String[] { "*.jpeg" };
// else if (format == SWT.IMAGE_ICO)
// filterExtensions = new String[] { "*.ico" };
fileDialog.setFilterExtensions(filterExtensions);
return fileDialog.open();
}
示例13: 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);
}
}
示例14: openFileDirectly
import org.eclipse.swt.widgets.FileDialog; //導入依賴的package包/類
/**
* Open the file dialog for the direct opening of a file. If a file is returned,
* expand the directory tree accordingly.
*/
public void openFileDirectly() {
FileDialog fileDialog = new FileDialog(this.shell, SWT.OPEN);
String[] extensions = {"*.class", "*.jar", "*.war", "*.ear"};
String[] names = {"Class file (*.class)", "Jar archive (*.jar)", "War archive (*.war)", "Ear archive (*.ear)"};
fileDialog.setFilterExtensions(extensions);
fileDialog.setFilterNames(names);
String path = fileDialog.open();
if (path != null) {
// First of all replace double backslashes against slashes.
path = path.replace("\\\\", "\\");
// different handling of class and jar files
if (JarFileEntry.isArchive(path) || (path.length() > 6 && path.substring(path.length() - 6).equals(".class")))
{
// Browse through the directory tree.
browseTroughTheDirectoryTree(path, null);
} else {
StaticGuiSupport.showMessageBox(FileSelectionComposite.this.shell, "Information", "This file cannot be processed.", SWT.OK | SWT.ICON_WARNING);
}
}
}
示例15: run
import org.eclipse.swt.widgets.FileDialog; //導入依賴的package包/類
@Override
public void run() {
ViewDataPreferencesVO viewDataPreferencesVO = debugDataViewer.getViewDataPreferences();
delimiter = viewDataPreferencesVO.getDelimiter();
quoteCharactor = viewDataPreferencesVO.getQuoteCharactor();
headerEnabled = viewDataPreferencesVO.getIncludeHeaders();
TableViewer tableViewer = debugDataViewer.getTableViewer();
List<RowData> eachRowData = getListOfRowData(tableViewer);
List<String[]> exportedfileDataList = new ArrayList<String[]>();
TableColumn[] columns = tableViewer.getTable().getColumns();
if (headerEnabled != null) {
addHeadersInList(tableViewer, exportedfileDataList, columns);
}
addRowsDataInList(tableViewer, eachRowData, exportedfileDataList);
FileDialog fileDialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.SAVE);
String filePath = getPathOfFileDialog(fileDialog);
writeDataInFile(exportedfileDataList, filePath);
}