1 package main;
2
3 import interfaces.*;
4 import simworldobjects.*;
5
6 import javax.swing.*;
7 import java.awt.image.*;
8 import java.awt.*;
9 import java.lang.*;
10 import java.util.*;
11 import java.awt.geom.*;
12
13
18 public class GridDisplay extends JPanel
19 {
20
21 private int width;
22
23 private int height;
24
25 private Graphics2D g2;
26
27 private int gridSize=25;
28
29 private BufferedImage gridBuffer;
30
31 private Graphics2D bufferG2D;
32
33 private RescaleOp op;
34
35 private BasicSimWorld simWorld;
36
37 private Color gridColor;
38
39 private Color worldColor;
40
41 private boolean wantGrid;
42
43 private int dotSize;
44
45
53 public GridDisplay(int size, int width, int height, Color gridColor, Color worldColor, boolean wantGrid)
54 {
55 this.gridSize = size;
56 this.width = width;
57 this.height = height;
58 this.simWorld = simWorld;
59 this.gridColor = gridColor;
60 this.worldColor = worldColor;
61 this.wantGrid = wantGrid;
62
63
64 gridBuffer = new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR_PRE);
65 bufferG2D = gridBuffer.createGraphics();
66 op=null;
67
68 this.drawImage();
70 }
71
74 public void updateGridDotSize(int x){
75 this.dotSize = x;
76 this.drawImage();
77 }
78
81 public void updateGridSize(int s){
82 this.gridSize = s;
83 this.drawImage();
84 }
85
86
89 public void updateWorldColor(Color c){
90 this.worldColor=c;
91 this.drawImage();
92 }
93
94
97 public void updateGridColor(Color c){
98 this.gridColor = c;
99 this.drawImage();
100 }
101
104 public boolean getWantGrid(){
105 return this.wantGrid;
106 }
107
110 public void setWantGrid(boolean s){
111 this.wantGrid = s;
112 this.drawImage();
113 }
114
115
118 private void drawImage(){
119 bufferG2D.setColor(this.worldColor);
121 bufferG2D.fillRect(0,0,width,height);
122
123 if(wantGrid){
124 bufferG2D.setColor(this.gridColor);
126 for(int a=0;a*gridSize<=width;a++){
127 for(int b=0; b*gridSize<=height;b++){
128 bufferG2D.fillOval((int)(a*gridSize-this.dotSize/2),(int)(b*gridSize-this.dotSize/2), this.dotSize,this.dotSize);
129 }
130 }
131 }
132 }
133
134
137 public void paintComponent(Graphics g)
138 {
139 g2 = (Graphics2D)g;
141 g2.drawImage(gridBuffer,op,0,0);
142 }
143 }
144
145