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
|
@ -256,6 +256,12 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
|
|
||||||
topPanel.add(sourcePanel);
|
topPanel.add(sourcePanel);
|
||||||
|
|
||||||
|
|
||||||
|
Action cancelAction = new AbstractAction("Cancel") {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
AbstractCompileDialog.this.dispose();
|
||||||
|
}
|
||||||
|
};
|
||||||
Action compileAction = new AbstractAction("Compile") {
|
Action compileAction = new AbstractAction("Compile") {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
public void actionPerformed(ActionEvent e) {
|
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 */
|
/* Restore old configuration if mote type is already configured */
|
||||||
boolean restoredDialogState = false;
|
boolean restoredDialogState = false;
|
||||||
if (moteType != null) {
|
if (moteType != null) {
|
||||||
|
@ -398,31 +439,6 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
if (!restoredDialogState) {
|
if (!restoredDialogState) {
|
||||||
setDialogState(DialogState.NO_SELECTION);
|
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");
|
throw new Exception("No compile commands specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
if (SwingUtilities.isEventDispatchThread()) {
|
||||||
|
setDialogState(DialogState.IS_COMPILING);
|
||||||
|
} else {
|
||||||
|
SwingUtilities.invokeAndWait(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
setDialogState(DialogState.IS_COMPILING);
|
setDialogState(DialogState.IS_COMPILING);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
createNewCompilationTab(taskOutput);
|
createNewCompilationTab(taskOutput);
|
||||||
|
|
||||||
/* Add abort compilation menu item */
|
/* Add abort compilation menu item */
|
||||||
|
@ -542,6 +562,7 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
);
|
);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("Exception when compiling: " + ex.getMessage());
|
logger.fatal("Exception when compiling: " + ex.getMessage());
|
||||||
|
taskOutput.addMessage(ex.getMessage(), MessageList.ERROR);
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
compilationFailureAction.actionPerformed(null);
|
compilationFailureAction.actionPerformed(null);
|
||||||
}
|
}
|
||||||
|
@ -698,8 +719,6 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Action defaultAction = new AbstractAction("Use default") {
|
private Action defaultAction = new AbstractAction("Use default") {
|
||||||
private static final long serialVersionUID = 2874355910493988933L;
|
|
||||||
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
/* Unselect all */
|
/* Unselect all */
|
||||||
for (Component c : moteIntfBox.getComponents()) {
|
for (Component c : moteIntfBox.getComponents()) {
|
||||||
|
|
|
@ -36,6 +36,7 @@ import java.awt.Container;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
|
@ -103,28 +104,7 @@ public class ContikiMoteCompileDialog extends AbstractCompileDialog {
|
||||||
addAdvancedTab(tabbedPane);
|
addAdvancedTab(tabbedPane);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canLoadFirmware(File file) {
|
private void updateForSource(File source) {
|
||||||
/* 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 "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (moteType.getIdentifier() == null) {
|
if (moteType.getIdentifier() == null) {
|
||||||
/* Generate mote type identifier */
|
/* Generate mote type identifier */
|
||||||
moteType.setIdentifier(
|
moteType.setIdentifier(
|
||||||
|
@ -152,7 +132,7 @@ public class ContikiMoteCompileDialog extends AbstractCompileDialog {
|
||||||
|
|
||||||
if (((ContikiMoteType)moteType).javaClassName == null) {
|
if (((ContikiMoteType)moteType).javaClassName == null) {
|
||||||
logger.fatal("Could not allocate a core communicator.");
|
logger.fatal("Could not allocate a core communicator.");
|
||||||
return "";
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare compiler environment */
|
/* Prepare compiler environment */
|
||||||
|
@ -184,6 +164,45 @@ public class ContikiMoteCompileDialog extends AbstractCompileDialog {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
env = null;
|
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 = "";
|
String defines = "";
|
||||||
if (((ContikiMoteType) moteType).getNetworkStack().getHeaderFile() != null) {
|
if (((ContikiMoteType) moteType).getNetworkStack().getHeaderFile() != null) {
|
||||||
|
|
Loading…
Reference in a new issue