Revision 308
GUI battery meter added
branches/i2c/code/projects/colonet/ColonetGUI/Colonet.java | ||
---|---|---|
33 | 33 |
JLabel lblTokenPasses; |
34 | 34 |
JLabel lblHastToken; |
35 | 35 |
JPanel panelStats; |
36 |
JPanel panelBattery; |
|
36 | 37 |
|
37 | 38 |
// South |
38 | 39 |
JPanel panelSouth; |
... | ... | |
148 | 149 |
|
149 | 150 |
// Status Elements |
150 | 151 |
lblTokenPasses = new JLabel(); |
151 |
lblBattery = new JLabel("???");
|
|
152 |
lblBattery = new JLabel(new BatteryIcon(75, 100, 100));
|
|
152 | 153 |
panelStats = new JPanel(); |
153 | 154 |
panelStats.setLayout(new GridLayout(4,2)); |
154 | 155 |
panelStats.add(new JLabel("Token Passes / sec ")); |
... | ... | |
235 | 236 |
tabPaneControl.addTab("Connection", panelServerInterface); |
236 | 237 |
tabPaneControl.addTab("Robots", panelRobotControl); |
237 | 238 |
tabPaneControl.addTab("Tasks", panelTaskManager); |
239 |
tabPaneControl.addTab("Stats", panelStats); |
|
238 | 240 |
panelControl.add(tabPaneControl); |
239 | 241 |
|
240 | 242 |
// Set up elements in the south |
... | ... | |
775 | 777 |
|
776 | 778 |
} |
777 | 779 |
|
780 |
class BatteryIcon implements Icon{ |
|
781 |
private int width; |
|
782 |
private int height; |
|
783 |
private int level; |
|
784 |
|
|
785 |
public BatteryIcon(){ |
|
786 |
width = 100; |
|
787 |
height =100; |
|
788 |
level = 100; |
|
789 |
} |
|
790 |
|
|
791 |
public BatteryIcon(int startLevel){ |
|
792 |
width = 50; |
|
793 |
height = 50; |
|
794 |
level = startLevel; |
|
795 |
} |
|
796 |
|
|
797 |
public BatteryIcon(int startLevel, int w, int h){ |
|
798 |
level = startLevel; |
|
799 |
width = w; |
|
800 |
height = h; |
|
801 |
} |
|
802 |
|
|
803 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
804 |
Graphics2D g2d = (Graphics2D) g.create(); |
|
805 |
//background |
|
806 |
g2d.setColor(Color.WHITE); |
|
807 |
g2d.fillRect(x +1 ,y + 1,width-2,height-2); |
|
808 |
//outline |
|
809 |
g2d.setColor(Color.BLACK); |
|
810 |
g2d.drawRect((int)(x + width*.3) ,y + 2,(int)(width*.4),height -4); |
|
811 |
//battery life rectangle |
|
812 |
g2d.setColor(Color.GREEN); |
|
813 |
int greenX = (int)(x + 1 + width*.3); |
|
814 |
int greenY = (int)((y+3) + Math.abs(level-100.0)*(height-6)/(100)); |
|
815 |
int greenWidth = (int)(width*.4 - 2)+1; |
|
816 |
int greenHeight = 1+(int)(level-0.0)*(height-6)/(100); |
|
817 |
g2d.fillRect(greenX, greenY, greenWidth, greenHeight); |
|
818 |
//text |
|
819 |
g2d.setColor(Color.BLACK); |
|
820 |
g2d.drawString(level + "%", greenX + greenWidth/2 - 10, greenY + greenHeight/2 + 5); |
|
821 |
|
|
822 |
g2d.dispose(); |
|
823 |
} |
|
824 |
|
|
825 |
public void setLevel(int newLevel){ |
|
826 |
level = newLevel; |
|
827 |
} |
|
828 |
|
|
829 |
public int getIconWidth() { |
|
830 |
return width; |
|
831 |
} |
|
832 |
|
|
833 |
public int getIconHeight() { |
|
834 |
return height; |
|
835 |
} |
|
836 |
} |
|
837 |
|
|
838 |
|
|
778 | 839 |
} |
Also available in: Unified diff