/** * Adds specified element into thumbnails queue. * * @param element element to add */ protected void queueThumbnailLoad(final FileElement element, final boolean disabled) { element.setThumbnailQueued(true); element.setDisabledThumbnailQueued(disabled); executorService.submit( new Runnable() { @Override public void run() { final String absolutePath = element.getFile().getAbsolutePath(); final String ext = FileUtils.getFileExtPart(element.getFile().getName(), false).toLowerCase(); if (fileList.isGenerateThumbnails() && GlobalConstants.IMAGE_FORMATS.contains(ext)) { final ImageIcon thumb = element.getEnabledThumbnail() != null ? element.getEnabledThumbnail() : ImageUtils.createThumbnailIcon(absolutePath, thumbSize); if (thumb != null) { element.setEnabledThumbnail(thumb); if (disabled) { element.setDisabledThumbnail(ImageUtils.createDisabledCopy(thumb)); } } else { element.setEnabledThumbnail( FileUtils.getStandartFileIcon(element.getFile(), true, true)); if (disabled) { element.setDisabledThumbnail( FileUtils.getStandartFileIcon(element.getFile(), true, false)); } } } else { element.setEnabledThumbnail( FileUtils.getStandartFileIcon(element.getFile(), true, true)); if (disabled) { element.setDisabledThumbnail( FileUtils.getStandartFileIcon(element.getFile(), true, false)); } } if (disabled != fileList.isEnabled()) { fileList.repaint(element); } } }); }
public void valueChanged(TreeSelectionEvent e) { TreePath[] paths = e.getPaths(); boolean enabled = true; for (TreePath treePath : paths) { if (!e.isAddedPath(treePath)) { continue; } DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent(); Object userObject = node.getUserObject(); if (!(userObject instanceof FileNodeDescriptor)) { enabled = false; break; } FileElement descriptor = ((FileNodeDescriptor) userObject).getElement(); VirtualFile file = descriptor.getFile(); enabled = file != null && myChooserDescriptor.isFileSelectable(file); } setOKActionEnabled(enabled); }
/** * Returns list cell renderer component. * * @param list tree * @param value cell value * @param index cell index * @param isSelected whether cell is selected or not * @param cellHasFocus whether cell has focus or not * @return cell renderer component */ @Override public Component getListCellRendererComponent( final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { super.getListCellRendererComponent(list, "", index, isSelected, cellHasFocus); final FileElement element = (FileElement) value; final File file = element.getFile(); // Proper margin setMargin(isTilesView() ? tileCellMargin : iconCellMargin); // Renderer icon String imageSize = null; if (iconLabel.isEnabled()) { // Thumbnail loading synchronized (thumbnailsLock) { if (!element.isThumbnailQueued() && !element.isDisabledThumbnailQueued()) { queueThumbnailLoad(element, false); } } // Image thumbnail final ImageIcon thumbnail = element.getEnabledThumbnail(); iconLabel.setIcon(thumbnail); // Image description if (thumbnail != null) { imageSize = thumbnail.getDescription(); } } else { // Disabled thumbnail loading synchronized (thumbnailsLock) { if (!element.isDisabledThumbnailQueued()) { queueThumbnailLoad(element, true); } } // Image disabled thumbnail iconLabel.setDisabledIcon(element.getDisabledThumbnail()); } // Updating file description elements if (fileList.getEditedCell() != index) { // Settings description final FileDescription fileDescription = FileUtils.getFileDescription(file, imageSize); nameLabel.setText(fileDescription.getName()); // Updating tile view additional description if (isTilesView()) { descriptionLabel.setText(fileDescription.getDescription()); // Updating size label if (fileDescription.getSize() != null) { sizeLabel.setText(fileDescription.getSize()); } else { sizeLabel.setText(null); } } else { descriptionLabel.setText(null); sizeLabel.setText(null); } } else { nameLabel.setText(null); descriptionLabel.setText(null); sizeLabel.setText(null); } return this; }