Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

click handling, dragging, seeking

  • Loading branch information...
commit 0b8858a5f20fd20feb919579a1914998653c71e0 1 parent 263fb35
@else else authored
View
21 src/de/raumzeitlabor/pr0nwall/ds/Frame.java
@@ -0,0 +1,21 @@
+package de.raumzeitlabor.pr0nwall.ds;
+
+import java.util.ArrayList;
+
+
+public class Frame {
+ private ArrayList<LED> leds;
+
+ public Frame(int dots) {
+ leds = new ArrayList<LED>(dots);
+
+ for (int i = 0; i < dots; i++) {
+ leds.add(new LED());
+ }
+ }
+
+ public ArrayList<LED> getLEDs() {
+ return leds;
+ }
+
+}
View
44 src/de/raumzeitlabor/pr0nwall/ds/FrameList.java
@@ -0,0 +1,44 @@
+package de.raumzeitlabor.pr0nwall.ds;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+public class FrameList {
+ private final int dots;
+ private final LinkedList<Frame> framelist;
+
+ public FrameList(int dots) {
+ this(dots, 1);
+ }
+
+ public FrameList(int dots, int frames) {
+ this.dots = dots;
+
+ framelist = new LinkedList<Frame>();
+ for (int i = 0; i < frames; i++) {
+ framelist.add(new Frame(dots));
+ }
+ }
+
+ public int getDots() {
+ return dots;
+ }
+
+ public List<Frame> getFrames() {
+ return framelist;
+ }
+
+ public void addFrame() {
+ framelist.add(new Frame(dots));
+ }
+
+ public void addFrame(int pos) {
+ framelist.add(pos - 1, new Frame(dots));
+ }
+
+ public void deleteFrame(int i) {
+ framelist.remove(i);
+ }
+}
View
33 src/de/raumzeitlabor/pr0nwall/ds/LED.java
@@ -0,0 +1,33 @@
+package de.raumzeitlabor.pr0nwall.ds;
+
+import java.awt.Shape;
+
+
+public class LED {
+ private boolean enabled = false;
+ private Shape shape;
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public void toggleEnabled() {
+ this.enabled = !this.enabled;
+ }
+
+ public boolean hasShape() {
+ return shape != null;
+ }
+
+ public void setShape(Shape s) {
+ this.shape = s;
+ }
+
+ public Shape getShape() {
+ return shape;
+ }
+}
View
36 src/de/raumzeitlabor/pr0nwall/gui/FrameSeeker.java
@@ -1,36 +1,56 @@
package de.raumzeitlabor.pr0nwall.gui;
import java.awt.Color;
-import java.awt.Frame;
-import java.util.ArrayList;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.MouseWheelListener;
import javax.swing.BorderFactory;
import javax.swing.JSlider;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
-public class FrameSeeker extends JSlider {
+import de.raumzeitlabor.pr0nwall.ds.FrameList;
+
+public class FrameSeeker extends JSlider implements MouseWheelListener {
/**
*
*/
private static final long serialVersionUID = 3975074419073256219L;
- private ArrayList<Frame> framelist = null;
+ private LEDPanel panel;
- public FrameSeeker(ArrayList<Frame> framelist) {
+ public FrameSeeker(LEDPanel panel) {
setMajorTickSpacing(5);
setMinorTickSpacing(1);
setSnapToTicks(true);
setPaintTicks(true);
-// setPaintLabels(true);
+ setPaintLabels(true);
setMinimum(1);
- setMaximum(framelist.size());
+ setValue(1);
+ setMaximum(panel.getNumberOfFrames());
setBackground(Color.WHITE);
setBorder(new CompoundBorder(BorderFactory.createMatteBorder(
0, 0, 0, 1, Color.gray),
new EmptyBorder(5, 10, 5, 10)));
- this.framelist = framelist;
+ addMouseWheelListener(this);
+
+ this.panel = panel;
+ }
+
+ public void refresh() {
+ setValue(panel.getCurrentFrameNumber());
+ setMaximum(panel.getNumberOfFrames());
+ }
+
+ @Override
+ public void mouseWheelMoved(MouseWheelEvent e) {
+ int newVal = getValue() + e.getWheelRotation();
+
+ if (newVal >= 1 && newVal <= panel.getNumberOfFrames()) {
+ panel.seekToFrame(newVal);
+ refresh();
+ }
}
}
View
277 src/de/raumzeitlabor/pr0nwall/gui/LEDPanel.java
@@ -1,45 +1,280 @@
package de.raumzeitlabor.pr0nwall.gui;
import java.awt.Color;
-import java.awt.Frame;
-import java.awt.GridBagConstraints;
-import java.awt.GridLayout;
-import java.awt.Insets;
-import java.util.ArrayList;
+import java.awt.Cursor;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Point;
+import java.awt.RenderingHints;
+import java.awt.Shape;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.MouseWheelListener;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.Rectangle2D;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.EmptyBorder;
-public class LEDPanel extends JPanel {
+import de.raumzeitlabor.pr0nwall.ds.Frame;
+import de.raumzeitlabor.pr0nwall.ds.FrameList;
+import de.raumzeitlabor.pr0nwall.ds.LED;
+
+public class LEDPanel extends JPanel implements MouseListener, MouseMotionListener, MouseWheelListener {
/**
*
*/
private static final long serialVersionUID = -8818828083394984856L;
+
+ private PositioningHelper helper;
+
+ private int current_frame = 0;
+ private FrameList framelist;
+ private FrameSeeker seeker;
- private final int PANEL_SIZE = 32;
+ private final Color C_LED_ENABLED = Color.RED;
+ private final Color C_LED_DISABLED = new Color(255, 191, 207);
- public boolean mousePressed = false;
- private ArrayList<Frame> framelist;
+ private int dragLedPos = -1;
- public LEDPanel(ArrayList<Frame> framelist) {
+ public LEDPanel(FrameList framelist) {
+ this.helper = new PositioningHelper((int) Math.sqrt(framelist.getDots()));
+ this.framelist = framelist;
+
+ addMouseListener(this);
+ addMouseWheelListener(this);
+ addMouseMotionListener(this);
- setLayout(new GridLayout(PANEL_SIZE, PANEL_SIZE));
- setBorder(BorderFactory.createMatteBorder(
- 0, 0, 0, 1, Color.gray));
setBackground(Color.WHITE);
+ setBorder(new CompoundBorder(BorderFactory.createMatteBorder(
+ 0, 0, 0, 1, Color.gray),
+ new EmptyBorder(5, 10, 5, 10)));
+ }
+
+ public void setFrameSeeker(FrameSeeker seeker) {
+ this.seeker = seeker;
+ }
+
+ @Override
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ Graphics2D g2 = (Graphics2D) g;
- GridBagConstraints c = new GridBagConstraints();
- for (int i = 1; i <= PANEL_SIZE*PANEL_SIZE; i++) {
- add(new LED(this), new GridBagConstraints(0, 0, 1, 1, 1, 1,
- GridBagConstraints.CENTER, GridBagConstraints.BOTH,
- new Insets(0, 0, 0, 0), 0, 0));
- }
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
- this.framelist = framelist;
+ int width = getWidth();
+ int height = getHeight();
+
+ helper.update(width, height);
+ double led_size = helper.getLEDSize();
+
+ for (int i = 0; i < framelist.getDots(); i++) {
+ Point p = helper.getLEDPosition(i);
+
+ Shape shape = new Ellipse2D.Double(p.getX(), p.getY(), led_size, led_size);
+ getLED(i).setShape(shape);
+
+ if (!getLED(i).isEnabled())
+ g2.setPaint(C_LED_DISABLED);
+ else
+ g2.setPaint(C_LED_ENABLED);
+
+ g2.fill(shape);
+ g2.setPaint(Color.GRAY);
+ g2.draw(shape);
+
+// g2.drawOval((int)posX, (int)posY, (int)led_size, (int) led_size);
+ }
}
- public ArrayList<Frame> getFrames() {
+ public FrameList getFrames() {
return framelist;
}
+
+ public int getNumberOfFrames() {
+ return framelist.getFrames().size();
+ }
+
+ public Frame getCurrentFrame() {
+ return framelist.getFrames().get(current_frame);
+ }
+
+ public int getCurrentFrameNumber() {
+ return current_frame + 1;
+ }
+
+ public void prevFrame() {
+ if (current_frame > 0) {
+ current_frame--;
+ repaint();
+ }
+ }
+
+ public void nextFrame() {
+ if (current_frame < framelist.getFrames().size() - 1) {
+ current_frame++;
+ repaint();
+ }
+ }
+
+ public void seekToFrame(int i) {
+ if (i > 0 && i <= framelist.getFrames().size()) {
+ current_frame = i - 1;
+ repaint();
+ }
+ }
+
+ public LED getLED(int pos) {
+ return framelist.getFrames().get(current_frame).getLEDs().get(pos);
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ Graphics2D g2 = (Graphics2D) getGraphics();
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ int ledNo = helper.getLEDNumber(e.getPoint());
+
+ if (ledNo != -1) {
+ LED l = getLED(ledNo);
+ Shape s = l.getShape();
+ if (s.contains(e.getPoint())) {
+ l.toggleEnabled();
+ g2.setColor(l.isEnabled() ? C_LED_ENABLED : C_LED_DISABLED);
+ g2.fill(s);
+ g2.setPaint(Color.GRAY);
+ g2.draw(s);
+ }
+ }
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent arg0) {}
+
+ @Override
+ public void mouseExited(MouseEvent arg0) {}
+
+ @Override
+ public void mousePressed(MouseEvent arg0) {}
+
+ @Override
+ public void mouseReleased(MouseEvent arg0) {}
+
+ @Override
+ public void mouseWheelMoved(MouseWheelEvent e) {
+ int newVal = seeker.getValue() + e.getWheelRotation();
+
+ if (newVal >= 1 && newVal <= getNumberOfFrames()) {
+ seekToFrame(newVal);
+ seeker.refresh();
+ }
+ }
+
+ @Override
+ public void mouseDragged(MouseEvent e) {
+ int ledPos = helper.getLEDNumber(e.getPoint());
+
+// if (dragLedPos != ledPos) {
+ dragLedPos = ledPos;
+ mouseClicked(e);
+// }
+ }
+
+ @Override
+ public void mouseMoved(MouseEvent e) {
+ int ledNo = helper.getLEDNumber(e.getX(), e.getY());
+
+ if (ledNo != -1) {
+ if (getLED(ledNo).getShape().contains(e.getPoint())) {
+ setCursor(new Cursor(Cursor.HAND_CURSOR));
+ return;
+ }
+ }
+
+ setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
+ }
+
+ private class PositioningHelper {
+ private final int MIN_PADDING = 20;
+ private final int dotsPerRow;
+
+ private double availableSize;
+ private double ledSpacer;
+ private double ledSize;
+
+ private double hspacer;
+ private double vspacer;
+
+ public PositioningHelper(int dots) {
+ this.dotsPerRow = dots;
+ }
+
+ public void update(int width, int height) {
+ availableSize = Math.min(width, height) - 2 * MIN_PADDING;
+
+ ledSpacer = availableSize / (dotsPerRow * 3);
+ ledSize = (availableSize - (dotsPerRow - 1) * ledSpacer) / dotsPerRow;
+
+ vspacer = (width <= height) ? (height - availableSize - 2 * MIN_PADDING) / 2 : 0;
+ hspacer = (width >= height) ? (width - availableSize - 2 * MIN_PADDING) / 2 : 0;
+ }
+
+ public double getAvailableSize() {
+ return availableSize;
+ }
+
+ public Point getLEDPosition(int num) {
+ double posX = MIN_PADDING + hspacer;
+ double posY = MIN_PADDING + vspacer;
+
+ double baseX = posX;
+
+ if (num % dotsPerRow != 0)
+ posX += (ledSize + ledSpacer) * (num % dotsPerRow);
+ else
+ posX = baseX;
+
+ if (num / dotsPerRow > 0) {
+ posY += (ledSize + ledSpacer) * (num / dotsPerRow);
+ }
+
+ Point p = new Point();
+ p.setLocation(posX, posY);
+
+ return p;
+ }
+
+ public int getLEDNumber(int x, int y) {
+ double posX = MIN_PADDING + hspacer;
+ double posY = MIN_PADDING + vspacer;
+
+ if (x < posX || y < posY || x > (posX + availableSize)
+ || y > (posY + availableSize))
+ return -1;
+
+ double deltaX = x - posX;
+ double deltaY = y - posY;
+
+ int ledX = (int) (deltaX / (ledSize + ledSpacer));
+ int ledY = (int) (deltaY / (ledSize + ledSpacer));
+ int ledPos = ledX + ledY * dotsPerRow;
+
+ return ledPos;
+ }
+
+ public int getLEDNumber(Point p) {
+ return getLEDNumber((int) p.getX(), (int) p.getY());
+ }
+
+ public double getLEDSize() {
+ return ledSize;
+ }
+ }
}
View
13 src/de/raumzeitlabor/pr0nwall/gui/MainFrame.java
@@ -2,13 +2,13 @@
import java.awt.BorderLayout;
import java.awt.Dimension;
-import java.awt.Frame;
-import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
+import de.raumzeitlabor.pr0nwall.ds.FrameList;
+
public class MainFrame extends JFrame {
/**
@@ -32,6 +32,7 @@ public MainFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
+ setMinimumSize(new Dimension(300, 200));
setLayout(new BorderLayout());
try {
@@ -48,17 +49,17 @@ public MainFrame() {
JPanel mainpanel = new JPanel();
mainpanel.setLayout(new BorderLayout());
- ArrayList<Frame> framelist = new ArrayList<Frame>();
- framelist.add(new Frame());
+ FrameList framelist = new FrameList(32*32, 5);
ledpanel = new LEDPanel(framelist);
- frameseeker = new FrameSeeker(framelist);
+ frameseeker = new FrameSeeker(ledpanel);
+ ledpanel.setFrameSeeker(frameseeker);
mainpanel.add(ledpanel, BorderLayout.CENTER);
mainpanel.add(frameseeker, BorderLayout.SOUTH);
add(mainpanel);
- toolbar = new Toolbar();
+ toolbar = new Toolbar(ledpanel, frameseeker);
add(toolbar, BorderLayout.EAST);
// JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
View
45 src/de/raumzeitlabor/pr0nwall/gui/Toolbar.java
@@ -3,6 +3,10 @@
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
+import java.awt.GridBagLayout;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
@@ -17,6 +21,8 @@
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
+import de.raumzeitlabor.pr0nwall.ds.FrameList;
+
public class Toolbar extends JPanel {
/**
@@ -25,8 +31,16 @@
private static final long serialVersionUID = -6353475337784152259L;
private JSlider ledbrightness;
private JSlider duration;
+ private FrameList framelist;
+ private LEDPanel panel;
+ private FrameSeeker seeker;
+ private JPanel propertypanel;
- public Toolbar() {
+ public Toolbar(LEDPanel panel, final FrameSeeker seeker) {
+ this.framelist = panel.getFrames();
+ this.seeker = seeker;
+ this.panel = panel;
+
Dimension d = new Dimension(220, 0);
setPreferredSize(d);
setMinimumSize(d);
@@ -49,6 +63,19 @@ public Toolbar() {
JPanel mainpanel = new JPanel();
/*
+ * Properties
+ */
+ JPanel properties = new JPanel();
+ properties.setBorder(new TitledBorder(
+ BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY), "LED Brightness"));
+ propertypanel = new JPanel(new GridLayout(5, 2));
+ propertypanel.add(new JLabel("Number of Frames"));
+ propertypanel.add(new JLabel("1337"));
+ properties.add(propertypanel);
+
+ mainpanel.add(properties);
+
+ /*
* LED settings
*/
JPanel ledsettings = new JPanel();
@@ -92,8 +119,24 @@ public Toolbar() {
BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY), "Frames"));
JButton newframebtn = new JButton("New");
+ newframebtn.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ framelist.addFrame(seeker.getValue() + 1);
+ seeker.refresh();
+ }
+ });
+
JButton playanimbtn = new JButton("Play");
+
JButton delframebtn = new JButton("Del");
+ delframebtn.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ framelist.deleteFrame(seeker.getValue()-1);
+ seeker.refresh();
+ }
+ });
framecontrol.add(newframebtn);
framecontrol.add(playanimbtn);
Please sign in to comment.
Something went wrong with that request. Please try again.