diff options
| author | 2016-11-28 13:15:10 -0800 | |
|---|---|---|
| committer | 2016-11-28 13:15:10 -0800 | |
| commit | 5cb8998363a16e667faee4eaa7e5040bce7e702b (patch) | |
| tree | ea629bbb341dbfcefa2ba92e6445b54969957eb6 | |
| parent | d7e597a2e7843b7269d4972abae820424c9d460e (diff) | |
Preload2: Abstract out UI
Create IUI interface and move UI to SwingUI.
Bug: 31961946
Test: manual
Change-Id: If56347fdde8b441c0c01337a3f5eac002ea5b4f3
| -rw-r--r-- | tools/preload2/src/com/android/preload/Main.java | 17 | ||||
| -rw-r--r-- | tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java | 7 | ||||
| -rw-r--r-- | tools/preload2/src/com/android/preload/ui/IUI.java | 43 | ||||
| -rw-r--r-- | tools/preload2/src/com/android/preload/ui/SwingUI.java (renamed from tools/preload2/src/com/android/preload/ui/UI.java) | 27 |
4 files changed, 78 insertions, 16 deletions
diff --git a/tools/preload2/src/com/android/preload/Main.java b/tools/preload2/src/com/android/preload/Main.java index ca5b0e005a1d..cc54a8d9c715 100644 --- a/tools/preload2/src/com/android/preload/Main.java +++ b/tools/preload2/src/com/android/preload/Main.java @@ -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() { diff --git a/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java b/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java index b524716fc2cb..5d052ccc7072 100644 --- a/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java +++ b/tools/preload2/src/com/android/preload/actions/ComputeThresholdAction.java @@ -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); } } diff --git a/tools/preload2/src/com/android/preload/ui/IUI.java b/tools/preload2/src/com/android/preload/ui/IUI.java new file mode 100644 index 000000000000..3c151d90ab0a --- /dev/null +++ b/tools/preload2/src/com/android/preload/ui/IUI.java @@ -0,0 +1,43 @@ +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); + +} diff --git a/tools/preload2/src/com/android/preload/ui/UI.java b/tools/preload2/src/com/android/preload/ui/SwingUI.java index 47174ddd0e07..1245f2c23d7e 100644 --- a/tools/preload2/src/com/android/preload/ui/UI.java +++ b/tools/preload2/src/com/android/preload/ui/SwingUI.java @@ -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) { |