enable reconfigurable mote interfaces
some minor trying to fix a bug that occasionally hangs cooja when reconfiguring a mote type
This commit is contained in:
parent
92655159c8
commit
e5fe37336e
2 changed files with 97 additions and 59 deletions
|
@ -256,6 +256,12 @@ public abstract class AbstractCompileDialog extends JDialog {
|
|||
|
||||
topPanel.add(sourcePanel);
|
||||
|
||||
|
||||
Action cancelAction = new AbstractAction("Cancel") {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
AbstractCompileDialog.this.dispose();
|
||||
}
|
||||
};
|
||||
Action compileAction = new AbstractAction("Compile") {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
@ -345,6 +351,41 @@ public abstract class AbstractCompileDialog extends JDialog {
|
|||
}
|
||||
});
|
||||
|
||||
descriptionField.requestFocus();
|
||||
descriptionField.select(0, descriptionField.getText().length());
|
||||
|
||||
/* Add listener only after restoring old config */
|
||||
contikiField.getDocument().addDocumentListener(contikiFieldListener);
|
||||
|
||||
/* Final touches: respect window size, focus on description etc */
|
||||
Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
|
||||
if (maxSize != null &&
|
||||
(getSize().getWidth() > maxSize.getWidth() || getSize().getHeight() > maxSize.getHeight())) {
|
||||
Dimension newSize = new Dimension();
|
||||
newSize.height = Math.min((int) maxSize.getHeight(), (int) getSize().getHeight());
|
||||
newSize.width = Math.min((int) maxSize.getWidth(), (int) getSize().getWidth());
|
||||
/*logger.info("Resizing dialog: " + myDialog.getSize() + " -> " + newSize);*/
|
||||
setSize(newSize);
|
||||
}
|
||||
|
||||
/* Recompile at Ctrl+R */
|
||||
InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.CTRL_DOWN_MASK, false), "recompile");
|
||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), "dispose");
|
||||
getRootPane().getActionMap().put("recompile", compileAction);
|
||||
getRootPane().getActionMap().put("dispose", cancelAction);
|
||||
|
||||
pack();
|
||||
setLocationRelativeTo(parent);
|
||||
|
||||
new Thread() {
|
||||
public void run() {
|
||||
tryRestoreMoteType();
|
||||
};
|
||||
}.start();
|
||||
}
|
||||
|
||||
private void tryRestoreMoteType() {
|
||||
/* Restore old configuration if mote type is already configured */
|
||||
boolean restoredDialogState = false;
|
||||
if (moteType != null) {
|
||||
|
@ -390,39 +431,14 @@ public abstract class AbstractCompileDialog extends JDialog {
|
|||
|
||||
/* Restore compile commands */
|
||||
if (moteType.getCompileCommands() != null) {
|
||||
setCompileCommands(moteType.getCompileCommands());
|
||||
setDialogState(DialogState.AWAITING_COMPILATION);
|
||||
setCompileCommands(moteType.getCompileCommands());
|
||||
setDialogState(DialogState.AWAITING_COMPILATION);
|
||||
restoredDialogState = true;
|
||||
}
|
||||
}
|
||||
if (!restoredDialogState) {
|
||||
setDialogState(DialogState.NO_SELECTION);
|
||||
}
|
||||
|
||||
descriptionField.requestFocus();
|
||||
descriptionField.select(0, descriptionField.getText().length());
|
||||
|
||||
/* Add listener only after restoring old config */
|
||||
contikiField.getDocument().addDocumentListener(contikiFieldListener);
|
||||
|
||||
/* Final touches: respect window size, focus on description etc */
|
||||
Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
|
||||
if (maxSize != null &&
|
||||
(getSize().getWidth() > maxSize.getWidth() || getSize().getHeight() > maxSize.getHeight())) {
|
||||
Dimension newSize = new Dimension();
|
||||
newSize.height = Math.min((int) maxSize.getHeight(), (int) getSize().getHeight());
|
||||
newSize.width = Math.min((int) maxSize.getWidth(), (int) getSize().getWidth());
|
||||
/*logger.info("Resizing dialog: " + myDialog.getSize() + " -> " + newSize);*/
|
||||
setSize(newSize);
|
||||
}
|
||||
|
||||
/* Recompile at Ctrl+R */
|
||||
InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.CTRL_DOWN_MASK, false), "recompile");
|
||||
getRootPane().getActionMap().put("recompile", compileAction);
|
||||
|
||||
pack();
|
||||
setLocationRelativeTo(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -472,11 +488,15 @@ public abstract class AbstractCompileDialog extends JDialog {
|
|||
throw new Exception("No compile commands specified");
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
setDialogState(DialogState.IS_COMPILING);
|
||||
}
|
||||
});
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
setDialogState(DialogState.IS_COMPILING);
|
||||
} else {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
setDialogState(DialogState.IS_COMPILING);
|
||||
}
|
||||
});
|
||||
}
|
||||
createNewCompilationTab(taskOutput);
|
||||
|
||||
/* Add abort compilation menu item */
|
||||
|
@ -542,6 +562,7 @@ public abstract class AbstractCompileDialog extends JDialog {
|
|||
);
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("Exception when compiling: " + ex.getMessage());
|
||||
taskOutput.addMessage(ex.getMessage(), MessageList.ERROR);
|
||||
ex.printStackTrace();
|
||||
compilationFailureAction.actionPerformed(null);
|
||||
}
|
||||
|
@ -698,8 +719,6 @@ public abstract class AbstractCompileDialog extends JDialog {
|
|||
}
|
||||
|
||||
private Action defaultAction = new AbstractAction("Use default") {
|
||||
private static final long serialVersionUID = 2874355910493988933L;
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
/* Unselect all */
|
||||
for (Component c : moteIntfBox.getComponents()) {
|
||||
|
|
|
@ -36,6 +36,7 @@ import java.awt.Container;
|
|||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
|
@ -103,28 +104,7 @@ public class ContikiMoteCompileDialog extends AbstractCompileDialog {
|
|||
addAdvancedTab(tabbedPane);
|
||||
}
|
||||
|
||||
public boolean canLoadFirmware(File file) {
|
||||
/* Disallow loading firmwares without compilation */
|
||||
/*
|
||||
if (file.getName().endsWith(ContikiMoteType.librarySuffix)) {
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDefaultCompileCommands(File source) {
|
||||
if (moteType == null) {
|
||||
/* Not ready to compile yet */
|
||||
return "";
|
||||
}
|
||||
|
||||
if (source == null || !source.exists()) {
|
||||
/* Not ready to compile yet */
|
||||
return "";
|
||||
}
|
||||
|
||||
private void updateForSource(File source) {
|
||||
if (moteType.getIdentifier() == null) {
|
||||
/* Generate mote type identifier */
|
||||
moteType.setIdentifier(
|
||||
|
@ -152,7 +132,7 @@ public class ContikiMoteCompileDialog extends AbstractCompileDialog {
|
|||
|
||||
if (((ContikiMoteType)moteType).javaClassName == null) {
|
||||
logger.fatal("Could not allocate a core communicator.");
|
||||
return "";
|
||||
return;
|
||||
}
|
||||
|
||||
/* Prepare compiler environment */
|
||||
|
@ -167,8 +147,8 @@ public class ContikiMoteCompileDialog extends AbstractCompileDialog {
|
|||
((ContikiMoteType)moteType).javaClassName
|
||||
);
|
||||
CompileContiki.redefineCOOJASources(
|
||||
moteType,
|
||||
env
|
||||
moteType,
|
||||
env
|
||||
);
|
||||
|
||||
String[] envOneDimension = new String[env.length];
|
||||
|
@ -184,6 +164,45 @@ public class ContikiMoteCompileDialog extends AbstractCompileDialog {
|
|||
e.printStackTrace();
|
||||
env = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canLoadFirmware(File file) {
|
||||
/* Disallow loading firmwares without compilation */
|
||||
/*
|
||||
if (file.getName().endsWith(ContikiMoteType.librarySuffix)) {
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDefaultCompileCommands(final File source) {
|
||||
if (moteType == null) {
|
||||
/* Not ready to compile yet */
|
||||
return "";
|
||||
}
|
||||
|
||||
if (source == null || !source.exists()) {
|
||||
/* Not ready to compile yet */
|
||||
return "";
|
||||
}
|
||||
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
updateForSource(source);
|
||||
} else {
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
updateForSource(source);
|
||||
}
|
||||
});
|
||||
} catch (InvocationTargetException e) {
|
||||
logger.fatal("Error when updating for source " + source + ": " + e.getMessage(), e);
|
||||
} catch (InterruptedException e) {
|
||||
logger.fatal("Error when updating for source " + source + ": " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
String defines = "";
|
||||
if (((ContikiMoteType) moteType).getNetworkStack().getHeaderFile() != null) {
|
||||
|
|
Loading…
Reference in a new issue