Package de.mpi.rgblab.gui.menu

Source Code of de.mpi.rgblab.gui.menu.CanvasSV

package de.mpi.rgblab.gui.menu;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.MemoryImageSource;
import java.util.Vector;

public class CanvasSV extends Canvas {
  static final int WIDTH = 256;
  static final int HEIGHT = 30;

  private int[] colormap = new int[WIDTH * HEIGHT];
  private Image col_img = null;
 
  private Vector<Color> clr;// = new Vector<Color>();

  // int mouseY = 0;
  // int prevY = 0;

  public void setNewColors(Vector<Color> clr) {
    this.clr = clr;
    super.setBackground(Color.white);
    super.resize(WIDTH, HEIGHT + 50);
    int len = clr.size();
    for (int x = 0; x < WIDTH; x++) {
      int i = (int) (x * len / (WIDTH));
      for (int y = 1; y <= HEIGHT; y++) {
        colormap[x + (HEIGHT - y) * WIDTH] = clr.get(i).getRGB();
      }
    }
    col_img = createImage(new MemoryImageSource(WIDTH, HEIGHT, colormap, 0,
        WIDTH));
    this.repaint();
    // mouseY = HEIGHT/2;
  }

  public Vector<Color> getColors() {
    return clr;
  }
 
  CanvasSV() {
    clr = new Vector<Color>();
    clr.add(Color.black);
    clr.add(Color.blue);
    clr.add(Color.CYAN);
    clr.add(Color.GREEN);
    clr.add(Color.MAGENTA);
    clr.add(Color.ORANGE);
    clr.add(Color.RED);
    clr.add(Color.yellow);
   
    super.setBackground(Color.white);
    super.resize(WIDTH, HEIGHT + 50);
    int len = clr.size();
    for (int x = 0; x < WIDTH; x++) {
      int i = (int) (x * len / (WIDTH));
      for (int y = 1; y <= HEIGHT; y++) {
        colormap[x + (HEIGHT - y) * WIDTH] = clr.get(i).getRGB();
      }
    }
    col_img = createImage(new MemoryImageSource(WIDTH, HEIGHT, colormap, 0,
        WIDTH));
    // mouseY = HEIGHT/2;
  }

  public void paint(Graphics g) {
    // int[] p_x = {0, 5, 0};
    // int[] p_y = {mouseY - 5, mouseY, mouseY + 5};
    // g.setColor(Color.black);
    // g.fillPolygon(p_x, p_y, 3);
    // p_x[0] = size().width - p_x[0];
    // p_x[1] = size().width - p_x[1];
    // p_x[2] = size().width - p_x[2];
    // g.fillPolygon(p_x, p_y, 3);
    g.drawImage(col_img, 5, 0, this);
  }

}
TOP

Related Classes of de.mpi.rgblab.gui.menu.CanvasSV

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.