added progress bar while scanning contiki (may take several seconds)

This commit is contained in:
fros4943 2009-02-18 15:02:32 +00:00
parent e3264d2e00
commit 472ecf2120

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: ContikiMoteTypeDialog.java,v 1.51 2009/01/12 10:44:36 fros4943 Exp $ * $Id: ContikiMoteTypeDialog.java,v 1.52 2009/02/18 15:02:32 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote; package se.sics.cooja.contikimote;
@ -126,45 +126,46 @@ public class ContikiMoteTypeDialog extends JDialog {
* @return True if compilation succeeded and library is ready to be loaded * @return True if compilation succeeded and library is ready to be loaded
*/ */
public static boolean showDialog(Container parentContainer, Simulation simulation, public static boolean showDialog(Container parentContainer, Simulation simulation,
ContikiMoteType moteTypeToConfigure) { final ContikiMoteType moteTypeToConfigure) {
ContikiMoteTypeDialog myDialog = null; ContikiMoteTypeDialog tmpDialog = null;
if (parentContainer instanceof Window) { if (parentContainer instanceof Window) {
myDialog = new ContikiMoteTypeDialog((Window) parentContainer); tmpDialog = new ContikiMoteTypeDialog((Window) parentContainer);
} else if (parentContainer instanceof Dialog) { } else if (parentContainer instanceof Dialog) {
myDialog = new ContikiMoteTypeDialog((Dialog) parentContainer); tmpDialog = new ContikiMoteTypeDialog((Dialog) parentContainer);
} else if (parentContainer instanceof Frame) { } else if (parentContainer instanceof Frame) {
myDialog = new ContikiMoteTypeDialog((Frame) parentContainer); tmpDialog = new ContikiMoteTypeDialog((Frame) parentContainer);
} else { } else {
logger.fatal("Unknown parent container type: " + parentContainer); logger.fatal("Unknown parent container type: " + parentContainer);
return false; return false;
} }
myDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); final ContikiMoteTypeDialog dialog = tmpDialog;
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
myDialog.myMoteType = moteTypeToConfigure; dialog.myMoteType = moteTypeToConfigure;
myDialog.myGUI = simulation.getGUI(); dialog.myGUI = simulation.getGUI();
myDialog.allOtherTypes = simulation.getMoteTypes(); dialog.allOtherTypes = simulation.getMoteTypes();
// Set identifier of mote type // Set identifier of mote type
if (moteTypeToConfigure.getIdentifier() != null) { if (moteTypeToConfigure.getIdentifier() != null) {
// Identifier already preset, assuming recompilation of mote type library // Identifier already preset, assuming recompilation of mote type library
// Use preset identifier (read-only) // Use preset identifier (read-only)
myDialog.textID.setText(moteTypeToConfigure.getIdentifier()); dialog.textID.setText(moteTypeToConfigure.getIdentifier());
myDialog.textID.setEditable(false); dialog.textID.setEditable(false);
myDialog.textID.setEnabled(false); dialog.textID.setEnabled(false);
// Change title to indicate this is a recompilation // Change title to indicate this is a recompilation
myDialog.setTitle("Recreate Mote Type"); dialog.setTitle("Recreate Mote Type");
} else { } else {
// Suggest new identifier // Suggest new identifier
String suggestedID = ContikiMoteType.generateUniqueMoteTypeID(myDialog.allOtherTypes, null); String suggestedID = ContikiMoteType.generateUniqueMoteTypeID(dialog.allOtherTypes, null);
myDialog.textID.setText(suggestedID); dialog.textID.setText(suggestedID);
} }
// Set preset description of mote type // Set preset description of mote type
if (moteTypeToConfigure.getDescription() != null) { if (moteTypeToConfigure.getDescription() != null) {
myDialog.textDescription.setText(moteTypeToConfigure.getDescription()); dialog.textDescription.setText(moteTypeToConfigure.getDescription());
} else { } else {
// Suggest unique description // Suggest unique description
int counter = 0; int counter = 0;
@ -176,61 +177,75 @@ public class ContikiMoteTypeDialog extends JDialog {
descriptionOK = true; descriptionOK = true;
// Check if identifier is already used by some other type // Check if identifier is already used by some other type
for (MoteType existingMoteType : myDialog.allOtherTypes) { for (MoteType existingMoteType : dialog.allOtherTypes) {
if (existingMoteType != myDialog.myMoteType if (existingMoteType != dialog.myMoteType
&& existingMoteType.getDescription().equals(testDescription)) { && existingMoteType.getDescription().equals(testDescription)) {
descriptionOK = false; descriptionOK = false;
break; break;
} }
} }
} }
myDialog.textDescription.setText(testDescription); dialog.textDescription.setText(testDescription);
} }
// Set preset Contiki base directory of mote type // Set preset Contiki base directory of mote type
if (moteTypeToConfigure.getContikiBaseDir() != null) { if (moteTypeToConfigure.getContikiBaseDir() != null) {
myDialog.textContikiDir.setText(moteTypeToConfigure.getContikiBaseDir()); dialog.textContikiDir.setText(moteTypeToConfigure.getContikiBaseDir());
} }
// Set preset Contiki core directory of mote type // Set preset Contiki core directory of mote type
if (moteTypeToConfigure.getContikiCoreDir() != null) { if (moteTypeToConfigure.getContikiCoreDir() != null) {
myDialog.textCoreDir.setText(moteTypeToConfigure.getContikiCoreDir()); dialog.textCoreDir.setText(moteTypeToConfigure.getContikiCoreDir());
} }
// Set preset project directories of mote type // Set preset project directories of mote type
if (moteTypeToConfigure.getProjectDirs() != null) { if (moteTypeToConfigure.getProjectDirs() != null) {
myDialog.moteTypeProjectDirs = moteTypeToConfigure dialog.moteTypeProjectDirs = moteTypeToConfigure
.getProjectDirs(); .getProjectDirs();
String projectText = null; String projectText = null;
for (File projectDir : myDialog.moteTypeProjectDirs) { for (File projectDir : dialog.moteTypeProjectDirs) {
if (projectText == null) { if (projectText == null) {
projectText = "'" + projectDir.getPath() + "'"; projectText = "'" + projectDir.getPath() + "'";
} else { } else {
projectText += ", '" + projectDir.getPath() + "'"; projectText += ", '" + projectDir.getPath() + "'";
} }
} }
myDialog.textProjectDirs.setText(projectText); dialog.textProjectDirs.setText(projectText);
} }
// Set preset "use symbols" // Set preset "use symbols"
if (moteTypeToConfigure.hasSystemSymbols()) { if (moteTypeToConfigure.hasSystemSymbols()) {
myDialog.symbolsCheckBox.setSelected(true); dialog.symbolsCheckBox.setSelected(true);
} }
// Set preset communication stack // Set preset communication stack
myDialog.commStackComboBox.setSelectedItem(moteTypeToConfigure.getCommunicationStack()); dialog.commStackComboBox.setSelectedItem(moteTypeToConfigure.getCommunicationStack());
// Scan directories for processes, sensors and core interfaces // Scan directories for processes, sensors and core interfaces, and then continue
// TODO Really do this without starting a separate thread? dialog.updateVisualFields();
myDialog.updateVisualFields(); SwingUtilities.invokeLater(new Runnable() {
myDialog.rescanDirectories(); public void run() {
final JProgressBar pBar = new JProgressBar(0, 100);
pBar.setValue(0);
pBar.setStringPainted(false);
pBar.setIndeterminate(true);
final JDialog pDialog = new JDialog(dialog, "Scanning...");
pDialog.getContentPane().add(pBar, BorderLayout.CENTER);
pDialog.pack();
pDialog.setLocationRelativeTo(dialog);
pDialog.setVisible(true);
new Thread(new Runnable() {
public void run() {
dialog.rescanDirectories();
pDialog.dispose();
// Select preset processes of mote type // Select preset processes of mote type
if (moteTypeToConfigure.getProcesses() != null) { if (moteTypeToConfigure.getProcesses() != null) {
for (String presetProcess : moteTypeToConfigure.getProcesses()) { for (String presetProcess : moteTypeToConfigure.getProcesses()) {
// Try to find process in current list // Try to find process in current list
boolean foundAndSelectedProcess = false; boolean foundAndSelectedProcess = false;
for (Component processCheckBox : myDialog.processPanel.getComponents()) { for (Component processCheckBox : dialog.processPanel.getComponents()) {
boolean inCompileFile = false; boolean inCompileFile = false;
ContikiProcess process = (ContikiProcess) ((JCheckBox) processCheckBox).getClientProperty("process"); ContikiProcess process = (ContikiProcess) ((JCheckBox) processCheckBox).getClientProperty("process");
@ -258,14 +273,14 @@ public class ContikiMoteTypeDialog extends JDialog {
+ "(" + presetProcess + ") not found during scan." + "(" + presetProcess + ") not found during scan."
+ "\nDo you want to include this anyway?"; + "\nDo you want to include this anyway?";
String title = "Add process?"; String title = "Add process?";
int answer = JOptionPane.showOptionDialog(myDialog, question, title, int answer = JOptionPane.showOptionDialog(dialog, question, title,
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,
options, options[0]); options, options[0]);
if (answer == JOptionPane.YES_OPTION) { if (answer == JOptionPane.YES_OPTION) {
// Create new check box // Create new check box
JCheckBox newCheckBox = new JCheckBox(presetProcess, true); JCheckBox newCheckBox = new JCheckBox(presetProcess, true);
myDialog.processPanel.add(newCheckBox); dialog.processPanel.add(newCheckBox);
} }
} }
} }
@ -274,7 +289,7 @@ public class ContikiMoteTypeDialog extends JDialog {
// Select preset sensors // Select preset sensors
if (moteTypeToConfigure.getSensors() != null) { if (moteTypeToConfigure.getSensors() != null) {
// Deselect all sensors already automatically selected // Deselect all sensors already automatically selected
for (Component coreInterfaceCheckBox : myDialog.sensorPanel for (Component coreInterfaceCheckBox : dialog.sensorPanel
.getComponents()) { .getComponents()) {
((JCheckBox) coreInterfaceCheckBox).setSelected(false); ((JCheckBox) coreInterfaceCheckBox).setSelected(false);
} }
@ -282,7 +297,7 @@ public class ContikiMoteTypeDialog extends JDialog {
for (String presetSensor : moteTypeToConfigure.getSensors()) { for (String presetSensor : moteTypeToConfigure.getSensors()) {
// Try to find sensor in current list // Try to find sensor in current list
boolean foundAndSelectedSensor = false; boolean foundAndSelectedSensor = false;
for (Component sensorCheckBox : myDialog.sensorPanel.getComponents()) { for (Component sensorCheckBox : dialog.sensorPanel.getComponents()) {
if (presetSensor.equals(((JCheckBox) sensorCheckBox).getText())) { if (presetSensor.equals(((JCheckBox) sensorCheckBox).getText())) {
((JCheckBox) sensorCheckBox).setSelected(true); ((JCheckBox) sensorCheckBox).setSelected(true);
foundAndSelectedSensor = true; foundAndSelectedSensor = true;
@ -299,14 +314,14 @@ public class ContikiMoteTypeDialog extends JDialog {
+ "(" + presetSensor + ") not found during scan." + "(" + presetSensor + ") not found during scan."
+ "\nDo you want to include this anyway?"; + "\nDo you want to include this anyway?";
String title = "Add sensor?"; String title = "Add sensor?";
int answer = JOptionPane.showOptionDialog(myDialog, question, title, int answer = JOptionPane.showOptionDialog(dialog, question, title,
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,
options, options[0]); options, options[0]);
if (answer == JOptionPane.YES_OPTION) { if (answer == JOptionPane.YES_OPTION) {
// Create new check box // Create new check box
JCheckBox newCheckBox = new JCheckBox(presetSensor, true); JCheckBox newCheckBox = new JCheckBox(presetSensor, true);
myDialog.sensorPanel.add(newCheckBox); dialog.sensorPanel.add(newCheckBox);
} }
} }
} }
@ -315,7 +330,7 @@ public class ContikiMoteTypeDialog extends JDialog {
// Select preset core interfaces // Select preset core interfaces
if (moteTypeToConfigure.getCoreInterfaces() != null) { if (moteTypeToConfigure.getCoreInterfaces() != null) {
// Deselect all core interfaces already automatically selected // Deselect all core interfaces already automatically selected
for (Component coreInterfaceCheckBox : myDialog.coreInterfacePanel for (Component coreInterfaceCheckBox : dialog.coreInterfacePanel
.getComponents()) { .getComponents()) {
((JCheckBox) coreInterfaceCheckBox).setSelected(false); ((JCheckBox) coreInterfaceCheckBox).setSelected(false);
} }
@ -323,7 +338,7 @@ public class ContikiMoteTypeDialog extends JDialog {
for (String presetCoreInterface : moteTypeToConfigure.getCoreInterfaces()) { for (String presetCoreInterface : moteTypeToConfigure.getCoreInterfaces()) {
// Try to find core interface in current list // Try to find core interface in current list
boolean foundAndSelectedCoreInterface = false; boolean foundAndSelectedCoreInterface = false;
for (Component coreInterfaceCheckBox : myDialog.coreInterfacePanel for (Component coreInterfaceCheckBox : dialog.coreInterfacePanel
.getComponents()) { .getComponents()) {
if (presetCoreInterface.equals(((JCheckBox) coreInterfaceCheckBox) if (presetCoreInterface.equals(((JCheckBox) coreInterfaceCheckBox)
.getText())) { .getText())) {
@ -342,14 +357,14 @@ public class ContikiMoteTypeDialog extends JDialog {
+ "(" + presetCoreInterface + ") not found during scan." + "(" + presetCoreInterface + ") not found during scan."
+ "\nDo you want to include this anyway?"; + "\nDo you want to include this anyway?";
String title = "Add core interface?"; String title = "Add core interface?";
int answer = JOptionPane.showOptionDialog(myDialog, question, title, int answer = JOptionPane.showOptionDialog(dialog, question, title,
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,
options, options[0]); options, options[0]);
if (answer == JOptionPane.YES_OPTION) { if (answer == JOptionPane.YES_OPTION) {
// Create new check box // Create new check box
JCheckBox newCheckBox = new JCheckBox(presetCoreInterface, true); JCheckBox newCheckBox = new JCheckBox(presetCoreInterface, true);
myDialog.coreInterfacePanel.add(newCheckBox); dialog.coreInterfacePanel.add(newCheckBox);
} }
} }
} }
@ -358,7 +373,7 @@ public class ContikiMoteTypeDialog extends JDialog {
// Select preset mote interfaces // Select preset mote interfaces
if (moteTypeToConfigure.getMoteInterfaces() != null) { if (moteTypeToConfigure.getMoteInterfaces() != null) {
// Deselect all mote interfaces already automatically selected // Deselect all mote interfaces already automatically selected
for (Component moteInterfaceCheckBox : myDialog.moteInterfacePanel for (Component moteInterfaceCheckBox : dialog.moteInterfacePanel
.getComponents()) { .getComponents()) {
((JCheckBox) moteInterfaceCheckBox).setSelected(false); ((JCheckBox) moteInterfaceCheckBox).setSelected(false);
} }
@ -366,7 +381,7 @@ public class ContikiMoteTypeDialog extends JDialog {
for (Class presetMoteInterface : moteTypeToConfigure.getMoteInterfaces()) { for (Class presetMoteInterface : moteTypeToConfigure.getMoteInterfaces()) {
// Try to find mote interface in current list // Try to find mote interface in current list
boolean foundAndSelectedMoteInterface = false; boolean foundAndSelectedMoteInterface = false;
for (Component moteInterfaceCheckBox : myDialog.moteInterfacePanel for (Component moteInterfaceCheckBox : dialog.moteInterfacePanel
.getComponents()) { .getComponents()) {
Class moteInterfaceClass = (Class) ((JCheckBox) moteInterfaceCheckBox) Class moteInterfaceClass = (Class) ((JCheckBox) moteInterfaceCheckBox)
.getClientProperty("class"); .getClientProperty("class");
@ -385,28 +400,32 @@ public class ContikiMoteTypeDialog extends JDialog {
} }
} }
} }
}
}).start();
}
});
// Set position and focus of dialog // Set position and focus of dialog
myDialog.pack(); dialog.pack();
myDialog.setLocationRelativeTo(parentContainer); dialog.setLocationRelativeTo(parentContainer);
myDialog.textDescription.requestFocus(); dialog.textDescription.requestFocus();
myDialog.textDescription.select(0, myDialog.textDescription.getText() dialog.textDescription.select(0, dialog.textDescription.getText()
.length()); .length());
Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
if (maxSize != null && if (maxSize != null &&
(myDialog.getSize().getWidth() > maxSize.getWidth() (dialog.getSize().getWidth() > maxSize.getWidth()
|| myDialog.getSize().getHeight() > maxSize.getHeight())) { || dialog.getSize().getHeight() > maxSize.getHeight())) {
Dimension newSize = new Dimension(); Dimension newSize = new Dimension();
newSize.height = Math.min((int) maxSize.getHeight(), (int) myDialog.getSize().getHeight()); newSize.height = Math.min((int) maxSize.getHeight(), (int) dialog.getSize().getHeight());
newSize.width = Math.min((int) maxSize.getWidth(), (int) myDialog.getSize().getWidth()); newSize.width = Math.min((int) maxSize.getWidth(), (int) dialog.getSize().getWidth());
/*logger.info("Resizing dialog: " + myDialog.getSize() + " -> " + newSize);*/ /*logger.info("Resizing dialog: " + myDialog.getSize() + " -> " + newSize);*/
myDialog.setSize(newSize); dialog.setSize(newSize);
} }
myDialog.setVisible(true); dialog.setVisible(true);
if (myDialog.myMoteType != null) { if (dialog.myMoteType != null) {
// Library was compiled and loaded // Library was compiled and loaded
return true; return true;
} }