- /**
- * Ask Chimera to save its session to the designated file path, or to a
- * temporary file if the path is null. Returns the file path if successful,
- * else null.
- *
- * @param filepath
- * @see getStateInfo
- */
- protected String saveSession(String filepath)
- {
- String pathUsed = filepath;
- try
- {
- if (pathUsed == null)
- {
- String suffix = jmb.getSessionFileExtension();
- File tempFile = File.createTempFile("chimera", suffix);
- tempFile.deleteOnExit();
- pathUsed = tempFile.getPath();
- }
- boolean result = jmb.saveSession(pathUsed);
- if (result)
- {
- this.chimeraSessionFile = pathUsed;
- return pathUsed;
- }
- } catch (IOException e)
- {
- }
- return null;
- }
-
- /**
- * Returns a string representing the state of the Chimera session. This is
- * done by requesting Chimera to save its session to a temporary file, then
- * reading the file contents. Returns an empty string on any error.
- */
- @Override
- public String getStateInfo()
- {
- String sessionFile = saveSession(null);
- if (sessionFile == null)
- {
- return "";
- }
- InputStream is = null;
- try
- {
- File f = new File(sessionFile);
- byte[] bytes = new byte[(int) f.length()];
- is = new FileInputStream(sessionFile);
- is.read(bytes);
- return new String(bytes);
- } catch (IOException e)
- {
- return "";
- } finally
- {
- if (is != null)
- {
- try
- {
- is.close();
- } catch (IOException e)
- {
- // ignore
- }
- }
- }
- }
-
- @Override
- protected void fitToWindow_actionPerformed()
- {
- jmb.focusView();
- }
-