[6270] in java-interest
a real poser (revisited)
daemon@ATHENA.MIT.EDU (Todd E. Gee)
Wed Mar 27 02:04:38 1996
Date: Wed, 20 Mar 1996 15:37:28 -0500
Reply-To: Java Interest <JAVA-INTEREST@JAVASOFT.COM>
From: "Todd E. Gee" <tgee@EECS.UMICH.EDU>
To: Multiple recipients of list JAVA-INTEREST
<JAVA-INTEREST@JAVASOFT.COM>
Hello All,
Sorry for the long winded message, but I'm desperate. I have a little
app/applet that is supposed to impliment the following interface:
-------------------------------------------------------------
| - | Window Title |
------------------------------------------------+---------+-|
| File | Edit | | Help |
------------------------------------------------+---------+-|
| |^| |^|
| | | | |
| ImagePanel with an image panel and | | t a e| |
| two associated scrollbars. | | h s a| |
| | | u s s| |
| The whole mess occupies the |#| m o t| |
| "center" position |#| b c | |
| |#| n i | |
| |#| a a |#|
| |#| i t |#|
| |#| l e |#|
| |#| s d |#|
| | | |#|
| | | w s |#|
| | | i c | |
| | | t r | |
| | | h o | |
| | | l | |
| | | l | |
| | | b | |
| |v| a | |
|-----------------------------------------------| r | |
|< ######## >| |v|
|-----------------------------------------------+---------+-|
| Control Panel -- south |
| |
------------------------------------------------------------+
I have it setup so whether it runs as an applet or an application, it
will open up an external frame to run it.
There are three panels in the frame (using BorderLayout()) -- an
ImagePanel class in the center, a ToolPalette class in the south, and
a ThumbnailPallette in the East. This focuses on the ImagePanel which
is composed of three items (using BorderLayout()) an image panel, and
two scrollbars.
My problem is this: I need to be able to change the size of the
embedded image panel. Well, the image panel needs to be able to
resize itself. The problem is, that if the ImagePanel class resizes
it's embedded image panel, the frame doesn't resize to accomidate the
new, larger ImagePanel. So, all you see is the upper-left-hand corner
of the ImagePanel -- the scrollbars disappear...
An abbreviated code sample is at the end of this message.
How do I get around this? (I.e. how do I get the frame to resize?)
Do I have to say
getParent().getParent().etc.resize(a complicated sum of panel sizes); ?
Or, do I have to tell the frame to re-pack()?
What I *want* is a no-nonsense way that the ImagePanel can get the frame
it's in to resize w/o having to know of that frame's existance -- makes
the code more portable.. Know what I mean?
Anyway, if *anyone* out there has any insights into this, let me know.
I pre-thank you a million million times.
Todd
tgee@umich.edu
----- Begin Include -----
/**********************************************************************
* MedImage
* MedImage.java --
*
* Author(s):
* T. Gee
*
* Recent Changes:
*
*
* Copyright (c) 1995-1996 The University of Michigan.
* All rights reserved.
**********************************************************************/
import java.awt.*;
import java.applet.*;
import java.net.*;
import java.util.*;
// This class just provides the same functionality if it's running
// as an applet or an application
public class MedImage extends Applet {
private boolean application = false; // Run as application or applet
ParseCmdLine parse; // Command line if application
// A text item for the center of the applet
Label txt;
private void isApplication(ParseCmdLine parse) {
application = true;
this.parse = parse;
}
public String getParameter(String pram) {
if (!application) {
return super.getParameter(pram);
}
// For each possible parameter, explain how to get it...
if (pram.equals("img")) {
return parse.getArgByPos(0);
}
return null;
}
public void init() {
// Set up the Annotation thread
// new Recorder(2, 0);
if (!application) {
txt = new Label("Starting MedImage", Label.CENTER);
setLayout(new BorderLayout());
add("Center", txt);
repaint();
}
// Create the application
new MedImageMain();
}
public static void main(String args[]) {
// Get filename from cmd line prams.
ParseCmdLine parse = new ParseCmdLine(args);
// Create instance of self
MedImage medImage = new MedImage();
// Setup new instance
medImage.isApplication(parse);
medImage.init();
medImage.start();
}
}
// This class is the whole frame -- includes other classes and a menu
class MedImageMain extends Frame {
// All of the components that have to be recorded.
ImagePanel ip;
ToolPalette tp;
ThumbnailPallette tnp;
// Items for the menu
MenuBar mb;
public MedImageMain() {
// Set up the Annotation thread
// new Recorder(2, 0);
super("MedImage");
// Add a menu! Whee!!!
mb = new MenuBar();
setMenuBar(mb);
// Create a menu
Mfile = new Menu("File");
mb.add(Mfile);
// <snip>
// Put stuff in frame
setLayout(new BorderLayout());
ip = new ImagePanel();
tp = new ToolPalette(ip);
tnp = new ThumbnailPallette(ip);
add("Center", ip);
add("South", tp);
add("East", tnp);
pack();
show();
repaint();
}
public boolean action(Event e, Object arg) {
if (e.target instanceof MenuItem) {
// Handle all the menu stuff
}
return false;
}
}
class ImagePanel extends NoFlickerPanel {
private static final int MINWIDTH = 1000;
private static final int MINHEIGHT = 500;
int scrollThickness;
Scrollbar vScroll = new Scrollbar(Scrollbar.VERTICAL);
Scrollbar hScroll = new Scrollbar(Scrollbar.HORIZONTAL);
NoFlickerPanel viewPanel = new NoFlickerPanel();
Image currImage = null;
public ImagePanel() {
setLayout(new BorderLayout());
Panel holder = new Panel();
add("Center", viewPanel);
add("South", gScroll);
add("East", vScroll);
}
public boolean handleEvent(Event e) {
if (e.target == hScroll) {
return true;
} else if (e.target == hScroll) {
return true;
} else if (e.target == viewPanel) {
return true;
}
return false;
}
public void paint(Graphics g) {
Dimension d;
d = viewPanel.size();
if ((d.height < MINHEIGHT) || (d.width < MINWIDTH)) {
viewPanel.resize(Math.max(MINWIDTH, d.width),
Math.max(MINHEIGHT, d.height));
// How do you tell the frame to resize here w/o
// referencing parent
}
}
}
class ToolPalette extends NoFlickerPanel {
ImagePanel ip;
Panel zoomPanel = new Panel();
Choice zoom = new Choice();
Panel contrast = new Panel();
Panel hideShowPanel = new Panel();
Label hideShow;
Panel recorder = new Panel();
public ToolPalette(ImagePanel ip) {
this.ip = ip;
setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
// Add Zoom popup
for (int x = 50 ; x <= 200 ; x += 10) {
zoom.addItem(Integer.toString(x) + "%");
}
// Add other tools now.
}
public boolean action(Event e, Object arg) {
return true;
}
public void paint(Graphics g) {
}
}
class ThumbnailPallette extends NoFlickerPanel {
ImagePanel ip;
Scrollbar vScroll = new Scrollbar(Scrollbar.VERTICAL, 0, 101, 0, 100);
NoFlickerPanel thumbPanel = new NoFlickerPanel();
Vector images = new Vector();
GridBagConstraints gbc = new GridBagConstraints();
public ThumbnailPallette(ImagePanel ip) {
this.ip = ip;
thumbPanel.setLayout(new GridBagLayout());
setLayout(new BorderLayout());
add("East", vScroll);
add("Center", thumbPanel);
}
public boolean action(Event e, Object arg) {
return true;
}
public void paint(Graphics g) {
}
}
------ End Include ------
-----
This message has been forwarded via the JAVA-INTEREST
mailing list. In order to unsubscribe from this list, send a message to
listserv@javasoft.com with the command 'signoff JAVA-INTEREST' in
the message body (not in the subject line).
-----
This message has been forwarded via the JAVA-INTEREST
mailing list. In order to unsubscribe from this list, send a message to
listserv@javasoft.com with the command 'signoff JAVA-INTEREST' in
the message body (not in the subject line).