001package jmri.jmrit.consisttool; 002 003import java.awt.event.ActionEvent; 004import javax.swing.Icon; 005import jmri.util.swing.JmriAbstractAction; 006import jmri.util.swing.WindowInterface; 007 008/** 009 * Swing action to create and register a ConsistToolFrame object. 010 * 011 * @author Paul Bender Copyright (C) 2003 012 */ 013public class ConsistToolAction extends JmriAbstractAction { 014 015 public ConsistToolAction(String s, WindowInterface wi) { 016 super(s, wi); 017 setConsistManagerState(); 018 } 019 020 public ConsistToolAction(String s, Icon i, WindowInterface wi) { 021 super(s, i, wi); 022 setConsistManagerState(); 023 } 024 025 public ConsistToolAction(String s) { 026 super(s); 027 setConsistManagerState(); 028 } 029 030 private void setConsistManagerState () { 031 // disable ourself if there is no consist manager available 032 jmri.ConsistManager consistManager = jmri.InstanceManager.getNullableDefault(jmri.ConsistManager.class); 033 if (consistManager == null) { 034 setEnabled(false); 035 } else if (consistManager.canBeDisabled()) { 036 consistManager.registerEnableListener((value) -> { 037 setEnabled(value); 038 }); 039 setEnabled(consistManager.isEnabled()); 040 } 041 } 042 043 public ConsistToolAction() { 044 this(Bundle.getMessage("MenuItemConsistTool")); 045 } 046 047 @Override 048 public void actionPerformed(ActionEvent e) { 049 050 ConsistToolFrame f = new ConsistToolFrame(); 051 f.setVisible(true); 052 } 053 054 // never invoked, because we overrode actionPerformed above 055 @Override 056 public jmri.util.swing.JmriPanel makePanel() { 057 throw new IllegalArgumentException("Should not be invoked"); 058 } 059 060}