/** * 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 getLegend(String[] cityMap, int[] POIs) { char[] ans = new char[POIs.length]; Hashtable hash = new Hashtable(); for (int i = 0; i < cityMap.length; i++) { for (int j = 0; j < cityMap[i].length(); j++) { char cur = cityMap[i].charAt(j); int k = 1; if (!hash.containsKey(cur)) { hash.put(cur, k); } else { int prev = (int) hash.get(cur); hash.remove(cur); hash.put(cur, prev + 1); } } } Enumeration vals = hash.keys(); while (vals.hasMoreElements()) { char c = (char) vals.nextElement(); for (int i = 0; i < POIs.length; i++) { if (hash.get(c) == POIs[i]) { ans[i] = c; } } } String str = new String(ans); return str; }
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; }
/** * 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(); }
public void save(PrintStream stream) { saved = true; stream.println("<?xml version=\"1.0\"?>"); stream.println("<scale>"); stream.println(" <name>" + nameTF.getText() + "</name>"); for (Enumeration en = sp.notes.elements(); en.hasMoreElements(); ) { ScalePanel.Notik cur = (ScalePanel.Notik) en.nextElement(); stream.println(" <note>" + cur.n + "</note>"); } stream.println("</scale>"); }
/** 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); }
/** Draw vertices on top of the edge structure */ public void drawNodes(Graphics2D gg) { Enumeration nodeList = argument.getBreadthFirstTraversal().elements(); // Run through the traversal and draw each vertex // using an Ellipse2D // The draw point has been determined previously in // calcNodeCoords() while (nodeList.hasMoreElements()) { TreeVertex vertex = (TreeVertex) nodeList.nextElement(); // Don't draw virtual nodes if (vertex.isVirtual()) continue; // If tree is incomplete and we're on the top layer, skip it if (argument.isMultiRoots() && vertex.getLayer() == 0) continue; Point corner = vertex.getDrawPoint(); Shape node = new Ellipse2D.Float(corner.x, corner.y, NODE_DIAM, NODE_DIAM); vertex.setShape(node, this); // Fill the interior of the node with vertex's fillPaint gg.setPaint(vertex.fillPaint); gg.fill(node); // Draw the outline with vertex's outlinePaint; bold if selected gg.setPaint(vertex.outlinePaint); if (vertex.isSelected()) { gg.setStroke(selectStroke); } else { gg.setStroke(solidStroke); } gg.draw(node); // Draw the short label on top of the vertex gg.setPaint(vertex.textPaint); String shortLabelString = new String(vertex.getShortLabel()); if (shortLabelString.length() == 1) { gg.setFont(labelFont1); gg.drawString(shortLabelString, corner.x + NODE_DIAM / 4, corner.y + 3 * NODE_DIAM / 4); } else if (shortLabelString.length() == 2) { gg.setFont(labelFont2); gg.drawString(shortLabelString, corner.x + NODE_DIAM / 5, corner.y + 3 * NODE_DIAM / 4); } } }
/** Draws the edge structure of the tree */ public void drawEdges(Graphics2D gg) { gg.setPaint(Color.black); Enumeration nodeList = argument.getBreadthFirstTraversal().elements(); // For each vertex... while (nodeList.hasMoreElements()) { // Get its edge list... TreeVertex vertex = (TreeVertex) nodeList.nextElement(); Enumeration edges = vertex.getEdgeList().elements(); // For each edge in the list... while (edges.hasMoreElements()) { TreeEdge edge = (TreeEdge) edges.nextElement(); // If we have several vertices on layer 0, only draw // edges for layers below that if (!(argument.isMultiRoots() && vertex.getLayer() == 0)) { // If the edge has been selected with the mouse, // use a thick line if (edge.isSelected()) { gg.setStroke(selectStroke); } gg.draw(edge.getShape(this)); // If we used a thick line, reset the stroke to normal // line for next edge. if (edge.isSelected()) { gg.setStroke(solidStroke); } TreeVertex edgeSource = edge.getDestVertex(); } } } }
/** 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); }
/* * Creates a line of width EDGE_SELECT_WIDTH for each edge * and tests if mouse click was in that Shape's boundary. * Returns the edge if one was selected, null otherwise. */ public TreeEdge testEdgeShapes(MouseEvent event) { if (argument == null || argument.getTree() == null) return null; double x = event.getX(); double y = event.getY(); BasicStroke edgeWidth = new BasicStroke(EDGE_SELECT_WIDTH); if (argument.getBreadthFirstTraversal() == null) return null; Enumeration nodeList = argument.getBreadthFirstTraversal().elements(); while (nodeList.hasMoreElements()) { TreeVertex vertex = (TreeVertex) nodeList.nextElement(); if (argument.isMultiRoots() && vertex.getLayer() == 0) continue; Enumeration edges = vertex.getEdgeList().elements(); while (edges.hasMoreElements()) { TreeEdge edge = (TreeEdge) edges.nextElement(); Shape shape = edge.getShape(this); Shape wideEdge = edgeWidth.createStrokedShape(shape); TreeVertex child = edge.getDestVertex(); if (wideEdge.contains(x, y)) { edge.setSelected(!edge.isSelected()); return edge; } } } return null; }
public void handleNotification(INotification notification) { // Logger.debug("@ClientMediator.handleNotification:noti="+notification.getBody()); String noname = notification.getName(); if (noname == Const.TICK) { if (destroyd) return; long t = TimerCmd.timeStamp; String[] ary; int st, ed; if (_lastRotTank != null) { ary = _lastRotTank.split(" "); st = Integer.parseInt(ary[0]); ed = st + Integer.parseInt(ary[6]); if (t <= ed && t >= st) { int ist = Integer.parseInt(ary[0]); if (_move.size() > 0) { st = Integer.parseInt(_move.peek().split(" ")[0]); while (st < ist && _move.size() > 0) { _move.poll(); if (_move.size() == 0) break; st = Integer.parseInt(_move.peek().split(" ")[0]); } } } } if (_move.size() > 0) { ary = _move.peek().split(" "); st = Integer.parseInt(ary[0]); ed = st + Integer.parseInt(ary[8]); while ((t > ed) && _move.size() > 0) { // Logger.debug("@TankMediator.handleNotification: t = " + t + " st = " + st + " // ed="+ed); String p = (String) _move.poll(); Logger.debug("ClientMediator.TICK _move.poll=" + p); if (_move.size() == 0) break; ary = _move.peek().split(" "); st = Integer.parseInt(ary[0]); ed = st + Integer.parseInt(ary[8]); } if (_move.size() > 0) { String[] li = (String[]) _move.toArray(new String[0]); for (int i = li.length - 1; i >= 0; i--) { String s = li[i]; ary = s.split(" "); st = Integer.parseInt(ary[0]); ed = st + Integer.parseInt(ary[8]); if (t <= ed && t >= st) { if (t == st) { // ed==st in this situation _state.x = (int) Float.parseFloat(ary[4]); _state.y = (int) Float.parseFloat(ary[5]); _nextX = _state.x; _nextY = _state.y; } else { float sx = Float.parseFloat(ary[4]); float ex = Float.parseFloat(ary[6]); float sy = Float.parseFloat(ary[5]); float ey = Float.parseFloat(ary[7]); double eco = 1.0 * (t - st) / (ed - st); _state.x = (int) (sx + (ex - sx) * eco); _state.y = (int) (sy + (ey - sy) * eco); double neco = 1.0 * (t + 1 - st) / (ed - st); _nextX = (sx + (ex - sx) * neco); _nextY = (sy + (ey - sy) * neco); } while (_move.size() > 1) _move.poll(); break; } } } } if (_state != null) { ConcurrentHashMap<Integer, BulletState> bs = ((ServerBulletMediator) (appFacade().retrieveMediator(Const.SERVER_BULLET_MEDIATOR))) .getBullets(); for (Enumeration enu = bs.keys(); enu.hasMoreElements(); ) { int id = (Integer) enu.nextElement(); BulletState blt = bs.get(id); if (Texter.distance(blt.x, blt.y, _state.x, _state.y) < 16) { this.sendNotification(Const.BROAD_CAST, "destroy bullet " + id, null); _state.life -= 100; if (_state.life <= 0) { this.sendNotification(Const.BROAD_CAST, "destroy tank " + _state.tankID, null); } else { this.sendNotification( Const.BROAD_CAST, "set-life tank " + _state.tankID + " " + _state.life, null); } } } } // barrier and tank if (_state != null) { // colision detection // Logger.only("ClientMediator.handleNotification: x="+_state.x+" y="+_state.y+" // nx="+_nextX+" ny="+_nextY+" "+Texter.sqrareDis(_nextX, _nextY, 470, 200)+" // "+Texter.sqrareDis(_state.x, _state.y, 470, 200)); if (!Arena.canGo(_state.x, _state.y, _nextX, _nextY)) { Arena.addReq(_id, Const.STOP_MOVE, getState()); } for (Enumeration enu = AcceptCmd.clients.elements(); enu.hasMoreElements(); ) { ClientMediator cmm = (ClientMediator) enu.nextElement(); if (cmm.destroyd) return; int cmid = cmm.getID(); if (cmid == _id) continue; TankState ts = cmm.getState(); if (ts == null) continue; double curdis = Texter.distance(ts.x, ts.y, _state.x, _state.y); double netdis = Texter.distance(ts.x, ts.y, _nextX, _nextY); if (curdis < 40 && netdis < curdis) { Arena.addReq(_id, Const.STOP_MOVE, getState()); Arena.addReq(cmid, Const.STOP_MOVE, ts); } } } // handle delayed first // ary=_delayOrder.toArray(new String[0]); // _delayOrder.clear(); // for(int i=0;i<ary.length;i++){ // Logger.only("delayArray: "+ary[i]); // int ttt=Integer.parseInt(ary[i].split(" ")[0]); // if(ttt==t){ // tellClientWithTime(ary[i]); // }else if(ttt>t){ // _delayOrder.add(ary[i]); // } // } } else if (noname == Const.BROAD_CAST) { String s = (String) notification.getBody(); String ary[] = s.split(" "); if (notification.getType() == Const.NO_PREFIX) { tellClientWithTime(s); return; } else if (s.indexOf("talk") > -1) { tellClient(s, 0); return; } if (_id == Integer.parseInt(ary[2])) { if (s.indexOf("rotate-gun") > -1) { _lastRotateGun = TimerCmd.timeStamp + " " + s; if (_state != null) _state.gunAngle = Float.parseFloat(_lastRotateGun.split(" ")[5]); } else if (s.indexOf("move tank") > -1) { Logger.debug("ClientMediator: move add s=" + s); int offset = Integer.parseInt(notification.getType()); if (offset == 0) _move.clear(); _move.add((TimerCmd.timeStamp + offset) + " " + s); } else if (s.indexOf("create tank") > -1) { _state = new TankState( _id, ary[3], Integer.parseInt(ary[6]), (int) Float.parseFloat(ary[8]), (int) Float.parseFloat(ary[9]), Float.parseFloat(ary[10]), Float.parseFloat(ary[11])); _state.printState(); } else if (s.indexOf("rotate-tank") > -1) { _lastRotTank = TimerCmd.timeStamp + " " + s; if (_state != null) _state.tankAngle = Float.parseFloat(_lastRotTank.split(" ")[5]); } else if (s.indexOf("destroy tank") > -1) { this.destroyd = true; } } if (notification.getType() != null) tellClient(s, Integer.parseInt(notification.getType())); else tellClient(s, 0); } }