Hi everyone,
I've been trying to place a few buttons with images over the screen.
I realized that the best way was to modify the
org.jmol.applet.AppletWrapper class
The first thing I did was create a class that inherits from
javax.swing.JButton which I named ImageComponent
I initialize a button like this
ImageComponent centerDirButton;
centerDirButton = new ImageComponent("controlFragmentModeButton.png");
And, inside the ImageComponent class, the button is created like this:
private Image image;
private BufferedImage originalBufferedImage;
public ImageComponent(String imageFileName) {
super();
String imageName = "org/jmol/modelkit/images/" + imageFileName;
URL imageUrl = this.getClass().getClassLoader().getResource(imageName);
if (imageUrl != null) {
imageString = imageUrl.toExternalForm();
this.imageIcon = new ImageIcon(imageUrl);
}else{
this.imageIcon = new ImageIcon(defaultImageString);
}
this.image = this.imageIcon.getImage();
this.originalBufferedImage = null;
try{
this.originalBufferedImage = toBufferedImage(this.image);
} catch(Exception e){
Logger.error(
"An error has ocurred converting an image into a buffered image",
null);
e.printStackTrace();
}
setBorders();
}
and when the button is painted, this happens
@Override
public void paint(Graphics g) {
super.paint(g);
if(getImage() == null)
return;
try {
BufferedImage bufferedImagetoDraw = originalBufferedImage;
bufferedImagetoDraw = resizeTrick(originalBufferedImage,
this.getWidth(), this.getHeight());
g.drawImage(bufferedImagetoDraw, border, border,
getWidth()-2*border,
getHeight()-2*border,
this);
} catch (Exception e) {
Logger.error(
"An error has ocurred during image resizing. Might be Sun's AWT
class " +
"sun.awt.image.BufferedImageGraphicsConfig. ",
null);
e.printStackTrace();
g.drawImage(image, border, border,
getWidth()-2*border,
getHeight()-2*border,
this);
}
}
I used the resizeTrick() method to adjust the button's image to the size of
the button. I found it in this web site:
http://www.componenthouse.com/article-20
The problem is that, to resize it, I had to use the java.awt.Graphics2D
class. I know you don't use it in any of the other classes. Instead, you
use org.jmol.g3d.Graphics3D, but Graphics3D doesn't have the same methods
and properties as Graphics2D so I can't use it.
What should I do? Is it OK for me to use Graphics2D in that one class I
created or is there another way for me to resize the image without it?
Thanks in advance
----
Eleazar
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Jmol-developers mailing list
Jmol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-developers