Skip to content
Permalink
Browse files

Merge pull request #5815 from pabender/master

refactor JMRIClient Monitor
  • Loading branch information...
pabender committed Sep 17, 2018
2 parents 70ed632 + 9819434 commit 3aaca96b54ca349a75a9a1522524602a86286fba
@@ -0,0 +1,97 @@
package jmri.jmrix.jmriclient.swing;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Locale;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
@CheckReturnValue
@SuppressFBWarnings(value = "NM_SAME_SIMPLE_NAME_AS_SUPERCLASS", justification = "Desired pattern is repeated class names with package-level access to members")

@javax.annotation.concurrent.Immutable

/**
* Provides standard access for resource bundles in a package.
*
* Convention is to provide a subclass of this name in each package, working off
* the local resource bundle name.
*
* @author Bob Jacobsen Copyright (C) 2012
* @since 3.3.1
*/
public class Bundle extends jmri.jmrix.jmriclient.Bundle {

@Nullable
private static final String name = "jmri.jmrix.jmriclient.swing.JmriClientSwingBundle"; // NOI18N

//
// below here is boilerplate to be copied exactly
//
/**
* Provides a translated string for a given key from the package resource
* bundle or parent.
* <p>
* Note that this is intentionally package-local access.
*
* @param key Bundle key to be translated
* @return Internationalized text
*/
static String getMessage(String key) {
return getBundle().handleGetMessage(key);
}

/**
* Merges user data with a translated string for a given key from the
* package resource bundle or parent.
* <p>
* Uses the transformation conventions of the Java MessageFormat utility.
* <p>
* Note that this is intentionally package-local access.
*
* @see java.text.MessageFormat
* @param key Bundle key to be translated
* @param subs One or more objects to be inserted into the message
* @return Internationalized text
*/
static String getMessage(String key, Object... subs) {
return getBundle().handleGetMessage(key, subs);
}

/**
* Merges user data with a translated string for a given key in a given
* locale from the package resource bundle or parent.
* <p>
* Uses the transformation conventions of the Java MessageFormat utility.
* <p>
* Note that this is intentionally package-local access.
*
* @see java.text.MessageFormat
* @param locale The locale to be used
* @param key Bundle key to be translated
* @param subs One or more objects to be inserted into the message
* @return Internationalized text
*/
static String getMessage(Locale locale, String key, Object... subs) {
return getBundle().handleGetMessage(locale, key, subs);
}

private final static Bundle b = new Bundle();

@Override
@Nullable
protected String bundleName() {
return name;
}

protected static jmri.Bundle getBundle() {
return b;
}

@Override
protected String retry(Locale locale, String key) {
return super.getBundle().handleGetMessage(locale,key);
}

}
@@ -18,17 +18,15 @@ public JMRIClientMenu(String name, jmri.jmrix.jmriclient.JMRIClientSystemConnect
public JMRIClientMenu(jmri.jmrix.jmriclient.JMRIClientSystemConnectionMemo memo) {
super();

ResourceBundle rb = ResourceBundle.getBundle("jmri.jmrix.JmrixSystemsBundle");

if (memo != null) {
setText(memo.getUserName());
} else {
setText(rb.getString("MenuItemJMRIClient"));
setText(Bundle.getMessage("MenuItemJMRIClient"));
}

if (memo != null) {
add(new jmri.jmrix.jmriclient.swing.mon.JMRIClientMonAction(rb.getString("MenuItemCommandMonitor"), memo));
add(new jmri.jmrix.jmriclient.swing.packetgen.PacketGenAction(rb.getString("MenuItemSendCommand"), memo));
add(new jmri.jmrix.jmriclient.swing.mon.JMRIClientMonAction());
add(new jmri.jmrix.jmriclient.swing.packetgen.PacketGenAction(Bundle.getMessage("MenuItemSendCommand"), memo));
}
}

@@ -0,0 +1,7 @@
# JmriClientSwingBundle.properties
#
# Default properties for the jmri.jmrix.jmriclient.swing package and swing.systeminfo package

MenuItemJmriClientCommandMonitor = JMRIClient Monitor
MenuItemJmriClientCommandMonitorTitle = JMRIClient Command Monitor
MenuItemSendJmriClientCommand = Generate JMRIClient Command
@@ -0,0 +1,97 @@
package jmri.jmrix.jmriclient.swing.mon;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Locale;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
@CheckReturnValue
@SuppressFBWarnings(value = "NM_SAME_SIMPLE_NAME_AS_SUPERCLASS", justification = "Desired pattern is repeated class names with package-level access to members")

@javax.annotation.concurrent.Immutable

/**
* Provides standard access for resource bundles in a package.
*
* Convention is to provide a subclass of this name in each package, working off
* the local resource bundle name.
*
* @author Bob Jacobsen Copyright (C) 2012
* @since 3.3.1
*/
public class Bundle extends jmri.jmrix.jmriclient.swing.Bundle {

@Nullable
private static final String name = null; // NOI18N

//
// below here is boilerplate to be copied exactly
//
/**
* Provides a translated string for a given key from the package resource
* bundle or parent.
* <p>
* Note that this is intentionally package-local access.
*
* @param key Bundle key to be translated
* @return Internationalized text
*/
static String getMessage(String key) {
return getBundle().handleGetMessage(key);
}

/**
* Merges user data with a translated string for a given key from the
* package resource bundle or parent.
* <p>
* Uses the transformation conventions of the Java MessageFormat utility.
* <p>
* Note that this is intentionally package-local access.
*
* @see java.text.MessageFormat
* @param key Bundle key to be translated
* @param subs One or more objects to be inserted into the message
* @return Internationalized text
*/
static String getMessage(String key, Object... subs) {
return getBundle().handleGetMessage(key, subs);
}

/**
* Merges user data with a translated string for a given key in a given
* locale from the package resource bundle or parent.
* <p>
* Uses the transformation conventions of the Java MessageFormat utility.
* <p>
* Note that this is intentionally package-local access.
*
* @see java.text.MessageFormat
* @param locale The locale to be used
* @param key Bundle key to be translated
* @param subs One or more objects to be inserted into the message
* @return Internationalized text
*/
static String getMessage(Locale locale, String key, Object... subs) {
return getBundle().handleGetMessage(locale, key, subs);
}

private final static Bundle b = new Bundle();

@Override
@Nullable
protected String bundleName() {
return name;
}

protected static jmri.Bundle getBundle() {
return b;
}

@Override
protected String retry(Locale locale, String key) {
return super.getBundle().handleGetMessage(locale,key);
}

}
@@ -1,40 +1,10 @@
package jmri.jmrix.jmriclient.swing.mon;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Swing action to create and register a JMRIClientMonFrame object
*
* @author Bob Jacobsen Copyright (C) 2008
* @author Paul Bender Copyright (C) 2018
*/
public class JMRIClientMonAction extends AbstractAction {

private jmri.jmrix.jmriclient.JMRIClientSystemConnectionMemo _memo;

public JMRIClientMonAction(jmri.jmrix.jmriclient.JMRIClientSystemConnectionMemo memo) {
this("JMRICLient Monitor", memo);
}

public JMRIClientMonAction(String s, jmri.jmrix.jmriclient.JMRIClientSystemConnectionMemo memo) {
super(s);
_memo = memo;
}

@Override
public void actionPerformed(ActionEvent e) {
// create a JMRIClientMonFrame
JMRIClientMonFrame f = new JMRIClientMonFrame(_memo);
try {
f.initComponents();
} catch (Exception ex) {
log.warn("JMRIClientMonAction starting JMRIClientMonFrame: Exception: " + ex.toString());
}
f.setVisible(true);
}

private final static Logger log = LoggerFactory.getLogger(JMRIClientMonAction.class);

public class JMRIClientMonAction extends JMRIClientMonPane.Default {
}

This file was deleted.

@@ -0,0 +1,70 @@
package jmri.jmrix.jmriclient.swing.mon;

import jmri.jmrix.jmriclient.JMRIClientListener;
import jmri.jmrix.jmriclient.JMRIClientMessage;
import jmri.jmrix.jmriclient.JMRIClientReply;
import jmri.jmrix.jmriclient.JMRIClientTrafficController;
import jmri.jmrix.jmriclient.JMRIClientSystemConnectionMemo;

/**
* Pane displaying (and logging) JMRIClient command messages
*
* @author Bob Jacobsen Copyright (C) 2008
*/
public class JMRIClientMonPane extends jmri.jmrix.AbstractMonPane implements JMRIClientListener {

protected JMRIClientTrafficController tc = null;

public JMRIClientMonPane() {
super();
}

@Override
public String getTitle() {
return Bundle.getMessage("MenuItemJmriClientCommandMonitorTitle");
}

@Override
protected void init() {
}

@Override
public void initContext(Object context) {
if (context instanceof JMRIClientSystemConnectionMemo) {
JMRIClientSystemConnectionMemo memo = (JMRIClientSystemConnectionMemo) context;
// connect to TrafficController
tc = memo.getJMRIClientTrafficController();
tc.addJMRIClientListener(this);
}
}

@Override
public void dispose() {
tc.removeJMRIClientListener(this);
tc = null;
super.dispose();
}

@Override
public synchronized void message(JMRIClientMessage l) { // receive a message and log it
logMessage("cmd: ",l);
}

@Override
public synchronized void reply(JMRIClientReply l) { // receive a reply message and log it
logMessage("rep: ",l);
}

/**
* Nested class to create one of these using old-style defaults
*/
static public class Default extends jmri.util.swing.JmriNamedPaneAction {

public Default() {
super(Bundle.getMessage("MenuItemJmriClientCommandMonitorTitle"), JMRIClientMonPane.class.getName());
setContext(jmri.InstanceManager.
getDefault(JMRIClientSystemConnectionMemo.class));
}
}

}

0 comments on commit 3aaca96

Please sign in to comment.
You can’t perform that action at this time.