ColorBufferBrowser.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 package com.generalrobotix.ui.view.vsensor;
11 
12 // Java2 SDK
13 import java.awt.Canvas;
14 import java.awt.FlowLayout;
15 import java.awt.Graphics;
16 import java.awt.Image;
17 import java.awt.image.ColorModel;
18 import java.awt.image.MemoryImageSource;
19 
20 // Swing
21 import javax.swing.JFrame;
22 
23 // Sun
25 
31 @SuppressWarnings("serial")
32 public final class ColorBufferBrowser extends JFrame {
33  // canvas for drawing image
34  private CanvasDraw canvas_;
35 
36  // working space
37  private boolean updated_ = false;
38 
45  public ColorBufferBrowser( int width, int height, String title ) {
46  super(title);
47 
48  canvas_ = new CanvasDraw (
50  width, height
51  );
52  canvas_.setSize(width, height);
53  canvas_.setBackground(java.awt.Color.white);
54 
55  getContentPane().setLayout(new FlowLayout());
56  getContentPane().add(canvas_);
57  pack();
58  setResizable(false);
59  }
60 
66  public void setColorBuffer(int[] colorBuffer) {
67  canvas_.setColorBuffer(colorBuffer);
68  updated_ = true;
69  canvas_.repaint();
70  }
71 
78  @SuppressWarnings("serial")
79  final class CanvasDraw extends Canvas {
80  // raster size
81  private int width_;
82 
83  // image source
84  private MemoryImageSource mis_;
85 
86  // color model
87  private ColorModel cm_ = ColorModel.getRGBdefault();
88 
89  // color buffer
90  private int[] colorBuffer_;
91 
92  // image
93  private Image img_;
94 
101  public CanvasDraw(java.awt.GraphicsConfiguration gconfig, int width, int height) {
102  super(gconfig);
103 
104  // raster size
105  width_ = width;
106 
107  // create image source
108  mis_ = new MemoryImageSource (
109  width,
110  height,
111  null, // color buffer
112  0,
113  width
114  );
115  }
116 
121  public void setColorBuffer(int[] colorBuffer) {
122  colorBuffer_ = colorBuffer;
123  mis_.newPixels(colorBuffer, cm_, 0, width_);
124  }
125 
130  public void update(Graphics g) {
131  if (updated_)
132  paint(g);
133  else
134  return;
135  }
136 
141  public void paint(Graphics g) {
142  if (!updated_)
143  return;
144  updated_ = false;
145 
146  if (colorBuffer_ == null)
147  return;
148 
149  // image
150  img_ = createImage(mis_);
151  g.drawImage(img_, 0, 0, this);
152  }
153  }
154 }
#define null
our own NULL pointer
Definition: IceTypes.h:57
ColorBufferBrowser(int width, int height, String title)
static final GraphicsConfiguration graphicsConfiguration
Definition: Grx3DView.java:98
png_infop png_uint_32 * width
Definition: png.h:2309
png_infop png_uint_32 png_uint_32 * height
Definition: png.h:2309


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:20