From 0c71a85cba8ca0bd2c7f5672dfa9316f9470b449 Mon Sep 17 00:00:00 2001 From: GustavoHMDS Date: Tue, 29 Sep 2026 00:21:04 -0300 Subject: [PATCH] WIP bug fix 3 --- pitiupi.testSocket/dist/testSocket.jar | Bin 6537 -> 0 bytes pitiupi.testSocket/out/GUI/ChatMenu.class | Bin 0 -> 4149 bytes pitiupi.testSocket/out/GUI/ChatWindow.class | Bin 0 -> 3750 bytes .../out/GUI/PrivateChatWindow.class | Bin 0 -> 2281 bytes .../out/GUI/PublicChatWindow.class | Bin 0 -> 3719 bytes .../META-INF/services/pitiupi.plugin.Plugin | 2 +- .../out/control/ChatController.class | Bin 0 -> 2224 bytes .../out/net/TestChatMessage.class | Bin 0 -> 747 bytes pitiupi.testSocket/out/plugin/TestChat.class | Bin 0 -> 3334 bytes pitiupi.testSocket/src/GUI/ChatMenu.java | 84 ++++++++++ pitiupi.testSocket/src/GUI/ChatWindow.java | 94 +++++++++++ .../src/GUI/PrivateChatWindow.java | 46 ++++++ .../src/GUI/PublicChatWindow.java | 93 +++++++++++ .../src/GUI/SocketTestMenu.java | 21 --- .../src/GUI/SocketTestWindow.java | 151 ------------------ .../META-INF/services/pitiupi.plugin.Plugin | 2 +- .../src/control/ChatController.java | 62 +++++++ ...{TestMessage.java => TestChatMessage.java} | 6 +- pitiupi.testSocket/src/plugin/SocketTest.java | 77 --------- pitiupi.testSocket/src/plugin/TestChat.java | 100 ++++++++++++ pitiupi/src/pitiupi/GUI/Login.java | 1 - 21 files changed, 484 insertions(+), 255 deletions(-) delete mode 100644 pitiupi.testSocket/dist/testSocket.jar create mode 100644 pitiupi.testSocket/out/GUI/ChatMenu.class create mode 100644 pitiupi.testSocket/out/GUI/ChatWindow.class create mode 100644 pitiupi.testSocket/out/GUI/PrivateChatWindow.class create mode 100644 pitiupi.testSocket/out/GUI/PublicChatWindow.class create mode 100644 pitiupi.testSocket/out/control/ChatController.class create mode 100644 pitiupi.testSocket/out/net/TestChatMessage.class create mode 100644 pitiupi.testSocket/out/plugin/TestChat.class create mode 100644 pitiupi.testSocket/src/GUI/ChatMenu.java create mode 100644 pitiupi.testSocket/src/GUI/ChatWindow.java create mode 100644 pitiupi.testSocket/src/GUI/PrivateChatWindow.java create mode 100644 pitiupi.testSocket/src/GUI/PublicChatWindow.java delete mode 100644 pitiupi.testSocket/src/GUI/SocketTestMenu.java delete mode 100644 pitiupi.testSocket/src/GUI/SocketTestWindow.java create mode 100644 pitiupi.testSocket/src/control/ChatController.java rename pitiupi.testSocket/src/net/{TestMessage.java => TestChatMessage.java} (76%) delete mode 100644 pitiupi.testSocket/src/plugin/SocketTest.java create mode 100644 pitiupi.testSocket/src/plugin/TestChat.java diff --git a/pitiupi.testSocket/dist/testSocket.jar b/pitiupi.testSocket/dist/testSocket.jar deleted file mode 100644 index 3b6438b3ccb62d29b66c776245e082711a2c73e1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6537 zcmaJ_1z42Z)<(K>kZweBq&p-8=@EwRlo5~yX;A4HrCS;a=?19*>F$OZ8bwM#Q261V z^B=h9o_p6k-}8O*%vyV`*?WKcUGEE0MnT0!Lc&BsT8R@kLb_vENT^7vPr%Y#ifZzY zF8h#>K-aDSBuq@q|8NCdhyCTMDy^m{|3niERFywc9q3n4<^qo5DRZ$84GdRla8K~9 ztUCjhR5=w@N8O65HMn^v`9}D_Bm0k(RE89_9ETpU_dHVKyvIJZwhmuMzD|mP34Ie6 zCVQPi=K8uR;*WZ#4gS4e)azdrv=krRmO1gae?ZKdd!p_Xa zB^|u0Mj{QkM8{T63`$6d_-Kd*Q8qhxUB`$`N?Ikr+(rCb$O=Ob;?cVo*I|)tqsV=5 zFLKyYylEa&R~i9LPj|T(@)$}>c92qQLDq%wk=onn5RQ%nss*eW6-q?ps()&LlVvV#O%Wi6gIzp5%FOaCUpAQbcv7EphxTwyhvulbyue@HC& z+>p$RBCg|$px_8lfH3Tb{(LuiTd>i{A`%bE3B^ zEJJk)URN~35!yt7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)!i9wuyyVqs@?mZ13{!>lVN`h`&#g?8)x{HD6bKr!Eios15l| zdt;YoXW+;Kos9(URsj(TtvBS@OW0f$4@sI-e$)#0j@EpUf2JfOWK4Ekl&IUDh%3=V zF~{V;wfT`x#pby=R!+(SZ&3l}4syl8@AcPWxOK~$Ow(!FgS9CRR<-70%_>@Pc6HYK z0-Aykyw1N2^-dvJd_}z4$`z%0$}oEUM8`LwYXz=N^6C&A)yejy(ZDRZ%4tn`#g`15 zvfVy5rcZx1pa{zxJ|QzTdB`pA+=Nr!O7bdwtsmHilip^)ECnkkFqD6XjsB&8GIUR6 z+UYAphgAFa^ z_3TxO|EnDA7J9U#*IM!9{y}BFOU?|ItwT|gvWHY#_T`U-W<+~GpDOgn@{3#i^uIY< zyo>+}hbTx$(bvZZNckQzHqw9Btgp|GJN6f}{h?srLk1w-YS?#$Hnlzw(<=?qd6mycZ>SplNxwE z=pQY?Z5cPyaTj}Tnu1%)`7`1_T7>_V^aiAEP5XLc{(`K3&wF=Y-hkGvdEW-zuIC>R W22w^tzj4I5{wZ~q6(G7Jy^ diff --git a/pitiupi.testSocket/out/GUI/ChatMenu.class b/pitiupi.testSocket/out/GUI/ChatMenu.class new file mode 100644 index 0000000000000000000000000000000000000000..65067fef2ec7f61d0bed894adccec041b1c32400 GIT binary patch literal 4149 zcma)9`&%4W8GaA2%&?gRvLtObNeM}*gS zfS_%>)_c8It=4PRc&pmjKm@IqsMT7v-mm|FKly_{>f_^kW(IZ^NS-`A?3{DvJKyC! z@ArLYUija_a{vzEA5qkxRzaPH2Rk^)icY0|I} zF|L&jci6bVO`F@Z(t%V_r}-h*p%*V-n}Yk^%s0M}K}F(M=1rQvq85mBlT*yC@if?Wm|c(Zyv27#B! znC=wVTZ!P5X%+05n}|V0hlT`_JX^<@w5JV$t=IK|@OKF`SHXYK)Qk3b6e;Xcuvf#& zaTisDMTR7UPP%5%bWNj7u*MD7_pjH=lM%KfaAydtv^`m}Eg~LvKL|+0E2v<=p0-=_ zq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upi.testSocket/out/GUI/ChatWindow.class b/pitiupi.testSocket/out/GUI/ChatWindow.class new file mode 100644 index 0000000000000000000000000000000000000000..98660b9974e9dcadf32a4b6caf2c35c4bcc01383 GIT binary patch literal 3750 zcma)9`Fj)B6+L6i9y1MLff(Q0AXoHof%=E z8{M*W-}imro3uf8aMH9**EHSt|D!+m>$x){TLORi^7-@3_`P@UJ@4Fe?|Xjne>Z;$ z;0XR>pb5=7VkTP9s-gRmb=kU-@a78kg~Y^|Yn7CS)&m8*;2+e`+&^%7722>$hhd@} zriPA(rpFV>idBTHl`%u!*8Ys2SfS;^BeQvUr1u zjp)&!b8)6{jcZ%_$H&9D%_d%jEwtub%E?)N!Ld)NBHx$Ql%ruo?MYx!v9oS>yHMm#9D(<*uxiti}vQbF#YfapT`w2=i zdrIXL$<3#g=MlRXP_aaG&CNtG91*?W#IV?Riv6hL`%WpCmgGKQ;vgQRY6vOm*ghpA zb4v~rVdiX~Vhf1UaVTPaDb|#_;vXU>21d{$}SC@#FU6*OB+sWSesV1aB6$o1o%uLZ+QlW@H!J&JWLISi4O`UU(4U# zmFlKpgOLvE&A8Q**wcn{>;_3vu3VAF8%(?rWcLE%q5lcnPVL} z4R^^DaRXI~_@vDIRq^pV(`jZdpj|6};KRTLe`HZDe`mMEH1{iMPv?&M6^E$2*vO zaU%Uux^Glm2Cm~>qK|iLIJQEb>yi<5%vUlZ342t-mZd#T+q1SaXA8O;pF@ z8a4$>f{uKuV*7=XTADZT7~U(;-X}cNg`K+SI&)Gr6h=1>r4N|+AU;GwvXtg;;oCaCW8%B`UPIt8t1Qy< zj$5)QxqbCiM>#)R$9}CQ>xQCL(xrZ2;)inVwp!(~vRRuWc+$jE_;FYxhn-xd#BM-s zM9Qww>rJn$xCajgO!B4}A+U&95bPy_86wEvfV!QC^bjMfAXI#)iUPwH z8^Ug)8#-aw`>+-J2w<2&AHcmh7>mjMg0nF^kDo)D}QgFUf%yz|NQA|A^Q&EtvZX%6z(hxd?2$$J?1Fn4`~*&bsKj&gPaJIVFW zInVqnovStc0xv|t@20J2p*=o$6YmEW@Zn_w<)1t7o@wA*SCce}$mkmJ3Q?oopVXhj zr?bsez-Ker7++t=WLx<9awgl#*Vi%&_-0x%MW((lZ~3j_N6+9V8mf3^Io3`}6}%*_ zLWZ)L!Ujx}z0(xSNp2vE-8f6>Ji@rY;<_gM8o%M&B%+r%_FMdpzklP1!I8h?pZGU= F{txge@+ANO literal 0 HcmV?d00001 diff --git a/pitiupi.testSocket/out/GUI/PrivateChatWindow.class b/pitiupi.testSocket/out/GUI/PrivateChatWindow.class new file mode 100644 index 0000000000000000000000000000000000000000..9415b28fc76579583a04a7ed31527a4607367a82 GIT binary patch literal 2281 zcma)7Yg5}s6g}$z0wG?8B)lOBA+~|IZPGT4)3n$%38_qI?2yv*k;Ps>AWN>a=F$G3 zeoiMfoiNiM(CKgL^scOc7#yY_q?LB>>)d#xTGum9xhT*TZ1mYe1o!V2GbVx5^!1YnTdA zr7f$~3~hPtQ*h%*D-RzqBwN~!ROji& z4iSms>cmG3-BifwkZ?M2@vec7@d-mu*%QRUg7AHUaccHVflbA~lJKQsS13x=xrfg* z+&7TH14?EK8FDM#?4cBkp2rUfL?ZbztK%WQ(D0>!MPwN!F621r_`;!7wkKX@RXM+U zSGFL){6SgNRI}(aJ7XK>I0jISIn>F zpXC`wS{YL^lzkK58d%47L^g_%Ar}U7)^i{nVMW-pk)6`E=kD_jTLcu2;d=u=;77`s zN<6WK>?e{G?)~=;k(1%ldQ2(hwwzm`-1nK5BUb9w4dIoPOCpFGQO$uvRl3^5a59O4 zUZuE*r$x!jy9Hhg^@eO--Kg-Hi24k5#Z;s#qBAA0=1X8mFS>QFES4=YMXE}TBuAmX2f+Q1s zlg6U!Q4e%iqksQI85AltJwE16#TNdI>AJi1S|(Dk^Cdi^SURkUsQCXsY`VNyH`+U) z9^(%uHS^N^Q~11+GyMI_b)x$*yiw`f8)^ zZu~^=SM)ch?pj*AQ}cg-rRI*Hy{2CVPVe5}Xn+(4p<{?tH&6~0Ux99DlDT_~p7nU& z5e5qLskbDA28NF@zJ83!_4dw7N0>gsjg^J@24-K(EyQWPed=K}2x*wCkCN&*X6Z_q z$29H)fm3gV-X!^ok+)l^_=gSLF;j2A<{J34fzN-#kQt9PkpB~3|Bi3e_KVk~210xp zIZ{(lX3<6On-ugc?a$Lmg6`lXhLOS;tv4tWvsgfdq%_2yYsmHY#}s+P2qtJ%5wxco nczFt-Bk(jziQ1yW7`9>2YS6Ajdpp>rr%pRM?d;(IzhLA)kyBxD literal 0 HcmV?d00001 diff --git a/pitiupi.testSocket/out/GUI/PublicChatWindow.class b/pitiupi.testSocket/out/GUI/PublicChatWindow.class new file mode 100644 index 0000000000000000000000000000000000000000..01f559275508d01cfa755155a7d194add83af3be GIT binary patch literal 3719 zcmb7G33nS;75>JtJc=@n71d6nCUFwuw6?scO-e)KHYJvw#;N2e^;WfoGL~NKiKQ7a z8hI&DO4+&qWv47HJ7tHIR0=VaeK{O{6Nm53j5b>-<@i|h-n_ef_kQ=@H~;$2&9?wd z;h!ONV3&$c4FPm1*!%GObUd-5JBx;yv(^=KJz$uIb5_Bj!DP{JjB?S4OPQ2zn4Zk| z&_W17>{b!dum_rg9x0G6FXfGFv#CAO(sc2>A@Vr|2L_W@^)-DXURpQI<@m+4Zi>8b zYp;fGY3QKTNLYnJ*)+1cV_4=y*>Nnhq+*|f{Vn=)V#9GwhY-f?GMpX-y9S3Ab`#uw z4F_;gfojy;A8hqr*B)1Khk}SS9oN^L_@q$~W{I9dh~ls`dqhECaC%xs9mY`&$8cOh zxFnpkEv^XL7P(pDX;BZb)d~Yt@h;y%YwRjcDCn&_p0Mnku#@_xRdzxcz~K=3F(?5H zxn$G@J&}}d>dV4*?GJCapVXH`K8R5Td#2OJa-!rIrgbKS7~<04-Sq3R5zp)7V%D)q z2~7oYQbFe;<)!m`HM|@5F{yfv{0;dUGD)PUXqm!v#@(!XRxT}F6dw=4{uL zKtUqHUP`D)`4PIzpU+$CH4>A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~QE*iIC{~yYS*~}*BCq%;n1GiV>o;!gIfCAL{CBv;Fi+2m^!x-*GA!fA zaVMUvd7YQBhdbmr^SvJ7Q+f@=DtN6ytn4gcjG~-_ZA8DbU38S99H4DPzrS5{gp~i1 n);sVk{F={W+;8#!8s6Z)w|cX_y1~_-DJ47pFZdh&f#`n$X5o*ifnI_hh2tt18vw{=%6M;+qQEQ%APQEbQ-HcHUV;CWI!Z96JaZRA7KtdU5 z)m(w0^eOw4vc0b3hO)h=YyNJ;dtfq|t18NhCoA2!MW)$Z`yf&(+j*lL zQGQ`WFsY6^MZai(kOq^s6g9b>UQ$^Ng|UD|4NE${ zz+-{&rWDV_r*KQsdr~Yq(q+v@qOl;VGG5`(*hz))C6+Zj)!9PNC}Ce3CyWHTJv*o$ zEt-+qtE%|D(6OSbuDR0Nl2ZlZc5h+wC%4qL{Zcs)p+*s%kXLreb<6YwfFPFN5tlPobHmPl)%&f5$(SzO{p-k^ZTG_?bkDwW6GB8 zBG1vEHZ8ectK_A#Y52M9HHyVnn+Z&`f~stt)kFflSt;|L1zm*_!!VR)uI-%cFifsXQtA^kOFOe9B!*-!Ah^q%$Xt;_p$3({|m1a zk5R&L9#ITdNnkS(s^c4ie%Ctu7`o_rhoG}e!CfBr9^vN*d!HCTBi}gqBr#MCdl+kw taer)uP=70cM`S-wV+U@-CBb!7rhx{n0%;Nar<0xw=*J>`Jlb}k_Ae&OFpvNM literal 0 HcmV?d00001 diff --git a/pitiupi.testSocket/out/net/TestChatMessage.class b/pitiupi.testSocket/out/net/TestChatMessage.class new file mode 100644 index 0000000000000000000000000000000000000000..02c09f3b8af1ca738669134b7f69292afea44387 GIT binary patch literal 747 zcmbVJ+fKqj5ItK96)cKeRJ`*B^}+{ed@+(3(HDvDRX4as+6Ic>rHPG+4}O3jWjuos z6?rmE=5%(>IWs%^_Wtq;;0T*pSeSBPyGS9eP>f7$29aq5I&Pfme&6qCh4j7&Onjg) zRjXfQFpZ3Ztcw}AR0y-J`|;t8ACD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FNA^_y4FT=*ChLYLH9D&PtmW9x#Ti7PxTL6 z#MWQ1qkmut*VbI!KnRfJI)HW9LpKKzM~Vv1;KfjF+>a&@Sw>>&BKn(2+(fyTPza?{ z>RwBo-O2tX4CInOV+T#{t(jcsAK%6(@2ANj!d}L{5WJgUm9$O;BmU+ZOx>5kD?|i` zDEtau4Iz7}uAL`6NtziL^?`eqa9a%-7);aPo#^J(Ti~@z8az;g1qL%Tc!H4E@kVHH zmgba${WR6RghTzmBAr}9M*S@zce?$D+)ucNWTt<^1Hcky+I}Du*n}9T^BTXzg1C=j zBTjPn6fa$O^O`t;Hz~*Ro6>wqUKc~7-_hh+o*h`m+*JQXoXstxIK`Ygqjc6C>WFpx ziNq)9igo;f#87*z{lfR?8EPk!So;zlB@1zZwmWHM4;I4b`H;;{Itkp%-D&jVeqM#o zuqF&jK1c=+F-bE%vmI#r8%Ygw8jAlC%l}_`G`z(P2r|}5@*OH#gLm;BpAnM(kbm#v PbN-6*?F)Q`ZxH(ra<@wu literal 0 HcmV?d00001 diff --git a/pitiupi.testSocket/src/GUI/ChatMenu.java b/pitiupi.testSocket/src/GUI/ChatMenu.java new file mode 100644 index 0000000..9b7e0e2 --- /dev/null +++ b/pitiupi.testSocket/src/GUI/ChatMenu.java @@ -0,0 +1,84 @@ +package GUI; + +import plugin.TestChat; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.List; + +public class ChatMenu extends JMenu { + private final TestChat testChat; + + public ChatMenu(TestChat testChat) { + this.testChat = testChat; + this.setText("MP-Chat"); + + JMenuItem startPrivateChat = new JMenuItem("start Private Chat"); + startPrivateChat.addActionListener(_ -> showPrivateChatDialog()); + this.add(startPrivateChat); + } + + public void newMenuItem(JMenuItem newMenuItem, ChatWindow chatWindow) { + newMenuItem.addActionListener(_ -> chatWindow.setVisible(true)); + + this.add(newMenuItem); + } + + public void removeMenuItem(JMenuItem removeMenuItem) { + this.remove(removeMenuItem); + } + + private void showPrivateChatDialog() { + JDialog dialog = new JDialog( + SwingUtilities.getWindowAncestor(this), + "Novo chat privado", + Dialog.ModalityType.APPLICATION_MODAL + ); + + JTextField ipField = new JTextField(); + + JButton startButton = new JButton("Iniciar"); + JButton cancelButton = new JButton("Cancelar"); + + JPanel contentPanel = new JPanel(new BorderLayout(10, 10)); + contentPanel.setBorder( + BorderFactory.createEmptyBorder(10, 10, 10, 10) + ); + + JPanel ipPanel = new JPanel(new BorderLayout(5, 5)); + ipPanel.add(new JLabel("IP:"), BorderLayout.WEST); + ipPanel.add(ipField, BorderLayout.CENTER); + + JPanel buttonsPanel = new JPanel( + new FlowLayout(FlowLayout.RIGHT) + ); + + buttonsPanel.add(cancelButton); + buttonsPanel.add(startButton); + + JLabel errorLabel = new JLabel("Não foi possível estabelecer a conexão."); + errorLabel.setForeground(Color.RED); + errorLabel.setVisible(false); + + contentPanel.add(errorLabel, BorderLayout.NORTH); + contentPanel.add(ipPanel, BorderLayout.CENTER); + contentPanel.add(buttonsPanel, BorderLayout.SOUTH); + + cancelButton.addActionListener(e -> dialog.dispose()); + + startButton.addActionListener(e -> { + String ip = ipField.getText(); + + if (testChat.openConnection(ip)) dialog.dispose(); + else errorLabel.setVisible(true); + + }); + + dialog.setContentPane(contentPanel); + dialog.pack(); + dialog.setLocationRelativeTo(SwingUtilities.getWindowAncestor(this)); + dialog.setVisible(true); + } +} diff --git a/pitiupi.testSocket/src/GUI/ChatWindow.java b/pitiupi.testSocket/src/GUI/ChatWindow.java new file mode 100644 index 0000000..9e9a0f6 --- /dev/null +++ b/pitiupi.testSocket/src/GUI/ChatWindow.java @@ -0,0 +1,94 @@ +package GUI; + +import net.TestChatMessage; +import pitiupi.GUI.MainWindow; + +import javax.swing.*; +import java.awt.*; +import java.net.InetAddress; +import java.net.UnknownHostException; + +public abstract class ChatWindow extends JFrame { + + protected final MainWindow mainWindow; + + private JTextArea receivedMessagesArea; + protected JTextField messageField; + + public ChatWindow(MainWindow mainWindow) { + this.mainWindow = mainWindow; + initComponents(); + } + + private void initComponents() { + setTitle("Socket Test"); + setSize(700, 500); + setLocationRelativeTo(null); + setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); + + JPanel mainPanel = new JPanel(new BorderLayout(10, 10)); + + mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + + initReceivedMessagesPanel(mainPanel); + initBottomPanel(mainPanel); + + setContentPane(mainPanel); + } + + private void initReceivedMessagesPanel(JPanel mainPanel) { + receivedMessagesArea = new JTextArea(); + receivedMessagesArea.setEditable(false); + receivedMessagesArea.setLineWrap(true); + receivedMessagesArea.setWrapStyleWord(true); + + JScrollPane messagesScrollPane = new JScrollPane(receivedMessagesArea); + + messagesScrollPane.setBorder(BorderFactory.createTitledBorder("Mensagens recebidas")); + + mainPanel.add(messagesScrollPane, BorderLayout.CENTER); + } + + private void initBottomPanel(JPanel mainPanel) { + messageField = new JTextField(); + + JPanel bottomPanel = new JPanel(new BorderLayout(10, 10)); + + bottomPanel.add(messageField, BorderLayout.CENTER); + + initButtons(bottomPanel); + + mainPanel.add(bottomPanel, BorderLayout.SOUTH); + } + + protected abstract void initButtons(JPanel bottomPanel); + + protected TestChatMessage createMessage(String tipoMensagem) { + try { + String nome = mainWindow.getUserName(); + String ip = InetAddress.getLocalHost().getHostAddress(); + String message = messageField.getText(); + + return new TestChatMessage(nome, ip, tipoMensagem, message); + + } catch (UnknownHostException e) { + throw new RuntimeException(e); + } + } + + public void receiveMessage(TestChatMessage msg) { + SwingUtilities.invokeLater(() -> { + String mensagem = String.format( + "[%s] %s (%s): %s%n", + msg.getTipoMensagem(), + msg.getNome(), + msg.getIp(), + msg.getMessage() + ); + + receivedMessagesArea.append(mensagem); + + receivedMessagesArea.setCaretPosition(receivedMessagesArea.getDocument().getLength()); + }); + } +} \ No newline at end of file diff --git a/pitiupi.testSocket/src/GUI/PrivateChatWindow.java b/pitiupi.testSocket/src/GUI/PrivateChatWindow.java new file mode 100644 index 0000000..8b809a9 --- /dev/null +++ b/pitiupi.testSocket/src/GUI/PrivateChatWindow.java @@ -0,0 +1,46 @@ +package GUI; + +import net.TestChatMessage; +import pitiupi.GUI.MainWindow; +import pitiupi.net.tcp.TcpConnection; + +import javax.swing.*; +import java.awt.*; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class PrivateChatWindow extends ChatWindow { + + private final TcpConnection connection; + + public PrivateChatWindow(MainWindow mainWindow, TcpConnection connection) { + this.connection = connection; + + super(mainWindow); + } + + @Override + protected void initButtons(JPanel bottomPanel) { + JButton tcpButton = new JButton("TCP"); + + tcpButton.addActionListener(e -> sendTCP()); + + JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0)); + + buttonsPanel.add(tcpButton); + + bottomPanel.add(buttonsPanel, BorderLayout.EAST); + } + + private void sendTCP() { + try { + TestChatMessage msg = createMessage("TCP Private"); + connection.send(msg.toByteArray()); + + } catch (Exception ex) { + Logger.getLogger( + PrivateChatWindow.class.getName() + ).log(Level.SEVERE, null, ex); + } + } +} \ No newline at end of file diff --git a/pitiupi.testSocket/src/GUI/PublicChatWindow.java b/pitiupi.testSocket/src/GUI/PublicChatWindow.java new file mode 100644 index 0000000..4c9e945 --- /dev/null +++ b/pitiupi.testSocket/src/GUI/PublicChatWindow.java @@ -0,0 +1,93 @@ +package GUI; + +import net.TestChatMessage; +import pitiupi.GUI.MainWindow; + +import javax.swing.*; +import java.awt.*; +import java.net.InetAddress; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class PublicChatWindow extends ChatWindow { + + private JTextField ipField; + + public PublicChatWindow(MainWindow mainWindow) { + super(mainWindow); + } + + @Override + protected void initButtons(JPanel bottomPanel) { + initIpField(bottomPanel); + initCommunicationButtons(bottomPanel); + } + + private void initIpField(JPanel bottomPanel) { + ipField = new JTextField(); + ipField.setPreferredSize(new Dimension(130, 30)); + + JPanel ipPanel = new JPanel(new BorderLayout(5, 5)); + + ipPanel.add(new JLabel("IP destino:"), BorderLayout.WEST); + + ipPanel.add(ipField, BorderLayout.CENTER); + + bottomPanel.add(ipPanel, BorderLayout.WEST); + } + + private void initCommunicationButtons(JPanel bottomPanel) { + JButton tcpButton = new JButton("TCP"); + JButton udpButton = new JButton("UDP"); + JButton multicastButton = new JButton("Multicast"); + + tcpButton.addActionListener(e -> sendTCP()); + udpButton.addActionListener(e -> sendUDP()); + multicastButton.addActionListener(e -> sendMulticast()); + + JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0)); + + buttonsPanel.add(tcpButton); + buttonsPanel.add(udpButton); + buttonsPanel.add(multicastButton); + + bottomPanel.add(buttonsPanel, BorderLayout.EAST); + } + + private void sendTCP() { + try { + TestChatMessage msg = createMessage("TCP Unicast"); + + InetAddress ip = InetAddress.getByName(ipField.getText()); + + mainWindow.getSocketTCP().send(msg, ip); + + } catch (Exception ex) { + Logger.getLogger(PublicChatWindow.class.getName()).log(Level.SEVERE, null, ex); + } + } + + private void sendUDP() { + try { + TestChatMessage msg = createMessage("UDP Unicast"); + + InetAddress ip = InetAddress.getByName(ipField.getText()); + + mainWindow.getSocketUDP().sendUnicast(msg, ip); + + } catch (Exception ex) { + Logger.getLogger(PublicChatWindow.class.getName()).log(Level.SEVERE, null, ex); + } + } + + private void sendMulticast() { + try { + TestChatMessage msg = createMessage("UDP Multicast"); + + mainWindow.getSocketUDP().sendMulticast(msg); + + } catch (Exception ex) { + Logger.getLogger(PublicChatWindow.class.getName()).log(Level.SEVERE, null, ex); + } + } +} \ No newline at end of file diff --git a/pitiupi.testSocket/src/GUI/SocketTestMenu.java b/pitiupi.testSocket/src/GUI/SocketTestMenu.java deleted file mode 100644 index 0f04bf9..0000000 --- a/pitiupi.testSocket/src/GUI/SocketTestMenu.java +++ /dev/null @@ -1,21 +0,0 @@ -package GUI; - -import javax.swing.*; -import java.awt.event.ActionEvent; - -public class SocketTestMenu extends JMenu { - private final SocketTestWindow socketTestWindow; - - public SocketTestMenu(SocketTestWindow socketTestWindow) { - this.socketTestWindow = socketTestWindow; - this.setText("MP-Chat"); - JMenuItem menuItem = new JMenuItem(); - menuItem.setText("Show Chat Window"); - menuItem.addActionListener(this::showTestWindow); - this.add(menuItem); - } - - private void showTestWindow(ActionEvent ae) { - this.socketTestWindow.setVisible(true); - } -} diff --git a/pitiupi.testSocket/src/GUI/SocketTestWindow.java b/pitiupi.testSocket/src/GUI/SocketTestWindow.java deleted file mode 100644 index e4d70d0..0000000 --- a/pitiupi.testSocket/src/GUI/SocketTestWindow.java +++ /dev/null @@ -1,151 +0,0 @@ -package GUI; - -import net.TestMessage; -import pitiupi.GUI.MainWindow; - -import javax.swing.*; -import java.awt.*; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class SocketTestWindow extends JFrame { - private MainWindow mainWindow; - private JTextArea receivedMessagesArea; - - private JTextField ipField; - private JTextField messageField; - - private JButton tcpButton; - private JButton udpButton; - private JButton multicastButton; - - public SocketTestWindow(MainWindow mainWindow) { - this.mainWindow = mainWindow; - initComponents(); - } - - public void initComponents() { - setTitle("Socket Test"); - setSize(700, 500); - setLocationRelativeTo(null); - setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); - - JPanel mainPanel = new JPanel(new BorderLayout(10, 10)); - - mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - - initReceivedMessagesPanel(mainPanel); - initBottomPanel(mainPanel); - - setContentPane(mainPanel); - } - - private void initReceivedMessagesPanel(JPanel mainPanel) { - receivedMessagesArea = new JTextArea(); - receivedMessagesArea.setEditable(false); - receivedMessagesArea.setLineWrap(true); - receivedMessagesArea.setWrapStyleWord(true); - - JScrollPane messagesScrollPane = new JScrollPane(receivedMessagesArea); - - messagesScrollPane.setBorder(BorderFactory.createTitledBorder("Mensagens recebidas")); - - mainPanel.add(messagesScrollPane, BorderLayout.CENTER); - } - - private void initBottomPanel(JPanel mainPanel) { - ipField = new JTextField(); - ipField.setPreferredSize(new Dimension(130, 30)); - - JPanel ipPanel = new JPanel(new BorderLayout(5, 5)); - ipPanel.add(new JLabel("IP destino:"), BorderLayout.WEST); - ipPanel.add(ipField, BorderLayout.CENTER); - - messageField = new JTextField(); - - JPanel bottomPanel = new JPanel(new BorderLayout(10, 10)); - - bottomPanel.add(ipPanel, BorderLayout.WEST); - bottomPanel.add(messageField, BorderLayout.CENTER); - initButtons(bottomPanel); - - mainPanel.add(bottomPanel, BorderLayout.SOUTH); - } - - private void initButtons(JPanel bottomPanel) { - tcpButton = new JButton("TCP"); - udpButton = new JButton("UDP"); - multicastButton = new JButton("Multicast"); - - tcpButton.addActionListener(e -> sendTCP()); - udpButton.addActionListener(e -> sendUDP()); - multicastButton.addActionListener(e -> sendMulticast()); - - JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0)); - - buttonsPanel.add(tcpButton); - buttonsPanel.add(udpButton); - buttonsPanel.add(multicastButton); - - bottomPanel.add(buttonsPanel, BorderLayout.EAST); - } - - public void sendTCP() { - try { - TestMessage msg = createMessage("TCP Unicast"); - InetAddress ip = InetAddress.getByName(ipField.getText()); - mainWindow.getSocketTCP().send(msg, ip); - } catch (Exception ex) { - Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); - } - - } - public void sendUDP() { - try { - TestMessage msg = createMessage("UDP Unicast"); - InetAddress ip = InetAddress.getByName(ipField.getText()); - mainWindow.getSocketUDP().sendUnicast(msg, ip); - } catch (Exception ex) { - Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); - } - } - public void sendMulticast() { - try { - TestMessage msg = createMessage("UDP Multicast"); - mainWindow.getSocketUDP().sendMulticast(msg); - } catch (Exception ex) { - Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); - } - } - - private TestMessage createMessage(String tipoMensagem) { - try { - String nome = mainWindow.getUserName(); - String ip = InetAddress.getLocalHost().getHostAddress(); - String message = messageField.getText(); - return new TestMessage(nome, ip, tipoMensagem, message); - } catch (UnknownHostException e) { - throw new RuntimeException(e); - } - } - - public void receiveMessage(TestMessage msg) { - SwingUtilities.invokeLater(() -> { - String mensagem = String.format( - "[%s] %s (%s): %s%n", - msg.getTipoMensagem(), - msg.getNome(), - msg.getIp(), - msg.getMessage() - ); - - receivedMessagesArea.append(mensagem); - - receivedMessagesArea.setCaretPosition( - receivedMessagesArea.getDocument().getLength() - ); - }); - } -} diff --git a/pitiupi.testSocket/src/META-INF/services/pitiupi.plugin.Plugin b/pitiupi.testSocket/src/META-INF/services/pitiupi.plugin.Plugin index cdf4196..58a4118 100644 --- a/pitiupi.testSocket/src/META-INF/services/pitiupi.plugin.Plugin +++ b/pitiupi.testSocket/src/META-INF/services/pitiupi.plugin.Plugin @@ -1 +1 @@ -plugin.SocketTest +plugin.TestChat diff --git a/pitiupi.testSocket/src/control/ChatController.java b/pitiupi.testSocket/src/control/ChatController.java new file mode 100644 index 0000000..96a3361 --- /dev/null +++ b/pitiupi.testSocket/src/control/ChatController.java @@ -0,0 +1,62 @@ +package control; + +import GUI.ChatMenu; +import GUI.ChatWindow; +import GUI.PrivateChatWindow; +import GUI.PublicChatWindow; +import net.TestChatMessage; +import pitiupi.GUI.MainWindow; +import pitiupi.net.tcp.TcpConnection; + +import javax.swing.*; +import java.util.HashMap; + +public class ChatController { + MainWindow mainWindow; + ChatMenu chatMenu; + + PublicChatWindow publicChatWindow; + + private final HashMap chatMenus; + private final HashMap chatWindows; + + + public ChatController(MainWindow mainWindow, ChatMenu chatMenu) { + this.mainWindow = mainWindow; + publicChatWindow = new PublicChatWindow(mainWindow); + + chatMenus = new HashMap<>(); + chatWindows = new HashMap<>(); + + chatMenu.newMenuItem(new JMenuItem("Show global chat"), publicChatWindow); + } + + public void addChatWindow(TcpConnection tcpConnection) { + if (chatWindows.containsKey(tcpConnection)) return; + + PrivateChatWindow newChat = new PrivateChatWindow(mainWindow, tcpConnection); + chatWindows.put(tcpConnection, newChat); + + JMenuItem newMenuItem = new JMenuItem(); + chatMenus.put(tcpConnection, newMenuItem); + + newMenuItem.setText(tcpConnection.getAddress().toString()); + chatMenu.newMenuItem(newMenuItem, newChat); + } + + public void removeChatWindow(TcpConnection tcpConnection) { + ChatWindow removedWindow = chatWindows.remove(tcpConnection); + JMenuItem removedMenu = chatMenus.remove(tcpConnection); + + chatMenu.removeMenuItem(removedMenu); + removedWindow.setVisible(false); + removedWindow.dispose(); + } + + public void receivePublic(TestChatMessage message) { + publicChatWindow.receiveMessage(message); + } + public void receivePrivate(TcpConnection tcpConnection, TestChatMessage message) { + chatWindows.get(tcpConnection).receiveMessage(message); + } +} diff --git a/pitiupi.testSocket/src/net/TestMessage.java b/pitiupi.testSocket/src/net/TestChatMessage.java similarity index 76% rename from pitiupi.testSocket/src/net/TestMessage.java rename to pitiupi.testSocket/src/net/TestChatMessage.java index cb947d4..3b9a499 100644 --- a/pitiupi.testSocket/src/net/TestMessage.java +++ b/pitiupi.testSocket/src/net/TestChatMessage.java @@ -2,20 +2,20 @@ package net; import pitiupi.net.Message; -public class TestMessage extends Message { +public class TestChatMessage extends Message { private String nome; private String ip; private String tipoMensagem; private String message; - public TestMessage(String nome, String ip, String tipoMensagem, String message) { + public TestChatMessage(String nome, String ip, String tipoMensagem, String message) { this.nome = nome; this.ip = ip; this.tipoMensagem = tipoMensagem; this.message = message; } - public TestMessage(){} + public TestChatMessage(){} public String getNome() { return nome; diff --git a/pitiupi.testSocket/src/plugin/SocketTest.java b/pitiupi.testSocket/src/plugin/SocketTest.java deleted file mode 100644 index 145dbca..0000000 --- a/pitiupi.testSocket/src/plugin/SocketTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package plugin; - -import GUI.SocketTestMenu; -import GUI.SocketTestWindow; -import net.TestMessage; -import pitiupi.GUI.MainWindow; -import pitiupi.net.Message; -import pitiupi.net.tcp.TcpConnection; -import pitiupi.plugin.PrivateConnectionPlugin; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; - -public class SocketTest implements PrivateConnectionPlugin{ - SocketTestWindow socketTestWindow; - - @Override - public String getName() { - return "Test Socket"; - } - - @Override - public String getAuthor() { - return "Gustavo Henrique"; - } - - @Override - public String getVersion() { - return "0"; - } - - @Override - public String getIdentifier() { - return "Socket.Test.123456"; - } - - @Override - public void createPlugin(MainWindow mainWindow) { - this.socketTestWindow = new SocketTestWindow(mainWindow); - mainWindow.addMenu(new SocketTestMenu(socketTestWindow)); - } - - @Override - public Message getMessage() { - return new TestMessage(); - } - - @Override - public void receiveMessage(byte[] message) { - ByteArrayInputStream bis = new ByteArrayInputStream(message); - ObjectInputStream ois; - try { - ois = new ObjectInputStream(bis); - if (ois.readObject() instanceof TestMessage msg) { - this.socketTestWindow.receiveMessage(msg); - } - } catch (IOException | ClassNotFoundException ex) { - System.out.println(ex.toString()); - } - } - - @Override - public void receivePrivateConnection(TcpConnection tcpConnection) { - - } - - @Override - public void receiveBytes(TcpConnection connection, byte[] bytes) { - - } - - @Override - public void onSocketClosed(TcpConnection tcpConnection) { - - } -} diff --git a/pitiupi.testSocket/src/plugin/TestChat.java b/pitiupi.testSocket/src/plugin/TestChat.java new file mode 100644 index 0000000..de25242 --- /dev/null +++ b/pitiupi.testSocket/src/plugin/TestChat.java @@ -0,0 +1,100 @@ +package plugin; + +import GUI.ChatMenu; +import control.ChatController; +import net.TestChatMessage; +import pitiupi.GUI.MainWindow; +import pitiupi.net.Message; +import pitiupi.net.tcp.TcpConnection; +import pitiupi.plugin.PrivateConnectionPlugin; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.net.InetAddress; + +public class TestChat implements PrivateConnectionPlugin{ + ChatController chatController; + MainWindow mainWindow; + + @Override + public String getName() { + return "MultiProtocol chat"; + } + + @Override + public String getAuthor() { + return "Gustavo Henrique"; + } + + @Override + public String getVersion() { + return "0"; + } + + @Override + public String getIdentifier() { + return "Multi.Protocol.Chat.Pitiupi"; + } + + @Override + public void createPlugin(MainWindow mainWindow) { + this.mainWindow = mainWindow; + + ChatMenu chatMenu = new ChatMenu(this); + chatController = new ChatController(mainWindow, chatMenu); + mainWindow.addMenu(chatMenu); + } + + @Override + public Message getMessage() { + return new TestChatMessage(); + } + + @Override + public void receiveMessage(byte[] message) { + TestChatMessage testChatMessage = parseMessage(message); + chatController.receivePublic(testChatMessage); + } + + @Override + public void receivePrivateConnection(TcpConnection tcpConnection) { + chatController.addChatWindow(tcpConnection); + } + + @Override + public void receiveBytes(TcpConnection connection, byte[] bytes) { + TestChatMessage testChatMessage = parseMessage(bytes); + chatController.receivePrivate(connection, testChatMessage); + } + + @Override + public void onSocketClosed(TcpConnection tcpConnection) { + chatController.removeChatWindow(tcpConnection); + } + + public boolean openConnection(String ip) { + try { + mainWindow.getSocketTCP().createPrivateConnection(InetAddress.getByName(ip), getIdentifier(), getIdentifier()); + return true; + } + catch (Exception e) { + System.out.println("Error opening connection: " + e.getMessage()); + } + return false; + } + + private TestChatMessage parseMessage(byte[] bytes) { + ByteArrayInputStream bis = new ByteArrayInputStream(bytes); + ObjectInputStream ois; + try { + ois = new ObjectInputStream(bis); + if (ois.readObject() instanceof TestChatMessage msg) { + return msg; + } + } catch (IOException | ClassNotFoundException ex) { + System.out.println(ex.toString()); + } + return null; + } +} diff --git a/pitiupi/src/pitiupi/GUI/Login.java b/pitiupi/src/pitiupi/GUI/Login.java index 20b2a37..893161d 100644 --- a/pitiupi/src/pitiupi/GUI/Login.java +++ b/pitiupi/src/pitiupi/GUI/Login.java @@ -48,7 +48,6 @@ public final class Login extends JDialog { public void initComponents() { this.setTitle("Login"); - String nomeSalvo = prefs.get(PREF_NOME, System.getProperty("user.name")); int portaSalva = prefs.getInt(PREF_PORTA, 8000);