001    /**
002     * iFish - An iRiver iHP jukebox database creation tool
003     *
004     * Copyright (C) 2009 Richard "Shred" Körber
005     *   http://ifish.shredzone.org
006     *
007     * This program is free software: you can redistribute it and/or modify
008     * it under the terms of the GNU General Public License as published by
009     * the Free Software Foundation, either version 3 of the License, or
010     * (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, see <http://www.gnu.org/licenses/>.
019     */
020    package net.shredzone.ifish.gui;
021    
022    import net.shredzone.ifish.*;
023    import net.shredzone.ifish.db.*;
024    import net.shredzone.ifish.i18n.L;
025    import net.shredzone.ifish.pool.ImgPool;
026    import net.shredzone.jshred.swing.*;
027    import java.awt.*;
028    import java.awt.RenderingHints.Key;
029    import java.text.*;
030    import java.util.prefs.*;
031    import javax.swing.*;
032    
033    /**
034     * This pane is responsible for scanner settings, a start button and
035     * a status box.
036     *
037     * @author  Richard Körber &lt;dev@shredzone.de&gt;
038     * @version $Id: ScannerPane.java 291 2009-04-28 21:29:27Z shred $
039     */
040    public class ScannerPane extends JPanel {
041      private static final long serialVersionUID = 3258126968544309304L;
042    
043      private final IFishPane fish;
044      private final IFishPrefs prefs;
045      private JLabel jlDir;
046      private JLabel jlAdded;
047      private JLabel jlUpdated;
048      private JLabel jlRemoved;
049      private JLabel jlCount;
050      private JLabel jlCreated;
051      
052      /**
053       * Create a new ScannerPane
054       *
055       * @param   fish        IFishPane
056       */
057      public ScannerPane( IFishPane fish ) {
058        this.fish  = fish;
059        this.prefs = fish.getPrefs();
060        setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) );
061        
062        JPanel jpStart = new SweetPanel();
063        jpStart.setLayout( new GridLayout( 3,1 ) );
064        {
065          JPanel jpCenter = new JPanel();
066          jpCenter.setLayout( new BoxLayout( jpCenter, BoxLayout.X_AXIS) );
067          jpCenter.setOpaque(false);
068          {
069            JButton jbSync = new JButton( fish.getAction( IFishPane.ACTION_SYNCDATABASE ) );
070            jpCenter.add( Box.createHorizontalGlue() );
071            jpCenter.add( jbSync );
072            jpCenter.add( Box.createHorizontalGlue() );
073          }
074          jpStart.add( new JLabel("") );
075          jpStart.add( jpCenter );
076          jpStart.add( new JLabel("") );
077        }
078        add( jpStart );
079        
080        JPanel jpStatus = new JPanel();
081        jpStatus.setLayout( new BoxLayout( jpStatus, BoxLayout.Y_AXIS ) );
082        {
083          JLabelGroup group = null;
084          
085          //--- Current directory ---
086          jlDir = new JLabel("");
087          group = new JLabelGroup( jlDir, L.tr("scanner.dir"), group );
088          jpStatus.add( group );
089          
090          //--- Files added ---
091          jlAdded = new JLabel("");
092          group = new JLabelGroup( jlAdded, L.tr("scanner.added"), group );
093          jpStatus.add( group );
094          
095          //--- Files updated ---
096          jlUpdated = new JLabel("");
097          group = new JLabelGroup( jlUpdated, L.tr("scanner.updated"), group );
098          jpStatus.add( group );
099    
100          //--- Files removed ---
101          jlRemoved = new JLabel("");
102          group = new JLabelGroup( jlRemoved, L.tr("scanner.removed"), group );
103          jpStatus.add( group );
104          
105          //--- Files in database ---
106          jlCount = new JLabel("");
107          group = new JLabelGroup( jlCount, L.tr("scanner.count"), group );
108          jpStatus.add( group );
109          
110          //--- Creation date ---
111          jlCreated = new JLabel("");
112          group = new JLabelGroup( jlCreated, L.tr("scanner.created"), group );
113          jpStatus.add( group );
114          
115          group.rearrange();
116        }
117        jpStatus.setBorder( new MyTitledBorder( L.tr("scanner.status") ) );
118        SwingUtils.setMinimumHeight( jpStatus );
119        add( jpStatus );
120        
121        prefs.getNode().addPreferenceChangeListener( new PreferenceChangeListener() {
122          @Override
123          public void preferenceChange( PreferenceChangeEvent evt ) {
124            updateDir();
125          }
126        });
127        
128        updateDir();
129        
130      }
131      
132      /**
133       * Update the status box according to the model data.
134       *
135       * @param   model       Model to use for update
136       */
137      public void update( NaviDb model ) {
138        final NumberFormat fmt = NumberFormat.getIntegerInstance();
139        final DateFormat   fmtDate = DateFormat.getDateTimeInstance();
140        
141        jlAdded.setText(   fmt.format( model.getAddCounter() ) );
142        jlUpdated.setText( fmt.format( model.getUpdateCounter() ) );
143        jlRemoved.setText( fmt.format( model.getRemoveCounter() ) );
144        jlCount.setText(   fmt.format( model.size() ) );
145        jlCreated.setText( fmtDate.format( model.getCreationDate() ) );
146      }
147      
148      /**
149       * Update the directory line in the status box.
150       */
151      public void updateDir() {
152        jlDir.setText( prefs.getDirectory() );
153      }
154      
155    /* -------------------------------------------------------------------------- */
156      
157      /**
158       * This is a decorated JPanel with some iFish stuff in the background. :)
159       */
160      private static class SweetPanel extends JPanel {
161        
162        private static final long serialVersionUID = 3617570522494545975L;
163        private static final ImageIcon fish = ImgPool.get("ifish-layer.png");
164        
165        public SweetPanel() {
166          setOpaque(false);
167        }
168        
169        @Override
170        public void paint( Graphics g ) {
171          Graphics2D g2 = (Graphics2D) g.create();
172    
173          g2.addRenderingHints( new RenderingHints(
174              RenderingHints.KEY_INTERPOLATION,
175              RenderingHints.VALUE_INTERPOLATION_BICUBIC
176          ));
177          g2.addRenderingHints( new RenderingHints(
178              RenderingHints.KEY_ANTIALIASING,
179              RenderingHints.VALUE_ANTIALIAS_ON
180          ));
181          
182          final int w = getWidth();
183          final int h = getHeight();
184    
185          g2.setPaint( new GradientPaint(0,0, new Color(34,206,189,40), 40, h, new Color(34,104,206,40) ) );
186          g2.fillOval( -(w*110/100), -(h*90/100), w*2, h*2 );
187    
188          g2.setColor( new Color(0,0,0,50) );
189          g2.setStroke( new BasicStroke( 8, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND ) );
190          g2.drawOval( -(w*110/100), -(h*90/100), w*2, h*2 );
191    
192          g2.drawImage( fish.getImage(), 20, 20, fish.getIconWidth()*2, fish.getIconHeight()*2, this );
193    
194          g2.dispose();
195          super.paint(g);
196        }
197    
198      }
199      
200    }