Java tutorial
/* * Copyright 2014 Patrik Karlsson. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package se.trixon.solos.core.panel; import java.awt.BorderLayout; import java.io.File; import java.util.Collection; import javax.swing.DefaultListModel; import javax.swing.JList; import org.apache.commons.io.FileUtils; import se.trixon.solos.core.Solos; import se.trixon.solos.core.io.DirLister; import se.trixon.solos.core.io.DirListerListener; /** * * @author Patrik Karlsson <patrik@trixon.se> */ public class FilePanel extends javax.swing.JPanel implements DirListerListener, NavigatorListener { private final long mCreatedAt; private JList mList; private TopAPanel topAPanel = new TopAPanel(); private final NavigatorPanel mNavigatorPanel = new NavigatorPanel(); private final StatusPanel mStatusPanel = new StatusPanel(); private DirLister mDirLister; /** * Creates new form SidePanel */ public FilePanel() { initComponents(); init(); mCreatedAt = System.currentTimeMillis(); } @Override public void onDirectoryChanged(File file) { Solos.log("cd " + file.getAbsolutePath()); mDirLister.setDirectory(file); mDirLister.refresh(); } @Override public void onDirRefreshed(final Collection<File> files) { new Thread(new Runnable() { @Override public void run() { DefaultListModel model = new DefaultListModel(); for (File file : files) { model.addElement(file); Solos.log(file.getAbsolutePath()); } mList.setModel(model); } }).start(); } @Override public String toString() { return "FilePanel{" + "mCreatedAt=" + mCreatedAt + '}'; } private void init() { mNavigatorPanel.setNavigatorListener(this); // topPanel.add(topAPanel); topPanel.add(mNavigatorPanel); add(mStatusPanel, BorderLayout.SOUTH); mDirLister = new DirLister(this); // mDirLister.refresh(); mNavigatorPanel.setPath(FileUtils.getUserDirectory()); mList = new JList(); scrollPane.setViewportView(mList); } /** * 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() { topPanel = new javax.swing.JPanel(); scrollPane = new javax.swing.JScrollPane(); table = new javax.swing.JTable(); setLayout(new java.awt.BorderLayout()); topPanel.setLayout(new java.awt.GridLayout(1, 0)); add(topPanel, java.awt.BorderLayout.NORTH); table.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null } }, new String[] { "Name", "Ext", "Size", "Date" })); table.setEnabled(false); scrollPane.setViewportView(table); add(scrollPane, java.awt.BorderLayout.CENTER); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JScrollPane scrollPane; private javax.swing.JTable table; private javax.swing.JPanel topPanel; // End of variables declaration//GEN-END:variables }