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