Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make XStream more agreeable, and other fixes #4067

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/net/rptools/lib/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import net.rptools.maptool.client.ui.token.BarTokenOverlay;
import net.rptools.maptool.model.AStarCellPointConverter;
import net.rptools.maptool.model.ShapeType;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -508,6 +510,8 @@ public static XStream getConfiguredXStream() {
XStream.setupDefaultSecurity(xStream);
xStream.allowTypesByWildcard(new String[] {"net.rptools.**", "java.awt.**", "sun.awt.**"});
xStream.registerConverter(new AStarCellPointConverter());
xStream.addImmutableType(ShapeType.class, true);
xStream.addImmutableType(BarTokenOverlay.Side.class, true);
return xStream;
}
}
1 change: 1 addition & 0 deletions src/main/java/net/rptools/maptool/client/MapTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public static String generateMessage(String msgKey, Throwable t) {
} else {
msg = I18N.getText(msgKey) + "<br/>" + t.toString();
}
msg = msg.replace("\n", "<br/>");
return msg;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,9 @@ public Object readResolve() {
if (toolTip == null) {
toolTip = "";
}
if (saveLocation == null) {
saveLocation = "";
}
return this;
}

Expand Down
21 changes: 13 additions & 8 deletions src/main/java/net/rptools/maptool/model/drawing/LineSegment.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.awt.geom.GeneralPath;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import net.rptools.maptool.model.GUID;
import net.rptools.maptool.server.Mapper;
import net.rptools.maptool.server.proto.drawing.DrawableDto;
Expand All @@ -33,7 +34,7 @@
*/
public class LineSegment extends AbstractDrawing {
private final List<Point> points = new ArrayList<Point>();
private Float width;
private @Nonnull Float width;
private boolean squareCap;
private transient int lastPointCount = -1;
private transient Rectangle cachedBounds;
Expand All @@ -50,6 +51,15 @@ public LineSegment(GUID id, float width, boolean squareCap) {
this.squareCap = squareCap;
}

@SuppressWarnings("ConstantValue")
private Object readResolve() {
if (width == null) {
width = 2.f;
}

return this;
}

/**
* Manipulate the points by calling {@link #getPoints} and then adding {@link Point} objects to
* the returned {@link List}.
Expand Down Expand Up @@ -95,17 +105,12 @@ private Area createLineArea() {
}
gp.lineTo(point.x, point.y);
}
BasicStroke stroke =
new BasicStroke(width != null ? width : 2, getStrokeCap(), getStrokeJoin());
BasicStroke stroke = new BasicStroke(width, getStrokeCap(), getStrokeJoin());
return new Area(stroke.createStrokedShape(gp));
}

@Override
protected void draw(Graphics2D g) {
if (width == null) {
// Handle legacy values
area = null; // reset, build with new value
}
width = ((BasicStroke) g.getStroke()).getLineWidth();
squareCap = ((BasicStroke) g.getStroke()).getEndCap() == BasicStroke.CAP_SQUARE;
Area area = getArea();
Expand Down Expand Up @@ -144,7 +149,7 @@ public Rectangle getBounds() {
return bounds;
}

public Float getWidth() {
public float getWidth() {
return width;
}

Expand Down