use of com.servoy.j2db.util.gui.FileNameSuggestionFileChooser in project servoy-client by Servoy.
the class FileChooserUtils method getAWriteFile.
public static File getAWriteFile(Component parent, File file, boolean doFileSuggestion, String title) {
JFileChooser fc = null;
if (file != null) {
if (file.isDirectory()) {
fc = new JFileChooser(file);
lastDir = file;
} else if (doFileSuggestion) {
fc = new FileNameSuggestionFileChooser(file.getParentFile());
lastDir = file.getParentFile();
((FileNameSuggestionFileChooser) fc).suggestFileName(file.getName());
}
} else {
fc = new JFileChooser(lastDir);
}
if (fc != null) {
if (title == null) {
// $NON-NLS-1$
fc.setDialogTitle(Messages.getString("servoy.filechooser.title"));
} else {
fc.setDialogTitle(title);
}
// $NON-NLS-1$);
fc.setApproveButtonText(Messages.getString("servoy.filechooser.button.title"));
int returnVal = fc.showSaveDialog(parent);
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = fc.getSelectedFile();
lastDir = fc.getCurrentDirectory();
} else {
file = null;
}
}
return file;
}
use of com.servoy.j2db.util.gui.FileNameSuggestionFileChooser in project servoy-client by Servoy.
the class DataImgMediaField method saveToFile.
void saveToFile() {
if (value instanceof byte[]) {
byte[] array = (byte[]) value;
FileNameSuggestionFileChooser fc = new FileNameSuggestionFileChooser();
String fileName = null;
// dataprovider_filename and dataprovider_mimetype fields will be used like in the web TODO maybe refactor to avoid cast below
if (resolver instanceof DataAdapterList) {
Object val = ((DataAdapterList) resolver).getValueObject(((DataAdapterList) resolver).getState(), dataProviderID + IMediaFieldConstants.FILENAME);
fileName = (val instanceof String) ? (String) val : null;
}
if (fileName != null) {
fc.suggestFileName(fileName);
} else if (// jpeg
array.length > 3 && array[0] == -1 && array[1] == -40 && array[2] == -1) {
fc.suggestFileName("image.jpg");
} else if (// gif
array.length > 3 && array[0] == 0x47 && array[1] == 0x49 && array[2] == 0x46) {
fc.suggestFileName("image.gif");
} else {
fc.suggestFileName("filename.unknown");
}
int returnVal = fc.showSaveDialog(((ISmartClientApplication) application).getMainApplicationFrame());
if (returnVal == JFileChooser.APPROVE_OPTION) {
try {
File f = fc.getSelectedFile();
OutputStream os = new FileOutputStream(f);
BufferedOutputStream bos = new BufferedOutputStream(os);
bos.write(array);
bos.close();
} catch (Exception e) {
if (application instanceof ISmartClientApplication) {
((ISmartClientApplication) application).reportError(this, application.getI18NMessage("servoy.imageMedia.error.loading"), e);
} else {
application.reportError(application.getI18NMessage("servoy.imageMedia.error.loading"), e);
}
}
}
}
}
Aggregations