added icon interface

This commit is contained in:
fros4943 2008-02-11 15:17:30 +00:00
parent bae02d252a
commit 38cce5e9c7
2 changed files with 38 additions and 3 deletions

View File

@ -26,13 +26,18 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: ESBMoteType.java,v 1.1 2008/02/07 14:53:29 fros4943 Exp $
* $Id: ESBMoteType.java,v 1.2 2008/02/11 15:17:30 fros4943 Exp $
*/
package se.sics.cooja.mspmote;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.net.URL;
import javax.swing.*;
import org.apache.log4j.Logger;
import se.sics.cooja.*;
@ClassDescription("ESB Mote Type")
@ -51,6 +56,24 @@ public class ESBMoteType extends MspMoteType {
setDescription(targetNice + " Mote Type #" + identifier);
}
public Icon getMoteTypeIcon() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
URL imageURL = this.getClass().getClassLoader().getResource("images/esb.jpg");
Image image = toolkit.getImage(imageURL);
MediaTracker tracker = new MediaTracker(GUI.frame);
tracker.addImage(image, 1);
try {
tracker.waitForAll();
} catch (InterruptedException ex) {
}
if (image.getHeight(GUI.frame) > 0 && image.getWidth(GUI.frame) > 0) {
image = image.getScaledInstance((100*image.getWidth(GUI.frame)/image.getHeight(GUI.frame)), 100, Image.SCALE_DEFAULT);
return new ImageIcon(image);
}
return null;
}
public Mote generateMote(Simulation simulation) {
return new ESBMote(this, simulation);
}

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MspMoteType.java,v 1.2 2008/02/08 14:30:28 fros4943 Exp $
* $Id: MspMoteType.java,v 1.3 2008/02/11 15:17:30 fros4943 Exp $
*/
package se.sics.cooja.mspmote;
@ -420,7 +420,8 @@ public abstract class MspMoteType implements MoteType {
sourceFile.getName().length() - 2);
final String command = getCompileCommand(filenameNoExtension);
logger.info("Compile command: " + command);
logger.info("-- Compiling MSP430 Firmware --");
logger.info("command: " + command);
compilationOutput.clearMessages();
@ -880,10 +881,21 @@ public abstract class MspMoteType implements MoteType {
smallPane.add(BorderLayout.EAST, label);
panel.add(smallPane);
// Icon (if available)
Icon moteTypeIcon = getMoteTypeIcon();
if (moteTypeIcon != null) {
smallPane = new JPanel(new BorderLayout());
label = new JLabel(moteTypeIcon);
smallPane.add(BorderLayout.CENTER, label);
panel.add(smallPane);
}
panel.add(Box.createRigidArea(new Dimension(0, 5)));
return panel;
}
public abstract Icon getMoteTypeIcon();
public ProjectConfig getConfig() {
logger.warn("Msp mote type project config not implemented");
return null;