First Commit
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
|
||||
public class BottomBar extends JPanel {
|
||||
|
||||
public BottomBar(FestivalPanel fp)
|
||||
{
|
||||
super();
|
||||
setPreferredSize(new Dimension(0, 50));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
|
||||
public class DrawObject {
|
||||
Point2D position;
|
||||
double rotation;
|
||||
double scale;
|
||||
Image image;
|
||||
protected boolean selected;
|
||||
|
||||
public DrawObject(String filename, Point2D position)
|
||||
{
|
||||
image = new ImageIcon(filename).getImage();
|
||||
scale = 1;
|
||||
rotation = 0;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g)
|
||||
{
|
||||
AffineTransform tx = getTransform();
|
||||
g.drawImage(image, tx, null);
|
||||
}
|
||||
|
||||
protected AffineTransform getTransform() {
|
||||
AffineTransform tx = new AffineTransform();
|
||||
tx.scale(scale, scale);
|
||||
tx.translate(position.getX(), position.getY());
|
||||
tx.rotate(Math.toRadians(rotation), image.getWidth(null) / 2, image.getHeight(null) / 2);
|
||||
return tx;
|
||||
}
|
||||
|
||||
public boolean contains(Point point) {
|
||||
Shape shape = new Rectangle2D.Double(0,0,image.getWidth(null), image.getHeight(null));
|
||||
return getTransform().createTransformedShape(shape).contains(point);
|
||||
}
|
||||
|
||||
public void setSelected(boolean b)
|
||||
{
|
||||
selected = b;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.TexturePaint;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseMotionAdapter;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RectangularShape;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
|
||||
public class FestivalPanel extends JPanel {
|
||||
|
||||
BufferedImage background;
|
||||
ArrayList<DrawObject> objects = new ArrayList<>();
|
||||
DrawObject dragObject = null;
|
||||
DrawObject selectedObject = null;
|
||||
Point2D dragOffset;
|
||||
|
||||
FestivalPanel()
|
||||
{
|
||||
|
||||
try {
|
||||
background = ImageIO.read(new File("images/grass.jpg"));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
addMouseListener(new MouseAdapter()
|
||||
{
|
||||
public void mousePressed(MouseEvent e) {
|
||||
for(DrawObject o : objects){
|
||||
o.setSelected(false);
|
||||
if(o.contains(e.getPoint()))
|
||||
{
|
||||
dragObject = o;
|
||||
selectedObject = o;
|
||||
selectedObject.setSelected(true);
|
||||
dragOffset = new Point2D.Double(e.getX() - o.position.getX(), e.getY() - o.position.getY());
|
||||
}
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
dragObject = null;
|
||||
dragOffset = null;
|
||||
}
|
||||
});
|
||||
|
||||
addMouseMotionListener(new MouseMotionAdapter() {
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
if(dragObject != null)
|
||||
{
|
||||
if(SwingUtilities.isLeftMouseButton(e))
|
||||
dragObject.position = new Point2D.Double(e.getX() - dragOffset.getX(), e.getY() - dragOffset.getY());
|
||||
else
|
||||
dragObject.rotation = e.getX();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void paintComponent(Graphics g)
|
||||
{
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2 = (Graphics2D)g;
|
||||
|
||||
TexturePaint p = new TexturePaint(background, new Rectangle2D.Double(0, 0, 100, 100));
|
||||
g2.setPaint(p);
|
||||
g2.fill(new Rectangle2D.Double(0,0,getWidth(), getHeight()));
|
||||
|
||||
for(DrawObject o : objects)
|
||||
o.draw(g2);
|
||||
|
||||
}
|
||||
|
||||
public void add(DrawObject o)
|
||||
{
|
||||
objects.add(o);
|
||||
repaint();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Window();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
|
||||
public class MenuBar extends JMenuBar {
|
||||
|
||||
public MenuBar(Window w)
|
||||
{
|
||||
super();
|
||||
|
||||
JMenu file = new JMenu("File");
|
||||
|
||||
JMenuItem exit = new JMenuItem("Exit");
|
||||
exit.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
file.add(exit);
|
||||
|
||||
add(file);
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
|
||||
public class Podium extends DrawObject {
|
||||
|
||||
Image selection = null;
|
||||
|
||||
public Podium(int num, Point2D position) {
|
||||
super("images/stage" + num + ".png", position);
|
||||
try {
|
||||
selection = ImageIO.read(new File("images/selection.png"));
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g)
|
||||
{
|
||||
super.draw(g);
|
||||
if(selected)
|
||||
{
|
||||
//Rectangle2D rect = new Rectangle2D.Double(0,0,super.image.getWidth(null), super.image.getHeight(null));
|
||||
//Shape sh = super.getTransform().createTransformedShape(rect);
|
||||
//g.setPaint(new Color(0,0,0));
|
||||
//g.draw(sh);
|
||||
g.drawImage(selection, super.getTransform(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
|
||||
public class SideBar extends JPanel {
|
||||
|
||||
public SideBar(FestivalPanel fp)
|
||||
{
|
||||
super();
|
||||
setPreferredSize(new Dimension(200, 0));
|
||||
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
|
||||
public class TopBar extends JPanel {
|
||||
|
||||
public TopBar(FestivalPanel fp)
|
||||
{
|
||||
super(new GridLayout(1,4));
|
||||
setPreferredSize(new Dimension(0, 150));
|
||||
|
||||
JButton addStage0 = new JButton(new ImageIcon("images/stage0.png"));
|
||||
addStage0.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
fp.add(new Podium(0, new Point2D.Double(0,0)));
|
||||
}
|
||||
});
|
||||
add(addStage0);
|
||||
|
||||
JButton addStage1 = new JButton(new ImageIcon("images/stage1.png"));
|
||||
addStage1.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
fp.add(new Podium(1, new Point2D.Double(0,0)));
|
||||
}
|
||||
});
|
||||
add(addStage1);
|
||||
|
||||
JButton addStage2 = new JButton(new ImageIcon("images/stage2.png"));
|
||||
addStage2.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
fp.add(new Podium(2, new Point2D.Double(0,0)));
|
||||
}
|
||||
});
|
||||
add(addStage2);
|
||||
|
||||
JButton addStage3 = new JButton(new ImageIcon("images/stage3.png"));
|
||||
addStage3.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
fp.add(new Podium(3, new Point2D.Double(0,0)));
|
||||
}
|
||||
});
|
||||
add(addStage3);
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
import java.awt.BorderLayout;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
|
||||
public class Window extends JFrame {
|
||||
private static final long serialVersionUID = -1324363758675184283L;
|
||||
|
||||
Window()
|
||||
{
|
||||
super("Festival Plannner");
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setSize(500,600);
|
||||
setExtendedState( getExtendedState()|JFrame.MAXIMIZED_BOTH );
|
||||
|
||||
//CONTENT PANELS
|
||||
JPanel contentPanel = new JPanel(new BorderLayout());
|
||||
FestivalPanel fp = new FestivalPanel();
|
||||
TopBar tb = new TopBar(fp);
|
||||
SideBar sb = new SideBar(fp);
|
||||
BottomBar bb = new BottomBar(fp);
|
||||
contentPanel.add(fp, BorderLayout.CENTER);
|
||||
contentPanel.add(tb, BorderLayout.NORTH);
|
||||
contentPanel.add(sb, BorderLayout.EAST);
|
||||
contentPanel.add(bb, BorderLayout.SOUTH);
|
||||
|
||||
setContentPane(contentPanel);
|
||||
//END CONTENT PANELS
|
||||
|
||||
|
||||
//MENUBAR
|
||||
setJMenuBar(new MenuBar(this));
|
||||
//END MENUBAR
|
||||
|
||||
setFocusable(true);
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 494 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
Reference in New Issue
Block a user