mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-23 01:29:33 +00:00
added progress bar while scanning contiki (may take several seconds)
This commit is contained in:
parent
e3264d2e00
commit
472ecf2120
@ -26,7 +26,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
@ -126,45 +126,46 @@ public class ContikiMoteTypeDialog extends JDialog {
|
||||
* @return True if compilation succeeded and library is ready to be loaded
|
||||
*/
|
||||
public static boolean showDialog(Container parentContainer, Simulation simulation,
|
||||
ContikiMoteType moteTypeToConfigure) {
|
||||
final ContikiMoteType moteTypeToConfigure) {
|
||||
|
||||
ContikiMoteTypeDialog myDialog = null;
|
||||
ContikiMoteTypeDialog tmpDialog = null;
|
||||
if (parentContainer instanceof Window) {
|
||||
myDialog = new ContikiMoteTypeDialog((Window) parentContainer);
|
||||
tmpDialog = new ContikiMoteTypeDialog((Window) parentContainer);
|
||||
} else if (parentContainer instanceof Dialog) {
|
||||
myDialog = new ContikiMoteTypeDialog((Dialog) parentContainer);
|
||||
tmpDialog = new ContikiMoteTypeDialog((Dialog) parentContainer);
|
||||
} else if (parentContainer instanceof Frame) {
|
||||
myDialog = new ContikiMoteTypeDialog((Frame) parentContainer);
|
||||
tmpDialog = new ContikiMoteTypeDialog((Frame) parentContainer);
|
||||
} else {
|
||||
logger.fatal("Unknown parent container type: " + parentContainer);
|
||||
return false;
|
||||
}
|
||||
|
||||
myDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
|
||||
final ContikiMoteTypeDialog dialog = tmpDialog;
|
||||
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
|
||||
|
||||
myDialog.myMoteType = moteTypeToConfigure;
|
||||
myDialog.myGUI = simulation.getGUI();
|
||||
myDialog.allOtherTypes = simulation.getMoteTypes();
|
||||
dialog.myMoteType = moteTypeToConfigure;
|
||||
dialog.myGUI = simulation.getGUI();
|
||||
dialog.allOtherTypes = simulation.getMoteTypes();
|
||||
|
||||
// Set identifier of mote type
|
||||
if (moteTypeToConfigure.getIdentifier() != null) {
|
||||
// Identifier already preset, assuming recompilation of mote type library
|
||||
// Use preset identifier (read-only)
|
||||
myDialog.textID.setText(moteTypeToConfigure.getIdentifier());
|
||||
myDialog.textID.setEditable(false);
|
||||
myDialog.textID.setEnabled(false);
|
||||
dialog.textID.setText(moteTypeToConfigure.getIdentifier());
|
||||
dialog.textID.setEditable(false);
|
||||
dialog.textID.setEnabled(false);
|
||||
|
||||
// Change title to indicate this is a recompilation
|
||||
myDialog.setTitle("Recreate Mote Type");
|
||||
dialog.setTitle("Recreate Mote Type");
|
||||
} else {
|
||||
// Suggest new identifier
|
||||
String suggestedID = ContikiMoteType.generateUniqueMoteTypeID(myDialog.allOtherTypes, null);
|
||||
myDialog.textID.setText(suggestedID);
|
||||
String suggestedID = ContikiMoteType.generateUniqueMoteTypeID(dialog.allOtherTypes, null);
|
||||
dialog.textID.setText(suggestedID);
|
||||
}
|
||||
|
||||
// Set preset description of mote type
|
||||
if (moteTypeToConfigure.getDescription() != null) {
|
||||
myDialog.textDescription.setText(moteTypeToConfigure.getDescription());
|
||||
dialog.textDescription.setText(moteTypeToConfigure.getDescription());
|
||||
} else {
|
||||
// Suggest unique description
|
||||
int counter = 0;
|
||||
@ -176,61 +177,75 @@ public class ContikiMoteTypeDialog extends JDialog {
|
||||
descriptionOK = true;
|
||||
|
||||
// Check if identifier is already used by some other type
|
||||
for (MoteType existingMoteType : myDialog.allOtherTypes) {
|
||||
if (existingMoteType != myDialog.myMoteType
|
||||
for (MoteType existingMoteType : dialog.allOtherTypes) {
|
||||
if (existingMoteType != dialog.myMoteType
|
||||
&& existingMoteType.getDescription().equals(testDescription)) {
|
||||
descriptionOK = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
myDialog.textDescription.setText(testDescription);
|
||||
dialog.textDescription.setText(testDescription);
|
||||
}
|
||||
|
||||
// Set preset Contiki base directory of mote type
|
||||
if (moteTypeToConfigure.getContikiBaseDir() != null) {
|
||||
myDialog.textContikiDir.setText(moteTypeToConfigure.getContikiBaseDir());
|
||||
dialog.textContikiDir.setText(moteTypeToConfigure.getContikiBaseDir());
|
||||
}
|
||||
|
||||
// Set preset Contiki core directory of mote type
|
||||
if (moteTypeToConfigure.getContikiCoreDir() != null) {
|
||||
myDialog.textCoreDir.setText(moteTypeToConfigure.getContikiCoreDir());
|
||||
dialog.textCoreDir.setText(moteTypeToConfigure.getContikiCoreDir());
|
||||
}
|
||||
|
||||
// Set preset project directories of mote type
|
||||
if (moteTypeToConfigure.getProjectDirs() != null) {
|
||||
myDialog.moteTypeProjectDirs = moteTypeToConfigure
|
||||
dialog.moteTypeProjectDirs = moteTypeToConfigure
|
||||
.getProjectDirs();
|
||||
String projectText = null;
|
||||
for (File projectDir : myDialog.moteTypeProjectDirs) {
|
||||
for (File projectDir : dialog.moteTypeProjectDirs) {
|
||||
if (projectText == null) {
|
||||
projectText = "'" + projectDir.getPath() + "'";
|
||||
} else {
|
||||
projectText += ", '" + projectDir.getPath() + "'";
|
||||
}
|
||||
}
|
||||
myDialog.textProjectDirs.setText(projectText);
|
||||
dialog.textProjectDirs.setText(projectText);
|
||||
}
|
||||
|
||||
// Set preset "use symbols"
|
||||
if (moteTypeToConfigure.hasSystemSymbols()) {
|
||||
myDialog.symbolsCheckBox.setSelected(true);
|
||||
dialog.symbolsCheckBox.setSelected(true);
|
||||
}
|
||||
|
||||
// Set preset communication stack
|
||||
myDialog.commStackComboBox.setSelectedItem(moteTypeToConfigure.getCommunicationStack());
|
||||
dialog.commStackComboBox.setSelectedItem(moteTypeToConfigure.getCommunicationStack());
|
||||
|
||||
// Scan directories for processes, sensors and core interfaces
|
||||
// TODO Really do this without starting a separate thread?
|
||||
myDialog.updateVisualFields();
|
||||
myDialog.rescanDirectories();
|
||||
// Scan directories for processes, sensors and core interfaces, and then continue
|
||||
dialog.updateVisualFields();
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
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
|
||||
if (moteTypeToConfigure.getProcesses() != null) {
|
||||
for (String presetProcess : moteTypeToConfigure.getProcesses()) {
|
||||
// Try to find process in current list
|
||||
boolean foundAndSelectedProcess = false;
|
||||
for (Component processCheckBox : myDialog.processPanel.getComponents()) {
|
||||
for (Component processCheckBox : dialog.processPanel.getComponents()) {
|
||||
boolean inCompileFile = false;
|
||||
ContikiProcess process = (ContikiProcess) ((JCheckBox) processCheckBox).getClientProperty("process");
|
||||
|
||||
@ -258,14 +273,14 @@ public class ContikiMoteTypeDialog extends JDialog {
|
||||
+ "(" + presetProcess + ") not found during scan."
|
||||
+ "\nDo you want to include this anyway?";
|
||||
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,
|
||||
options, options[0]);
|
||||
|
||||
if (answer == JOptionPane.YES_OPTION) {
|
||||
// Create new check box
|
||||
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
|
||||
if (moteTypeToConfigure.getSensors() != null) {
|
||||
// Deselect all sensors already automatically selected
|
||||
for (Component coreInterfaceCheckBox : myDialog.sensorPanel
|
||||
for (Component coreInterfaceCheckBox : dialog.sensorPanel
|
||||
.getComponents()) {
|
||||
((JCheckBox) coreInterfaceCheckBox).setSelected(false);
|
||||
}
|
||||
@ -282,7 +297,7 @@ public class ContikiMoteTypeDialog extends JDialog {
|
||||
for (String presetSensor : moteTypeToConfigure.getSensors()) {
|
||||
// Try to find sensor in current list
|
||||
boolean foundAndSelectedSensor = false;
|
||||
for (Component sensorCheckBox : myDialog.sensorPanel.getComponents()) {
|
||||
for (Component sensorCheckBox : dialog.sensorPanel.getComponents()) {
|
||||
if (presetSensor.equals(((JCheckBox) sensorCheckBox).getText())) {
|
||||
((JCheckBox) sensorCheckBox).setSelected(true);
|
||||
foundAndSelectedSensor = true;
|
||||
@ -299,14 +314,14 @@ public class ContikiMoteTypeDialog extends JDialog {
|
||||
+ "(" + presetSensor + ") not found during scan."
|
||||
+ "\nDo you want to include this anyway?";
|
||||
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,
|
||||
options, options[0]);
|
||||
|
||||
if (answer == JOptionPane.YES_OPTION) {
|
||||
// Create new check box
|
||||
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
|
||||
if (moteTypeToConfigure.getCoreInterfaces() != null) {
|
||||
// Deselect all core interfaces already automatically selected
|
||||
for (Component coreInterfaceCheckBox : myDialog.coreInterfacePanel
|
||||
for (Component coreInterfaceCheckBox : dialog.coreInterfacePanel
|
||||
.getComponents()) {
|
||||
((JCheckBox) coreInterfaceCheckBox).setSelected(false);
|
||||
}
|
||||
@ -323,7 +338,7 @@ public class ContikiMoteTypeDialog extends JDialog {
|
||||
for (String presetCoreInterface : moteTypeToConfigure.getCoreInterfaces()) {
|
||||
// Try to find core interface in current list
|
||||
boolean foundAndSelectedCoreInterface = false;
|
||||
for (Component coreInterfaceCheckBox : myDialog.coreInterfacePanel
|
||||
for (Component coreInterfaceCheckBox : dialog.coreInterfacePanel
|
||||
.getComponents()) {
|
||||
if (presetCoreInterface.equals(((JCheckBox) coreInterfaceCheckBox)
|
||||
.getText())) {
|
||||
@ -342,14 +357,14 @@ public class ContikiMoteTypeDialog extends JDialog {
|
||||
+ "(" + presetCoreInterface + ") not found during scan."
|
||||
+ "\nDo you want to include this anyway?";
|
||||
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,
|
||||
options, options[0]);
|
||||
|
||||
if (answer == JOptionPane.YES_OPTION) {
|
||||
// Create new check box
|
||||
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
|
||||
if (moteTypeToConfigure.getMoteInterfaces() != null) {
|
||||
// Deselect all mote interfaces already automatically selected
|
||||
for (Component moteInterfaceCheckBox : myDialog.moteInterfacePanel
|
||||
for (Component moteInterfaceCheckBox : dialog.moteInterfacePanel
|
||||
.getComponents()) {
|
||||
((JCheckBox) moteInterfaceCheckBox).setSelected(false);
|
||||
}
|
||||
@ -366,7 +381,7 @@ public class ContikiMoteTypeDialog extends JDialog {
|
||||
for (Class presetMoteInterface : moteTypeToConfigure.getMoteInterfaces()) {
|
||||
// Try to find mote interface in current list
|
||||
boolean foundAndSelectedMoteInterface = false;
|
||||
for (Component moteInterfaceCheckBox : myDialog.moteInterfacePanel
|
||||
for (Component moteInterfaceCheckBox : dialog.moteInterfacePanel
|
||||
.getComponents()) {
|
||||
Class moteInterfaceClass = (Class) ((JCheckBox) moteInterfaceCheckBox)
|
||||
.getClientProperty("class");
|
||||
@ -385,28 +400,32 @@ public class ContikiMoteTypeDialog extends JDialog {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
});
|
||||
|
||||
// Set position and focus of dialog
|
||||
myDialog.pack();
|
||||
myDialog.setLocationRelativeTo(parentContainer);
|
||||
myDialog.textDescription.requestFocus();
|
||||
myDialog.textDescription.select(0, myDialog.textDescription.getText()
|
||||
dialog.pack();
|
||||
dialog.setLocationRelativeTo(parentContainer);
|
||||
dialog.textDescription.requestFocus();
|
||||
dialog.textDescription.select(0, dialog.textDescription.getText()
|
||||
.length());
|
||||
|
||||
Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
|
||||
if (maxSize != null &&
|
||||
(myDialog.getSize().getWidth() > maxSize.getWidth()
|
||||
|| myDialog.getSize().getHeight() > maxSize.getHeight())) {
|
||||
(dialog.getSize().getWidth() > maxSize.getWidth()
|
||||
|| dialog.getSize().getHeight() > maxSize.getHeight())) {
|
||||
Dimension newSize = new Dimension();
|
||||
newSize.height = Math.min((int) maxSize.getHeight(), (int) myDialog.getSize().getHeight());
|
||||
newSize.width = Math.min((int) maxSize.getWidth(), (int) myDialog.getSize().getWidth());
|
||||
newSize.height = Math.min((int) maxSize.getHeight(), (int) dialog.getSize().getHeight());
|
||||
newSize.width = Math.min((int) maxSize.getWidth(), (int) dialog.getSize().getWidth());
|
||||
/*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
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user