Skip to content

Commit

Permalink
Version 1.5. Updated libraries to latest versions. Removed potential …
Browse files Browse the repository at this point in the history
…NULL pointer exceptions. Improved "MISSING IMAGE" image.

- fixed a polygon point drag and drop issue in ObjectTreeDropTargetListener.java
  drop() method
- added drawMissingAttributes() to GraphicObjectOperations.java
- removed many potential NULL pointer exceptions
- refactored getMissingImage() out of exiting code and made some
  improvements
  • Loading branch information
moehman committed Nov 12, 2019
1 parent c9724f2 commit 697b42d
Show file tree
Hide file tree
Showing 10 changed files with 3,215 additions and 24 deletions.
Binary file modified lib/idw-gpl.jar
Binary file not shown.
Binary file modified lib/xercesImpl.jar
Binary file not shown.
Binary file modified lib/xml-apis.jar
Binary file not shown.
1,562 changes: 1,562 additions & 0 deletions library_export_emb.xml

Large diffs are not rendered by default.

1,552 changes: 1,552 additions & 0 deletions library_export_iso.xml

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions src/objecttree/ObjectTreeDropTargetListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,16 @@ else if (data instanceof StringReader) {
}
*/
}
// if parent is not a real object (or a command), user root instead
if (!otherNode.isType(OBJECTS) && !otherNode.getType().startsWith(COMMAND)) {
otherNode = (XMLTreeNode) otherNode.getModel().getRoot();
asSibling = false;
}

// if parent is not a real object (or a command), user root instead
if (!otherNode.isType(OBJECTS) &&
!otherNode.isType(POINT) &&
!otherNode.getType().startsWith(COMMAND))
{
//System.out.println("SUBSTITUTING: " + otherNode);
otherNode = (XMLTreeNode) otherNode.getModel().getRoot();
asSibling = false;
}

Document doc = otherNode.getModel().getDocument();

Expand Down
51 changes: 50 additions & 1 deletion src/objectview/GraphicObjectOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ public boolean getFlash() {
return this.flash;
}

private void drawMissingAttributes(Graphics2D gfx, int w, int h) {
gfx.setColor(Color.RED);
gfx.fillRect(0, 0, w, h);
gfx.setColor(Color.YELLOW);
gfx.drawLine(0, 0, w, h);
gfx.drawLine(0, h, w, 0);
}

