/******************************************************************************* * 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.mobileID; 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.JTextArea; import javax.swing.JTextField; import javax.swing.text.MaskFormatter; import net.miginfocom.swing.MigLayout; import alias.AliasID; import alias.ComponentEditor; import alias.id.esn.ESNEditor; public class MINEditor extends ComponentEditor { private static final long serialVersionUID = 1L; private static final String HELP_TEXT = "" + "

Passport Mobile ID (MIN) Example

" + "MIN: six character hex value (e.g. AB12CD)
" + "Wildcard: use an asterisk (*) to wildcard individual
" + "digits (e.g. AB**CD or AB12**)" + ""; private JTextField mTextField; public MINEditor( AliasID aliasID ) { super( aliasID ); initGUI(); setComponent( aliasID ); } private void initGUI() { setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][]" ) ); add( new JLabel( "MIN:" ) ); MaskFormatter formatter = null; try { //Mask: 6 hex characters formatter = new MaskFormatter( "HHHHHH" ); } 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( MINEditor.this, HELP_TEXT, "Example", JOptionPane.INFORMATION_MESSAGE ); } } ); add( example ); } public Min getMin() { if( getComponent() instanceof Min ) { return (Min)getComponent(); } return null; } @Override public void setComponent( AliasID aliasID ) { mComponent = aliasID; Min min = getMin(); if( min != null ) { mTextField.setText( min.getMin() ); } setModified( false ); repaint(); } @Override public void save() { Min min = getMin(); if( min != null ) { min.setMin( mTextField.getText() ); } setModified( false ); } }