content: package com.japisoft.editix.ui;
  
  import java.awt.Dimension;
  import java.awt.Event;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  
  import javax.swing.JPanel;
  
  import com.japisoft.framework.ui.toolkit.FileManager;
  
  /**
  This program is available under two licenses : 
  
  1. For non commercial usage : 
  
  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 <http://www.gnu.org/licenses/>.
  
  2. For commercial usage :
  
  You need to get a commercial license for source usage at : 
  
  http://www.editix.com/buy.html
  
  Copyright (c) 2018 Alexandre Brillant - JAPISOFT SARL - http://www.japisoft.com
  
  @author Alexandre Brillant - abrillant@japisoft.com
  @author JAPISOFT SARL - http://www.japisoft.com
  
  */
  class RegisteredDialog extends EditixDialog implements ActionListener {
  	
  	private JPanel panel = null;
  	
  	public RegisteredDialog() {
  		super( 
  			"Register",
  			"Register",
  			"You can order at http://www.editix.com/buy.html and receive instantly by mail your activating key. Copy and Paste your registered name and key or fill it from a file"
  		);		
  		add( panel = new JPanel() );
  		initComponents();
  		loadFromMail.addActionListener( this );
  		pasteKey.addActionListener( this );
  		pasteUserName.addActionListener( this );
  	}
  
  	@Override
  	public boolean action(Event evt, Object what) {
  		return super.action(evt, what);
  	}
  	
  	@Override
  	public void addNotify() {
  		super.addNotify();
  	}
  
  	public void removeNotify() {
  		super.removeNotify();
  		loadFromMail.removeActionListener( this );
  		pasteKey.removeActionListener( this );
  		pasteUserName.removeActionListener( this );
  	}
  
  	public void actionPerformed( ActionEvent e ) {
  		if ( e.getSource() == pasteKey ) {
  			txtKey.paste();
  		} else
  		if ( e.getSource() == pasteUserName ) {
  			txtUserName.paste();
  		} else
  		if ( e.getSource() == loadFromMail ) {
  			File f = FileManager.getSelectedFile( true, new String[] { "eml", "msg" }, new String[] { "Mail message (*.eml)", "Mail message (*.msg)" } );				
  			if ( f != null ) {
  				try {
  					BufferedReader 
  						buf = new BufferedReader(
  								new FileReader( f ) );
  					try {
  						String line = null;
  						while ( ( line = buf.readLine() ) != null  ) {
  							if ( line.startsWith( "Username:" ) ) {
  								txtUserName.setText(
  										line.substring( 9 ).trim() );
  							} else
  							if ( line.startsWith( "Registered name:" )) {
  								txtKey.setText( buf.readLine() );
  							}
  							if ( line.startsWith( "Key:" ) || 
  									line.startsWith( "Registered key:" ) ) {
  								txtKey.setText( buf.readLine() );
  							}
  						}
  					} finally {
  						try {
  							buf.close();
  						} catch ( IOException e1 ) {
  						}
  					}
  				} catch ( FileNotFoundException e1 ) {
  				} catch( IOException ex ) {}
  			}
  		}
  	}	
  
  	public Dimension getDefaultSize() {
  		return new Dimension( 400, 300 );
  	}
  
  	String getUser() { return txtUserName.getText(); }
  
  	String getKey() {
  		if ( txtKey.getText() == null || "".equals( txtKey.getText() ) )
  			return null;
  		
  		String key = txtKey.getText().trim(); 
  		StringBuffer sbKey = new StringBuffer();
  
  		// Remove wrong characters
  		for ( int i = 0; i < key.length(); i++ ) {
  			if ( Character.isDigit( key.charAt( i ) ) )
  				sbKey.append( key.charAt( i ) );
  		}
  		return sbKey.toString(); 
  	}
  	
  	 /**
       * This method is called from within the constructor to initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is always
       * regenerated by the Form Editor.
       */
      @SuppressWarnings("unchecked")
      // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
      private void initComponents() {
  
          jLabel2 = new javax.swing.JLabel();
          jLabel1 = new javax.swing.JLabel();
          txtUserName = new javax.swing.JTextField();
          pasteUserName = new javax.swing.JButton();
          jLabel3 = new javax.swing.JLabel();
          jScrollPane1 = new javax.swing.JScrollPane();
          txtKey = new javax.swing.JTextArea();
          pasteKey = new javax.swing.JButton();
          loadFromMail = new javax.swing.JButton();
  
          jLabel2.setText("jLabel2");
  
          jLabel1.setText("Username");
  
          pasteUserName.setText("Paste");
  
          jLabel3.setText("Key");
  
          txtKey.setColumns(20);
          txtKey.setLineWrap(true);
          txtKey.setRows(5);
          jScrollPane1.setViewportView(txtKey);
  
          pasteKey.setText("Paste");
          pasteKey.setToolTipText("");
  
          loadFromMail.setText("Load from mail");
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(panel);
          panel.setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE)
                      .addGroup(layout.createSequentialGroup()
                          .addComponent(txtUserName)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                          .addComponent(pasteUserName))
                      .addGroup(layout.createSequentialGroup()
                          .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                              .addComponent(jLabel1)
                              .addComponent(jLabel3))
                          .addGap(0, 0, Short.MAX_VALUE))
                      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                          .addComponent(loadFromMail)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                          .addComponent(pasteKey)))
                  .addContainerGap())
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(jLabel1)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(pasteUserName))
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(jLabel3)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(pasteKey)
                      .addComponent(loadFromMail))
                  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
          );
      }// </editor-fold>                        
  
  
      // Variables declaration - do not modify                     
      private javax.swing.JLabel jLabel1;
      private javax.swing.JLabel jLabel2;
      private javax.swing.JLabel jLabel3;
      private javax.swing.JScrollPane jScrollPane1;
      private javax.swing.JButton loadFromMail;
      private javax.swing.JButton pasteKey;
      private javax.swing.JButton pasteUserName;
      private javax.swing.JTextArea txtKey;
      private javax.swing.JTextField txtUserName;
      // End of variables declaration                   
  
  }
  