933d00ad
rlentieu
add JPaint
|
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
import java.awt.Label;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPanel;
import javax.swing.JButton;
/**
* The ColorBox class is a color pallette. It stores the color the user clicked
* with the right and left mouse button. It also contains a set of preset colors
* which can be changed with the advanced feature.
**/
public class ColorBox extends JPanel
{
public static Label foreGround, backGround;
public static int selectedSwatchX, selectedSwatchY;
public static ColorLabel[][] colorPal;
private JButton clrPnlBtn;
private ColorPanel clrPnl;
/** Creates a default ColorBox. **/
public ColorBox()
{
// sets the layout to null and sets a size to the color box
setLayout(null);
setSize(350,120);
// instantiates the Mouse Left and Mouse Right color labels
setForeBack();
// instantiates the Color Panel
clrPnl = new ColorPanel();
// instantiates a button that calls for advanced settings, sets the size
// and the x,y coordinates and adds it to screen
clrPnlBtn = new JButton("Advanced");
clrPnlBtn.setBounds(100,65,100,20);
add(clrPnlBtn);
clrPnlBtn.addActionListener(new AdvancedListener());
// instantiates the color label and it finds its corresponding color
// depending on its x and y coordinates
colorPal = new ColorLabel[2][14];
for(int i=0;i<colorPal.length;i++)
for(int j=0;j<colorPal[i].length;j++)
{
Color c = setDefaultColors(i,j);
colorPal[i][j] = new ColorLabel(c,j*20+40,i*20+20,i,j);
add(colorPal[i][j]);
}
setVisible(true);
}
/** Sets the ColorLabels with its corresponding default colors **/
public Color setDefaultColors(int x, int y)
{
if(x == 0 && y == 0) return Color.BLACK;
if(x == 0 && y == 1) return new Color(128,128,128);
if(x == 0 && y == 2) return new Color(128,0,0);
if(x == 0 && y == 3) return new Color(128,128,0);
if(x == 0 && y == 4) return new Color(0,128,0);
if(x == 0 && y == 5) return new Color(0,128,128);
if(x == 0 && y == 6) return new Color(0,0,128);
if(x == 0 && y == 7) return new Color(128,0,128);
if(x == 0 && y == 8) return new Color(128,128,64);
if(x == 0 && y == 9) return new Color(0,64,64);
if(x == 0 && y == 10) return new Color(0,128,255);
if(x == 0 && y == 11) return new Color(0,64,128);
if(x == 0 && y == 12) return new Color(128,0,255);
if(x == 0 && y == 13) return new Color(128,64,0);
if(x == 1 && y == 0) return Color.WHITE;
if(x == 1 && y == 1) return new Color(192,192,192);
if(x == 1 && y == 2) return Color.RED;
if(x == 1 && y == 3) return Color.YELLOW;
if(x == 1 && y == 4) return Color.GREEN;
if(x == 1 && y == 5) return Color.CYAN;
if(x == 1 && y == 6) return Color.BLUE;
if(x == 1 && y == 7) return Color.MAGENTA;
if(x == 1 && y == 8) return new Color(255,255,128);
if(x == 1 && y == 9) return new Color(0,255,128);
if(x == 1 && y == 10) return new Color(128,255,255);
if(x == 1 && y == 11) return new Color(128,128,255);
if(x == 1 && y == 12) return new Color(255,0,128);
if(x == 1 && y == 13) return new Color(255,128,64);
return Color.WHITE;
}
/** Instantiates the mouse right and left click colors **/
public void setForeBack()
{
// creates the foreground and background label and then sets the size
// and its x,y coordinates and adds it to the Color Box
foreGround = new Label();
backGround = new Label();
foreGround.setBounds(10,10,15,15);
foreGround.setBackground(new Color(0,0,0));
backGround.setBounds(17,17,15,15);
backGround.setBackground(new Color(255,255,255));
add(foreGround);
add(backGround);
}
class AdvancedListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
clrPnl.setVisible(true);
}
}
}
|