ObjectInputStream is = new ObjectInputStream(fis);
Object o = is.readObject();
if ((o == null) || !(o instanceof ShapesContainer)) {
throw new java.io.IOException();
}
ShapesContainer sc = (ShapesContainer) o;
String name = f.getName();
String myExt = resources.getStringValue("jsynopticFilterExtension");
if (name.endsWith(myExt)) {
name = name.substring(0, name.length() - myExt.length() - 1);
}
sc.getComponent().setName(name);
// for ascending compatibility
o = is.readObject();
if ((o != null) && (o instanceof Vector)) {
for (Iterator it = ((Vector) o).iterator(); it.hasNext();) {
Object ito = it.next();
if (!(ito instanceof ColorMapper)) {
continue;
}
if (ColorMapper.colorMappers == null) {
ColorMapper.colorMappers = new Vector();
}
if (!ColorMapper.colorMappers.contains(ito)) {
ColorMapper.colorMappers.add(ito);
}
}
}
// for ascending compatibility
o = is.readObject();
if ((o != null) && (o instanceof Vector)) {
for (Iterator it = ((Vector) o).iterator(); it.hasNext();) {
Object ito = it.next();
if (!(ito instanceof TextMapper)) {
continue;
}
if (TextMapper.textMappers == null) {
TextMapper.textMappers = new Vector();
}
if (!TextMapper.textMappers.contains(ito)) {
TextMapper.textMappers.add(ito);
}
}
}
// for ascending compatibility
o = is.readObject();
if ((o != null) && (o instanceof Vector)) {
for (Iterator it = ((Vector) o).iterator(); it.hasNext();) {
Object ito = it.next();
if (!(ito instanceof ImageMapper)) {
continue;
}
if (ImageMapper.imageMappers == null) {
ImageMapper.imageMappers = new Vector();
}
if (!ImageMapper.imageMappers.contains(ito)) {
ImageMapper.imageMappers.add(ito);
}
}
}
is.close();
fis.close(); // also closes the file
for (Iterator it = sc.iterator(); it.hasNext();) {
try {
AbstractShape abs = (AbstractShape) it.next();
abs.addListener( (ShapeListener)sc.getComponent());
if (!(abs instanceof Linkable)) {
continue;
}
Linkable l = (Linkable) abs;
// Now trying to restore absolute file
File parent = f.getParentFile();
if (parent == null) {
parent = new File("./");
}
String link = l.getLink();
if ((link != null) && (!link.equals(""))) {
File nl = new File(parent, link);
l.setLink(nl.getCanonicalPath());
}
} catch (ClassCastException cce) {
}
}
if (JSynoptic.gui != null) {
JSynoptic.gui.addContainer(sc, f);
}
if (JSynopticBatch.batch != null) {
JSynopticBatch.batch.addContainer(sc, f);
}
} catch (Exception e) {
if (JSynoptic.gui != null) {
JOptionPane.showMessageDialog(JSynoptic.gui.getOwner(), new JLabel(messageWriter.print1args(
"cannotLoadFile", f.getName())), messageWriter.print0args("loadedFileRemarks"),
JOptionPane.ERROR_MESSAGE);
}
e.printStackTrace();
if (JSynopticBatch.batch != null) {
_logger.severe(messageWriter.print1args("cannotLoadFile", f.getName()));
}
JSynoptic.setStatus(messageWriter.print1args("cannotLoadFile", f.getName()));
return false;
}
if (!DataSourcePool.global.localEmptySourcesIsEmpty()) {
if (JSynoptic.gui != null) {
JOptionPane.showMessageDialog(JSynoptic.gui.getOwner(), new ReportingDialog(messageWriter
.print1args("missingElements", f.getName()), DataSourcePool.global
.getEmptySourcesDumpColumnNames(), DataSourcePool.global.getEmptySourcesDump()),
messageWriter.print0args("loadedFileRemarks"), JOptionPane.INFORMATION_MESSAGE);
}
}
JSynoptic.setStatus(messageWriter.print1args("loadOK", f.getName()));
return true;
case SAVE:
if (JSynoptic.gui == null) {
return false;
}
JSynoptic.setStatus(messageWriter.print1args("saving", f.getName()));
try {
ShapesContainer sc = JSynoptic.gui.getActiveContainer();
if (sc == null) {
return false;
}
// Save container into specified file
saveShapeContainer(sc, f);