Beispiel #1
0
  public Path dateiAuswählen(Path neuesLaufwerk) {
    JFileChooser fc1 = new JFileChooser();
    fc1.setDialogTitle("SyncOrdner auswählen");
    fc1.setCurrentDirectory(neuesLaufwerk.toFile());
    fc1.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    if (fc1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
      return fc1.getSelectedFile().toPath();
    else return null;
  }
Beispiel #2
0
 public void actionPerformed(ActionEvent e) {
   JFileChooser chooser = new JFileChooser();
   chooser.setDialogTitle("Load");
   int choice = 0;
   do {
     int result = chooser.showOpenDialog(null);
     if (result == JFileChooser.APPROVE_OPTION) {
       file = chooser.getSelectedFile();
       try {
         if (file != null) {
           fileName = file.getCanonicalPath();
           reader = new BufferedReader(new FileReader(fileName));
           String line;
           while ((line = reader.readLine()) != null) {
             myPatternList.add(line);
           }
           //							for(int i=0;i<myPatternList.size();i++) {
           //								responseArea.append(myPatternList.get(i)+"\n");
           //							}
         }
         choice = 2;
         reader.close();
       } catch (IOException c) {
         c.printStackTrace();
         Object[] options = new String[] {"Load New File", "Exit"};
         choice =
             JOptionPane.showOptionDialog(
                 null,
                 "Invalid FileChoosen." + "Would you like to load a new file " + "or exit?",
                 "Options",
                 JOptionPane.YES_NO_OPTION,
                 JOptionPane.ERROR_MESSAGE,
                 null,
                 options,
                 options[0]);
         if (choice == 1) System.exit(0);
       }
     } else if (result == JFileChooser.CANCEL_OPTION) {
       Object[] options = new String[] {"Load Different File", "Exit"};
       choice =
           JOptionPane.showOptionDialog(
               null,
               "Would you like to load a new file " + " or exit?",
               "Options",
               JOptionPane.YES_NO_OPTION,
               JOptionPane.ERROR_MESSAGE,
               null,
               options,
               options[0]);
       if (choice == 1) System.exit(0);
     }
   } while (choice == 0);
 }
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == save) {
     JFileChooser c = new JFileChooser(ResourceFactory.getRootDir());
     c.setDialogTitle("Save result");
     if (c.showSaveDialog(resultFrame) == JFileChooser.APPROVE_OPTION) {
       File output = c.getSelectedFile();
       if (output.exists()) {
         String[] options = {"Overwrite", "Cancel"};
         if (JOptionPane.showOptionDialog(
                 resultFrame,
                 output + "exists. Overwrite?",
                 "Save result",
                 JOptionPane.YES_NO_OPTION,
                 JOptionPane.WARNING_MESSAGE,
                 null,
                 options,
                 options[0])
             == 1) return;
       }
       try {
         PrintWriter w = new PrintWriter(new BufferedWriter(new FileWriter(output)));
         w.println("Searched for unused strings");
         w.println("Number of hits: " + table.getRowCount());
         w.println("");
         for (int i = 0; i < table.getRowCount(); i++) {
           w.println(
               "StringRef: "
                   + table.getTableItemAt(i).getObjectAt(1)
                   + " /* "
                   + table
                       .getTableItemAt(i)
                       .toString()
                       .replaceAll("\r\n", System.getProperty("line.separator"))
                   + " */");
         }
         w.close();
         JOptionPane.showMessageDialog(
             resultFrame,
             "Result saved to " + output,
             "Save complete",
             JOptionPane.INFORMATION_MESSAGE);
       } catch (IOException ex) {
         JOptionPane.showMessageDialog(
             resultFrame, "Error while saving " + output, "Error", JOptionPane.ERROR_MESSAGE);
         ex.printStackTrace();
       }
     }
   }
 }
