aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2011-09-16 09:15:27 +0100
committerChristopher Baines <cbaines8@gmail.com>2011-09-16 09:15:27 +0100
commitebc965a9f1dc2a1a6aaf66a0c048695eda3a7a25 (patch)
treec6d6106b40c26b08373c7da78aeef0ca3e1575a1
parentd1da2c2b09f2e4754dc89fdb89bbb1d7cb73e0f0 (diff)
downloadpunchingbag-ebc965a9f1dc2a1a6aaf66a0c048695eda3a7a25.tar
punchingbag-ebc965a9f1dc2a1a6aaf66a0c048695eda3a7a25.tar.gz
Image improvements.
-rw-r--r--PunchingBag/src/PicHelper/ImagePanel.java9
-rw-r--r--PunchingBag/src/uk/ac/open/punchingbag/PunchingBagGUI.java29
2 files changed, 18 insertions, 20 deletions
diff --git a/PunchingBag/src/PicHelper/ImagePanel.java b/PunchingBag/src/PicHelper/ImagePanel.java
index 099fcb8..0551c27 100644
--- a/PunchingBag/src/PicHelper/ImagePanel.java
+++ b/PunchingBag/src/PicHelper/ImagePanel.java
@@ -67,6 +67,11 @@ public class ImagePanel extends JPanel {
g.drawImage(scaledImage, 0, 0, this);
}
}
+
+ public Dimension getPreferredSize() {
+ setScaledImage();
+ return new Dimension(scaledImage.getWidth(null), scaledImage.getHeight(null));
+ }
private void setScaledImage() {
if (image != null) {
@@ -74,8 +79,8 @@ public class ImagePanel extends JPanel {
// use floats so division below won't round
float iw = imageWidth;
float ih = imageHeight;
- float pw = this.getWidth(); // panel width
- float ph = this.getHeight(); // panel height
+ float pw = super.getWidth(); // panel width
+ float ph = super.getHeight(); // panel height
if (pw < iw || ph < ih) {
diff --git a/PunchingBag/src/uk/ac/open/punchingbag/PunchingBagGUI.java b/PunchingBag/src/uk/ac/open/punchingbag/PunchingBagGUI.java
index 5cbc3f5..d71a6c6 100644
--- a/PunchingBag/src/uk/ac/open/punchingbag/PunchingBagGUI.java
+++ b/PunchingBag/src/uk/ac/open/punchingbag/PunchingBagGUI.java
@@ -67,7 +67,7 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener,
JFrame frame;
JPanel bagDebugingPanel = new JPanel();
- JPanel programOptionsPanel = new JPanel();
+ JPanel programOptionsPanel = new JPanel(new GridBagLayout());
// Contact
public enum Direction {
@@ -140,12 +140,13 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener,
bagDebugingPanel.add(bottomTopSplitPane, BorderLayout.CENTER);
- programOptionsPanel.add(new DisplayPanel());
+ programOptionsPanel.add(new JButton("Debug"));
- //frame.add(bagDebugingPanel);
- frame.add(programOptionsPanel);
+ frame.add(bagDebugingPanel);
+ frame.add(new DisplayPanel(), BorderLayout.CENTER);
+ frame.add(programOptionsPanel, BorderLayout.SOUTH);
- //setMode(currentMode);
+ setMode(currentMode);
GraphicsDevice device;
device = GraphicsEnvironment.getLocalGraphicsEnvironment()
@@ -197,33 +198,25 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener,
}
}
- class DisplayPanel extends JPanel implements Runnable {
+ class DisplayPanel extends ImagePanel implements Runnable {
ArrayList<File> files = new ArrayList<File>();
- ImagePanel imagePanel = new ImagePanel();
int image = 0;
DisplayPanel() {
- this.add(imagePanel);
+ super();
new Thread(this).start();
}
- /*public void paintComponent(Graphics g) {
- if (images.size() != 0) {
- if (debugImages)
- System.out.println("Displaying Image");
- g.drawImage(images.get(image), 0, 0, frame.getSize().width, frame.getSize().height, null);
- }
- }*/
-
public void run() {
loadImages();
while (true) {
try {
- imagePanel.loadImage(files.get(image));
+ this.loadImage(files.get(image));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
+ this.repaint();
if (image == (files.size() - 1)) {
image = 0;
} else {
@@ -232,7 +225,7 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener,
if (debugImages)
System.out.println("Moving to the next image ");
try {
- Thread.sleep(10000);
+ Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();