001package jmri.jmrix.loconet.swing; 002 003import jmri.jmrix.loconet.LocoNetSystemConnectionMemo; 004 005/** 006 * JPanel extension to handle automatic creation of window title and help 007 * reference for LocoNet panels 008 * <p> 009 * For use with JmriAbstractAction, etc 010 * 011 * @author Bob Jacobsen Copyright 2010, 2015 012 * @since 2.9.4 013 */ 014abstract public class LnPanel extends jmri.util.swing.JmriPanel implements LnPanelInterface { 015 016 /** 017 * Make "memo" object available as convenience. 018 */ 019 protected LocoNetSystemConnectionMemo memo; 020 021 /** 022 * {@inheritDoc} 023 */ 024 @Override 025 public void initComponents(LocoNetSystemConnectionMemo memo) { 026 this.memo = memo; 027 } 028 029 /** 030 * {@inheritDoc} 031 */ 032 @Override 033 public void initContext(Object context) { 034 if (context instanceof LocoNetSystemConnectionMemo) { 035 initComponents((LocoNetSystemConnectionMemo) context); 036 } 037 } 038 039 public String getTitle(String menuTitle) { 040 return getTitleHelper(memo, menuTitle); 041 } 042 043 /** 044 * Create menu title from connection name. 045 * <p> 046 * Static to allow code to be shared by other LnPanelInterface 047 * implementations. 048 * 049 * @param memo the memo to get connection name from 050 * @param menuTitle window title 051 * @return window title with connection name 052 */ 053 public static String getTitleHelper(LocoNetSystemConnectionMemo memo, String menuTitle) { 054 String uName = ""; 055 if (memo != null) { 056 uName = memo.getUserName(); 057 // string "LocoNet" is hard coded 058 if (!"LocoNet".equals(uName)) { // NOI18N 059 uName = uName + ": "; // NOI18N 060 } else { 061 uName = ""; 062 } 063 } 064 return uName + menuTitle; 065 } 066 067}