Skip to content

Commit 1a70394

Browse files
author
David Capper
committed
init
1 parent ad7b98d commit 1a70394

13 files changed

+1492
-0
lines changed

src/Designer/ColourPanel.java

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
package Designer;
2+
3+
import javax.swing.*;
4+
import java.awt.*;
5+
import java.awt.event.MouseEvent;
6+
import java.awt.event.MouseListener;
7+
8+
/**
9+
* Created with IntelliJ IDEA.
10+
* User: thip
11+
* Date: 30/04/2013
12+
* Time: 15:23
13+
*/
14+
public class ColourPanel extends JPanel implements MouseListener
15+
{
16+
17+
private char selectedColour;
18+
private char backGroundColour;
19+
private int cellSize;
20+
private int rowCapacity;
21+
private char[] colours;
22+
23+
private Editor editor;
24+
25+
public ColourPanel ( Editor editor )
26+
{
27+
28+
this.editor = editor;
29+
30+
selectedColour = 'n';
31+
backGroundColour = 'w';
32+
33+
cellSize = 20;
34+
rowCapacity = 4;
35+
36+
colours = new char[]
37+
{
38+
'b', //Blue
39+
'r', //red
40+
'g', //green
41+
'l', //Light Grey
42+
'd', //Dark Grey
43+
'w', //white
44+
'n' //Black
45+
};
46+
47+
setPreferredSize ( new Dimension ( rowCapacity * cellSize + 8 , 0) );
48+
this.addMouseListener ( this );
49+
}
50+
51+
public static Color getColor ( char colour )
52+
{
53+
Color color;
54+
switch ( colour )
55+
{
56+
57+
case 'b':
58+
return Color.blue;
59+
case 'r':
60+
return Color.red;
61+
case 'g':
62+
return Color.green;
63+
case 'l':
64+
return Color.lightGray;
65+
case 'd':
66+
return Color.darkGray;
67+
case 'w':
68+
return Color.white;
69+
case 'n':
70+
return Color.black;
71+
72+
default:
73+
return Color.magenta; //do this if color not recognised
74+
}
75+
76+
}
77+
78+
public char getSelectedColour ()
79+
{
80+
return selectedColour;
81+
}
82+
83+
public char getBackGroundColour ()
84+
{
85+
return backGroundColour;
86+
}
87+
88+
@Override
89+
public void paintComponent ( Graphics g )
90+
{
91+
super.paintComponent ( g );
92+
93+
int row = 0;
94+
95+
for ( int i = 0; i < colours.length; i++ )
96+
{
97+
char colour = colours[i];
98+
99+
int place = i % rowCapacity;
100+
row = (int) Math.floor ( i / rowCapacity );
101+
102+
g.setColor ( getColor ( colour ) );
103+
g.fillRect ( 4+ place * cellSize, 4+ row * cellSize, cellSize, cellSize );
104+
105+
}
106+
107+
g.setColor ( getColor ( backGroundColour ) );
108+
g.fillRect ( 4, 4+ ( row + 1 ) * cellSize + 10, cellSize * rowCapacity, cellSize * rowCapacity );
109+
110+
g.setColor ( getColor ( selectedColour ) );
111+
g.fillRect ( 4, 4+( row + 1 ) * cellSize + 10, cellSize * ( rowCapacity - 1 ), cellSize * ( rowCapacity - 1 ) );
112+
113+
}
114+
115+
@Override
116+
public void mouseClicked ( MouseEvent e )
117+
{
118+
int x = (int) Math.ceil ( (e.getX () -4) / cellSize );
119+
int y = (int) Math.ceil ( (e.getY () -4) / cellSize );
120+
121+
int index = ( y * rowCapacity ) + x;
122+
123+
124+
if ( index < colours.length )
125+
{
126+
char tempColour = colours[index];
127+
128+
if ( e.getButton () == MouseEvent.BUTTON1 ) selectedColour = tempColour;
129+
if ( e.getButton () == MouseEvent.BUTTON3 )
130+
{
131+
backGroundColour = tempColour;
132+
editor.setBackground ();
133+
}
134+
}
135+
136+
137+
repaint ();
138+
}
139+
140+
141+
@Override
142+
public void mousePressed ( MouseEvent e )
143+
{
144+
}
145+
146+
@Override
147+
public void mouseReleased ( MouseEvent e )
148+
{
149+
}
150+
151+
@Override
152+
public void mouseEntered ( MouseEvent e )
153+
{
154+
}
155+
156+
@Override
157+
public void mouseExited ( MouseEvent e )
158+
{
159+
}
160+
}

src/Designer/Designer.java

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package Designer;
2+
3+
import common.Animation;
4+
import common.AnimationFrame;
5+
import common.FrameViewer;
6+
7+
import javax.swing.*;
8+
import java.awt.*;
9+
import java.awt.event.ActionEvent;
10+
import java.awt.event.ActionListener;
11+
12+
class Designer extends JFrame implements ActionListener
13+
{
14+
15+
private JMenuItem exitItem;
16+
17+
Thread run;
18+
19+
public Designer ()
20+
{
21+
setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
22+
setTitle ( "Blockmation - Designer" );
23+
24+
JMenuBar menuBar = new JMenuBar ();
25+
JMenu fileMenu = new JMenu ( "File" );
26+
exitItem = new JMenuItem("Exit");
27+
28+
menuBar.add ( fileMenu );
29+
30+
31+
FrameViewer frameViewer = new FrameViewer ();
32+
frameViewer.showGrid ();
33+
Editor editor = new Editor ();
34+
FrameManager frameManager = new FrameManager ();
35+
FileManager fileManager = new FileManager ( fileMenu );
36+
37+
fileMenu.add ( exitItem );
38+
39+
40+
editor.registerFrameViewer ( frameViewer );
41+
editor.registerFrameManager ( frameManager );
42+
frameManager.registerFrameViewer ( frameViewer );
43+
frameManager.registerEditor ( editor );
44+
fileManager.registerFrameManager ( frameManager );
45+
46+
this.setJMenuBar ( menuBar );
47+
this.add ( frameManager, BorderLayout.SOUTH );
48+
49+
this.add ( frameViewer, BorderLayout.CENTER );
50+
51+
52+
this.add ( editor, BorderLayout.WEST );
53+
54+
55+
setSize ( 800, 600 );
56+
setVisible ( true );
57+
58+
59+
Animation temp = new Animation (20);
60+
temp.addFrame ( new AnimationFrame ( 20, 'w' ) );
61+
62+
63+
frameManager.setAnimation ( temp );
64+
65+
exitItem.addActionListener ( this );
66+
67+
68+
}
69+
70+
@Override
71+
public void actionPerformed ( ActionEvent e )
72+
{
73+
if ( e.getSource () == exitItem)
74+
{
75+
System.exit ( 0 );
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)