Gradle/Mavenが持っているjarファイルのパスを表示するツール
Revisão | 2d78ccb058c5325c2c7e5db5b9dff21aa4fa1848 (tree) |
---|---|
Hora | 2022-08-28 09:50:08 |
Autor | kemono7h |
Commiter | kemono7h |
出力先ディレクトリもExplorerで開けるようにした
@@ -15,6 +15,7 @@ | ||
15 | 15 | import javax.swing.JPanel; |
16 | 16 | import javax.swing.JScrollPane; |
17 | 17 | import javax.swing.JTextField; |
18 | +import javax.swing.JToolTip; | |
18 | 19 | import javax.swing.LayoutFocusTraversalPolicy; |
19 | 20 | import javax.swing.border.EmptyBorder; |
20 | 21 | import javax.swing.event.ChangeEvent; |
@@ -68,7 +69,7 @@ | ||
68 | 69 | frame = new JFrame(); |
69 | 70 | frame.setSize(600, 300); |
70 | 71 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
71 | - frame.setTitle("DokonanJar - Gradle/MavenのJarファイルを探す"); | |
72 | + frame.setTitle("DokonanJar - Gradle/MavenのJarファイルを探してコピー"); | |
72 | 73 | |
73 | 74 | Font font = (fontName == null) ? frame.getFont() : new Font(fontName, Font.PLAIN, 12); |
74 | 75 |
@@ -77,6 +78,9 @@ | ||
77 | 78 | topPanel.setBorder(new EmptyBorder(0,4,0,4)); |
78 | 79 | topPanel.setLayout(new BorderLayout()); |
79 | 80 | frame.getContentPane().add(topPanel, BorderLayout.NORTH); |
81 | + JPanel editPanel = new JPanel(); | |
82 | + editPanel.setLayout(new BorderLayout()); | |
83 | + topPanel.add(editPanel, BorderLayout.NORTH); | |
80 | 84 | |
81 | 85 | //チェックボックス |
82 | 86 | { |
@@ -90,7 +94,7 @@ | ||
90 | 94 | panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
91 | 95 | panel.add(cbGradle); |
92 | 96 | panel.add(cbMaven); |
93 | - topPanel.add(panel, BorderLayout.NORTH); | |
97 | + editPanel.add(panel, BorderLayout.CENTER); | |
94 | 98 | |
95 | 99 | CheckBoxActionListener cbActionListener = new CheckBoxActionListener(); |
96 | 100 | cbGradle.addActionListener(cbActionListener); |
@@ -128,12 +132,19 @@ | ||
128 | 132 | |
129 | 133 | //コピーボタン |
130 | 134 | { |
131 | - copyButton = new JButton("コピー"); | |
135 | + copyButton = new JButton("出力先にコピー") { | |
136 | + @Override | |
137 | + public JToolTip createToolTip() { | |
138 | + JToolTip toolTip = new JToolTip(); | |
139 | + toolTip.setFont(font); | |
140 | + return toolTip; | |
141 | + } | |
142 | + }; | |
132 | 143 | JPanel panel = new JPanel(); |
133 | 144 | panel.setBorder(new EmptyBorder(4,4,4,4)); |
134 | 145 | panel.setLayout(new BorderLayout()); |
135 | 146 | panel.add(copyButton); |
136 | - frame.getContentPane().add(panel, BorderLayout.SOUTH); | |
147 | + editPanel.add(panel, BorderLayout.EAST); | |
137 | 148 | |
138 | 149 | } |
139 | 150 |
@@ -2,6 +2,8 @@ | ||
2 | 2 | |
3 | 3 | import java.awt.event.ActionEvent; |
4 | 4 | import java.awt.event.ActionListener; |
5 | +import java.awt.event.MouseAdapter; | |
6 | +import java.awt.event.MouseEvent; | |
5 | 7 | import java.io.File; |
6 | 8 | import java.io.FileInputStream; |
7 | 9 | import java.util.ArrayList; |
@@ -83,7 +85,9 @@ | ||
83 | 85 | public void initFrame() { |
84 | 86 | dokoFrame.initComponent(); |
85 | 87 | JButton button = dokoFrame.getCopyButton(); |
88 | + button.setToolTipText("表示中のjarを [" + FileUtils.getFullPath(outputDir) + "] にコピー。右クリックで出力先を開きます"); | |
86 | 89 | button.addActionListener(new CopyButtonActionListener()); |
90 | + button.addMouseListener(new DokonanMouseListener()); | |
87 | 91 | Thread thread = new Thread(){ |
88 | 92 | @Override |
89 | 93 | public void run(){ |
@@ -99,14 +103,8 @@ | ||
99 | 103 | dokoFrame.getResultArea().addHyperlinkListener(new HyperlinkListener() { |
100 | 104 | @Override public void hyperlinkUpdate(HyperlinkEvent e) { |
101 | 105 | if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { |
102 | - try { | |
103 | - //Windows Only | |
104 | - String path = e.getURL().getPath().replaceAll("/", "\\\\"); | |
105 | - Runtime.getRuntime().exec("explorer.exe /select," + path); | |
106 | - } catch (Throwable th) { | |
107 | - System.out.println("フォルダ表示に失敗しました。"); | |
108 | - //th.printStackTrace(); | |
109 | - } | |
106 | + String path = e.getURL().getPath().replaceAll("/", "\\\\"); | |
107 | + FileUtils.openFiler(path, true); | |
110 | 108 | } |
111 | 109 | } |
112 | 110 | }); |
@@ -168,6 +166,15 @@ | ||
168 | 166 | } |
169 | 167 | } |
170 | 168 | |
169 | + private class DokonanMouseListener extends MouseAdapter { | |
170 | + @Override | |
171 | + public void mousePressed(MouseEvent e) { | |
172 | + if (e.getButton() == MouseEvent.BUTTON3) { | |
173 | + FileUtils.openFiler(FileUtils.getFullPath(outputDir), false); | |
174 | + } | |
175 | + } | |
176 | + } | |
177 | + | |
171 | 178 | public void searchFiles(String path) { |
172 | 179 | String[] texts = getSearchTexts(path); |
173 | 180 | List<File> allList = new ArrayList<File>(); |
@@ -195,7 +202,7 @@ | ||
195 | 202 | } |
196 | 203 | |
197 | 204 | private String toPathText(File file, String[] texts) { |
198 | - String fullpath = file.getAbsolutePath(); | |
205 | + String fullpath = FileUtils.getFullPath(file); | |
199 | 206 | int filenameIndex = fullpath.lastIndexOf(File.separator) + 1; |
200 | 207 | String beforeLastFolder = fullpath.substring(0, filenameIndex); |
201 | 208 | String filename = fullpath.substring(filenameIndex); |
@@ -288,4 +288,27 @@ | ||
288 | 288 | file.delete(); |
289 | 289 | } |
290 | 290 | |
291 | + //--------------------------------------------- | |
292 | + // パス処理 | |
293 | + //--------------------------------------------- | |
294 | + | |
295 | + public static String getFullPath(File file) { | |
296 | + try { | |
297 | + return file.getCanonicalPath(); | |
298 | + } catch (IOException e) { | |
299 | + return file.getAbsolutePath(); | |
300 | + } | |
301 | + } | |
302 | + | |
303 | + public static void openFiler(String path, boolean isFile) { | |
304 | + try { | |
305 | + | |
306 | + //Windows Only | |
307 | + String args = isFile ? "/select," : ""; | |
308 | + Runtime.getRuntime().exec("explorer.exe "+args + path); | |
309 | + } catch (Throwable th) { | |
310 | + System.out.println("フォルダ表示に失敗しました。"); | |
311 | + //th.printStackTrace(); | |
312 | + } | |
313 | + } | |
291 | 314 | } |
\ No newline at end of file |
@@ -20,23 +20,10 @@ | ||
20 | 20 | |
21 | 21 | while ((zipEntry = zistr.getNextEntry()) != null) { |
22 | 22 | String name = zipEntry.getName(); |
23 | - System.out.println(name); | |
24 | 23 | if (name.endsWith(".class")) { |
25 | 24 | return true; |
26 | 25 | } |
27 | - //classList | |
28 | -// File uncompressFile = new File(zipEntry.getName()); | |
29 | -// System.out.println(""); | |
30 | - // | |
31 | -// if (zipEntry.isDirectory()) { | |
32 | -// uncompressFile.mkdirs(); | |
33 | -// } else { | |
34 | -// BufferedOutputStream bostr = new BufferedOutputStream(new FileOutputStream(uncompressFile)); | |
35 | -// while ((len = zistr.read(buf)) != -1) { | |
36 | -// bostr.write(buf, 0, len); | |
37 | -// } | |
38 | -// bostr.close(); | |
39 | -// } | |
26 | + | |
40 | 27 | } |
41 | 28 | } catch (IOException ex) { |
42 | 29 | ex.printStackTrace(); |