View Javadoc

1   /*
2    * Copyright (c) 2003-2008 by Cosylab d. d.
3    *
4    * This file is part of CosyBeans.
5    *
6    * CosyBeans 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, or
9    * (at your option) any later version.
10   *
11   * CosyBeans is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with CosyBeans.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  
20  package com.cosylab.gui.infopanel;
21  
22  import java.awt.Dimension;
23  import java.awt.GridBagConstraints;
24  import java.awt.GridBagLayout;
25  import java.awt.Insets;
26  import java.util.Date;
27  
28  import javax.swing.JLabel;
29  import javax.swing.JPanel;
30  
31  import com.cosylab.gui.displayers.DataState;
32  
33  /**
34   * <code>DebugPanel</code> displays the current state that was initiated on
35   * a displayer. The panel shows data that belongs to the set DataState.
36   * 
37   * @author <a href="mailto:jaka.bobnar@cosylab.com">Jaka Bobnar</a>
38   * @version $Id: DebugPanel.java,v 1.4 2008-04-22 12:31:02 jbobnar Exp $
39   *
40   */
41  public class DebugPanel extends JPanel {
42  		
43  	private static final long serialVersionUID = -1976156943972439878L;
44  	private DataState dataState;
45  	
46  	private JLabel stateLabel;
47  	private JLabel errorLabel;
48  	private JLabel timeLabel;
49  	
50  	private JLabel state;
51  	private JLabel error;
52  	private JLabel time;
53  	
54  	public DebugPanel() {
55  		super();
56  		initialize();
57  	}
58  	
59  	private void initialize() {
60  		this.setLayout(new GridBagLayout());
61  		stateLabel = new JLabel("State: ");
62  		stateLabel.setMaximumSize(new Dimension(100,21));
63  		stateLabel.setMinimumSize(new Dimension(100,21));
64  		stateLabel.setPreferredSize(new Dimension(100,21));
65  		this.add(stateLabel, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(11,11,1,1),0,0));
66  		state = new JLabel();
67  		this.add(state, new GridBagConstraints(1,0,1,1,1,0,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(11,1,1,11),0,0));
68  		
69  		errorLabel = new JLabel("Description: ");
70  		errorLabel.setMaximumSize(new Dimension(100,21));
71  		errorLabel.setMinimumSize(new Dimension(100,21));
72  		errorLabel.setPreferredSize(new Dimension(100,21));
73  		this.add(errorLabel, new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,11,1,1),0,0));
74  		error = new JLabel();
75  		this.add(error, new GridBagConstraints(1,1,1,1,1,0,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(1,1,1,11),0,0));
76  
77  		timeLabel = new JLabel("Time: ");
78  		timeLabel.setMaximumSize(new Dimension(100,21));
79  		timeLabel.setMinimumSize(new Dimension(100,21));
80  		timeLabel.setPreferredSize(new Dimension(100,21));
81  		this.add(timeLabel, new GridBagConstraints(0,2,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,11,11,1),0,0));
82  		time = new JLabel();
83  		this.add(time, new GridBagConstraints(1,2,1,1,1,0,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(1,1,11,11),0,0));
84  	}
85  	
86  	/**
87  	 * Sets the DataState, which provides data for this panel.
88  	 * 
89  	 * @param dataState
90  	 */
91  	public void setDataState(DataState dataState) {
92  		this.dataState = dataState;
93  		if (this.dataState != null) {
94  			state.setText(dataState.type);
95  			error.setText(dataState.description);
96  			time.setText(String.valueOf(new Date(dataState.timestamp)));
97  		} else {
98  			state.setText("< NONE >");
99  			error.setText("< NONE >");
100 			time.setText(String.valueOf(new Date(System.currentTimeMillis())));
101 		}
102 		
103 	}
104 	
105 	/**
106 	 * Returns the DataState, that the info belongs to.
107 	 * @return
108 	 */
109 	public DataState getDataState() {
110 		return dataState;
111 	}
112 	
113 }