Beispiel #4
0
    public void actionPerformed(ActionEvent e) {
      JFileChooser chooser = new JFileChooser();
      chooser.setDialogTitle("SaveAs");
      int choice = 0;
      do {
        int result = chooser.showOpenDialog(null);
        if (result == JFileChooser.APPROVE_OPTION) {
          file = chooser.getSelectedFile();
          try {
            if (file != null) {
              fileName = file.getCanonicalPath();
              printWriter = new PrintWriter(new FileOutputStream(fileName), true);
            }
            printWriter.append(responseArea.getText());
            choice = 2;

          } catch (IOException c) {
            c.printStackTrace();
            Object[] options = new String[] {"Choose New File", "Exit"};
            choice =
                JOptionPane.showOptionDialog(
                    null,
                    "Invalid FileChoosen." + "Would you like to choose a new file " + "or exit?",
                    "Options",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.ERROR_MESSAGE,
                    null,
                    options,
                    options[0]);
            if (choice == 1) System.exit(0);
          }
        } else if (result == JFileChooser.CANCEL_OPTION) {
          Object[] options = new String[] {"Choose Different File", "Exit"};
          choice =
              JOptionPane.showOptionDialog(
                  null,
                  "Would you like to choose a new file " + " or exit?",
                  "Options",
                  JOptionPane.YES_NO_OPTION,
                  JOptionPane.ERROR_MESSAGE,
                  null,
                  options,
                  options[0]);
          if (choice == 1) System.exit(0);
        }
      } while (choice == 0);
      printWriter.flush();
      printWriter.close();
    }
    /**
     * Show the selector for selecting the default folder.
     *
     * @return true if the user selected a default folder and false if not.
     */
    protected boolean showDefaultFolderSelector() throws Exception {
      final JFileChooser selector = new JFileChooser(_activeFileChooser.getCurrentDirectory());
      selector.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      final String title =
          (_subfolderName == null)
              ? "Default Folder"
              : "Default Parent Folder of " + _subfolderName;
      selector.setDialogTitle(title);
      final int status = selector.showDialog(_view, "Make Default");

      switch (status) {
        case JFileChooser.APPROVE_OPTION:
          final File defaultFolder = selector.getSelectedFile();
          if (defaultFolder != null) {
            _folderTracker.cacheURL(defaultFolder.toURI().toURL());
            return true;
          } else {
            return false;
          }
        default:
          return false;
      }
    }
  private ObjectOutputStream getObjectOutputStream() {
    File f = new File(".");
    String loadDirectory = f.getAbsolutePath();

    JFileChooser chooser = new JFileChooser(loadDirectory);
    chooser.setDialogTitle("Save Generation File As...");
    chooser.setMultiSelectionEnabled(false);

    int result = chooser.showSaveDialog(this);
    File selectedFile = chooser.getSelectedFile();

    if (result == JFileChooser.APPROVE_OPTION) {
      try {
        FileOutputStream fileStream = new FileOutputStream(selectedFile.getPath());
        ObjectOutputStream objectStream = new ObjectOutputStream(fileStream);

        return objectStream;
      } catch (IOException e) {
        System.err.println(e);
      }
    }

    return null;
  }
Beispiel #7
0
  private void createOpsMenu() {
    opsMenu = new JMenu("Ops");
    menuBar.add(opsMenu);

    insertItem = new JMenuItem("Insert...");
    opsMenu.add(insertItem);
    final Object[] insertMsg = new Object[4];
    insertMsg[0] = "Key:";
    final JTextField insertKey = new JTextField("");
    insertMsg[1] = insertKey;
    insertMsg[2] = "Data:";
    final JTextField insertData = new JTextField("");
    insertMsg[3] = insertData;
    insertItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            int response =
                JOptionPane.showOptionDialog(
                    MainWindow.this,
                    insertMsg,
                    "Insert",
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.PLAIN_MESSAGE,
                    null,
                    null,
                    null);
            if (response != JOptionPane.OK_OPTION) {
              return;
            }

            // insert new item
            cmd.reset();
            cmd.cmdType = LibgistCommand.INSERT;
            cmd.key.append(insertKey.getText());
            cmd.data.append(insertData.getText());
            opThread.dispatchCmd(cmd);
          }
        });

    deleteItem = new JMenuItem("Delete...");
    opsMenu.add(deleteItem);
    final Object[] deleteMsg = new Object[2];
    deleteMsg[0] = "Query:";
    final JTextField deleteQuery = new JTextField("");
    deleteMsg[1] = deleteQuery;
    deleteItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            int response =
                JOptionPane.showOptionDialog(
                    MainWindow.this,
                    deleteMsg,
                    "Delete",
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.PLAIN_MESSAGE,
                    null,
                    null,
                    null);
            if (response != JOptionPane.OK_OPTION) {
              return;
            }

            // delete item(s)
            cmd.reset();
            cmd.cmdType = LibgistCommand.REMOVE;
            cmd.qual.append(deleteQuery.getText());
            opThread.dispatchCmd(cmd);
          }
        });

    searchItem = new JMenuItem("Search...");
    opsMenu.add(searchItem);
    final Object[] searchMsg = new Object[4];
    searchMsg[0] = "Query:";
    final JTextField searchQuery = new JTextField("");
    searchMsg[1] = searchQuery;
    searchMsg[2] = "Retrieval Limit:";
    final JTextField retrLimit = new JTextField("");
    searchMsg[3] = retrLimit;
    searchItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            int response =
                JOptionPane.showOptionDialog(
                    MainWindow.this,
                    searchMsg,
                    "Search",
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.PLAIN_MESSAGE,
                    null,
                    null,
                    null);
            if (response != JOptionPane.OK_OPTION) {
              return;
            }
            int limit = 0; // 0 means "get them all"
            // if no limit is specified: we leave it at 0
            if (retrLimit.getText() != null) {
              try {
                limit = Integer.parseInt(retrLimit.getText());
              } catch (NumberFormatException e) {
                // user typed junk
                limit = 0;
                retrLimit.setText("");
              }
            }

            // execute query
            cmd.reset();
            cmd.cmdType = LibgistCommand.FETCH;
            cmd.qual.append(searchQuery.getText());
            cmd.fetchLimit = limit;
            opThread.dispatchCmd(cmd);
          }
        });

    executeItem = new JMenuItem("Execute...");
    final JFileChooser executeChooser = new JFileChooser(".");
    executeChooser.setDialogTitle("Execute Script");
    executeChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    opsMenu.add(executeItem);
    executeItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            // let user choose script file
            int retval = executeChooser.showDialog(MainWindow.this, "Execute");
            if (retval != 0) {
              return;
            }

            // execute script
            cmd.reset();
            cmd.cmdType = LibgistCommand.SCRIPT;
            cmd.scriptFile.append(executeChooser.getSelectedFile().getPath());
            opThread.dispatchCmd(cmd);
          }
        });
  }
