1 | package main;
|
---|
2 |
|
---|
3 | import java.awt.*;
|
---|
4 | import java.awt.image.*;
|
---|
5 |
|
---|
6 | public class Cell {
|
---|
7 | int x, y, location;
|
---|
8 | WineBottle bottle;
|
---|
9 | BufferedImage img, brightImg;
|
---|
10 | static BufferedImage bg, wideBg;
|
---|
11 |
|
---|
12 | public Cell(int x, int y, int location, WineBottle bottle, BufferedImage img, BufferedImage brightImg) {
|
---|
13 | this.x = x;
|
---|
14 | this.y = y;
|
---|
15 | this.location = location;
|
---|
16 | this.bottle = bottle;
|
---|
17 | this.img = img;
|
---|
18 | this.brightImg = brightImg;
|
---|
19 | }
|
---|
20 |
|
---|
21 | int getX() {
|
---|
22 | return x;
|
---|
23 | }
|
---|
24 |
|
---|
25 | int getY() {
|
---|
26 | return y;
|
---|
27 | }
|
---|
28 |
|
---|
29 | int getLocation() {
|
---|
30 | return location;
|
---|
31 | }
|
---|
32 |
|
---|
33 | public void draw(Graphics g) {
|
---|
34 | if(bottle != null && bottle.isSelected())
|
---|
35 | drawBright(g);
|
---|
36 | else
|
---|
37 | g.drawImage(img, x, y, null);
|
---|
38 | }
|
---|
39 |
|
---|
40 | public void drawBright(Graphics g) {
|
---|
41 | g.drawImage(brightImg, x, y, null);
|
---|
42 | }
|
---|
43 |
|
---|
44 | public void drawDescription(Graphics g, int x, int y, Font font) {
|
---|
45 | if(bottle == null)
|
---|
46 | return;
|
---|
47 |
|
---|
48 | FontMetrics metrics = g.getFontMetrics(font);
|
---|
49 |
|
---|
50 | int height = 160;
|
---|
51 |
|
---|
52 | if(metrics.stringWidth(bottle.getName()) >= 120 || metrics.stringWidth("Variety: "+bottle.getVariety()) >= 120)
|
---|
53 | g.drawImage(wideBg, x, y-height, null);
|
---|
54 | else
|
---|
55 | g.drawImage(bg, x, y-height, null);
|
---|
56 |
|
---|
57 | g.setColor(new Color(174, 11, 27));
|
---|
58 |
|
---|
59 | g.setFont(font);
|
---|
60 | g.drawString(bottle.getName(), x+5, y-height+20);
|
---|
61 |
|
---|
62 | g.drawString("Winery: "+bottle.getVineyard(), x+5, y-height+35);
|
---|
63 |
|
---|
64 | if(bottle.getVintage() == 0)
|
---|
65 | g.drawString("Vintage Unknown", x+5, y-height+50);
|
---|
66 | else
|
---|
67 | g.drawString(Integer.toString(bottle.getVintage()), x+5, y-height+50);
|
---|
68 |
|
---|
69 | g.drawString("Country: "+bottle.getCountry(), x+5, y-height+65);
|
---|
70 | g.drawString("Region: "+bottle.getRegion(), x+5, y-height+80);
|
---|
71 | g.drawString("Variety: "+bottle.getVariety(), x+5, y-height+95);
|
---|
72 | }
|
---|
73 | }
|
---|