Android Open Source - SmartTools Page Filer






From Project

Back to project page SmartTools.

License

The source code is released under:

GNU General Public License

If you think the Android project SmartTools listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nj.simba.page.filer;
//from w  ww .  j  a  va2s.co  m
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import com.android.ddmlib.FileListingService;
import com.android.ddmlib.FileListingService.FileEntry;
import com.nj.simba.app.SmartToolsApp;
import com.nj.simba.ctrls.FilerListRender;
import com.nj.simba.ctrls.TabPanel;
import com.nj.simba.utils.Config;
import com.nj.simba.utils.FileSyncHelper;
import com.nj.simba.utils.Utils;


public class PageFiler extends TabPanel {
    private DefaultListModel mListModel;
    private DefaultTableModel mCurDirFilesModel;
    private JList mFileList;
    private FileListingService mFileSvr;
    private JTable mCurDirFiles;
    private FileEntry mCurEntry;
    private ImageIcon mIconFolder;
    private ImageIcon mIconFile;
    private JButton mBtnGetOut;
    private int mCurSel = -1;

    public PageFiler(JPanel tabPanel, int x, int y, int w, int h) {
        super(tabPanel, x, y, w, h);
    }

    public PageFiler(JPanel tabPanel) {
        super(tabPanel);
    }

    @Override
    protected void setTabPageName() {
        mTabPageName = "filer";
    }

    @Override
    protected void addBody() {
        super.addBody();

        mIconFolder = Utils.getResImage("res/folder-mid.png");
        mIconFile = Utils.getResImage("res/file-mid.png");

        mCurDirFilesModel = new FileListModel();
        mCurDirFiles = getFileList(mCurDirFilesModel);

        JScrollPane scroll = new JScrollPane(mCurDirFiles);
        scroll.setBounds(8, 4, Config.PANEL_BODY_WIDTH - 8 * 2,
                Config.PANEL_LEFT_HEIGHT - 4 * 2);
        scroll.setOpaque(false);
        scroll.getViewport().setOpaque(false);
        scroll.setBorder(BorderFactory.createEmptyBorder());

        JButton btnUp = new JButton("..");
        scroll.add(btnUp);

        mBodyPanel.add(scroll);
    }

    @Override
    protected void addLeft() {
        super.addLeft();

        mListModel = new DefaultListModel();
        mFileList = new JList(mListModel);
        mFileList.setBounds(6, 16, Config.PANEL_LEFT_WIDTH - 6 * 2,
                Config.PANEL_LEFT_HEIGHT);
        mFileList.setOpaque(false);
        mFileList.setCellRenderer(new FilerListRender());
        mFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        mFileList.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                int index = mFileList.getSelectedIndex();

                if (index < 0) {
                    return;
                }

                if (e.getClickCount() >= 2) {
                    mCurEntry = (FileEntry) mListModel.get(index);

                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            if (mFileSvr != null) {
                                updateFiler();
                            }
                        }
                    });
                }
            }
        });

        JScrollPane scroll = new JScrollPane(mFileList);
        scroll.setBounds(6, 4, Config.PANEL_LEFT_WIDTH - 6 * 2,
                Config.PANEL_LEFT_HEIGHT - 4 * 2);
        scroll.setOpaque(false);
        scroll.getViewport().setOpaque(false);

        mLeftPanel.add(scroll);
    }

    @Override
    protected void addRight() {
        super.addRight();

        JLabel rightTitle = new JLabel("?????");
        rightTitle.setForeground(Color.WHITE);
        rightTitle.setBounds(4, 0, Config.PANEL_RIGHT_WIDTH, 32);
        rightTitle.setOpaque(false);
        mRightPanel.add(rightTitle);

        rightTitle = new JLabel("???????");
        rightTitle.setForeground(Color.WHITE);
        rightTitle.setBounds(4, 30, Config.PANEL_RIGHT_WIDTH, 32);
        rightTitle.setOpaque(false);
        mRightPanel.add(rightTitle);

        rightTitle = new JLabel("???????");
        rightTitle.setForeground(Color.WHITE);
        rightTitle.setBounds(4, 60, Config.PANEL_RIGHT_WIDTH, 32);
        rightTitle.setOpaque(false);
        mRightPanel.add(rightTitle);

        mBtnGetOut = getButton("??????");
        mBtnGetOut.setBounds(4, 100, 100, 24);
        mRightPanel.add(mBtnGetOut);
        mBtnGetOut.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (mCurSel < 0) {
                    return;
                }

                String child = (String) mCurDirFiles.getValueAt(mCurSel, 1);
                FileEntry curSel = mCurEntry.findChild(child);
                FileSyncHelper syncHelper = new FileSyncHelper(mCurDevice,
                        curSel);
                syncHelper.syncOut();
            }
        });
    }

    @Override
    public void deviceConnected(SmartToolsApp app) {
        super.deviceConnected(app);

        if (mCurDevice == null) {
            return;
        }

        mFileSvr = mCurDevice.getFileListingService();
        mCurEntry = mFileSvr.getRoot();
        updateFiler();
    }

    @Override
    public void deviceDisconnected(SmartToolsApp app) {
        super.deviceDisconnected(app);
        System.out.println("PageFiler: deviceDisconnected");
    }

    protected JButton getButton(String text) {
        JButton btn = new JButton(text);
        btn.setOpaque(false);
        btn.setContentAreaFilled(false);
        btn.setFocusable(false);
        btn.setForeground(Color.WHITE);
        btn.addMouseListener(this);
        return btn;
    }

    private JTable getFileList(DefaultTableModel model) {
        String columns[] = { "Icon", "Name", "Size", "Date", "Time",
                "Permissions", "info" };
        model.setColumnIdentifiers(columns);

        JTable listFiles = new JTable(model);
        listFiles.setBounds(0, 0, Config.PANEL_BODY_WIDTH - 6 * 2,
                Config.PANEL_LEFT_HEIGHT - 4 * 2);
        listFiles.setDefaultRenderer(Object.class, new FileTableRender());
        listFiles.setOpaque(false);
        listFiles.getSelectionModel().setSelectionMode(
                ListSelectionModel.SINGLE_SELECTION);
        listFiles.setRowHeight(36);

        TableColumnModel columnMode = listFiles.getColumnModel();
        columnMode.getColumn(0).setPreferredWidth(48);
        columnMode.getColumn(1).setPreferredWidth(120);
        columnMode.getColumn(2).setPreferredWidth(64);
        columnMode.getColumn(3).setPreferredWidth(100);
        columnMode.getColumn(4).setPreferredWidth(80);
        columnMode.getColumn(5).setPreferredWidth(120);

        listFiles.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 1) {
                    mCurSel = mCurDirFiles.getSelectedRow();
                }
            }
        });

        return listFiles;
    }

    private void updateFiler() {
        FileEntry[] entries = mFileSvr.getChildren(mCurEntry, true, null);

        mListModel.clear();
        ((DefaultTableModel) mCurDirFilesModel).getDataVector().clear();

        mListModel.addElement(mCurEntry.getParent());

        for (FileEntry fileEntry : entries) {
            Object[] details = new Object[7];

            if (fileEntry.isDirectory()) {
                mListModel.addElement(fileEntry);
                details[0] = mIconFolder;
            } else {
                details[0] = mIconFile;
            }

            details[1] = fileEntry.getName();
            details[2] = fileEntry.getSize();
            details[3] = fileEntry.getDate();
            details[4] = fileEntry.getTime();
            details[5] = fileEntry.getPermissions();
            details[6] = fileEntry.getInfo();
            mCurDirFilesModel.addRow(details);

            // System.out.println(details[1]);
        }
    }

    @SuppressWarnings("serial")
    public static class FileListModel extends DefaultTableModel {

        @Override
        public boolean isCellEditable(int row, int column) {
            if (column == 0) {
                return false;
            }
            return super.isCellEditable(row, column);
        }
    }

}




