@Override public boolean equals(Object obj) { if (!(obj instanceof Cluster)) return false; if (obj == this) return true; if (obj == null) return false; return ((Cluster)obj).getName().equals(getName()); // String otherName = obj != null ? obj.toString() : ""; // return toString().equals(otherName); }
@Override public int hashCode() { return getName().hashCode(); }
public int getNameWidth(Graphics2D g, boolean includeNonLeafs) { int width = 0; if (includeNonLeafs || cluster.isLeaf()) { Rectangle2D rect = g.getFontMetrics().getStringBounds(cluster.getName(), g); width = (int)rect.getWidth(); } return width; }
public int getNameWidth(Graphics2D g, boolean includeNonLeafs) { int width = 0; if (includeNonLeafs || cluster.isLeaf()) { Rectangle2D rect = g.getFontMetrics().getStringBounds(cluster.getName().toString(), g); width = (int)rect.getWidth(); } return width; }
public int getNameWidth(Graphics2D g, boolean includeNonLeafs) { int width = 0; if (includeNonLeafs || cluster.isLeaf()) { Rectangle2D rect = g.getFontMetrics().getStringBounds(cluster.getName(), g); width = (int)rect.getWidth(); } return width; }
public void toConsole(int indent) { for (int i = 0; i < indent; i++) { System.out.print(" "); } String name = getName() + (isLeaf() ? " (leaf)" : "") + (distance != null ? " distance: " + distance : ""); System.out.println(name); for (Cluster child : getChildren()) { child.toConsole(indent + 1); } }
public void toConsole(int indent) { for (int i = 0; i < indent; i++) { System.out.print(" "); } String name = getName() + (isLeaf() ? " (leaf)" : "") + (distance != null ? " distance: " + distance : ""); System.out.println(name); for (Cluster child : getChildren()) { child.toConsole(indent + 1); } }
public void toConsole(int indent) { for (int i = 0; i < indent; i++) { System.out.print(" "); } String name = getName() + (isLeaf() ? " (leaf)" : "") + (distance != null ? " distance: " + distance : ""); System.out.println(name); for (Cluster child : getChildren()) { child.toConsole(indent + 1); } }
private ArrayList<String> getNameInCluster(Cluster cluster) { ArrayList<String> itemsInCluster = new ArrayList<String>(); String nodeName; if (cluster.isLeaf()) { nodeName = cluster.getName(); itemsInCluster.add(nodeName); } else { // String[] clusterName = cluster.getName().split("#"); // nodeName = clusterName[1]; } for (Cluster child : cluster.getChildren()) { ArrayList<String> childrenNames = getNameInCluster(child); itemsInCluster.addAll(childrenNames); } return itemsInCluster; }
public Cluster agglomerate(String name) { if (name == null) { StringBuilder sb = new StringBuilder(); if (lCluster != null) { sb.append(lCluster.getName()); } if (rCluster != null) { if (sb.length() > 0) { sb.append("&"); } sb.append(rCluster.getName()); } name = sb.toString(); } Cluster cluster = new Cluster(name); cluster.setDistance(getLinkageDistance()); cluster.addChild(lCluster); cluster.addChild(rCluster); lCluster.setParent(cluster); rCluster.setParent(cluster); return cluster; }
@Override public void paint(Graphics2D g, int xDisplayOffset, int yDisplayOffset, double xDisplayFactor, double yDisplayFactor, boolean decorated) { int x1, y1, x2, y2; FontMetrics fontMetrics = g.getFontMetrics(); x1 = (int)(initPoint.getX() * xDisplayFactor + xDisplayOffset); y1 = (int)(initPoint.getY() * yDisplayFactor + yDisplayOffset); x2 = (int)(linkPoint.getX() * xDisplayFactor + xDisplayOffset); y2 = y1; g.fillOval(x1-dotRadius, y1-dotRadius, dotRadius * 2, dotRadius * 2); g.drawLine(x1, y1, x2, y2); if (cluster.isLeaf()) { g.drawString(cluster.getName().toString(), x1 + namePadding, y1 + (fontMetrics.getHeight()/2) - 2); } if (decorated && cluster.getDistance() != null && !cluster.getDistance().isNaN() && cluster.getDistance() > 0) { String s = String.format("%.2f", cluster.getDistance()); Rectangle2D rect = fontMetrics.getStringBounds(s, g); g.drawString(s, x1 - (int)rect.getWidth() , y1 - 2); } x1 = x2; y1 = y2; y2 = (int)(linkPoint.getY() * yDisplayFactor + yDisplayOffset); g.drawLine(x1, y1, x2, y2); for (ClusterComponent child : children) { child.paint(g, xDisplayOffset, yDisplayOffset, xDisplayFactor, yDisplayFactor, decorated); } }
@Override public void paint(Graphics2D g, int xDisplayOffset, int yDisplayOffset, double xDisplayFactor, double yDisplayFactor, boolean decorated) { int x1, y1, x2, y2; FontMetrics fontMetrics = g.getFontMetrics(); x1 = (int)(initPoint.getX() * xDisplayFactor + xDisplayOffset); y1 = (int)(initPoint.getY() * yDisplayFactor + yDisplayOffset); x2 = (int)(linkPoint.getX() * xDisplayFactor + xDisplayOffset); y2 = y1; g.fillOval(x1-dotRadius, y1-dotRadius, dotRadius * 2, dotRadius * 2); g.drawLine(x1, y1, x2, y2); if (cluster.isLeaf()) { g.drawString(cluster.getName(), x1 + namePadding, y1 + (fontMetrics.getHeight()/2) - 2); } if (decorated && cluster.getDistance() != null && !cluster.getDistance().isNaN() && cluster.getDistance().getDistance() > 0) { String s = String.format("%.2f", cluster.getDistance()); Rectangle2D rect = fontMetrics.getStringBounds(s, g); g.drawString(s, x1 - (int)rect.getWidth() , y1 - 2); } x1 = x2; y1 = y2; y2 = (int)(linkPoint.getY() * yDisplayFactor + yDisplayOffset); g.drawLine(x1, y1, x2, y2); for (ClusterComponent child : children) { child.paint(g, xDisplayOffset, yDisplayOffset, xDisplayFactor, yDisplayFactor, decorated); } }
cdtString+=getName();
cdtString+=getName();
@Override public void paint(Graphics2D g, int xDisplayOffset, int yDisplayOffset, double xDisplayFactor, double yDisplayFactor, boolean decorated) { int x1, y1, x2, y2; FontMetrics fontMetrics = g.getFontMetrics(); x1 = (int)(initPoint.getX() * xDisplayFactor + xDisplayOffset); y1 = (int)(initPoint.getY() * yDisplayFactor + yDisplayOffset); x2 = (int)(linkPoint.getX() * xDisplayFactor + xDisplayOffset); y2 = y1; g.fillOval(x1-dotRadius, y1-dotRadius, dotRadius * 2, dotRadius * 2); g.drawLine(x1, y1, x2, y2); if (cluster.isLeaf()) { g.drawString(cluster.getName(), x1 + namePadding, y1 + (fontMetrics.getHeight()/2) - 2); } if (decorated && cluster.getDistance() != null && !cluster.getDistance().isNaN() && cluster.getDistance().getDistance() > 0) { String s = String.format("%.2f", cluster.getDistance()); Rectangle2D rect = fontMetrics.getStringBounds(s, g); g.drawString(s, x1 - (int)rect.getWidth() , y1 - 2); } x1 = x2; y1 = y2; y2 = (int)(linkPoint.getY() * yDisplayFactor + yDisplayOffset); g.drawLine(x1, y1, x2, y2); for (ClusterComponent child : children) { child.paint(g, xDisplayOffset, yDisplayOffset, xDisplayFactor, yDisplayFactor, decorated); } }