Package pdfdb.settings

Source Code of pdfdb.settings.ColumnSettingsManager

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pdfdb.settings;

import java.util.Hashtable;
import org.jdom.Element;
import pdfdb.data.filetable.ColumnState;

/** Manages persisting table column changes in the GUI.
* @author ug22cmg */
public class ColumnSettingsManager extends AbstractSettingsManager<ColumnState>
{

    private static final String FILENAME = "columns.setup";

    /** Stops multiple instantiation to preserve memory. */
    private ColumnSettingsManager()
    {
    }

    /** Gets the singleton instance.
     * @return The instance. */
    public static ColumnSettingsManager getInstance()
    {
        ColumnSettingsManager manager = (ColumnSettingsManager) instances.get(
                ColumnSettingsManager.class);
        if (manager == null)
        {
            ColumnSettingsManager tmp = new ColumnSettingsManager();
            instances.put(ColumnSettingsManager.class, tmp);
            return tmp;
        }
        return manager;
    }

    /** Gets the column state for the element.
     * @param e The element to be deserialized.
     * @return The column state. */
    @Override
    protected ColumnState getValue(Element e)
    {
        Element key = e.getChild("key");
        Element label = e.getChild("label");
        Element visible = e.getChild("visible");
        Element index = e.getChild("index");
        Element width = e.getChild("width");
        String visibleText = visible.getText();
        boolean isVisible = Boolean.parseBoolean(visibleText);
        int w = -1;
        if (width != null && width.getValue() != null &&
                !width.getValue().equals("-1"))
        {
            w = Integer.parseInt(width.getText());
        }
        return new ColumnState(key.getText(), label.getText(), isVisible,
                Integer.parseInt(index.getValue()), w);
    }

    /** Gets the element for the specified column state to be serialized.
     * @param value The column to be serialized.
     * @param element The element to return.
     * @return The element parameter. */
    @Override
    protected Element getElement(ColumnState value, Element element)
    {
        Element key = new Element("key");
        Element label = new Element("label");
        Element visible = new Element("visible");
        Element index = new Element("index");
        Element width = new Element("width");
        width.setText(String.valueOf(value.getWidth()));
        index.setText(String.valueOf(value.getIndex()));
        key.setText(value.getKey());
        label.setText(value.getLabel());
        visible.setText(String.valueOf(value.isVisible()));
        element.addContent(key);
        element.addContent(label);
        element.addContent(visible);
        element.addContent(index);
        element.addContent(width);
        return element;
    }

    /** Gets the default values for the config file, indexed by column
     *  identifier (upper-case).
     * @return The default values. */
    @Override
    protected Hashtable<String, ColumnState> getDefaults()
    {
        Hashtable<String, ColumnState> ht = new Hashtable<String, ColumnState>();
        ht.put("TITLE", new ColumnState("TITLE", "Title", true, 0, -1));
        ht.put("SUBTITLE", new ColumnState("SUBTITLE", "Sub-Title", true, 1, -1));
        ht.put("AUTHOR", new ColumnState("AUTHOR", "Author", true, 2, -1));
        ht.put("MODULE_CODE",
                new ColumnState("MODULE_CODE", "Module-Code", true, 3, -1));
        return ht;
    }

    /** Gets the config file name.
     * @return The file name. */
    @Override
    protected String getFileName()
    {
        return FILENAME;
    }
}
TOP

Related Classes of pdfdb.settings.ColumnSettingsManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.