001 package net.sourceforge.mp3dings.utils;
002
003 /* Mp3dings - manage mp3 meta-information
004 * Copyright (C) 2003-2004 Moritz Ringler
005 * $Id: ChecksumFactoryCustomizer.java,v 1.5 2007/03/29 16:03:02 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.Component;
023 import java.awt.Container;
024 import java.awt.event.WindowEvent;
025 import javax.swing.JFrame;
026 import java.text.DecimalFormat;
027 import javax.swing.JLabel;
028 import javax.swing.JPanel;
029 import javax.swing.SpringLayout;
030 import de.mospace.swing.SpringUtilities;
031 import net.sourceforge.mp3dings.Globals;
032
033 /**
034 * A Customizer for Counters.
035 * @author Moritz Ringler
036 * @version $Revision: 1.5 $ ($Date: 2007/03/29 16:03:02 $)
037 * @see Counter
038 */
039 public class CounterCustomizer extends AbstractBeanCustomizer{
040 Container uui = new JPanel(new SpringLayout());
041 private Component[] format;
042
043 public CounterCustomizer(Counter counter){
044 super(counter);
045 createGUI();
046 }
047
048 public CounterCustomizer(){
049 this(new Counter());
050 }
051
052 private void createGUI(){
053 int rowcount = 0;
054 Component editor = getPropertyEditor("value", null);
055 JLabel label = new JLabel(Globals.getString("COUNTER_START"));
056 label.setLabelFor(editor);
057 uui.add(label);
058 uui.add(editor);
059 rowcount++;
060
061 editor = getPropertyEditor("increment", null);
062 label = new JLabel(Globals.getString("COUNTER_INCREMENT"));
063 label.setLabelFor(editor);
064 uui.add(label);
065 uui.add(editor);
066 rowcount++;
067
068 editor = getPropertyEditor("decimalFormat", new Object[]{DecimalFormat.class});
069 label = new JLabel(Globals.getString("COUNTER_FORMAT"));
070 label.setLabelFor(editor);
071 format = new Component[]{editor, label};
072 uui.add(label);
073 uui.add(editor);
074 rowcount++;
075
076 SpringUtilities.makeCompactGrid(uui,
077 rowcount, 2, //rows, cols
078 2, 2, //initX, initY
079 5, 2); //xPad, yPad
080 }
081
082 public static void main (String[] argv){
083 final CounterCustomizer ccz = new CounterCustomizer();
084 JFrame frame = new JFrame(){
085 protected void processWindowEvent(WindowEvent e) {
086 super.processWindowEvent(e);
087 if (e.getID() == WindowEvent.WINDOW_CLOSING) {
088 Counter c = ccz.getCounter();
089 for(int i=0; i<10; i++){
090 System.out.println(c.getNextFormattedValue());
091 }
092 System.exit(0);
093 }
094 }
095 };
096 frame.add(ccz.getUI());
097 frame.pack();
098 frame.setVisible(true);
099 }
100
101 public final void setModel(Bean counter){
102 if(!(counter instanceof Counter)){
103 throw new IllegalArgumentException("Model is not a Counter.");
104 }
105 super.setModel(counter);
106 }
107
108 public Counter getCounter(){
109 return (Counter) getModel();
110 }
111
112 public void setFormatVisible(boolean b){
113 for(int i=0; i<format.length; i++){
114 format[i].setVisible(b);
115 }
116 }
117
118 public Component getUI(){
119 return uui;
120 }
121
122 }