Coverage Report - de.glossmaker.gui.gloss.frames.MessageFrame
 
Classes in this File Line Coverage Branch Coverage Complexity
MessageFrame
0%
0/45
0%
0/6
1,429
MessageFrame$1
0%
0/3
N/A
1,429
 
 1  
 package de.glossmaker.gui.gloss.frames;
 2  
 
 3  
 import javax.swing.JFrame;
 4  
 import java.awt.Dimension;
 5  
 import javax.swing.JTextPane;
 6  
 import javax.swing.JPanel;
 7  
 import java.awt.Toolkit;
 8  
 
 9  
 import javax.swing.JButton;
 10  
 import java.awt.Rectangle;
 11  
 import java.awt.event.ActionEvent;
 12  
 import java.awt.event.ActionListener;
 13  
 import java.awt.BorderLayout;
 14  
 import java.awt.Color;
 15  
 import java.awt.SystemColor;
 16  
 import java.awt.Point;
 17  
 
 18  
 /**
 19  
  * 
 20  
  * 
 21  
  * @author Markus Flingelli
 22  
  *
 23  
  */
 24  
 public class MessageFrame extends JFrame {
 25  
         private static final long serialVersionUID = -2151183569671877741L;
 26  0
         private JPanel jMainPanel = null;
 27  0
         private JTextPane jInfoTextPane = null;
 28  0
         private JButton jOkButton = null;
 29  0
         private int mWidth = 400;
 30  0
         private int mHeight = 220;
 31  
 
 32  
         /**
 33  
          * Shows a info frame.
 34  
          * 
 35  
          * @param infoText Has to be coded as HTML.
 36  
          */
 37  
         public MessageFrame(String infoText) {
 38  0
                 super();
 39  0
                 initialize();
 40  0
                 jInfoTextPane.setText(infoText);
 41  0
         }
 42  
         
 43  
         /**
 44  
          * Shows a info frame.
 45  
          * 
 46  
          * @param infoText Has to be coded as HTML.
 47  
          */
 48  
         public MessageFrame(int width, int height, String infoText) {
 49  0
                 super();
 50  0
                 mWidth = width;
 51  0
                 mHeight = height;
 52  0
                 initialize();
 53  0
                 jInfoTextPane.setText(infoText);
 54  0
         }
 55  
 
 56  
         private void initialize() {
 57  0
         this.setPreferredSize(new Dimension(mWidth, mHeight));
 58  0
         this.setSize(new Dimension(mWidth, mHeight));
 59  0
         this.setLocation(new Point(0, 0));
 60  0
         this.setContentPane(getJMainPanel());
 61  0
         this.setTitle("");                
 62  0
         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
 63  0
         int top = (screenSize.height - this.getHeight()) / 2;
 64  0
         int left = (screenSize.width - this.getWidth()) / 2;
 65  0
         this.setLocation(left, top); 
 66  0
         }
 67  
 
 68  
 
 69  
 
 70  
         private JPanel getJMainPanel() {
 71  0
                 if (jMainPanel == null) {
 72  0
                         jMainPanel = new JPanel();
 73  0
                         jMainPanel.setLayout(new BorderLayout());
 74  0
                         jMainPanel.add(getJInfoTextPane(), BorderLayout.CENTER);
 75  0
                         jMainPanel.add(getJOkButton(), BorderLayout.SOUTH);
 76  
                 }
 77  0
                 return jMainPanel;
 78  
         }
 79  
 
 80  
 
 81  
         private JTextPane getJInfoTextPane() {
 82  0
                 if (jInfoTextPane == null) {
 83  0
                         jInfoTextPane = new JTextPane();
 84  0
                         jInfoTextPane.setEditable(false);
 85  0
                         jInfoTextPane.setEnabled(true);
 86  0
                         jInfoTextPane.setBackground(SystemColor.control);
 87  0
                         jInfoTextPane.setForeground(Color.blue);
 88  0
                         jInfoTextPane.setContentType("text/html");
 89  
                 }
 90  0
                 return jInfoTextPane;
 91  
         }
 92  
 
 93  
 
 94  
         private JButton getJOkButton() {
 95  0
                 if (jOkButton == null) {
 96  0
                         jOkButton = new JButton();
 97  0
                         jOkButton.setBounds(new Rectangle(mHeight - 60, (mWidth - 100) / 2, 100, 25));
 98  0
                         jOkButton.setText("OK");
 99  0
                         jOkButton.addActionListener(new ActionListener() {
 100  
                                 
 101  
                                 @Override
 102  
                                 public void actionPerformed(ActionEvent event) {
 103  0
                                         MessageFrame.this.setVisible(false);
 104  0
                                 }
 105  
                         });
 106  
                 }
 107  0
                 return jOkButton;
 108  
         }
 109  
         
 110  
         
 111  
 
 112  
 }