[Firebug-cvs] firebug/project/zaurus/vu/isis/nest/zaurus ZCanvas.java,1.1,1.2 ZMain.java,1.3,1.4
Brought to you by:
doolin
From: <do...@us...> - 2003-07-21 17:09:32
|
Update of /cvsroot/firebug/firebug/project/zaurus/vu/isis/nest/zaurus In directory sc8-pr-cvs1:/tmp/cvs-serv22139/vu/isis/nest/zaurus Modified Files: ZCanvas.java ZMain.java Log Message: will now display an arbitrary message running in test mode. Index: ZCanvas.java =================================================================== RCS file: /cvsroot/firebug/firebug/project/zaurus/vu/isis/nest/zaurus/ZCanvas.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ZCanvas.java 21 Jul 2003 15:44:03 -0000 1.1 --- ZCanvas.java 21 Jul 2003 17:09:29 -0000 1.2 *************** *** 12,18 **** public static final int LEFT = 0; // Alignment constants - public static final int CENTER = 1; public static final int RIGHT = 2; protected String[] lines; // The lines of text to display --- 12,18 ---- public static final int LEFT = 0; // Alignment constants public static final int CENTER = 1; public static final int RIGHT = 2; + protected String[] lines; // The lines of text to display *************** *** 35,66 **** // This method breaks a specified label up into an array of lines. // It uses the StringTokenizer utility class. ! protected void newLabel (String label) ! { StringTokenizer t = new StringTokenizer (label, "\n"); num_lines = t.countTokens (); lines = new String[num_lines]; line_widths = new int[num_lines]; ! for (int i = 0; i < num_lines; i++) lines[i] = t.nextToken (); } // This method figures out how the font is, and how wide each // line of the label is, and how wide the widest line is. ! protected void measure () ! { FontMetrics fm = this.getFontMetrics (this.getFont ()); // If we don't have font metrics yet, just return. ! if (fm == null) return; line_height = fm.getHeight (); line_ascent = fm.getAscent (); max_width = 0; ! for (int i = 0; i < num_lines; i++) ! { line_widths[i] = fm.stringWidth (lines[i]); if (line_widths[i] > max_width) max_width = line_widths[i]; ! } } --- 35,68 ---- // This method breaks a specified label up into an array of lines. // It uses the StringTokenizer utility class. ! protected void newLabel (String label) { ! StringTokenizer t = new StringTokenizer (label, "\n"); num_lines = t.countTokens (); lines = new String[num_lines]; line_widths = new int[num_lines]; ! ! for (int i = 0; i < num_lines; i++) { lines[i] = t.nextToken (); + } } // This method figures out how the font is, and how wide each // line of the label is, and how wide the widest line is. ! protected void measure () { ! FontMetrics fm = this.getFontMetrics (this.getFont ()); // If we don't have font metrics yet, just return. ! if (fm == null) { return; + } line_height = fm.getHeight (); line_ascent = fm.getAscent (); max_width = 0; ! for (int i = 0; i < num_lines; i++) { line_widths[i] = fm.stringWidth (lines[i]); if (line_widths[i] > max_width) max_width = line_widths[i]; ! } } *************** *** 109,114 **** ! public void setForeground (Color c) ! { super.setForeground (c); repaint (); --- 111,116 ---- ! public void setForeground (Color c) { ! super.setForeground (c); repaint (); *************** *** 116,121 **** ! public void setAlignment (int a) ! { alignment = a; repaint (); --- 118,123 ---- ! public void setAlignment (int a) { ! alignment = a; repaint (); *************** *** 123,128 **** ! public void setMarginWidth (int mw) ! { margin_width = mw; repaint (); --- 125,130 ---- ! public void setMarginWidth (int mw) { ! margin_width = mw; repaint (); *************** *** 130,135 **** ! public void setMarginHeight (int mh) ! { margin_height = mh; repaint (); --- 132,137 ---- ! public void setMarginHeight (int mh) { ! margin_height = mh; repaint (); *************** *** 137,154 **** ! public int getAlignment () ! { return alignment; } ! public int getMarginWidth () ! { return margin_width; } ! public int getMarginHeight () ! { return margin_height; } --- 139,156 ---- ! public int getAlignment () { ! return alignment; } ! public int getMarginWidth () { ! return margin_width; } ! public int getMarginHeight () { ! return margin_height; } *************** *** 168,173 **** // This method is called by a layout manager when it wants to // know how big we'd like to be. ! public Dimension getPreferredSize () ! { return new Dimension (max_width + 2 * margin_width, num_lines * line_height + 2 * margin_height); --- 170,175 ---- // This method is called by a layout manager when it wants to // know how big we'd like to be. ! public Dimension getPreferredSize () { ! return new Dimension (max_width + 2 * margin_width, num_lines * line_height + 2 * margin_height); *************** *** 176,181 **** // This method is called when the layout manager wants to know // the bare minimum amount of space we need to get by. ! public Dimension getMinimumSize () ! { return new Dimension (max_width, num_lines * line_height); } --- 178,183 ---- // This method is called when the layout manager wants to know // the bare minimum amount of space we need to get by. ! public Dimension getMinimumSize () { ! return new Dimension (max_width, num_lines * line_height); } *************** *** 185,210 **** // it doesn't have to worry about the color or font--the superclass // takes care of setting those in the Graphics object we're passed. ! public void paint (Graphics g) ! { int x, y; Dimension d = this.getSize (); y = line_ascent + (d.height - num_lines * line_height) / 2; ! for (int i = 0; i < num_lines; i++, y += line_height) ! { ! switch (alignment) ! { case LEFT: x = margin_width; break; ! case CENTER: default: x = (d.width - line_widths[i]) / 2; break; ! case RIGHT: x = d.width - margin_width - line_widths[i]; break; ! } g.drawString (lines[i], x, y); ! } } } --- 187,212 ---- // it doesn't have to worry about the color or font--the superclass // takes care of setting those in the Graphics object we're passed. ! public void paint (Graphics g) { ! int x, y; Dimension d = this.getSize (); y = line_ascent + (d.height - num_lines * line_height) / 2; ! for (int i = 0; i < num_lines; i++, y += line_height) { ! ! switch (alignment) { ! case LEFT: x = margin_width; break; ! case CENTER: default: x = (d.width - line_widths[i]) / 2; break; ! case RIGHT: x = d.width - margin_width - line_widths[i]; break; ! } g.drawString (lines[i], x, y); ! } } } Index: ZMain.java =================================================================== RCS file: /cvsroot/firebug/firebug/project/zaurus/vu/isis/nest/zaurus/ZMain.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ZMain.java 21 Jul 2003 15:44:03 -0000 1.3 --- ZMain.java 21 Jul 2003 17:09:29 -0000 1.4 *************** *** 3,6 **** --- 3,8 ---- import java.awt. *; import java.lang. *; + import org.firebug.*; + import net.tinyos.message.*; public class ZMain extends Object { *************** *** 40,56 **** System.out.println(cwidth +", " + cheight); - Canvas canvas = new Canvas(); - canvas.setSize(cwidth,cheight); Color color = new Color((float).5,(float).55,(float).5); - canvas.setBackground(color); - //panel.add(canvas); - //canvas.repaint(); ! ZCanvas zcanvas = new ZCanvas("Foobar"); zcanvas.setSize(cwidth-50,cheight-50); zcanvas.setBackground(color); panel.add(zcanvas); zcanvas.repaint(); } --- 42,69 ---- System.out.println(cwidth +", " + cheight); Color color = new Color((float).5,(float).55,(float).5); ! String packetdata = "Mote ID : 13\n" ! + "Temp : 72.3\n" ! + "Baro : 29.2\n" ! + "Humidity: 99%\n"; ! ! ! ZCanvas zcanvas = new ZCanvas(packetdata); zcanvas.setSize(cwidth-50,cheight-50); zcanvas.setBackground(color); panel.add(zcanvas); zcanvas.repaint(); + + SensorMsg msg = new SensorMsg(); + msg.set_addr(13); + msg.set_cnt(1313); + msg.set_baro_pres((float)29.2); + msg.set_rel_hum((float)99.9); + msg.set_temp((float)73.13); + + packetdata = msg.toString(); + zcanvas.setLabel(packetdata); } |