コード例 #1
0
  public void save() {
    for (String key : fields.keySet()) {
      JComponent comp = fields.get(key);

      if (comp instanceof JTextField) {
        JTextField c = (JTextField) comp;

        if (c.getText().trim().equals("")) {
          sketch.configFile.unset(key);
        } else {
          sketch.configFile.set(key, c.getText());
        }
      } else if (comp instanceof JTextArea) {
        JTextArea c = (JTextArea) comp;

        if (c.getText().trim().equals("")) {
          sketch.configFile.unset(key);
        } else {
          sketch.configFile.set(key, c.getText());
        }
      }
    }

    sketch.saveConfig();
  }
コード例 #2
0
    public boolean stopCellEditing() {
      Object descrip = null, costo = null;
      JTextField campo = ((JTextField) this.getComponent());
      String codigo = campo.getText();
      if (codigo == "") {
        return false;
      }
      descrip =
          Almacenes.groovyPort(
              "omoikane.principal.Articulos.getArticulo('codigo = \""
                  + codigo
                  + "\"').descripcion");
      costo =
          Almacenes.groovyPort(
              "omoikane.principal.Articulos.getArticulo('select * from articulos,precios where articulos.codigo = \""
                  + codigo
                  + "\" "
                  + "and articulos.id_articulo = precios.id_articulo and precios.id_almacen = '+omoikane.principal.Principal.config.idAlmacen[0].text()).costo");

      if (descrip == null) {
        Dialogos.lanzarAlerta("El artículo que capturó no exíste");
        campo.setText("");
        return false;
      } else {
        tablaPrincipal.setValueAt(
            descrip, tablaPrincipal.getEditingRow(), tablaPrincipal.getEditingColumn() + 1);
        tablaPrincipal.setValueAt(
            costo, tablaPrincipal.getEditingRow(), tablaPrincipal.getEditingColumn() + 2);
        return super.stopCellEditing();
      }
    }
コード例 #3
0
 @Override
 public void setSelectedIndex(int ind) {
   super.setSelectedIndex(ind);
   editor.setText(getItemAt(ind).toString());
   editor.setSelectionEnd(caretPos + editor.getText().length());
   editor.moveCaretPosition(caretPos);
 }
コード例 #4
0
ファイル: DrawTool.java プロジェクト: tstamler/linAlg
 static String waitForInputString() {
   try {
     while (!hasEntered) {
       Thread.sleep(100);
     }
     return inputField.getText();
   } catch (Exception e) {
     return "";
   }
 }
