public void redrawTree(boolean doRepaint) { displayText = false; if (argument == null) return; if (argument.isMultiRoots()) { argument.deleteDummyRoot(); argument.setMultiRoots(false); } TreeVertex root = null; Vector roots = argument.getTree().getRoots(); if (roots.size() > 1) { if (argument.getDummyRoot() == null) { argument.addDummyRoot(roots); } root = argument.getDummyRoot(); } else if (roots.size() == 1) { root = (TreeVertex) roots.firstElement(); } // if root == null, the entire tree has been erased, // so call emptyTree() to clean things up and // clear the display if (root == null) { argument.emptyTree(false); } else { calcTreeShape(root); } if (doRepaint) { repaint(); } /* if (displayFrame.getMainDiagramPanel() == this) { searchFrame.updateDisplays(false); } */ }
public void mousePressed(MouseEvent e) { System.out.println("mousePressed"); Point1 p2; switch (toolFlag) { case 3: // 直线 x = (int) e.getX(); y = (int) e.getY(); p2 = new Point1(x, y, c, toolFlag, con); paintInfo.addElement(p2); break; case 4: // 圆 x = (int) e.getX(); y = (int) e.getY(); p2 = new Point1(x, y, c, toolFlag, con); paintInfo.addElement(p2); break; case 5: // 矩形 x = (int) e.getX(); y = (int) e.getY(); p2 = new Point1(x, y, c, toolFlag, con); paintInfo.addElement(p2); break; default: } }
static Point project(Line l, Point p) { Point p1 = l.getP1(); Point p2 = l.getP2(); Vector base = new Vector(p2, p1); double r = Vector.dot(new Vector(p, p1), base) / base.norm(); return base.scalarMul(r).plus(p1).toPoint(); }
public void paint(Graphics g) { System.out.println("paint"); Graphics2D g2d = (Graphics2D) g; Point1 p1, p2; n = paintInfo.size(); if (toolFlag == 2) g2d.clearRect(0, 0, getSize().width - 100, getSize().height - 100); // 清除 for (int i = 0; i < n - 1; i++) { p1 = (Point1) paintInfo.elementAt(i); p2 = (Point1) paintInfo.elementAt(i + 1); size = new BasicStroke(p1.boarder, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); g2d.setColor(p1.col); g2d.setStroke(size); if (p1.tool == p2.tool) { switch (p1.tool) { case 0: // 画笔 Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line1); break; case 1: // 橡皮 g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder); break; case 3: // 画直线 Line2D line2 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line2); break; case 4: // 画圆 Ellipse2D ellipse = new Ellipse2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); g2d.draw(ellipse); break; case 5: // 画矩形 Rectangle2D rect = new Rectangle2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); g2d.draw(rect); break; case 6: // 截断,跳过 i = i + 1; break; default: } // end switch } // end if } // end for }
/** * Fills a SubtreeFrame with info about the subtree. Used to display info when user right clicks * on an existing subtree. */ public void buildSubtreeFrame(SubtreeFrame sFrame) { // Clear visited flag on all vertices in the tree // and determine the layer number of the root node int highestLayer = 100; Enumeration edges = m_edgeList.elements(); while (edges.hasMoreElements()) { TreeEdge edge = (TreeEdge) edges.nextElement(); edge.getDestVertex().setVisited(false); edge.getSourceVertex().setVisited(false); if (edge.getSourceVertex().getLayer() < highestLayer) { highestLayer = edge.getSourceVertex().getLayer(); } } // Create list of premises and conclusion and assign // to text areas in the dialog Vector premiseList = new Vector(); String conclusion = ""; String criticalQuestions = ""; edges = m_edgeList.elements(); while (edges.hasMoreElements()) { TreeEdge edge = (TreeEdge) edges.nextElement(); TreeVertex source = edge.getSourceVertex(); TreeVertex dest = edge.getDestVertex(); if (!source.getVisited()) { if (source.getLayer() == highestLayer) { conclusion += (String) source.getLabel(); } else { premiseList.add((String) source.getLabel()); } source.setVisited(true); } if (!dest.getVisited()) { premiseList.add((String) dest.getLabel()); dest.setVisited(true); } } sFrame.setPremisesText(premiseList); sFrame.setConclusionText(conclusion); sFrame.loadArgTypeCombo(); // Assign the correct argument type to the combo box for (int index = 0; index < sFrame.selectArgumentCombo.getItemCount(); index++) { if (m_argumentType.getName().equals(sFrame.selectArgumentCombo.getItemAt(index))) { sFrame.selectArgumentCombo.setSelectedIndex(index); sFrame.selectArgumentCombo.setEditable(false); break; } } // Construct list of critical questions // Enumeration quesList = m_argumentType.getCriticalQuestions().elements(); // while (quesList.hasMoreElements()) { // criticalQuestions += (String)quesList.nextElement() + // "\r\n _____________________________ \r\n"; // } sFrame.updateTextBoxes(); }
protected void fireChangeListeners() { if (changeListeners == null) return; for (int a = 0; a < changeListeners.size(); a++) { ChangeListener l = (ChangeListener) changeListeners.get(a); try { l.stateChanged(new ChangeEvent(this)); } catch (RuntimeException e) { e.printStackTrace(); } } }
private void recurseSelectEdges(TreeVertex root) { Vector edges = root.getEdgeList(); for (int i = 0; i < edges.size(); i++) { TreeEdge edge = (TreeEdge) edges.elementAt(i); TreeVertex dest = edge.getDestVertex(); if (m_vertexList.contains(dest)) { edge.setSelected(true); recurseSelectEdges(dest); } } }
/** Determines if this subtree contains the given vertex */ public boolean containsTreeVertex(TreeVertex vertex) { if (vertex == null) return false; for (int i = 0; i < m_vertexList.size(); i++) { if ((TreeVertex) m_vertexList.elementAt(i) == vertex) return true; } for (int i = 0; i < m_edgeList.size(); i++) { TreeEdge edge = (TreeEdge) m_edgeList.elementAt(i); if (edge.getSourceVertex() == vertex || edge.getDestVertex() == vertex) { return true; } } return false; }
public TreeVertex findRoot() { if (m_root != null) return m_root; int rootLayer = 1000; TreeVertex root = null; for (int i = 0; i < m_vertexList.size(); i++) { TreeVertex vertex = (TreeVertex) m_vertexList.elementAt(i); if (vertex.getLayer() < rootLayer) { rootLayer = vertex.getLayer(); root = vertex; } } return root; }
/** * Build a shape for the entire subtree by joining together the shapes for each of its edges. * Vertices included since needed for FullTextPanel. */ public Shape constructInternalShape(DiagramBase diagram, boolean includeVertices) { GeneralPath shape = new GeneralPath(); Enumeration edges = m_edgeList.elements(); while (edges.hasMoreElements()) { TreeEdge edge = (TreeEdge) edges.nextElement(); Shape edgeShape = edge.getSchemeShape(diagram); PathIterator path = edgeShape.getPathIterator(null); shape.append(path, false); if (includeVertices) { Shape vertexShape; if (!edge.getSourceVertex().isVirtual()) { vertexShape = edge.getSourceVertex().getShape(diagram); path = vertexShape.getPathIterator(null); shape.append(path, false); } if (!edge.getDestVertex().isVirtual()) { vertexShape = edge.getDestVertex().getShape(diagram); path = vertexShape.getPathIterator(null); shape.append(path, false); } } } BasicStroke stroke = new BasicStroke( diagram.getSubtreeLineWidth() - DiagramBase.EDGE_OUTLINE_WIDTH + 1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER); internalShapeTable.put(diagram, stroke.createStrokedShape(shape)); return (Shape) internalShapeTable.get(diagram); }
public String getInfo() { String info = "Edges: "; Enumeration edges = m_edgeList.elements(); while (edges.hasMoreElements()) { TreeEdge edge = (TreeEdge) edges.nextElement(); info += edge.getSourceVertex().getLabel() + " => " + edge.getDestVertex().getLabel() + "; "; } return info; }
public void mouseDragged(MouseEvent e) { System.out.println("mouseDragged"); Point1 p1; switch (toolFlag) { case 0: // 画笔 x = (int) e.getX(); y = (int) e.getY(); p1 = new Point1(x, y, c, toolFlag, con); paintInfo.addElement(p1); repaint(); break; case 1: // 橡皮 x = (int) e.getX(); y = (int) e.getY(); p1 = new Point1(x, y, null, toolFlag, Econ); paintInfo.addElement(p1); repaint(); break; default: } }
/** Build a shape for the entire subtree by joining together the shapes for each of its edges. */ public Shape constructShape(DiagramBase diagram) { GeneralPath shape = new GeneralPath(); Enumeration edges = m_edgeList.elements(); while (edges.hasMoreElements()) { TreeEdge edge = (TreeEdge) edges.nextElement(); if (!edge.visible) { continue; } Shape edgeShape = edge.getSchemeShape(diagram); PathIterator path = edgeShape.getPathIterator(null); shape.append(path, false); } BasicStroke stroke = new BasicStroke( diagram.getSubtreeLineWidth(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER); shapeTable.put(diagram, stroke.createStrokedShape(shape)); return (Shape) shapeTable.get(diagram); }
public void mouseReleased(MouseEvent e) { System.out.println("mouseReleased"); Point1 p3; switch (toolFlag) { case 0: // 画笔 paintInfo.addElement(cutflag); break; case 1: // eraser paintInfo.addElement(cutflag); break; case 3: // 直线 x = (int) e.getX(); y = (int) e.getY(); p3 = new Point1(x, y, c, toolFlag, con); paintInfo.addElement(p3); paintInfo.addElement(cutflag); repaint(); break; case 4: // 圆 x = (int) e.getX(); y = (int) e.getY(); p3 = new Point1(x, y, c, toolFlag, con); paintInfo.addElement(p3); paintInfo.addElement(cutflag); repaint(); break; case 5: // 矩形 x = (int) e.getX(); y = (int) e.getY(); p3 = new Point1(x, y, c, toolFlag, con); paintInfo.addElement(p3); paintInfo.addElement(cutflag); repaint(); break; default: } }
/** Build a shape for the entire subtree by joining together the shapes for each of its edges. */ public Shape constructFullTextShape(DiagramBase diagram) { GeneralPath shape = new GeneralPath(); Enumeration edges = m_edgeList.elements(); while (edges.hasMoreElements()) { TreeEdge edge = (TreeEdge) edges.nextElement(); if (!edge.visible) { continue; } Shape edgeShape = edge.getSchemeShape(diagram); PathIterator path = edgeShape.getPathIterator(null); shape.append(path, false); TreeVertex vertex = edge.getSourceVertex(); if (!vertex.isVirtual()) { shape.append(vertex.getShape(diagram).getPathIterator(null), false); } vertex = edge.getDestVertex(); if (!vertex.isVirtual()) { shape.append(vertex.getShape(diagram).getPathIterator(null), false); } } BasicStroke stroke = new BasicStroke(20, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER); shapeTable.put(diagram, stroke.createStrokedShape(shape)); return (Shape) shapeTable.get(diagram); }
/** @deprecated replaced by ImagePlus.getOverlay() */ public Vector getDisplayList() { if (overlay == null) return null; Vector displayList = new Vector(); for (int i = 0; i < overlay.size(); i++) displayList.add(overlay.get(i)); return displayList; }
public void addNewEdge() { if (!canCreateEdge) { // refreshDisplay(); return; } canCreateEdge = false; Vector vertexList = argument.getTree().getVertexList(); boolean addNewEdge = false; if (!vertexList.contains(startVertex)) { addNewEdge = true; argument.getTree().addVertex(startVertex); argument.getFreeVertexList().remove(startVertex); } if (!vertexList.contains(endVertex)) { addNewEdge = true; argument.getTree().addVertex(endVertex); argument.getFreeVertexList().remove(endVertex); } if (addNewEdge) { argument.getTree().addEdge(endVertex, startVertex); // If addNewEdge is true here, either or both vertexes are new // to the tree, so new edge must be OK startVertex.setHasParent(true); calcSubtreeShapes(); displayFrame.controlFrame.updateDisplays(true); // displayFrame.controlFrame.getUndoStack().push(new // EditAction(displayFrame.controlFrame, "adding a support")); } // If reach this far, tree already contains both vertices. // No need to check if edge already exists since have checked if // vertex has a parent. Just need to check if new edge creates a // cycle. If it does, we delete the edge we just added. if (argument.isMultiRoots()) { argument.deleteDummyRoot(); argument.setMultiRoots(false); } argument.getTree().addEdge(endVertex, startVertex); startVertex.setHasParent(true); TreeVertex root; Vector roots = argument.getTree().getRoots(); if (roots.size() == 0) { deleteCycle(startVertex, endVertex); return; } if (roots.size() > 1) { argument.addDummyRoot(roots); root = argument.getDummyRoot(); } else { root = (TreeVertex) roots.firstElement(); } try { argument.getTree().breadthFirstTopSort(root); } catch (GraphException e) { deleteCycle(startVertex, endVertex); return; } // If we survive the cycle test, the edge is OK. redrawTree(true); }
/** Returns the number of edges in the subtree */ public int getNumberOfEdges() { return m_edgeList.size(); }
/** * Remove a <code>ChangeListener</code> so it is no longer notified when the selected color * changes. */ public void removeChangeListener(ChangeListener l) { if (changeListeners == null) return; changeListeners.remove(l); }
/** * This listener will be notified when the current HSB or RGB values change, depending on what * mode the user is in. */ public void addChangeListener(ChangeListener l) { if (changeListeners == null) changeListeners = new Vector(); if (changeListeners.contains(l)) return; changeListeners.add(l); }
public static double dot(Vector a, Vector b) { return a.getX() * b.getX() + a.getY() * b.getY(); }
public static double cross(Vector a, Vector b) { return a.getX() * b.getY() - a.getY() * b.getX(); }
/** Deletes edge from m_edgeList. Returns true if edge found and deleted, false otherwise */ public boolean deleteEdge(TreeEdge edge) { return m_edgeList.remove(edge); }
public void addEdge(TreeEdge edge) { m_edgeList.add(edge); }
public void actionPerformed(ActionEvent e) { System.out.println("actionPerformed"); if (e.getSource() == pen) // 画笔 { System.out.println("pen"); toolFlag = 0; } if (e.getSource() == eraser) // 橡皮 { System.out.println("eraser"); toolFlag = 1; } if (e.getSource() == clear) // 清除 { System.out.println("clear"); toolFlag = 2; paintInfo.removeAllElements(); repaint(); } if (e.getSource() == drLine) // 画线 { System.out.println("drLine"); toolFlag = 3; } if (e.getSource() == drCircle) // 画圆 { System.out.println("drCircle"); toolFlag = 4; } if (e.getSource() == drRect) // 画矩形 { System.out.println("drRect"); toolFlag = 5; } if (e.getSource() == colchooser) // 调色板 { System.out.println("colchooser"); Color newColor = JColorChooser.showDialog(this, "我的调色板", c); c = newColor; } if (e.getSource() == openPic) // 打开图画 { openPicture.setVisible(true); if (openPicture.getFile() != null) { int tempflag; tempflag = toolFlag; toolFlag = 2; repaint(); try { paintInfo.removeAllElements(); File filein = new File(openPicture.getDirectory(), openPicture.getFile()); picIn = new FileInputStream(filein); VIn = new ObjectInputStream(picIn); paintInfo = (Vector) VIn.readObject(); VIn.close(); repaint(); toolFlag = tempflag; } catch (ClassNotFoundException IOe2) { repaint(); toolFlag = tempflag; System.out.println("can not read object"); } catch (IOException IOe) { repaint(); toolFlag = tempflag; System.out.println("can not read file"); } } } if (e.getSource() == savePic) // 保存图画 { savePicture.setVisible(true); try { File fileout = new File(savePicture.getDirectory(), savePicture.getFile()); picOut = new FileOutputStream(fileout); VOut = new ObjectOutputStream(picOut); VOut.writeObject(paintInfo); VOut.close(); } catch (IOException IOe) { System.out.println("can not write object"); } } }
/** Updates the FancyShape. */ void update() { // don't update warning regions here, do it in GraphArea... if (getNeedsUpdate()) { if (lightSource == TOP) { paint = new GradientPaint( lightBounds.x, lightBounds.y, color.brighter(), lightBounds.x, lightBounds.y + lightBounds.height, color); if (outlineExistence) { outlinePaint = new GradientPaint( lightBounds.x, lightBounds.y, outlineColor.brighter(), lightBounds.x, lightBounds.y + lightBounds.height, outlineColor); } warningPaints.removeAllElements(); if (warningRegions != null) { for (int i = 0; i < warningRegions.size(); ++i) { Color warningColor = ((WarningRegion) warningRegions.get(i)).getComponentColor(); warningPaints.add( new GradientPaint( lightBounds.x, lightBounds.y, warningColor.brighter(), lightBounds.x, lightBounds.y + lightBounds.height, warningColor)); } } } else if (lightSource == BOTTOM) { paint = new GradientPaint( lightBounds.x, lightBounds.y, color, lightBounds.x, lightBounds.y + lightBounds.height, color.brighter()); if (outlineExistence) { outlinePaint = new GradientPaint( lightBounds.x, lightBounds.y, outlineColor, lightBounds.x, lightBounds.y + lightBounds.height, outlineColor.brighter()); } warningPaints.removeAllElements(); for (int i = 0; i < warningRegions.size(); ++i) { Color warningColor = ((WarningRegion) warningRegions.get(i)).getComponentColor(); warningPaints.add( new GradientPaint( lightBounds.x, lightBounds.y, warningColor, lightBounds.x, lightBounds.y + lightBounds.height, warningColor.brighter())); } } else if (lightSource == LEFT) { paint = new GradientPaint( lightBounds.x, lightBounds.y, color.brighter(), lightBounds.x + lightBounds.width, lightBounds.y, color); if (outlineExistence) { outlinePaint = new GradientPaint( lightBounds.x, lightBounds.y, outlineColor.brighter(), lightBounds.x + lightBounds.width, lightBounds.y, outlineColor); } warningPaints.removeAllElements(); if (warningRegions != null) { for (int i = 0; i < warningRegions.size(); ++i) { Color warningColor = ((WarningRegion) warningRegions.get(i)).getComponentColor(); warningPaints.add( new GradientPaint( lightBounds.x, lightBounds.y, warningColor.brighter(), lightBounds.x + lightBounds.width, lightBounds.y, warningColor)); } } } else if (lightSource == RIGHT) { paint = new GradientPaint( lightBounds.x, lightBounds.y, color, lightBounds.x + lightBounds.width, lightBounds.y, color.brighter()); if (outlineExistence) { outlinePaint = new GradientPaint( lightBounds.x, lightBounds.y, outlineColor, lightBounds.x + lightBounds.width, lightBounds.y, outlineColor.brighter()); } warningPaints.removeAllElements(); if (warningRegions != null) { for (int i = 0; i < warningRegions.size(); ++i) { Color warningColor = ((WarningRegion) warningRegions.get(i)).getComponentColor(); warningPaints.add( new GradientPaint( lightBounds.x, lightBounds.y, warningColor, lightBounds.x + lightBounds.width, lightBounds.y, warningColor.brighter())); } } } else { paint = color; outlinePaint = outlineColor; warningPaints.removeAllElements(); if (warningRegions != null) { for (int i = 0; i < warningRegions.size(); ++i) { Color warningColor = ((WarningRegion) warningRegions.get(i)).getComponentColor(); warningPaints.add(warningColor); } } } needsUpdate = false; } }
public void addVertex(TreeVertex vertex) { m_vertexList.add(vertex); }