public void actionPerformed(ActionEvent e) {

    // Handle open button action.
    if (e.getSource() == openButton) {
      int returnVal = fc.showOpenDialog(FileChooserDemo.this);

      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // This is where a real application would open the file.
        log.append("Opening: " + file.getName() + "." + newline);
      } else {
        log.append("Open command cancelled by user." + newline);
      }
      log.setCaretPosition(log.getDocument().getLength());

      // Handle save button action.
    } else if (e.getSource() == saveButton) {
      int returnVal = fc.showSaveDialog(FileChooserDemo.this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // This is where a real application would save the file.
        log.append("Saving: " + file.getName() + "." + newline);
      } else {
        log.append("Save command cancelled by user." + newline);
      }
      log.setCaretPosition(log.getDocument().getLength());
    }
  }
Exemplo n.º 2
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == top) {
     tabbedpane.setTabPlacement(JTabbedPane.TOP);
   } else if (e.getSource() == left) {
     tabbedpane.setTabPlacement(JTabbedPane.LEFT);
   } else if (e.getSource() == bottom) {
     tabbedpane.setTabPlacement(JTabbedPane.BOTTOM);
   } else if (e.getSource() == right) {
     tabbedpane.setTabPlacement(JTabbedPane.RIGHT);
   }
 }
Exemplo n.º 3
0
 public void actionPerformed(ActionEvent e) {
   int index = list.getSelectedIndex();
   if ("Move".equals(e.getActionCommand())) {
     copy = false;
     directoryList.getDirectory(index).copy = false;
   }
   if ("Copy".equals(e.getActionCommand())) {
     copy = true;
     directoryList.getDirectory(index).copy = true;
   }
 }
Exemplo n.º 4
0
 public void actionPerformed(ActionEvent ev) {
   JComponent src = (JComponent) ev.getSource();
   if (src == saveAsMI) {
     saveAs();
   } else {
     int index = timeRangeMenu.getPopupMenu().getComponentIndex(src);
     setViewRange(rangeValues[index]);
   }
 }
Exemplo n.º 5
0
  public void actionPerformed(ActionEvent e) {

    // Handle open button action.
    if (e.getSource() == openButton) {
      int returnVal = fc.showOpenDialog(DirectorySize.this);

      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // This is where a real application would open the file.
        ListSubDirectorySizes(file);
      } else {
        log.append("Open command cancelled by user." + newline);
      }
      log.setCaretPosition(log.getDocument().getLength());

      // Handle save button action.
    } else if (e.getSource() == saveButton) {
      log.setText(""); // reset
    }
  }
 /** Effectue differentes actions en fonction du bouton que l'on clique */
 @Override
 public void actionPerformed(ActionEvent e) {
   if (e.getActionCommand().equals("Réinitialiser")) {
     this.maGrille.viderTabCases();
   } else if (e.getActionCommand().equals("Aléatoire")) {
     this.maGrille.remplirAleatTabCases();
   } else if (e.getActionCommand().equals("Chemin")) {
     this.etat = (byte) 0;
     this.indication.setEtat((byte) 0);
   } else if (e.getActionCommand().equals("Mur")) {
     this.etat = (byte) 1;
     this.indication.setEtat((byte) 1);
   } else if (e.getActionCommand().equals("Perso")) {
     this.etat = (byte) 2;
     this.indication.setEtat((byte) 2);
   } else if (e.getActionCommand().equals("Sortie")) {
     this.etat = (byte) 3;
     this.indication.setEtat((byte) 3);
   } else if (e.getActionCommand().equals("Sauvegarder")) {
     /* appel de la methode mapSaver */
     JFileChooser chooser = new JFileChooser("./MAP/");
     FileNameExtensionFilter filter = new FileNameExtensionFilter("Labyrinthe file (.lab)", "lab");
     chooser.setFileFilter(filter);
     int returnval = chooser.showOpenDialog(null);
     if (returnval == JFileChooser.APPROVE_OPTION) {
       System.out.println("You chose to save this file: " + chooser.getSelectedFile().getName());
       MapSaver map =
           new MapSaver(
               chooser.getSelectedFile(),
               (byte) this.maGrille.getTaille(),
               this.maGrille.getPosThesee(),
               this.maGrille.getPosSortie(),
               this.maGrille.getTabCases());
     } else {
       System.out.println("saving file aborded!");
     }
   } else if (e.getActionCommand().equals("Retour")) {
     /* retour au menu precedent */
     this.oldFenetre.setVisible(true);
     this.oldFenetre.repaint();
     this.maGrille.setClosed();
   }
   if (maGrille.estValide()) {
     this.sauvegarder.setEnabled(true);
   } else {
     this.sauvegarder.setEnabled(false);
   }
 }
