Skip to content

Commit

Permalink
color marks for files in MacOSX
Browse files Browse the repository at this point in the history
  • Loading branch information
trol73 committed Dec 27, 2016
1 parent 595c198 commit a2113ec
Show file tree
Hide file tree
Showing 22 changed files with 155 additions and 28 deletions.
Binary file modified res/runtime/images/action/GoToHome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/runtime/images/action/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/runtime/images/action/MarkGroup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/runtime/images/action/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/runtime/images/action/Pack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/runtime/images/action/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/runtime/images/action/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/runtime/images/action/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/runtime/images/action/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/runtime/images/action/UnmarkGroup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/runtime/images/action/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/runtime/images/action/Unpack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/runtime/images/action/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/runtime/images/action/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/runtime/images/action/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/main/com/mucommander/commons/file/FileFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,15 @@ private static void updateArchiveFormatProviderArray() {
* @param filename an archive filename that potentially matches one of the registered <code>ArchiveFormatProvider</code>
* @return the first <code>ArchiveFormatProvider</code> that matches the specified filename, <code>null</code> if there is none
*/
public static ArchiveFormatProvider getArchiveFormatProvider(String filename) {
private static ArchiveFormatProvider getArchiveFormatProvider(String filename) {
if (filename == null || archiveFormatProviders == null) {
return null;
}

for (ArchiveFormatProvider provider : archiveFormatProviders) {
if (provider.getFilenameFilter().accept(filename))
if (provider != null && provider.getFilenameFilter() != null && provider.getFilenameFilter().accept(filename)) {
return provider;
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ class SwingFileIconProviderImpl extends LocalFileIconProvider implements Cacheab
private static JFileChooser fileChooser;

/** Caches icons for directories, used only for non-local files */
protected static IconCache directoryIconCache = CachedFileIconProvider.createCache();
private static IconCache directoryIconCache = CachedFileIconProvider.createCache();

/** Caches icons for regular files, used only for non-local files */
protected static IconCache fileIconCache = CachedFileIconProvider.createCache();
private static IconCache fileIconCache = CachedFileIconProvider.createCache();

/** True if init has been called */
protected static boolean initialized;
Expand All @@ -72,10 +72,10 @@ class SwingFileIconProviderImpl extends LocalFileIconProvider implements Cacheab
private final static String SYMLINK_ICON_NAME = "link.png";

/** Icon that is painted over a symlink's target file icon to symbolize a symlink to the target file. */
protected static ImageIcon SYMLINK_OVERLAY_ICON;
private static ImageIcon SYMLINK_OVERLAY_ICON;

/** Allows stderr to be 'silenced' when needed */
protected static SilenceableOutputStream errOut;
private static SilenceableOutputStream errOut;



Expand Down
57 changes: 38 additions & 19 deletions src/main/com/mucommander/ui/main/table/CellLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,26 @@ public class CellLabel extends JLabel {
// - Instance fields -----------------------------------------------------------------
// -----------------------------------------------------------------------------------
/** Last text set by the setText method */
protected String lastText;
private String lastText;
/** Last icon set by the setIcon method */
protected ImageIcon lastIcon;
private ImageIcon lastIcon;
/** Last tooltip text set by the setToolTipText method */
protected String lastTooltip;
private String lastTooltip;
/** Last foreground color set by the setForeground method */
protected Color lastForegroundColor;
private Color lastForegroundColor;
/** Last background color set by the setBackground method */
protected Color lastBackgroundColor;
private Color lastBackgroundColor;
/** Outline color (top and bottom). */
protected Color outlineColor;
/** Gradient color for the background. */
protected Color gradientColor;
private Color gradientColor;

protected boolean hasSeparatorLine;
private boolean hasSeparatorLine;

private int progressValue;

private Color markerColor;


// - Initialisation ------------------------------------------------------------------
// -----------------------------------------------------------------------------------
Expand Down Expand Up @@ -245,9 +247,9 @@ public void setupText(String text, int maxWidth) {
*/
@Override
public void paint(Graphics g) {
boolean doOutline;

doOutline = outlineColor != null && !outlineColor.equals(lastBackgroundColor);
boolean doOutline = outlineColor != null && !outlineColor.equals(lastBackgroundColor);
final int w = getWidth();
final int h = getHeight();

// Checks whether we need to paint a gradient background.
if (gradientColor != null) {
Expand All @@ -259,33 +261,42 @@ public void paint(Graphics g) {
// TODO avoid object creation in paint methods
g2.setPaint(new GradientPaint(0, 0, lastBackgroundColor, 0, getHeight(), gradientColor, false));
if (doOutline) {
g2.fillRect(0, 1, getWidth(), getHeight() - 2);
g2.fillRect(0, 1, w, h - 2);
} else {
g2.fillRect(0, 0, getWidth(), getHeight());
g2.fillRect(0, 0, w, h);
}

// Restores the graphics to its previous state.
g2.setPaint(oldPaint);
}

// Normal painting.
super.paint(g);
if (markerColor != null) {
setSize(w - h, h);
super.paint(g);
setSize(w, h);
if (gradientColor == null) {
g.setColor(lastBackgroundColor);
g.fillRect(w - h, 1, h, h - 2);
}
g.setColor(markerColor);
g.fillArc(w - h, h/6, h*2/3, h*2/3, 0, 360);
} else {
// Normal painting
super.paint(g);
}

// If necessary, paints the outline color.
if (doOutline) {
paintOutline(g);
}
if (hasSeparatorLine) {
int w = getWidth()-1;
Graphics2D g2d = (Graphics2D)g;
g2d.setColor(Color.GRAY);
g2d.setStroke(DASHED_STROKE);
g2d.drawLine(w, 0, w, getHeight());
g2d.drawLine(w-1, 0, w-1, getHeight());
}
// TODO improve it
if (progressValue > 0) {
int w = getWidth();
int h = getHeight();
int a = -progressValue*20 % 360;
int r = h - 4;
if (r % 2 != 0) {
Expand All @@ -302,7 +313,7 @@ public void paint(Graphics g) {
g.fillOval(w - r + d, 2 + d, r2, r2);
//g.fillArc(w - r + d, 2 + d, r2, r2, a+100, 200);
}
}
}

protected void paintOutline(Graphics g) {
g.setColor(outlineColor);
Expand Down Expand Up @@ -395,4 +406,12 @@ public void setProgressValue(int progressValue) {
this.progressValue = progressValue;
}

/**
* Set label color (Mac OS X only)
* @param markerColor color or null if file has no label
*/
public void setMarkerColor(Color markerColor) {
this.markerColor = markerColor;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ public static Font getCellFont() {
}




/**
* Sets CellLabels' font to the current one.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.mucommander.ui.quicksearch.QuickSearch;
import com.mucommander.ui.theme.*;
import com.mucommander.utils.FileIconsCache;
import ru.trolsoft.macosx.FileLabelCache;

import javax.swing.*;
import javax.swing.table.TableColumn;
Expand Down Expand Up @@ -210,6 +211,12 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
label.setOutline(null);
}

if (column == Column.NAME) {
label.setMarkerColor(FileLabelCache.getInstance().getLabelColor(file));
} else {
label.setMarkerColor(null);
}

return label;
}

Expand Down
1 change: 0 additions & 1 deletion src/main/com/mucommander/utils/FileIconsCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public Icon getIcon(String path) {

public Image getImageIcon(AbstractFile file) {
Icon icon = getIcon(file);
System.out.println("> " + icon.getClass().getName());
if (icon instanceof RetinaImageIcon) {
return ((RetinaImageIcon) icon).getImage();
} else if (icon instanceof ImageIcon) {
Expand Down
103 changes: 103 additions & 0 deletions src/main/ru/trolsoft/macosx/FileLabelCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* This file is part of trolCommander, http://www.trolsoft.ru/en/soft/trolcommander
* Copyright (C) 2013-2016 Oleg Trifonov
*
* trolCommander is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* trolCommander is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package ru.trolsoft.macosx;

import ch.randelshofer.quaqua.osx.OSXFile;
import com.mucommander.commons.file.AbstractFile;
import com.mucommander.commons.file.impl.CachedFile;
import com.mucommander.commons.file.impl.local.LocalFile;
import com.mucommander.commons.runtime.OsFamily;
import com.mucommander.utils.FileIconsCache;

import java.awt.*;
import java.io.File;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

/**
* Created on 27/12/16.
* @author Oleg Trifonov
*/
public class FileLabelCache {

private static final int DEFAULT_SIZE = 100;

private static FileLabelCache instance;
private final Map<AbstractFile, Color> colors = new HashMap<>();
private final LinkedList<AbstractFile> files = new LinkedList<>();
private int size = DEFAULT_SIZE;

public static FileLabelCache getInstance() {
if (instance == null) {
synchronized (FileIconsCache.class) {
if (instance == null) {
if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) {
instance = new FileLabelCache();
} else {
instance = new FileLabelCache() {
@Override
public Color getLabelColor(AbstractFile file) {
return null;
}
};
}
}
}
}
return instance;
}


public Color getLabelColor(AbstractFile file) {
String path = file.getAbsolutePath();
Color result = colors.get(path);
if (result != null) {
// move record to top
files.remove(path);
files.addFirst(file);
return result;
}
return addColor(file);
}

private Color addColor(AbstractFile file) {
Color color = getFileLabel(file);
colors.put(file, color);
files.addFirst(file);

// remove oldest record if the cache is full
if (files.size() > size) {
colors.remove(files.removeLast());
}
return color;
}

private Color getFileLabel(AbstractFile file) {
if (file instanceof CachedFile) {
file = ((CachedFile) file).getProxiedFile();
}
if (file instanceof LocalFile) {
File f = (File) file.getUnderlyingFileObject();
return OSXFile.getLabelColor(OSXFile.getLabel(f), 0);
} else {
return null;
}
}

}

0 comments on commit a2113ec

Please sign in to comment.