⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rasterpanel.java

📁 Java source code for the Ant Colony Optimization Problem.
💻 JAVA
字号:
package jwo.jpss.spatial.gui;  // Part of the spatial GUI package.

import jwo.jpss.spatial.*;     // For spatial classes.
import java.awt.*;             // For image management.
import java.awt.image.*;
			
//  **************************************************************
/** Panel that draws a GIS raster map.
  * @author Jo Wood.
  * @version 1.3, 21st October, 2001
  */
//  **************************************************************

public class RasterPanel extends SpatialPanel
{   
    // -------------------- Object variables ---------------------
 
    private Image rasterImage;       // Raster map to display.
    private RasterMap rasterMap;
      
    // ---------------------- Constructor ------------------------
    
    /** Creates a panel and draws the given raster upon it.
      * @param rastermap Raster map to draw.
      */
    public RasterPanel(RasterMap rasterMap)
    { 
        super(rasterMap);         // Call JPanel's constructor.
        setRasterMap(rasterMap);  // Create image out of raster map.
    }
        
    // ----------------------- Methods ---------------------------
    
    /** Sets a new raster map to draw. Currently assumes raster values
      * are scaled between 0 and 255.
      * @param rasterMap New raster map to draw.
      */
    public void setRasterMap(RasterMap rasterMap)
    {
        this.rasterMap = rasterMap;
        int numRows = rasterMap.getNumRows();
        int numCols = rasterMap.getNumCols();

        // Transfer raster values into pixel array.
        int pixels[] = new int[numRows * numCols];
        int pixelCount=0;
        float min = rasterMap.getMinAttribute();
        float max = rasterMap.getMaxAttribute();

        for (int row=0; row<numRows; row++)
        {
            for (int col=0; col<numCols; col++)
            {
                int greyLevel = (int)(255*(rasterMap.getAttribute(row,col)-min)/(max-min));
                Color colour = new Color(greyLevel,greyLevel,greyLevel);
                pixels[pixelCount++] = colour.getRGB();
            }
        }
       
        // Create a drawable image out of pixel array.
        rasterImage = createImage(new MemoryImageSource(numCols,numRows,pixels,0,numCols));
        repaint();
    }

    /** Draws graphics on the panel.
      * @param g Graphics context in which to draw.
      */
    public void paintComponent(Graphics g)
    {        
    	super.paintComponent(g);		// Paint background.
        
        // Scale image to fit inside panel.
        Footprint fp = getGeoToPixel(rasterMap.getBounds());
        g.drawImage(rasterImage,(int)fp.getXOrigin(),
                                (int)fp.getYOrigin(),
                                (int)fp.getMERWidth(), 
                                (int)fp.getMERHeight(),this);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -