📄 netmapconnector.java
字号:
*/ public ChoiceList getViews() { ChoiceList views = null; try { reader = new NetMapReader(server, port, this); } catch (IOException e) { Debug.message("netmap", "Can't start reader: " + e); } Debug.message("netmap", "Checking for views..."); // reader will be null if server or port is bad... if (reader != null) { views = reader.getViewList(server, port); } if (serverPanel != null) { viewChoice.removeAll(); if (views != null) { for (int i = 0; i < views.size(); i++) { if (Debug.debugging("netmap")) { Debug.output("Adding view: " + views.labelAt(i)); } viewChoice.add(views.labelAt(i)); } serverAddrField.setEnabled(false); serverPortField.setEnabled(false); viewChoice.setEnabled(true); controlButton.setText(LoadViewCmd); controlButton.setActionCommand(LoadViewCmd); } } return views; } /** * Connects to the NetMap server to get messages about the given * view. */ public void connect(String view) { try { reader = new NetMapReader(server, port, this, view); reader.start(); if (serverPanel != null) { serverAddrField.setEnabled(false); serverPortField.setEnabled(false); controlButton.setText(ServerDisconnectCmd); controlButton.setActionCommand(ServerDisconnectCmd); } } catch (IOException e) { Debug.message("netmap", "Can't start reader: " + e); disconnect(); } } /** * Complete disconnect, sends clear command to NetMapListeners, * resets GUI if it's being used. */ public void reset() { disconnect(); Properties rp = new Properties(); rp.setProperty(COMMAND_FIELD, CLEAR); distributeEvent(rp); if (serverPanel != null) { viewChoice.removeAll(); connectedStatus.setText(STATUS_IDLE); } } /** * Gets the GUI control for the NetMapReader, creates it if it * doesn't exist. */ public Component getGUI() { if (serverPanel != null) { return serverPanel; } serverAddrField = new JTextField(server); serverPortField = new JTextField(port); /* * Make the NETMAP Server address entry field */ JPanel serverAddrPanel = new JPanel(new GridLayout(0, 2)); serverAddrPanel.add(new JLabel("Name or IP Addr: ")); serverAddrPanel.add(serverAddrField); /* * Make the NETMAP Server port entry field */ JPanel serverPortPanel = new JPanel(new GridLayout(0, 2)); serverPortPanel.add(new JLabel("Port: ")); serverPortPanel.add(serverPortField); /* */ JPanel statusPanel = PaletteHelper.createHorizontalPanel("Server Connection"); connectedStatus = new JLabel(STATUS_IDLE); JButton resetButton = new JButton("Reset"); resetButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { reset(); } }); statusPanel.add(connectedStatus); statusPanel.add(resetButton); /* * Make the toplevel input panel */ // JPanel netmapPanel = new JPanel(new GridLayout(0, 1)); JPanel netmapPanel = PaletteHelper.createVerticalPanel("Server Settings"); netmapPanel.add(serverAddrPanel); netmapPanel.add(serverPortPanel); /* * Make the "Load View" panel */ viewChoice = new Choice(); viewList = new ChoiceList(); viewChoice.setEnabled(false); controlButton = new JButton(GetViewsCmd); controlButton.setActionCommand(GetViewsCmd); controlButton.addActionListener(this); // JPanel viewPanel = new JPanel(new GridLayout(0, 1)); JPanel viewPanel = PaletteHelper.createVerticalPanel(null); viewPanel.add(new JLabel("Available Views")); viewPanel.add(viewChoice); viewPanel.add(controlButton); serverPanel = new JPanel(); Box box = Box.createVerticalBox(); box.add(netmapPanel); box.add(statusPanel); box.add(viewPanel); serverPanel.add(box); return serverPanel; } /** * Method to set the properties in the PropertyConsumer. It is * assumed that the properties do not have a prefix associated * with them, or that the prefix has already been set. * * @param setList a properties object that the PropertyConsumer * can use to retrieve expected properties it can use for * configuration. */ public void setProperties(Properties setList) { setProperties(null, setList); } /** * Method to set the properties in the PropertyConsumer. The * prefix is a string that should be prepended to each property * key (in addition to a separating '.') in order for the * PropertyConsumer to uniquely identify properties meant for it, * in the midst of of Properties meant for several objects. * * @param prefix a String used by the PropertyConsumer to prepend * to each property value it wants to look up - * setList.getProperty(prefix.propertyKey). If the prefix * had already been set, then the prefix passed in should * replace that previous value. * @param setList a Properties object that the PropertyConsumer * can use to retrieve expected properties it can use for * configuration. */ public void setProperties(String prefix, Properties setList) { setPropertyPrefix(prefix); prefix = PropUtils.getScopedPropertyPrefix(prefix); server = setList.getProperty(prefix + ServerProperty); if (server == null) { server = DEFAULT_SERVER; } port = setList.getProperty(prefix + PortProperty); if (port == null) { port = DEFAULT_PORT; } } /** * Method to fill in a Properties object, reflecting the current * values of the PropertyConsumer. If the PropertyConsumer has a * prefix set, the property keys should have that prefix plus a * separating '.' prepended to each property key it uses for * configuration. * * @param list a Properties object to load the PropertyConsumer * properties into. If getList equals null, then a new * Properties object should be created. * @return Properties object containing PropertyConsumer property * values. If getList was not null, this should equal * getList. Otherwise, it should be the Properties object * created by the PropertyConsumer. */ public Properties getProperties(Properties list) { if (list == null) { list = new Properties(); } String prefix = PropUtils.getScopedPropertyPrefix(this); list.put(prefix + ServerProperty, server); list.put(prefix + PortProperty, port); return list; } /** * Method to fill in a Properties object with values reflecting * the properties able to be set on this PropertyConsumer. The key * for each property should be the raw property name (without a * prefix) with a value that is a String that describes what the * property key represents, along with any other information about * the property that would be helpful (range, default value, * etc.). * * @param list a Properties object to load the PropertyConsumer * properties into. If getList equals null, then a new * Properties object should be created. * @return Properties object containing PropertyConsumer property * values. If getList was not null, this should equal * getList. Otherwise, it should be the Properties object * created by the PropertyConsumer. */ public Properties getPropertyInfo(Properties list) { if (list == null) { list = new Properties(); } list.put(ServerProperty, "The hostname or IP for NetMap server"); list.put(PortProperty, "The port number for NetMap server"); return list; } /** * Set the property key prefix that should be used by the * PropertyConsumer. The prefix, along with a '.', should be * prepended to the property keys known by the PropertyConsumer. * * @param prefix the prefix String. */ public void setPropertyPrefix(String prefix) { propertyPrefix = prefix; } /** * Get the property key prefix that is being used to prepend to * the property keys for Properties lookups. * * @return the property prefix */ public String getPropertyPrefix() { return propertyPrefix; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -