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