コード例 #5
0
  public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();

    for (JRadioButton u : ub) {
      if (o == u) {
        mapTM.setUnitType(u.getText());
        System.out.println("Set unit type - " + u.getText());
        return;
      }
    }

    if (o == timer) {

      /*
      mmLabel.setText("Main Menu ("+(cdTime--)+")");

      if(cdTime == 0){
      	timer.stop();
      	gsButton.setText("Game Start");
      	mmLabel.setText("Main Menu");

      	ArrayList<Building> bArr = new ArrayList<Building>();

      	String temp = "Elixir Collector-24,8-960|Elixir Collector-31,8-960|Gold Mine-17,10-960|Elixir Collector-25,21-960|Elixir Collector-11,22-960";
      	String[] bs = temp.split("\\|");
      	for(String b : bs){
      		String[] bParts = b.split("-");
      		String[] cParts = bParts[1].split(",");
      		int x = Integer.parseInt(cParts[0].trim());
      		int y = Integer.parseInt(cParts[1].trim());

      		Building tb = new Building(bParts[0], new Coordinate(x,y));
      		tb.setHp(Integer.parseInt(bParts[2].trim()));

      		bArr.add(tb);
      	}



      	mapTM.setBuildings(bArr);
      	switchCards("TM");
      }
      */

      return;
    }

    if (o == gsButton) {

      if (timer.isRunning()) {
        // timer.stop();
        gsButton.setText("Game Start");
        mmLabel.setText("Main Menu");
        // sends the leave command
        client.sendUDP("leave~" + unameUDP);
        return;
      }
      // sends the joinlobby command
      client.sendUDP("joinlobby~" + unameUDP);
      // gsButton.setText("Game Stop");
      String serverResp = client.receiveUDP();

      if (serverResp.trim().equals("false")) {

        // place false handler here

      } else {

        String[] enemies = serverResp.trim().split(",");
        ArrayList<Building> bArr = new ArrayList<Building>();
        String mapConfig = getBaseConfig(enemies[0]);
        String[] bs = mapConfig.split("\\|");
        for (String b : bs) {

          String[] bParts = b.split("-");
          String[] cParts = bParts[1].split(",");
          int x = Integer.parseInt(cParts[0].trim());
          int y = Integer.parseInt(cParts[1].trim());

          Building tb = new Building(bParts[0], new Coordinate(x, y));
          tb.setHp(Integer.parseInt(bParts[2].trim()));
          bArr.add(tb);
        }

        mapTM.setBuildings(bArr);
        switchCards("TM");
      }

      // System.out.println(serverResp);
      // cdTime = 10;
      // timer.start();
      return;
    }

    if (o == logout) {
      client.sendMessage(new ChatMessage(ChatMessage.LOGOUT, ""));
      chatArea.setText("");

      switchCards("Login");
      return;
    }

    if (o == cmButton) {
      String baseConfig = getBaseConfig();
      System.out.println("base config: " + baseConfig);

      for (int i = 0; i < mapSize; i++) {
        for (int j = 0; j < mapSize; j++) {
          tiles[i][j].setValue("");
        }
      }

      if (!baseConfig.equals("")) {

        String[] bs = baseConfig.split("\\|");
        for (String b : bs) {
          String[] bParts = b.split("-");
          String[] cParts = bParts[1].split(",");
          int x = Integer.parseInt(cParts[0].trim());
          int y = Integer.parseInt(cParts[1].trim());

          int index = 0;
          for (int i = 0; i < bb.size(); i++) {
            if (bb.get(i).getText().split("-")[0].trim().equals(bParts[0])) {
              index = i;
              break;
            }
          }
          insertBuilding(y, x, index);
        }
      }

      switchCards("CM");

      return;
    }

    if (o == tmButton) {

      ArrayList<Building> bArr = new ArrayList<Building>();

      for (int i = 0; i < 40; i++) {
        for (int j = 0; j < 40; j++) {
          if (tiles[i][j].getValue().equals("") || tiles[i][j].getValue().contains("-")) {
            continue;
          }
          // weird part here
          bArr.add(new Building(tiles[i][j].getValue(), new Coordinate(j, i)));
        }
      }

      mapTM.setBuildings(bArr);

      switchCards("TM");
      return;
    }

    // if it the who is in button
    if (o == whoIsIn) {
      client.sendMessage(new ChatMessage(ChatMessage.WHOISIN, ""));
      return;
    }

    if (o == cmBack) {
      ArrayList<Building> bArr = new ArrayList<Building>();
      for (int i = 0; i < 40; i++) {
        for (int j = 0; j < 40; j++) {
          if (tiles[i][j].getValue().equals("") || tiles[i][j].getValue().contains("-")) {
            continue;
          }
          // weird part here
          bArr.add(new Building(tiles[i][j].getValue(), new Coordinate(j, i)));
        }
      }

      String temp = "mapdata~" + unameUDP + "~";
      int tileCount = 40;
      int dim = 600;
      int tileDim = (int) (dim / tileCount);
      int counter = 0;
      for (Building b : bArr) {
        int x, y, hp;
        x = b.getPos().getX() / tileDim;
        y = b.getPos().getY() / tileDim;
        hp = b.getHp();
        temp += b.getName() + "-" + x + "," + y + "-" + hp + "|";
        counter += 1;
      }
      if (counter > 0) {
        temp = temp.substring(0, temp.length() - 1); // removes the last '|'
      } else {
        temp += "none";
      }

      client.sendUDP(temp); // allows saving of the current state of the map into the user's account

      switchCards("Menu");

      return;
    }
    if (o == tmBack) {
      switchCards("Menu");

      return;
    }

    for (int i = 0; i < 40; i++) {
      for (int j = 0; j < 40; j++) {
        if (o == tiles[i][j]) {
          for (int k = 0; k < bb.size(); k++) {
            if (bb.get(k).isSelected()) {
              if (bb.get(k).getText().equals("Remove Building")) {
                removeBuilding(i, j);
                return;
              }

              insertBuilding(i, j, k);
              // JOptionPane.showMessageDialog(null, bb.get(k).getText());
              return;
            }
          }

          // JOptionPane.showMessageDialog(null, "i-"+i+" j-"+j);
          return;
        }
      }
    }

    // ok it is coming from the JTextField
    if (connected) {
      // just have to send the message
      client.sendMessage(new ChatMessage(ChatMessage.MESSAGE, chatField.getText()));
      chatField.setText("");
      return;
    }

    if (o == login) {
      // ok it is a connection request
      String username = usernameField.getText().trim();
      String password = passwordField.getText().trim();
      // empty username ignore it
      if (username.length() == 0) return;
      // empty serverAddress ignore it
      String server = tfServer.getText().trim();
      if (server.length() == 0) return;
      // empty or invalid port numer, ignore it
      String portNumber = tfPort.getText().trim();
      if (portNumber.length() == 0) return;
      int port = 0;
      try {
        port = Integer.parseInt(portNumber);
      } catch (Exception en) {
        return; // nothing I can do if port number is not valid
      }

      // try creating a new Client with GUI
      client = new Client(server, port, username, password, this);
      // test if we can start the Client
      if (!client.start()) return;

      unameUDP = username;

      switchCards("Menu");
      // fetching of the base_config string from the database

      chatField.setText("");
      chatArea.setText("");
    }
  }
