Coverage Report - com.nilhcem.fakesmtp.gui.info.SaveMsgField
 
Classes in this File Line Coverage Branch Coverage Complexity
SaveMsgField
0%
0/14
0%
0/4
1.222
SaveMsgField$1
0%
0/10
N/A
1.222
 
 1  
 package com.nilhcem.fakesmtp.gui.info;
 2  
 
 3  
 import com.nilhcem.fakesmtp.core.ArgsHandler;
 4  
 import com.nilhcem.fakesmtp.core.I18n;
 5  
 import com.nilhcem.fakesmtp.gui.DirChooser;
 6  
 import com.nilhcem.fakesmtp.model.UIModel;
 7  
 
 8  
 import javax.swing.JTextField;
 9  
 import java.awt.Color;
 10  
 import java.awt.event.MouseEvent;
 11  
 import java.awt.event.MouseListener;
 12  
 import java.util.Observable;
 13  
 import java.util.Observer;
 14  
 
 15  
 /**
 16  
  * Text field in which will be written the path where emails will be automatically saved.
 17  
  *
 18  
  * @author Nilhcem
 19  
  * @since 1.0
 20  
  */
 21  0
 public final class SaveMsgField extends Observable implements Observer {
 22  
 
 23  0
         private final JTextField saveMsgField = new JTextField(UIModel.INSTANCE.getSavePath());
 24  
 
 25  
         /**
 26  
          * Creates a text field and adds a mouse listener, to display the directory chooser dialog when a user clicks on the field.
 27  
          * <p>
 28  
          * The text field will be disabled by default to avoid the user to type any folder directly.<br>
 29  
          * Instead, he can use the directory chooser dialog to select the path he wants.
 30  
          * </p>
 31  
          */
 32  0
         public SaveMsgField() {
 33  0
                 saveMsgField.setToolTipText(I18n.INSTANCE.get("savemsgfield.tooltip"));
 34  
 
 35  
                 // Disable edition but keep the same background color
 36  0
                 Color bg = saveMsgField.getBackground();
 37  0
                 saveMsgField.setEditable(false);
 38  0
                 saveMsgField.setBackground(bg);
 39  
 
 40  0
                 if (!ArgsHandler.INSTANCE.memoryModeEnabled()) {
 41  
                         // Add a MouseListener
 42  0
                         saveMsgField.addMouseListener(new MouseListener() {
 43  
                                 @Override
 44  
                                 public void mouseClicked(MouseEvent e) {
 45  0
                                 }
 46  
 
 47  
                                 @Override
 48  
                                 public void mousePressed(MouseEvent e) {
 49  0
                                         openFolderSelection();
 50  0
                                 }
 51  
 
 52  
                                 @Override
 53  
                                 public void mouseReleased(MouseEvent e) {
 54  0
                                 }
 55  
 
 56  
                                 @Override
 57  
                                 public void mouseEntered(MouseEvent e) {
 58  0
                                 }
 59  
 
 60  
                                 @Override
 61  
                                 public void mouseExited(MouseEvent e) {
 62  0
                                 }
 63  
 
 64  
                                 private void openFolderSelection() {
 65  0
                                         setChanged();
 66  0
                                         notifyObservers();
 67  0
                                 }
 68  
                         });
 69  
                 }
 70  0
         }
 71  
 
 72  
         /**
 73  
          * Returns the JTextField object.
 74  
          *
 75  
          * @return the JTextField object.
 76  
          */
 77  
         public JTextField get() {
 78  0
                 return saveMsgField;
 79  
         }
 80  
 
 81  
         /**
 82  
          * Updates the content of the JTextField with the new directory value.
 83  
          * <p>
 84  
          * Once a directory has been chosen by the {@link DirChooser}, the latter will
 85  
          * notify this class, so that it can update its content.
 86  
          * </p>
 87  
          *
 88  
          * @param o the observable element which will notify this class.
 89  
          * @param arg optional parameters (not used).
 90  
          */
 91  
         @Override
 92  
         public void update(Observable o, Object arg) {
 93  0
                 if (o instanceof DirChooser) {
 94  0
                         saveMsgField.setText(UIModel.INSTANCE.getSavePath());
 95  
                 }
 96  0
         }
 97  
 }