diff --git a/pom.xml b/pom.xml index df06e2e..9e0ba0f 100644 --- a/pom.xml +++ b/pom.xml @@ -62,6 +62,14 @@ commons-math3 3.6.1 + + + + com.fifesoft + autocomplete + 3.2.0 + + diff --git a/src/main/java/info/istlab/Zemi01/gitmonitor/App.java b/src/main/java/info/istlab/Zemi01/gitmonitor/App.java new file mode 100644 index 0000000..ec83f80 --- /dev/null +++ b/src/main/java/info/istlab/Zemi01/gitmonitor/App.java @@ -0,0 +1,163 @@ +package info.istlab.Zemi01.gitmonitor; + +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.CodeSource; +import java.security.ProtectionDomain; + +import javax.swing.SwingUtilities; +import javax.swing.UIManager; + +/** + * Hello world! + * + */ +public class App { + public static String userhome; + public static Path execPath; + // public static String nwpsrc = File.separator + "NWP" + File.separator + "src"; + // public static String gitrepos = "https://git.istlab.info/git/miura250/NWP.git"; + public static String latestVersion; + // public static String downloadurl = "https://cit.istlab.info/KisoJikkenNWP/target/"; + + public App() { + + } + + public static void main(String[] args) { + try { + App.execPath = getApplicationPath(new App().getClass()); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + + // 最新版かどうかチェック + // if (!isLatest()) { + // System.out.println("Different! " + latestVersion + " from " + execPath.getFileName().toString()); + // String pathfile = download(); + // if (pathfile != null) { + // int res = JOptionPane.showConfirmDialog(null, "最新版をダウンロードしました。最新版を起動しますか?", "アプリ更新", JOptionPane.YES_NO_OPTION); + // if (res == JOptionPane.YES_OPTION) { + // reboot(pathfile); + // } + // } + // } + + // ファイルがあるかチェック + userhome = System.getProperty("user.home"); + // getNWPifnotexist(false); + + SwingUtilities.invokeLater(() -> { + try { + String laf = UIManager.getSystemLookAndFeelClassName(); + // System.out.println(laf); + // Linuxの場合 + if (laf.endsWith("GTKLookAndFeel")) laf = "javax.swing.plaf.metal.MetalLookAndFeel"; + UIManager.setLookAndFeel(laf); + } catch (Exception e) { + /* Never happens */ } + new GitFinder().setVisible(true); + }); + + } + + public static Path getApplicationPath(Class cls) throws URISyntaxException { + ProtectionDomain pd = cls.getProtectionDomain(); + CodeSource cs = pd.getCodeSource(); + URL location = cs.getLocation(); + URI uri = location.toURI(); + Path path = Paths.get(uri); + return path; + } + +/* public static boolean isLatest() { + // 最初に、ダウンロードサイトから最新版の情報を得る + // 更新があれば、ダウンロードし、ファイルを表示する。 + StringBuilder sb = new StringBuilder(); + latestVersion = null; + try { + URL url = new URL(downloadurl); + InputStream is = url.openConnection().getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + String line = null; + while ((line = reader.readLine()) != null) { + if (latestVersion == null) { + latestVersion = line.trim(); + System.out.println(line); + } + sb.append(line + "\n"); + } + reader.close(); + } catch (Exception ex) { + } + // System.out.println(sb.toString()); + // 同じかどうかチェック + // System.out.println("[" + latestVersion + "]"); + // System.out.println("=" + execPath.getFileName() + "="); + if (execPath.getFileName().toString().equals("classes")) + return true; + return latestVersion.equals(execPath.getFileName().toString()); + }*/ + +/* // ダウンロードして実行パーミッションをつける + public static String download() { + try { + URL url = new URL(downloadurl + "/" + latestVersion); + ReadableByteChannel readableByteChannel = Channels.newChannel(url.openStream()); + FileOutputStream fileOutputStream = new FileOutputStream(latestVersion); + FileChannel fileChannel = fileOutputStream.getChannel(); + fileOutputStream.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE); + fileChannel.close(); + fileOutputStream.close(); + + File execjar = new File(execPath.getParent().toString() + File.separator + latestVersion); + execjar.setExecutable(true); + return execjar.getAbsolutePath(); + } catch (Exception ex) { + } finally { + } + return null; + } + + public static void reboot(String pathfile) { + String com = "sleep 2 ; java -jar " + pathfile; + System.out.println(com); + ProcessBuilder processBuilder = new ProcessBuilder("bash", "-c", com); + try { + processBuilder.start(); + System.exit(0); + }catch(Exception ex){ + + } + } + + public static void getNWPifnotexist(boolean showMessageIfExist) { + if (Files.notExists(Paths.get(userhome + nwpsrc))) { + int res = JOptionPane.showConfirmDialog(GitMonitor.rootFrame, + "NWP実験用のファイルが " + userhome + nwpsrc + " にありません。ダウンロードしますか?"); + if (res == JOptionPane.YES_OPTION) { + System.out.println("cd ; git clone " + gitrepos + " を実行。"); + ProcessBuilder processBuilder = new ProcessBuilder("git", "clone", gitrepos); + processBuilder.directory(new File(userhome)); + processBuilder.inheritIO(); + try { + Process process; + process = processBuilder.start(); + process.waitFor(); + } catch (IOException | InterruptedException e1) { + e1.printStackTrace(); + } + } else { + System.out.println("cd ; git clone " + gitrepos + " を実行してください。"); + System.exit(0); + } + } else { + if (showMessageIfExist) + JOptionPane.showMessageDialog(GitMonitor.rootFrame, + "NWP実験用のファイルが " + userhome + nwpsrc + " にすでにあるため、ダウンロードをキャンセルしました。"); + } + }*/ +} diff --git a/src/main/java/info/istlab/Zemi01/gitmonitor/CommandRunner.java b/src/main/java/info/istlab/Zemi01/gitmonitor/CommandRunner.java new file mode 100644 index 0000000..d109b45 --- /dev/null +++ b/src/main/java/info/istlab/Zemi01/gitmonitor/CommandRunner.java @@ -0,0 +1,93 @@ +package info.istlab.Zemi01.gitmonitor; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +public class CommandRunner implements Runnable { + public static String prompt = "> "; + + String command; + + Thread thread; + Process process; + // JButton runB; + String workingDir; + + JTAConsole con; + + public CommandRunner(String cmd, String workDir) { + command = cmd; + workingDir = workDir; + // runB = rB; + } + + public void startstop() { + if (thread == null) { + thread = new Thread(this); + thread.start(); + // runB.setText("Stop"); + } else { + process.destroyForcibly(); + thread = null; + // runB.setText("Run"); + } + } + + public void invoke() { + if (con != null) + con.frame.setTitle(command + " " + workingDir); + startstop(); + } + + public void invoke(String cmd) { + command = cmd; + invoke(); + } + + @Override + public void run() { + // Run script + // System.out.println(scriptfile); + List cmds = Arrays.asList(command.split(" ")); + ProcessBuilder processBuilder = new ProcessBuilder(cmds); + // ProcessBuilder processBuilder = new ProcessBuilder("pwd"); + processBuilder.directory(new File(workingDir)); + // processBuilder.inheritIO(); + + if (con == null) + con = new JTAConsole(command + " " + workingDir, this); + else + con.Systemoutprintln("==========================="); + // con = new JTAConsole("(Exec) " + command); + // con.Systemoutprintln("=== 実行開始 ==="); + // if (workingDir.equals(App.userhome)) { + // con.Systemoutprintln(prompt+"cd ~" + App.nwpsrc); + // } else { + con.Systemoutprintln(prompt + "cd " + workingDir); + // } + con.Systemoutprintln(prompt + command); + + try { + process = processBuilder.start(); + // Launcher.allProcs.add(process); + con.startBR(process); + + // BufferedReader reader = new BufferedReader(new + // InputStreamReader(process.getInputStream())); + // String line; + // while ((line = reader.readLine()) != null) { + // jta.append(line); + // } + process.waitFor(); + } catch (IOException | InterruptedException e1) { + e1.printStackTrace(); + } + // con.Systemoutprintln("=== 終了 === (ALT+Wで閉じる)"); + + thread = null; + // runB.setText("Run"); + } + +} diff --git a/src/main/java/info/istlab/Zemi01/gitmonitor/GitFinder.java b/src/main/java/info/istlab/Zemi01/gitmonitor/GitFinder.java new file mode 100644 index 0000000..4f44c04 --- /dev/null +++ b/src/main/java/info/istlab/Zemi01/gitmonitor/GitFinder.java @@ -0,0 +1,225 @@ +package info.istlab.Zemi01.gitmonitor; + +import java.awt.BorderLayout; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.io.File; +import java.io.FileFilter; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JFrame; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; +import javax.swing.ListSelectionModel; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.text.BadLocationException; + +import info.istlab.Zemi01.Launcher; + +public class GitFinder extends JPanel implements MouseListener { + public static JFrame rootFrame; + public static String userhome; + public static Path execPath; + + public static void main(String[] args) { + new GitFinder(); + } + + JList list; + JTextField searchJTF; + ArrayList gitDirs; + + public GitFinder() { + rootFrame = new JFrame("GitFinder"); + + basicDirs(); + System.out.println(execPath); + System.out.println(userhome); + + gitDirs = new ArrayList(); + findDotGitFileRecursive(new File(userhome), gitDirs, 0); // 指定フォルダ以下の.gitを探索する + for (File f : gitDirs) { + System.out.println(f.getAbsolutePath()); + } + searchJTF = new JTextField(); + searchJTF.getDocument().addDocumentListener(new DocumentListener() { + @Override + public void insertUpdate(DocumentEvent e) { + filterList(); + } + @Override + public void removeUpdate(DocumentEvent e) { + filterList(); + } + @Override + public void changedUpdate(DocumentEvent e) { + filterList(); + } + private void filterList() { + String filterText; + try { + filterText = searchJTF.getDocument().getText(0, searchJTF.getDocument().getLength()); + } catch (BadLocationException ex) { + filterText = ""; + } + + List filteredListData = new ArrayList(); + for (File item : gitDirs) { + if (item.getAbsolutePath().contains(filterText)) { + filteredListData.add(item); + } + } + list.setListData(filteredListData.toArray(new File[0])); + if (filteredListData.size()==1) list.setSelectedIndex(0); + } + }); + searchJTF.addKeyListener(new KeyListener() { + @Override + public void keyTyped(KeyEvent e) { + } + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER){ + if (list.getModel().getSize()==1){ + File item = list.getModel().getElementAt(0); + chooseDir(item); + } else { + System.out.println(list.getSelectedIndex()); + } + } else if (e.getKeyCode() == KeyEvent.VK_DOWN){ + list.requestFocus(); + if (list.getSelectedIndex()==-1) list.setSelectedIndex(0); + } + } + @Override + public void keyReleased(KeyEvent e) { + } + }); + + + rootFrame.add(searchJTF, BorderLayout.NORTH); + + list = new JList(gitDirs.toArray(new File[0])); + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + list.addMouseListener(this); + list.addKeyListener(new KeyListener() { + @Override + public void keyTyped(KeyEvent e) { + } + + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER){ + int pos; + if ( (pos = list.getSelectedIndex()) != -1 ){ + File item = list.getModel().getElementAt(pos); + chooseDir(item); + } + } else if (e.getKeyCode() == KeyEvent.VK_UP && list.getSelectedIndex()==0){ + //テキストフィールドにフォーカスを戻す + searchJTF.requestFocus(); + list.clearSelection(); + } + } + + @Override + public void keyReleased(KeyEvent e) { + // TODO Auto-generated method stub + + } + + }); + JScrollPane jsp = new JScrollPane(list); + rootFrame.add(jsp); + rootFrame.pack(); + // rootFrame.setSize(600,300); + rootFrame.setLocation(Launcher.centerOfScreen(rootFrame.getSize())); + + rootFrame.setVisible(true); + rootFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + } + + /** + * 選んだ! + * @param targetDir + */ + private void chooseDir(File targetDir){ + System.out.println("Selected : " + targetDir.getParentFile().getAbsolutePath()); + new CommandRunner("git status", targetDir.getParentFile().getAbsolutePath() ).startstop(); + + + } + + private void basicDirs() { + try { + execPath = App.getApplicationPath(this.getClass()); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + userhome = System.getProperty("user.home"); + + } + + private void findDotGitFileRecursive(File dir, ArrayList gitDirs, int level) { + if (level > 2) + return; + System.out.println("checking " + dir.getAbsolutePath()); + File[] list = dir.listFiles(new FileFilter() { + public boolean accept(File path) { + return (path.isDirectory()); + } + }); + if (list == null) + return; + for (File tempdir : list) { + if (tempdir.getName().equals(".git")) { + gitDirs.add(tempdir); + } else { + findDotGitFileRecursive(tempdir, gitDirs, level + 1); + } + } + } + + @Override + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + int index = list.locationToIndex(e.getPoint()); + File item = list.getModel().getElementAt(index); + chooseDir(item); + } + } + + @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/info/istlab/Zemi01/gitmonitor/JTAConsole.java b/src/main/java/info/istlab/Zemi01/gitmonitor/JTAConsole.java new file mode 100644 index 0000000..3ddb56c --- /dev/null +++ b/src/main/java/info/istlab/Zemi01/gitmonitor/JTAConsole.java @@ -0,0 +1,328 @@ +package info.istlab.Zemi01.gitmonitor; + +import java.awt.Point; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +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; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.util.Stack; + +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.text.BadLocationException; + +import info.istlab.Zemi01.Launcher; + +public class JTAConsole extends MyRSJTextArea + implements Runnable, WindowListener, KeyListener, MouseListener, ActionListener { + // static JTAConsole lastWindow; + // static Point lastActivePoint; + static Stack winStack = new Stack(); + JFrame frame; + Process process; + Thread thread; + InputStream instream; + InputStreamReader isreader; + BufferedReader reader; + OutputStream outstream; + + // StringBuilder originalContent; + // String mainSrc; + // ProcessBuilder pb; + CommandRunner comRunner; + + // public JTAConsole(ProcessBuilder prob) { + public JTAConsole(String title, CommandRunner runner) { + comRunner = runner; + // pb = prob; + + frame = new JFrame(title); + frame.getContentPane().add(new JScrollPane(this)); + frame.setSize(500, 200); + frame.setLocation(Launcher.centerOfScreen(frame.getSize())); + frame.setVisible(true); + frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); + frame.addWindowListener(this); + if (winStack.size() > 0) { + JTAConsole last = winStack.peek(); + if (last.isVisible()) { + Point lastFrameP = last.frame.getLocationOnScreen(); + frame.setLocation(lastFrameP.x + 470, lastFrameP.y); + } + } else { + // if (Editor.lastOpened != null) { + // Point lastEditorP = Editor.lastOpened.getLocationOnScreen(); + // Dimension lastEditorD = Editor.lastOpened.getSize(); + // frame.setLocation(lastEditorP.x, lastEditorP.y + lastEditorD.height); + // } + + } + addKeyListener(this); + addMouseListener(this); + + // if (lastActivePoint != null){ + // frame.setLocation(lastActivePoint.x+500, lastActivePoint.y); + // } else if (lastWindow != null && lastWindow.isVisible()){ + // Point lastFrameP = lastWindow.frame.getLocationOnScreen(); + // frame.setLocation(lastFrameP.x+500, lastFrameP.y); + // } + // lastWindow = this; + winStack.push(this); + // originalContent = new StringBuilder(); + } + + public void Systemoutprintln(String s) { + append(s + "\n"); + // originalContent.append(s + "\n"); + int len = getDocument().getLength(); + if (getSelectedText() == null) + setCaretPosition(len); + } + + public void startBR(Process proc) { + process = proc; + try { + reader = new BufferedReader(new InputStreamReader(proc.getInputStream(), "UTF-8")); + } catch (UnsupportedEncodingException e1) { + e1.printStackTrace(); + } + // isreader = new InputStreamReader(proc.getInputStream()); + outstream = process.getOutputStream(); + String line; + try { + // while(true){ + // if (isreader.ready()){ + // char[] buf = new char[1000]; + // isreader.read(buf); + // } + // } + while ((line = reader.readLine()) != null) { + Systemoutprintln(line); + } + process.waitFor(); + + } catch (IOException | InterruptedException e) { + // e.printStackTrace(); + System.out.print(e.getClass().getCanonicalName() + " : "); + System.out.println(e.getLocalizedMessage()); + } + } + + @Override + public void run() { + String line; + try { + while ((line = reader.readLine()) != null) { + Systemoutprintln(line); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void windowOpened(WindowEvent e) { + + } + + private void destroyProcess() { + try { + if (outstream != null) + outstream.close(); + if (instream != null) + instream.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } + process.destroyForcibly(); + } + + @Override + public void windowClosing(WindowEvent e) { + destroyProcess(); + + winStack.remove(this); + setVisible(false); + // if (!process.isAlive()) { + // Launcher.allProcs.remove(process); + // } + } + + @Override + public void windowClosed(WindowEvent e) { + + } + + @Override + public void windowIconified(WindowEvent e) { + + } + + @Override + public void windowDeiconified(WindowEvent e) { + + } + + @Override + public void windowActivated(WindowEvent e) { + // JTAConsole.lastActivePoint = frame.getLocationOnScreen(); + } + + @Override + public void windowDeactivated(WindowEvent e) { + + } + + @Override + public void keyTyped(KeyEvent e) { + + } + + @Override + public void keyPressed(KeyEvent e) { + // if (e.isShiftDown()){ + // setText(""); //reset content + // } + if (e.getKeyCode() == 10) { + setText(""); //reset content + comRunner.invoke(); + } + if (e.getKeyCode()== KeyEvent.VK_B){ + setText(""); //reset content + comRunner.invoke("git branch -avv"); + } + if (e.getKeyCode()== KeyEvent.VK_S){ + setText(""); //reset content + comRunner.invoke("git status"); + } + if (e.getKeyCode()== KeyEvent.VK_R){ + setText(""); //reset content + comRunner.invoke("git remote -v"); + } + + // if (e.getKeyCode() > 64 && e.getKeyCode() < 64 + 32) { + // if (e.isControlDown()) { + // System.out.print("CTRL+"); + // } + // if (e.isAltDown()) { + // System.out.print("ALT+"); + // } + // if (e.isAltGraphDown()) { + // System.out.print("AltGraph+"); + // } + // if (e.isMetaDown()) { + // System.out.print("META+"); + // } + // System.out.println(KeyEvent.getKeyText(e.getKeyCode())); + // } + + if (e.isControlDown() || e.isAltDown() || e.isAltGraphDown() || e.isMetaDown()) { + if (e.getKeyCode() == 67) { // CTRL+C + if (getSelectedText() != null) { + // 文字列をクリップボードにコピーする + Toolkit kit = Toolkit.getDefaultToolkit(); + Clipboard clip = kit.getSystemClipboard(); + StringSelection ss = new StringSelection(getSelectedText()); + clip.setContents(ss, ss); + System.out.println("選択範囲をコピーしました"); + } else { + // プロセスのみ終了 + destroyProcess(); + } + } + if (e.getKeyCode() == 68 || e.getKeyCode() == 87) { // CTRL+D or Alt-W + windowClosing(null); + frame.dispose(); + } + } + } + + private void sendLastLine() { + int start; + try { + start = getLineStartOffset(getLineCount() - 1); + int end = getLineEndOffset(getLineCount() - 1); + String lastLineText = getText(start, end - start) + "\n"; + // System.out.println(lastLineText); + + byte[] sbyte = lastLineText.getBytes(); + outstream.write(sbyte); + outstream.flush(); + // originalContent.append("") + + } catch (BadLocationException | IOException e) { + System.out.println(e.getLocalizedMessage()); + } + } + + @Override + 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 + + } + + /** + * PopupMenuの選択によるコマンド実行 + * + * @param e + */ + @Override + public void actionPerformed(ActionEvent e) { + if (e.getActionCommand().equals("Copy")) { + Toolkit kit = Toolkit.getDefaultToolkit(); + Clipboard clip = kit.getSystemClipboard(); + StringSelection ss = new StringSelection(getSelectedText()); + clip.setContents(ss, ss); + } else if (e.getActionCommand().equals("Show Diff")) { + } else if (e.getActionCommand().equals("Submit")) { + } + } + + public void setMainSrcByFileName(String absolutePath) { + } +} + \ No newline at end of file diff --git a/src/main/java/info/istlab/Zemi01/gitmonitor/MyRSJTextArea.java b/src/main/java/info/istlab/Zemi01/gitmonitor/MyRSJTextArea.java new file mode 100644 index 0000000..3b80e10 --- /dev/null +++ b/src/main/java/info/istlab/Zemi01/gitmonitor/MyRSJTextArea.java @@ -0,0 +1,93 @@ +package info.istlab.Zemi01.gitmonitor; + +import java.awt.Color; +import java.awt.Font; + +import javax.swing.JPopupMenu; +import javax.swing.plaf.FontUIResource; + +import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory; +import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; +import org.fife.ui.rsyntaxtextarea.Style; +import org.fife.ui.rsyntaxtextarea.SyntaxScheme; +import org.fife.ui.rsyntaxtextarea.Token; +import org.fife.ui.rsyntaxtextarea.TokenMakerFactory; + +public class MyRSJTextArea extends RSyntaxTextArea { + AbstractTokenMakerFactory atmf; + + public MyRSJTextArea() { + String syn = "TokenMaker4MyRSJTextArea"; + atmf = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance(); + atmf.putMapping(syn, "istlab.KisoJikken.Test." + syn); //独自のTokenMakerを登録 + setSyntaxEditingStyle(syn); + setFont(new FontUIResource("sansserif", Font.PLAIN, 14)); + + SyntaxScheme scheme = getSyntaxScheme(); + // SyntaxScheme scheme = new SyntaxScheme(false); + // for(Style s : scheme.getStyles()){ + // System.out.println(s); + + Style baseStyle = new Style(Color.black); + for (int i = 0; i < 39; i++) + scheme.setStyle(i, baseStyle); + Style commentStyle = new Style(new Color(0, 128, 0), new Color(255, 255, 0x66), //緑文字、黄色背景 + new Font("SansSerif", Font.ITALIC, 14)); + Style commentStyle2 = new Style(new Color(0, 128, 0), new Color(0xcc, 255, 255),// 緑文字、水色背景 + new Font("SansSerif", Font.ITALIC, 14)); + Style commentStyle3 = new Style(new Color(0xcc, 0x00, 0xcc), new Color(0xff, 0xcc, 0xff),//マゼンタむらさき文字、ピンク背景 + new Font("SansSerif", Font.ITALIC, 14)); + Style commentStyle4 = new Style(new Color(0x33, 0x88, 0xcc), new Color(0xee, 0xee, 0xee), + new Font("SansSerif", Font.PLAIN, 14)); + int[] comlist = new int[] { Token.COMMENT_EOL, Token.COMMENT_KEYWORD, Token.COMMENT_MARKUP }; + for (int c : comlist) { + scheme.setStyle(c, commentStyle); + } + int[] comlist2 = new int[] { Token.COMMENT_MULTILINE }; + for (int c : comlist2) { + scheme.setStyle(c, commentStyle2); + } + int[] comlist3 = new int[] { Token.COMMENT_DOCUMENTATION }; + for (int c : comlist3) { + scheme.setStyle(c, commentStyle3); + } + int[] comlist4 = new int[] { Token.ANNOTATION }; + for (int c : comlist4) { + scheme.setStyle(c, commentStyle4); + } + setSyntaxScheme(scheme); + + // scheme.getStyle(Token.COMMENT_EOL).background = Color.cyan; + // scheme.getStyle(Token.COMMENT_DOCUMENTATION).background = + // Color.cyan.brighter(); + // scheme.getStyle(Token.COMMENT_KEYWORD).background = Color.green; + // scheme.getStyle(Token.COMMENT_MARKUP).background = Color.gray; + // scheme.getStyle(Token.COMMENT_MULTILINE).background = Color.yellow; + + // scheme.getStyle(Token.FUNCTION).foreground = Color.black; + // scheme.getStyle(Token.IDENTIFIER).foreground = Color.black; + // scheme.getStyle(Token.LITERAL_NUMBER_DECIMAL_INT).foreground = Color.black; + // scheme.getStyle(Token.LITERAL_NUMBER_FLOAT).foreground = Color.black; + // scheme.getStyle(Token.LITERAL_NUMBER_HEXADECIMAL).foreground = Color.black; + // scheme.getStyle(Token.OPERATOR).foreground = Color.black; + // scheme.getStyle(Token.VARIABLE).foreground = Color.black; + // scheme.getStyle(Token.ANNOTATION).foreground = Color.black; + // scheme.getStyle(Token.DATA_TYPE).foreground = Color.black; + // scheme.getStyle(Token.ERROR_CHAR).foreground = Color.black; + // scheme.getStyle(Token.LITERAL_CHAR).foreground = Color.black; + + setHighlightCurrentLine(false); // カーソル行のハイライトを消す + setCodeFoldingEnabled(true); + + } + + @Override + protected void configurePopupMenu(JPopupMenu popupMenu) { + } + + @Override + protected JPopupMenu createPopupMenu() { + return null; + } + +}