[TeamTalk 130]: [667] TeamTalk/Agents/PenDecoder: Camera imager is now also undockable.
tk@edam.speech.cs.cmu.edu
tk at edam.speech.cs.cmu.edu
Tue Jul 24 10:29:37 EDT 2007
An HTML attachment was scrubbed...
URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20070724/e2d7d3c0/attachment.html
-------------- next part --------------
Modified: TeamTalk/Agents/PenDecoder/nbproject/project.properties
===================================================================
--- TeamTalk/Agents/PenDecoder/nbproject/project.properties 2007-07-21 06:42:04 UTC (rev 666)
+++ TeamTalk/Agents/PenDecoder/nbproject/project.properties 2007-07-24 14:29:35 UTC (rev 667)
@@ -29,8 +29,8 @@
# Space-separated list of extra javac options
javac.compilerargs=-Xlint
javac.deprecation=false
-javac.source=${default.javac.source}
-javac.target=${default.javac.target}
+javac.source=1.5
+javac.target=1.5
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}:\
Modified: TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/Imager.java
===================================================================
--- TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/Imager.java 2007-07-21 06:42:04 UTC (rev 666)
+++ TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/Imager.java 2007-07-24 14:29:35 UTC (rev 667)
@@ -11,28 +11,48 @@
import java.awt.image.BufferedImage;
/**
- *
+ * This class manages the display of the robot camera images.
* @author tkharris
*/
public class Imager extends Canvas {
+
+ static final long serialVersionUID = -2498616324568959806L;
+
+ /**
+ * The image to display.
+ */
+ protected BufferedImage image;
+
+ /**
+ * Creates a new instance of Imager
+ */
+ public Imager() {}
+
+ /**
+ * Set the image to display amd deal with image resizing.
+ * @param i The new image.
+ * @return true if the image dimensions have changed.
+ */
+ public boolean setImage(BufferedImage i) {
+ //keep native aspect ratio with a height of 200 pixels
+ final int fixedHeight = 200;
+ Dimension newDimensions =
+ new Dimension(i.getWidth()*fixedHeight/i.getHeight(),
+ fixedHeight);
+ image = i;
+ if(newDimensions != getPreferredSize()) {
+ setPreferredSize(newDimensions);
+ return true;
+ }
+ repaint();
+ return false;
+ }
- static final long serialVersionUID = -2498616324568959806L;
- BufferedImage image;
-
- /** Creates a new instance of Imager */
- public Imager() {}
-
- public void setImage(BufferedImage i) {
- int native_w = i.getWidth();
- int native_h = i.getHeight();
- //keep native aspect ratio with a height of 200 pixels
- int h = 200;
- int w = native_w*h/native_h;
- setPreferredSize(new Dimension(w, h));
- image = i;
- }
-
- public void paint(Graphics g) {
- g.drawImage(image, 0, 0, getSize().width, getSize().height, Color.BLACK, this);
- }
+ /**
+ * Paint the image.
+ */
+ public void paint(Graphics g) {
+ super.paint(g);
+ g.drawImage(image, 0, 0, getSize().width, getSize().height, Color.BLACK, this);
+ }
}
Modified: TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/PenDecoderDisplay.java
===================================================================
--- TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/PenDecoderDisplay.java 2007-07-21 06:42:04 UTC (rev 666)
+++ TeamTalk/Agents/PenDecoder/src/edu/cmu/ravenclaw/pendecoder/PenDecoderDisplay.java 2007-07-24 14:29:35 UTC (rev 667)
@@ -6,6 +6,9 @@
import javax.swing.*;
import bsh.util.JConsole;
+import java.io.File;
+import java.io.IOException;
+import javax.imageio.ImageIO;
/**
* PenDecoderDisplay is the top-level JFrame (docked mode) or collection of
@@ -100,34 +103,37 @@
oldViewSize = viewport.getSize();
}
- //clear map canvas and console from docked frame
+ //clear map canvas, console, and imager from docked frame
dockedRootPane.setContentPane(new JPanel());
lowerContainer.remove(console);
+ lowerContainer.remove(imager);
//build undocked viewpane and set paramters congruent with docked parameters
JScrollPane pane = new JScrollPane(mapCanvas);
pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
- Dimension newSize = new Dimension(dockSize.width*320/oldViewSize.width,
- dockSize.height*320/oldViewSize.width);
+ Dimension newMapViewSize = new Dimension(320, 320*oldViewSize.height/oldViewSize.width);
+ Dimension newSize =
+ new Dimension(dockSize.width*newMapViewSize.width/oldViewSize.width,
+ dockSize.height*newMapViewSize.height/oldViewSize.height);
mapCanvas.setPreferredSize(newSize);
mapCanvas.setSize(newSize);
pane.getViewport().setViewPosition(new Point(dockAnchor.x*320/oldViewSize.width,
dockAnchor.y*320/oldViewSize.width));
//resize undocked frames and attach components
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- Dimension newMapViewSize = new Dimension(320, 320*oldViewSize.height/oldViewSize.width);
- mapCanvasFrame.setBounds(0, screenSize.height-newMapViewSize.height,
- newMapViewSize.width, newMapViewSize.height);
+ mapCanvasFrame.setPreferredSize(newMapViewSize);
mapCanvasFrame.setContentPane(pane);
- mapCanvasFrame.setVisible(true);
- consoleFrame.setBounds(newMapViewSize.width, screenSize.height-100,
- screenSize.width-640, 100);
consoleFrame.setContentPane(console);
- consoleFrame.setVisible(true);
+ imagerFrame.setPreferredSize(imager.getPreferredSize());
+ imagerFrame.add(imager);
docked = false;
+ revalidate();
+
+ mapCanvasFrame.setVisible(true);
+ consoleFrame.setVisible(true);
+ imagerFrame.setVisible(true);
}
/**
@@ -136,10 +142,12 @@
public void dock() {
mapCanvasFrame.setVisible(false);
consoleFrame.setVisible(false);
+ imagerFrame.setVisible(false);
//clear components from undocked frame
mapCanvasFrame.setContentPane(new JPanel());
consoleFrame.setContentPane(new JPanel());
+ imagerFrame.remove(imager);
//build docked viewpane and restore viewpane parameters
JScrollPane pane = new JScrollPane(mapCanvas);
@@ -152,9 +160,12 @@
//reattach components
dockedRootPane.setContentPane(pane);
lowerContainer.add(console, BorderLayout.CENTER);
+ lowerContainer.add(imager, BorderLayout.EAST);
+ docked = true;
+ revalidate();
+
dockedFrame.setVisible(true);
- docked = true;
}
/**
@@ -196,8 +207,6 @@
//console and imager
lowerContainer = new JPanel(new BorderLayout());
- lowerContainer.add(console, BorderLayout.CENTER);
- lowerContainer.add(imager, BorderLayout.EAST);
dockedFrame.getContentPane().add(lowerContainer, BorderLayout.SOUTH);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
@@ -218,6 +227,9 @@
consoleFrame = new JFrame();
consoleFrame.setUndecorated(true);
consoleFrame.setAlwaysOnTop(true);
+ imagerFrame = new JFrame();
+ imagerFrame.setUndecorated(true);
+ imagerFrame.setAlwaysOnTop(true);
}
/**
@@ -228,6 +240,8 @@
dockedFrame.repaint();
} else {
mapCanvasFrame.repaint();
+ consoleFrame.repaint();
+ imagerFrame.repaint();
}
}
@@ -236,13 +250,37 @@
* @param i image to paint in imager panel
*/
public void image(BufferedImage i) {
- imager.setImage(i);
+ if(imager.setImage(i)) {
+ revalidate();
+ }
+ }
+
+ /**
+ * This function places the undocked windows along the bottom of the window.
+ * The mapCanvas frame takes the bottom left corner, the imager takes the
+ * bottom right corner, and the console take the bottom center. The frames
+ * are sized based on the preferred size of their contents.
+ */
+ public void revalidate() {
if(docked) {
dockedFrame.getRootPane().revalidate();
+ } else {
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ mapCanvasFrame.setBounds(0,
+ screenSize.height-mapCanvasFrame.getPreferredSize().height,
+ mapCanvasFrame.getPreferredSize().width,
+ mapCanvasFrame.getPreferredSize().height);
+ consoleFrame.setBounds(mapCanvasFrame.getPreferredSize().width,
+ screenSize.height-100,
+ screenSize.width-mapCanvasFrame.getPreferredSize().width-imager.getPreferredSize().width,
+ 100);
+ imagerFrame.setBounds(screenSize.width-imager.getPreferredSize().width,
+ screenSize.height-imager.getPreferredSize().height,
+ imager.getPreferredSize().width, imager.getPreferredSize().height);
+ imager.setBounds(0, 0, imager.getPreferredSize().width, imager.getPreferredSize().height);
}
- imager.repaint();
}
-
+
/**
* Update map image with new map.
* @param type full image or image diff
@@ -511,11 +549,23 @@
}
/**
- * An entry point that displays everything but doesn't communicate with Olympus
- * @param args Unused.
+ * An entry point that displays everything but doesn't communicate with Olympus.
+ * This is just for debugging graphincs stuff.
+ !
!
!
!
!
!
* @param args Unused.
*/
public static void main(String[] args) {
PenDecoderDisplay frame = new PenDecoderDisplay("Treasure Hunt GUI");
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ System.err.println("Sleep interupted");
+ }
+ try {
+ BufferedImage i = ImageIO.read(new File("highbay.png"));
+ frame.image(i);
+ } catch (IOException e) {
+ System.err.println("problem reading test image");
+ }
}
/**
@@ -606,6 +656,11 @@
protected JFrame consoleFrame;
/**
+ * The undocked imager frame
+ */
+ protected JFrame imagerFrame;
+
+ /**
* This is the root pane for the docked map canvas. It is a container for the
* JScrollPane which has the map and the GlassPane which has the floating logo.
*/
More information about the TeamTalk-developers
mailing list