Exemplo n.º 7
0
  public void actionPerformed(ActionEvent e) {
    String cmd = (e.getActionCommand());

    if (cmd.equals(aboutItem.getText()))
      JOptionPane.showMessageDialog(
          this,
          "Simple Image Program for DB2004\nversion 0.1\nThanks to BvS",
          "About imageLab",
          JOptionPane.INFORMATION_MESSAGE);
    else if (cmd.equals(quitItem.getText())) System.exit(0);
    else if (cmd.equals(openItem.getText())) {
      int returnVal = chooser.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
          pic2 = new Picture(chooser.getSelectedFile().getName());
          pic1 = new Picture(pic2.width(), pic2.height());
          lab.setIcon(pic2.getJLabel().getIcon());
          sliderPanel.setVisible(false);
          pack();
          repaint();
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this,
              "Could not open " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(),
              "Open Error",
              JOptionPane.INFORMATION_MESSAGE);
        }
      }

    } else if (cmd.equals(saveItem.getText())) {
      int returnVal = chooser.showSaveDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
          pic2.save(chooser.getSelectedFile().getName());
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this,
              "Could not write " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(),
              "Save Error",
              JOptionPane.INFORMATION_MESSAGE);
        }
      }
    }
  }
Exemplo n.º 8
0
    public void actionPerformed(ActionEvent e) {
      if (isDirectorySelected()) {
        File dir = getDirectory();
        if (dir != null) {
          try {
            // Strip trailing ".."
            dir = ShellFolder.getNormalizedFile(dir);
          } catch (IOException ex) {
            // Ok, use f as is
          }
          changeDirectory(dir);
          return;
        }
      }

      JFileChooser chooser = getFileChooser();

      String filename = getFileName();
      FileSystemView fs = chooser.getFileSystemView();
      File dir = chooser.getCurrentDirectory();

      if (filename != null) {
        // Remove whitespaces from end of filename
        int i = filename.length() - 1;

        while (i >= 0 && filename.charAt(i) <= ' ') {
          i--;
        }

        filename = filename.substring(0, i + 1);
      }

      if (filename == null || filename.length() == 0) {
        // no file selected, multiple selection off, therefore cancel the approve action
        resetGlobFilter();
        return;
      }

      File selectedFile = null;
      File[] selectedFiles = null;

      // Unix: Resolve '~' to user's home directory
      if (File.separatorChar == '/') {
        if (filename.startsWith("~/")) {
          filename = System.getProperty("user.home") + filename.substring(1);
        } else if (filename.equals("~")) {
          filename = System.getProperty("user.home");
        }
      }

      if (chooser.isMultiSelectionEnabled()
          && filename.length() > 1
          && filename.charAt(0) == '"'
          && filename.charAt(filename.length() - 1) == '"') {
        List<File> fList = new ArrayList<File>();

        String[] files = filename.substring(1, filename.length() - 1).split("\" \"");
        // Optimize searching files by names in "children" array
        Arrays.sort(files);

        File[] children = null;
        int childIndex = 0;

        for (String str : files) {
          File file = fs.createFileObject(str);
          if (!file.isAbsolute()) {
            if (children == null) {
              children = fs.getFiles(dir, false);
              Arrays.sort(children);
            }
            for (int k = 0; k < children.length; k++) {
              int l = (childIndex + k) % children.length;
              if (children[l].getName().equals(str)) {
                file = children[l];
                childIndex = l + 1;
                break;
              }
            }
          }
          fList.add(file);
        }

        if (!fList.isEmpty()) {
          selectedFiles = fList.toArray(new File[fList.size()]);
        }
        resetGlobFilter();
      } else {
        selectedFile = fs.createFileObject(filename);
        if (!selectedFile.isAbsolute()) {
          selectedFile = fs.getChild(dir, filename);
        }
        // check for wildcard pattern
        FileFilter currentFilter = chooser.getFileFilter();
        if (!selectedFile.exists() && isGlobPattern(filename)) {
          changeDirectory(selectedFile.getParentFile());
          if (globFilter == null) {
            globFilter = new GlobFilter();
          }
          try {
            globFilter.setPattern(selectedFile.getName());
            if (!(currentFilter instanceof GlobFilter)) {
              actualFileFilter = currentFilter;
            }
            chooser.setFileFilter(null);
            chooser.setFileFilter(globFilter);
            return;
          } catch (PatternSyntaxException pse) {
            // Not a valid glob pattern. Abandon filter.
          }
        }

        resetGlobFilter();

        // Check for directory change action
        boolean isDir = (selectedFile != null && selectedFile.isDirectory());
        boolean isTrav = (selectedFile != null && chooser.isTraversable(selectedFile));
        boolean isDirSelEnabled = chooser.isDirectorySelectionEnabled();
        boolean isFileSelEnabled = chooser.isFileSelectionEnabled();
        boolean isCtrl =
            (e != null
                && (e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0);

        if (isDir && isTrav && (isCtrl || !isDirSelEnabled)) {
          changeDirectory(selectedFile);
          return;
        } else if ((isDir || !isFileSelEnabled)
            && (!isDir || !isDirSelEnabled)
            && (!isDirSelEnabled || selectedFile.exists())) {
          selectedFile = null;
        }
      }

      if (selectedFiles != null || selectedFile != null) {
        if (selectedFiles != null || chooser.isMultiSelectionEnabled()) {
          if (selectedFiles == null) {
            selectedFiles = new File[] {selectedFile};
          }
          chooser.setSelectedFiles(selectedFiles);
          // Do it again. This is a fix for bug 4949273 to force the
          // selected value in case the ListSelectionModel clears it
          // for non-existing file names.
          chooser.setSelectedFiles(selectedFiles);
        } else {
          chooser.setSelectedFile(selectedFile);
        }
        chooser.approveSelection();
      } else {
        if (chooser.isMultiSelectionEnabled()) {
          chooser.setSelectedFiles(null);
        } else {
          chooser.setSelectedFile(null);
        }
        chooser.cancelSelection();
      }
    }
Exemplo n.º 9
0
  public void actionPerformed(ActionEvent event) {

    if (posicion == -2) posicion = indexaux;

    // Abrir nueva imagen
    if (event.getSource() == carpeta) {

      siguiente.setEnabled(true);
      atras.setEnabled(true);
      presentacion.setEnabled(true);
      grid.setEnabled(true);
      bcomentario.setEnabled(true);
      zoom.setEnabled(true);

      imagenesbean.clear();

      if (imagenes != null) {
        imagenes.clear();
      }

      returnChooser = chooser.showOpenDialog(ArcViewer.this);
      imagenes = lista.Miranda(chooser, returnChooser);

      for (int asd1 = 0; asd1 < imagenes.size(); asd1++) {
        imagenesbean.add(new ImagenBean(imagenes.get(asd1), 0, 0));
      }

      String getImgSelected = chooser.getSelectedFile().getPath();

      for (int index = 0; index < imagenesbean.size(); index++) {
        if (getImgSelected.equals(imagenesbean.get(index).getIcon())) {
          imagen.setIcon(new ImageIcon(imagenesbean.get(index).getIcon()));
          indexaux = index;
        }
      }
    }

    // Imagen siguiente
    if (event.getSource() == siguiente) {
      posicion++;
      if (posicion >= imagenesbean.size()) {
        posicion = 0;
      }

      imagen.setIcon(
          ajustar.ajusteImg(
              new ImageIcon(imagenesbean.get(posicion).getIcon()),
              imagenesbean.get(posicion).getAncho(),
              imagenesbean.get(posicion).getAlto(),
              areaventana.getWidth() - 50,
              areaventana.getHeight()));
    }

    // Imagen anterior
    if (event.getSource() == atras) {
      posicion--;
      if (posicion == -1) {
        posicion = imagenesbean.size() - 1;
      }

      imagen.setIcon(
          ajustar.ajusteImg(
              new ImageIcon(imagenesbean.get(posicion).getIcon()),
              imagenesbean.get(posicion).getAncho(),
              imagenesbean.get(posicion).getAlto(),
              areaventana.getWidth() - 50,
              areaventana.getHeight()));
    }

    // Presentacion iniciar/detener
    if (event.getSource() == presentacion) {

      if (isPresentacion == false) {
        grid.setVisible(false);
        atras.setVisible(false);
        siguiente.setVisible(false);
        carpeta.setVisible(false);
        bcomentario.setVisible(false);
        zoom.setVisible(false);
        ptiempo.setVisible(true);
      }

      if (isPresentacion == true) {
        grid.setVisible(true);
        atras.setVisible(true);
        siguiente.setVisible(true);
        carpeta.setVisible(true);
        bcomentario.setVisible(true);
        zoom.setVisible(true);
        ptiempo.setVisible(false);
      }

      if (presentacion.getIcon() == imgPausa) {
        slide.detener();
        posicion = slide.getPosicion();
        presentacion.setIcon(imgPlay);
        isPresentacion = false;
        return;
      }

      if (presentacion.getIcon() == imgPlay) {
        slide.setTodo(posicion, imagen, imagenesbean, areaventana, ptiempo);
        new Thread(slide, "prueba").start();
        presentacion.setIcon(imgPausa);
        isPresentacion = true;
        return;
      }
    }

    // Modo rejilla
    if (event.getSource() == grid) {

      imagen.setVisible(false);
      siguiente.setVisible(false);
      atras.setVisible(false);
      presentacion.setVisible(false);
      grid.setVisible(false);
      bcomentario.setVisible(false);
      zoom.setVisible(false);
      carpeta.setVisible(false);
      ptiempo.setVisible(false);

      // desplazamiento.setVisible(true);

      if (corrobora == true) {
        for (int celular = 0; celular < imgButtonArray.length; celular++) {
          imgButtonArray[celular].setVisible(true);
        }
      }

      if (corrobora == false) {
        imgButtonArray = new JButton[imagenesbean.size()];

        for (int goku = 0; goku < imagenesbean.size(); goku++) {
          areaventana.add(imgButtonArray[goku] = new JButton());
          imgButtonArray[goku].setPreferredSize(new Dimension(200, 200));
          imgButtonArray[goku].addActionListener(this);
          imgButtonArray[goku].setBackground(colorGris);
          imgButtonArray[goku].setIcon(
              ajustar.ajusteCuadrado(new ImageIcon(imagenesbean.get(goku).getIcon())));
          corrobora = true;
        }
      }
    }

    // Comentario
    if (event.getSource() == bcomentario) {
      new Comentario(imagenesbean.get(posicion), posicion);
    }

    // Cuando se apreta un boton de la rejilla
    if (corrobora == true) {
      for (int alice = 0; alice < imgButtonArray.length; alice++) {
        if (event.getSource() == imgButtonArray[alice]) {
          for (int wonderland = 0; wonderland < imgButtonArray.length; wonderland++) {
            imgButtonArray[wonderland].setVisible(false);
          }
          posicion = alice;

          imagen.setIcon(
              ajustar.ajusteImg(
                  new ImageIcon(imagenesbean.get(posicion).getIcon()),
                  imagenesbean.get(posicion).getAncho(),
                  imagenesbean.get(posicion).getAlto(),
                  areaventana.getWidth() - 50,
                  areaventana.getHeight()));

          imagen.setVisible(true);
          siguiente.setVisible(true);
          atras.setVisible(true);
          presentacion.setVisible(true);
          grid.setVisible(true);
          bcomentario.setVisible(true);
          zoom.setVisible(true);
          carpeta.setVisible(true);
        }
      }
    }

    if (event.getSource() == zoom) {
      System.out.println("Haciendo un ZOOOOOOOOOOOOM");
    }
  }