📄 vectorpanel.java
字号:
package jwo.jpss.spatial.gui; // Part of the spatial GUI package.
import jwo.jpss.spatial.*; // For spatial classes.
import java.awt.*; // For graphics context.
import java.awt.geom.*; // For 2D geometry display.
import java.util.*; // For dynamic collections.
// **************************************************************
/** Panel that draws a GIS vector map.
* @author Jo Wood.
* @version 1.3, 21st October, 2001
*/
// **************************************************************
public class VectorPanel extends SpatialPanel
{
// ---------------- Object and Class variables ---------------
private VectorMap vectorMap; // Vector map to draw.
// Drawing styles.
private static final int LINE_WIDTH = 1;
private static final BasicStroke STROKE = new BasicStroke(LINE_WIDTH);
private static final Color BACKGROUND_COLOUR = new Color(250,250,240);
private static final Color BORDER_COLOUR = new Color(0,0,0);
private static final Color FILL_COLOUR = new Color(240,240,180,100);
// ---------------------- Constructor ------------------------
/** Creates a panel and draws the given vector map upon it.
* @param vectorMap Vector map to draw.
*/
public VectorPanel(VectorMap vectorMap)
{
super(vectorMap);
setBackground(new Color(255,255,255,0)); // Transparent.
this.vectorMap = vectorMap;
}
// ----------------------- Methods ---------------------------
/** Draws graphics on the panel.
* @param g Graphics context in which to draw.
*/
public void paintComponent(Graphics g)
{
super.paintComponent(g); // Paint background.
Graphics2D g2 = (Graphics2D) g; // Typecast graphics as graphics2D
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// Draw each of the drawable GISVectors
Iterator i = vectorMap.getGISVectors().iterator();
while (i.hasNext())
{
GISVector gisVect = (GISVector)i.next();
GeneralPath path = gisVect.getCoords();
path.transform(getGeoToPixel());
if (gisVect.getType() == SpatialModel.AREA)
{
g2.setPaint(FILL_COLOUR);
g2.fill(path);
}
g2.setPaint(BORDER_COLOUR);
g2.setStroke(STROKE);
g2.draw(path);
// Restore vector object back to georeferenced coords.
path.transform(getPixelToGeo());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -