public void drawCluster(Cluster cluster) { int index = clusters.indexOf(cluster); if (index != -1) { cluster.y = maxY; cluster.x = minX + index * factor; if (cluster.size() > 1) g.setColor(Color.RED); else g.setColor(Color.BLACK); g.drawRect(cluster.x - 1, cluster.y - cluster.size(), 2, 1 + cluster.size()); } else { Cluster left = cluster.getLeft(); Cluster right = cluster.getRight(); drawCluster(left); drawCluster(right); int yBar = minY + (int) ((maxY - minY) * (cluster.getSimilarity() / threshold)); g.setColor(Color.DARK_GRAY); if (left.y > yBar) { g.drawLine(left.x, left.y - 1, left.x, yBar); writeMap(left, yBar); } if (right.y > yBar) { g.drawLine(right.x, right.y - 1, right.x, yBar); writeMap(right, yBar); } g.setColor(Color.BLACK); g.drawLine(left.x, yBar, right.x, yBar); cluster.x = (right.x + left.x) / 2; cluster.y = yBar; } }
@Override public void mouseDragged(MouseEvent e) { mouseX = e.getX(); mouseY = e.getY(); if (dragMoveButton.isChecked()) { if (structureBeingMoved) { int x = Math.min(Main.canvasWidth - 11, Math.max(10, e.getX())); int y = Math.min(Main.canvasHeight - 45, Math.max(45, e.getY())); if (selectedNeuron != null) { selectedNeuron.x = x; selectedNeuron.y = y; } else if (selectedCluster != null) { selectedCluster.x = x; selectedCluster.y = y; } redraw = true; } } else if (dragDeleteButton.isChecked()) { for (int i = 0; i < neurons.size(); i++) if (neurons.get(i).collides(mouseX, mouseY)) { neurons.get(i).delete(); i--; } for (int i = 0; i < inputs.size(); i++) if (inputs.get(i).collides(mouseX, mouseY)) { inputs.get(i).delete(); i--; } for (int i = 0; i < outputs.size(); i++) if (outputs.get(i).collides(mouseX, mouseY)) { outputs.get(i).delete(); i--; } for (int i = 0; i < clusters.size(); i++) if (clusters.get(i).collides(mouseX, mouseY)) { clusters.get(i).delete(); i--; } } }