/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * PresenceDrawPanel.java * * Created on 29 mai 2011, 23:11:59 */ package feuille.karaoke.lib; import java.awt.Color; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; import javax.swing.JFileChooser; /** * <p>This class is a panel that returns if we have drawing file in the chosen * directory or not by a message..<br />Cette classe est un panel qui retourne * un message en fonction de la présence ou non de fichier de dessin dans * un répertoire.</p> * @author The Wingate 2940 */ public class PresenceDrawPanel extends javax.swing.JPanel implements PropertyChangeListener { String OKMessage = "<html><h1>OK"; String NOKMessage = "<html><h1>No files"; /** <p>Creates new form PresenceDrawPanel.<br />Crée un nouveau formulaire PresenceDrawPanel.</p>*/ @SuppressWarnings("LeakingThisInConstructor") public PresenceDrawPanel(JFileChooser fc) { initComponents(); fc.addPropertyChangeListener(this); jLabel1.setForeground(Color.red); jLabel1.setText("<html><h1>?"); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel1.setBackground(new java.awt.Color(255, 255, 255)); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setText("jLabel1"); jLabel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); jLabel1.setOpaque(true); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE) .addContainerGap()) ); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; // End of variables declaration//GEN-END:variables /** <p>Return a message.<br />Retourne un message.</p> */ @Override public void propertyChange(PropertyChangeEvent evt) { String prop = evt.getPropertyName(); //If the directory changed. if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) { File f = (File)evt.getNewValue(); int numFiles = countAssDrawingFiles(f); if(numFiles>0){ jLabel1.setForeground(Color.green); jLabel1.setText(OKMessage); }else{ jLabel1.setForeground(Color.red); jLabel1.setText(NOKMessage); } } } /** <p>Return the count of drawing file.<br /> * Retourne le nombre de fichier de dessin.</p> */ private int countAssDrawingFiles(File dir){ int count = 0; for(File file : dir.listFiles()){ if(file.getAbsolutePath().endsWith(".adf")){ count += 1; } } return count; } }