# HG changeset patch # User ichikitakahiro # Date 1579610609 -32400 # Node ID 05c0b1649ca7230e13e954f800eb333c5911f6eb # Parent 8a7a2b8d0f07f02e666f5c5503bee5e32b33418f# Parent c8c8c447b2b398dda650553f1a539e7a0af8bb02 merge diff -r 8a7a2b8d0f07 -r 05c0b1649ca7 src/main/java/christie/remotingTextEditor/GetOpponentMessage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/remotingTextEditor/GetOpponentMessage.java Tue Jan 21 21:43:29 2020 +0900 @@ -0,0 +1,31 @@ +package christie.remotingTextEditor; + +import christie.annotation.Peek; +import christie.annotation.Take; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; +import christie.textEditor.NewTextEditor; +import christie.topology.Message; +import christie.topology.TopologyDataGear; + +public class GetOpponentMessage extends CodeGear { + @Take + int offset; + + @Take + String string; + Message offset; + + @Peek + NewTextEditor myEditor; + + @Peek + TopologyDataGear topoDG; + + + @Override + protected void run(CodeGearManager cgm) { + System.out.println( topoDG.getNodeName() + " catch Offest:" + offset); + cgm.setup(new GetOpponentMessage()); + } +} diff -r 8a7a2b8d0f07 -r 05c0b1649ca7 src/main/java/christie/remotingTextEditor/SetEditorCommunication.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/remotingTextEditor/SetEditorCommunication.java Tue Jan 21 21:43:29 2020 +0900 @@ -0,0 +1,35 @@ +package christie.remotingTextEditor; + +import christie.annotation.Peek; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; +import christie.textEditor.NewTextEditor; +import christie.topology.Message; +import christie.topology.TopologyDataGear; + +public class SetEditorCommunication extends CodeGear { + @Peek + TopologyDataGear topoDG; + + @Peek + NewTextEditor myEditor; + + @Override + protected void run(CodeGearManager cgm) { +// System.out.println(topoDG.getNodeName()); + while(myEditor.checkPermission() == false){ + try{ + Thread.sleep(1); + }catch(InterruptedException e){ + + } + } + int sendOffset = myEditor.getOffset(); + System.out.println(topoDG.getNodeName()+ ":catchoffset=: " + sendOffset); +// put("opponent", "offset", new Message()); + myEditor.changeToFalseSendPermmision(); + cgm.setup(new SetEditorCommunication()); + + } + +} diff -r 8a7a2b8d0f07 -r 05c0b1649ca7 src/main/java/christie/remotingTextEditor/SetInstance.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/remotingTextEditor/SetInstance.java Tue Jan 21 21:43:29 2020 +0900 @@ -0,0 +1,57 @@ +package christie.remotingTextEditor; + +import christie.annotation.Peek; +import christie.annotation.Take; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; + +import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.text.*; +import christie.textEditor.*; +import christie.topology.Message; +import christie.topology.TopologyDataGear; + +import java.io.FileWriter; + + +public class SetInstance extends CodeGear { + + @Peek + TopologyDataGear topoDG; + + protected void run(CodeGearManager cgm) { + + System.out.println("I am " + topoDG.getNodeName()); + if(topoDG.getNodeName().equals("node0")) { + NewTextEditor Editor0 = new NewTextEditor(); + Editor0.StartEditor(topoDG.getNodeName()); + System.out.println("node0"); + //cgm.setup(new GetOpponentMessage()); + cgm.setup(new SetEditorCommunication()); + cgm.getLocalDGM().put("myEditor", Editor0); + + }else if(topoDG.getNodeName().equals("node1")){ + NewTextEditor Editor1 = new NewTextEditor(); + Editor1.StartEditor(topoDG.getNodeName()); + System.out.println("node1"); + //cgm.setup(new GetOpponentMessage()); + cgm.setup(new SetEditorCommunication()); + cgm.getLocalDGM().put("myEditor", Editor1); + } + //cgm.setup(new CatchDG()); + + + /* + while(myEditor.SendPermission() == false){ + try{ + Thread.sleep(1); + }catch(InterruptedException e){ + + } + } + System.out.println("catch"); + */ + } +} diff -r 8a7a2b8d0f07 -r 05c0b1649ca7 src/main/java/christie/remotingTextEditor/StartManToManSession.java.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/remotingTextEditor/StartManToManSession.java.orig Tue Jan 21 21:43:29 2020 +0900 @@ -0,0 +1,34 @@ +package christie.remotingTextEditor; + +import christie.codegear.CodeGearManager; +import christie.codegear.StartCodeGear; +import christie.topology.manager.StartTopologyManager; +import christie.topology.manager.TopologyManagerConfig; + +public class StartManToManSession extends StartCodeGear { + + public StartManToManSession(CodeGearManager cgm) { + super(cgm); + } + + public static void main(String[] args){ + int TopologyManagerPort = 10000; + int TopologyNodePort = 10001; + + String[] managerArg = {"--localPort", String.valueOf(TopologyManagerPort), "--confFile", "scripts/Log/manToMan.dot"}; + + TopologyManagerConfig topologyManagerConfig = new TopologyManagerConfig(managerArg); + new StartTopologyManager(topologyManagerConfig); + + + for (int i = 0; i <= 1; i++){ + String[] nodeArg = {"--managerPort", String.valueOf(TopologyManagerPort), + "--managerHost", "localhost", + "--localPort", String.valueOf(TopologyNodePort + i), + }; + + NodeStart.main(nodeArg); + + } + } +} diff -r 8a7a2b8d0f07 -r 05c0b1649ca7 src/main/java/christie/remotingTextEditor/StartManToManSession.java.rej --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/remotingTextEditor/StartManToManSession.java.rej Tue Jan 21 21:43:29 2020 +0900 @@ -0,0 +1,17 @@ +*************** +*** 12,17 **** + } + + public static void main(String[] args){ + //ポート番号10000~1000xはone上では他のライブラリに使われている。(Net.javaにつかわれている?) + int TopologyManagerPort = 10100; + int TopologyNodePort = 10101; +--- 12,19 ---- + } + + public static void main(String[] args){ ++ int TopologyManagerPort = 10000; ++ int TopologyNodePort = 10001; + //ポート番号10000~1000xはone上では他のライブラリに使われている。(Net.javaにつかわれている?) + int TopologyManagerPort = 10100; + int TopologyNodePort = 10101; diff -r 8a7a2b8d0f07 -r 05c0b1649ca7 src/main/java/christie/textEditor/NewTextEditor.java --- a/src/main/java/christie/textEditor/NewTextEditor.java Tue Jan 21 21:14:04 2020 +0900 +++ b/src/main/java/christie/textEditor/NewTextEditor.java Tue Jan 21 21:43:29 2020 +0900 @@ -14,6 +14,11 @@ TextFrame textFrame = new TextFrame(); static JTextArea textArea = new JTextArea(); + + public void callInner(){ + textFrame.insertText(); + } + public boolean checkPermission(){ return textFrame.SendPermission(); } @@ -30,8 +35,6 @@ textFrame.changeToFalseSend(); } - public void insertMessage(int offset, String str){textFrame.insertText(offset, str);} - // public static void main(String[] args){ // NewTextEditor editor = new NewTextEditor(); // diff -r 8a7a2b8d0f07 -r 05c0b1649ca7 src/main/java/christie/textEditor/main.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/textEditor/main.java Tue Jan 21 21:43:29 2020 +0900 @@ -0,0 +1,8 @@ +package christie.textEditor; + +public class main { + public static void main(String[] args) { + mainFrame mF = mainFrame.getInstance(); + mF.setVisible(true); + } +} diff -r 8a7a2b8d0f07 -r 05c0b1649ca7 src/main/java/christie/textEditor/mainFrame.java.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/textEditor/mainFrame.java.orig Tue Jan 21 21:43:29 2020 +0900 @@ -0,0 +1,86 @@ +package christie.textEditor; + +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.event.KeyEvent; + +import java.io.File; +import java.io.IOException; + +import javax.swing.JDesktopPane; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.KeyStroke;; + +public class mainFrame extends JFrame{ + private JDesktopPane desktop; + + private JFileChooser fileChooser; + + private static mainFrame instance; + + private mainFrame(){ + //タイトルを設定 + super("テキストエディタ") ; + setSize(1024,768); + //ウィンドウを閉じたらアプリを終了する。 + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + //メインウィンドウにコンポーネントを配置する領域とのこと。 + Container container = this.getContentPane(); + + //メニューバーを初期化 + JMenuBar menuBar = new JMenuBar(); + //コンテナにメニューバーを配置する(ウインドウ上部に) + container.add(menuBar, BorderLayout.NORTH); + JMenu menuFile = new JMenu("ファイル"); + menuBar.add(menuFile); + //開くメニューの作成 + JMenuItem menuOpen = new JMenuItem(new menuActionOpen()); + //CTRT + oショートカットキーの設定 + menuOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_0,KeyEvent.CTRL_DOWN_MASK)); + //ファイルメニューに開くを追加する + menuFile.add(menuOpen); + + desktop = new JDesktopPane(); + container.add(desktop); + + textFrame tF = new textFrame(); + desktop.add(tF); + tF.setVisible(true); + + //ファイル選択ダイアグの初期化 + fileChooser = new JFileChooser(); + //テキストファイル(*.txt)のみ表示するフィルターを追加 + //fileChooser.addChoosableFileFilter(new TextFileFilter()); + } + + void openFile(){ + //ファイルを開くダイアログを表示する + int result = fileChooser.showOpenDialog(this); + //ファイル選択時の処理 + if (JFileChooser.APPROVE_OPTION == result) { + File selectedFile = fileChooser.getSelectedFile(); + try{ + textFrame tF = new textFrame(selectedFile); + //JDesktopPaneにテキストウィンドウを追加 + desktop.add(tF); + tF.setVisible(true); + }catch(IOException e){ + JOptionPane.showMessageDialog(this, "IOExeption: ファイルを開くのに失敗しました。"); + } + } + } + + public static mainFrame getInstance(){ + if (instance == null){ + instance = new mainFrame(); + } + return instance; + } + +} diff -r 8a7a2b8d0f07 -r 05c0b1649ca7 src/main/java/christie/textEditor/menuActionOpen.java.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/textEditor/menuActionOpen.java.orig Tue Jan 21 21:43:29 2020 +0900 @@ -0,0 +1,17 @@ +package christie.textEditor; + +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; + +class menuActionOpen extends AbstractAction{ + + @Override + public void actionPerformed(ActionEvent e){ + mainFrame.getInstance().openFile(); + } + + menuActionOpen(){ + super("開く"); + } +} diff -r 8a7a2b8d0f07 -r 05c0b1649ca7 src/main/java/christie/textEditor/textFrame.java.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/textEditor/textFrame.java.orig Tue Jan 21 21:43:29 2020 +0900 @@ -0,0 +1,68 @@ +package christie.textEditor; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; + +import javax.swing.JInternalFrame; +import javax.swing.JTextArea; + + + +public class textFrame extends JInternalFrame{ + private JTextArea textArea; + + private static String DEFAULT_CHARACTER_CODE = "Shift_JIS"; + + public textFrame(){ + this("新規テキスト"); + } + + public textFrame(String title){ + //JInternalFrameのコンストラクタの呼び出しを実行 + super(title, true, true, true , true); + //サイズの指定 + this.setSize(800,600); + // JTextArea(テキスト入力のコンポーネントを追加する。) + textArea = new JTextArea(); + this.add(textArea); + } + + public textFrame(File file) throws IOException { + this(file.getName()); + this.openFile(file); + } + + void openFile(File file) throws IOException{ + FileInputStream fiStream = null; + ByteArrayOutputStream baoStream = null; + try { + fiStream = new FileInputStream(file); + baoStream = new ByteArrayOutputStream(); + //読み込みデータ格納用配列 + byte[] byteData = new byte[1]; + int ret = fiStream.read(byteData); + //ファイルの最後まで繰り返す。 + while (ret != -1) { + baoStream.write(byteData); + ret = fiStream.read(byteData); + } + //バイト配列を文字列に変換 + String text = new String(baoStream.toByteArray(), DEFAULT_CHARACTER_CODE); + //テキストGUIに読み込んだファイルの内容を設定 + textArea.setText(text); + //タイトルを開いたファイル名へ変更 + this.setTitle(file.getName()); + }finally{ + if(fiStream != null){ + fiStream.close(); + } + if(baoStream != null){ + baoStream.close(); + } + } + } +}