Beispiel #8
0
  private void createFileMenu() {
    fileMenu = new JMenu("File");
    menuBar.add(fileMenu);

    newItem = new JMenuItem("New...");
    fileMenu.add(newItem);
    // construct components of option pane to input name and type of new AM
    final Object[] newMsg = new Object[3];
    newMsg[0] = "Name for new AM:";
    final JTextField newName = new JTextField("new-am");
    newMsg[1] = newName;
    final JComboBox cb = new JComboBox();
    for (int i = 0; i < Libgist.extInfo.length; i++) {
      cb.addItem(Libgist.extInfo[i].name);
    }
    newMsg[2] = cb;
    newItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // first close the currently opened index
            int response =
                JOptionPane.showOptionDialog(
                    MainWindow.this,
                    newMsg,
                    "New",
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.PLAIN_MESSAGE,
                    null,
                    null,
                    null);
            if (response != JOptionPane.OK_OPTION) {
              return;
            }

            // create new AM
            cmd.reset();
            cmd.cmdType = LibgistCommand.CREATE;
            cmd.indexName.append(newName.getText());
            cmd.extension.append(Libgist.extInfo[cb.getSelectedIndex()]);
            opThread.dispatchCmd(cmd);
          }
        });

    openItem = new JMenuItem("Open...");
    final JFileChooser openChooser = new JFileChooser(".");
    openChooser.setDialogTitle("Open Index");
    openChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileMenu.add(openItem);
    openItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            // first close currently opened index
            // let user choose index file
            int retval = openChooser.showOpenDialog(MainWindow.this);
            if (retval != 0) {
              return;
            }
            String fileName = openChooser.getSelectedFile().getPath();

            // open AM
            cmd.reset();
            cmd.cmdType = LibgistCommand.OPEN;
            cmd.indexName.append(fileName);
            opThread.dispatchCmd(cmd);

            enableIndexOpened();
          }
        });

    closeItem = new JMenuItem("Close");
    fileMenu.add(closeItem);
    closeItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            // close AM
            cmd.reset();
            cmd.cmdType = LibgistCommand.CLOSE;
            opThread.dispatchCmd(cmd);
            // MainWindow.this.setTitle("amdb");
          }
        });

    flushItem = new JMenuItem("Flush");
    fileMenu.add(flushItem);
    flushItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            // open AM
            cmd.reset();
            cmd.cmdType = LibgistCommand.FLUSH;
            opThread.dispatchCmd(cmd);
          }
        });

    fileMenu.addSeparator();

    optionsItem = new JMenuItem("Properties...");
    fileMenu.add(optionsItem);
    optionsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Properties.edit();
          }
        });

    settingsItem = new JMenuItem("Save Settings");
    fileMenu.add(settingsItem);
    settingsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            saveConfig();
          }
        });
    fileMenu.addSeparator();
    exitItem = new JMenuItem("Exit");
    fileMenu.add(exitItem);
    exitItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // close AM
            opThread.stopNow();
            Libgist.cleanup();
            System.exit(0);
          }
        });
  }
Beispiel #9
0
  private void createAnalysisMenu() {
    analysisMenu = new JMenu("Analysis");
    menuBar.add(analysisMenu);

    // analysis-related variables
    analysisInfo = new AnalysisInfo();
    wkldStatsDlg = new WkldStatsDlg(this);
    splitStatsDlg = new SplitStatsDlg(this);
    penaltyStatsDlg = new PenaltyStatsDlg(this);

    newAnalysisItem = new JMenuItem("Create Analysis ...");
    analysisMenu.add(newAnalysisItem);
    newAnalysisItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            JOptionPane.showMessageDialog(
                MainWindow.this,
                "Not implemented yet.\nUse command createanl in gistcmdline instead.");
          }
        });

    openAnalysisItem = new JMenuItem("Open Analysis ...");
    final JFileChooser openAnalysisChooser = new JFileChooser(".");
    openAnalysisChooser.setDialogTitle("Open Analysis");
    openAnalysisChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    analysisMenu.add(openAnalysisItem);
    openAnalysisItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            int retval = openAnalysisChooser.showOpenDialog(MainWindow.this);
            if (retval != 0) {
              return;
            }
            File f = openAnalysisChooser.getSelectedFile();

            cmd.reset();
            cmd.cmdType = LibgistCommand.OPENANL;
            cmd.analysisFile = f;
            opThread.dispatchCmd(cmd);
          }
        });

    completeAnalysisItem = new JMenuItem("Complete Analysis ...");
    analysisMenu.add(completeAnalysisItem);
    completeAnalysisItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            JOptionPane.showMessageDialog(
                MainWindow.this,
                "Not implemented yet.\nUse commands wkldstats, splitstats and penaltystats\nin gistcmdline instead.");
          }
        });

    analysisMenu.addSeparator();

    wkldStatsItem = new JMenuItem("Workload Stats ...");
    analysisMenu.add(wkldStatsItem);
    wkldStatsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            wkldStatsDlg.setVisible(true);
          }
        });

    splitStatsItem = new JMenuItem("Split Stats ...");
    analysisMenu.add(splitStatsItem);
    wkldStatsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            splitStatsDlg.setVisible(true);
          }
        });

    penaltyStatsItem = new JMenuItem("Penalty Stats ...");
    analysisMenu.add(penaltyStatsItem);
    penaltyStatsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            penaltyStatsDlg.setVisible(true);
          }
        });
  }
