public boolean isTraversable(File f) { Boolean traversable = null; if (f != null) { if (getFileView() != null) { traversable = getFileView().isTraversable(f); } FileView uiFileView = getUI().getFileView(this); if (traversable == null && uiFileView != null) { traversable = uiFileView.isTraversable(f); } if (traversable == null) { traversable = getFileSystemView().isTraversable(f); } } return (traversable != null && traversable.booleanValue()); }
/** * Invokes the <code>getFileView</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public FileView getFileView(JFileChooser a) { FileView returnValue = ((FileChooserUI) (uis.elementAt(0))).getFileView(a); for (int i = 1; i < uis.size(); i++) { ((FileChooserUI) (uis.elementAt(i))).getFileView(a); } return returnValue; }
/** * Maps {@code JFileChooser.getFileView()} through queue */ public FileView getFileView() { return (runMapping(new MapAction<FileView>("getFileView") { @Override public FileView map() { return ((JFileChooser) getSource()).getFileView(); } })); }
/** * Maps {@code JFileChooser.setFileView(FileView)} through queue */ public void setFileView(final FileView fileView) { runMapping(new MapVoidAction("setFileView") { @Override public void map() { ((JFileChooser) getSource()).setFileView(fileView); } }); }
/** Return the icon of a File. * <p>Unfortunately Windows and Mac require different * approaches. * * @param file the file to get the icon of. * @return an icon for this file. */ public static Icon getIcon(File file) { if(file==null) throw new NullPointerException(); if(JVM.isWindows) { //on Macs this appears to only return the vanilla folder/file icons: FileSystemView fsv = FileSystemView.getFileSystemView(); Icon icon = fsv.getSystemIcon(file); return icon; } else { //but this returns different icons for different folders/icons: FileView fileView = getFileView(); return fileView.getIcon(file); } }
protected static FileView getFileView() { if(sharedFileView==null) { JFileChooser chooser = new JFileChooser(); sharedFileView = chooser.getUI().getFileView(chooser); } return sharedFileView; }
/** * Sets a custom {@link FileView} for the file chooser and sends a * {@link PropertyChangeEvent} to all registered listeners. The property * name is {@link #FILE_VIEW_CHANGED_PROPERTY}. * * @param fileView the file view (<code>null</code> permitted). * * @see #getFileView() */ public void setFileView(FileView fileView) { if (fv != fileView) { FileView old = fv; fv = fileView; firePropertyChange(FILE_VIEW_CHANGED_PROPERTY, old, fv); } }
/** * Returns a component that can render the specified value. * * @param table the table * @param value the string value of the cell * @param isSelected is the item selected? * @param hasFocus does the item have the focus? * @param row the row * @param column the column * * @return The renderer. */ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (column == 0) { FileView v = getFileView(getFileChooser()); ListModel lm = fileList.getModel(); if (row < lm.getSize()) setIcon(v.getIcon((File) lm.getElementAt(row))); } else setIcon(null); setText(value.toString()); setOpaque(true); setEnabled(table.isEnabled()); setFont(fileList.getFont()); if (startEditing && column == 0 || !isSelected) { setBackground(table.getBackground()); setForeground(table.getForeground()); } else { setBackground(table.getSelectionBackground()); setForeground(table.getSelectionForeground()); } if (hasFocus) setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); else setBorder(noFocusBorder); return this; }
/** * Returns a component that can render the specified value. * * @param list the list. * @param value the value (a {@link File}). * @param index the index. * @param isSelected is the item selected? * @param cellHasFocus does the item have the focus? * * @return The renderer. */ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { FileView v = getFileView(getFileChooser()); File f = (File) value; if (f != null) { setText(v.getName(f)); setIcon(v.getIcon(f)); } else { setText(""); setIcon(null); } setOpaque(true); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } setEnabled(list.isEnabled()); setFont(list.getFont()); if (cellHasFocus) setBorder(UIManager.getBorder("List.focusCellHighlightBorder")); else setBorder(noFocusBorder); return this; }
private void menuOpenProjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuOpenProjectActionPerformed final JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileView(new FileView() { private Icon KNOWLEDGE_FOLDER_ICO = null; @Override public Icon getIcon(final File f) { if (f.isDirectory()) { final File knowledge = new File(f, Context.KNOWLEDGE_FOLDER); if (knowledge.isDirectory()) { if (KNOWLEDGE_FOLDER_ICO == null) { final Icon icon = UIManager.getIcon("FileView.directoryIcon"); //NOI18N if (icon != null) { KNOWLEDGE_FOLDER_ICO = new ImageIcon(UiUtils.makeBadgedRightBottom(UiUtils.iconToImage(fileChooser, icon), Icons.MMDBADGE.getIcon().getImage())); } } return KNOWLEDGE_FOLDER_ICO; } else { return super.getIcon(f); } } else if (f.isFile() && f.getName().toLowerCase(Locale.ENGLISH).endsWith(".mmd")) { //NOI18N return Icons.DOCUMENT.getIcon(); } else { return super.getIcon(f); } } }); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setMultiSelectionEnabled(false); fileChooser.setDialogTitle("Open project folder"); if (fileChooser.showOpenDialog(Main.getApplicationFrame()) == JFileChooser.APPROVE_OPTION) { openProject(fileChooser.getSelectedFile(), false); } }
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseButtonActionPerformed JFileChooser fileChooser = new JFileChooser(PANBOX_DIR + "/" + shareName); fileChooser.setFileView(new FileView() { @Override public Boolean isTraversable(File f) { try { return f.isDirectory() && FilenameUtils.directoryContains( PANBOX_DIR.getAbsolutePath(), f.getAbsolutePath()); } catch (IOException e) { logger.error("Error determining folder parent status!"); return true; } } }); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int ret = fileChooser.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION && fileChooser.getSelectedFile().getParentFile() .getAbsolutePath() .startsWith(PANBOX_DIR.getAbsolutePath())) { String path = getCSPSupportedPath(fileChooser.getSelectedFile() .getPath()); fileTextField.setText(path); fillRevisionsForFileName(path); } }
private void dropboxBrowseButtonActionPerformed( java.awt.event.ActionEvent evt) {// GEN-FIRST:event_dropboxBrowseButtonActionPerformed try { final File dropboxSyncDir = dbClientIntegration.getCurrentSyncDir(); if (dropboxSyncDir != null) { JFileChooser fileChooser = new JFileChooser(dropboxSyncDir); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setFileView(new FileView() { @Override public Boolean isTraversable(File f) { return dropboxSyncDir.equals(f) || dropboxSyncDir.equals(f.getParentFile()); } }); int ret = fileChooser.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION && fileChooser.getSelectedFile().getParentFile() .equals(dropboxSyncDir)) { if (dropboxBrowseButtonClicked) { comboBoxModel .removeElementAt(comboBoxModel.getSize() - 1); } comboBoxModel.addElement(new DropboxShare(fileChooser .getSelectedFile().getName(), fileChooser .getSelectedFile().getAbsolutePath())); dropboxSharesComboBox .setSelectedIndex(dropboxSharesComboBox .getItemCount() - 1); if (nameWasAutoSet) { nameTextField.setText(fileChooser.getSelectedFile() .getName()); } dropboxBrowseButtonClicked = true; } } } catch (IOException e) { // ignore this } }
public String getName(File f) { String filename = null; if(f != null) { if(getFileView() != null) { filename = getFileView().getName(f); } FileView uiFileView = getUI().getFileView(this); if(filename == null && uiFileView != null) { filename = uiFileView.getName(f); } } return filename; }
public String getDescription(File f) { String description = null; if(f != null) { if(getFileView() != null) { description = getFileView().getDescription(f); } FileView uiFileView = getUI().getFileView(this); if(description == null && uiFileView != null) { description = uiFileView.getDescription(f); } } return description; }
public String getTypeDescription(File f) { String typeDescription = null; if(f != null) { if(getFileView() != null) { typeDescription = getFileView().getTypeDescription(f); } FileView uiFileView = getUI().getFileView(this); if(typeDescription == null && uiFileView != null) { typeDescription = uiFileView.getTypeDescription(f); } } return typeDescription; }
public Icon getIcon(File f) { Icon icon = null; if (f != null) { if(getFileView() != null) { icon = getFileView().getIcon(f); } FileView uiFileView = getUI().getFileView(this); if(icon == null && uiFileView != null) { icon = uiFileView.getIcon(f); } } return icon; }
@Override public FileView getFileView(JFileChooser fc) { for (int i = 1; i < numberOfUIs; i++) { ((FileChooserUI) uis.get(i)).getFileView(fc); } return ((FileChooserUI) uis.firstElement()).getFileView(fc); }
public void testGetSetFileView() throws Exception { assertNull(chooser.getFileView()); assertNotNull(chooser.getUI().getFileView(chooser)); FileView view = new FileView() { }; chooser.setFileView(view); assertTrue(propertyChangeController.isChanged("fileViewChanged")); assertEquals(view, chooser.getFileView()); assertNotSame(view, chooser.getUI().getFileView(chooser)); }