001    package net.sourceforge.mp3dings.preferences;
002    
003    /* Mp3dings - manage mp3 meta-information
004     * Copyright (C) 2003 Moritz Ringler
005     * $Id: WarnLevelPanel.java,v 1.4 2006/07/11 16:59:55 ringler Exp $
006     *
007     * This program is free software; you can redistribute it and/or
008     * modify it under the terms of the GNU General Public License
009     * as published by the Free Software Foundation; either version 2
010     * of the License, or (at your option) any later version.
011     *
012     * This program is distributed in the hope that it will be useful,
013     * but WITHOUT ANY WARRANTY; without even the implied warranty of
014     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015     * GNU General Public License for more details.
016     *
017     * You should have received a copy of the GNU General Public License
018     * along with this program; if not, write to the Free Software
019     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020     */
021    
022    import java.awt.BorderLayout;
023    import java.awt.GridBagConstraints;
024    import java.awt.GridBagLayout;
025    import java.util.prefs.Preferences;
026    import javax.swing.JLabel;
027    import javax.swing.JPanel;
028    import javax.swing.JSpinner;
029    import javax.swing.SpinnerNumberModel;
030    import net.sourceforge.mp3dings.Globals;
031    import net.sourceforge.mp3dings.MainFrame;
032    
033    /**
034     * A preference field that configures after how many changes a
035     * "Discard changes?" warning is issued in an mp3dings table.
036     * @author Moritz Ringler
037     * @version $Revision: 1.4 $ ($Date: 2006/07/11 16:59:55 $)
038     */
039    public class WarnLevelPanel extends PrefPanel{
040        private JSpinner[] warnLevel;
041        private String prefParent;
042        private final static int n = 4;
043    
044        public WarnLevelPanel(MainFrame owner, Preferences pref,String name){
045            super(owner, pref,name);
046            JPanel me = new JPanel();
047            this.add(me, BorderLayout.WEST);
048            prefParent = pref.absolutePath()+"/";
049            warnLevel = new JSpinner[n];
050            for(int i=0;i<n;i++){
051                warnLevel[i] = new JSpinner(
052                 new SpinnerNumberModel(
053                  getTabModel(i).getPrefs().getInt("WarnChangedLevel",1),// value
054                  0, //minimum
055                  99, //maximum
056                  1
057                 ) //stepSize
058                );
059            }
060            JLabel[] tabs = new JLabel[]{
061                new JLabel(Globals.getString("DATA_TAB_TEXT")),
062                new JLabel(Globals.getString("NAMES_TAB_TEXT")),
063                new JLabel(Globals.getString("ID3V1_TAB_TEXT")),
064                new JLabel(Globals.getString("ID3V2_TAB_TEXT"))
065            };
066            JLabel text = new JLabel(Globals.getString("PREFS_WARNLEVEL_TEXT"));
067    
068            me.setLayout(new GridBagLayout());
069            GridBagConstraints gbc = new GridBagConstraints();
070            gbc = new GridBagConstraints();
071    
072            gbc.gridx  = 0;
073            gbc.gridy  = 0;
074            gbc.fill   = GridBagConstraints.NONE;
075            gbc.anchor = GridBagConstraints.WEST;
076            gbc.gridheight = 1;
077            gbc.gridwidth = 4;
078            gbc.weightx = 1;
079            gbc.weighty = 1;
080            me.add(text, gbc);
081    
082            gbc.gridy = 1;
083            gbc.gridwidth = 1;
084            for(int i=0;i<n;i++){
085                gbc.gridx = i;
086                tabs[i].setLabelFor(warnLevel[i]);
087                me.add(tabs[i], gbc);
088            }
089    
090            gbc.gridy = 2;
091            for(int i=0;i<n;i++){
092                gbc.gridx = i;
093                me.add(warnLevel[i], gbc);
094            }
095        }
096    
097        public void save(){
098            for(int i=0; i<n; i++){
099                getTabModel(i).getPrefs().putInt(
100                        "WarnChangedLevel",
101                        ((Integer) warnLevel[i].getValue()).intValue()
102                );
103            }
104        }
105    }