• R/O
  • SSH

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

Gradle/Mavenが持っているjarファイルのパスを表示するツール


Commit MetaInfo

修訂3a2754eed8a52b7e79244c7821729ed5a8a798bf (tree)
時間2022-02-27 11:02:47
作者kemono7h
Commiterkemono7h

Log Message

結果表示を色付け

Change Summary

差異

diff -r db3182b98ec3 -r 3a2754eed8a5 src/jp/nanah/dnj/DokonanFrame.java
--- a/src/jp/nanah/dnj/DokonanFrame.java Sun Feb 27 08:51:06 2022 +0900
+++ b/src/jp/nanah/dnj/DokonanFrame.java Sun Feb 27 11:02:47 2022 +0900
@@ -1,23 +1,27 @@
11 package jp.nanah.dnj;
22
33 import java.awt.BorderLayout;
4+import java.awt.Component;
45 import java.awt.FlowLayout;
56 import java.awt.Font;
7+import java.awt.Window;
68 import java.awt.event.ActionEvent;
79 import java.awt.event.ActionListener;
810
911 import javax.swing.JButton;
1012 import javax.swing.JCheckBox;
13+import javax.swing.JEditorPane;
1114 import javax.swing.JFrame;
1215 import javax.swing.JPanel;
1316 import javax.swing.JScrollPane;
14-import javax.swing.JTextArea;
1517 import javax.swing.JTextField;
18+import javax.swing.LayoutFocusTraversalPolicy;
1619 import javax.swing.border.EmptyBorder;
1720 import javax.swing.event.ChangeEvent;
1821 import javax.swing.event.ChangeListener;
1922 import javax.swing.event.DocumentEvent;
2023 import javax.swing.event.DocumentListener;
24+import javax.swing.plaf.ComponentUI;
2125 import javax.swing.text.Document;
2226
2327 public class DokonanFrame {
@@ -46,7 +50,7 @@
4650 /**
4751 * 結果表示エリア
4852 */
49- private JTextArea resultArea;
53+ private JEditorPane resultArea;
5054
5155 /**
5256 * CopyButton
@@ -65,7 +69,7 @@
6569 frame = new JFrame();
6670 frame.setSize(600, 300);
6771 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
68- frame.setTitle("DokonanJar - GradleのJarファイルを探す");
72+ frame.setTitle("DokonanJar - Gradle/MavenのJarファイルを探す");
6973
7074 Font font = (fontName == null) ? frame.getFont() : new Font(fontName, Font.PLAIN, 12);
7175
@@ -105,9 +109,13 @@
105109
106110 //結果出力エリア
107111 {
108- resultArea = new JTextArea();
112+ resultArea = new NoWrapEditorPane();
113+ resultArea.setContentType("text/html; charset=UTF-8");
109114 resultArea.setFont(font);
110115 resultArea.setEditable(false);
116+ if (font != null) {
117+ resultArea.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
118+ }
111119 JScrollPane scrollPane = new JScrollPane(resultArea);
112120 JPanel panel = new JPanel();
113121 panel.setBorder(new EmptyBorder(4,4,4,4));
@@ -126,6 +134,13 @@
126134 frame.getContentPane().add(panel, BorderLayout.SOUTH);
127135
128136 }
137+
138+ //入力フィールドに初期フォーカス。https://ateraimemo.com/Swing/DefaultFocus.htmlより
139+ frame.setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() {
140+ @Override public Component getInitialComponent(Window w) {
141+ return txtField;
142+ }
143+ });
129144 }
130145
131146 public JFrame getFrame() {
@@ -140,7 +155,7 @@
140155 public JButton getCopyButton() {
141156 return copyButton;
142157 }
143- public JTextArea getResultArea() {
158+ public JEditorPane getResultArea() {
144159 return resultArea;
145160 }
146161
@@ -233,4 +248,14 @@
233248 }
234249 }
235250
251+ //折り返さずにスクロールするJEditorPane。from http://www.java2s.com/Code/Java/Swing-JFC/NonWrappingWrapTextPane.htm
252+ private class NoWrapEditorPane extends JEditorPane {
253+ @Override
254+ public boolean getScrollableTracksViewportWidth() {
255+ Component parent = getParent();
256+ ComponentUI ui = getUI();
257+ return (parent != null) ? (ui.getPreferredSize(this).width <= parent.getSize().width) : true;
258+ }
259+ }
260+
236261 }
diff -r db3182b98ec3 -r 3a2754eed8a5 src/jp/nanah/dnj/DokonanJar.java
--- a/src/jp/nanah/dnj/DokonanJar.java Sun Feb 27 08:51:06 2022 +0900
+++ b/src/jp/nanah/dnj/DokonanJar.java Sun Feb 27 11:02:47 2022 +0900
@@ -14,9 +14,9 @@
1414
1515 public DokonanJar(Properties prop) {
1616 userHome = System.getProperty("user.home");
17- String dir = prop.getProperty("user.home");
18- if (dir != null && dir.trim().length() > 0) {
19- userHome = dir;
17+ String customUserHome = prop.getProperty("user.home");
18+ if (customUserHome != null && customUserHome.trim().length() > 0) {
19+ userHome = customUserHome;
2020 }
2121 }
2222
diff -r db3182b98ec3 -r 3a2754eed8a5 src/jp/nanah/dnj/DokonanJarMain.java
--- a/src/jp/nanah/dnj/DokonanJarMain.java Sun Feb 27 08:51:06 2022 +0900
+++ b/src/jp/nanah/dnj/DokonanJarMain.java Sun Feb 27 11:02:47 2022 +0900
@@ -105,6 +105,7 @@
105105
106106 Map<String, JarInfo> doneJarInfoMap = new TreeMap<String, JarInfo>();
107107
108+ StringBuilder sb = new StringBuilder();
108109 for (File f : resultFile) {
109110 try {
110111 String fname = f.getName();
@@ -120,10 +121,10 @@
120121 }
121122 //ファイル内容が違っていたらサイズが大きい方を採用する。英文法については気にしないこと。
122123 String fileinfo = ji.file.getAbsolutePath() + "," + ji.data.length;
123- if (ji.data.length > doneJi.data.length) {
124- dokoFrame.getResultArea().append("\n## file size is different and overwrited by " + fileinfo);
125- } else {
126- dokoFrame.getResultArea().append("\n## file size is different and skipped " + fileinfo);
124+ boolean isOverwrite = (ji.data.length > doneJi.data.length);
125+ String warningMessage = isOverwrite ? "overwrited" : "skipped";
126+ sb.append("<br/><font color='red'>## file size is different and " + warningMessage +" by " + fileinfo + "</font>");
127+ if (isOverwrite == false) {
127128 continue;
128129 }
129130 }
@@ -135,6 +136,10 @@
135136 th.printStackTrace();
136137 }
137138 }
139+
140+ String orgText = dokoFrame.getResultArea().getText();
141+ int bodyEnd = orgText.lastIndexOf("</body>");
142+ dokoFrame.getResultArea().setText(orgText.substring(0, bodyEnd) + sb.toString() + orgText.substring(bodyEnd));
138143 }
139144 }
140145
@@ -146,7 +151,6 @@
146151 }
147152 }
148153
149-
150154 public void searchFiles(String path) {
151155 String[] texts = getSearchTexts(path);
152156 List<File> allList = new ArrayList<File>();
@@ -164,16 +168,33 @@
164168 }
165169 StringBuilder sb = new StringBuilder();
166170 for (File f : allList) {
167- //System.out.println(">>" + f.getAbsolutePath());
168171 if (sb.length() > 0) {
169- sb.append("\n");
172+ sb.append("<br/>");
170173 }
171- sb.append(f.getAbsolutePath());
174+ sb.append(toPathText(f, texts));
172175 }
173176 dokoFrame.getResultArea().setText(sb.toString());
174177 resultFile = allList;
175178 }
176179
180+ private String toPathText(File file, String[] texts) {
181+ String fullpath = file.getAbsolutePath();
182+ int filenameIndex = fullpath.lastIndexOf(File.separator);
183+ int lastFolderIndex = fullpath.lastIndexOf(File.separator, filenameIndex-1);
184+ if (lastFolderIndex < 0) {
185+ lastFolderIndex = filenameIndex;
186+ }
187+
188+ String lastFolder = fullpath.substring(lastFolderIndex, filenameIndex);
189+ String beforeLastFolder = fullpath.substring(0, lastFolderIndex);
190+ String filename = fullpath.substring(filenameIndex, fullpath.length()-4);
191+
192+ for (int i=0; i<texts.length; i++) {
193+ filename = filename.replaceAll(texts[i], "<b>"+texts[i]+"</b>");
194+ }
195+ return beforeLastFolder + "<a href=\"" + beforeLastFolder + lastFolder + "\">" + lastFolder + "</a>" + filename + ".jar";
196+ }
197+
177198 private String[] getSearchTexts(String path) {
178199 String[] texts = path.split(" ");
179200 for (int i=0; i<texts.length; i++) {