Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package com.generalrobotix.ui.view.vsensor;
00011
00012
00013 import java.awt.Canvas;
00014 import java.awt.FlowLayout;
00015 import java.awt.Graphics;
00016 import java.awt.Image;
00017 import java.awt.image.ColorModel;
00018 import java.awt.image.MemoryImageSource;
00019
00020
00021 import javax.swing.JFrame;
00022
00023
00024 import com.generalrobotix.ui.view.Grx3DView;
00025
00031 @SuppressWarnings("serial")
00032 public final class ColorBufferBrowser extends JFrame {
00033
00034 private CanvasDraw canvas_;
00035
00036
00037 private boolean updated_ = false;
00038
00045 public ColorBufferBrowser( int width, int height, String title ) {
00046 super(title);
00047
00048 canvas_ = new CanvasDraw (
00049 Grx3DView.graphicsConfiguration,
00050 width, height
00051 );
00052 canvas_.setSize(width, height);
00053 canvas_.setBackground(java.awt.Color.white);
00054
00055 getContentPane().setLayout(new FlowLayout());
00056 getContentPane().add(canvas_);
00057 pack();
00058 setResizable(false);
00059 }
00060
00066 public void setColorBuffer(int[] colorBuffer) {
00067 canvas_.setColorBuffer(colorBuffer);
00068 updated_ = true;
00069 canvas_.repaint();
00070 }
00071
00078 @SuppressWarnings("serial")
00079 final class CanvasDraw extends Canvas {
00080
00081 private int width_;
00082
00083
00084 private MemoryImageSource mis_;
00085
00086
00087 private ColorModel cm_ = ColorModel.getRGBdefault();
00088
00089
00090 private int[] colorBuffer_;
00091
00092
00093 private Image img_;
00094
00101 public CanvasDraw(java.awt.GraphicsConfiguration gconfig, int width, int height) {
00102 super(gconfig);
00103
00104
00105 width_ = width;
00106
00107
00108 mis_ = new MemoryImageSource (
00109 width,
00110 height,
00111 null,
00112 0,
00113 width
00114 );
00115 }
00116
00121 public void setColorBuffer(int[] colorBuffer) {
00122 colorBuffer_ = colorBuffer;
00123 mis_.newPixels(colorBuffer, cm_, 0, width_);
00124 }
00125
00130 public void update(Graphics g) {
00131 if (updated_)
00132 paint(g);
00133 else
00134 return;
00135 }
00136
00141 public void paint(Graphics g) {
00142 if (!updated_)
00143 return;
00144 updated_ = false;
00145
00146 if (colorBuffer_ == null)
00147 return;
00148
00149
00150 img_ = createImage(mis_);
00151 g.drawImage(img_, 0, 0, this);
00152 }
00153 }
00154 }