001package jmri.jmrix.can.swing;
002
003import jmri.jmrix.can.CanSystemConnectionMemo;
004
005/**
006 * JPanel extension to handle automatic creation of window title and help
007 * reference for Cbus panels.
008 * <p>
009 * For use with JmriAbstractAction, etc
010 *
011 * @author Bob Jacobsen Copyright 2010
012 * @since 2.99.2
013 */
014abstract public class CanPanel extends jmri.util.swing.JmriPanel implements CanPanelInterface {
015
016    /**
017     * Make "memo" object available as convenience.
018     */
019    protected CanSystemConnectionMemo memo;
020
021    /**
022     * {@inheritDoc}
023     */
024    @Override
025    public void initComponents(CanSystemConnectionMemo memo) {
026        this.memo = memo;
027    }
028    
029    public CanSystemConnectionMemo getMemo() {
030        return this.memo;
031    }
032
033    /**
034     * {@inheritDoc}
035     */
036    @Override
037    public void initContext(Object context) {
038        if (context instanceof CanSystemConnectionMemo) {
039            initComponents((CanSystemConnectionMemo) context);
040        }
041    }
042    
043    /**
044     * Prepends Connection UserName, if present, to start of a String.
045     * @param initial The Initial String
046     * @return The Connection with the initial String appended
047     */
048    public String prependConnToString(String initial) {
049        if (memo != null) {
050            StringBuilder buf = new StringBuilder();
051            buf.append(memo.getUserName());
052            buf.append(" ");
053            buf.append(initial);
054            return buf.toString();
055        }
056        return initial;
057    }
058}