//Copyright (c) 2000-2003 San Diego Supercomputer Center (SDSC), //a facility operated by the University of California, San Diego (UCSD) // //Users and possessors of this source code are hereby granted a //nonexclusive, royalty-free copyright and design patent license to //use this code in individual software. License is not granted for //commercial resale, in whole or in part, without prior written //permission from SDSC. This source is provided "AS IS" without express //or implied warranty of any kind. // //For further information, please see: http://mbt.sdsc.edu // package edu.sdsc.mbt.viewables; import edu.sdsc.mbt.util.*; import java.util.prefs.*; /** * This class encapsulates element color settings and is used to provide persistence * to user settings by saving current colors to filesystem storage and reading them * when loading the application and opening the element editing dialog. * @see edu.sdsc.mbt.viewables.StructureStyles * @see edu.sdsc.mbt.viewables.StylesPreferences * @see edu.sdsc.sirius.dialogs.ElementStylesDialog * * @author Oleksandr V. Buzko */ public class ElementPreferences { private float[][] colors = null; public ElementPreferences(){ colors = new float[PeriodicTable.getElementCount() + 1][4];//to keep indices the same as atomic numbers } /** * Read currently set element color preferences from ElementStyles */ public void getCurrentConfiguration(){ //get element colors from ElementStyles for (int i = 1; i < PeriodicTable.getElementCount(); i++){ float[] temp = ElementProperties.getElementColor(i); colors[i][0] = temp[0]; colors[i][1] = temp[1]; colors[i][2] = temp[2]; } } /** * Apply currently stored in this instance colors to ElementStyles. */ public void applyConfiguration(){ for (int i = 1; i < PeriodicTable.getElementCount(); i++){ ElementProperties.setElementColor(i, colors[i][0], colors[i][1], colors[i][2]); } } /** * Save current color settings to the filesystem. */ public void writePreferences(){ Preferences root = Preferences.userRoot(); final Preferences node = root.node("/edu/sdsc/siriuswb/viewer/elements"); for (int i = 1; i < PeriodicTable.getElementCount(); i++){ node.putFloat("color" + i + "0", colors[i][0]); node.putFloat("color" + i + "1", colors[i][1]); node.putFloat("color" + i + "2", colors[i][2]); } try{ node.flush(); } catch (BackingStoreException ex){ System.out.println("Unable to save element preferences: " + ex); } } /** * Open current color settings from persistent storage. */ public void readPreferences(){ Preferences root = Preferences.userRoot(); final Preferences node = root.node("/edu/sdsc/siriuswb/viewer/elements"); for (int i = 1; i < PeriodicTable.getElementCount(); i++){ colors[i][0] = node.getFloat("color" + i + "0", colors[i][0]); colors[i][1] = node.getFloat("color" + i + "1", colors[i][1]); colors[i][2] = node.getFloat("color" + i + "2", colors[i][2]); } } }