Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

seeking

  • Loading branch information...
commit bbb563b3e7804d9a995bb94cd1490f1f16ce33fc 1 parent 0b8858a
@else else authored
View
2  src/de/raumzeitlabor/pr0nwall/ds/FrameList.java
@@ -1,7 +1,5 @@
package de.raumzeitlabor.pr0nwall.ds;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
View
16 src/de/raumzeitlabor/pr0nwall/ds/LED.java
@@ -5,7 +5,6 @@
public class LED {
private boolean enabled = false;
- private Shape shape;
public boolean isEnabled() {
return enabled;
@@ -15,19 +14,8 @@ public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
- public void toggleEnabled() {
+ public boolean toggleEnabled() {
this.enabled = !this.enabled;
- }
-
- public boolean hasShape() {
- return shape != null;
- }
-
- public void setShape(Shape s) {
- this.shape = s;
- }
-
- public Shape getShape() {
- return shape;
+ return this.enabled;
}
}
View
20 src/de/raumzeitlabor/pr0nwall/gui/FrameSeeker.java
@@ -8,10 +8,12 @@
import javax.swing.JSlider;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
import de.raumzeitlabor.pr0nwall.ds.FrameList;
-public class FrameSeeker extends JSlider implements MouseWheelListener {
+public class FrameSeeker extends JSlider implements MouseWheelListener, ChangeListener {
/**
*
@@ -21,7 +23,7 @@
private LEDPanel panel;
public FrameSeeker(LEDPanel panel) {
- setMajorTickSpacing(5);
+ setMajorTickSpacing(1);
setMinorTickSpacing(1);
setSnapToTicks(true);
setPaintTicks(true);
@@ -35,22 +37,24 @@ public FrameSeeker(LEDPanel panel) {
new EmptyBorder(5, 10, 5, 10)));
addMouseWheelListener(this);
+ addChangeListener(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();
- }
+ panel.seekToFrame(newVal);
+ }
+
+ @Override
+ public void stateChanged(ChangeEvent arg0) {
+ int newVal = getValue();
+ panel.seekToFrame(newVal);
}
}
View
98 src/de/raumzeitlabor/pr0nwall/gui/LED.java
@@ -1,98 +0,0 @@
-package de.raumzeitlabor.pr0nwall.gui;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Cursor;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-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.geom.Ellipse2D;
-
-import javax.swing.JComponent;
-
-public class LED extends JComponent implements MouseListener, MouseMotionListener {
-
- /**
- *
- */
- private static final long serialVersionUID = -5698663633870675134L;
-
- final static BasicStroke stroke = new BasicStroke(2.0f);
-
- private Shape ellipsis;
- private boolean enabled = false;
- private LEDPanel ledpanel;
-
- public LED(LEDPanel parent) {
- ledpanel = parent;
- addMouseListener(this);
- addMouseMotionListener(this);
- }
-
- public void paint(Graphics g) {
- Graphics2D g2 = (Graphics2D) g;
-
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
-
- int posX = getWidth()/4;
- int posY = getHeight()/4;
-
- int radius = (int) (getWidth()*0.5);
- ellipsis = new Ellipse2D.Double(posX, posY, radius, radius);
-
- if (!enabled) {
- g2.setPaint(new Color(255, 191, 207));
- } else {
- g2.setPaint(Color.RED);
- }
-
- g2.fill(ellipsis);
- g2.setPaint(Color.GRAY);
- g2.draw(ellipsis);
- }
-
- @Override
- public void mouseClicked(MouseEvent e) {}
-
- @Override
- public void mouseEntered(MouseEvent e) {}
-
- @Override
- public void mouseExited(MouseEvent e) {}
-
- @Override
- public void mousePressed(MouseEvent e) {
- ledpanel.mousePressed = true;
-
- if (ellipsis.contains(e.getX(), e.getY())) {
- enabled = !enabled;
- repaint();
- }
- }
-
- @Override
- public void mouseReleased(MouseEvent e) {
- ledpanel.mousePressed = false;
- }
-
- @Override
- public void mouseDragged(MouseEvent e) {}
-
- @Override
- public void mouseMoved(MouseEvent e) {
- if (ellipsis.contains(e.getX(), e.getY())) {
- setCursor(new Cursor(Cursor.HAND_CURSOR));
- } else {
- setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
- }
- }
-
- public boolean isEnabled() {
- return enabled;
- }
-}
View
186 src/de/raumzeitlabor/pr0nwall/gui/LEDPanel.java
@@ -7,13 +7,14 @@
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.Shape;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
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;
@@ -24,7 +25,7 @@
import de.raumzeitlabor.pr0nwall.ds.FrameList;
import de.raumzeitlabor.pr0nwall.ds.LED;
-public class LEDPanel extends JPanel implements MouseListener, MouseMotionListener, MouseWheelListener {
+public class LEDPanel extends JPanel implements MouseListener, MouseMotionListener, MouseWheelListener, KeyListener {
/**
*
@@ -39,17 +40,30 @@
private final Color C_LED_ENABLED = Color.RED;
private final Color C_LED_DISABLED = new Color(255, 191, 207);
+ private final int PANEL_WIDTH;
- private int dragLedPos = -1;
+ private int[] shapeState;
+ private boolean partialRedraw = false;
+
+ private int currentLedCursor = 1;
public LEDPanel(FrameList framelist) {
- this.helper = new PositioningHelper((int) Math.sqrt(framelist.getDots()));
+ this.PANEL_WIDTH = (int) Math.sqrt(framelist.getDots());
+ this.helper = new PositioningHelper(PANEL_WIDTH);
this.framelist = framelist;
+
+ this.shapeState = new int[framelist.getDots() / 32];
+ for (int i = 0; i < shapeState.length; i++) {
+ shapeState[i] = 0xFFFFFFFF;
+ }
addMouseListener(this);
addMouseWheelListener(this);
addMouseMotionListener(this);
+ setFocusable(true);
+ addKeyListener(this);
+
setBackground(Color.WHITE);
setBorder(new CompoundBorder(BorderFactory.createMatteBorder(
0, 0, 0, 1, Color.gray),
@@ -60,6 +74,40 @@ public void setFrameSeeker(FrameSeeker seeker) {
this.seeker = seeker;
}
+ private void setShapeState(int pos, boolean state) {
+ int arrayPos = (int) (pos / 32);
+ int bytePos = pos % 32;
+
+ int current = shapeState[arrayPos];
+ int toStore = 1 << (31 - bytePos);
+
+// System.out.println("current: "+Integer.toBinaryString(current));
+
+ if (state) {
+ shapeState[arrayPos] = toStore ^ current;
+// System.out.println("tostore: "+Integer.toBinaryString(toStore));
+// System.out.println(" AND "+Integer.toBinaryString(toStore ^ current));
+ } else {
+ shapeState[arrayPos] = ~toStore & current;
+// System.out.println("tostore: "+Integer.toBinaryString(~toStore));
+// System.out.println(" OR "+Integer.toBinaryString(~toStore & current));
+ }
+
+// System.out.println("result: "+Integer.toBinaryString(shapeState[arrayPos]));
+// System.out.println();
+ }
+
+ private boolean getShapeState(int pos) {
+ int arrayPos = (int) (pos / 32);
+ int bytePos = pos % 32;
+
+ int current = shapeState[arrayPos];
+
+// System.out.println("GET bit: "+Integer.toBinaryString(current >>> (31 - bytePos)));
+
+ return (current >>> (31 - bytePos)) == 1;
+ }
+
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
@@ -73,24 +121,35 @@ public void paintComponent(Graphics g) {
helper.update(width, height);
double led_size = helper.getLEDSize();
-
+
+ int j = 0;
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);
-
+// System.out.println("led is enabled: "+getLED(i).isEnabled());
+// System.out.println("shape state: "+getShapeState(i));
+// if (partialRedraw == false || getLED(i).isEnabled() != getShapeState(i)) {
+ j++;
+ Shape shape = new Ellipse2D.Double(p.getX(), p.getY(), led_size, led_size);
+
+ g2.setPaint(getLED(i).isEnabled() ? C_LED_ENABLED : C_LED_DISABLED);
+ setShapeState(i, getLED(i).isEnabled());
+
+ g2.fill(shape);
+
+ if (currentLedCursor - 1 == i) {
+ g2.setPaint(Color.BLACK);
+ } else {
+ g2.setPaint(Color.GRAY);
+ }
+
+ g2.draw(shape);
+// }
+
// g2.drawOval((int)posX, (int)posY, (int)led_size, (int) led_size);
}
+
+ partialRedraw = false;
+// System.out.println("redraw "+j+" leds");
}
public FrameList getFrames() {
@@ -113,6 +172,7 @@ public void prevFrame() {
if (current_frame > 0) {
current_frame--;
repaint();
+ partialRedraw = true;
}
}
@@ -120,6 +180,7 @@ public void nextFrame() {
if (current_frame < framelist.getFrames().size() - 1) {
current_frame++;
repaint();
+ partialRedraw = true;
}
}
@@ -127,6 +188,7 @@ public void seekToFrame(int i) {
if (i > 0 && i <= framelist.getFrames().size()) {
current_frame = i - 1;
repaint();
+ partialRedraw = true;
}
}
@@ -143,12 +205,19 @@ public void mouseClicked(MouseEvent e) {
int ledNo = helper.getLEDNumber(e.getPoint());
if (ledNo != -1) {
+
LED l = getLED(ledNo);
- Shape s = l.getShape();
+ Point p = helper.getLEDPosition(ledNo);
+
+ double led_size = helper.getLEDSize();
+ Shape s = new Ellipse2D.Double(p.getX(), p.getY(), led_size, led_size);
+
if (s.contains(e.getPoint())) {
- l.toggleEnabled();
+ setShapeState(ledNo, l.toggleEnabled());
+
g2.setColor(l.isEnabled() ? C_LED_ENABLED : C_LED_DISABLED);
g2.fill(s);
+
g2.setPaint(Color.GRAY);
g2.draw(s);
}
@@ -174,6 +243,7 @@ public void mouseWheelMoved(MouseWheelEvent e) {
if (newVal >= 1 && newVal <= getNumberOfFrames()) {
seekToFrame(newVal);
seeker.refresh();
+ seeker.setValue(newVal);
}
}
@@ -182,9 +252,9 @@ public void mouseDragged(MouseEvent e) {
int ledPos = helper.getLEDNumber(e.getPoint());
// if (dragLedPos != ledPos) {
- dragLedPos = ledPos;
+// dragLedPos = ledPos;
mouseClicked(e);
-// }
+//// }
}
@Override
@@ -192,7 +262,11 @@ public void mouseMoved(MouseEvent e) {
int ledNo = helper.getLEDNumber(e.getX(), e.getY());
if (ledNo != -1) {
- if (getLED(ledNo).getShape().contains(e.getPoint())) {
+ Point p = helper.getLEDPosition(ledNo);
+ double led_size = helper.getLEDSize();
+
+ Shape s = new Ellipse2D.Double(p.getX(), p.getY(), led_size, led_size);
+ if (s.contains(e.getPoint())) {
setCursor(new Cursor(Cursor.HAND_CURSOR));
return;
}
@@ -277,4 +351,70 @@ public double getLEDSize() {
return ledSize;
}
}
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ int oldLedCursor = currentLedCursor;
+
+ switch (e.getKeyCode()) {
+ case 37: // LEFT-ARROW
+ if (currentLedCursor % PANEL_WIDTH > 1) {
+ currentLedCursor--;
+ }
+ break;
+ case 38: // UP-ARROW
+ if (currentLedCursor > PANEL_WIDTH) {
+ currentLedCursor -= PANEL_WIDTH;
+ }
+ break;
+ case 39: // RIGHT-ARROW
+ if (currentLedCursor % PANEL_WIDTH < PANEL_WIDTH) {
+ currentLedCursor++;
+ }
+ break;
+ case 40: // DOWN-ARROW
+ if (currentLedCursor < (PANEL_WIDTH - 1) * PANEL_WIDTH) {
+ currentLedCursor += PANEL_WIDTH;
+ }
+ break;
+ case 32:
+ getLED(currentLedCursor).toggleEnabled();
+ selectLed(currentLedCursor, true);
+ break;
+ }
+
+ if (e.getKeyCode() >= 37 && e.getKeyCode() <= 40) {
+ selectLed(oldLedCursor, false);
+ selectLed(currentLedCursor, true);
+ }
+ }
+
+ private void selectLed(int ledNo, boolean b) {
+ Graphics2D g2 = (Graphics2D) getGraphics();
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ LED l = getLED(ledNo);
+ Point p = helper.getLEDPosition(ledNo);
+
+ double led_size = helper.getLEDSize();
+ Shape s = new Ellipse2D.Double(p.getX(), p.getY(), led_size, led_size);
+
+ g2.setColor(l.isEnabled() ? C_LED_ENABLED : C_LED_DISABLED);
+ g2.fill(s);
+
+ if (b) {
+ g2.setPaint(Color.BLACK);
+ } else {
+ g2.setPaint(Color.GRAY);
+ }
+
+ g2.draw(s);
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {}
+
+ @Override
+ public void keyTyped(KeyEvent e) {}
}
View
2  src/de/raumzeitlabor/pr0nwall/gui/MainFrame.java
@@ -49,7 +49,7 @@ public MainFrame() {
JPanel mainpanel = new JPanel();
mainpanel.setLayout(new BorderLayout());
- FrameList framelist = new FrameList(32*32, 5);
+ FrameList framelist = new FrameList(32*32, 1);
ledpanel = new LEDPanel(framelist);
frameseeker = new FrameSeeker(ledpanel);
View
25 src/de/raumzeitlabor/pr0nwall/gui/Toolbar.java
@@ -3,10 +3,11 @@
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.event.ComponentEvent;
+import java.awt.event.ComponentListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
@@ -29,14 +30,14 @@
*
*/
private static final long serialVersionUID = -6353475337784152259L;
- private JSlider ledbrightness;
- private JSlider duration;
- private FrameList framelist;
- private LEDPanel panel;
- private FrameSeeker seeker;
- private JPanel propertypanel;
+ private final JSlider ledbrightness;
+ private final JSlider duration;
+ private final FrameList framelist;
+ private final LEDPanel panel;
+ private final FrameSeeker seeker;
+ private final JPanel propertypanel;
- public Toolbar(LEDPanel panel, final FrameSeeker seeker) {
+ public Toolbar(final LEDPanel panel, final FrameSeeker seeker) {
this.framelist = panel.getFrames();
this.seeker = seeker;
this.panel = panel;
@@ -67,7 +68,7 @@ public Toolbar(LEDPanel panel, final FrameSeeker seeker) {
*/
JPanel properties = new JPanel();
properties.setBorder(new TitledBorder(
- BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY), "LED Brightness"));
+ BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY), "Properties"));
propertypanel = new JPanel(new GridLayout(5, 2));
propertypanel.add(new JLabel("Number of Frames"));
propertypanel.add(new JLabel("1337"));
@@ -123,7 +124,9 @@ public Toolbar(LEDPanel panel, final FrameSeeker seeker) {
@Override
public void actionPerformed(ActionEvent e) {
framelist.addFrame(seeker.getValue() + 1);
+ panel.seekToFrame(seeker.getValue() + 1);
seeker.refresh();
+ seeker.setValue(seeker.getValue() + 1);
}
});
@@ -133,7 +136,9 @@ public void actionPerformed(ActionEvent e) {
delframebtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- framelist.deleteFrame(seeker.getValue()-1);
+ if (framelist.getFrames().size() == 1) return;
+ framelist.deleteFrame(seeker.getValue() - 1);
+ panel.seekToFrame(seeker.getValue() - 2);
seeker.refresh();
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.