示例#1
0
 @Override
 public void paintComponent(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   Object hint = new Object();
   if (isAntialiased()) {
     hint = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
     g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   }
   translation = getTranslation();
   Color oldColor = g2.getColor();
   g2.setColor(new Color(230, 230, 250));
   g2.fill(translation.createTransformedShape(getShape()));
   g2.setColor(Color.BLACK);
   g2.draw(translation.createTransformedShape(getShape()));
   if (isShowingSensors) {
     for (Iterator<Sensor> sIter = sensors.iterator(); sIter.hasNext(); ) {
       Sensor s = (Sensor) sIter.next();
       s.paintComponent(g2);
     }
   }
   if (isShowingStatusFrame) {
     paintStatusFrame(g2);
   }
   g2.setColor(oldColor);
   if (isAntialiased()) {
     g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, hint);
   }
 }
示例#2
0
 @Override
 public void paintStatusFrame(Graphics g, int baseX, int baseY) {
   Graphics2D g2 = (Graphics2D) g;
   Color oldColor = g2.getColor();
   Composite oldComposite = g2.getComposite();
   g2.setComposite(opacityBack);
   g2.setColor(Color.BLACK);
   g2.fillRect(baseX, baseY, 100, 100);
   g2.setComposite(opacityFront);
   g2.setColor(Color.WHITE);
   g2.drawRect(baseX, baseY, 100, 100);
   if (isStatusFramePinedToPosition) {
     g2.drawLine((int) this.x, (int) this.y, baseX + 100, baseY + 100);
   }
   baseX += 5;
   baseY += 15;
   g2.drawString(String.format(getActiveName() + "  #%d", myNumber), baseX, baseY);
   baseY += STATUS_FRAME_LINE_HEIGHT;
   g2.drawString(String.format("x: %4.0f", x), baseX, baseY);
   baseY += STATUS_FRAME_LINE_HEIGHT;
   g2.drawString(String.format("y: %4.0f", y), baseX, baseY);
   baseY += STATUS_FRAME_LINE_HEIGHT;
   String s = "";
   for (int j = 0; j < sensoryData[0].length; j++) {
     s += String.format("%1.1f ", sensoryData[0][j]);
   }
   g2.drawString(s, baseX, baseY);
   baseY += STATUS_FRAME_LINE_HEIGHT;
   s = "";
   for (int j = 0; j < sensoryData[1].length; j++) {
     s += String.format("%1.1f ", sensoryData[1][j]);
   }
   g2.drawString(s, baseX, baseY);
   g2.setComposite(oldComposite);
   g2.setColor(oldColor);
 }