Java Source Code List

com.nj.simba.BatteryReceiver.java
com.nj.simba.DaemonController.java
com.nj.simba.DeviceInfo.java
com.nj.simba.DviceInfoCollector.java
com.nj.simba.IDeviceInfo.java
com.nj.simba.PackageReceiver.java
com.nj.simba.SdcardStatuChangeReceiver.java
com.nj.simba.SmartToolService.java
com.nj.simba.app.MainFrame.java
com.nj.simba.app.SmartToolsApp.java
com.nj.simba.app.ToolbarPanel.java
com.nj.simba.base.IDeviceListener.java
com.nj.simba.base.IDeviceReqListener.java
com.nj.simba.connect.DeviceCmdWorker.java
com.nj.simba.connect.DeviceConnectWorker.java
com.nj.simba.connect.DeviceMessage.java
com.nj.simba.connect.DeviceMsgChannel.java
com.nj.simba.ctrls.FilerListRender.java
com.nj.simba.ctrls.ImageBtn.java
com.nj.simba.ctrls.LeftPanel.java
com.nj.simba.ctrls.MetroCoolBtn.java
com.nj.simba.ctrls.MyProgessBar.java
com.nj.simba.ctrls.SubPanel.java
com.nj.simba.ctrls.TabPanel.java
com.nj.simba.ctrls.ThemeButton.java
com.nj.simba.ctrls.ThemeLabel.java
com.nj.simba.ctrls.ToolbarBtn.java
com.nj.simba.cts.CtsResultReset.java
com.nj.simba.page.appmgr.AppTableRender.java
com.nj.simba.page.appmgr.DeviceAppTableModel.java
com.nj.simba.page.appmgr.PageAppMgr.java
com.nj.simba.page.device.DeviceListRender.java
com.nj.simba.page.device.DevicePanel.java
com.nj.simba.page.device.PageMyDevice.java
com.nj.simba.page.filer.FileTableRender.java
com.nj.simba.page.filer.PageFiler.java
com.nj.simba.page.logcat.ILogCatBufferChangeListener.java
com.nj.simba.page.logcat.LogCatMessageList.java
com.nj.simba.page.logcat.LogCatMessageParser.java
com.nj.simba.page.logcat.LogCatMessage.java
com.nj.simba.page.logcat.LogCatPidToNameMapper.java
com.nj.simba.page.logcat.LogCatReceiverFactory.java
com.nj.simba.page.logcat.LogCatReceiver.java
com.nj.simba.page.logcat.PageLogcat.java
com.nj.simba.utils.Config.java
com.nj.simba.utils.FileSyncHelper.java
com.nj.simba.utils.I2CTest.java
com.nj.simba.utils.IProgressMonitor.java
com.nj.simba.utils.SyncProgressHelper.java
com.nj.simba.utils.SyncProgressMonitor.java
com.nj.simba.utils.Utils.java