📄 netmapconnector.java
字号:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/graphicLoader/netmap/NetMapConnector.java,v $// $RCSfile: NetMapConnector.java,v $// $Revision: 1.4.2.2 $// $Date: 2005/08/09 17:59:28 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.graphicLoader.netmap;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.IOException;import java.util.Properties;import javax.swing.*;import com.bbn.openmap.PropertyConsumer;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PaletteHelper;import com.bbn.openmap.util.PropUtils;/** * The NetMapConnector is the bridge between the parser from the * output of the NetMap server (NetMapReader), and whoever wants the * OMGraphicList that is being mananged. It forwards the list on to * the NetMapListReceiver that wants the list. The NetMapConnector * will create it's NetMapReader to control and use. If you have a * component that wants to receive updates from the reader, then you * can register as an NetMapListener with the NetMapConnector. * * The NetMapConnector can be used in conjunction with the * NetMapConnectionHandler. The NetMapConnectionHandler will look for * NetMapConnectors in the BeanContext (MapHandler), and create a * NetMapGraphicLoader for it. That will set off the GraphicLoader -> * GraphicLoaderConnector -> GraphicLoaderPlugIn -> PlugInLayer * creation chain, if the GraphicLoaderConnector is also in the * MapHandler. * * The following properties can be set: * * <pre> * * * server=hostname of the NetMap server * port=port of NetMap server * defaultView=default view for NetMap server stream * * </pre> */public class NetMapConnector implements ActionListener, NetMapConstants, PropertyConsumer { public final static String ServerConnectCmd = "Connect"; public final static String ServerDisconnectCmd = "Disconnect"; public final static String LoadViewCmd = "Load View"; public final static String GetViewsCmd = "Get Network Views"; public final static String ServerProperty = "server"; public final static String PortProperty = "port"; public final static String DefaultViewProperty = "defaultView"; public final static String STATUS_CONNECTING = " Connecting "; public final static String STATUS_CONNECTED = " Connected "; public final static String STATUS_IDLE = " Idle "; private JPanel serverPanel = null; private JTextField serverAddrField = null; private JTextField serverPortField = null; private JLabel connectedStatus = null; private Choice viewChoice = null; private ChoiceList viewList = null; private JButton controlButton = null; protected String server = DEFAULT_SERVER; protected String port = DEFAULT_PORT; /** * The NetMap server has a notion of views that represent nodes * and links, and these are names. If using a GUI, the view names * will show up because they are received from the NetMap server. * Programmatically, you can set what the default view should be. */ protected String defaultView = null; protected String propertyPrefix = null; /** * The component that listens to the NetMap server and parses the * stream. */ NetMapReader reader = null; /** * Support for sending new NetMap events to listeners. */ NetMapListenerSupport listenerSupport = null; public NetMapConnector() { listenerSupport = new NetMapListenerSupport(this); } /** * Set the hostname or IP address to use to contact the NetMap * server. */ public void setServer(String sName) { server = sName; } /** * Get the hostname or IP address of the NetMap server. */ public String getServer() { return server; } /** * Set the port that the NetMap server is running on. */ public void setPort(String port) { this.port = port; } /** * Get the port that the NetMap server is running on. */ public String getPort() { return port; } /** * Set the defaultView to use for NetMap server queries. */ public void setDefaultView(String view) { defaultView = view; } /** * Get the defaultView to use for NetMap server queries. */ public String getDefaultView() { return defaultView; } /** * Add a NetMapListener to receive NetMapEvents. */ public void addNetMapListener(NetMapListener nml) { listenerSupport.addNetMapListener(nml); } /** * Remove a NetMapListener from the list to receive NetMapEvents. */ public void removeNetMapListener(NetMapListener nml) { listenerSupport.removeNetMapListener(nml); } /** * Clear all NetMapListeners from receiving NetMapEvents. */ public void clearNetMapListeners() { listenerSupport.clearNetMapListeners(); } /** * Called by the NetMapReader so a parsed line, representing an * event, can be dispersed to the listeners. */ protected void distributeEvent(Properties netmapProps) { listenerSupport.fireNetMapEvent(netmapProps); } /** Act on GUI commands controlling the NetMapReader. */ public void actionPerformed(java.awt.event.ActionEvent ae) { String cmd = ae.getActionCommand(); server = serverAddrField.getText(); port = serverPortField.getText(); if (cmd == GetViewsCmd) { connectedStatus.setText(STATUS_CONNECTING); viewList = getViews(); if (viewList == null) { Debug.message("netmap", "Can't get view list from " + server + ":" + port); disconnect(); } } else if (cmd == ServerDisconnectCmd) { Debug.message("netmap", "Disconnecting from server " + server + ":" + port); disconnect(); } else if (cmd == LoadViewCmd) { ChoiceItem ci = viewList.get(viewChoice.getSelectedItem()); if (ci == null) { disconnect(); return; } String view = ((String) ci.value()).trim(); Debug.message("netmap", "Loading view " + view); connect(view); } } /** * Callback for the NetMapReader to let it provide the connector * with connection status. */ protected void connectionUp() { if (connectedStatus != null) { connectedStatus.setText(STATUS_CONNECTED); connectedStatus.setBackground(Color.green); } } /** * Callback for the NetMapReader to let it provide the connector * with connection status. */ protected void connectionDown() { if (connectedStatus != null) { connectedStatus.setText(STATUS_IDLE); connectedStatus.setBackground(Color.red); } } /** * Resets the controls to the disconnected mode. */ public void disconnect() { if (reader != null) { reader.shutdown(); } reader = null; if (serverPanel != null) { serverAddrField.setEnabled(true); serverPortField.setEnabled(true); viewChoice.setEnabled(false); controlButton.setText(GetViewsCmd); controlButton.setActionCommand(GetViewsCmd); connectedStatus.setText(STATUS_IDLE); } } /** * Gets a list of possible views. * * @return ChoiceList of possible views retrieved from the NetMap * server.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -