p.getParent() == null))
return;
int style = 0;
java.awt.Container parent = comp.getParent();
if (parent instanceof javax.swing.JSplitPane ||
parent instanceof javax.swing.JTabbedPane ||
parent.getLayout() instanceof javax.swing.ViewportLayout)
{
style = ElasticHandles.NOSIZE;
}
else
if (comp instanceof com.sas.visuals.ResizeToFitInterface)
{
if (((com.sas.visuals.ResizeToFitInterface)comp).isResizeToFit())
style = ElasticHandles.NOSIZE;
}
// style = ElasticComponentList.getSelectionType(comp) | style;
// this code is copied from ElasticHandles.paint()
// There should be only one SINGLESELECT. This is the dominant component
// all others should be MULTISELECT.
// NOSIZE is used to modify slightly how handles are drawn.
//System.out.println("Handles painting "+g.getClipBounds());
int Style = style & ~ElasticHandles.NOSIZE;
int nosize = style & ElasticHandles.NOSIZE;
//System.out.println("Style: "+Style+ "style: "+style);
//System.out.println("Actually drawing");
Rectangle bounds = comp.getBounds();
Rectangle parentBounds = null;
Point contentPaneOrigin = getContentPane().getLocation();
if (parent != getContentPane())
{
bounds = javax.swing.SwingUtilities.convertRectangle(comp, new Rectangle(comp.getSize()), getContentPane());
parentBounds = javax.swing.SwingUtilities.convertRectangle(parent, new Rectangle(parent.getSize()), getContentPane());
parentBounds.translate(contentPaneOrigin.x, contentPaneOrigin.y);
}
else
{
parentBounds = getContentPane().getBounds();
}
bounds.translate(contentPaneOrigin.x, contentPaneOrigin.y);
int hWidth;
int hHeight;
if (nosize != 0)
{
hWidth = ElasticHandles.nosizeWidth;
hHeight = ElasticHandles.nosizeHeight;
}
else
{
hWidth = ElasticHandles.handleWidth;
hHeight = ElasticHandles.handleHeight;
}
int x = bounds.x - hWidth;
int y = bounds.y - hHeight;
int width = bounds.width + 2 * hWidth;
int height = bounds.height + 2 * hHeight;
bounds.x = x;
bounds.y = y;
bounds.width = width;
bounds.height = height;
g.setClip(parentBounds);
Rectangle clipBounds = g.getClipBounds();
if (clipBounds != null && bounds.intersects(clipBounds) == false)
{
return;
}
// DEFAULT means no handles, just an outline
// MULTISELECT means outline and empty box
// SINGLESELECT means outline and filled box
Color fore = parent.getForeground();
if (nosize != 0)
{
if ((Style == ElasticHandles.SINGLESELECT) || (Style == ElasticHandles.MULTISELECT))
{
if (Style == ElasticHandles.SINGLESELECT)
{
g.setColor(java.awt.SystemColor.activeCaption);
g.fillRect(x,y,hWidth-1,height);
g.fillRect(x,y,width,hHeight-1);
g.fillRect(x+width-hWidth,y,hWidth-1,height);
g.fillRect(x,y+height-hHeight,width,hHeight-1);
}
g.setColor(fore);
g.drawRect(x,y,width-1, height-1);
}
}
else if (Style == ElasticHandles.MULTISELECT)
{
// corner handles
//System.out.println("Multi select empty");
int tmphHeight = hHeight-1;
int tmphWidth = hWidth-1;
g.setColor(fore);
g.drawRect(x,y,tmphWidth,tmphHeight);
g.drawRect(x+width-hWidth,y+height-hHeight,tmphWidth,tmphHeight);
g.drawRect(x+width-hWidth,y,tmphWidth,tmphHeight);
g.drawRect(x,y+height-hHeight,tmphWidth,tmphHeight);
// side resize handles
g.drawRect(x+(width/2)-hWidth/2, y, tmphWidth, tmphHeight);
g.drawRect(x+(width/2)-hWidth/2, y+height-hHeight, tmphWidth, tmphHeight);
g.drawRect(x, y+(height/2)-hHeight/2, tmphWidth, tmphHeight);
g.drawRect(x+width-hWidth, y+(height/2)-hHeight/2, tmphWidth, tmphHeight);
}
else if (Style == ElasticHandles.SINGLESELECT)
{
//System.out.println("Filled handle");
// corner handles
int tmphHeight = hHeight-1;
int tmphWidth = hWidth-1;
g.setColor(java.awt.SystemColor.activeCaption);
g.fillRect(x,y,tmphWidth,tmphHeight);
g.fillRect(x+width-hWidth,y+height-hHeight,tmphWidth,tmphHeight);
g.fillRect(x+width-hWidth,y,tmphWidth,tmphHeight);
g.fillRect(x,y+height-hHeight,tmphWidth,tmphHeight);
// side resize handles
g.fillRect(x+(width/2)-hWidth/2, y, tmphWidth, tmphHeight);
g.fillRect(x+(width/2)-hWidth/2, y+height-hHeight, tmphWidth, tmphHeight);
g.fillRect(x, y+(height/2)-hHeight/2, tmphWidth, tmphHeight);
g.fillRect(x+width-hWidth, y+(height/2)-hHeight/2, tmphWidth, tmphHeight);
g.setColor(fore);
g.drawRect(x,y,tmphWidth,tmphHeight);
g.drawRect(x+width-hWidth,y+height-hHeight,tmphWidth,tmphHeight);
g.drawRect(x+width-hWidth,y,tmphWidth,tmphHeight);
g.drawRect(x,y+height-hHeight,tmphWidth,tmphHeight);
// side resize handles
g.drawRect(x+(width/2)-hWidth/2, y, tmphWidth, tmphHeight);
g.drawRect(x+(width/2)-hWidth/2, y+height-hHeight, tmphWidth, tmphHeight);
g.drawRect(x, y+(height/2)-hHeight/2, tmphWidth, tmphHeight);
g.drawRect(x+width-hWidth, y+(height/2)-hHeight/2, tmphWidth, tmphHeight);
}
//g.drawRect(bounds.x-1,bounds.y-1,bounds.width+1,bounds.height+1);
style = 0;
}
}
// This panel is added to the layeredPane at the highest level
class GridLayer extends javax.swing.JPanel
{
int gridState = 0;
int gridSize = 10;
// int gridColor = 0;// this should get set the first time in...
public void setGridSize(int size)
{
gridSize = size;
}
public int getGridSize()
{
return gridSize;
}
public void setGridState(int state)
{
gridState = state;
}
public int getGridState()
{
return gridState;
}
public void paintComponent(Graphics g)
{
// draw a grid on the background
Rectangle b = g.getClipBounds();
Rectangle r = new Rectangle(
(b.x/gridSize)*gridSize, (b.y/gridSize)*gridSize,
((b.width/gridSize)+1)*gridSize, ((b.height/gridSize)+1)*gridSize);
//System.out.println("grid: "+b + " "+r);
//g.setColor(java.awt.Color.red);
int limitx = r.width/gridSize;
int limity = r.height/gridSize;
int i;
int j;
int x;
int y;
//System.out.println("r: "+r+" gridSize: "+gridSize+" limitx: "+limitx+" limity: "+limity);
if (gridState == 1) // dots
{
//if (r.x != 0)
// g.setColor(java.awt.Color.red);
for(i=0;i<=limitx;++i)
{
for(j=0;j<=limity;++j)
{
x = r.x+i*gridSize;
y = r.y+j*gridSize;
g.drawLine(x,y,x,y);
}
}
}
else if (gridState == 2) // lines
{
// System.out.println("limitx: "+limitx+" limity: "+limity);
// g.setColor(getForeground());
for(i=0;i<=limitx;++i)
g.drawLine(r.x+i*gridSize, r.y, r.x+i*gridSize, r.y+r.height);
for(i=0;i<=limity;++i)
g.drawLine(r.x, r.y+i*gridSize, r.x+r.width, r.y+i*gridSize);
// g.setColor(getForeground());
}
}
}
/**
* Creates a runtime exception with a message like:
* <pre>
* "Do not use JEmbeddedFrame.add() use JEmbeddedFrame.getContentPane().add() instead"
* </pre>
*
* @param op a <code>String</code> indicating the attempted operation;
* in the example above, the operation string is "add"
*/
private Error createRootPaneException(String op) {
String type = getClass().getName();
return new Error(
"Do not use " + type + "." + op + "() use "
+ type + ".getContentPane()." + op + "() instead");
}
}
class ElasticHandles
{
public static final int SINGLESELECT=0;
public static final int MULTISELECT= 1;
public static final int NOSIZE =2;
public static int nosizeWidth =6;
public static int nosizeHeight =6;
public static int handleWidth =6;
public static int handleHeight =6;
}
==========================================
Here is some sample output from javap. The first set is from the class compiled in 1.3.1. The second set is from the class compiled with 1.4b65. This seems really similar to bug 4390048 which was closed as unreproducible.
------------------------------------------
Line numbers for method FrameTest. GridLayer(FrameTest)
line 684: 0
line 686: 9
line 687: 14
line 684: 20
-----------------------------------------
Line numbers for method FrameTest. GridLayer(FrameTest)
line 753: 0
line 755: 9
line 756: 14
line 753: 20
======================================================================
Name: pa48320 Date: 05/22/2001
The following code, when compiled with JDK 1.3.1 has correct line number information. When compiled with 1.4, the line numbers go off by line 254 in the file. I compuled with javac -g FrameTest.java. I dumped the line information with javap -l -classpath . FrameTest. The real problem is that, by the end of the file, the line number are so far off that this code cannot be debugged in JDB or any debugger.
=============================
import javax.swing.JRootPane;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.RootPaneContainer;
import java.awt.Container;
import java.awt.Component;
import java.awt.LayoutManager;
import java.awt.Graphics;
import javax.swing.JMenuBar;
import javax.swing.UIManager;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.awt.Point;
import java.awt.Color;
public class FrameTest extends JPanel
implements RootPaneContainer
{
private JRootPane rootPane;
protected boolean rootPaneCheckingEnabled = false;
private String m_imageName;
private com.sas.idesupport.BackgroundPainter painter;
private com.sas.visuals.ImageView backgroundImage;
//apparently, the ps sets values on imageview, but does not call setImageView().
//Therefore, the image does not display as a background immediately after set in the ps.
//using the propertyChange event to notify painter of update.
private ImageViewPropertyChangeAdapter imageAdapter = new ImageViewPropertyChangeAdapter();
// private JFrameEventHandler listener;
private GridLayer gridLayer;
private GlassPane glassPane;
private String title;
public FrameTest()
{
frameInit();
painter = new com.sas.idesupport.BackgroundPainter();
painter.setOwner(this);
painter.setPainter(new com.sas.idesupport.DefaultPainter());
backgroundImage = new com.sas.visuals.ImageView();
backgroundImage.addPropertyChangeListener (imageAdapter);
}
/** Called by the constructors to init the <code>JFrame</code> properly. */
protected void frameInit() {
setLayout(new java.awt.BorderLayout());
//?? enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK);
setRootPane(createRootPane());
setBackground(UIManager.getColor("control"));
setRootPaneCheckingEnabled(true);
// if (JEmbeddedFrame.isDefaultLookAndFeelDecorated()) {
// boolean supportsWindowDecorations =
// UIManager.getLookAndFeel().getSupportsWindowDecorations();
// if (supportsWindowDecorations) {
// setUndecorated(true);
// getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
// }
// }
}
public java.awt.Frame getParentFrame()
{
return (java.awt.Frame)getParent().getParent();
}
public void setGridState(int state, int size)
{
//gridLayer.updateGrid(state, size);
// printContainment(this);
gridLayer.setGridState(state);
gridLayer.setGridSize(size);
gridLayer.repaint();
// listener.setSnapState(state, size);
}
// separate this functionality. Call it separately in the designtime construction piece.
public void initializeBuildTime()
{
// listener = new JFrameEventHandler();
getContentPane().setLayout(null);
// getContentPane().addContainerListener(listener);
m_imageName = "";
gridLayer = new GridLayer();
getLayeredPane().add(painter, new Integer(Integer.MIN_VALUE));
painter.setBounds(0,0,5000,5000);
getLayeredPane().add(gridLayer, new Integer(Integer.MAX_VALUE));
gridLayer.setBounds(0,0,5000,5000);
glassPane = new GlassPane();
setGlassPane(glassPane);
glassPane.setBounds(0,0,5000,5000);
((JPanel)getContentPane()).setOpaque(false);
gridLayer.setOpaque(false);
glassPane.setOpaque(false);
glassPane.setVisible(true);
}
public void setTitle(String title)
{
this.title = title;
// need to repaint the outer frame
}
public String getTitle()
{
return title;
}
public void setPainter(com.sas.idesupport.PainterInterface defaultPainter)
{
painter.setPainter(defaultPainter );
// this.defaultPainter = defaultPainter;
}
public com.sas.idesupport.PainterInterface getPainter()
{
return painter.getPainter();
// return defaultPainter;
}
// public String getClassName()
// {
// return IDESupport.getFrameClassName(this);
// }
// public void setClassName(String name)
// {
// IDESupport.setFrameClassName(this, name);
// }
// public Object[] getModels(){return IDESupport.getModels(this);}
public void setModels(Object[] o) {}
// public boolean isInitialFrame(){return IDESupport.isInitialFrame(this);}
// public boolean isPrimaryFrame(){return IDESupport.isPrimaryFrame(this);}
// public void setInitialFrame(boolean state){IDESupport.setInitialFrame(this, state);}
// public javax.swing.JMenuBar getJMenuBar(){ return IDESupport.getJMenuBar(this);}
public javax.swing.JMenuBar getJMenuBar() { return getRootPane().getMenuBar();}
public void setJMenuBar(javax.swing.JMenuBar m)
{
getRootPane().setMenuBar(m);
// super.setJMenuBar(m);
// IDESupport.setJMenuBar(this, m);
}
public boolean isVisualFrame() { return true; }
public boolean isServlet()
{
return false;
}
private boolean m_bIsApplet;
public boolean isApplet()
{
return m_bIsApplet;
}
public void setIsApplet(boolean b)
{
m_bIsApplet = b;
//parent.setDecorationState(b);
}
public void setPrePainter(com.sas.visuals.PainterInterface p)
{
// prePainter = p;
}
public com.sas.visuals.PainterInterface getPrePainter()
{
// return prePainter;
return null;
}
public com.sas.visuals.ImageView getBackgroundImage()
{
// System.out.println ("getBackgroundImage");
//return new com.sas.visuals.ImageView(m_imageName);
if (backgroundImage != null)
return backgroundImage;
else
{
// System.out.println (" backgroundImage = null");
backgroundImage = new com.sas.visuals.ImageView();
backgroundImage.addPropertyChangeListener(imageAdapter);
return backgroundImage;
}
}
public void setBackgroundImage(com.sas.visuals.ImageView s)
{
// System.out.println ("setBackgroundImage-"+s);
if ((s != null) && (s.getSource() != null) && (!s.getSource().equals("")))
{
if (backgroundImage != null)
backgroundImage.removePropertyChangeListener(imageAdapter);
backgroundImage = s;
backgroundImage.addPropertyChangeListener(imageAdapter);
// System.out.println ("add propertyChangeListener");
m_imageName = s.getSource();
// System.out.println ("setBackgroundImage-"+m_imageName);
if (painter != null)
painter.setImageName(m_imageName);
}
else
{
if (s != null)
{
// System.out.println (" s.getSource = null");
if (backgroundImage != null)
backgroundImage.removePropertyChangeListener(imageAdapter);
backgroundImage = s;
backgroundImage.addPropertyChangeListener(imageAdapter);
}
else //s== null
{
// System.out.println (" s= null");
if (backgroundImage != null)
backgroundImage.removePropertyChangeListener(imageAdapter);
backgroundImage = new com.sas.visuals.ImageView();
backgroundImage.addPropertyChangeListener(imageAdapter);
}
m_imageName = "";
if (painter != null)
painter.setImageName(m_imageName);
}
invalidate();
// IDESupport.repaintComponent(this);
}
// public IFrameEventHandler getEventHandler()
// {
// //System.out.println("BuildFrame as handler");
// return listener;
// //return null;
// }
public java.awt.Container getRoot()
{
return this;
}
/**
* Called by the constructor methods to create the default
* <code>rootPane</code>.
*/
protected JRootPane createRootPane() {
return new JRootPane();
}
public JRootPane getRootPane()
{
return rootPane;
}
/**
* Sets the <code>rootPane</code> property.
* This method is called by the constructor.
* @param root the <code>rootPane</code> object for this frame
*
* @see #getRootPane
*
* @beaninfo
* hidden: true
* description: the RootPane object for this frame.
*/
protected void setRootPane(JRootPane root)
{
if(rootPane != null) {
remove(rootPane);
}
rootPane = root;
if(rootPane != null) {
boolean checkingEnabled = isRootPaneCheckingEnabled();
try {
setRootPaneCheckingEnabled(false);
add(rootPane, BorderLayout.CENTER);
}
finally {
setRootPaneCheckingEnabled(checkingEnabled);
}
}
}
public void setContentPane(Container contentPane)
{
getRootPane().setContentPane(contentPane);
}
public Container getContentPane()
{
return getRootPane().getContentPane();
}
public void setLayeredPane(JLayeredPane layeredPane)
{
getRootPane().setLayeredPane(layeredPane);
}
public JLayeredPane getLayeredPane()
{
return getRootPane().getLayeredPane();
}
public void setGlassPane(Component glassPane)
{
getRootPane().setGlassPane(glassPane);
}
public Component getGlassPane()
{
return getRootPane().getGlassPane();
}
/**
* Returns whether calls to <code>add</code> and
* <code>setLayout</code> cause an exception to be thrown.
*
* @return true if <code>add</code> and <code>setLayout</code>
* are checked; false otherwise
*
* @see #addImpl
* @see #setLayout
* @see #setRootPaneCheckingEnabled
*/
protected boolean isRootPaneCheckingEnabled() {
return rootPaneCheckingEnabled;
}
/**
* Determines whether calls to <code>add</code> and
* <code>setLayout</code> will cause an exception to be thrown.
*
* @param enabled true if checking is to be
* enabled, which causes the exceptions to be thrown
*
* @see #addImpl
* @see #setLayout
* @see #isRootPaneCheckingEnabled
* @beaninfo
* hidden: true
* description: Whether the add and setLayout methods throw exceptions when invoked.
*/
protected void setRootPaneCheckingEnabled(boolean enabled) {
rootPaneCheckingEnabled = enabled;
}
/**
* By default, children may not be added directly to this component,
* they must be added to its contentPane instead. For example:
* <pre>
* thisComponent.getContentPane().add(child)
* </pre>
* An attempt to add to directly to this component will cause an
* runtime exception to be thrown. Subclasses can disable this
* behavior.
*
* @param comp the component to be enhanced
* @param constraints the constraints to be respected
* @param index the index
* @exception Error if called with <code>rootPaneChecking</code> true
*
* @see #setRootPaneCheckingEnabled
*/
protected void addImpl(Component comp, Object constraints, int index)
{
if(isRootPaneCheckingEnabled()) {
throw createRootPaneException("add");
}
else {
super.addImpl(comp, constraints, index);
}
}
/**
* Removes the specified component from this container.
* @param comp the component to be removed
* @see #add
*/
public void remove(Component comp) {
if (comp == rootPane) {
super.remove(comp);
} else {
// Client mistake, but we need to handle it to avoid a
// common object leak in client applications.
getContentPane().remove(comp);
}
}
/**
* By default the layout of this component may not be set,
* the layout of its <code>contentPane</code> should be set instead.
* For example:
* <pre>
* thisComponent.getContentPane().setLayout(new GridLayout(1, 2))
* </pre>
* An attempt to set the layout of this component will cause an
* runtime exception to be thrown. Subclasses can disable this
* behavior.
* @param manager the <code>LayoutManager</code>
* @exception Error if called with <code>rootPaneChecking</code> true
*
* @see #setRootPaneCheckingEnabled
*/
public void setLayout(LayoutManager manager) {
if(isRootPaneCheckingEnabled()) {
throw createRootPaneException("setLayout");
}
else {
super.setLayout(manager);
}
}
/**
* Just calls <code>paint(g)</code>. This method was overridden to
* prevent an unnecessary call to clear the background.
*
* @param g the Graphics context in which to paint
*/
public void update(Graphics g) {
paint(g);
}
// /**
// * Sets the menubar for this frame.
// * @param menubar the menubar being placed in the frame
// *
// * @see #getJMenuBar
// *
// * @beaninfo
// * hidden: true
// * description: The menubar for accessing pulldown menus from this frame.
// */
// public void setJMenuBar(JMenuBar menubar) {
// getRootPane().setMenuBar(menubar);
// }
// /**
// * Returns the menubar set on this frame.
// * @return the menubar for this frame
// *
// * @see #setJMenuBar
// */
// public JMenuBar getJMenuBar() {
// return getRootPane().getMenuBar();
// }
class ImageViewPropertyChangeAdapter implements java.beans.PropertyChangeListener
{
public ImageViewPropertyChangeAdapter(){}
public void propertyChange (java.beans.PropertyChangeEvent e)
{
if (e.getPropertyName().equals ("source"))
{
m_imageName = backgroundImage.getSource();
if (painter != null)
painter.setImageName(m_imageName);
}
invalidate();
// IDESupport.repaintComponent(IDESwingFrame.this);
}
}
class GlassPane extends javax.swing.JPanel
{
public GlassPane()
{
//enableEvents(java.awt.AWTEvent.MOUSE_EVENT_MASK);
// addMouseMotionListener(IDESwingFrame.this.listener);
// addMouseListener(IDESwingFrame.this.listener);
}
// public IFrameEventHandler getEventHandler()
// {
// //System.out.println("Glasspane as handler");
// //return JBuildFrame.this.getEventHandler();
// return IDESwingFrame.this.listener;
// }
// public java.awt.Container getRoot()
// {
// return IDESwingFrame.this;
// }
public void paintComponent(Graphics g)
{
synchronized (getTreeLock())
{
// Object[] c = ElasticComponentList.getSelectedObjects(IDESwingFrame.this);
Object[] c = getComponents();
if (c == null)
return;
int i;
for(i = 0;i<c.length;++i)
{
if (c[i] instanceof Component)
{
Component visibleComp = (Component)c[i];
boolean visible = visibleComp.isVisible();
while(visibleComp != null && visible)
{
visibleComp = visibleComp.getParent();
if (visibleComp != null)
visible = visibleComp.isVisible();
}
if (visible)
paintElasticComponent((Component)c[i], g);
}
}
}
}
void paintElasticComponent(Component comp, Graphics g)
{
if ((comp == null) || (g == null) || (com
return;
int style = 0;
java.awt.Container parent = comp.getParent();
if (parent instanceof javax.swing.JSplitPane ||
parent instanceof javax.swing.JTabbedPane ||
parent.getLayout() instanceof javax.swing.ViewportLayout)
{
style = ElasticHandles.NOSIZE;
}
else
if (comp instanceof com.sas.visuals.ResizeToFitInterface)
{
if (((com.sas.visuals.ResizeToFitInterface)comp).isResizeToFit())
style = ElasticHandles.NOSIZE;
}
// style = ElasticComponentList.getSelectionType(comp) | style;
// this code is copied from ElasticHandles.paint()
// There should be only one SINGLESELECT. This is the dominant component
// all others should be MULTISELECT.
// NOSIZE is used to modify slightly how handles are drawn.
//System.out.println("Handles painting "+g.getClipBounds());
int Style = style & ~ElasticHandles.NOSIZE;
int nosize = style & ElasticHandles.NOSIZE;
//System.out.println("Style: "+Style+ "style: "+style);
//System.out.println("Actually drawing");
Rectangle bounds = comp.getBounds();
Rectangle parentBounds = null;
Point contentPaneOrigin = getContentPane().getLocation();
if (parent != getContentPane())
{
bounds = javax.swing.SwingUtilities.convertRectangle(comp, new Rectangle(comp.getSize()), getContentPane());
parentBounds = javax.swing.SwingUtilities.convertRectangle(parent, new Rectangle(parent.getSize()), getContentPane());
parentBounds.translate(contentPaneOrigin.x, contentPaneOrigin.y);
}
else
{
parentBounds = getContentPane().getBounds();
}
bounds.translate(contentPaneOrigin.x, contentPaneOrigin.y);
int hWidth;
int hHeight;
if (nosize != 0)
{
hWidth = ElasticHandles.nosizeWidth;
hHeight = ElasticHandles.nosizeHeight;
}
else
{
hWidth = ElasticHandles.handleWidth;
hHeight = ElasticHandles.handleHeight;
}
int x = bounds.x - hWidth;
int y = bounds.y - hHeight;
int width = bounds.width + 2 * hWidth;
int height = bounds.height + 2 * hHeight;
bounds.x = x;
bounds.y = y;
bounds.width = width;
bounds.height = height;
g.setClip(parentBounds);
Rectangle clipBounds = g.getClipBounds();
if (clipBounds != null && bounds.intersects(clipBounds) == false)
{
return;
}
// DEFAULT means no handles, just an outline
// MULTISELECT means outline and empty box
// SINGLESELECT means outline and filled box
Color fore = parent.getForeground();
if (nosize != 0)
{
if ((Style == ElasticHandles.SINGLESELECT) || (Style == ElasticHandles.MULTISELECT))
{
if (Style == ElasticHandles.SINGLESELECT)
{
g.setColor(java.awt.SystemColor.activeCaption);
g.fillRect(x,y,hWidth-1,height);
g.fillRect(x,y,width,hHeight-1);
g.fillRect(x+width-hWidth,y,hWidth-1,height);
g.fillRect(x,y+height-hHeight,width,hHeight-1);
}
g.setColor(fore);
g.drawRect(x,y,width-1, height-1);
}
}
else if (Style == ElasticHandles.MULTISELECT)
{
// corner handles
//System.out.println("Multi select empty");
int tmphHeight = hHeight-1;
int tmphWidth = hWidth-1;
g.setColor(fore);
g.drawRect(x,y,tmphWidth,tmphHeight);
g.drawRect(x+width-hWidth,y+height-hHeight,tmphWidth,tmphHeight);
g.drawRect(x+width-hWidth,y,tmphWidth,tmphHeight);
g.drawRect(x,y+height-hHeight,tmphWidth,tmphHeight);
// side resize handles
g.drawRect(x+(width/2)-hWidth/2, y, tmphWidth, tmphHeight);
g.drawRect(x+(width/2)-hWidth/2, y+height-hHeight, tmphWidth, tmphHeight);
g.drawRect(x, y+(height/2)-hHeight/2, tmphWidth, tmphHeight);
g.drawRect(x+width-hWidth, y+(height/2)-hHeight/2, tmphWidth, tmphHeight);
}
else if (Style == ElasticHandles.SINGLESELECT)
{
//System.out.println("Filled handle");
// corner handles
int tmphHeight = hHeight-1;
int tmphWidth = hWidth-1;
g.setColor(java.awt.SystemColor.activeCaption);
g.fillRect(x,y,tmphWidth,tmphHeight);
g.fillRect(x+width-hWidth,y+height-hHeight,tmphWidth,tmphHeight);
g.fillRect(x+width-hWidth,y,tmphWidth,tmphHeight);
g.fillRect(x,y+height-hHeight,tmphWidth,tmphHeight);
// side resize handles
g.fillRect(x+(width/2)-hWidth/2, y, tmphWidth, tmphHeight);
g.fillRect(x+(width/2)-hWidth/2, y+height-hHeight, tmphWidth, tmphHeight);
g.fillRect(x, y+(height/2)-hHeight/2, tmphWidth, tmphHeight);
g.fillRect(x+width-hWidth, y+(height/2)-hHeight/2, tmphWidth, tmphHeight);
g.setColor(fore);
g.drawRect(x,y,tmphWidth,tmphHeight);
g.drawRect(x+width-hWidth,y+height-hHeight,tmphWidth,tmphHeight);
g.drawRect(x+width-hWidth,y,tmphWidth,tmphHeight);
g.drawRect(x,y+height-hHeight,tmphWidth,tmphHeight);
// side resize handles
g.drawRect(x+(width/2)-hWidth/2, y, tmphWidth, tmphHeight);
g.drawRect(x+(width/2)-hWidth/2, y+height-hHeight, tmphWidth, tmphHeight);
g.drawRect(x, y+(height/2)-hHeight/2, tmphWidth, tmphHeight);
g.drawRect(x+width-hWidth, y+(height/2)-hHeight/2, tmphWidth, tmphHeight);
}
//g.drawRect(bounds.x-1,bounds.y-1,bounds.width+1,bounds.height+1);
style = 0;
}
}
// This panel is added to the layeredPane at the highest level
class GridLayer extends javax.swing.JPanel
{
int gridState = 0;
int gridSize = 10;
// int gridColor = 0;// this should get set the first time in...
public void setGridSize(int size)
{
gridSize = size;
}
public int getGridSize()
{
return gridSize;
}
public void setGridState(int state)
{
gridState = state;
}
public int getGridState()
{
return gridState;
}
public void paintComponent(Graphics g)
{
// draw a grid on the background
Rectangle b = g.getClipBounds();
Rectangle r = new Rectangle(
(b.x/gridSize)*gridSize, (b.y/gridSize)*gridSize,
((b.width/gridSize)+1)*gridSize, ((b.height/gridSize)+1)*gridSize);
//System.out.println("grid: "+b + " "+r);
//g.setColor(java.awt.Color.red);
int limitx = r.width/gridSize;
int limity = r.height/gridSize;
int i;
int j;
int x;
int y;
//System.out.println("r: "+r+" gridSize: "+gridSize+" limitx: "+limitx+" limity: "+limity);
if (gridState == 1) // dots
{
//if (r.x != 0)
// g.setColor(java.awt.Color.red);
for(i=0;i<=limitx;++i)
{
for(j=0;j<=limity;++j)
{
x = r.x+i*gridSize;
y = r.y+j*gridSize;
g.drawLine(x,y,x,y);
}
}
}
else if (gridState == 2) // lines
{
// System.out.println("limitx: "+limitx+" limity: "+limity);
// g.setColor(getForeground());
for(i=0;i<=limitx;++i)
g.drawLine(r.x+i*gridSize, r.y, r.x+i*gridSize, r.y+r.height);
for(i=0;i<=limity;++i)
g.drawLine(r.x, r.y+i*gridSize, r.x+r.width, r.y+i*gridSize);
// g.setColor(getForeground());
}
}
}
/**
* Creates a runtime exception with a message like:
* <pre>
* "Do not use JEmbeddedFrame.add() use JEmbeddedFrame.getContentPane().add() instead"
* </pre>
*
* @param op a <code>String</code> indicating the attempted operation;
* in the example above, the operation string is "add"
*/
private Error createRootPaneException(String op) {
String type = getClass().getName();
return new Error(
"Do not use " + type + "." + op + "() use "
+ type + ".getContentPane()." + op + "() instead");
}
}
class ElasticHandles
{
public static final int SINGLESELECT=0;
public static final int MULTISELECT= 1;
public static final int NOSIZE =2;
public static int nosizeWidth =6;
public static int nosizeHeight =6;
public static int handleWidth =6;
public static int handleHeight =6;
}
==========================================
Here is some sample output from javap. The first set is from the class compiled in 1.3.1. The second set is from the class compiled with 1.4b65. This seems really similar to bug 4390048 which was closed as unreproducible.
------------------------------------------
Line numbers for method FrameTest. GridLayer(FrameTest)
line 684: 0
line 686: 9
line 687: 14
line 684: 20
-----------------------------------------
Line numbers for method FrameTest. GridLayer(FrameTest)
line 753: 0
line 755: 9
line 756: 14
line 753: 20
======================================================================
Name: pa48320 Date: 05/22/2001
The following code, when compiled with JDK 1.3.1 has correct line number information. When compiled with 1.4, the line numbers go off by line 254 in the file. I compuled with javac -g FrameTest.java. I dumped the line information with javap -l -classpath . FrameTest. The real problem is that, by the end of the file, the line number are so far off that this code cannot be debugged in JDB or any debugger.
=============================
import javax.swing.JRootPane;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.RootPaneContainer;
import java.awt.Container;
import java.awt.Component;
import java.awt.LayoutManager;
import java.awt.Graphics;
import javax.swing.JMenuBar;
import javax.swing.UIManager;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.awt.Point;
import java.awt.Color;
public class FrameTest extends JPanel
implements RootPaneContainer
{
private JRootPane rootPane;
protected boolean rootPaneCheckingEnabled = false;
private String m_imageName;
private com.sas.idesupport.BackgroundPainter painter;
private com.sas.visuals.ImageView backgroundImage;
//apparently, the ps sets values on imageview, but does not call setImageView().
//Therefore, the image does not display as a background immediately after set in the ps.
//using the propertyChange event to notify painter of update.
private ImageViewPropertyChangeAdapter imageAdapter = new ImageViewPropertyChangeAdapter();
// private JFrameEventHandler listener;
private GridLayer gridLayer;
private GlassPane glassPane;
private String title;
public FrameTest()
{
frameInit();
painter = new com.sas.idesupport.BackgroundPainter();
painter.setOwner(this);
painter.setPainter(new com.sas.idesupport.DefaultPainter());
backgroundImage = new com.sas.visuals.ImageView();
backgroundImage.addPropertyChangeListener (imageAdapter);
}
/** Called by the constructors to init the <code>JFrame</code> properly. */
protected void frameInit() {
setLayout(new java.awt.BorderLayout());
//?? enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK);
setRootPane(createRootPane());
setBackground(UIManager.getColor("control"));
setRootPaneCheckingEnabled(true);
// if (JEmbeddedFrame.isDefaultLookAndFeelDecorated()) {
// boolean supportsWindowDecorations =
// UIManager.getLookAndFeel().getSupportsWindowDecorations();
// if (supportsWindowDecorations) {
// setUndecorated(true);
// getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
// }
// }
}
public java.awt.Frame getParentFrame()
{
return (java.awt.Frame)getParent().getParent();
}
public void setGridState(int state, int size)
{
//gridLayer.updateGrid(state, size);
// printContainment(this);
gridLayer.setGridState(state);
gridLayer.setGridSize(size);
gridLayer.repaint();
// listener.setSnapState(state, size);
}
// separate this functionality. Call it separately in the designtime construction piece.
public void initializeBuildTime()
{
// listener = new JFrameEventHandler();
getContentPane().setLayout(null);
// getContentPane().addContainerListener(listener);
m_imageName = "";
gridLayer = new GridLayer();
getLayeredPane().add(painter, new Integer(Integer.MIN_VALUE));
painter.setBounds(0,0,5000,5000);
getLayeredPane().add(gridLayer, new Integer(Integer.MAX_VALUE));
gridLayer.setBounds(0,0,5000,5000);
glassPane = new GlassPane();
setGlassPane(glassPane);
glassPane.setBounds(0,0,5000,5000);
((JPanel)getContentPane()).setOpaque(false);
gridLayer.setOpaque(false);
glassPane.setOpaque(false);
glassPane.setVisible(true);
}
public void setTitle(String title)
{
this.title = title;
// need to repaint the outer frame
}
public String getTitle()
{
return title;
}
public void setPainter(com.sas.idesupport.PainterInterface defaultPainter)
{
painter.setPainter(defaultPainter );
// this.defaultPainter = defaultPainter;
}
public com.sas.idesupport.PainterInterface getPainter()
{
return painter.getPainter();
// return defaultPainter;
}
// public String getClassName()
// {
// return IDESupport.getFrameClassName(this);
// }
// public void setClassName(String name)
// {
// IDESupport.setFrameClassName(this, name);
// }
// public Object[] getModels(){return IDESupport.getModels(this);}
public void setModels(Object[] o) {}
// public boolean isInitialFrame(){return IDESupport.isInitialFrame(this);}
// public boolean isPrimaryFrame(){return IDESupport.isPrimaryFrame(this);}
// public void setInitialFrame(boolean state){IDESupport.setInitialFrame(this, state);}
// public javax.swing.JMenuBar getJMenuBar(){ return IDESupport.getJMenuBar(this);}
public javax.swing.JMenuBar getJMenuBar() { return getRootPane().getMenuBar();}
public void setJMenuBar(javax.swing.JMenuBar m)
{
getRootPane().setMenuBar(m);
// super.setJMenuBar(m);
// IDESupport.setJMenuBar(this, m);
}
public boolean isVisualFrame() { return true; }
public boolean isServlet()
{
return false;
}
private boolean m_bIsApplet;
public boolean isApplet()
{
return m_bIsApplet;
}
public void setIsApplet(boolean b)
{
m_bIsApplet = b;
//parent.setDecorationState(b);
}
public void setPrePainter(com.sas.visuals.PainterInterface p)
{
// prePainter = p;
}
public com.sas.visuals.PainterInterface getPrePainter()
{
// return prePainter;
return null;
}
public com.sas.visuals.ImageView getBackgroundImage()
{
// System.out.println ("getBackgroundImage");
//return new com.sas.visuals.ImageView(m_imageName);
if (backgroundImage != null)
return backgroundImage;
else
{
// System.out.println (" backgroundImage = null");
backgroundImage = new com.sas.visuals.ImageView();
backgroundImage.addPropertyChangeListener(imageAdapter);
return backgroundImage;
}
}
public void setBackgroundImage(com.sas.visuals.ImageView s)
{
// System.out.println ("setBackgroundImage-"+s);
if ((s != null) && (s.getSource() != null) && (!s.getSource().equals("")))
{
if (backgroundImage != null)
backgroundImage.removePropertyChangeListener(imageAdapter);
backgroundImage = s;
backgroundImage.addPropertyChangeListener(imageAdapter);
// System.out.println ("add propertyChangeListener");
m_imageName = s.getSource();
// System.out.println ("setBackgroundImage-"+m_imageName);
if (painter != null)
painter.setImageName(m_imageName);
}
else
{
if (s != null)
{
// System.out.println (" s.getSource = null");
if (backgroundImage != null)
backgroundImage.removePropertyChangeListener(imageAdapter);
backgroundImage = s;
backgroundImage.addPropertyChangeListener(imageAdapter);
}
else //s== null
{
// System.out.println (" s= null");
if (backgroundImage != null)
backgroundImage.removePropertyChangeListener(imageAdapter);
backgroundImage = new com.sas.visuals.ImageView();
backgroundImage.addPropertyChangeListener(imageAdapter);
}
m_imageName = "";
if (painter != null)
painter.setImageName(m_imageName);
}
invalidate();
// IDESupport.repaintComponent(this);
}
// public IFrameEventHandler getEventHandler()
// {
// //System.out.println("BuildFrame as handler");
// return listener;
// //return null;
// }
public java.awt.Container getRoot()
{
return this;
}
/**
* Called by the constructor methods to create the default
* <code>rootPane</code>.
*/
protected JRootPane createRootPane() {
return new JRootPane();
}
public JRootPane getRootPane()
{
return rootPane;
}
/**
* Sets the <code>rootPane</code> property.
* This method is called by the constructor.
* @param root the <code>rootPane</code> object for this frame
*
* @see #getRootPane
*
* @beaninfo
* hidden: true
* description: the RootPane object for this frame.
*/
protected void setRootPane(JRootPane root)
{
if(rootPane != null) {
remove(rootPane);
}
rootPane = root;
if(rootPane != null) {
boolean checkingEnabled = isRootPaneCheckingEnabled();
try {
setRootPaneCheckingEnabled(false);
add(rootPane, BorderLayout.CENTER);
}
finally {
setRootPaneCheckingEnabled(checkingEnabled);
}
}
}
public void setContentPane(Container contentPane)
{
getRootPane().setContentPane(contentPane);
}
public Container getContentPane()
{
return getRootPane().getContentPane();
}
public void setLayeredPane(JLayeredPane layeredPane)
{
getRootPane().setLayeredPane(layeredPane);
}
public JLayeredPane getLayeredPane()
{
return getRootPane().getLayeredPane();
}
public void setGlassPane(Component glassPane)
{
getRootPane().setGlassPane(glassPane);
}
public Component getGlassPane()
{
return getRootPane().getGlassPane();
}
/**
* Returns whether calls to <code>add</code> and
* <code>setLayout</code> cause an exception to be thrown.
*
* @return true if <code>add</code> and <code>setLayout</code>
* are checked; false otherwise
*
* @see #addImpl
* @see #setLayout
* @see #setRootPaneCheckingEnabled
*/
protected boolean isRootPaneCheckingEnabled() {
return rootPaneCheckingEnabled;
}
/**
* Determines whether calls to <code>add</code> and
* <code>setLayout</code> will cause an exception to be thrown.
*
* @param enabled true if checking is to be
* enabled, which causes the exceptions to be thrown
*
* @see #addImpl
* @see #setLayout
* @see #isRootPaneCheckingEnabled
* @beaninfo
* hidden: true
* description: Whether the add and setLayout methods throw exceptions when invoked.
*/
protected void setRootPaneCheckingEnabled(boolean enabled) {
rootPaneCheckingEnabled = enabled;
}
/**
* By default, children may not be added directly to this component,
* they must be added to its contentPane instead. For example:
* <pre>
* thisComponent.getContentPane().add(child)
* </pre>
* An attempt to add to directly to this component will cause an
* runtime exception to be thrown. Subclasses can disable this
* behavior.
*
* @param comp the component to be enhanced
* @param constraints the constraints to be respected
* @param index the index
* @exception Error if called with <code>rootPaneChecking</code> true
*
* @see #setRootPaneCheckingEnabled
*/
protected void addImpl(Component comp, Object constraints, int index)
{
if(isRootPaneCheckingEnabled()) {
throw createRootPaneException("add");
}
else {
super.addImpl(comp, constraints, index);
}
}
/**
* Removes the specified component from this container.
* @param comp the component to be removed
* @see #add
*/
public void remove(Component comp) {
if (comp == rootPane) {
super.remove(comp);
} else {
// Client mistake, but we need to handle it to avoid a
// common object leak in client applications.
getContentPane().remove(comp);
}
}
/**
* By default the layout of this component may not be set,
* the layout of its <code>contentPane</code> should be set instead.
* For example:
* <pre>
* thisComponent.getContentPane().setLayout(new GridLayout(1, 2))
* </pre>
* An attempt to set the layout of this component will cause an
* runtime exception to be thrown. Subclasses can disable this
* behavior.
* @param manager the <code>LayoutManager</code>
* @exception Error if called with <code>rootPaneChecking</code> true
*
* @see #setRootPaneCheckingEnabled
*/
public void setLayout(LayoutManager manager) {
if(isRootPaneCheckingEnabled()) {
throw createRootPaneException("setLayout");
}
else {
super.setLayout(manager);
}
}
/**
* Just calls <code>paint(g)</code>. This method was overridden to
* prevent an unnecessary call to clear the background.
*
* @param g the Graphics context in which to paint
*/
public void update(Graphics g) {
paint(g);
}
// /**
// * Sets the menubar for this frame.
// * @param menubar the menubar being placed in the frame
// *
// * @see #getJMenuBar
// *
// * @beaninfo
// * hidden: true
// * description: The menubar for accessing pulldown menus from this frame.
// */
// public void setJMenuBar(JMenuBar menubar) {
// getRootPane().setMenuBar(menubar);
// }
// /**
// * Returns the menubar set on this frame.
// * @return the menubar for this frame
// *
// * @see #setJMenuBar
// */
// public JMenuBar getJMenuBar() {
// return getRootPane().getMenuBar();
// }
class ImageViewPropertyChangeAdapter implements java.beans.PropertyChangeListener
{
public ImageViewPropertyChangeAdapter(){}
public void propertyChange (java.beans.PropertyChangeEvent e)
{
if (e.getPropertyName().equals ("source"))
{
m_imageName = backgroundImage.getSource();
if (painter != null)
painter.setImageName(m_imageName);
}
invalidate();
// IDESupport.repaintComponent(IDESwingFrame.this);
}
}
class GlassPane extends javax.swing.JPanel
{
public GlassPane()
{
//enableEvents(java.awt.AWTEvent.MOUSE_EVENT_MASK);
// addMouseMotionListener(IDESwingFrame.this.listener);
// addMouseListener(IDESwingFrame.this.listener);
}
// public IFrameEventHandler getEventHandler()
// {
// //System.out.println("Glasspane as handler");
// //return JBuildFrame.this.getEventHandler();
// return IDESwingFrame.this.listener;
// }
// public java.awt.Container getRoot()
// {
// return IDESwingFrame.this;
// }
public void paintComponent(Graphics g)
{
synchronized (getTreeLock())
{
// Object[] c = ElasticComponentList.getSelectedObjects(IDESwingFrame.this);
Object[] c = getComponents();
if (c == null)
return;
int i;
for(i = 0;i<c.length;++i)
{
if (c[i] instanceof Component)
{
Component visibleComp = (Component)c[i];
boolean visible = visibleComp.isVisible();
while(visibleComp != null && visible)
{
visibleComp = visibleComp.getParent();
if (visibleComp != null)
visible = visibleComp.isVisible();
}
if (visible)
paintElasticComponent((Component)c[i], g);
}
}
}
}
void paintElasticComponent(Component comp, Graphics g)
{
if ((comp == null) || (g == null) || (com
- duplicates
-
JDK-4463373 JavaDoc comments throw off javac line numbers
- Closed