UnknownImageTypeException,
UserCanceledException,
MissingImageFileException,
ImagingException
{
XmlNode root = doc.getRoot();
int version = root.getVersion();
if (version > SavedDocVersion) {
throw new XMLException(LOCALE.get("FutureLznError"));
}
if (version < 0) {
throw new XMLException(LOCALE.get("MissingLznVersionError"));
}
if (meta == null) {
// Find the original image:
XmlNode node = root.getChild(ImageTag);
String path = node.getAttribute(ImagePathTag);
File file = new File(path);
if (! file.isFile()) {
throw new MissingImageFileException(file);
}
// Override with a relative path, if one was defined:
if (node.hasAttribute(ImageRelativePathTag)) {
path = node.getAttribute(ImageRelativePathTag);
File relativeFile = new File(path);
if (relativeFile.isFile()) {
file = relativeFile;
}
}
ImageInfo info = ImageInfo.getInstanceFor(file);
try {
meta = info.getMetadata();
}
catch (FileNotFoundException e) {
throw new MissingImageFileException(file);
}
}
this.meta = meta;
// Enforce the saved original image orientation, which defines the
// coordinate system used for regions and crop bounds:
XmlNode imageNode = root.getChild(ImageTag);
if (imageNode.hasAttribute(ImageOrientationTag)) {
String value = imageNode.getAttribute(ImageOrientationTag);
try {
ImageOrientation oldOrientation =
ImageOrientation.getOrientationFor(Short.parseShort(value));
ImageOrientation newOrientation = meta.getOrientation();
if (oldOrientation != newOrientation) {
meta.setOrientation(oldOrientation);
}
}
catch (NumberFormatException e) {
throw new XMLException(
"Image orientation \"" + value + "\" is not a number", e
);
}
}
// Backwards compatibility: before XMP support, the convention in LZN
// files was that the image orientation was its original orientation,
// before any browser rotations.
else {
// Make sure this pre-XMP LZN structure is not a Template.
// (See Application.saveTemplate().)
if (! root.getName().equals("Template")) {
ImageOrientation origOrient = meta.getOriginalOrientation();
meta.setOrientation(origOrient);
}
}
engine = EngineFactory.createEngine(meta, versionInfo, thread);
xform = new XFormModel(engine);
regions = new RegionManager();
crop = new CropRotateManager(engine, xform);
scale = new ScaleModel(engine);
XmlNode scaleNode = root.getChild(ScaleTag);
Scale s = new Scale(scaleNode);
scale.setScale(s);
editor = new Editor(engine, scale, xform, regions, crop, this);
editor.showWait(LOCALE.get("EditorWaitText"));
crop.setEditor( editor );
XmlNode controlNode = root.getChild(ControlTag);
// this does the inverse of save(XmlNode):
try {
editor.restore(controlNode);
} catch (XMLException e) {
dispose();
throw e;
}
commonInitialization();
if (root.hasChild(SaveTag)) {
XmlNode saveNode = root.getChild(SaveTag);
save = SaveOptions.restore(saveNode);
}
if (root.hasChild(PrintTag)) {
XmlNode printNode = root.getChild(PrintTag);
Dimension size = engine.getNaturalSize();
print = new PrintLayoutModel(size.width, size.height);
print.restore(printNode);
}
if (root.hasChild(ExportTag)) {
XmlNode exportNode = root.getChild(ExportTag);
export = ImageExportOptions.read(exportNode);
}
}