Beispiel #10
0
  public void init() {

    areaventana = new JPanel();
    areabotones = new JPanel();
    imagen = new JLabel("");
    presentacion = new JButton(imgPlay);
    siguiente = new JButton(imgSiguiente);
    atras = new JButton(imgAnterior);
    ptiempo = new JSlider();
    carpeta = new JButton(imgNuevaCarpeta);
    grid = new JButton(imgGrid);
    bcomentario = new JButton(imgComentario);
    zoom = new JButton(imgZoom);

    /* Agregando los componentes */

    areaventana.add(imagen);
    // areaventana.add(desplazamiento);

    areabotones.add(grid);
    areabotones.add(atras);
    areabotones.add(presentacion);
    areabotones.add(siguiente);
    areabotones.add(ptiempo);
    areabotones.add(carpeta);
    areabotones.add(bcomentario);
    areabotones.add(zoom);

    areabotones.setBackground(colorGris);
    areaventana.setBackground(colorGris);

    // desplazamiento.setVisible(false);
    // areaventana.add(desplazamiento);

    /* GUI GUI GUI GUI  */
    presentacion.setBackground(colorGris);
    atras.setBackground(colorGris);
    siguiente.setBackground(colorGris);
    carpeta.setBackground(colorGris);
    grid.setBackground(colorGris);
    ptiempo.setBackground(colorGris);
    bcomentario.setBackground(colorGris);
    zoom.setBackground(colorGris);

    presentacion.setPreferredSize(new Dimension(100, 80));
    atras.setPreferredSize(new Dimension(100, 80));
    siguiente.setPreferredSize(new Dimension(100, 80));
    carpeta.setPreferredSize(new Dimension(100, 80));
    grid.setPreferredSize(new Dimension(100, 80));
    bcomentario.setPreferredSize(new Dimension(100, 80));
    zoom.setPreferredSize(new Dimension(100, 80));

    grid.setFocusPainted(false);
    atras.setFocusPainted(false);
    siguiente.setFocusPainted(false);
    carpeta.setFocusPainted(false);
    presentacion.setFocusPainted(false);
    bcomentario.setFocusPainted(false);
    zoom.setFocusPainted(false);

    grid.setBorder(null);
    atras.setBorder(null);
    siguiente.setBorder(null);
    carpeta.setBorder(null);
    presentacion.setBorder(null);
    areabotones.setBorder(null);
    areaventana.setBorder(null);
    bcomentario.setBorder(null);
    zoom.setBorder(null);
    /* GUI GUI GUI GUI  */

    /* Action Listeners */
    siguiente.addActionListener(this);
    atras.addActionListener(this);
    presentacion.addActionListener(this);
    carpeta.addActionListener(this);
    grid.addActionListener(this);
    bcomentario.addActionListener(this);
    zoom.addActionListener(this);

    this.setLayout(new BorderLayout());
    add(areaventana, BorderLayout.CENTER);
    add(areabotones, BorderLayout.SOUTH);

    ptiempo.setVisible(false);

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

    /* Abre el selector desde que inicia el programa */

    chooser = new JFileChooser();
    chooser.setDialogTitle("Selecciona una imagen...");
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);

    // Abrir archivo es de acá...
    returnChooser = chooser.showOpenDialog(ArcViewer.this);

    if (returnChooser == 0) {

      imagenes = lista.Miranda(chooser, returnChooser);

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

      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;
        }
      }
    } else {
      System.out.println("No Selection");
      carpeta.setEnabled(true);
    }

    // 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;
    // 	}
    // }

  }