Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit af5b2c30 authored by Andreas Gampe's avatar Andreas Gampe Committed by android-build-merger
Browse files

Preload2: Abstract out UI am: 5cb89983 am: 826ec71e

am: eab0eadb

Change-Id: Ie6ad17cb25e0d7e843d36ceaa28a7ee9fc78d792
parents 4f74f3fd eab0eadb
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -32,7 +32,8 @@ import com.android.preload.actions.ShowDataAction;
import com.android.preload.classdataretrieval.ClassDataRetriever;
import com.android.preload.classdataretrieval.hprof.Hprof;
import com.android.preload.classdataretrieval.jdwp.JDWPClassDataRetriever;
import com.android.preload.ui.UI;
import com.android.preload.ui.IUI;
import com.android.preload.ui.SwingUI;

import java.util.ArrayList;
import java.util.Collection;
@@ -66,7 +67,7 @@ public class Main {
    private DumpTableModel dataTableModel;
    private DefaultListModel<Client> clientListModel;

    private UI ui;
    private IUI ui;

    // Actions that need to be updated once a device is selected.
    private Collection<DeviceSpecific> deviceSpecificActions;
@@ -89,13 +90,15 @@ public class Main {
     * @param args
     */
    public static void main(String[] args) {
        Main m = new Main();
        Main m = new Main(new SwingUI());
        top = m;

        m.startUp();
    }

    public Main() {
    public Main(IUI ui) {
        this.ui = ui;

        clientListModel = new DefaultListModel<Client>();
        dataTableModel = new DumpTableModel();

@@ -124,11 +127,10 @@ public class Main {
            }
        }

        ui = new UI(clientListModel, dataTableModel, actions);
        ui.setVisible(true);
        ui.prepare(clientListModel, dataTableModel, actions);
    }

    public static UI getUI() {
    public static IUI getUI() {
        return top.ui;
    }

@@ -176,6 +178,7 @@ public class Main {
        new ReloadListAction(clientUtils, getDevice(), clientListModel).run();

        getUI().hideWaitDialog();
        getUI().ready();
    }

    private void initDevice() {
+2 −5
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import java.util.TreeSet;
import java.util.regex.Pattern;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;

/**
 * Compute an intersection of classes from the given data. A class is in the intersection if it
@@ -92,10 +91,8 @@ public class ComputeThresholdAction extends AbstractAction implements Runnable {
        boolean ret = Main.getUI().showConfirmDialog("Computed a set with " + result.size()
                + " classes, would you like to save to disk?", "Save?");
        if (ret) {
            JFileChooser jfc = new JFileChooser();
            int ret2 = jfc.showSaveDialog(Main.getUI());
            if (ret2 == JFileChooser.APPROVE_OPTION) {
                File f = jfc.getSelectedFile();
            File f = Main.getUI().showSaveDialog();
            if (f != null) {
                saveSet(result, f);
            }
        }
+43 −0
Original line number Diff line number Diff line
package com.android.preload.ui;

import com.android.ddmlib.Client;
import java.io.File;
import java.util.List;
import javax.swing.Action;
import javax.swing.ListModel;
import javax.swing.table.TableModel;

/**
 * UI abstraction for the tool. This allows a graphical mode, command line mode,
 * or silent mode.
 */
public interface IUI {

    void prepare(ListModel<Client> clientListModel, TableModel dataTableModel,
            List<Action> actions);

    void ready();

    Client getSelectedClient();

    int getSelectedDataTableRow();

    void showWaitDialog();

    void updateWaitDialog(String s);

    void hideWaitDialog();

    void showMessageDialog(String s);

    boolean showConfirmDialog(String title, String message);

    String showInputDialog(String message);

    <T> T showChoiceDialog(String title, String message, T[] choices);

    File showSaveDialog();

    File[] showOpenDialog(boolean multi);

}
+23 −4
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ import javax.swing.ListModel;
import javax.swing.SwingUtilities;
import javax.swing.table.TableModel;

public class UI extends JFrame {
public class SwingUI extends JFrame implements IUI {

    private JList<Client> clientList;
    private JTable dataTable;
@@ -49,11 +49,13 @@ public class UI extends JFrame {
    // Shared file chooser, means the directory is retained.
    private JFileChooser jfc;

    public UI(ListModel<Client> clientListModel,
              TableModel dataTableModel,
              List<Action> actions) {
    public SwingUI() {
        super("Preloaded-classes computation");
    }

    @Override
    public void prepare(ListModel<Client> clientListModel, TableModel dataTableModel,
            List<Action> actions) {
        getContentPane().add(new JScrollPane(clientList = new JList<Client>(clientListModel)),
                BorderLayout.WEST);
        clientList.setCellRenderer(new ClientListCellRenderer());
@@ -74,18 +76,27 @@ public class UI extends JFrame {

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 800, 600);

        setVisible(true);
    }

    @Override
    public void ready() {
    }

    @Override
    public Client getSelectedClient() {
        return clientList.getSelectedValue();
    }

    @Override
    public int getSelectedDataTableRow() {
        return dataTable.getSelectedRow();
    }

    private JDialog currentWaitDialog = null;

    @Override
    public void showWaitDialog() {
        if (currentWaitDialog == null) {
            currentWaitDialog = new JDialog(this, "Please wait...", true);
@@ -111,6 +122,7 @@ public class UI extends JFrame {
        });
    }

    @Override
    public void updateWaitDialog(String s) {
        if (currentWaitDialog != null) {
            ((JLabel) currentWaitDialog.getContentPane().getComponent(0)).setText(s);
@@ -124,6 +136,7 @@ public class UI extends JFrame {
        }
    }

    @Override
    public void hideWaitDialog() {
        if (currentWaitDialog != null) {
            currentWaitDialog.setVisible(false);
@@ -131,6 +144,7 @@ public class UI extends JFrame {
        }
    }

    @Override
    public void showMessageDialog(String s) {
        // Hide the wait dialog...
        if (currentWaitDialog != null) {
@@ -147,6 +161,7 @@ public class UI extends JFrame {
        }
    }

    @Override
    public boolean showConfirmDialog(String title, String message) {
        // Hide the wait dialog...
        if (currentWaitDialog != null) {
@@ -164,6 +179,7 @@ public class UI extends JFrame {
        }
    }

    @Override
    public String showInputDialog(String message) {
        // Hide the wait dialog...
        if (currentWaitDialog != null) {
@@ -180,6 +196,7 @@ public class UI extends JFrame {
        }
    }

    @Override
    @SuppressWarnings("unchecked")
    public <T> T showChoiceDialog(String title, String message, T[] choices) {
        // Hide the wait dialog...
@@ -203,6 +220,7 @@ public class UI extends JFrame {
        }
    }

    @Override
    public File showSaveDialog() {
        // Hide the wait dialog...
        if (currentWaitDialog != null) {
@@ -228,6 +246,7 @@ public class UI extends JFrame {
        }
    }

    @Override
    public File[] showOpenDialog(boolean multi) {
        // Hide the wait dialog...
        if (currentWaitDialog != null) {