001    /* JAPI - (Yet another (hopefully) useful) Java API
002     *
003     * Copyright (C) 2004-2006 Christian Hujer
004     *
005     * This program is free software; you can redistribute it and/or
006     * modify it under the terms of the GNU General Public License as
007     * published by the Free Software Foundation; either version 2 of the
008     * License, or (at your option) any later version.
009     *
010     * This program is distributed in the hope that it will be useful, but
011     * WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013     * General Public License for more details.
014     *
015     * You should have received a copy of the GNU General Public License
016     * along with this program; if not, write to the Free Software
017     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
018     * 02111-1307, USA.
019     */
020    
021    package net.sf.japi.swing.prefs;
022    
023    import java.net.URL;
024    import javax.swing.Icon;
025    import javax.swing.JComponent;
026    
027    /** Interface that is to be implemented by classes that provide preferences.
028     * <p />
029     * Often, implementations of this interface will subclass JComponent or JPanel.
030     * In that case {@link #getEditComponent()} will <code>return this</code>.
031     * {@link AbstractPrefs} provides a useful basic implementation of this interface.
032     * @author <a href="mailto:chris@riedquat.de">Christian Hujer</a>
033     */
034    public interface Prefs {
035    
036        /** Apply the changes in the UI to get into effect / be stored. */
037        void apply();
038    
039        /** Revert the preferences to the default values. */
040        void defaults();
041    
042        /** Provide a component for editing the prefs.
043         * The edit component MUST NOT automatically change preferences itself.
044         * Preferences MUST only changed when the method {@link #apply()} is invoked.
045         * @return component for editing the prefs
046         */
047        JComponent getEditComponent();
048    
049        /** Provide help (HTML).
050         * This method will only be queried if {@link #getHelpURL()} returns <code>null</code>.
051         * This method may return <code>null</code> as well, which means that this prefs does not provide any help.
052         * @return help text (HTML) or <code>null</code>
053         */
054        String getHelpText();
055    
056        /** Provide help.
057         * This method may return <code>null</code> in which case the method {@link #getHelpText()} will be queried instead.
058         * @return help url or <code>null</code>
059         */
060        URL getHelpURL();
061    
062        /** Provide text to be displayed as title for this prefs module.
063         * @return title of this prefs module
064         */
065        String getLabelText();
066    
067        /** Provide an icon to be displayed in the list where the user can choose amongst preferences.
068         * @return icon to be displayed in the list or <code>null</code> if no icon is available
069         */
070        Icon getListLabelIcon();
071    
072        /** Provide a label to be displayed in the list where the user can choose amongst preferences.
073         * @return text to be displayed in the list
074         */
075        String getListLabelText();
076    
077        /** Check whether there are unsaved changes.
078         * @return <code>true</code> if there are unsaved changes, otherwise <code>false</code>
079         */
080        boolean isChanged();
081    
082        /** Revert the preferences to the previously stored settings. */
083        void revert();
084    
085    } // class Prefs