*/
private void showBestInstance() throws PhotovaultException {
// Find the original file
EnumSet<ImageOperations> allowedOps = EnumSet.allOf( ImageOperations.class );
allowedOps.removeAll( dynOps );
ImageInstance instance = photo.getPreferredInstance(
EnumSet.noneOf( ImageOperations.class ),
allowedOps,
imageView.getWidth(), imageView.getHeight() );
if ( instance != null ) {
File imageFile = instance.getImageFile();
if ( imageFile != null && imageFile.canRead() ) {
// TODO: is this really needed?
String fname = imageFile.getName();
int lastDotPos = fname.lastIndexOf( "." );
if ( lastDotPos <= 0 || lastDotPos >= fname.length()-1 ) {
// TODO: error handling needs thinking!!!!
// throw new IOException( "Cannot determine file type extension of " + imageFile.getAbsolutePath() );
fireViewChangeEvent();
return;
}
PhotovaultImageFactory imageFactory = new PhotovaultImageFactory();
PhotovaultImage img = null;
try {
/*
Do not read the image yet since setting raw conversion
parameters later may force a re-read.
*/
img = imageFactory.create(imageFile, false, false);
} catch (PhotovaultException ex) {
final JAIPhotoViewer component = this;
final String msg = ex.getMessage();
SwingUtilities.invokeLater( new Runnable() {
public void run() {
JOptionPane.showMessageDialog( component,
msg, "Error loading file",
JOptionPane.ERROR_MESSAGE );
}
});
}
if ( img != null ) {
if ( rawImage != null ) {
rawImage.removeChangeListener( this );
}
if ( img instanceof RawImage ) {
rawImage = (RawImage) img;
rawImage.setRawSettings(
localRawSettings != null ?
localRawSettings : photo.getRawSettings() );
rawImage.addChangeListener( this );
// Check the correct resolution for this image
if ( isFit ) {
fit();
} else {
setScale( getScale() );
}
} else {
rawImage = null;
rawConvScaling = 1.0f;
}
}
appliedOps = instance.getAppliedOperations();
if ( !appliedOps.contains( ImageOperations.COLOR_MAP ) ) {
img.setColorAdjustment(
localChanMap != null ?
localChanMap : photo.getColorChannelMapping() );
}
setImage( img );
if ( !appliedOps.contains( ImageOperations.CROP ) ) {
instanceRotation = instance.getRotated();
double rot = photo.getPrefRotation() - instanceRotation;
imageView.setRotation( rot );
imageView.setCrop( photo.getCropBounds() );
}
fireViewChangeEvent();