import java.io.File;
/*
* uploadv3.java
*
* Created on 12. Mai 2008, 19:36
*/
import java.io.FilenameFilter;
import javax.swing.DefaultListModel;
/**
*
* @author Administrator
*/
public class uploadv3 extends javax.swing.JApplet {
/** Initializes the applet uploadv3 */
@Override
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
// deklaration hier weil erst hier die List variablen deklariert sind
//static javax.swing.JList[] listen = {jLdemos,jLscreens,jLamparo};
//Update file Lists on Startup
update_files();
//introduce Drag'n'Drop
dragndrop();
}
public void dragndrop() {
}
public void update_files() {
//Variablen initialisieren
// array[typ][zähler][datei informationen(abs pfad, dateiname, größe)]
String[][][] files = new String[3][5000][5];
// typen und beginn der parameter namen (params[].i)
String[] params = {"demos","screens","amparo"};
//javax.swing.JList[] listen = {jLdemos,jLscreens,jLamparo};
// Listmodel für einträge der Listen
DefaultListModel[] inhalt = { new DefaultListModel(), new DefaultListModel(), new DefaultListModel() };
//Listen Leeren
/* liste muss nicht geleert werden, da das Listmodel immer neu initialisiert wird */
Integer o = new Integer(0);
for(Integer i=0;i<3;i++) {
o=0;
Integer nextpos = new Integer(0);
//System.err.println("schleife1");
while(o<3) {
File maindir = new File(getParameter(params[i]+Integer.toString(o)));
if(maindir.isDirectory()) {
// User dir ist geöffnet und nun alle beinhalteten dateien eintragen
FileFilter Filter = new FileFilter();
//eigene Func set_typ um dateityp zu übergeben
Filter.set_typ(params[i]);
File[] dateien = maindir.listFiles( Filter );
for(Integer r = 0; r<dateien.length;r++) {
//dateien[r].
//Wert in Array Füllen
files[i][nextpos][0] = dateien[r].getAbsolutePath();
files[i][nextpos][1] = dateien[r].getName();
files[i][nextpos][2] = Long.toString(dateien[r].length());
//System.err.println(dateien[r].getName());
//Liste Füllen
inhalt[i].addElement(dateien[r].getName());
nextpos++;
}
}
o++; // Einen Parametereintrag weiter springen
}
listen[i].setModel(inhalt[i]);
}
}
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jLdemos = new javax.swing.JList();
jScrollPane2 = new javax.swing.JScrollPane();
jLscreens = new javax.swing.JList();
jScrollPane3 = new javax.swing.JScrollPane();
jLamparo = new javax.swing.JList();
jButton1 = new javax.swing.JButton();
jScrollPane4 = new javax.swing.JScrollPane();
jLupload = new javax.swing.JList();
jLdemos.setDragEnabled(true);
jScrollPane1.setViewportView(jLdemos);
jLscreens.setDragEnabled(true);
jScrollPane2.setViewportView(jLscreens);
jLamparo.setDragEnabled(true);
jScrollPane3.setViewportView(jLamparo);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jScrollPane4.setViewportView(jLupload);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(59, 59, 59)
.addComponent(jButton1))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(159, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(61, 61, 61)
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(20, Short.MAX_VALUE))
);
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
update_files();
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private static javax.swing.JList jLamparo;
private static javax.swing.JList jLdemos;
private static javax.swing.JList jLscreens;
private javax.swing.JList jLupload;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
// End of variables declaration
class FileFilter implements FilenameFilter
{
String typ = new String();
public boolean accept( File f, String s ) {
boolean result = false;
if( this.typ == "demos" && new File(f.getAbsoluteFile()+f.separator+s).isFile() && ( s.toLowerCase().endsWith( ".dem" ) || s.toLowerCase().endsWith( ".zip" ) ) ) {
result = true;
} else if (this.typ == "screens" && s.toLowerCase().endsWith(".jpg") && new File(f.getAbsoluteFile()+f.separator+s).isFile() ) {
result = true;
} else if (this.typ == "amparo" && s.toLowerCase().endsWith(".zip") && new File(f.getAbsoluteFile()+f.separator+s).isFile() ) {
result = true;
}
return result;
}
public void set_typ(String t) {
this.typ = t;
}
}
// deklaration hier weil erst hier die List variablen deklariert sind
static javax.swing.JList[] listen = {jLdemos,jLscreens,jLamparo};
}