1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| package colorCross;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
public class Pix extends JPanel {
private static final long serialVersionUID = 1L;
private final PlayableGridModel model;
private final Point coord;
private final Color color;
public Pix(Color border, int borderWidth,
Color helpBorder, int helpBorderWidth,
int x, int y,
int width, int height,
int helpRhythm, PixSizes size,
PlayableGridModel m, Color c) {
super(null);
model = m;
color = c;
coord = new Point(x, y);
setPreferredSize(new Dimension(size.getPixSize(), size.getPixSize()));
setLayout(new BorderLayout());
JPanel p = new JPanel(new BorderLayout()); {
int top = (y != 0 && y % helpRhythm == 0) ? helpBorderWidth : 0,
left = (x != 0 && x % helpRhythm == 0) ? helpBorderWidth : 0,
bottom = 0,
right = 0;
if (top != 0 || left != 0) {
p.setBorder(BorderFactory.createMatteBorder(top, left, bottom, right, helpBorder));
}
JPanel q = new JPanel(new BorderLayout()); {
int top0 = (y != 0 && y % helpRhythm == 0) ? 0 : borderWidth,
left0 = (x != 0 && x % helpRhythm == 0) ? 0 : borderWidth,
bottom0 = (y == height - 1) ? borderWidth : 0,
right0 = (x == width - 1) ? borderWidth : 0;
q.setBorder(BorderFactory.createMatteBorder(top0, left0, bottom0, right0, border));
q.setPreferredSize(new Dimension(size.getPixSize(), size.getPixSize()));
q.add(new JPanel());
}
p.add(q);
}
add(p);
System.out.println("create " + this.toString());
}
public JPanel getLastChild() {
return (JPanel) ((JPanel) ((JPanel) getComponent(0)).getComponent(0)).getComponent(0);
}
public void paintComponent(Graphics g) {
System.out.println("paintComponent");
model.getPixState(coord.x, coord.y).drawPix(getLastChild(), color);
}
} |
Partager