| Printed |
Page 68
Last paragraph |
Hi,
The hack for checkable JList's works correctly with one exception. Once an item is selected, and
being the only selected item, if we want to deselect it, it will not allow us.
The reason for this: the ListSelectionEvent doesn't go through, since at the JList level, the
selection is still the same. So in order to do it, one is forced to select another item, and then
come back to the previous one.
So we need an extra hack on top of this hack ;)
Below is the code and comments:
//inner class to CheckBoxJList
class MyMouseAdapter extends MouseAdapter {
/* note: this works because the ListSelection event always is produced before the MouseEvent */
public void mouseClicked(MouseEvent evt) {
if (!listEvtProduced) { //only react when a list event has not been produced
//instead of manipulating the model and cached selections, we simply produce the event so it gets
handled by the Listener method
VersionJList.this.valueChanged(new ListSelectionEvent(VersionJList.this, 0, 0, false));
} else { //reset
listEvtProduced = false;
}
}
}
//private field CheckBoxJList also for this added hack
private boolean listEvtProduced;
//finally, in the valueChanged() method, after the line:
addListSelectionListener(this);
the following line must be added:
listEvtProduced=true;
|
Anonymous |
| Printed |
Page 236
Inside method actionPerformed of Example 6-9 |
The animated sheet hack works great, but only once - try calling the showJDialogAsSheet method again, and the incoming/outgoing sheet image is painted in the topleft corner of the glass pane.
I found that the following change fixes it:
##
// used by the Timer
public void actionPerformed (ActionEvent e) {
if (animating) {
// calculate height to show
float animationPercent =
(System.currentTimeMillis() - animationStart) /
ANIMATION_DURATION;
animationPercent = Math.min (1.0f, animationPercent);
int animatingHeight = 0;
if (animationDirection == INCOMING) {
animatingHeight =
(int) (animationPercent * sheet.getHeight());
} else {
animatingHeight =
(int) ((1.0f - animationPercent) * sheet.getHeight());
}
// clip off that much from sheet and blit it
// into animatingSheet
animatingSheet.setAnimatingHeight (animatingHeight);
- animatingSheet.repaint();
+ glass.revalidate();
if (animationPercent >= 1.0f) {
stopAnimation();
if (animationDirection == INCOMING) {
finishShowingSheet();
} else {
glass.removeAll();
glass.setVisible(false);
}
}
}
}
##
As glass.revalidate() triggers animatingSheet.repaint(), this modification ensures that everything continues to work smoothly.
|
Jan Schenkel |
| Printed |
Page 311-312
Within the drawLiquidButton source code |
protected void drawLiquidButton(Color base,
int width, int height,
String text, float scale,
Graphics2D g2) {
// calculate inset
int inset = (int)(scale*0.04f);
int w = width - inset*2 - 1;
int h = height - (int)(scale*0.1f) - 1;
g2.translate(inset,0);
drawDropShadow(w,h,scale,g2);
if(pressed) {
g2.translate(0, 0.04f*scale);
}
drawButtonBody(w,h,scale,base,g2);
drawText(w,h,scale,text,g2);
drawHighlight(w,h,scale,base,g2);
drawBorder(w,h,scale,g2);
if(pressed) {
g2.translate(0, 0.04f*scale);
}
g2.translate(-inset,0);
}
Is the drawLiquidButton method in the book, there are two if(pressed) blocks which translate the g2 object the same way, the second should actually read
if(pressed) {
g2.translate(0, -(0.04f*scale));
}
|
Colin Sowter |
| PDF |
Page 397
Source code snippet at bottom |
The following line of code is incorrect:
int bytesPerSec = format.getSampleSizeInBits() *
(int) format.getSampleRate();
This computes the bits per second, not bytes per second. As a result, the buffer is 8 times larger than it should be.
|
Vocaro |