diff --git a/src/main/java/istlab/KisoJikken/Editor.java b/src/main/java/istlab/KisoJikken/Editor.java index bebb9d9..62f64fb 100644 --- a/src/main/java/istlab/KisoJikken/Editor.java +++ b/src/main/java/istlab/KisoJikken/Editor.java @@ -58,7 +58,7 @@ textArea.addKeyListener(this); try { - setTitle(file.getCanonicalPath()); + setTitle(file.getCanonicalPath().replaceAll(App.userhome, "~")); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/istlab/KisoJikken/JTAConsole.java b/src/main/java/istlab/KisoJikken/JTAConsole.java index 5156d37..2966834 100644 --- a/src/main/java/istlab/KisoJikken/JTAConsole.java +++ b/src/main/java/istlab/KisoJikken/JTAConsole.java @@ -4,6 +4,8 @@ import java.awt.Point; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.io.BufferedReader; @@ -19,7 +21,7 @@ import javax.swing.JTextArea; import javax.swing.text.BadLocationException; -public class JTAConsole extends JTextArea implements Runnable, WindowListener, KeyListener { +public class JTAConsole extends JTextArea implements Runnable, WindowListener, KeyListener, MouseListener { // static JTAConsole lastWindow; // static Point lastActivePoint; static Stack winStack = new Stack(); @@ -57,6 +59,7 @@ } addKeyListener(this); + addMouseListener(this); // if (lastActivePoint != null){ // frame.setLocation(lastActivePoint.x+500, lastActivePoint.y); @@ -239,4 +242,36 @@ public void keyReleased(KeyEvent e) { } + + @Override + public void mouseClicked(MouseEvent e) { + if (e.getButton()==MouseEvent.BUTTON3){ + JTAConsolePopup popupMenu = new JTAConsolePopup(this); + popupMenu.show(this,e.getX(),e.getY()); + } + } + + @Override + public void mousePressed(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseReleased(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseEntered(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseExited(MouseEvent e) { + // TODO Auto-generated method stub + + } } diff --git a/src/main/java/istlab/KisoJikken/JTAConsolePopup.java b/src/main/java/istlab/KisoJikken/JTAConsolePopup.java new file mode 100644 index 0000000..d89d264 --- /dev/null +++ b/src/main/java/istlab/KisoJikken/JTAConsolePopup.java @@ -0,0 +1,30 @@ +package istlab.KisoJikken; + +import java.awt.Component; + +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; + +public class JTAConsolePopup extends JPopupMenu { + + JTAConsole console; + + public JTAConsolePopup(JTAConsole con) { + console = con; + + JMenuItem mi; + setLightWeightPopupEnabled(true); + + mi = new JMenuItem("cancel"); + add(mi); + addSeparator(); + + mi = new JMenuItem("Submit"); + add(mi); + mi.addActionListener(ae -> System.out.println(ae.getActionCommand())); + + } +public void showWithFrame(Component c, int x, int y) { + show(c, x, y); + } +} diff --git a/src/main/java/istlab/KisoJikken/Launcher.java b/src/main/java/istlab/KisoJikken/Launcher.java index 2ab47f4..517dd65 100644 --- a/src/main/java/istlab/KisoJikken/Launcher.java +++ b/src/main/java/istlab/KisoJikken/Launcher.java @@ -67,9 +67,9 @@ } if (args.length > 0) - root = new File(args[0]); + root = new MyFile(args[0]); else - root = new File(App.userhome + App.nwpsrc); + root = new MyFile(App.userhome + App.nwpsrc); // Create a TreeModel object to represent our tree of files FileTreeModel model = new FileTreeModel(root, false); @@ -118,30 +118,30 @@ menuBar.add(menu); jcbmi = new JCheckBoxMenuItem("exclude class files"); - jcbmi.addItemListener(ae -> reloadFiles() ); + jcbmi.addItemListener(ae -> reloadFiles()); menu.add(jcbmi); mi = new JMenuItem("reload folders/files"); - mi.addActionListener(ae -> reloadFiles() ); + mi.addActionListener(ae -> reloadFiles()); menu.add(mi); menu = new JMenu("Process"); menuBar.add(menu); mi = new JMenuItem("stop alive"); - mi.addActionListener(ae -> stopProcess(false) ); + mi.addActionListener(ae -> stopProcess(false)); menu.add(mi); mi = new JMenuItem("stop all"); - mi.addActionListener(ae -> stopProcess(true) ); + mi.addActionListener(ae -> stopProcess(true)); menu.add(mi); mi = new JMenuItem("jps"); - mi.addActionListener(ae -> runCommand(ae.getActionCommand()) ); + mi.addActionListener(ae -> runCommand(ae.getActionCommand())); menu.add(mi); mi = new JMenuItem("killall java"); - mi.addActionListener(ae -> runCommand(ae.getActionCommand()) ); + mi.addActionListener(ae -> runCommand(ae.getActionCommand())); menu.add(mi); setJMenuBar(menuBar); @@ -150,23 +150,25 @@ setSize(400, 600); } - public void runCommand(String cmd){ + public void runCommand(String cmd) { System.out.println(cmd); new CommandRunner(cmd).startstop(); } - public void stopProcess(boolean isAll){ + + public void stopProcess(boolean isAll) { ArrayList toberemoved = new ArrayList(); - for(Process proc : allProcs){ - if (!isAll){ - if (proc.isAlive()) continue; + for (Process proc : allProcs) { + if (!isAll) { + if (proc.isAlive()) + continue; } proc.destroyForcibly(); toberemoved.add(proc); } - for(Process delproc: toberemoved){ + for (Process delproc : toberemoved) { allProcs.remove(delproc); Enumeration enu = JTAConsole.winStack.elements(); - while(enu.hasMoreElements()){ + while (enu.hasMoreElements()) { JTAConsole con = enu.nextElement(); con.windowClosing(null); con.frame.dispose(); @@ -217,7 +219,7 @@ fileChannel.close(); fileOutputStream.close(); - File execjar = new File(execPath.getParent().toString()+File.separator+latestVersion); + File execjar = new File(execPath.getParent().toString() + File.separator + latestVersion); execjar.setExecutable(true); } catch (Exception ex) { } finally { @@ -272,8 +274,9 @@ if (tp == null) return; File node = (File) tp.getLastPathComponent(); - //フォルダなら開かない - if (node.isDirectory()) return; + // フォルダなら開かない + if (node.isDirectory()) + return; Editor ed = file2editor.get(node); if (ed == null) { ed = new Editor(node); @@ -350,6 +353,16 @@ } +class MyFile extends File { + public MyFile(String pathname) { + super(pathname); + } + + public String toString() { + return super.toString().replaceAll(App.userhome, "~"); + } +} + /** * The methods in this class allow the JTree component to traverse * the file system tree, and display the files and directories. @@ -375,9 +388,9 @@ return ((File) node).isFile(); } - private File[] getChildFiles(File parent){ - if (isExcludeClassFiles){ - return parent.listFiles(path -> !path.toString().endsWith(".class")); + private File[] getChildFiles(File parent) { + if (isExcludeClassFiles) { + return parent.listFiles(path -> !path.toString().endsWith(".class")); } else { return parent.listFiles(); } @@ -401,7 +414,7 @@ if ((children == null) || (index >= children.length)) return null; // return new File((File) parent, children[index]); - return children[index]; + return new MyFile(children[index].getAbsolutePath()); } // Figure out a child's position in its parent node.