diff --git a/java/Chat/README.md b/java/Chat/README.md deleted file mode 100644 index 2c231af92c..0000000000 --- a/java/Chat/README.md +++ /dev/null @@ -1,14 +0,0 @@ -This demo is a Java client for the [ZeroC Chat Demo][1]. It connects to a -single chat room, allowing you to chat with other chat room participants. - -By default, the demo connects to the chat server hosted on demo.zeroc.com -through a WebSocket reverse proxy hosted on zeroc.com. - -If you wish to run your own server you can specify a custom configuration -file when launching the application: - -``` -java -jar Chat.jar --Ice.Config=config.client -``` - -[1]: https://doc.zeroc.com/technical-articles/general-topics/chat-demo diff --git a/java/Chat/build.gradle b/java/Chat/build.gradle deleted file mode 100644 index 152a43cbf9..0000000000 --- a/java/Chat/build.gradle +++ /dev/null @@ -1,54 +0,0 @@ - -buildscript { - repositories { - mavenCentral() - } - - dependencies { - classpath "com.guardsquare:proguard-gradle:7.4.0-beta02" - } -} - -slice { - java { - include = ["${projectDir}/src/main/slice"] - } -} - -dependencies { - implementation 'com.jgoodies:jgoodies-common:1.8.0' - implementation 'com.jgoodies:jgoodies-looks:2.6.0' - implementation 'com.jgoodies:jgoodies-forms:1.8.0' - implementation localDependency("ice") - implementation localDependency("glacier2") -} - -jar { - archiveFileName = "ChatTEMP.jar" - manifest { - attributes 'Main-Class': "com.zeroc.demos.Chat.MainView" - } -} - -def javaHome = System.properties['java.home'] - -task proguard(type: proguard.gradle.ProGuardTask, dependsOn: jar) { - injars configurations.runtimeClasspath.resolve(), filter: '!META-INF/**,!module-info.class' - injars "${buildDir}/libs/ChatTEMP.jar" - if(JavaVersion.current() <= JavaVersion.VERSION_1_8) { - libraryjars "${javaHome}/lib/rt.jar" - libraryjars "${javaHome}/lib/jsse.jar" - } else { - libraryjars "${javaHome}/jmods/java.base.jmod" - libraryjars "${javaHome}/jmods/java.logging.jmod" - libraryjars "${javaHome}/jmods/java.desktop.jmod" - libraryjars "${javaHome}/jmods/java.prefs.jmod" - } - outjars "Chat.jar" - configuration "chatdemo.pro" -} -assemble.dependsOn(proguard) - -clean { - delete("Chat.jar") -} diff --git a/java/Chat/chatdemo.pro b/java/Chat/chatdemo.pro deleted file mode 100644 index 1fe8968aff..0000000000 --- a/java/Chat/chatdemo.pro +++ /dev/null @@ -1,28 +0,0 @@ --dontshrink --dontoptimize --dontobfuscate --dontusemixedcaseclassnames --dontpreverify - --dontnote jdk.internal.jimage.** --dontnote jdk.internal.jrtfs.** --dontnote module-info - --dontnote com.jgoodies.** - -# Keep - Applications. Keep all application classes, along with their 'main' -# methods. --keepclasseswithmembers public class * { - public static void main(java.lang.String[]); -} - -# Also keep - Swing UI L&F. Keep all extensions of javax.swing.plaf.ComponentUI, -# along with the special 'createUI' method. --keep class * extends javax.swing.plaf.ComponentUI { - public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent); -} - -# Keep names - Native method names. Keep all native class/method names. --keepclasseswithmembers,includedescriptorclasses,allowshrinking class * { - native ; -} diff --git a/java/Chat/config.client b/java/Chat/config.client deleted file mode 100644 index 6d77212927..0000000000 --- a/java/Chat/config.client +++ /dev/null @@ -1,44 +0,0 @@ -# -# The proxy to the Glacier2 router for all outgoing connections. This -# must match the value of Glacier2.Client.Endpoints in your Chat server's config. -# -Ice.Default.Router=DemoGlacier2/router:ssl -p 4064 -h 127.0.0.1 - -# -# Warn about connection exceptions -# -#Ice.Warn.Connections=1 - -# -# Network Tracing -# -# 0 = no network tracing -# 1 = trace connection establishment and closure -# 2 = like 1, but more detailed -# 3 = like 2, but also trace data transfer -# -#Ice.Trace.Network=1 - -# -# Protocol Tracing -# -# 0 = no protocol tracing -# 1 = trace protocol messages -# -#Ice.Trace.Protocol=1 - -# -# Security Tracing -# -# 0 = no security tracing -# 1 = trace messages -# -#IceSSL.Trace.Security=1 - -# -# SSL Configuration -# -Ice.Plugin.IceSSL=com.zeroc.IceSSL.PluginFactory -IceSSL.DefaultDir=../../certs -IceSSL.Keystore=client.jks -IceSSL.Password=password diff --git a/java/Chat/src/main/java/com/zeroc/demos/Chat/ChatDemoGUIFactory.java b/java/Chat/src/main/java/com/zeroc/demos/Chat/ChatDemoGUIFactory.java deleted file mode 100644 index 78d2f15e40..0000000000 --- a/java/Chat/src/main/java/com/zeroc/demos/Chat/ChatDemoGUIFactory.java +++ /dev/null @@ -1,41 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -package com.zeroc.demos.Chat; - -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Point; - -import javax.swing.JScrollPane; - -// -// Helper methods to create the UI. -// -final public class ChatDemoGUIFactory -{ - public static void locateOnScreen(Component component) - { - Dimension paneSize = component.getSize(); - Dimension screenSize = component.getToolkit().getScreenSize(); - component.setLocation((screenSize.width - paneSize.width) / 2, (screenSize.height - paneSize.height) / 2); - } - - public static void centerComponent(Component component, Component base) - { - Dimension baseSize = base.getSize(); - Point basePoint = base.getLocation(); - Dimension componentSize = component.getSize(); - component.setLocation(basePoint.x + (baseSize.width - componentSize.width) / 2, - basePoint.y + (baseSize.height - componentSize.height) / 2); - } - - public static JScrollPane createStrippedScrollPane(Component component) - { - JScrollPane scrollPane = new JScrollPane(component); - scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane.setBorder(null); - return scrollPane; - } -} diff --git a/java/Chat/src/main/java/com/zeroc/demos/Chat/ChatRoomCallbackI.java b/java/Chat/src/main/java/com/zeroc/demos/Chat/ChatRoomCallbackI.java deleted file mode 100644 index 03e1718456..0000000000 --- a/java/Chat/src/main/java/com/zeroc/demos/Chat/ChatRoomCallbackI.java +++ /dev/null @@ -1,41 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -package com.zeroc.demos.Chat; - -// -// This class implements the ChatRoomCallback interface. -// -class ChatRoomCallbackI implements ChatRoomCallback -{ - public ChatRoomCallbackI(Coordinator coordinator) - { - _coordinator = coordinator; - } - - public void init(String[] users, com.zeroc.Ice.Current currrent) - { - _coordinator.initEvent(users); - } - - public void send(long timestamp, String name, String message, com.zeroc.Ice.Current currrent) - { - if(name.compareToIgnoreCase(_coordinator.getUsername()) != 0) - { - _coordinator.userSayEvent(timestamp, name, message); - } - } - - public void join(long timestamp, String name, com.zeroc.Ice.Current currrent) - { - _coordinator.userJoinEvent(timestamp, name); - } - - public void leave(long timestamp, String name, com.zeroc.Ice.Current currrent) - { - _coordinator.userLeaveEvent(timestamp, name); - } - - private final Coordinator _coordinator; -} diff --git a/java/Chat/src/main/java/com/zeroc/demos/Chat/ChatUtils.java b/java/Chat/src/main/java/com/zeroc/demos/Chat/ChatUtils.java deleted file mode 100644 index 58591fca97..0000000000 --- a/java/Chat/src/main/java/com/zeroc/demos/Chat/ChatUtils.java +++ /dev/null @@ -1,63 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -package com.zeroc.demos.Chat; - -import java.util.Date; -import java.util.TimeZone; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.io.StringWriter; -import java.io.PrintWriter; - -public class ChatUtils -{ - // - // This function unescapes HTML entities in the data string - // and return the unescaped string. - // - public static String unstripHtml(String data) - { - data = data.replace(""", "\""); - data = data.replace("'", "'"); - data = data.replace("<", "<"); - data = data.replace(">", ">"); - data = data.replace("&", "&"); - return data; - } - - public static String formatTimestamp(long timestamp) - { - DateFormat dtf = new SimpleDateFormat("HH:mm:ss"); - dtf.setTimeZone(TimeZone.getDefault()); - return dtf.format(new Date(timestamp)); - } - - public static String formatUsername(String in) - { - try - { - in = in.substring(0, 1).toUpperCase() + in.substring(1, in.length()).toLowerCase(); - } - catch(IndexOutOfBoundsException ex) - { - } - return in; - } - - public static String stack2string(Throwable e) - { - try - { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - e.printStackTrace(pw); - return sw.toString(); - } - catch(Exception e2) - { - return e.toString(); - } - } -} diff --git a/java/Chat/src/main/java/com/zeroc/demos/Chat/ChatView.java b/java/Chat/src/main/java/com/zeroc/demos/Chat/ChatView.java deleted file mode 100644 index ada2c6c70e..0000000000 --- a/java/Chat/src/main/java/com/zeroc/demos/Chat/ChatView.java +++ /dev/null @@ -1,249 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -package com.zeroc.demos.Chat; - -import java.awt.Component; -import java.awt.event.ComponentListener; -import java.awt.event.ComponentEvent; - -import java.awt.BorderLayout; -import java.awt.event.KeyListener; -import java.awt.event.KeyEvent; -import java.awt.Dimension; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -import javax.swing.JPanel; -import javax.swing.JList; -import javax.swing.JPopupMenu; -import javax.swing.DefaultListCellRenderer; -import javax.swing.JLabel; -import javax.swing.JSplitPane; -import javax.swing.JTextArea; -import javax.swing.JScrollPane; -import javax.swing.JScrollBar; -import javax.swing.DefaultListModel; -import javax.swing.text.Document; -import javax.swing.text.Element; -import javax.swing.text.AttributeSet; -import javax.swing.text.BadLocationException; -import javax.swing.text.DefaultEditorKit; - -import java.util.prefs.Preferences; -import java.util.prefs.BackingStoreException; - -public class ChatView extends JPanel -{ - @SuppressWarnings("unchecked") - ChatView(Preferences prefs, DefaultListModel users) - { - _prefs = prefs; - setLayout(new BorderLayout()); - - // Build the user list. - _userList = new JList(); - _userList.setCellRenderer(new UserListCellRender()); - _userList.setModel(users); - - // Build the JTextArea that shows the chat conversation. - _conversationText = new JTextArea(""); - _conversationText.setLineWrap(true); - _conversationText.setEditable(false); - - final JPopupMenu textMenu = new JPopupMenu(); - textMenu.add(new DefaultEditorKit.CopyAction()); - textMenu.pack(); - - _conversationText.addMouseListener(new MouseAdapter() - { - public void mousePressed(MouseEvent e) - { - if (e.isPopupTrigger()) // BUTTON3 is the right mouse button - { - textMenu.show(_conversationText, e.getX(), e.getY()); - } - } - }); - - // Build the JTextArea where the user writes input messages. - _conversationInput = new JTextArea(""); - _conversationInput.setLineWrap(true); - _conversationInput.setEditable(true); - _conversationInput.addKeyListener(new InputLineKeyListener()); - - // Build the split panes. - _horizontalSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); - - JScrollPane usersScroll = ChatDemoGUIFactory.createStrippedScrollPane(_userList); - usersScroll.setMinimumSize(new Dimension(100, 100)); - _horizontalSplit.setLeftComponent(usersScroll); - - _conversationTextScroll = ChatDemoGUIFactory.createStrippedScrollPane(_conversationText); - _conversationTextScroll.setMinimumSize(new Dimension(100, 100)); - _conversationTextScroll.setPreferredSize(new Dimension(100, 100)); - _horizontalSplit.setRightComponent(_conversationTextScroll); - - _verticalSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT); - _verticalSplit.setTopComponent(_horizontalSplit); - - JScrollPane conversationInputScroll = ChatDemoGUIFactory.createStrippedScrollPane(_conversationInput); - conversationInputScroll.setMinimumSize(new Dimension(100, 100)); - conversationInputScroll.setPreferredSize(new Dimension(100, 100)); - _verticalSplit.setBottomComponent(conversationInputScroll); - - _horizontalSplit.setResizeWeight(0.1); - _verticalSplit.setResizeWeight(0.9); - - _conversationText.addComponentListener(new ComponentListener() - { - public void componentResized(ComponentEvent e) - { - JScrollBar vertivalScrollbar = _conversationTextScroll.getVerticalScrollBar(); - vertivalScrollbar.setValue(vertivalScrollbar.getMaximum()); - } - - public void componentHidden(ComponentEvent e) - { - } - - public void componentMoved(ComponentEvent e) - { - } - - public void componentShown(ComponentEvent e) - { - } - }); - - add(_verticalSplit, BorderLayout.CENTER); - } - - public void setCoordinator(Coordinator coordinator) - { - _coordinator = coordinator; - } - - public void appendMessage(String message) - { - Document doc = (Document) _conversationText.getDocument(); - Element e = doc.getDefaultRootElement(); - AttributeSet attr = e.getAttributes().copyAttributes(); - try - { - doc.insertString(doc.getLength(), message + "\n", attr); - } - catch(BadLocationException ex) - { - } - _conversationText.setCaretPosition(doc.getLength()); - } - - public void appendError(String error) - { - appendMessage(error); - _conversationInput.setEditable(false); - } - - class UserListCellRender extends DefaultListCellRenderer - { - public Component - getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean hasFocus) - { - JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, hasFocus); - label.setIcon(MainView.getIcon("/icons/16x16/user.png")); - return label; - } - } - - // - // Event handler for input messages. - // - class InputLineKeyListener implements KeyListener - { - public void keyTyped(KeyEvent e) - { - if(e.getKeyChar() == KeyEvent.VK_ENTER) - { - try - { - Document doc = _conversationInput.getDocument(); - String msg = doc.getText(0, doc.getLength()).trim(); - if(msg.length() > 0) - { - _coordinator.sendMessage(msg); - } - } - catch(BadLocationException ex) - { - } - _conversationInput.setText(""); - } - } - - public void keyPressed(KeyEvent e) - { - } - - public void keyReleased(KeyEvent e) - { - } - } - - public void storeWindowPrefs() - { - Preferences windowPrefs = _prefs.node("ChatView"); - windowPrefs.putInt("hSplitLocation", _horizontalSplit.getDividerLocation()); - windowPrefs.putInt("vSplitLocation", _verticalSplit.getDividerLocation()); - } - - public boolean loadWindowPrefs() - { - try - { - if(!_prefs.nodeExists("ChatView")) - { - return false; - } - } - catch(BackingStoreException ex) - { - return false; - } - - Preferences windowPrefs = _prefs.node("ChatView"); - _horizontalSplit.setDividerLocation(windowPrefs.getInt("hSplitLocation", 120)); - _verticalSplit.setDividerLocation(windowPrefs.getInt("vSplitLocation", 50)); - return true; - } - - public void setConnected(boolean connected) - { - setVisible(connected); - if(connected) - { - loadWindowPrefs(); - _conversationInput.setEditable(true); - if(!_conversationInput.hasFocus()) - { - _conversationInput.requestFocus(); - } - } - else - { - storeWindowPrefs(); - _conversationText.setText(""); - _conversationInput.setText(""); - } - } - - private final JList _userList; - private final JScrollPane _conversationTextScroll; - private final JTextArea _conversationText; - private final JTextArea _conversationInput; - private final JSplitPane _verticalSplit; - private final JSplitPane _horizontalSplit; - private Coordinator _coordinator; - private final Preferences _prefs; -} diff --git a/java/Chat/src/main/java/com/zeroc/demos/Chat/Coordinator.java b/java/Chat/src/main/java/com/zeroc/demos/Chat/Coordinator.java deleted file mode 100644 index a29d3f027b..0000000000 --- a/java/Chat/src/main/java/com/zeroc/demos/Chat/Coordinator.java +++ /dev/null @@ -1,476 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -package com.zeroc.demos.Chat; - -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; -import java.awt.Cursor; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Frame; - -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -import javax.swing.DefaultListModel; -import javax.swing.SwingUtilities; -import javax.swing.JOptionPane; - -import javax.swing.JDialog; -import javax.swing.JPopupMenu; -import javax.swing.JPanel; -import javax.swing.JLabel; -import javax.swing.JTextArea; -import javax.swing.JButton; -import javax.swing.BoxLayout; -import javax.swing.text.DefaultEditorKit; -import javax.swing.ImageIcon; - -import com.jgoodies.forms.layout.FormLayout; -import com.jgoodies.forms.builder.DefaultFormBuilder; -import com.jgoodies.forms.factories.Borders; - -import com.zeroc.demos.Chat.*; -import com.zeroc.Glacier2.SessionFactoryHelper; -import com.zeroc.Glacier2.SessionHelper; -import com.zeroc.Glacier2.SessionCallback; -import com.zeroc.Glacier2.SessionNotExistException; - -class Coordinator -{ - public enum ClientState { Disconnected, Connecting, Connected, Disconnecting } - - public Coordinator(MainView mainView, LoginView loginView, ChatView chatView, DefaultListModel users, - String[] args) - { - _args = args; - _mainView = mainView; - _loginView = loginView; - _chatView = chatView; - _users = users; - - com.zeroc.Ice.InitializationData initData = new com.zeroc.Ice.InitializationData(); - - java.util.List rArgs = new java.util.ArrayList<>(); - initData.properties = new com.zeroc.Ice.Properties(_args, rArgs); - _args = rArgs.toArray(new String[rArgs.size()]); - - initData.properties.setProperty("Ice.Plugin.IceSSL", "com.zeroc.IceSSL.PluginFactory"); - - // Load the configuration file. - initData.properties.setProperty("Ice.Default.Package", "com.zeroc.demos"); - initData.properties = new com.zeroc.Ice.Properties(args, initData.properties); - - // - // Set Ice.Default.Router if not set. - // - if(initData.properties.getProperty("Ice.Default.Router").isEmpty()) - { - initData.properties.setProperty("IceSSL.UsePlatformCAs", "1"); - initData.properties.setProperty("IceSSL.CheckCertName", "2"); - initData.properties.setProperty("IceSSL.VerifyDepthMax", "5"); - initData.properties.setProperty("Ice.Default.Router", - "Glacier2/router:wss -p 443 -h zeroc.com -r /demo-proxy/chat/glacier2"); - } - - initData.dispatcher = (runnable, connection) -> - { - if(_exit) // The GUI is being destroyed, don't use the GUI thread any more - { - runnable.run(); - } - else - { - SwingUtilities.invokeLater(runnable); - } - }; - - final Coordinator coordinator = this; - _factory = new SessionFactoryHelper(initData, new SessionCallback() - { - public void connected(final SessionHelper session) - throws SessionNotExistException - { - // - // Ignore callbacks during shutdown. - // - if(_exit) - { - return; - } - - // - // If the session has been reassigned avoid the spurious callback. - // - - if(session != _session) - { - return; - } - - ChatRoomCallbackPrx callback = ChatRoomCallbackPrx.uncheckedCast( - _session.addWithUUID(new ChatRoomCallbackI(coordinator))); - - _chat = ChatSessionPrx.uncheckedCast(_session.session()); - try - { - _chat.setCallbackAsync(callback).whenCompleteAsync((result, ex) -> - { - if(ex == null) - { - _info.save(); - _username = ChatUtils.formatUsername(_info.username); - setState(ClientState.Connected); - } - else - { - destroySession(); - } - }, - _chat.ice_executor()); - } - catch(com.zeroc.Ice.CommunicatorDestroyedException ex) - { - // Ignore client session was destroyed. - } - } - - public void disconnected(SessionHelper session) - { - // - // Ignore callbacks during shutdown. - // - if(_exit) - { - return; - } - - _username = ""; - if(_state == ClientState.Disconnecting) // Connection closed by user logout/exit - { - setState(ClientState.Disconnected); - } - else if(_state == ClientState.Connected) // Connection lost while user was chatting - { - setError(" - The connection with the server was unexpectedly lost.\n" + - "You can try to login again from the File menu."); - } - else // Connection lost while user was connecting - { - setError(" - The connection with the server was unexpectedly lost.\n" + - "Try again."); - } - } - - public void connectFailed(SessionHelper session, Throwable exception) - { - // - // Ignore callbacks during shutdown. - // - if(_exit) - { - return; - } - - try - { - throw exception; - } - catch(final com.zeroc.Glacier2.CannotCreateSessionException ex) - { - setError("Login failed (Glacier2.CannotCreateSessionException):\n" + ex.reason); - } - catch(final com.zeroc.Glacier2.PermissionDeniedException ex) - { - setError("Login failed (Glacier2.PermissionDeniedException):\n" + ex.reason); - } - catch(com.zeroc.Ice.Exception ex) - { - setError("Login failed (" + ex.ice_id() + ").\n" + "Please check your configuration."); - } - catch(final Throwable ex) - { - setError("Login failed:\n" + ChatUtils.stack2string(ex)); - } - } - - public void createdCommunicator(SessionHelper session) - { - } - }); - } - - public void login(LoginInfo info) - { - setState(ClientState.Connecting); - _info = info; - _session = _factory.connect(info.username, info.password); - } - - public void logout() - { - setState(ClientState.Disconnecting); - destroySession(); - } - - public void exit() - { - _exit = true; - com.zeroc.Ice.Communicator communicator = _session == null ? null : _session.communicator(); - destroySession(); - _mainView.dispose(); - if(communicator != null) - { - try - { - communicator.waitForShutdown(); - } - catch(com.zeroc.Ice.CommunicatorDestroyedException ex) - { - // - // Can happen if the communicator is already destroyed - // - } - } - System.exit(0); - } - - @SuppressWarnings("unchecked") - public void initEvent(final String[] users) - { - for(int cont = 0; cont < users.length; ++cont) - { - _users.addElement(users[cont]); - } - } - - @SuppressWarnings("unchecked") - public void userJoinEvent(final long timestamp, final String name) - { - _users.addElement(name); - _chatView.appendMessage(ChatUtils.formatTimestamp(timestamp) + " - - " + name + " joined."); - } - - public void userLeaveEvent(final long timestamp, final String name) - { - int index = _users.indexOf(name); - if(index != -1) - { - _users.remove(index); - _chatView.appendMessage(ChatUtils.formatTimestamp(timestamp) + " - " + " - " + - name + " left."); - } - } - - public void userSayEvent(final long timestamp, final String name, final String message) - { - _chatView.appendMessage(ChatUtils.formatTimestamp(timestamp) + " - <" + name + "> " + - ChatUtils.unstripHtml(message)); - } - - public void sendMessage(final String message) - { - - if(_chat != null) - { - if(message.length() > _maxMessageSize) - { - _chatView.appendMessage(" - Message length exceeded, maximum length is " + - _maxMessageSize + " characters."); - } - else - { - try - { - _chat.sendAsync(message).whenCompleteAsync((timestamp, ex) -> - { - if(ex == null) - { - userSayEvent(timestamp, _username, message); - } - else if(ex instanceof InvalidMessageException) - { - InvalidMessageException e = (InvalidMessageException)ex; - _chatView.appendMessage(" - " + e.reason); - } - else - { - destroySession(); - } - }, - _chat.ice_executor()); - } - catch(com.zeroc.Ice.CommunicatorDestroyedException ex) - { - // Ignore client session was destroyed. - } - } - } - } - - public void setState(ClientState state) - { - _state = state; - if(state == ClientState.Disconnected) - { - _loginView.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - _chatView.setConnected(false); - _loginView.setEnabled(true); - _loginView.setConnected(false); - _mainView.setEnabled(false); - _mainView.setConnected(false); - _users.clear(); - } - else if(state == ClientState.Connecting) - { - _loginView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - _loginView.setEnabled(false); - _mainView.setEnabled(false); - } - else if(state == ClientState.Connected) - { - _chatView.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - _loginView.setConnected(true); - _chatView.setConnected(true); - _mainView.setEnabled(true); - _mainView.setConnected(true); - } - else if(state == ClientState.Disconnecting) - { - _chatView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - _mainView.setEnabled(false); - } - } - - public void setError(final String message) - { - // - // Don't display errors at that point GUI is being destroyed. - // - if(_exit == true) - { - return; - } - if(_state != ClientState.Connected) - { - setState(ClientState.Disconnected); - ErrorView errorView = new ErrorView(_mainView, message); - errorView.setSize(430, 200); - errorView.setMinimumSize(new Dimension(430, 200)); - errorView.setMaximumSize(new Dimension(430, 200)); - errorView.setResizable(false); - ChatDemoGUIFactory.centerComponent(errorView, _mainView); - errorView.setVisible(true); - } - else - { - _mainView.setEnabled(false); - _mainView.setConnected(false); - _chatView.appendError(message); - } - } - - public String getUsername() - { - return _username; - } - - public class ErrorView extends JDialog - { - private JButton bttClose = new JButton("Close"); - ErrorView(Frame frame, String message) - { - super(frame, true); - setTitle("Error - Chat Demo"); - ActionListener closeListener = new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - setVisible(false); - } - }; - bttClose.addActionListener(closeListener); - - final JTextArea txtErrorMessage = new JTextArea(message, 5, 30); - txtErrorMessage.setLineWrap(true); - JPanel errorPanel = null; // Build the error panel. - { - FormLayout layout = new FormLayout("center:pref:grow", "center:pref:grow"); - DefaultFormBuilder builder = new DefaultFormBuilder(layout); - builder.border(Borders.DIALOG); - javax.swing.ImageIcon icon = MainView.getIcon("/icons/32x32/error.png"); - if(icon != null) - { - builder.append(new JLabel(icon)); - builder.nextLine(); - } - txtErrorMessage.setEditable(false); - builder.append(ChatDemoGUIFactory.createStrippedScrollPane(txtErrorMessage)); - errorPanel = builder.getPanel(); - } - - JPanel actionsPanel = null; // Build a panel for put actions. - { - FormLayout layout = new FormLayout("center:3dlu:grow", "pref"); - DefaultFormBuilder builder = new DefaultFormBuilder(layout); - builder.append(bttClose); - actionsPanel = builder.getPanel(); - getRootPane().setDefaultButton(bttClose); - } - - FormLayout layout = new FormLayout("fill:pref:grow", "pref"); - DefaultFormBuilder builder = new DefaultFormBuilder(layout); - builder.append(errorPanel); - builder.nextLine(); - builder.append(actionsPanel); - - setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - setContentPane(builder.getPanel()); - - final JPopupMenu textMenu = new JPopupMenu(); - textMenu.add(new DefaultEditorKit.CopyAction()); - textMenu.pack(); - - txtErrorMessage.addMouseListener(new MouseAdapter() - { - public void mousePressed(MouseEvent e) - { - if (e.isPopupTrigger()) // BUTTON3 is the right mouse button - { - textMenu.show(txtErrorMessage, e.getX(), e.getY()); - } - } - }); - } - } - - protected void - destroySession() - { - final com.zeroc.Glacier2.SessionHelper s = _session; - _session = null; - _chat = null; - - if(s != null) - { - s.destroy(); - } - } - - private final SessionFactoryHelper _factory; - private ClientState _state; - private String[] _args; - private final MainView _mainView; - private final ChatView _chatView; - private final LoginView _loginView; - private final DefaultListModel _users; - private LoginInfo _info = new LoginInfo(); - private SessionHelper _session = null; - private Object _sessionMonitor = new java.lang.Object(); - private ChatSessionPrx _chat = null; - private String _username = ""; - private static final int _maxMessageSize = 1024; - private boolean _exit = false; -} diff --git a/java/Chat/src/main/java/com/zeroc/demos/Chat/LoginInfo.java b/java/Chat/src/main/java/com/zeroc/demos/Chat/LoginInfo.java deleted file mode 100644 index 1ec9439ae5..0000000000 --- a/java/Chat/src/main/java/com/zeroc/demos/Chat/LoginInfo.java +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -package com.zeroc.demos.Chat; - -import java.util.prefs.Preferences; -import java.util.prefs.BackingStoreException; - -class LoginInfo -{ - public LoginInfo() - { - } - - public LoginInfo(Preferences connectionPrefs) - { - _connectionPrefs = connectionPrefs; - load(); - } - - public void load() - { - username = _connectionPrefs.get("chatdemo.username", username); - } - - public void save() - { - _connectionPrefs.put("chatdemo.username", username); - } - - public String username = System.getProperty("user.name"); - public String password = ""; - private Preferences _connectionPrefs; -} diff --git a/java/Chat/src/main/java/com/zeroc/demos/Chat/LoginView.java b/java/Chat/src/main/java/com/zeroc/demos/Chat/LoginView.java deleted file mode 100644 index 21ad70a6d4..0000000000 --- a/java/Chat/src/main/java/com/zeroc/demos/Chat/LoginView.java +++ /dev/null @@ -1,124 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -package com.zeroc.demos.Chat; - -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; -import java.awt.Cursor; -import java.awt.Toolkit; - -import javax.swing.JPanel; -import javax.swing.JLabel; -import javax.swing.JCheckBox; -import javax.swing.JTextField; -import javax.swing.JTextArea; -import javax.swing.JPasswordField; -import javax.swing.JButton; -import javax.swing.BoxLayout; - -import com.jgoodies.forms.layout.FormLayout; -import com.jgoodies.forms.builder.DefaultFormBuilder; -import com.jgoodies.forms.factories.Borders; - -import java.util.prefs.Preferences; - -public class LoginView extends JPanel -{ - LoginView(MainView mainview, Preferences connectionPrefs) - { - _mainView = mainview; - _info = new LoginInfo(connectionPrefs); - - ActionListener loginListener = new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - login(); - } - }; - _bttLogin.addActionListener(loginListener); - - { // Build the basic login panel. - FormLayout layout = new FormLayout("center:pref:grow", "pref:grow"); - DefaultFormBuilder builder = new DefaultFormBuilder(layout); - builder.border(Borders.DIALOG); - builder.append(new JLabel("Chat Demo")); - builder.nextLine(); - builder.append(new JLabel("Welcome! You can login with any username / password.")); - builder.append(new JLabel("Username")); - builder.nextLine(); - builder.append(_txtUsername); - builder.nextLine(); - builder.append(new JLabel("Password")); - builder.nextLine(); - builder.append(_txtPassword); - _directPanel = builder.getPanel(); - } - - JPanel actionsPanel = null; // Build a panel for put actions. - { - FormLayout layout = new FormLayout("center:3dlu:grow", "pref"); - DefaultFormBuilder builder = new DefaultFormBuilder(layout); - builder.append(_bttLogin); - actionsPanel = builder.getPanel(); - _mainView.getRootPane().setDefaultButton(_bttLogin); - } - - FormLayout layout = new FormLayout("fill:pref:grow", "pref"); - DefaultFormBuilder builder = new DefaultFormBuilder(layout); - builder.append(_directPanel); - builder.nextLine(); - builder.append(actionsPanel); - - _txtUsername.setText(_info.username); - - setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - add(builder.getPanel()); - } - - public void setCoordinator(Coordinator coordinator) - { - _coordinator = coordinator; - } - - public void setEnabled(boolean enabled) - { - _txtUsername.setEnabled(enabled); - _txtPassword.setEnabled(enabled); - _bttLogin.setEnabled(enabled); - } - - private void login() - { - _coordinator.setState(Coordinator.ClientState.Connecting); - _info.username = _txtUsername.getText(); - if(_txtPassword.getPassword() != null) - { - _info.password = new String(_txtPassword.getPassword()); - } - _coordinator.login(_info); - } - - public void setConnected(boolean connected) - { - setVisible(!connected); - if(connected) - { - _mainView.getRootPane().setDefaultButton(null); - } - else - { - _mainView.getRootPane().setDefaultButton(_bttLogin); - } - } - - private final JPanel _directPanel; - private final JTextField _txtUsername = new JTextField(20); - private final JPasswordField _txtPassword = new JPasswordField(20); - private final JButton _bttLogin = new JButton("Login"); - private final LoginInfo _info; - private Coordinator _coordinator = null; - private final MainView _mainView; -} diff --git a/java/Chat/src/main/java/com/zeroc/demos/Chat/MainView.java b/java/Chat/src/main/java/com/zeroc/demos/Chat/MainView.java deleted file mode 100644 index 8ce01d0fae..0000000000 --- a/java/Chat/src/main/java/com/zeroc/demos/Chat/MainView.java +++ /dev/null @@ -1,281 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -package com.zeroc.demos.Chat; - -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.BorderLayout; -import java.awt.Frame; -import java.awt.Rectangle; -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; -import java.awt.Dimension; - -import javax.swing.JFrame; -import javax.swing.JToolBar; -import javax.swing.JPanel; -import javax.swing.SwingUtilities; -import javax.swing.UIManager; -import javax.swing.ImageIcon; -import javax.swing.BoxLayout; -import javax.swing.DefaultListModel; -import javax.swing.JButton; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JOptionPane; -import javax.swing.KeyStroke; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JMenuBar; - -import java.util.prefs.Preferences; -import java.util.prefs.BackingStoreException; - -import com.jgoodies.looks.Options; -import com.jgoodies.looks.HeaderStyle; -import com.jgoodies.looks.BorderStyle; -import com.jgoodies.looks.plastic.PlasticLookAndFeel; -import com.jgoodies.forms.layout.FormLayout; -import com.jgoodies.forms.builder.DefaultFormBuilder; -import com.jgoodies.forms.util.LayoutStyle; - -public class MainView extends JFrame -{ - public static void main(final String[] args) - { - try - { - if(System.getProperty("os.name").startsWith("Mac OS")) // OS X L&F - { - System.setProperty("apple.laf.useScreenMenuBar", "true"); - System.setProperty("com.apple.mrj.application.apple.menu.about.name", "IceGrid Admin"); - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } - else if(System.getProperty("os.name").startsWith("Windows")) - { - UIManager.setLookAndFeel("com.jgoodies.looks.windows.WindowsLookAndFeel"); - } - else // JGoodies L&F - { - UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticLookAndFeel"); - } - } - catch(Exception e) - { - } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - new MainView(args); // Create and set up the window. - } - }); - } - - private class MenuBar extends JMenuBar - { - private MenuBar() - { - putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH); - putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR); - - // - // File menu - // - JMenu fileMenu = new JMenu("File"); - fileMenu.setMnemonic(java.awt.event.KeyEvent.VK_F); - add(fileMenu); - fileMenu.add(_login); - fileMenu.add(_logout); - if(!System.getProperty("os.name").startsWith("Mac OS")) - { - fileMenu.add(_exit); - } - - // - // Help menu - // - JMenu helpMenu = new JMenu("Help"); - helpMenu.setMnemonic(java.awt.event.KeyEvent.VK_H); - add(helpMenu); - helpMenu.add(_about); - } - } - - MainView(String[] args) - { - super("Chat Demo"); - setMinimumSize(new Dimension(minWidth, minHeight)); - _prefs = Preferences.userNodeForPackage(getClass()); - javax.swing.ImageIcon icon = getIcon("/icons/16x16/chat.png"); - if(icon != null) - { - setIconImage(icon.getImage()); - } - setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() - { - public void windowClosing(WindowEvent e) - { - storeWindowPrefs(); - _coordinator.exit(); - } - }); - - _about = new AbstractAction("About") - { - public void - actionPerformed(ActionEvent e) - { - about(); - } - }; - - _login = new AbstractAction("Login") - { - public void actionPerformed(ActionEvent e) - { - _coordinator.setState(Coordinator.ClientState.Disconnected); - _login.setEnabled(false); - } - }; - _login.setEnabled(false); - - _logout = new AbstractAction("Logout") - { - public void actionPerformed(ActionEvent e) - { - _logout.setEnabled(false); - _chatView.storeWindowPrefs(); - _coordinator.logout(); - } - }; - _logout.setEnabled(false); - - _exit = new AbstractAction("Exit") - { - public void actionPerformed(ActionEvent e) - { - _logout.setEnabled(false); - _chatView.storeWindowPrefs(); - _coordinator.exit(); - } - }; - _exit.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("alt F4")); - - DefaultListModel users = new DefaultListModel(); - _loginView = new LoginView(this, _prefs.node("Connection")); - _chatView = new ChatView(_prefs, users); - _statusBar = new StatusBarI(); - _coordinator = new Coordinator(this, _loginView, _chatView, users, args); - _chatView.setCoordinator(_coordinator); - _loginView.setCoordinator(_coordinator); - - FormLayout layout = new FormLayout("fill:pref:grow", "fill:pref:grow"); - DefaultFormBuilder builder = new DefaultFormBuilder(layout); - builder.add(_loginView); - builder.add(_chatView); - - setJMenuBar(new MenuBar()); - - JPanel panel = new JPanel(new BorderLayout()); - panel.add(builder.getPanel(), BorderLayout.CENTER); - panel.add(_statusBar, BorderLayout.PAGE_END); - setContentPane(panel); - - _coordinator.setState(Coordinator.ClientState.Disconnected); - - setSize(minWidth, minHeight); - if(!loadWindowPrefs()) - { - ChatDemoGUIFactory.locateOnScreen(this); - } - setVisible(true); - } - - public void setEnabled(boolean enabled) - { - _logout.setEnabled(enabled); - _login.setEnabled(!enabled); - } - - public void setConnected(boolean connected) - { - _statusBar.setConnected(connected); - } - - private void about() - { - String text = "Chat Demo.\nCopyright \u00A9 ZeroC, Inc. All rights reserved.\n"; - JOptionPane.showMessageDialog(this, text, "About", JOptionPane.INFORMATION_MESSAGE); - } - - private boolean loadWindowPrefs() - { - try - { - if(!_prefs.nodeExists("Window")) - { - return false; - } - } - catch(BackingStoreException e) - { - return false; - } - - Preferences windowPrefs = _prefs.node("Window"); - int x = windowPrefs.getInt("x", 0); - int y = windowPrefs.getInt("y", 0); - int width = windowPrefs.getInt("width", minWidth); - int height = windowPrefs.getInt("height", minHeight); - setBounds(new Rectangle(x, y, width, height)); - if(windowPrefs.getBoolean("maximized", false)) - { - setExtendedState(Frame.MAXIMIZED_BOTH); - } - return true; - } - - private void storeWindowPrefs() - { - Preferences windowPrefs = _prefs.node("Window"); - Rectangle rect = getBounds(); - windowPrefs.putInt("x", rect.x); - windowPrefs.putInt("y", rect.y); - windowPrefs.putInt("width", rect.width); - windowPrefs.putInt("height", rect.height); - windowPrefs.putBoolean("maximized", getExtendedState() == Frame.MAXIMIZED_BOTH); - } - - static public ImageIcon getIcon(String path) - { - java.net.URL imgURL = MainView.class.getResource(path); - if(imgURL == null) - { - return null; - } - else - { - return new ImageIcon(imgURL); - } - } - - private final Preferences _prefs; - private final Coordinator _coordinator; - private final LoginView _loginView; - private final ChatView _chatView; - private final StatusBarI _statusBar; - private final Action _login; - private final Action _logout; - private final Action _exit; - private final Action _about; - - // default size - private static final int minWidth = 400; - private static final int minHeight = 540; -} diff --git a/java/Chat/src/main/java/com/zeroc/demos/Chat/StatusBarI.java b/java/Chat/src/main/java/com/zeroc/demos/Chat/StatusBarI.java deleted file mode 100644 index e9498aa4c5..0000000000 --- a/java/Chat/src/main/java/com/zeroc/demos/Chat/StatusBarI.java +++ /dev/null @@ -1,37 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -package com.zeroc.demos.Chat; - -import java.awt.BorderLayout; - -import javax.swing.border.EmptyBorder; -import javax.swing.SwingConstants; -import javax.swing.JPanel; -import javax.swing.JLabel; - -public class StatusBarI extends JPanel -{ - StatusBarI() - { - super(new BorderLayout()); - setBorder(new EmptyBorder(7, 7, 7, 7)); - _connectedLabel.setHorizontalAlignment(SwingConstants.RIGHT); - add(_connectedLabel, BorderLayout.LINE_START); - } - - public void setConnected(boolean connected) - { - if(connected) - { - _connectedLabel.setText("Online"); - } - else - { - _connectedLabel.setText("Offline"); - } - } - - private final JLabel _connectedLabel = new JLabel("Offline"); -} diff --git a/java/Chat/src/main/resources/icons/128x128/chat.png b/java/Chat/src/main/resources/icons/128x128/chat.png deleted file mode 100644 index 9f20745c5f..0000000000 Binary files a/java/Chat/src/main/resources/icons/128x128/chat.png and /dev/null differ diff --git a/java/Chat/src/main/resources/icons/16x16/chat.png b/java/Chat/src/main/resources/icons/16x16/chat.png deleted file mode 100644 index d8bf10b070..0000000000 Binary files a/java/Chat/src/main/resources/icons/16x16/chat.png and /dev/null differ diff --git a/java/Chat/src/main/resources/icons/16x16/user.png b/java/Chat/src/main/resources/icons/16x16/user.png deleted file mode 100644 index 8e35655e35..0000000000 Binary files a/java/Chat/src/main/resources/icons/16x16/user.png and /dev/null differ diff --git a/java/Chat/src/main/resources/icons/32x32/chat.png b/java/Chat/src/main/resources/icons/32x32/chat.png deleted file mode 100644 index 7da0fa09b5..0000000000 Binary files a/java/Chat/src/main/resources/icons/32x32/chat.png and /dev/null differ diff --git a/java/Chat/src/main/resources/icons/32x32/error.ico b/java/Chat/src/main/resources/icons/32x32/error.ico deleted file mode 100644 index 985c596eb2..0000000000 Binary files a/java/Chat/src/main/resources/icons/32x32/error.ico and /dev/null differ diff --git a/java/Chat/src/main/resources/icons/32x32/error.png b/java/Chat/src/main/resources/icons/32x32/error.png deleted file mode 100644 index ae1fd7d73a..0000000000 Binary files a/java/Chat/src/main/resources/icons/32x32/error.png and /dev/null differ diff --git a/java/Chat/src/main/slice/Chat.ice b/java/Chat/src/main/slice/Chat.ice deleted file mode 100644 index bcc0548b4f..0000000000 --- a/java/Chat/src/main/slice/Chat.ice +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#pragma once - -/** - * - * The Chat module defines types shared by definitions from - * ChatSession.ice and PollingChat.ice. - * - **/ - -["java:package:com.zeroc.demos"] -module Chat -{ - -/** - * - * The InvalidMessageException is raised when a user sends an invalid - * message to the server. A message is considered invalid if the - * message size exceeds the maximum message size. - * - **/ -exception InvalidMessageException -{ - /** - * - * The reason why the message was rejected by the server. - * - **/ - string reason; -} - -} diff --git a/java/Chat/src/main/slice/ChatSession.ice b/java/Chat/src/main/slice/ChatSession.ice deleted file mode 100644 index a0b9c25fcc..0000000000 --- a/java/Chat/src/main/slice/ChatSession.ice +++ /dev/null @@ -1,118 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#pragma once - -#include -#include -#include - -["java:package:com.zeroc.demos"] -module Chat -{ - -/** - * - * The ChatRoomCallback interface is the interface that clients implement - * as their callback object. - * - * The server calls operations of this interface to communicate - * with connected clients. - * - **/ -interface ChatRoomCallback -{ - /** - * - * The server invokes this operation when the client sets the callback - * for a session. This provides the client with the initial list of users - * currently in the chat room. - * - * @param users The names of users currently in the chat room. - * - **/ - void init(Ice::StringSeq users); - - /** - * - * The server invokes this operation to deliver a message - * that was sent to the chat room. - * - * @param name The name of the user that send the message. - * - * @param message The contents of the message. - * - * @param timestamp The time at which the message was sent. - * - **/ - void send(long timestamp, string name, string message); - - /** - * - * The server invokes this operation when a user joins - * the chat room. - * - * @param name The name of the user that joined the chat room. - * - * @param timestamp The time at which the user joined the chat room. - * - **/ - void join(long timestamp, string name); - - /** - * - * The servers invokes this operation when a user leaves - * the chat room. - * - * @param name The name of the user that left the chat room. - * - * @param timestamp The time at which the user left the chat room. - * - **/ - void leave(long timestamp, string name); -} - -/** - * - * A ChatSession is a custom Glacier2::Session for clients that use - * Glacier2 and support callbacks (C++, Java, and .NET clients). - * - * @see Glacier2::Session - * - **/ -interface ChatSession extends Glacier2::Session -{ - /** - * - * The setCallback operation is called by clients to set the - * callback used to receive notification of activity in the - * room. Clients receive notifications as soon as they call this - * operation (before setCallback returns). - * - * The first callback made by the server is a call to - * ChatRoomCallback::init, which delivers the current list of - * users to the client. - * - * @param cb The callback the server uses to deliver notifications. - * - * @see ChatRoomCallback - * - **/ - void setCallback(ChatRoomCallback* cb); - - /** - * - * Send a message to the chat room. - * - * @param message The message to be sent. - * - * @return The time at which the message is sent. - * - * @throws InvalidMessageException should the message be invalid. - * - **/ - long send(string message) throws InvalidMessageException; -} - -} diff --git a/java/Glacier2/README.md b/java/Glacier2/README.md index a97385621c..9cc549a3ad 100644 --- a/java/Glacier2/README.md +++ b/java/Glacier2/README.md @@ -4,8 +4,3 @@ Demos in this directory: Illustrates how to allow a server to call back into a client via a Glacier2 connection. - -- [simpleChat](./simpleChat) - - A swing application that shows how to use write a graphical Glacier2 - simple chat client. diff --git a/java/Glacier2/build.gradle b/java/Glacier2/build.gradle index 552fdab99e..ef74b9a8cb 100644 --- a/java/Glacier2/build.gradle +++ b/java/Glacier2/build.gradle @@ -2,7 +2,7 @@ // Copyright (c) ZeroC, Inc. All rights reserved. // -['callback', 'simpleChat'].each { +['callback'].each { def name = it project(":demoGlacier2${it.capitalize()}") { slice { @@ -30,10 +30,6 @@ jar.enabled = false demoJar("client") - - // The simpleChat demo has no serverJar. - if(name != "simpleChat") { - demoJar("server") - } + demoJar("server") } } diff --git a/java/Glacier2/simpleChat/Chat.ice b/java/Glacier2/simpleChat/Chat.ice deleted file mode 100644 index 34e7ad8157..0000000000 --- a/java/Glacier2/simpleChat/Chat.ice +++ /dev/null @@ -1,22 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#pragma once - -#include - -["java:package:com.zeroc.demos.Glacier2.simpleChat"] -module Demo -{ - interface ChatCallback - { - void message(string data); - } - - interface ChatSession extends Glacier2::Session - { - void setCallback(ChatCallback* callback); - void say(string data); - } -} diff --git a/java/Glacier2/simpleChat/Client.java b/java/Glacier2/simpleChat/Client.java deleted file mode 100644 index c28dc5c29f..0000000000 --- a/java/Glacier2/simpleChat/Client.java +++ /dev/null @@ -1,492 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.GridLayout; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - -import javax.swing.BoxLayout; -import javax.swing.JDialog; -import javax.swing.AbstractAction; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPasswordField; -import javax.swing.JPopupMenu; -import javax.swing.JScrollBar; -import javax.swing.JScrollPane; -import javax.swing.JSeparator; -import javax.swing.JSplitPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.ScrollPaneConstants; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; -import javax.swing.WindowConstants; -import javax.swing.text.AttributeSet; -import javax.swing.text.BadLocationException; -import javax.swing.text.DefaultEditorKit; -import javax.swing.text.Document; -import javax.swing.text.Element; - -import com.zeroc.demos.Glacier2.simpleChat.Demo.*; -import com.zeroc.Glacier2.SessionFactoryHelper; -import com.zeroc.Glacier2.SessionHelper; -import com.zeroc.Glacier2.SessionCallback; -import com.zeroc.Glacier2.SessionNotExistException; -import com.zeroc.Ice.Current; -import com.zeroc.Ice.LocalException; -import com.zeroc.Ice.Util; - -@SuppressWarnings("serial") -public class Client extends JFrame -{ - public static void main(final String[] args) - { - SwingUtilities.invokeLater(() -> - { - try - { - // - // Create and set up the window. - // - new Client(args); - } - catch(com.zeroc.Ice.LocalException e) - { - JOptionPane.showMessageDialog(null, e.toString(), "Initialization failed", JOptionPane.ERROR_MESSAGE); - } - }); - } - - Client(String[] args) - { - // Build the JTextArea that shows the chat conversation. - _output = new JTextArea(""); - _output.setLineWrap(true); - _output.setEditable(false); - - final JPopupMenu textMenu = new JPopupMenu(); - textMenu.add(new DefaultEditorKit.CopyAction()); - textMenu.pack(); - - _output.addMouseListener(new MouseAdapter() - { - @Override - public void mousePressed(MouseEvent e) - { - if(e.isPopupTrigger()) - { - textMenu.show(_output, e.getX(), e.getY()); - } - } - }); - - // Build the JTextArea where the user writes input messages. - _input = new JTextArea(""); - _input.setLineWrap(true); - _input.setEditable(true); - _input.addKeyListener(new KeyListener() - { - @Override - public void keyTyped(KeyEvent e) - { - if(e.getKeyChar() == KeyEvent.VK_ENTER) - { - Document doc = _input.getDocument(); - try - { - String msg = doc.getText(0, doc.getLength()).trim(); - if(msg.length() > 0) - { - _chat.sayAsync(msg).whenCompleteAsync((result, ex) -> - { - if(ex != null) - { - appendMessage(" - " + ex); - } - }, - _chat.ice_executor()); - } - } - catch(BadLocationException e1) - { - } - - _input.setText(""); - } - } - - @Override - public void keyPressed(KeyEvent e) - { - } - - @Override - public void keyReleased(KeyEvent e) - { - } - }); - - _outputScroll = new JScrollPane(_output); - _outputScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - _outputScroll.setBorder(null); - - _outputScroll.setMinimumSize(new Dimension(100, 100)); - _outputScroll.setPreferredSize(new Dimension(100, 100)); - - JSplitPane verticalSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT); - verticalSplit.setTopComponent(_outputScroll); - - JScrollPane conversationInputScroll = new JScrollPane(_input); - conversationInputScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - conversationInputScroll.setBorder(null); - - conversationInputScroll.setMinimumSize(new Dimension(100, 100)); - conversationInputScroll.setPreferredSize(new Dimension(100, 100)); - verticalSplit.setBottomComponent(conversationInputScroll); - - verticalSplit.setResizeWeight(0.9); - - _output.addComponentListener(new ComponentListener() - { - @Override - public void componentResized(ComponentEvent e) - { - JScrollBar vertivalScrollbar = _outputScroll.getVerticalScrollBar(); - vertivalScrollbar.setValue(vertivalScrollbar.getMaximum()); - } - - @Override - public void componentHidden(ComponentEvent e) - { - } - - @Override - public void componentMoved(ComponentEvent e) - { - } - - @Override - public void componentShown(ComponentEvent e) - { - } - }); - - add(verticalSplit, BorderLayout.CENTER); - - JPanel statusPanel = new JPanel(); - JSeparator statusPanelSeparator = new JSeparator(); - _status = new JLabel(); - _status.setText("Not connected"); - - statusPanel.add(statusPanelSeparator, BorderLayout.NORTH); - statusPanel.add(_status, BorderLayout.SOUTH); - - add(statusPanel, BorderLayout.SOUTH); - - JMenuBar menuBar = new JMenuBar(); - JMenu connectMenu = new JMenu("Session"); - - _login = new AbstractAction("Login") - { - @Override - public void actionPerformed(ActionEvent e) - { - login(); - } - }; - - _logout = new AbstractAction("Logout") - { - @Override - public void actionPerformed(ActionEvent e) - { - setEnabled(false); - _status.setText("Logging out"); - destroySession(); - _chat = null; - } - }; - _logout.setEnabled(false); - - _exit = new AbstractAction("Exit") - { - @Override - public void actionPerformed(ActionEvent e) - { - exit(); - } - }; - - connectMenu.add(_login); - connectMenu.add(_logout); - if(!System.getProperty("os.name").startsWith("Mac OS")) - { - connectMenu.add(_exit); - } - - menuBar.add(connectMenu); - - setJMenuBar(menuBar); - - setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - - addWindowListener(new WindowAdapter() - { - @Override - public void windowClosing(WindowEvent e) - { - exit(); - } - }); - - pack(); - setSize(640, 480); - locateOnScreen(this); - setVisible(true); - - // Create the labels and text fields. - JLabel hostLabel = new JLabel("Host: ", SwingConstants.RIGHT); - _hostField = new JTextField("", 12); - _hostField.setText("127.0.0.1"); - JLabel userNameLabel = new JLabel("Username: ", SwingConstants.RIGHT); - _userNameField = new JTextField("", 12); - _userNameField.setText("test"); - JLabel passwordLabel = new JLabel("Password: ", SwingConstants.RIGHT); - _passwordField = new JPasswordField("", 12); - _connectionPanel = new JPanel(false); - _connectionPanel.setLayout(new BoxLayout(_connectionPanel, BoxLayout.X_AXIS)); - - JPanel labelPanel = new JPanel(false); - labelPanel.setLayout(new GridLayout(0, 1)); - labelPanel.add(hostLabel); - labelPanel.add(userNameLabel); - labelPanel.add(passwordLabel); - JPanel fieldPanel = new JPanel(false); - fieldPanel.setLayout(new GridLayout(0, 1)); - fieldPanel.add(_hostField); - fieldPanel.add(_userNameField); - fieldPanel.add(_passwordField); - _connectionPanel.add(labelPanel); - _connectionPanel.add(fieldPanel); - - _input.setEnabled(false); - - com.zeroc.Ice.InitializationData initData = new com.zeroc.Ice.InitializationData(); - - // Load the configuration file. - initData.properties = new com.zeroc.Ice.Properties(); - initData.properties.load("config.client"); - initData.properties.setProperty("Ice.Default.Package", "com.zeroc.demos.Glacier2.simpleChat"); - initData.properties = new com.zeroc.Ice.Properties(args, initData.properties); - - // Setup a dispatcher to dispath Ice and Glacier2 helper callbacks to the GUI thread. - initData.dispatcher = (runnable, connection) -> - { - SwingUtilities.invokeLater(runnable); - }; - - _factory = new SessionFactoryHelper(initData, new SessionCallback() - { - @Override - public void connected(SessionHelper session) - throws SessionNotExistException - { - // If the session has been reassigned avoid the spurious callback. - if(session != _session) - { - return; - } - - // The chat callback servant. We use an anonymous - // inner class since the implementation is very - // simple. - ChatCallback servant = new ChatCallback() - { - @Override - public void message(final String data, Current current) - { - appendMessage(data); - } - }; - - ChatCallbackPrx callback = ChatCallbackPrx.uncheckedCast(_session.addWithUUID(servant)); - - _chat = ChatSessionPrx.uncheckedCast(_session.session()); - _chat.setCallbackAsync(callback).whenCompleteAsync((result, ex) -> - { - if(ex == null) - { - assert _loginDialog != null; - _loginDialog.dispose(); - - _login.setEnabled(false); - _logout.setEnabled(true); - - _input.setEnabled(true); - - _status.setText("Connected with " + _hostField.getText()); - } - else - { - destroySession(); - } - }, - _chat.ice_executor()); - } - - @Override - public void disconnected(SessionHelper session) - { - // If the session has been reassigned avoid the spurious callback. - if(session != _session) - { - return; - } - - if(_loginDialog != null) - { - _loginDialog.dispose(); - } - - _session = null; - _chat = null; - - _login.setEnabled(true); - _logout.setEnabled(false); - - _input.setEnabled(false); - _status.setText("Not connected"); - } - - @Override - public void connectFailed(SessionHelper session, Throwable ex) - { - // If the session has been reassigned avoid the - // spurious callback. - if(session != _session) - { - return; - } - - if(_loginDialog != null) - { - _loginDialog.dispose(); - } - _status.setText(ex.getClass().getName()); - } - - @Override - public void createdCommunicator(SessionHelper session) - { - } - }); - _factory.setRouterIdentity(new com.zeroc.Ice.Identity("router", "DemoGlacier2")); - - login(); - } - - protected void login() - { - String[] options = {"Login", "Cancel" }; - // Show Login Dialog. - int option = JOptionPane.showOptionDialog(this, _connectionPanel, "Login", JOptionPane.OK_CANCEL_OPTION, - JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); - - if(option == 0) - { - _factory.setRouterHost(_hostField.getText()); - // Connect to Glacier2 using SessionFactoryHelper - _session = _factory.connect(_userNameField.getText(), _passwordField.getText()); - String[] cancel = { "Cancel" }; - - // Show Connecting Dialog - JOptionPane pane = new JOptionPane("Please wait while connecting...", JOptionPane.INFORMATION_MESSAGE, - JOptionPane.DEFAULT_OPTION, null, cancel, cancel[0]); - _loginDialog = pane.createDialog(this, "Connecting"); - _loginDialog.setVisible(true); - - // User pressed cancel. - if(pane.getValue() != JOptionPane.UNINITIALIZED_VALUE) - { - // Destroy session - destroySession(); - } - } - } - - private void destroySession() - { - if(_session != null) - { - _session.destroy(); - //The session will be set to null on disconnected. - } - } - - private void exit() - { - destroySession(); - dispose(); - Runtime.getRuntime().exit(0); - } - - public void appendMessage(String message) - { - Document doc = _output.getDocument(); - Element e = doc.getDefaultRootElement(); - AttributeSet attr = e.getAttributes().copyAttributes(); - try - { - doc.insertString(doc.getLength(), message + "\n", attr); - } - catch(BadLocationException ex) - { - } - _output.setCaretPosition(doc.getLength()); - } - - private static void locateOnScreen(Component component) - { - Dimension paneSize = component.getSize(); - Dimension screenSize = component.getToolkit().getScreenSize(); - component.setLocation((screenSize.width - paneSize.width) / 2, (screenSize.height - paneSize.height) / 2); - } - - private JLabel _status; - private JTextArea _output; - private JTextArea _input; - private JScrollPane _outputScroll; - - // Login/Logout actions. - private AbstractAction _login; - private AbstractAction _logout; - private AbstractAction _exit; - - // Login dialog - private JDialog _loginDialog; - private JTextField _userNameField; - private JTextField _passwordField; - private JTextField _hostField; - private JPanel _connectionPanel; - - // The session factory and current session. - private SessionFactoryHelper _factory; - private SessionHelper _session; - private ChatSessionPrx _chat; -} diff --git a/java/Glacier2/simpleChat/README.md b/java/Glacier2/simpleChat/README.md deleted file mode 100644 index 829681c8a1..0000000000 --- a/java/Glacier2/simpleChat/README.md +++ /dev/null @@ -1,21 +0,0 @@ -This demo demonstrates the use of [Glacier2 session helpers][1] and Swing -to create a graphical client for the simple chat server. - -First follow the instructions in the C++ Glacier2 simpleChat demo -README to start the server and the Glacier2 router. - -In a separate window, start the swing client: - -``` -java -jar build/libs/client.jar -``` - -If you plan to run this demo using clients running on different hosts -than the glacier2router, it is necessary to first modify the -configuration. You need to change the `Glacier2.Client.Endpoints` -property in `config.glacier2` and the `Ice.Default.Router` property in -`config.client`. In all cases you must set the host parameter of the -`-h host` endpoint option to the actual external address of the machine -on which glacier2router is running. - -[1]: https://doc.zeroc.com/ice/3.7/ice-services/glacier2/glacier2-sessionhelper-class diff --git a/java/Glacier2/simpleChat/config.client b/java/Glacier2/simpleChat/config.client deleted file mode 100644 index e3083191fb..0000000000 --- a/java/Glacier2/simpleChat/config.client +++ /dev/null @@ -1,46 +0,0 @@ -# -# Warn about connection exceptions -# -#Ice.Warn.Connections=1 - -# -# Network Tracing -# -# 0 = no network tracing -# 1 = trace connection establishment and closure -# 2 = like 1, but more detailed -# 3 = like 2, but also trace data transfer -# -#Ice.Trace.Network=1 - -# -# Protocol Tracing -# -# 0 = no protocol tracing -# 1 = trace protocol messages -# -#Ice.Trace.Protocol=1 - -# -# Security Tracing -# -# 0 = no security tracing -# 1 = trace messages -# -#IceSSL.Trace.Security=1 - -# -# SSL Configuration -# -Ice.Plugin.IceSSL=com.zeroc.IceSSL.PluginFactory -IceSSL.DefaultDir=../../../certs -IceSSL.Keystore=client.jks -IceSSL.Password=password - -# -# IceMX configuration. -# -#Ice.Admin.Endpoints=tcp -h localhost -p 10004 -Ice.Admin.InstanceName=client -IceMX.Metrics.Debug.GroupBy=id -IceMX.Metrics.ByParent.GroupBy=parent diff --git a/java/README.md b/java/README.md index 33a082d6e3..72af4f6c14 100644 --- a/java/README.md +++ b/java/README.md @@ -15,8 +15,6 @@ following additional subdirectories: - [Manual](./Manual) contains complete examples for some of the code snippets in the [Ice manual][1]. -- [Chat](./Chat) contains a GUI client for the ZeroC [Chat Demo][2]. - Refer to the [C++11 demos](../cpp11) for more examples that use the Ice services (Glacier2, IceGrid, IceStorm). @@ -113,4 +111,3 @@ Follow these steps to open the project in Android Studio: Refer to the README.md file in each demo directory for usage instructions. [1]: https://doc.zeroc.com/ice/3.7/introduction -[2]: https://doc.zeroc.com/technical-articles/general-topics/chat-demo diff --git a/java/settings.gradle b/java/settings.gradle index 63006eef25..bb3f422233 100644 --- a/java/settings.gradle +++ b/java/settings.gradle @@ -10,7 +10,7 @@ def demos = [ 'session', 'swing', 'throughput', 'optional', 'context'], 'IceDiscovery' : ['hello', 'replication'], 'IceBox' : ['hello'], - 'Glacier2' : ['callback', 'simpleChat'], + 'Glacier2' : ['callback'], 'IceStorm' : ['clock'], 'IceGrid' : ['icebox', 'simple'], 'Manual' : ['printer', 'simpleFilesystem'] @@ -32,6 +32,3 @@ demos.each { project("${projectName}").projectDir = new File("${dir}/${it}") } } - -include ":demoChat" -project(":demoChat").projectDir = new File("Chat")