Problem with adjusting both transparency and color of an object
I am writing a program where when an object is picked, both it's transparency and color will be altered (the object will become opaque, and its color will turn to a predefined "selected" color), while the previously selected object will return to its original transparency and color. I am able to get this to work, except that objects that were picked two or more picks ago will remain in the selected color, albeit in their original transparency. This problem only seems to occur when transparency is factored in. The picking/color & transparency altering code is as follows.
publicclass PickingListenerextends MouseAdapter{
private PickCanvas pickCanvas;
private TextDisplay overlay;
private Primitive p;
private Primitive lastP;
private ColoringAttributes origColor;
private TransparencyAttributes origTransparency;
public PickingListener(PickCanvas pickCanvasArg, TextDisplay overlayArg){
pickCanvas = pickCanvasArg;
overlay = overlayArg;
}
publicvoid mouseClicked(MouseEvent e){
pickCanvas.setShapeLocation(e);
PickResult result = pickCanvas.pickClosest();
if (result ==null){
System.out.println("Nothing picked");
}else{
p = (Primitive) result.getNode(PickResult.PRIMITIVE);
if (p !=null){
setSelectedColor();
overlay.setPickedBarInfo((BarInformation) p.getUserData());
}
else
System.out.println("null");
}
}
privatevoid setSelectedColor(){
ColoringAttributes barCA =new ColoringAttributes();
TransparencyAttributes barTransp =new TransparencyAttributes(TransparencyAttributes.NICEST, 0.0f);
barCA.setColor(ColorConstants.SELECTED);
if (lastP !=null){
lastP.getAppearance().setColoringAttributes(origColor);
lastP.getAppearance().setTransparencyAttributes(origTransparency);
}
origColor = p.getAppearance().getColoringAttributes();
origTransparency = p.getAppearance().getTransparencyAttributes();
p.getAppearance().setColoringAttributes(barCA);
p.getAppearance().setTransparencyAttributes(barTransp);
lastP = p;
}
}
Capabilities to alter the primitive's color and transparency are all set.
(
barAppearance.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
barAppearance.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
barAppearance.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);barAppearance.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
ColoringAttributes barCA =new ColoringAttributes();
barCA.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
barCA.setCapability(ColoringAttributes.ALLOW_COLOR_READ);
)
Any insight as to why this would occur would be greatly appreciated.
-Adrian Benton

