@Override
  public void keyPressed(KeyEvent e) {
    // Do not edit neural web while user is selecting key bindings
    if (expandContractKey.isActive()
        || newNeuronKey.isActive()
        || newClusterKey.isActive()
        || deleteKey.isActive()) return;

    try {
      if (e.getKeyChar() == expandContractKey.getText().charAt(0)) {
        if (selectedCluster != null && selectedCluster.clusterNum != 0)
          selectedCluster.expanded = !selectedCluster.expanded;
        else if (selectedNeuron != null)
          selectedNeuron.cluster.expanded = !selectedNeuron.cluster.expanded;

        redraw = true;
      } else if (e.getKeyChar() == newNeuronKey.getText().charAt(0)) {
        Cluster cluster;

        if (selectedCluster != null) cluster = selectedCluster;
        else if (selectedNeuron != null) cluster = selectedNeuron.cluster;
        else if (clusters.size() > 2) {
          cluster = clusters.get(2);
        } else {
          WindowTools.informationWindow(
              "Error: You cannot add a neuron without a cluster, please select a Neuron or a Cluster.",
              "Error");
          return;
        }

        int x = Math.min(Main.canvasWidth - 11, Math.max(10, mouseX));
        int y = Math.min(Main.canvasHeight - 33, Math.max(33, mouseY));

        neurons.add(new Neuron(x, y, cluster));

        redraw = true;
      } else if (e.getKeyChar() == newClusterKey.getText().charAt(0)) {
        int x = Math.min(Main.canvasWidth - 11, Math.max(10, mouseX));
        int y = Math.min(Main.canvasHeight - 33, Math.max(33, mouseY));

        clusters.add(new Cluster(x, y));

        redraw = true;
      } else if (e.getKeyChar() == deleteKey.getText().charAt(0)) {
        if (selectedCluster != null) selectedCluster.delete();
        else if (selectedNeuron != null) selectedNeuron.delete();
        else if (selectedConnection != null) selectedConnection.delete();

        redraw = true;
      }
    } catch (StringIndexOutOfBoundsException sioobe) {
      WindowTools.informationWindow(
          "Invalid keybinding, please select a character for each action.", "Whoops!");
    }
  }
Esempio n. 2
0
  @Test
  public void testDeleteLongListOfLong() {
    Connection db = getConnection();
    long app = getAppId();
    try {
      List<Long> ids = insertRecords();
      db.delete(app, ids);

      ResultSet rs = db.select(app, "");
      if (rs.size() != 0) {
        fail("failed to delete");
      }
    } catch (Exception e) {
      fail("db exception:" + e.getMessage());
    }
  }
  @Override
  public void mousePressed(MouseEvent e) {
    int x = e.getX();
    int y = e.getY();

    switch (e.getButton()) {
      case MouseEvent.BUTTON1:
        if (leftSelectButton.isChecked()) {
          for (Cluster c : clusters)
            if (c.collides(x, y)) {
              selectCluster(c);
              return;
            }

          for (Neuron n : neurons) {
            if (n.collides(x, y)) {
              selectNeuron(n);
              return;
            }
            for (Connection c : n.outgoingConnections)
              if (c.collides(x, y)) {
                selectConnection(c);
                return;
              }
          }

          for (Neuron n : inputs) {
            if (n.collides(x, y)) {
              selectNeuron(n);
              return;
            }
            for (Connection c : n.outgoingConnections)
              if (c.collides(x, y)) {
                selectConnection(c);
                return;
              }
          }

          for (Neuron n : outputs) {
            if (n.collides(x, y)) {
              selectNeuron(n);
              return;
            }
            for (Connection c : n.outgoingConnections)
              if (c.collides(x, y)) {
                selectConnection(c);
                return;
              }
          }
        }
        break;
      case MouseEvent.BUTTON3:
        if (rightConnectButton.isChecked()) {
          for (Neuron n : neurons) {
            if (n.collides(x, y) && n != selectedNeuron) {
              new Connection(selectedNeuron, n);
              return;
            }
          }

          for (Neuron n : inputs) {
            if (n.collides(x, y) && n != selectedNeuron) {
              new Connection(selectedNeuron, n);
              return;
            }
          }

          for (Neuron n : outputs) {
            if (n.collides(x, y) && n != selectedNeuron) {
              new Connection(selectedNeuron, n);
              return;
            }
          }
        } else if (rightDeleteButton.isChecked()) {
          for (Cluster c : clusters)
            if (c.collides(x, y)) {
              c.delete();
              return;
            }

          for (Neuron n : neurons) {
            if (n.collides(x, y)) {
              n.delete();
              return;
            }
            for (Connection c : n.outgoingConnections)
              if (c.collides(x, y)) {
                c.delete();
                return;
              }
          }

          for (Neuron n : inputs) {
            if (n.collides(x, y)) {
              n.delete();
              return;
            }
            for (Connection c : n.outgoingConnections)
              if (c.collides(x, y)) {
                c.delete();
                return;
              }
          }

          for (Neuron n : outputs) {
            if (n.collides(x, y)) {
              n.delete();
              return;
            }
            for (Connection c : n.outgoingConnections)
              if (c.collides(x, y)) {
                c.delete();
                return;
              }
          }
        }
    }
  }