/******************************************************************************* * SDR Trunk * Copyright (C) 2014-2016 Dennis Sheirer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see ******************************************************************************/ package alias.id.mdc; import java.awt.Color; import java.awt.Cursor; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JFormattedTextField; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JTextField; import javax.swing.text.MaskFormatter; import net.miginfocom.swing.MigLayout; import alias.AliasID; import alias.ComponentEditor; public class MDC1200IDEditor extends ComponentEditor { private static final long serialVersionUID = 1L; private static final String HELP_TEXT = "" + "

MDC-1200 Identifier Example

" + "MDC-1200: four digit [0-9] value (e.g. 1234)
" + "Wildcard: use an asterisk (*) to wildcard individual
" + "digits (e.g. 123* or **34)" + ""; private JTextField mTextField; public MDC1200IDEditor( AliasID aliasID ) { super( aliasID ); initGUI(); setComponent( aliasID ); } private void initGUI() { setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][]" ) ); add( new JLabel( "MDC-1200 ID:" ) ); MaskFormatter formatter = null; try { //Mask: 4 digits formatter = new MaskFormatter( "####" ); } catch( Exception e ) { //Do nothing, the mask was invalid } mTextField = new JFormattedTextField( formatter ); mTextField.getDocument().addDocumentListener( this ); mTextField.setToolTipText( HELP_TEXT ); add( mTextField, "growx,push" ); JLabel example = new JLabel( "Example ..." ); example.setForeground( Color.BLUE.brighter() ); example.setCursor( new Cursor( Cursor.HAND_CURSOR ) ); example.addMouseListener( new MouseAdapter() { @Override public void mouseClicked( MouseEvent e ) { JOptionPane.showMessageDialog( MDC1200IDEditor.this, HELP_TEXT, "Example", JOptionPane.INFORMATION_MESSAGE ); } } ); add( example ); } public MDC1200ID getMDC1200ID() { if( getComponent() instanceof MDC1200ID ) { return (MDC1200ID)getComponent(); } return null; } @Override public void setComponent( AliasID aliasID ) { mComponent = aliasID; MDC1200ID mdc = getMDC1200ID(); if( mdc != null ) { mTextField.setText( mdc.getIdent() ); } setModified( false ); repaint(); } @Override public void save() { MDC1200ID mdc = getMDC1200ID(); if( mdc != null ) { mdc.setIdent( mTextField.getText() ); } setModified( false ); } }