use of com.servoy.j2db.ISmartClientApplication in project servoy-client by Servoy.
the class SwingForm method willingToPrint.
/**
* @return 0 when ok,1 when cancel,2 when current rec.
*/
private int willingToPrint(IFoundSetInternal formModel) {
// test if foundset is big. if so ask if really want to print/preview
if (formModel.getSize() >= ((FoundSetManager) formModel.getFoundSetManager()).config.pkChunkSize()) {
Object[] options = new String[] { // $NON-NLS-1$
Messages.getString("servoy.button.ok"), // $NON-NLS-1$
Messages.getString("servoy.button.cancel"), // $NON-NLS-1$
Messages.getString("servoy.formPanel.printCurrentRecord") };
ISmartClientApplication application = (ISmartClientApplication) formController.getApplication();
return JOptionPane.showOptionDialog(application.getMainApplicationFrame(), // $NON-NLS-1$
Messages.getString("servoy.formPanel.message.largeResultset", new Object[] { new Integer(formModel.getSize()) }), // $NON-NLS-1$
Messages.getString("servoy.general.warning"), JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[2]);
}
return 0;
}
use of com.servoy.j2db.ISmartClientApplication 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);
}
}
}
}
}
use of com.servoy.j2db.ISmartClientApplication in project servoy-client by Servoy.
the class DataImgMediaField method drop.
public synchronized void drop(DropTargetDropEvent dropTargetDropEvent) {
try {
Transferable tr = dropTargetDropEvent.getTransferable();
if (popup != null && tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
List fileList = (List) tr.getTransferData(DataFlavor.javaFileListFlavor);
Iterator iterator = fileList.iterator();
if (iterator.hasNext()) {
try {
File file = (File) iterator.next();
if (editProvider != null)
editProvider.startEdit();
byte[] content = FileChooserUtils.paintingReadFile(application.getScheduledExecutor(), application, file);
setValueObject(content);
if (editProvider != null)
editProvider.commitData();
// dataprovider_filename and dataprovider_mimetype fields will be set like in the web TODO maybe refactor to avoid cast below and existence of method setValueObject in DataAdapterList
if (resolver instanceof DataAdapterList) {
((DataAdapterList) resolver).setValueObject(dataProviderID + IMediaFieldConstants.FILENAME, file.getName());
((DataAdapterList) resolver).setValueObject(dataProviderID + IMediaFieldConstants.MIMETYPE, MimeTypes.getContentType(content, file.getName()));
}
} 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);
}
}
}
dropTargetDropEvent.getDropTargetContext().dropComplete(true);
} else {
Debug.trace("Rejected");
dropTargetDropEvent.rejectDrop();
}
} catch (Exception io) {
Debug.error(io);
dropTargetDropEvent.rejectDrop();
}
}
Aggregations