From d0763db383a882d6449da3e39aa05aaabdf9dbcb Mon Sep 17 00:00:00 2001 From: Raphael Girardot <raphael.girardot@synchrotron-soleil.fr> Date: Mon, 17 Feb 2014 10:12:32 +0000 Subject: [PATCH] some methods renamed + added the possibility to interact with any docking area (not necessary the main one) --- .../infonode/InfoNodeDockingManager.java | 51 +++++++++++-------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/dockinginfonode/src/main/java/fr/soleil/docking/infonode/InfoNodeDockingManager.java b/dockinginfonode/src/main/java/fr/soleil/docking/infonode/InfoNodeDockingManager.java index 9dba35f..d6b669e 100644 --- a/dockinginfonode/src/main/java/fr/soleil/docking/infonode/InfoNodeDockingManager.java +++ b/dockinginfonode/src/main/java/fr/soleil/docking/infonode/InfoNodeDockingManager.java @@ -16,7 +16,6 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import javax.swing.JComponent; -import javax.swing.JOptionPane; import net.infonode.docking.RootWindow; import net.infonode.docking.View; @@ -99,9 +98,10 @@ public class InfoNodeDockingManager extends ADockingManager { } @Override - public void loadPerspective(IPerspective perspective) throws DockingException { + public void applyPerspective(IPerspective perspective, JComponent dockingArea) throws DockingException { DockingException dockingException = null; - if (perspective.getByteArray().length > 0) { + if ((perspective != null) && (perspective.getByteArray().length > 0) && (dockingArea instanceof RootWindow)) { + RootWindow rootWindow = (RootWindow) dockingArea; ObjectInputStream ois = null; ByteArrayInputStream bais = null; try { @@ -109,7 +109,8 @@ public class InfoNodeDockingManager extends ADockingManager { ois = new ObjectInputStream(bais); rootWindow.read(ois); } catch (Exception e) { - dockingException = new DockingException("Perspective.load() :" + " Unexpected Error", e); + dockingException = new DockingException(getClass().getSimpleName() + + ".applyPerspective(): Unexpected Error", e); } finally { try { if (ois != null) { @@ -131,26 +132,36 @@ public class InfoNodeDockingManager extends ADockingManager { } @Override - protected void savePerspective(IPerspective perspective) { - ByteArrayOutputStream baos = null; - ObjectOutputStream ous = null; - baos = new ByteArrayOutputStream(); - try { - ous = new ObjectOutputStream(baos); - rootWindow.write(ous, false); - } catch (IOException e) { - e.printStackTrace(); - JOptionPane.showMessageDialog(rootWindow, "Perspective.save() :" + " Unexpected Error (see traces)", - "INFONODE Docking - Error", JOptionPane.ERROR_MESSAGE); - } finally { + public void updatePerspective(IPerspective perspective, JComponent dockingArea) throws DockingException { + DockingException dockingException = null; + if ((perspective != null) && (dockingArea instanceof RootWindow)) { + RootWindow rootWindow = (RootWindow) dockingArea; + ByteArrayOutputStream baos = null; + ObjectOutputStream ous = null; + baos = new ByteArrayOutputStream(); try { - ous.close(); - // Actually there is no effect to close baos ... + ous = new ObjectOutputStream(baos); + rootWindow.write(ous, false); + perspective.setByteArray(baos.toByteArray()); } catch (IOException e) { - e.printStackTrace(); + dockingException = new DockingException(getClass().getSimpleName() + + ".updatePerspective(): Unexpected Error", e); + } finally { + try { + ous.close(); + // Actually there is no effect to close baos ... + } catch (IOException e) { + if (dockingException == null) { + dockingException = new DockingException("I/O Exception", e); + } else { + e.printStackTrace(); + } + } } } - perspective.setByteArray(baos.toByteArray()); + if (dockingException != null) { + throw dockingException; + } } @Override -- GitLab