Coverage Report - org.jtheque.core.managers.view.impl.frame.MessageView
 
Classes in this File Line Coverage Branch Coverage Complexity
MessageView
0 %
0/35
0 %
0/10
1.556
 
 1  
 package org.jtheque.core.managers.view.impl.frame;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.message.Message;
 20  
 import org.jtheque.core.managers.view.able.IMessageView;
 21  
 import org.jtheque.core.managers.view.able.components.IModel;
 22  
 import org.jtheque.core.managers.view.impl.actions.messages.DisplayNextMessageAction;
 23  
 import org.jtheque.core.managers.view.impl.actions.messages.DisplayPreviousMessageAction;
 24  
 import org.jtheque.core.managers.view.impl.frame.abstraction.SwingBuildedDialogView;
 25  
 import org.jtheque.core.managers.view.impl.models.IMessageModel;
 26  
 import org.jtheque.core.managers.view.impl.models.MessageModel;
 27  
 import org.jtheque.core.utils.ui.PanelBuilder;
 28  
 import org.jtheque.utils.ui.GridBagUtils;
 29  
 
 30  
 import javax.swing.JLabel;
 31  
 import javax.swing.JTextArea;
 32  
 
 33  
 /**
 34  
  * A view to display the messages of the module and the application. 
 35  
  *
 36  
  * @author Baptiste Wicht
 37  
  */
 38  0
 public final class MessageView extends SwingBuildedDialogView<IModel> implements IMessageView {
 39  
     private JLabel dateLabel;
 40  
     private JLabel sourceLabel;
 41  
     private JLabel titleLabel;
 42  
     private JTextArea messageArea;
 43  
 
 44  
     /**
 45  
      * Construct a new MessageView.
 46  
      */
 47  
     public MessageView(){
 48  0
         super();
 49  
 
 50  0
         build();
 51  0
     }
 52  
 
 53  
     @Override
 54  
     protected void initView(){
 55  0
         setModel(new MessageModel());
 56  0
         setTitleKey("messages.view.title");
 57  0
         setResizable(false);
 58  0
     }
 59  
 
 60  
     @Override
 61  
     protected void buildView(PanelBuilder builder){
 62  0
         addLabels(builder);
 63  0
         addFields(builder);
 64  
 
 65  0
         builder.addButtonBar(builder.gbcSet(0, 4, GridBagUtils.HORIZONTAL, GridBagUtils.LINE_END, 2, 1),
 66  
                 getCloseAction("messages.actions.close"), new DisplayNextMessageAction(), new DisplayPreviousMessageAction());
 67  0
     }
 68  
 
 69  
     /**
 70  
      * Add the labels to the view.
 71  
      *
 72  
      * @param builder The builder to add the labels to.
 73  
      */
 74  
     private static void addLabels(PanelBuilder builder) {
 75  0
         builder.addI18nLabel("messages.view.data.date", PanelBuilder.BOLD, builder.gbcSet(0, 0, GridBagUtils.NONE, GridBagUtils.LINE_END));
 76  0
         builder.addI18nLabel("messages.view.data.source", PanelBuilder.BOLD, builder.gbcSet(0, 1, GridBagUtils.NONE, GridBagUtils.LINE_END));
 77  0
         builder.addI18nLabel("messages.view.data.title", PanelBuilder.BOLD, builder.gbcSet(0, 2, GridBagUtils.NONE, GridBagUtils.LINE_END));
 78  0
     }
 79  
 
 80  
     /**
 81  
      * Add the fields to the view.
 82  
      *
 83  
      * @param builder The builder to add the fields to.
 84  
      */
 85  
     private void addFields(PanelBuilder builder) {
 86  0
         dateLabel = builder.add(new JLabel(getModel().isDefaultMessage() ? "" : getModel().getCurrentMessage().getDate().getStrDate()),
 87  
                 builder.gbcSet(1, 0));
 88  
 
 89  0
         sourceLabel = builder.add(new JLabel(getModel().isDefaultMessage() ? "" : getModel().getCurrentMessage().getSource()),
 90  
                 builder.gbcSet(1, 1));
 91  
 
 92  0
         titleLabel = builder.add(new JLabel(getModel().isDefaultMessage() ? "" : getModel().getCurrentMessage().getTitle()),
 93  
                 builder.gbcSet(1, 2));
 94  
 
 95  0
         messageArea = new JTextArea(getModel().isDefaultMessage() ? "" : getModel().getCurrentMessage().getMessage());
 96  0
         messageArea.setRows(8);
 97  0
         messageArea.setEnabled(false);
 98  
 
 99  0
         builder.addScrolled(messageArea, builder.gbcSet(0, 3, GridBagUtils.BOTH, GridBagUtils.LINE_START, 2, 1));
 100  0
     }
 101  
 
 102  
     @Override
 103  
     public void next() {
 104  0
         setMessage(getModel().getNextMessage());
 105  0
     }
 106  
 
 107  
     @Override
 108  
     public void previous() {
 109  0
         setMessage(getModel().getPreviousMessage());
 110  0
     }
 111  
 
 112  
     /**
 113  
      * Set the message to display.
 114  
      *
 115  
      * @param message The message to display.
 116  
      */
 117  
     private void setMessage(Message message) {
 118  0
         if (getModel().isDefaultMessage()) {
 119  0
             dateLabel.setText(message.getDate().getStrDate());
 120  0
             sourceLabel.setText(message.getSource());
 121  0
             titleLabel.setText(message.getTitle());
 122  0
             messageArea.setText(message.getMessage());
 123  
         }
 124  0
     }
 125  
 
 126  
     @Override
 127  
     public IMessageModel getModel() {
 128  0
         return (IMessageModel) super.getModel();
 129  
     }
 130  
 }