private void jMenuItemImportActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItemImportActionPerformed JFileChooser jfc = new JFileChooser(); jfc.setMultiSelectionEnabled(true); if (lastPath != null) { jfc.setCurrentDirectory(lastPath); } int fileDialogReturnVal = jfc.showOpenDialog(this); // now select the file if (fileDialogReturnVal == JFileChooser.APPROVE_OPTION) { // add code here to allow selection of a document class DocumentClassDialog d = DocumentClassDialog.showClassDialog(this, this.theProject); DocumentClass selectedClass = d.getSelectedDocumentClass(); File[] selected = jfc.getSelectedFiles(); for (int i = 0; i < selected.length; i++) { theProject.addNewDocument(selected[i], 1.0f, selected[i].toString(), selectedClass); } docFrameTableModel.fireTableDataChanged(); lastPath = new File(jfc.getSelectedFile().getPath()); } } // GEN-LAST:event_jMenuItemImportActionPerformed
/** Call this to browse for a custom gradle executor. */ private void browseForCustomGradleExecutor() { File startingDirectory = new File(SystemProperties.getInstance().getUserHome()); File currentFile = gradlePluginLord.getCustomGradleExecutor(); if (currentFile != null) { startingDirectory = currentFile.getAbsoluteFile(); } else { if (gradlePluginLord.getCurrentDirectory() != null) { startingDirectory = gradlePluginLord.getCurrentDirectory(); } } JFileChooser chooser = new JFileChooser(startingDirectory); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); File file = null; if (chooser.showOpenDialog(mainPanel) == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); } if (file != null) { setCustomGradleExecutor(file); } else { // if they canceled, and they have no custom gradle executor specified, then we must // clear things // This will reset the UI back to 'not using a custom executor'. We can't have them check the // field and not have a value here. if (gradlePluginLord.getCustomGradleExecutor() == null) { setCustomGradleExecutor(null); } } }
/** * Actions-handling method. * * @param e The event. */ public void actionPerformed(ActionEvent e) { // Prepares the file chooser JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(idata.getInstallPath())); fc.setMultiSelectionEnabled(false); fc.addChoosableFileFilter(fc.getAcceptAllFileFilter()); // fc.setCurrentDirectory(new File(".")); // Shows it try { if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { // We handle the xml data writing File file = fc.getSelectedFile(); FileOutputStream out = new FileOutputStream(file); BufferedOutputStream outBuff = new BufferedOutputStream(out, 5120); parent.writeXMLTree(idata.xmlData, outBuff); outBuff.flush(); outBuff.close(); autoButton.setEnabled(false); } } catch (Exception err) { err.printStackTrace(); JOptionPane.showMessageDialog( this, err.toString(), parent.langpack.getString("installer.error"), JOptionPane.ERROR_MESSAGE); } }
/** * Create text panel with the specified title, text, and mode * * @param container Reference to the container of this panel * @param title Title for this panel, to appear in the title field of a frame, or title of a tab * @param filename The name of the file to be opened * @param type The predefined file type * @param project */ public EPlusEditorPanel( Container container, String title, String filename, FileType type, JEPlusProject project) { initComponents(); initRSTA(type.getRSTA_Style()); FC.setFileFilter(type.getFileFilter()); FC.setMultiSelectionEnabled(false); this.ContainerComponent = container; this.Title = title; this.CurrentFileName = filename; if (CurrentFileName != null) { this.rsTextArea.setText(getFileContent(CurrentFileName)); } this.ContentType = type; this.ContentChanged = false; this.Project = project; switch (ContentType) { case IDF: updateSearchStrings((Project == null) ? null : Project.getSearchStrings()); this.cmdLoad.setEnabled(true); this.cmdCheck.setEnabled(false); this.cmdSave.setEnabled(true); break; case EPW: case RVI: updateSearchStrings(null); this.cmdLoad.setEnabled(false); this.cmdCheck.setEnabled(false); this.cmdSave.setEnabled(true); break; case RVX: updateSearchStrings(RVX.quickIndex()); this.cmdLoad.setEnabled(false); this.cmdCheck.setEnabled(true); this.cmdSave.setEnabled(true); break; case JSON: updateSearchStrings(null); this.cmdLoad.setEnabled(false); this.cmdCheck.setEnabled(true); this.cmdSave.setEnabled(false); break; case PYTHON: case CSV: case XML: case PLAIN: default: updateSearchStrings(null); this.cmdLoad.setEnabled(true); this.cmdCheck.setEnabled(false); this.cmdSave.setEnabled(true); } // this.cboSearchStrings.setEditable(true); this.Document = rsTextArea.getDocument(); Document.addDocumentListener(this); }
/** * Display a file chooser dialog box. * * @param owner <code>Component</code> which 'owns' the dialog * @param mode Can be either <code>OPEN</code>, <code>SCRIPT</code> or <code>SAVE</code> * @return The path to selected file, null otherwise */ public static String chooseFile(Component owner, int mode) { JFileChooser chooser = getFileChooser(owner, mode); chooser.setMultiSelectionEnabled(false); if (chooser.showDialog(owner, null) == JFileChooser.APPROVE_OPTION) { /*Jext*/ AbstractEditorPanel.setProperty( "lastdir." + mode, chooser.getSelectedFile().getParent()); return chooser.getSelectedFile().getAbsolutePath(); } else owner.repaint(); return null; }
private void fileLocButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_fileLocButtonActionPerformed JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Zip Archive (.zip)", "zip"); fileChooser.setFileFilter(filter); fileChooser.setMultiSelectionEnabled(false); if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { loadVCardFile(fileChooser.getSelectedFile()); } checkCurrentPIN(); } // GEN-LAST:event_fileLocButtonActionPerformed
/** Browses for a file using the text value from the text field as the current value. */ private File browseForDirectory(File initialFile) { if (initialFile == null) { initialFile = SystemProperties.getInstance().getCurrentDir(); } JFileChooser chooser = new JFileChooser(initialFile); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); File file = null; if (chooser.showOpenDialog(mainPanel) == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); } return file; }
private void openFile() { // opens a single file chooser (can select multiple), does not traverse folders. this.copyList = new ArrayList(); final JFileChooser fc = new JFileChooser(currentPath); fc.setMultiSelectionEnabled(true); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter filterhtml = new FileNameExtensionFilter("HTML File (.html)", "html"); fc.addChoosableFileFilter(filterhtml); fc.setFileFilter(filterhtml); int result = fc.showOpenDialog(FrontEnd.this); dir = fc.getCurrentDirectory(); dirImp = dir.toString(); switch (result) { case JFileChooser.APPROVE_OPTION: for (File file1 : fc.getSelectedFiles()) { fileImp = file1.toString(); boolean exists = false; for (int i = 0; i < table.getRowCount(); i++) { dir = fc.getCurrentDirectory(); dirImp = dir.toString(); String copyC = dtm.getValueAt(i, 0).toString(); if (duplC.isSelected()) { if (fileImp.endsWith(copyC)) { exists = true; break; } } } if (!exists) { addRow(); dtm.setValueAt(fileImp.substring(67), curRow, 0); dtm.setValueAt(dirImp.substring(67), curRow, 1); curRow++; if (headC == 1) { if (fileImp.substring(67).endsWith(dirImp.substring(67) + ".html")) { curRow--; dtm.removeRow(curRow); } } } } case JFileChooser.CANCEL_OPTION: break; } }
void doEditFilename() { // create the file open dialog final JFileChooser jf = new JFileChooser(); // cancel multiple selections jf.setMultiSelectionEnabled(false); // set the start directory if (_lastDirectory != null) { jf.setCurrentDirectory(new File(_lastDirectory)); } else { String val = ""; // see if we have an old directory to retrieve val = Application.getThisProperty("RANGE_Directory"); // give it a default value, if we have to if (val == null) val = ""; // try to get the import directory jf.setCurrentDirectory(new File(val)); } // open the dialog final int state = jf.showOpenDialog(null); // do we have a valid file? if (state == JFileChooser.APPROVE_OPTION) { // retrieve the filename final File theFile = jf.getSelectedFile(); _theFilename = theFile.getPath(); // retrieve the directory name _lastDirectory = theFile.getParent(); // trigger a refresh refreshForm(); } else if (state == JFileChooser.CANCEL_OPTION) { _theFilename = null; } }
private void jButtonWorkingDirectoryBrowseActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButtonWorkingDirectoryBrowseActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); String workDir = jTextWorkingDirectory.getText(); if (workDir.equals("")) { workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath(); } chooser.setSelectedFile(new File(workDir)); chooser.setDialogTitle( NbBundle.getMessage( CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory_Browse_Title")); // NOI18N if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { // NOI18N File file = FileUtil.normalizeFile(chooser.getSelectedFile()); jTextWorkingDirectory.setText(file.getAbsolutePath()); } } // GEN-LAST:event_jButtonWorkingDirectoryBrowseActionPerformed
public static void startGui(MusicLibraryAgent musicLibraryAgent) { /* Set the Nimbus look and feel */ // <editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Windows".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(MainFrame.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(MainFrame.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(MainFrame.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MainFrame.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } // </editor-fold> fc.setMultiSelectionEnabled(true); fc.setCurrentDirectory(new File("D:")); final MainFrame mainFrame = new MainFrame(musicLibraryAgent); /* Create and display the form */ java.awt.EventQueue.invokeLater( new Runnable() { public void run() { mainFrame.setVisible(true); } }); }
private void prepareChooser(SipModel sipModel) { File directory = new File(sipModel.getPreferences().get(RECENT_DIR, System.getProperty("user.home"))); chooser.setCurrentDirectory(directory); chooser.setFileFilter( new FileFilter() { @Override public boolean accept(File file) { return file.isFile() && (file.getName().endsWith(".xml") || file.getName().endsWith(".xml.gz") || file.getName().endsWith(".xml.zip") || file.getName().endsWith(".csv")); } @Override public String getDescription() { return "Files ending with .xml, .xml.gz, .xml.zip, or .csv"; } }); chooser.setMultiSelectionEnabled(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; }
@SuppressWarnings({"unchecked", "serial"}) public SourcesSelector(final ProcessLog logger) { super(new BorderLayout(0, 5)); this.logger = logger; JPanel buttons = new JPanel(new GridLayout(5, 1, 0, 10)); buttons.add( new JButton( new AbstractAction("Add Source") { @Override public void actionPerformed(ActionEvent e) { chooser.showOpenDialog(null); } })); buttons.add( new JButton( new AbstractAction("Load Sources") { @Override public void actionPerformed(ActionEvent e) { // TODO: use an xml config file to load sources from a saved file refreshModules(); } })); buttons.add( new JButton( new AbstractAction("Remove Source") { @Override public void actionPerformed(ActionEvent e) { int[] selected = list.getSelectedIndices(); int pos = selected.length; while (pos > 0) dir.remove(selected[--pos]); refreshModules(); } })); buttons.add( new JButton( new AbstractAction("Remove All Sources") { @Override public void actionPerformed(ActionEvent e) { dir.removeAllElements(); refreshModules(); } })); buttons.add( new JButton( new AbstractAction("Clear Log") { @Override public void actionPerformed(ActionEvent e) { logger.clear(); } })); splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); splitter.setLeftComponent(buttons); dir = new DefaultListModel(); chooser = new JFileChooser(); chooser.setFileFilter( new FileFilter() { @Override public String getDescription() { return "Directories Or Jars"; } @Override public boolean accept(File f) { return f.isDirectory() || f.toString().endsWith(".jar"); } }); chooser.setMultiSelectionEnabled(true); chooser.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (File f : chooser.getSelectedFiles()) { int ind = dir.indexOf(f); if (ind > -1) dir.remove(ind); dir.add(0, f); } refreshModules(); } }); list = new JList(dir); list.setCellRenderer( new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { try { File f = (File) value; if (f.isDirectory()) { return super.getListCellRendererComponent( list, f.toString(), index, isSelected, cellHasFocus); } else { return super.getListCellRendererComponent( list, f.getName(), index, isSelected, cellHasFocus); } } catch (Exception e) { e.printStackTrace(); } return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); list.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int[] selected = list.getSelectedIndices(); if (selected.length > 0) { File f = (File) dir.get(selected[0]); if (f.isDirectory()) { chooser.setCurrentDirectory(f); } else { chooser.setCurrentDirectory(f.getParentFile()); } } } }); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); JScrollPane scroller = new JScrollPane( list, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); splitter.setRightComponent(scroller); add(splitter); splitter.setDividerLocation(0.5); }
public static void addToPlaylist() { if (logger.isDebugEnabled()) logger.debug("Add to playlist (methode without parameters)."); JFileChooser choixFichier = new JFileChooser(); choixFichier.setFileSelectionMode(JFileChooser.FILES_ONLY); choixFichier.setMultiSelectionEnabled(true); }
@Override void mergeTiffs() { JFileChooser jf = new JFileChooser(); jf.setDialogTitle(bundle.getString("Select") + " Input Images"); jf.setCurrentDirectory(imageFolder); jf.setMultiSelectionEnabled(true); FileFilter tiffFilter = new SimpleFilter("tif;tiff", "TIFF"); FileFilter jpegFilter = new SimpleFilter("jpg;jpeg", "JPEG"); FileFilter gifFilter = new SimpleFilter("gif", "GIF"); FileFilter pngFilter = new SimpleFilter("png", "PNG"); FileFilter bmpFilter = new SimpleFilter("bmp", "Bitmap"); FileFilter allImageFilter = new SimpleFilter("tif;tiff;jpg;jpeg;gif;png;bmp", "All Image Files"); jf.addChoosableFileFilter(tiffFilter); jf.addChoosableFileFilter(jpegFilter); jf.addChoosableFileFilter(gifFilter); jf.addChoosableFileFilter(pngFilter); jf.addChoosableFileFilter(bmpFilter); jf.addChoosableFileFilter(allImageFilter); if (selectedFilter != null) { jf.setFileFilter(selectedFilter); } jf.setAcceptAllFileFilterUsed(false); if (jf.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { selectedFilter = jf.getFileFilter(); final File[] inputs = jf.getSelectedFiles(); imageFolder = jf.getCurrentDirectory(); jf = new JFileChooser(); jf.setDialogTitle(bundle.getString("Save") + " Multi-page TIFF Image"); jf.setCurrentDirectory(imageFolder); jf.setFileFilter(tiffFilter); jf.setAcceptAllFileFilterUsed(false); if (jf.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File selectedFile = jf.getSelectedFile(); if (!(selectedFile.getName().endsWith(".tif") || selectedFile.getName().endsWith(".tiff"))) { selectedFile = new File(selectedFile.getParent(), selectedFile.getName() + ".tif"); } final File outputTiff = selectedFile; if (outputTiff.exists()) { outputTiff.delete(); } jLabelStatus.setText(bundle.getString("Merge_running...")); jProgressBar1.setIndeterminate(true); jProgressBar1.setString(bundle.getString("Merge_running...")); jProgressBar1.setVisible(true); getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); getGlassPane().setVisible(true); SwingWorker worker = new SwingWorker<File, Void>() { @Override protected File doInBackground() throws Exception { ImageIOHelper.mergeTiff(inputs, outputTiff); return outputTiff; } @Override protected void done() { jLabelStatus.setText(bundle.getString("Mergecompleted")); jProgressBar1.setIndeterminate(false); jProgressBar1.setString(bundle.getString("Mergecompleted")); try { File result = get(); JOptionPane.showMessageDialog( GuiWithTools.this, bundle.getString("Mergecompleted") + result.getName() + bundle.getString("created"), APP_NAME, JOptionPane.INFORMATION_MESSAGE); } catch (InterruptedException ignore) { ignore.printStackTrace(); } catch (java.util.concurrent.ExecutionException e) { String why = null; Throwable cause = e.getCause(); if (cause != null) { if (cause instanceof OutOfMemoryError) { why = bundle.getString("OutOfMemoryError"); } else { why = cause.getMessage(); } } else { why = e.getMessage(); } e.printStackTrace(); JOptionPane.showMessageDialog( GuiWithTools.this, why, APP_NAME, JOptionPane.ERROR_MESSAGE); } finally { jProgressBar1.setVisible(false); getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); getGlassPane().setVisible(false); } } }; worker.execute(); } } }
public void secureImport() { JFileChooser imp = new JFileChooser(); imp.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); imp.setMultiSelectionEnabled(true); int ret = imp.showOpenDialog(frm); if (ret != JFileChooser.APPROVE_OPTION) { return; } File[] fis = imp.getSelectedFiles(); ArrayList<String> impJobs = new ArrayList<String>(); boolean dirs = false; for (File fi : fis) { if (fi.isDirectory()) { dirs = true; File lib = new File(fi, LIBRARY_NAME); if (lib.exists()) { try { Scanner sca = new Scanner(lib); while (sca.hasNextLine()) { String nm = sca.nextLine(); String date = sca.nextLine(); String tags = sca.nextLine(); File addr = new File(fi, nm); if (addr.exists() && !addr.isDirectory()) impJobs.add(impJob(addr, date, tags)); } sca.close(); } catch (IOException exc) { // add nothing? } } else { for (File cont : fi.listFiles()) if (!cont.isDirectory()) impJobs.add(impJob(cont, null, null)); } } else { impJobs.add(impJob(fi, null, null)); } } if (impJobs.size() > 1 || dirs) { // dont bother user if selected single file String shw = "Importing:"; if (impJobs.size() > 30) shw = null; int pcount = 0; for (String jb : impJobs) { String[] prts = jb.split(",", 4); // import jobs have 4 parts, import, name, date, tags if (shw != null) shw = shw + "\n - " + new File(prts[1]).getName(); if (!prts[3].equalsIgnoreCase(Storage.NEW_TAG)) { pcount++; if (shw != null) shw = shw + " []"; } } if (shw == null) shw = "importing "; else shw = shw + "\n"; shw = shw + impJobs.size() + "(" + pcount + ") files"; if (JOptionPane.showConfirmDialog(frm, shw, "Confirm Import", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) return; } synchronized (jobs) { for (String j : impJobs) { if (priorityExport) jobs.addLast(j); else jobs.addFirst(j); } } updateStatus(); }
public Viewer() { leveldbStore.setMultiSelectionEnabled(false); leveldbStore.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); putButton.setEnabled(false); key.setEnabled(false); value.setEnabled(false); findField.setEnabled(false); deleteButton.setEnabled(false); saveButton.setEnabled(false); putType.setEnabled(false); putType.setEditable(false); signedBox.setEnabled(false); openButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (openButton.isEnabled()) { openButton.setEnabled(false); new Thread() { public void run() { if (leveldbStore.showOpenDialog(pane) == JFileChooser.APPROVE_OPTION) { File select = leveldbStore.getSelectedFile(); if (select.isDirectory()) { new OpenLevelDBDialog(Viewer.this, select); openDatabase(select); dbPathField.setText(select.getAbsolutePath()); } else { JOptionPane.showMessageDialog( pane, "The selecting item must be a directory", "Unable to load database", JOptionPane.WARNING_MESSAGE); } } else { openButton.setEnabled(true); } } }.start(); } } }); deleteButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (dataList.getSelectedValue() != null) { delete(dataList.getSelectedValue().key); } openDatabase(leveldbStore.getSelectedFile()); } }); putButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { put( ((PutType) putType.getSelectedItem()).getBytes(key.getText()), ((PutType) putType.getSelectedItem()).getBytes(value.getText())); openDatabase(leveldbStore.getSelectedFile()); } }); findField.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openDatabase(leveldbStore.getSelectedFile()); } }); findField .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { openDatabase(leveldbStore.getSelectedFile()); } @Override public void removeUpdate(DocumentEvent e) { openDatabase(leveldbStore.getSelectedFile()); } @Override public void changedUpdate(DocumentEvent e) { openDatabase(leveldbStore.getSelectedFile()); } }); findField .getDocument() .addUndoableEditListener( new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { openDatabase(leveldbStore.getSelectedFile()); } }); hexKey .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { update(hexKey); } @Override public void removeUpdate(DocumentEvent e) { update(hexKey); } @Override public void changedUpdate(DocumentEvent e) { update(hexKey); } }); hexKey .getDocument() .addUndoableEditListener( new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { update(hexKey); } }); stringKey .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { update(stringKey); } @Override public void removeUpdate(DocumentEvent e) { update(stringKey); } @Override public void changedUpdate(DocumentEvent e) { update(stringKey); } }); stringKey .getDocument() .addUndoableEditListener( new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { update(stringKey); } }); hexValue .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { update(hexValue); } @Override public void removeUpdate(DocumentEvent e) { update(hexValue); } @Override public void changedUpdate(DocumentEvent e) { update(hexValue); } }); hexValue .getDocument() .addUndoableEditListener( new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { update(hexValue); } }); stringValue .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { update(stringValue); } @Override public void removeUpdate(DocumentEvent e) { update(stringValue); } @Override public void changedUpdate(DocumentEvent e) { update(stringValue); } }); stringValue .getDocument() .addUndoableEditListener( new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { update(stringValue); } }); saveButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { save(); openDatabase(leveldbStore.getSelectedFile()); } }); dataList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); dataList.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { DBItem item = dataList.getSelectedValue(); if (item != null) { hexValue.setText(cutToLine(LevelDBViewer.toHexString(item.value), 64)); stringValue.setText(cutToLine(new String(item.value), 64)); hexKey.setText(cutToLine(LevelDBViewer.toHexString(item.key), 64)); stringKey.setText(cutToLine(new String(item.key), 64)); lengthLabel.setText(String.valueOf(item.value.length + item.key.length)); keyLength.setText(String.valueOf(item.key.length)); valueLength.setText(String.valueOf(item.value.length)); } } }); signedBox.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { LevelDBViewer.DEFAULT_SINGED = signedBox.isSelected(); int i = dataList.getSelectedIndex(); dataList.clearSelection(); dataList.updateUI(); dataList.setSelectedIndex(i); update(hexKey); update(hexValue); } }); for (PutType t : PutType.values()) { putType.addItem(t); } putType.setSelectedItem(PutType.STRING); putType.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { openDatabase(leveldbStore.getSelectedFile()); } }); putType.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openDatabase(leveldbStore.getSelectedFile()); } }); dialog.setLocationByPlatform(true); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setContentPane(pane); dialog.setTitle("LevelDB Viewer By Marcus (https://github.com/SuperMarcus)"); dialog.getRootPane().setDefaultButton(openButton); dialog.pack(); dialog.setVisible(true); }
/** Called for button presses and checkbox toggles. */ public void actionPerformed(ActionEvent e) { Object src = e.getSource(); // the source of the event is the add files button // so we need to let the user add some files! if (src == addFiles) { // create an appropriate file chooser JFileChooser myTempFileChooser = new JFileChooser((new File("")).getAbsolutePath()); myTempFileChooser.setMultiSelectionEnabled(true); myTempFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); myTempFileChooser.setDialogType(JFileChooser.OPEN_DIALOG); myTempFileChooser.setFileHidingEnabled(true); // open the file chooser and get the user's selctions int returnCode = myTempFileChooser.showOpenDialog(this); // use the return info to add files if the // user selected any in the file chooser if (returnCode == JFileChooser.APPROVE_OPTION) { // grab the files the user selected File[] selectedFiles = myTempFileChooser.getSelectedFiles(); // pull the files into the list changeFilesInList.importFileData(list, selectedFiles); } } // the source of the event was the process button else if (src == process) { if (((DefaultListModel) list.getModel()).size() == 0) return; setComponentsEnabled(false); final ThumbMaker tm = this; Thread t = new Thread( new Runnable() { public void run() { tm.process(); setComponentsEnabled(true); } }); t.start(); // because we can't do it on quit, we are going to save // all the preference values when the user processes a set // of images savePreferences(); } // the source of the event was the remove button else if (src == remove) { DefaultListModel model = (DefaultListModel) list.getModel(); while (true) { int ndx = list.getSelectedIndex(); if (ndx < 0) break; model.removeElementAt(ndx); } } // the source of the event was the preserve aspect check box else if (src == aspect) { boolean b = aspect.isSelected(); colorLabel.setEnabled(b); colorBox.setEnabled(b); redLabel.setEnabled(b); red.setEnabled(b); redValue.setEnabled(b); greenLabel.setEnabled(b); green.setEnabled(b); greenValue.setEnabled(b); blueLabel.setEnabled(b); blue.setEnabled(b); blueValue.setEnabled(b); } // the source of the event is the "..." button, // we need to let the user select a destination file else if (src == dotDotDot) { // create an appropriate file chooser JFileChooser myTempFileChooser = new JFileChooser(new File(output.getText()).getAbsolutePath()); myTempFileChooser.setMultiSelectionEnabled(false); myTempFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); myTempFileChooser.setDialogType(JFileChooser.OPEN_DIALOG); myTempFileChooser.setFileHidingEnabled(true); // open the file chooser and get the user's selctions int returnCode = myTempFileChooser.showOpenDialog(this); // use the return info to set the directory if the // user selected one in the file chooser if (returnCode == JFileChooser.APPROVE_OPTION) { // grab the file the user selected File selectedFile = myTempFileChooser.getSelectedFile(); // stuff the file path into the text field output.setText(selectedFile.getAbsolutePath()); } } }