use of com.igormaznitsa.sciareto.ui.tree.NodeFileOrFolder in project netbeans-mmd-plugin by raydac.
the class NodeListRenderer method getListCellRendererComponent.
@Override
@Nonnull
public Component getListCellRendererComponent(@Nonnull final JList<?> list, @Nonnull final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
final NodeFileOrFolder node = (NodeFileOrFolder) value;
final String ext = FilenameUtils.getExtension(node.toString()).toLowerCase(Locale.ENGLISH);
if (!isSelected && COLOR_ROW_EVEN != null && COLOR_ROW_ODD != null) {
if (index % 2 == 0) {
this.setBackground(COLOR_ROW_EVEN);
} else {
this.setBackground(COLOR_ROW_ODD);
}
}
if (node instanceof NodeProject || !node.isLeaf()) {
this.setIcon(TreeCellRenderer.DEFAULT_FOLDER_CLOSED);
} else if (ext.equals("mmd")) {
// NOI18N
this.setIcon(Icons.DOCUMENT.getIcon());
} else if (PictureViewer.SUPPORTED_FORMATS.contains(ext)) {
this.setIcon(TreeCellRenderer.ICON_IMAGE);
} else {
this.setIcon(TreeCellRenderer.DEFAULT_FILE);
}
this.setText(makeTextForNode(node));
return this;
}
use of com.igormaznitsa.sciareto.ui.tree.NodeFileOrFolder in project netbeans-mmd-plugin by raydac.
the class FindFilesForTextPanel method buttonFindActionPerformed.
// </editor-fold>//GEN-END:initComponents
private void buttonFindActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_buttonFindActionPerformed
this.fieldText.setEnabled(false);
this.buttonFind.setEnabled(false);
this.comboCharsets.setEnabled(false);
this.comboLocale.setEnabled(false);
this.listOfFoundElements.clearSelection();
this.foundFiles.clear();
this.listOfFoundElements.revalidate();
this.listOfFoundElements.repaint();
final List<NodeFileOrFolder> folders = new ArrayList<>();
folders.add(this.folder);
final Locale selectedLocale = ((TheLocale) this.comboLocale.getSelectedItem()).locale;
try {
final byte[] str1 = this.fieldText.getText().toLowerCase(selectedLocale).getBytes(this.comboCharsets.getSelectedItem().toString());
final byte[] str2 = this.fieldText.getText().toUpperCase(selectedLocale).getBytes(this.comboCharsets.getSelectedItem().toString());
startSearchThread(folders, str1, str2);
} catch (UnsupportedEncodingException ex) {
JOptionPane.showMessageDialog(this, ex, "Error", JOptionPane.ERROR_MESSAGE);
}
}
use of com.igormaznitsa.sciareto.ui.tree.NodeFileOrFolder in project netbeans-mmd-plugin by raydac.
the class FindFilesForTextPanel method startSearchThread.
private void startSearchThread(@Nonnull @MustNotContainNull final List<NodeFileOrFolder> scope, @Nonnull final byte[] dataToFindVariant1, @Nonnull final byte[] dataToFindVariant2) {
int size = 0;
for (final NodeFileOrFolder p : scope) {
size += p.size();
}
final byte[] fileOpBuffer = new byte[1024 * 1024];
final Runnable runnable = new Runnable() {
int value = 0;
private void processFile(final NodeFileOrFolder file) {
value++;
final File f = file.makeFileForNode();
try {
if (new FileExaminator(f).doesContainData(fileOpBuffer, dataToFindVariant1, dataToFindVariant2)) {
addFileIntoList(file);
}
} catch (Exception ex) {
LOGGER.error("Error during text search in '" + f + '\'', ex);
}
if (!Thread.currentThread().isInterrupted()) {
safeSetProgressValue(value);
}
}
private void processFolder(final NodeFileOrFolder folder) {
value++;
for (final NodeFileOrFolder f : folder) {
if (f.isLeaf()) {
processFile(f);
} else {
processFolder(f);
}
}
if (!Thread.currentThread().isInterrupted()) {
safeSetProgressValue(value);
}
}
@Override
public void run() {
for (final NodeFileOrFolder p : scope) {
for (final NodeFileOrFolder f : p) {
if (Thread.currentThread().isInterrupted()) {
return;
}
if (f.isLeaf()) {
processFile(f);
} else {
processFolder(f);
}
}
}
safeSetProgressValue(Integer.MAX_VALUE);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
buttonFind.setEnabled(true);
fieldText.setEnabled(true);
comboCharsets.setEnabled(true);
comboLocale.setEnabled(true);
if (foundFiles.isEmpty()) {
fieldText.requestFocus();
} else {
listOfFoundElements.requestFocus();
}
}
});
}
};
// NOI18N
final Thread thread = new Thread(runnable, "SciaRetoSearchUsage");
thread.setDaemon(true);
final Thread oldThread = this.searchingThread.getAndSet(thread);
if (oldThread != null) {
oldThread.interrupt();
try {
oldThread.join(1000L);
} catch (InterruptedException ex) {
// NOI18N
LOGGER.error("Exception during waiting of search thread interruption", ex);
}
}
this.progressBarSearch.setMinimum(0);
this.progressBarSearch.setMaximum(size);
this.progressBarSearch.setValue(0);
thread.start();
}
Aggregations