Skip to content

Commit

Permalink
duplicate code to AbstractMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
icklesteve committed Feb 20, 2020
1 parent d82be49 commit 7c99aa9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 40 deletions.
32 changes: 17 additions & 15 deletions java/src/jmri/jmrix/can/cbus/CbusEventHighlighter.java
Expand Up @@ -28,19 +28,29 @@ public class CbusEventHighlighter {
*/
public CbusEventHighlighter() {
}

/**
* highlight an event, based on previous settings.
* Highlight a CAN Frame, based on previous settings.
*
* @param m CanMessage to highlight.
* @param m CanMessage or CanReply to highlight.
* @return true if event matches
*/
public boolean highlight(CanMessage m) {
return !((doNotHighlight(m))
|| ((_dir != CbusConstants.EVENT_DIR_EITHER)
public boolean highlight(AbstractMessage m){
if (m instanceof CanMessage){
return !((doNotHighlight(m))
|| ((_dir != CbusConstants.EVENT_DIR_EITHER)
&& (_dir != CbusConstants.EVENT_DIR_OUT)));
}
else if (m instanceof CanReply){
return !((doNotHighlight(m))
|| ((_dir != CbusConstants.EVENT_DIR_EITHER)
&& (_dir != CbusConstants.EVENT_DIR_IN)));
}
else {
return false;
}
}

/**
*
* @param m CanFrame to test against
Expand All @@ -53,14 +63,6 @@ private boolean doNotHighlight(AbstractMessage m) {
|| ((_type != CbusConstants.EVENT_EITHER)
&& (_type != CbusMessage.getEventType(m))));
}

public boolean highlight(CanReply r) {
return !((doNotHighlight(r))
|| ((_dir != CbusConstants.EVENT_DIR_EITHER)
&& (_dir != CbusConstants.EVENT_DIR_IN)));
}

// control terms to be included in highlight

/**
* Set whether NN (Node Number) will be included in highlight.
Expand Down
54 changes: 29 additions & 25 deletions java/src/jmri/jmrix/can/cbus/swing/CbusEventHighlightFrame.java
Expand Up @@ -4,16 +4,15 @@
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.WindowConstants;
import jmri.jmrix.can.CanMessage;
import jmri.jmrix.can.CanReply;
import jmri.jmrix.AbstractMessage;
import jmri.jmrix.can.cbus.CbusConstants;
import jmri.jmrix.can.cbus.CbusEventHighlighter;
import jmri.jmrix.can.cbus.swing.console.CbusConsolePane;
import jmri.jmrix.can.cbus.swing.configtool.ConfigToolPane;
import jmri.util.JmriJFrame;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// import org.slf4j.Logger;
// import org.slf4j.LoggerFactory;

/**
* Frame to control an instance of CBUS highlighter to highlight events.
Expand Down Expand Up @@ -44,22 +43,24 @@ public class CbusEventHighlightFrame extends JmriJFrame {
*/
public CbusEventHighlightFrame(CbusConsolePane console, ConfigToolPane evCap) {
super();
log.debug("CbusEventhighlightFrame(CbusEventFilter) ctor called");
for (int i = 0; i < HIGHLIGHTERS; i++) {
_highlight[i] = new CbusEventHighlighter();
_highlightActive[i] = false;
}
_console = console;
_evCap = evCap;
this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
log.debug("CbusEventFilterFrame(CbusEventFilter) ctor done");
}

protected CbusEventHighlightFrame() {
super();
}

protected String title() {
/**
* {@inheritDoc}
*/
@Override
public String getTitle() {
if ( _console != null) {
return _console.getTitle() + " " + Bundle.getMessage("EventHighlightTitle");
}
Expand All @@ -69,9 +70,6 @@ else if ( _evCap != null) {
return(Bundle.getMessage("EventHighlightTitle"));
}

protected void init() {
}

/**
* {@inheritDoc}
*/
Expand All @@ -85,7 +83,7 @@ public void dispose() {
*/
@Override
public void initComponents() {
setTitle(title());
setTitle(getTitle());
// Panels will be added downwards
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

Expand All @@ -102,6 +100,9 @@ public void initComponents() {
pack();
}

/**
* Enable Highlighter.
*/
public void enable(int index, int nn, boolean nnEn, int ev, boolean evEn, int ty, int dr) {

_highlight[index].setNn(nn);
Expand Down Expand Up @@ -162,36 +163,39 @@ private void appendDirection( StringBuilder sb, int index ){
}
}

/**
* Disable a Highlighter by Index Number.
* @param index Highlighter Index number
*/
public void disable(int index) {
_highlightActive[index] = false;
if ( _console != null) {
_console.nextLine( Bundle.getMessage("HighlightDisabled") + " \n", Bundle.getMessage("HighlightDisabled") + " \n", index);
}
}

public int highlight(CanMessage m) {
int i;
for (i = 0; i < HIGHLIGHTERS; i++) {
/**
* Get whether to Highlight a particular CAN Frame.
* @param m CanMessage or CanReply
* @return -1 to NOT Highlight, else Highlighter Number.
*/
public int highlight(AbstractMessage m) {
for (int i = 0; i < HIGHLIGHTERS; i++) {
if (_highlightActive[i] && _highlight[i].highlight(m)) {
return i;
}
}
return -1;
}

public int highlight(CanReply r) {
int i;
for (i = 0; i < HIGHLIGHTERS; i++) {
if (_highlightActive[i] && _highlight[i].highlight(r)) {
return i;
}
}
return -1;
}

/**
* Get Colour for a particular highlighter.
* @param i Highlight index
* @return Highlight Colour
*/
public Color getColor(int i) {
return highlightColors[i];
}

private final static Logger log = LoggerFactory.getLogger(CbusEventHighlightFrame.class);
// private final static Logger log = LoggerFactory.getLogger(CbusEventHighlightFrame.class);
}

0 comments on commit 7c99aa9

Please sign in to comment.