1554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe/*
2554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * Copyright (C) 2015 The Android Open Source Project
3554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe *
4554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * Licensed under the Apache License, Version 2.0 (the "License");
5554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * you may not use this file except in compliance with the License.
6554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * You may obtain a copy of the License at
7554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe *
8554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe *      http://www.apache.org/licenses/LICENSE-2.0
9554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe *
10554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * Unless required by applicable law or agreed to in writing, software
11554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * distributed under the License is distributed on an "AS IS" BASIS,
12554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * See the License for the specific language governing permissions and
14554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * limitations under the License.
15554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe */
16554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
17554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampepackage com.android.preload.ui;
18554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
19554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport com.android.ddmlib.Client;
20554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport com.android.ddmlib.ClientData;
21554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
22554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport java.awt.BorderLayout;
23554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport java.awt.Component;
24554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport java.awt.Dimension;
25554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport java.io.File;
26554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport java.util.List;
27554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
28554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.Action;
29554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.DefaultListCellRenderer;
30554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.JDialog;
31554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.JFileChooser;
32554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.JFrame;
33554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.JLabel;
34554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.JList;
35554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.JOptionPane;
36554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.JProgressBar;
37554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.JScrollPane;
38554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.JTable;
39554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.JToolBar;
40554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.ListModel;
41554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.SwingUtilities;
42554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.table.TableModel;
43554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
445cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampepublic class SwingUI extends JFrame implements IUI {
45554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
46554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    private JList<Client> clientList;
47554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    private JTable dataTable;
48554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
49554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    // Shared file chooser, means the directory is retained.
50554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    private JFileChooser jfc;
51554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
525cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    public SwingUI() {
53554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        super("Preloaded-classes computation");
545cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    }
55554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
565cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    @Override
573bf65c916ce65c06b0920ec4b8f68d3ef6c5e721Andreas Gampe    public boolean isSingleThreaded() {
583bf65c916ce65c06b0920ec4b8f68d3ef6c5e721Andreas Gampe        return false;
593bf65c916ce65c06b0920ec4b8f68d3ef6c5e721Andreas Gampe    }
603bf65c916ce65c06b0920ec4b8f68d3ef6c5e721Andreas Gampe
613bf65c916ce65c06b0920ec4b8f68d3ef6c5e721Andreas Gampe    @Override
625cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    public void prepare(ListModel<Client> clientListModel, TableModel dataTableModel,
635cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe            List<Action> actions) {
64554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        getContentPane().add(new JScrollPane(clientList = new JList<Client>(clientListModel)),
65554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                BorderLayout.WEST);
66554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        clientList.setCellRenderer(new ClientListCellRenderer());
67554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        // clientList.addListSelectionListener(listener);
68554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
69554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        dataTable = new JTable(dataTableModel);
70554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        getContentPane().add(new JScrollPane(dataTable), BorderLayout.CENTER);
71554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
72554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        JToolBar toolbar = new JToolBar(JToolBar.HORIZONTAL);
73554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        for (Action a : actions) {
74554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            if (a == null) {
75554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                toolbar.addSeparator();
76554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            } else {
77554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                toolbar.add(a);
78554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            }
79554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
80554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        getContentPane().add(toolbar, BorderLayout.PAGE_START);
81554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
82554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
83554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        setBounds(100, 100, 800, 600);
845cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe
855cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe        setVisible(true);
865cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    }
875cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe
885cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    @Override
895cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    public void ready() {
90554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    }
91554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
925cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    @Override
93554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    public Client getSelectedClient() {
94554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        return clientList.getSelectedValue();
95554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    }
96554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
975cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    @Override
98554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    public int getSelectedDataTableRow() {
99554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        return dataTable.getSelectedRow();
100554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    }
101554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
102554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    private JDialog currentWaitDialog = null;
103554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
1045cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    @Override
105554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    public void showWaitDialog() {
106554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        if (currentWaitDialog == null) {
107554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            currentWaitDialog = new JDialog(this, "Please wait...", true);
108554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            currentWaitDialog.getContentPane().add(new JLabel("Please be patient."),
109554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                    BorderLayout.CENTER);
110554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            JProgressBar progress = new JProgressBar(JProgressBar.HORIZONTAL);
111554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            progress.setIndeterminate(true);
112554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            currentWaitDialog.getContentPane().add(progress, BorderLayout.SOUTH);
113554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            currentWaitDialog.setSize(200, 100);
114554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            currentWaitDialog.setLocationRelativeTo(null);
115554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            showWaitDialogLater();
116554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
117554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    }
118554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
119554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    private void showWaitDialogLater() {
120554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        SwingUtilities.invokeLater(new Runnable() {
121554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            @Override
122554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            public void run() {
123554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                if (currentWaitDialog != null) {
124554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                    currentWaitDialog.setVisible(true); // This is blocking.
125554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                }
126554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            }
127554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        });
128554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    }
129554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
1305cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    @Override
131554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    public void updateWaitDialog(String s) {
132554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        if (currentWaitDialog != null) {
133554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            ((JLabel) currentWaitDialog.getContentPane().getComponent(0)).setText(s);
134554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            Dimension prefSize = currentWaitDialog.getPreferredSize();
135554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            Dimension curSize = currentWaitDialog.getSize();
136554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            if (prefSize.width > curSize.width || prefSize.height > curSize.height) {
137554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                currentWaitDialog.setSize(Math.max(prefSize.width, curSize.width),
138554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                        Math.max(prefSize.height, curSize.height));
139554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                currentWaitDialog.invalidate();
140554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            }
141554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
142554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    }
143554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
1445cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    @Override
145554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    public void hideWaitDialog() {
146554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        if (currentWaitDialog != null) {
147554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            currentWaitDialog.setVisible(false);
148554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            currentWaitDialog = null;
149554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
150554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    }
151554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
1525cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    @Override
153554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    public void showMessageDialog(String s) {
154554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        // Hide the wait dialog...
155554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        if (currentWaitDialog != null) {
156554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            currentWaitDialog.setVisible(false);
157554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
158554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
159554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        try {
160554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            JOptionPane.showMessageDialog(this, s);
161554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        } finally {
162554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            // And reshow it afterwards...
163554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            if (currentWaitDialog != null) {
164554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                showWaitDialogLater();
165554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            }
166554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
167554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    }
168554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
1695cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    @Override
170554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    public boolean showConfirmDialog(String title, String message) {
171554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        // Hide the wait dialog...
172554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        if (currentWaitDialog != null) {
173554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            currentWaitDialog.setVisible(false);
174554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
175554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
176554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        try {
177554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            return JOptionPane.showConfirmDialog(this, title, message, JOptionPane.YES_NO_OPTION)
178554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                    == JOptionPane.YES_OPTION;
179554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        } finally {
180554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            // And reshow it afterwards...
181554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            if (currentWaitDialog != null) {
182554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                showWaitDialogLater();
183554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            }
184554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
185554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    }
186554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
1875cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    @Override
188554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    public String showInputDialog(String message) {
189554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        // Hide the wait dialog...
190554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        if (currentWaitDialog != null) {
191554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            currentWaitDialog.setVisible(false);
192554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
193554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
194554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        try {
195554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            return JOptionPane.showInputDialog(message);
196554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        } finally {
197554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            // And reshow it afterwards...
198554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            if (currentWaitDialog != null) {
199554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                showWaitDialogLater();
200554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            }
201554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
202554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    }
203554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
2045cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    @Override
205554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    @SuppressWarnings("unchecked")
206554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    public <T> T showChoiceDialog(String title, String message, T[] choices) {
207554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        // Hide the wait dialog...
208554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        if (currentWaitDialog != null) {
209554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            currentWaitDialog.setVisible(false);
210554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
211554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
212554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        try{
213554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            return (T)JOptionPane.showInputDialog(this,
214554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                    title,
215554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                    message,
216554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                    JOptionPane.QUESTION_MESSAGE,
217554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                    null,
218554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                    choices,
219554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                    choices[0]);
220554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        } finally {
221554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            // And reshow it afterwards...
222554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            if (currentWaitDialog != null) {
223554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                showWaitDialogLater();
224554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            }
225554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
226554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    }
227554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
2285cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    @Override
229554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    public File showSaveDialog() {
230554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        // Hide the wait dialog...
231554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        if (currentWaitDialog != null) {
232554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            currentWaitDialog.setVisible(false);
233554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
234554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
235554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        try{
236554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            if (jfc == null) {
237554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                jfc = new JFileChooser();
238554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            }
239554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
240554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            int ret = jfc.showSaveDialog(this);
241554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            if (ret == JFileChooser.APPROVE_OPTION) {
242554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                return jfc.getSelectedFile();
243554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            } else {
244554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                return null;
245554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            }
246554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        } finally {
247554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            // And reshow it afterwards...
248554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            if (currentWaitDialog != null) {
249554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                showWaitDialogLater();
250554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            }
251554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
252554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    }
253554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
2545cb8998363a16e667faee4eaa7e5040bce7e702bAndreas Gampe    @Override
255554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    public File[] showOpenDialog(boolean multi) {
256554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        // Hide the wait dialog...
257554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        if (currentWaitDialog != null) {
258554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            currentWaitDialog.setVisible(false);
259554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
260554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
261554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        try{
262554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            if (jfc == null) {
263554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                jfc = new JFileChooser();
264554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            }
265554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
266554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            jfc.setMultiSelectionEnabled(multi);
267554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            int ret = jfc.showOpenDialog(this);
268554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            if (ret == JFileChooser.APPROVE_OPTION) {
269554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                return jfc.getSelectedFiles();
270554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            } else {
271554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                return null;
272554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            }
273554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        } finally {
274554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            // And reshow it afterwards...
275554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            if (currentWaitDialog != null) {
276554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                showWaitDialogLater();
277554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            }
278554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
279554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    }
280554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
281554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    private class ClientListCellRenderer extends DefaultListCellRenderer {
282554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe
283554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        @Override
284554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        public Component getListCellRendererComponent(JList<?> list, Object value, int index,
285554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe                boolean isSelected, boolean cellHasFocus) {
286554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            ClientData cd = ((Client) value).getClientData();
287554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            String s = cd.getClientDescription() + " (pid " + cd.getPid() + ")";
288554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe            return super.getListCellRendererComponent(list, s, index, isSelected, cellHasFocus);
289554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe        }
290554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe    }
291554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe}
292