Thread View: borland.public.jbuilder.java.swing
3 messages
3 total messages
Started by Ramon F Herrera
Thu, 23 Dec 2004 02:26
How to retrieve an object deep inside another object?
Author: Ramon F Herrera
Date: Thu, 23 Dec 2004 02:26
Date: Thu, 23 Dec 2004 02:26
144 lines
4627 bytes
4627 bytes
This is a problem of some listeners being applied to the
wrong object.
I am trying to write an application which places a
JAI image on top of a JPanel and then performs some
rubberbanding on the image.
I used the standard JBuilder wizard "New Application" and
obviously I have added my own code as you can see below.
This is one of the critical pieces of code:
ScrollingImagePanel sip = new ScrollingImagePanel(img, 950, 645);
frame.getContentPane().add(sip);
MainFrame frame = new MainFrame();
Later on, at the end of jbInit() I have these 2 lines:
contentPane.addMouseListener(this);
contentPane.addMouseMotionListener(this);
Those 2 lines allow me to perform the rubberbanding on the
JPanel (without the ScrollingImagePanel on top of it).
So what I need is something like this (I think):
sip.addMouseListener(this);
sip.addMouseMotionListener(this);
However, the variable 'sip' is out of reach at that point.
The question is: given this statement that inserts an object:
frame.getContentPane().add(sip);
How can I retrieve that 'sip' from the object.
I guess am looking for something like this:
sip = frame.getContentPane().retrieveScrollingImagePanel;
Thanks to anyone that can figure this one out...
-Ramon F Herrera
------------------------------------------------------------------
package widgetmaker;
import javax.swing.*;
import javax.media.jai.*;
import javax.media.jai.widget.*;
/**
* <p>Title: WidgetMaker</p>
* <p>Description: Making Widgets by Click & Drag</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: Herrera Creations</p>
* @author Ramon F Herrera
* @version 1.0
*/
public class WidgetMaker {
boolean packFrame = false;
//Construct the application
public WidgetMaker(String fileName) {
RenderedOp img = JAI.create("fileload", fileName);
ScrollingImagePanel sip = new ScrollingImagePanel(img, 950, 645);
MainFrame frame = new MainFrame();
// I wish I could do this: new MainFrame(sip);
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
// Set display name and layout.
frame.setTitle(getClass().getName() + ": " + fileName);
// Display the image.
frame.setLocation(40, 0);
frame.getContentPane().add(sip);
frame.pack();
frame.show();
}
//Main method
public static void main(String[] args) {
String fileName = args[0];
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
e.printStackTrace();
}
new WidgetMaker(args[0]);
}
}
-------------------------------------------------
package widgetmaker;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.media.jai.widget.ScrollingImagePanel;
/**
* <p>Title: WidgetMaker</p>
* <p>Description: Making Widget by Click & Drag</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: Herrera Creations</p>
* @author Ramon F Herrera
* @version 1.0
*/
public class MainFrame
extends JFrame implements MouseListener, MouseMotionListener {
int x, y;
final Stroke[] strokes = new Stroke[10];
int mouseX = 0, mouseY = 0;
int index = 0;
boolean shouldErase;
public ScrollingImagePanel sp;
JPanel contentPane;
[...]
contentPane.addMouseListener(this);
contentPane.addMouseMotionListener(this);
Re: How to retrieve an object deep inside another object?
Author: Ramon F Herrera
Date: Thu, 23 Dec 2004 02:37
Date: Thu, 23 Dec 2004 02:37
11 lines
1314 bytes
1314 bytes
While rereading my own positng I realized that this statement: ScrollingImagePanel sip = frame.getContentPane().retrieveScrollingImagePanel; Would be trying to retrieve an objet which is not even there yet. Still, the question remains. How can I retrieve that 'sip'?? -Ramon
Re: How to retrieve an object deep inside another object?
Author: Paul Furbacher [TeamB]
Date: Thu, 23 Dec 2004 04:47
Date: Thu, 23 Dec 2004 04:47
64 lines
3027 bytes
3027 bytes
Ramon F Herrera wrote:
>
> This is a problem of some listeners being applied to the
> wrong object.
>
> I am trying to write an application which places a
> JAI image on top of a JPanel and then performs some
> rubberbanding on the image.
>
> I used the standard JBuilder wizard "New Application" and
> obviously I have added my own code as you can see below.
>
> This is one of the critical pieces of code:
>
> ScrollingImagePanel sip = new ScrollingImagePanel(img, 950, 645);
> frame.getContentPane().add(sip);
> MainFrame frame = new MainFrame();
>
> Later on, at the end of jbInit() I have these 2 lines:
>
> contentPane.addMouseListener(this);
> contentPane.addMouseMotionListener(this);
>
> Those 2 lines allow me to perform the rubberbanding on the
> JPanel (without the ScrollingImagePanel on top of it).
> So what I need is something like this (I think):
Rubber-banding might also be done by using a glass pane,
at least that's an approach I'd look into. Have you done
the requisite Google on the topic?
Otherwise, you have two choices.
1. MainFrame can have a private ivar which is
set via
setSIP(SIP sip) {
this.sip = sip;
sip.addMouseListener(this);
sip.addMouseMotionListener(this);
}
2. You can subclass the content pane, override the
add() method. Then set that custom content pane
into your MainFrame via its "setContentPane()".
Not too long ago, I think I read a JDJ article
which did just this, but for what reason, I cannot
remember.
--
Paul Furbacher (TeamB)
Save time, search the archives:
http://www.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads