mirror of
https://gitlab.com/biskuteri-cafe/JKomasto2.git
synced 2025-01-23 22:41:37 +01:00
Fixed ClassCastException bug in PostWindow.
Fixed page flipping in RichTextPane3, after last bug fix.
This commit is contained in:
parent
2b63e37276
commit
3ca2b58277
@ -29,6 +29,7 @@ import java.awt.Image;
|
|||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.MediaTracker;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -428,7 +429,49 @@ implements ActionListener {
|
|||||||
setAuthorId(String n) { authorId.setText(n); }
|
setAuthorId(String n) { authorId.setText(n); }
|
||||||
|
|
||||||
public void
|
public void
|
||||||
setAuthorAvatar(Image n) { profile.setImage(n); }
|
setAuthorAvatar(Image n)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
MediaTracker mt = new MediaTracker(this);
|
||||||
|
mt.addImage(n, 0);
|
||||||
|
mt.waitForID(0);
|
||||||
|
}
|
||||||
|
catch (InterruptedException eIt) {
|
||||||
|
assert false;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Blocks until the image loads. We have to do this because
|
||||||
|
* there is an unfixed JDK bug in Image#getScaledInstance
|
||||||
|
* (which RoundButton uses) where when you pass it an AWT
|
||||||
|
* image, it incorrectly sets the ColorModel's transfer type,
|
||||||
|
* causing a ClassCastException, and returns a valid image
|
||||||
|
* with blank data. It seems using loaded images does not
|
||||||
|
* replicate the issue, which would explain why the bug
|
||||||
|
* hasn't been found and fixed..
|
||||||
|
*
|
||||||
|
* For future readers wondering. JDK 11, up to JDK 15.
|
||||||
|
* java.awt.image.ColorModel#getAlpha(:845), who was called
|
||||||
|
* sun.awt.image.ImageRepresentation#convertToRGB, who was
|
||||||
|
* called by AreaAveragingScaleFilter trying to #setPixels.
|
||||||
|
* Cause RoundButton was using Image.SCALE_SMOOTH.
|
||||||
|
*
|
||||||
|
* I guess it kind of makes sense, why would I try to get a
|
||||||
|
* scaled instance of an image that hadn't finished loading.
|
||||||
|
* An intelligent class would render the awt.Image as-is until
|
||||||
|
* it has completely loaded, then call #getScaledInstance
|
||||||
|
* instead. I won't have RoundButton do that for now, as
|
||||||
|
* my other classes like RichTextPane3 might have this too.
|
||||||
|
*
|
||||||
|
* If you asked me how I'd generalise the solution. My
|
||||||
|
* expectation had been that #getScaledInstance waits for
|
||||||
|
* the image too, returning a null image until it's done.
|
||||||
|
* So I'd put a #getScaledInstance in ImageApi, which does
|
||||||
|
* this, using MediaTracker. That assumes what I'm doing
|
||||||
|
* right now definitely works.
|
||||||
|
*/
|
||||||
|
|
||||||
|
profile.setImage(n);
|
||||||
|
}
|
||||||
|
|
||||||
public void
|
public void
|
||||||
setDate(String n) { date.setText(n); }
|
setDate(String n) { date.setText(n); }
|
||||||
|
@ -39,7 +39,7 @@ implements
|
|||||||
layoutEnd, selStart, selEnd;
|
layoutEnd, selStart, selEnd;
|
||||||
|
|
||||||
private int
|
private int
|
||||||
startingLine, endingLine;
|
startingLine, lastLine;
|
||||||
|
|
||||||
// ---%-@-%---
|
// ---%-@-%---
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ implements
|
|||||||
startingLine = 1;
|
startingLine = 1;
|
||||||
layout(html, fm, cursor);
|
layout(html, fm, cursor);
|
||||||
layout.put(layoutEnd, cursor.clone());
|
layout.put(layoutEnd, cursor.clone());
|
||||||
endingLine = cursor.line;
|
lastLine = cursor.line;
|
||||||
repaint();
|
repaint();
|
||||||
|
|
||||||
int iy = fm.getAscent();
|
int iy = fm.getAscent();
|
||||||
@ -108,7 +108,7 @@ implements
|
|||||||
nextPage()
|
nextPage()
|
||||||
{
|
{
|
||||||
int advance = getHeightInLines();
|
int advance = getHeightInLines();
|
||||||
if (endingLine - startingLine < advance) return;
|
if (lastLine - startingLine < advance) return;
|
||||||
else startingLine += advance;
|
else startingLine += advance;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
@ -557,7 +557,7 @@ implements
|
|||||||
FontMetrics fm = getFontMetrics(getFont());
|
FontMetrics fm = getFontMetrics(getFont());
|
||||||
int initial = fm.getAscent();
|
int initial = fm.getAscent();
|
||||||
int advance = fm.getAscent() + fm.getDescent();
|
int advance = fm.getAscent() + fm.getDescent();
|
||||||
return isnap2(getHeight(), initial, advance);
|
return isnap2(getHeight(), initial, advance) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void
|
public void
|
||||||
|
@ -298,8 +298,6 @@ implements KeyListener, MouseListener, FocusListener {
|
|||||||
|
|
||||||
int ow = image.getWidth(this);
|
int ow = image.getWidth(this);
|
||||||
int oh = image.getHeight(this);
|
int oh = image.getHeight(this);
|
||||||
if (ow == -1) return;
|
|
||||||
|
|
||||||
int nx = 6;
|
int nx = 6;
|
||||||
int ny = 6;
|
int ny = 6;
|
||||||
int nw = button.getWidth(this) - 12;
|
int nw = button.getWidth(this) - 12;
|
||||||
@ -312,6 +310,8 @@ implements KeyListener, MouseListener, FocusListener {
|
|||||||
{
|
{
|
||||||
int sw = ow > oh ? -1 : nw;
|
int sw = ow > oh ? -1 : nw;
|
||||||
int sh = oh > ow ? -1 : nh;
|
int sh = oh > ow ? -1 : nh;
|
||||||
|
// We do not defend against unloaded images. There is
|
||||||
|
// a bug on those anyways, see comment in PostWindow.
|
||||||
scaled = image.getScaledInstance(
|
scaled = image.getScaledInstance(
|
||||||
sw, sh,
|
sw, sh,
|
||||||
Image.SCALE_SMOOTH
|
Image.SCALE_SMOOTH
|
||||||
|
Loading…
x
Reference in New Issue
Block a user