add Icon Mac Windows
This commit is contained in:
parent
9cf5076bab
commit
42a8c75cdf
18
pom.xml
18
pom.xml
|
@ -127,6 +127,24 @@
|
|||
<artifactId>jfreechart</artifactId>
|
||||
<version>${jfreechart.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-imaging</artifactId>
|
||||
<version>1.0-alpha3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-icns</artifactId>
|
||||
<version>3.10.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.oleg-cherednik.icoman</groupId>
|
||||
<artifactId>icon-manager</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -8,15 +8,29 @@ import com.intellij.uiDesigner.core.Spacer;
|
|||
import com.luoboduner.moo.info.App;
|
||||
import com.luoboduner.moo.info.ui.UiConsts;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.imaging.ImageReadException;
|
||||
import org.apache.commons.imaging.formats.icns.IcnsImageParser;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import oshi.PlatformEnum;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.software.os.OSProcess;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
import oshi.util.FormatUtil;
|
||||
import ru.olegcherednik.icoman.IconFile;
|
||||
import ru.olegcherednik.icoman.IconManager;
|
||||
import ru.olegcherednik.icoman.exceptions.IconManagerException;
|
||||
import ru.olegcherednik.icoman.exceptions.IconNotFoundException;
|
||||
import sun.awt.shell.ShellFolder;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileSystemView;
|
||||
import javax.swing.table.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -30,9 +44,9 @@ import java.util.Map;
|
|||
*/
|
||||
@Getter
|
||||
public class ProcessesForm {
|
||||
private static final String[] COLUMNS = {"PID", "PPID", "Threads", "% CPU", "Cumulative", "VSZ", "RSS", "% Memory",
|
||||
private static final String[] COLUMNS = {"ICON", "PID", "PPID", "Threads", "% CPU", "Cumulative", "VSZ", "RSS", "% Memory",
|
||||
"Process Name"};
|
||||
private static final double[] COLUMN_WIDTH_PERCENT = {0.07, 0.07, 0.07, 0.07, 0.09, 0.1, 0.1, 0.08, 0.35};
|
||||
private static final double[] COLUMN_WIDTH_PERCENT = {0.001, 0.07, 0.07, 0.07, 0.07, 0.09, 0.1, 0.1, 0.08, 0.35};
|
||||
|
||||
private transient static Map<Integer, OSProcess> priorSnapshotMap = new HashMap<>();
|
||||
|
||||
|
@ -101,7 +115,13 @@ public class ProcessesForm {
|
|||
*/
|
||||
private static void initInfo() {
|
||||
OperatingSystem os = App.si.getOperatingSystem();
|
||||
TableModel model = new DefaultTableModel(parseProcesses(os.getProcesses(null, null, 0), App.si), COLUMNS);
|
||||
TableModel model = new DefaultTableModel(parseProcesses(os.getProcesses(null, null, 0), App.si), COLUMNS) {
|
||||
@Override
|
||||
public Class<?> getColumnClass(int column) {
|
||||
if (column == 0) return ImageIcon.class;
|
||||
return Object.class;
|
||||
}
|
||||
};
|
||||
JTable procTable = getInstance().getProcessTable();
|
||||
procTable.setModel(model);
|
||||
resizeColumns(procTable.getColumnModel());
|
||||
|
@ -174,22 +194,23 @@ public class ProcessesForm {
|
|||
// Matches order of COLUMNS field
|
||||
i--;
|
||||
int pid = p.getProcessID();
|
||||
procArr[i][0] = pid;
|
||||
procArr[i][1] = p.getParentProcessID();
|
||||
procArr[i][2] = p.getThreadCount();
|
||||
procArr[i][0] = getProcessIcon(p.getCommandLine());
|
||||
procArr[i][1] = pid;
|
||||
procArr[i][2] = p.getParentProcessID();
|
||||
procArr[i][3] = p.getThreadCount();
|
||||
if (processesForm.perProc.isSelected()) {
|
||||
procArr[i][3] = String.format("%.1f",
|
||||
procArr[i][4] = String.format("%.1f",
|
||||
100d * p.getProcessCpuLoadBetweenTicks(priorSnapshotMap.get(pid)) / cpuCount);
|
||||
procArr[i][4] = String.format("%.1f", 100d * p.getProcessCpuLoadCumulative() / cpuCount);
|
||||
procArr[i][5] = String.format("%.1f", 100d * p.getProcessCpuLoadCumulative() / cpuCount);
|
||||
} else {
|
||||
procArr[i][3] = String.format("%.1f",
|
||||
procArr[i][4] = String.format("%.1f",
|
||||
100d * p.getProcessCpuLoadBetweenTicks(priorSnapshotMap.get(pid)));
|
||||
procArr[i][4] = String.format("%.1f", 100d * p.getProcessCpuLoadCumulative());
|
||||
procArr[i][5] = String.format("%.1f", 100d * p.getProcessCpuLoadCumulative());
|
||||
}
|
||||
procArr[i][5] = FormatUtil.formatBytes(p.getVirtualSize());
|
||||
procArr[i][6] = FormatUtil.formatBytes(p.getResidentSetSize());
|
||||
procArr[i][7] = String.format("%.1f", 100d * p.getResidentSetSize() / totalMem);
|
||||
procArr[i][8] = p.getName();
|
||||
procArr[i][6] = FormatUtil.formatBytes(p.getVirtualSize());
|
||||
procArr[i][7] = FormatUtil.formatBytes(p.getResidentSetSize());
|
||||
procArr[i][8] = String.format("%.1f", 100d * p.getResidentSetSize() / totalMem);
|
||||
procArr[i][9] = p.getName();
|
||||
}
|
||||
// Re-populate snapshot map
|
||||
priorSnapshotMap.clear();
|
||||
|
@ -199,6 +220,61 @@ public class ProcessesForm {
|
|||
return procArr;
|
||||
}
|
||||
|
||||
private static Icon getProcessIcon(String fullProcessPathName) {
|
||||
if (SystemUtils.IS_OS_WINDOWS) {
|
||||
File file = new File(fullProcessPathName);
|
||||
// Get metadata and create an icon
|
||||
Icon icon = FileSystemView.getFileSystemView()
|
||||
.getSystemIcon(file);
|
||||
// ShellFolder sf =
|
||||
// ShellFolder.getShellFolder(file);
|
||||
// Icon icon = new ImageIcon(sf.getIcon(true));
|
||||
return icon;
|
||||
}
|
||||
if (SystemUtils.IS_OS_MAC) {
|
||||
if (fullProcessPathName.contains("MacOS")) {
|
||||
String iconPath[] = fullProcessPathName.split("MacOS");
|
||||
if (iconPath.length > 0) {
|
||||
//"AppIcon.icns"
|
||||
String iconFilePath = iconPath[0] + "Resources/AppIcon.icns";
|
||||
File file = new File(iconFilePath);
|
||||
//Imaging.getAllBufferedImages(iconFilePath);
|
||||
try {
|
||||
if (file.exists()) {
|
||||
List<BufferedImage> is = new IcnsImageParser().getAllBufferedImages(new File(iconFilePath));
|
||||
BufferedImage bufferedImage = is.get(0);
|
||||
|
||||
BufferedImage bufferedImageR = resizeImage(bufferedImage, 28, 28);
|
||||
Icon icon = new ImageIcon(bufferedImageR);
|
||||
return icon;
|
||||
}
|
||||
} catch (ImageReadException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
//return new ImageIcon(Toolkit.getDefaultToolkit().getImage(iconFilePath));
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* ResizeImage BufferedImage to given targetWidth targetHeight preserve transparency
|
||||
*
|
||||
* @param originalImage
|
||||
* @param targetWidth
|
||||
* @param targetHeight
|
||||
* @return resizeImage
|
||||
*/
|
||||
public static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws IOException {
|
||||
BufferedImage resizedImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_ARGB_PRE);
|
||||
Graphics2D graphics2D = resizedImage.createGraphics();
|
||||
graphics2D.drawImage(originalImage, 0, 0, targetWidth, targetHeight, null);
|
||||
graphics2D.dispose();
|
||||
return resizedImage;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Codes are copied from oshi and have some modifications.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue