001    package net.sourceforge.mp3dings.filter;
002    
003    /* Mp3dings - manage mp3 meta-information
004     * Copyright (C) 2003-2004 Moritz Ringler
005     * $Id: StringSelectorCustomizer.java 43 2007-10-20 17:39:59Z ringler $
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.Component;
024    import java.awt.event.WindowEvent;
025    import java.awt.GridBagConstraints;
026    import java.awt.GridBagLayout;
027    import java.util.prefs.Preferences;
028    import javax.swing.JFrame;
029    import javax.swing.JLabel;
030    import javax.swing.JPanel;
031    import net.sourceforge.mp3dings.Globals;
032    import net.sourceforge.mp3dings.utils.AbstractBeanCustomizer;
033    import net.sourceforge.mp3dings.utils.Bean;
034    
035    /**
036     * The customizer class for string selector filters.
037     * @author Moritz Ringler
038     * @version $Revision: 43 $ ($Date: 2007-10-20 19:39:59 +0200 (Sa, 20 Okt 2007) $)
039     * @see StringSelector
040     */
041    public class StringSelectorCustomizer extends AbstractBeanCustomizer{
042        JPanel uui = new JPanel(new BorderLayout());
043    
044        public StringSelectorCustomizer(StringSelector filter){
045            super(filter);
046            final String[] words = Globals.getStringArray("PREFS_NUMFILTER");
047    
048            JPanel ui = new JPanel(new GridBagLayout());
049            GridBagConstraints gbc = new GridBagConstraints();
050    
051            gbc.gridx = 0;
052            gbc.gridy = 0;
053            gbc.gridwidth = 3;
054            gbc.gridheight = 1;
055            gbc.weightx = 1.;
056            gbc.weighty = 0.;
057            gbc.fill = GridBagConstraints.BOTH;
058            gbc.anchor = GridBagConstraints.WEST;
059            gbc.insets = Globals.INSETS_5;
060    
061            ui.add(getPropertyEditor("include", new Object[]{words[1],words[2]}), gbc);
062    
063            gbc.gridx = 0;
064            gbc.gridy = 1;
065            gbc.weightx = 1.;
066            ui.add(new JLabel(Globals.getString("TEXT_THAT_MATCHES")), gbc);
067    
068            gbc.gridy = 2;
069    
070            ui.add(getPropertyEditor("pattern", null), gbc);
071    
072            gbc.gridwidth = 1;
073            gbc.weightx = 0.33;
074            gbc.gridy = 3;
075    
076            ui.add(getPropertyEditor("regExp",
077                                     new Object[]{Globals.getString("REG_EXP")}),
078                   gbc);
079    
080            gbc.gridx = 1;
081    
082            ui.add(getPropertyEditor("caseSensitive",
083                                     new Object[]{Globals.getString("CASE_SENSITIVE")}),
084                   gbc);
085    
086            gbc.gridx = 2;
087    
088            ui.add(getPropertyEditor("wordMatch",
089                                     new Object[]{Globals.getString("MATCH_WORD")}),
090                   gbc);
091    
092            uui.add(ui, BorderLayout.NORTH);
093        }
094    
095        public StringSelectorCustomizer(){
096            this(new StringSelector());
097        }
098    
099        public static void main (String[] argv){
100            final Preferences pref = Preferences.userNodeForPackage(StringSelectorCustomizer.class);
101            StringSelector filter = (StringSelector) StringSelector.load(pref ,"test_ssc");
102            final StringSelector xfilter = (filter == null)
103                ? new StringSelector()
104                : filter ;
105            JFrame frame = new JFrame(){
106                protected void processWindowEvent(WindowEvent e) {
107                    xfilter.save(pref, "test_ssc");
108                    super.processWindowEvent(e);
109                    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
110                        System.exit(0);
111                    }
112                }
113            };
114            frame.add((new StringSelectorCustomizer(xfilter)).getUI());
115            frame.pack();
116            frame.setVisible(true);
117        }
118    
119        public void setModel(Bean filter){
120            if(!(filter instanceof StringSelector)){
121                throw new IllegalArgumentException("Model is not a StringSelector.");
122            }
123            super.setModel(filter);
124        }
125    
126        public Component getUI(){
127            return uui;
128        }
129    }