[Date Prev][Date Next][Index][Thread]
[SGT Mail Archive]
[SGT Main Page]
Re: problems with SGT
Fabienne,
I've put together a quick modification of JRealTimeDemo that uses
JDesktopPane and JInternalFrame. I hope this is what you need.
Don
At 04:57 PM 4/27/2001 +0200, f.lagarrue@netcourrier.com wrote:
>*************************************************
>Message from the sgt mail list.
>*************************************************
>
>HI,
>
>I've downloaded SGT V2.0 in order to use it. There is no problem in
>viewing the JRealTimeDemo in a JFrame, but now, if I try to open the same
>demo in a JInternalFrame (and I need that !), that's doesn't work at all,
>and I have the following error message :
>
>java.lang.NullPointerException
> at gov.noaa.pmel.sgt.PaneProxy.draw(PaneProxy.java:115)
> at gov.noaa.pmel.sgt.PaneProxy.setBatch(PaneProxy.java:740)
> at gov.noaa.pmel.sgt.JPane.setBatch(JPane.java:578)
> at gov.noaa.pmel.sgt.demo.JRealTimeDemo.<init>(JRealTimeDemo.java:52)
> at gov.noaa.pmel.sgt.demo.JRealTimeDemo.main(JRealTimeDemo.java:56)
>
>Looking in paneProxy, I've seen that the draw() method couldn't work
>because of the instruction :
>Graphics g = pane_.getGraphics which gives null with a JInternalFrame,
>whereas she gives an object of type sun.awt.windows.WGraphics with a JFrame.
>
>Can you help me, or explain me where my error comes from, or how to
>resolve it ?
>
>
>Sincerly yours,
>
>Fabienne Lagarrue
>
>----- La messagerie itinérante sans abonnement NetCourrier -----
>Web : www.netcourrier.com - Minitel : 3615 NETCOURRIER
>Téléphone : 08 36 69 00 21
>
>
>*************************************************
>To remove yourself from this mailing list,
>send mail to <Majordomo@epic.noaa.gov> with
>"unsubscribe sgt" in the message body.
==================================================
Donald W. Denbo dwd@pmel.noaa.gov
Ph: (206) 526-4487 Fax: (206) 526-6744
Collaborative tools: http://www.epic.noaa.gov/collab/
Netcdf Browser: http://www.epic.noaa.gov/java/ncBrowse
Scientific Java Graphics: http://www.epic.noaa.gov/java/sgt
EPIC Oceangraphic Data Management: http://www.pmel.noaa.gov/epic
==================================================
/*
* $Id: JRealTimeDemo.java,v 1.7 2001/02/06 00:14:35 dwd Exp $
*
* This software is provided by NOAA for full, free and open release. It is
* understood by the recipient/user that NOAA assumes no liability for any
* errors contained in the code. Although this software is released without
* conditions or restrictions in its use, it is expected that appropriate
* credit be given to its author and to the National Oceanic and Atmospheric
* Administration should the software be included by the recipient as an
* element in other product development.
*/
package gov.noaa.pmel.sgt.demo;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import gov.noaa.pmel.sgt.*;
import gov.noaa.pmel.util.*;
/**
* Example demonstrating the use of <code>PropertyChangeEvents</code>
* in the datamodel. <code>JRealTimeDemo</code> constructs the plot
* from basic <code>sgt</code> objects.
*
* @author Donald Denbo
* @version $Revision: 1.7 $, $Date: 2001/02/06 00:14:35 $
* @since 2.0
*/
public class JDesktopDemo extends JApplet implements PropertyChangeListener {
PseudoRealTimeData rtData_;
JPane pane_;
Layer layer_;
TimeAxis xbot_;
PlainAxis yleft_;
LinearTransform xt_, yt_;
boolean isStandalone = false;
BorderLayout borderLayout1 = new BorderLayout();
JPanel buttonPanel = new JPanel();
JButton startButton = new JButton();
JButton stopButton = new JButton();
JButton resetButton = new JButton();
/**Construct the applet*/
public JDesktopDemo() {
}
/**Initialize the applet*/
public void init() {
/*
* Create the data source
*/
rtData_ = new PseudoRealTimeData("rtDataSource", "Sea Level");
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
/*
* add listener for data source. JRealTimeDemo is listening
* for rangeModified events
*/
rtData_.addPropertyChangeListener(this);
}
/**Component initialization*/
private void jbInit() throws Exception {
this.setSize(new Dimension(800, 440));
this.getContentPane().setLayout(borderLayout1);
startButton.setText("start");
startButton.addActionListener(new JRealTimeDemo_startButton_actionAdapter(this));
stopButton.setText("stop");
stopButton.addActionListener(new JRealTimeDemo_stopButton_actionAdapter(this));
resetButton.setText("reset");
resetButton.addActionListener(new JRealTimeDemo_resetButton_actionAdapter(this));
buttonPanel.setBorder(BorderFactory.createEtchedBorder());
this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
buttonPanel.add(startButton, null);
buttonPanel.add(stopButton, null);
buttonPanel.add(resetButton, null);
//
// construct JPane
//
pane_ = new JPane("Real Time Data Demo", new Dimension(800, 400));
pane_.setBatch(true);
pane_.setLayout(new StackedLayout());
pane_.setBackground(Color.white);
/*
* xsize, ysize are the width and height in physical units
* of the Layer graphics region.
*
* xstart, xend are the start and end points for the X axis
* ystart, yend are the start and end points for the Y axis
*/
double xsize = 6.0;
double xstart = 0.6;
double xend = 5.5;
double ysize = 3.0;
double ystart = 0.6;
double yend = 2.75;
/*
* Create the layer and add it to the Pane.
*/
CartesianGraph graph;
/*
* Get x and y ranges from data source.
*/
SoTRange.GeoDate xrange = (SoTRange.GeoDate)rtData_.getXRange();
SoTRange.Double yrange = (SoTRange.Double)rtData_.getYRange();
xt_ = new LinearTransform(xstart, xend, xrange.start, xrange.end);
yt_ = new LinearTransform(ystart, yend, yrange.start, yrange.end);
layer_ = new Layer("Layer 1", new Dimension2D(xsize, ysize));
pane_.add(layer_);
SGLabel title = new SGLabel("title",
"Real Time Demo",
new Point2D.Double((xstart+xend)/2.0,
ysize-0.05));
title.setAlign(SGLabel.TOP, SGLabel.CENTER);
title.setFont(new Font("Serif", Font.PLAIN, 14));
title.setHeightP(0.25);
title.setColor(Color.blue.darker());
layer_.addChild(title);
/*
* Create a CartesianGraph and set transforms.
*/
graph = new CartesianGraph("Time Graph");
layer_.setGraph(graph);
graph.setXTransform(xt_);
graph.setYTransform(yt_);
/*
* Create the bottom axis, set its range in user units
* and its origin. Add the axis to the graph.
*/
SoTPoint origin = new SoTPoint(xrange.start, yrange.start);
xbot_ = new TimeAxis("Botton Axis", TimeAxis.AUTO);
xbot_.setRangeU(xrange);
xbot_.setLocationU(origin);
Font xbfont = new Font("Helvetica", Font.PLAIN, 14);
xbot_.setLabelFont(xbfont);
graph.addXAxis(xbot_);
/*
* Create the left axis, set its range in user units
* and its origin. Add the axis to the graph.
*/
String yLabel = "Latitude";
yleft_ = new PlainAxis("Left Axis");
yleft_.setRangeU(yrange);
yleft_.setLocationU(origin);
yleft_.setLabelFont(xbfont);
SGLabel ytitle = new SGLabel("yaxis title", yLabel,
new Point2D.Double(0.0, 0.0));
Font ytfont = new Font("Helvetica", Font.PLAIN, 14);
ytitle.setFont(ytfont);
ytitle.setHeightP(0.2);
yleft_.setTitle(ytitle);
graph.addYAxis(yleft_);
LineAttribute attr = new LineAttribute();
graph.setData(rtData_, attr);
this.getContentPane().add(pane_, BorderLayout.CENTER);
if(!isStandalone) pane_.setBatch(false);
}
/**Start the applet*/
public void start() {
}
/**Stop the applet*/
public void stop() {
rtData_.stopData();
}
/**Destroy the applet*/
public void destroy() {
rtData_.stopData();
}
/**Get Applet information*/
public String getAppletInfo() {
return "Applet Information";
}
/**Main method*/
public static void main(String[] args) {
JFrame desk = new JFrame("Desktop Demo");
//EXIT_ON_CLOSE == 3
desk.setDefaultCloseOperation(3);
desk.getContentPane().setLayout(new BorderLayout());
desk.setSize(850, 500);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
desk.setLocation((d.width - desk.getSize().width) / 2,
(d.height - desk.getSize().height) / 2);
JDesktopPane desktop = new JDesktopPane();
desk.getContentPane().add(desktop, BorderLayout.CENTER);
desk.setVisible(true);
JDesktopDemo applet = new JDesktopDemo();
applet.isStandalone = true;
JInternalFrame frame = new JInternalFrame("Real Time Data Demo",
false, false, false, true);
frame.getContentPane().add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(800,440);
desktop.add(frame);
frame.setVisible(true);
applet.pane_.setBatch(false);
}
//static initializer for setting look & feel
static {
try {
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch(Exception e) {
}
}
void startButton_actionPerformed(ActionEvent e) {
rtData_.startData();
}
void stopButton_actionPerformed(ActionEvent e) {
rtData_.stopData();
}
void resetButton_actionPerformed(ActionEvent e) {
rtData_.stopData();
rtData_.resetData();
resetRange();
}
private void resetRange() {
/*
* A change in the range has occured. Get new range
* and set transforms, axes, and origin appropriately.
*/
pane_.setBatch(true);
SoTRange.GeoDate xrange = (SoTRange.GeoDate)rtData_.getXRange();
SoTRange.Double yrange = (SoTRange.Double)rtData_.getYRange();
SoTPoint origin = new SoTPoint(xrange.start, yrange.start);
xt_.setRangeU(xrange);
yt_.setRangeU(yrange);
xbot_.setRangeU(xrange);
xbot_.setLocationU(origin);
yleft_.setRangeU(yrange);
yleft_.setLocationU(origin);
pane_.setBatch(false);
}
public void propertyChange(PropertyChangeEvent evt) {
/**
* dataModified property is handled by CartesianGraph
* only need to look for rangeModified here to make sure
* range is properly updated
*/
if("rangeModified".equals(evt.getPropertyName())) {
resetRange();
}
}
}
/*
* wrappers for button events created by JBuilder
*/
class JRealTimeDemo_startButton_actionAdapter implements ActionListener {
JDesktopDemo adaptee;
JRealTimeDemo_startButton_actionAdapter(JDesktopDemo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.startButton_actionPerformed(e);
}
}
class JRealTimeDemo_stopButton_actionAdapter implements ActionListener {
JDesktopDemo adaptee;
JRealTimeDemo_stopButton_actionAdapter(JDesktopDemo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.stopButton_actionPerformed(e);
}
}
class JRealTimeDemo_resetButton_actionAdapter implements ActionListener {
JDesktopDemo adaptee;
JRealTimeDemo_resetButton_actionAdapter(JDesktopDemo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.resetButton_actionPerformed(e);
}
}