Revision 532
fixed NPE in client
Colonet.java | ||
---|---|---|
964 | 964 |
* original size of the image that the panel contains. |
965 | 965 |
*/ |
966 | 966 |
public Point convertClick (MouseEvent e) { |
967 |
if (img == null) { |
|
968 |
return new Point(e.getX(), e.getY()); |
|
969 |
} |
|
970 |
|
|
967 | 971 |
// Calculate scaling |
968 | 972 |
int clickx = e.getX(); |
969 |
int clicky = e.getY();
|
|
973 |
int clicky = e.getY(); |
|
970 | 974 |
int maxWidth = getWidth() - 2*BORDER; |
971 | 975 |
int maxHeight = getHeight() - 2*BORDER; |
972 | 976 |
double widthRatio = 1.0 * maxWidth / img.getWidth(); |
... | ... | |
978 | 982 |
int py = 0; |
979 | 983 |
|
980 | 984 |
if (widthRatio > heightRatio) { //height is the limiting factor |
981 |
scale = heightRatio;
|
|
982 |
newHeight = maxHeight;
|
|
983 |
newWidth = (int) (img.getWidth() * scale);
|
|
984 |
py = clicky - BORDER;
|
|
985 |
px = clickx - BORDER - (maxWidth - newWidth) / 2;
|
|
986 |
py *= scale;
|
|
987 |
px *= scale;
|
|
985 |
scale = heightRatio; |
|
986 |
newHeight = maxHeight; |
|
987 |
newWidth = (int) (img.getWidth() * scale); |
|
988 |
py = clicky - BORDER; |
|
989 |
px = clickx - BORDER - (maxWidth - newWidth) / 2; |
|
990 |
py *= scale; |
|
991 |
px *= scale; |
|
988 | 992 |
} else { //width is the limiting factor |
989 |
scale = widthRatio;
|
|
990 |
newWidth = maxWidth;
|
|
991 |
newHeight = (int) (img.getHeight() * scale);
|
|
992 |
px = clickx - BORDER;
|
|
993 |
py = clicky - BORDER - (maxHeight - newHeight) / 2;
|
|
994 |
px *= scale;
|
|
995 |
py *= scale;
|
|
993 |
scale = widthRatio; |
|
994 |
newWidth = maxWidth; |
|
995 |
newHeight = (int) (img.getHeight() * scale); |
|
996 |
px = clickx - BORDER; |
|
997 |
py = clicky - BORDER - (maxHeight - newHeight) / 2; |
|
998 |
px *= scale; |
|
999 |
py *= scale; |
|
996 | 1000 |
} |
997 | 1001 |
|
998 |
return new Point(px, py); |
|
999 |
|
|
1002 |
return new Point(px, py); |
|
1000 | 1003 |
} |
1001 |
|
|
1002 | 1004 |
} |
1003 | 1005 |
|
1004 | 1006 |
/* |
Also available in: Unified diff