コード例 #6
0
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == b) {
      JFrame frame2 = new JFrame();
      JFileChooser chooser = new JFileChooser(".");
      int option =
          chooser.showOpenDialog(
              frame2); // parentComponent must a component like JFrame, JDialog...
      if (option == JFileChooser.APPROVE_OPTION) {
        File selectedFile = chooser.getSelectedFile();
        path = selectedFile.getAbsolutePath();
      }
      try {
        loadImage();
      } catch (IOException ioe) {
        System.out.println(ioe.getMessage());
      }
    } else if (e.getSource() == c) {

      gaussianBlur();
      // filtered = grayscale.filter(filtered, null);
      sobel();
      // thinImage();
      nonMax();
      float lowThreshold = 2.5f;
      float highThreshold = 7.5f;
      int low = Math.round(lowThreshold * MAGNITUDE_SCALE);
      int high = Math.round(highThreshold * MAGNITUDE_SCALE);
      performHysteresis(low, high);
      thresholdEdges();
      writeEdges(data);
      Hough();
      ImageIcon icon1 = new ImageIcon(res);
      lbl1.setIcon(icon1);
      ImageIcon icon2 = new ImageIcon(filtered);
      lbl2.setIcon(icon2);
      filterBtn.setSelected(true);
    }
    if (e.getSource() == findCircles) {
      try {
        accSize = Integer.parseInt(inputCircles.getText());
        res = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics g = res.getGraphics();
        g.drawImage(img, 0, 0, null);
        g.dispose();
        findMaxima();
        ImageIcon icon1 = new ImageIcon(res);
        lbl1.setIcon(icon1);
      } catch (Exception err) {
        System.out.println("Not a valid integer");
      }
    } else if (e.getSource() == filterBtn) {
      ImageIcon icon2 = new ImageIcon(filtered);
      lbl2.setIcon(icon2);
    } else if (e.getSource() == sobelBtn) {
      ImageIcon icon2 = new ImageIcon(sobel);
      lbl2.setIcon(icon2);
    } else if (e.getSource() == nonMaxBtn) {
      ImageIcon icon2 = new ImageIcon(nonMax);
      lbl2.setIcon(icon2);
    } else if (e.getSource() == accumulator) {
      buildAccumulator(whichRadius.getValue());
    }
  }
コード例 #7
0
ファイル: LJ3MDApp.java プロジェクト: eskilj/mvp
  public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();
    if (src == timer) {
      for (int i = 0; i < speed; i++) // integrate a few steps
      md.vv();
      repaint();
      return;
    }

    boolean adjCanvasScale = false;

    if (src == bTstat) md.thermostat = !md.thermostat;

    if (src == bPot) {
      md.ljPotential = !md.ljPotential;
      md.clearData();

      if (timer.isRunning()) timer.stop();
      bStart.setSelected(false);
      bStart.setText("Start");
      md.init(md.rho);
    }

    if (src == tTemp || src == bReset) {
      double kT = Double.parseDouble(tTemp.getText().trim());
      if (kT < 1e-8) {
        kT = 1e-8;
        tTemp.setText("  " + kT);
      }
      md.kT = kT;
      md.clearData();
    }

    if (src == tRho || src == bReset) {
      double rho = Double.parseDouble(tRho.getText().trim());
      if (rho < 1e-3) {
        rho = 1e-3;
        tRho.setText("   " + rho);
      }
      if (rho > 1.2) {
        rho = 1.2;
        tRho.setText("   " + rho);
      }
      md.setDensity(rho);
      md.clearData();
      adjCanvasScale = true;
    }

    if (src == tSpeed || src == bReset) {
      speed = Integer.parseInt(tSpeed.getText().trim());
      if (speed < 1) {
        speed = 1;
        tSpeed.setText("   " + speed);
      }
    }

    if (src == bRetime) md.clearData();

    if (src == bStart) {
      boolean on = bStart.isSelected();
      if (on) {
        timer.restart();
        bStart.setText("Pause");
      } else {
        timer.stop();
        bStart.setText("Resume");
      }
    }

    if (src == tNum) {
      int n = Integer.parseInt(tNum.getText().trim());
      if (n < 2) {
        n = 2;
        tNum.setText(" " + n);
      }
      md.N = n;
      md.init(md.rho);
      adjCanvasScale = true;
    }

    if (src == bReset) {
      if (timer.isRunning()) timer.stop();
      bStart.setSelected(false);
      bStart.setText("Start");
      md.init(md.rho);
    }

    canvas.refresh(md.getXWrap(), md.N, true, adjCanvasScale);

    repaint();
  }
コード例 #8
0
 public String getUser() {
   return user.getText();
 }
コード例 #9
0
 public String getAbsolutePath() {
   return _txtPath.getText()
       + File.separatorChar
       + _txtFilename.getSelectedItem()
       + _txtFileExt.getText();
 }