/**
* Draws borders.
* @param gfx
Expand Down Expand Up @@ -273,6 +281,12 @@ public void opButton(Graphics2D gfx, XMLTreeNode node) {
public void opInputBoolean(Graphics2D gfx, XMLTreeNode node) {
int w = node.getWidth();

XMLTreeNode fas = node.getFontAttributes();
if (fas == null) {
drawMissingAttributes(gfx, w, w);
drawBorders(gfx, w, w);
return;
}
// fill background
if (!node.isOptionsTransparent()) {
gfx.setColor(node.getBackgroundColor(colorDepth));
Expand All @@ -281,7 +295,7 @@ public void opInputBoolean(Graphics2D gfx, XMLTreeNode node) {

// paint mark (V)
if (node.getEffectiveValue() != 0) {
gfx.setColor(node.getFontAttributes().getFontColor(colorDepth));
gfx.setColor(fas.getFontColor(colorDepth));
gfx.fillPolygon(new int[] {w / 8, w / 10, w / 2, w - w / 10, w - w / 8, w / 2},
new int[] {w / 10, w / 8, w - w / 8, w / 8, w / 10, w / 2}, 6);
}
Expand All @@ -295,6 +309,11 @@ public void opInputString(Graphics2D gfx, XMLTreeNode node) throws IOException {
int h = node.getHeight();

XMLTreeNode fas = node.getFontAttributes();
if (fas == null) {
drawMissingAttributes(gfx, w, h);
drawBorders(gfx, w, h);
return;
}
BitmapFont font = fas.getFont(colorDepth);
Color backgroundColor = node.getBackgroundColor(colorDepth);

Expand Down Expand Up @@ -332,6 +351,11 @@ public void opInputNumber(Graphics2D gfx, XMLTreeNode node) throws IOException {
int h = node.getHeight();

XMLTreeNode fas = node.getFontAttributes();
if (fas == null) {
drawMissingAttributes(gfx, w, h);
drawBorders(gfx, w, h);
return;
}
BitmapFont font = fas.getFont(colorDepth);
Color backgroundColor = node.getBackgroundColor(colorDepth);

Expand Down Expand Up @@ -399,6 +423,11 @@ public void opOutputString(Graphics2D gfx, XMLTreeNode node) throws IOException
int h = node.getHeight();

XMLTreeNode fas = node.getFontAttributes();
if (fas == null) {
drawMissingAttributes(gfx, w, h);
drawBorders(gfx, w, h);
return;
}
BitmapFont font = fas.getFont(colorDepth);
Color backgroundColor = node.getBackgroundColor(colorDepth);

Expand Down Expand Up @@ -439,6 +468,11 @@ public void opOutputNumber(Graphics2D gfx, XMLTreeNode node) throws IOException
int h = node.getHeight();

XMLTreeNode fas = node.getFontAttributes();
if (fas == null) {
drawMissingAttributes(gfx, w, h);
drawBorders(gfx, w, h);
return;
}
BitmapFont font = fas.getFont(colorDepth);
Color backgroundColor = node.getBackgroundColor(colorDepth);

Expand Down Expand Up @@ -531,6 +565,11 @@ public void opRectangle(Graphics2D gfx, XMLTreeNode node, String imagepath) thro
int h = node.getHeight();

LineAttributes latt = node.getLineAttributes(colorDepth);
if (latt == null) {
drawMissingAttributes(gfx, w, h);
drawBorders(gfx, w, h);
return;
}
Paint paint = node.getFillAttributesPaint(latt.getColor(), imagepath, PAINT, reduceImages, colorDepth);

// fill rectangle
Expand Down Expand Up @@ -584,6 +623,11 @@ public void opEllipse(Graphics2D gfx, XMLTreeNode node, String imagepath) throws
Integer ellipseType = node.getEllipseType();

LineAttributes latt = node.getLineAttributes(colorDepth);
if (latt == null) {
drawMissingAttributes(gfx, w, h);
drawBorders(gfx, w, h);
return;
}
Paint paint = node.getFillAttributesPaint(latt.getColor(), imagepath, PAINT, reduceImages, colorDepth);

float lw = ((BasicStroke) gfx.getStroke()).getLineWidth();
Expand Down Expand Up @@ -636,6 +680,11 @@ public void opPolygon(Graphics2D gfx, XMLTreeNode node, String imagepath) throws
int h = node.getHeight();

LineAttributes latt = node.getLineAttributes(colorDepth);
if (latt == null) {
drawMissingAttributes(gfx, w, h);
drawBorders(gfx, w, h);
return;
}
Paint paint = node.getFillAttributesPaint(latt.getColor(), imagepath, PAINT, reduceImages, colorDepth);
Polygon p = node.getPolygon();

Expand Down
3 changes: 2 additions & 1 deletion src/pooledit/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,8 @@ public static Element parseFragment(String text, Document doc) {
public static boolean insertFragment(Element fragment, Element actual,
Element link, boolean asSibling) {

// System.out.println("OTHER NODE: " + otherElement + ", ITS PARENT: " + otherElement.getParentNode());
//System.out.println("insertFragment(fragment: " + fragment + ", actual: "
// + actual + ", link: " + link + ", asSibling: " + asSibling + ")");
String trgName;
if (asSibling) {
Node parent;
Expand Down
7 changes: 6 additions & 1 deletion src/pooledit/TreeEditPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ public void actionPerformed(ActionEvent e) {
}
int length = value.length();
// we do not really care about the color palette (color reduction etc)
Dimension fontdim = node.getFontAttributes().getFont(ColorPalette.COLOR_8BIT).getDimension();
XMLTreeNode fas = node.getFontAttributes();
if (fas == null) {
System.err.println("*** NORMALIZING IS NOT POSSIBLE WITHOUT FONT ATTRIBUTES ***");
return;
}
Dimension fontdim = fas.getFont(ColorPalette.COLOR_8BIT).getDimension();
int width = fontdim.width * length;
int height = fontdim.height;
Element element = node.actual();
Expand Down
50 changes: 34 additions & 16 deletions src/treemodel/XMLTreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public void setLineDirection(boolean lineDirection) {

/**
* This method returns the value of the "actual_width" attribute.
* FIXME: this is never used, actual witdh is read from the file?
* FIXME: this is never used, actual width is read from the file?
* @return
*/
public Integer getActualWidth() {
Expand Down Expand Up @@ -664,29 +664,47 @@ private BufferedImage getImageFile(String imagepath) throws IOException {
return null;
}

/**
* Returns red image with yellow text saying "MISSING IMAGE".
* @return
*/
private BufferedImage getMissingImage() {
// the width is given as an attribute but without the image,
// the height is unknown (h = w * imageH / imageW)
int w = Math.max(40, getWidth());
int h = w * 40 / 64; // 64x40 drawing coordinates
double k = w / 64.0; // scaling factor
BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D gfx = (Graphics2D) img.getGraphics();
gfx.scale(k, k);
gfx.setColor(Color.YELLOW);
gfx.fillRect(0, 0, 64, 40);
gfx.setColor(Color.RED);
gfx.fillRect(1, 1, 62, 38);
gfx.setColor(Color.YELLOW);
gfx.drawString("MISSING", 7, 15);
gfx.drawString("IMAGE", 12, 35);
return img;
}

/**
* Reads the specified image from disk.
* @param fileAttr
* @param imagepath
* @return
* @throws IOException
*/
private BufferedImage getImageFile(String fileAttr, String imagepath) throws IOException {
String s = actual.getAttribute(fileAttr);
File f;
if (s.isEmpty()) {
return null;
}
try {
//all \ are converted to / on a unix system and vice versa
String fullname = FileTools.joinPaths(imagepath, s);
f = new File(fullname);
return ImageIO.read(f);
return ImageIO.read(new File(fullname));
}
catch (IOException ex) {
BufferedImage img = new BufferedImage(64, 40, BufferedImage.TYPE_INT_ARGB);
Graphics2D gfx = (Graphics2D) img.getGraphics();
gfx.setColor(Color.RED);
gfx.fillRect(0, 0, 64, 40);
gfx.setColor(Color.YELLOW);
gfx.drawRect(0, 0, 63, 39);
gfx.drawString("MISSING", 5, 15);
gfx.drawString("IMAGE", 5, 35);
return img;
//throw new IOException(ex.getMessage() + " " + f);
return getMissingImage();
}
}

Expand Down Expand Up @@ -1290,7 +1308,7 @@ public Integer getEffectiveTargetValue() {
/**
* Returns the size of this node.For example the size of a container
* is obtained by calling getWidth() and getHeight() methods, but the
* size of a meter is its width times width.The sizes of picture graphic
* size of a meter is its width times width. The sizes of picture graphic
* and object pointer objects are more difficult to calculate.
* @param dim
* @return
Expand Down

0 comments on commit 697b42d

Please sign in to comment.