コード例 #1
0
  private void pnGraphMouseMoved(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_pnGraphMouseMoved

    if (this.pnGraph.mDrag) {
      this.pnGraph.xM = evt.getX();
      this.pnGraph.yM = evt.getY();
      this.pnGraph.repaint();
    }
  } // GEN-LAST:event_pnGraphMouseMoved
コード例 #2
0
ファイル: trial.java プロジェクト: Abhiroop/Ontology
    public void itemPressed(VisualItem item, java.awt.event.MouseEvent e) {
      if (e.getClickCount() == 2) {
        Node v = null;
        String pindex = "/";
        String parent = "/";
        int ind;
        String itemname = item.getString(LABEL);
        for (int i = 0; ; i++) {
          v = (getNode(i));
          String current = getName(v);
          if (current.compareTo(itemname) == 0) {
            ind = (int) v.get(Index);
            if (ind <= 9) itemname = itemname.substring(0, itemname.length() - 1);
            else itemname = itemname.substring(0, itemname.length() - 2);
            while (pindex != "Start") {
              Node h = v.getParent();
              pindex = getName(h);
              ind = (int) h.get(Index);

              if (pindex == "Start") break;

              if (ind <= 9) parent = "/" + pindex.substring(0, pindex.length() - 1) + parent;
              else parent = "/" + pindex.substring(0, pindex.length() - 2) + parent;

              v = h;
            }
            break;
          }
        }

        System.out.println(parent.substring(1) + itemname);

        // trial2 hello2 = new
        // trial2(item.getInt(Index),(item.getString(LABEL)),parent.substring(1)+itemname,100);
        urllink mainPanel =
            new urllink(
                item.getInt(Index), (item.getString(LABEL)), parent.substring(1) + itemname, 100);

        JFrame frame = new JFrame("Click any option");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(mainPanel);
        frame.pack();
        frame.setLocationByPlatform(true);
        frame.setVisible(true);
      }
    }
コード例 #3
0
  private void pnGraphMouseReleased(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_pnGraphMouseReleased

    int x = 0;
    int y = 0;
    Vertex vertex = null;
    if (this.drawType != DrawType.NODRAW || this.start || this.end) {
      x = evt.getX() - jGraphPanel.radius / 2;
      y = evt.getY() - jGraphPanel.radius / 2;
      if (x < 0 || y < 0) {
        this.jTextStatus.setText("Invalid position");
        this.drawType = DrawType.NODRAW;
        return;
      }
      vertex = this.pnGraph.checkInVertex(x, y);
      if (vertex != null)
        if (vertex.state != State.LABELED)
          if (this.start) {
            vertex.state = State.LABELED;
            vertex.setKey(0);
            this.startVertex = vertex;
            this.jTextStatus.setText("");
            this.jSolution.append(
                "Starting vertex\t: Vertex " + Integer.toString(vertex.getData()) + "\n");
            this.start = false;
          } else if (this.end) {
            vertex.state = State.LABELED;
            this.endVertex = vertex;
            this.jTextStatus.setText("");
            this.jSolution.append(
                "Ending vertex\t: Vertex " + Integer.toString(vertex.getData()) + "\n");
            this.end = false;
          }
    }

    if (this.drawType == DrawType.VERTEXS) {
      if (vertex != null) {
        this.jTextStatus.setText("Concurred with another vertex");
      } else {
        this.pnGraph.listVertexs.add(new Vertex(x, y, this.numVertexs, -1));
        this.numVertexs++;
      }
    } else if (this.drawType == DrawType.EDGES) {
      if (vertex == null) this.jTextStatus.setText("You must click on exist vertex");
      else if (vertex == this.head) this.jTextStatus.setText("You must choose another vertex");
      else {
        if (draw) {
          this.pnGraph.mDrag = false;
          this.pnGraph.head = null;
          Edge edge = new Edge(this.head, vertex, 10);
          edge.edgeType = this.pnGraph.checkEdge(this.head, vertex);
          if (this.jRandomCheck.isSelected()) {
            Random random = new Random();
            edge.setLength(random.nextInt(20));
          } else
            edge.setLength(
                Integer.parseInt(
                    JOptionPane.showInputDialog(
                        null, "Length of edge", "Edge", JOptionPane.QUESTION_MESSAGE)));
          this.head.outgoingEdges.add(edge);
          vertex.incomingEdges.add(edge);
          this.pnGraph.listEdges.add(edge);
          this.head = null;
          this.jTextStatus.setText("Draw an edge");
          this.draw = false;
        } else {
          this.head = vertex;
          this.pnGraph.head = vertex;
          this.pnGraph.xM = evt.getX();
          this.pnGraph.yM = evt.getY();
          this.pnGraph.mDrag = true;
          this.jTextStatus.setText("Choose tail vertex");
          this.draw = true;
        }
      }
    }
    this.pnGraph.repaint();
  } // GEN-LAST:event_pnGraphMouseReleased