001 package nl.cwi.sen1.visplugin; 002 003 import java.awt.BorderLayout; 004 import java.awt.event.ActionEvent; 005 import java.awt.event.ActionListener; 006 import javax.swing.JButton; 007 import javax.swing.JLabel; 008 import javax.swing.JPanel; 009 010 /** 011 * The ContainerPanel class forms a container panel for 012 * a contentpanel and a warning panel. 013 * 014 * @author Arjen van Schie 015 * @date 16-3-2007 016 */ 017 public class ContainerPanel extends JPanel{ 018 private static final long serialVersionUID = -5928381544709327449L; 019 020 private JPanel m_contentPanel = null; 021 private JPanel m_warningPanel = null; 022 private JLabel m_warningLabel = null; 023 024 private static final String constWarningChanged = "The RStore has changed, this view might be outdated."; 025 private static final String constWarningUnloaded = "The RStore of this fact has been unloaded!"; 026 027 /** 028 * Generate a container panel for the warningpanel 029 * and the content panel and hide the warningpanel by default 030 * 031 * @author Arjen van Schie 032 * @date 16-3-2007 033 * @param JPanel content 034 */ 035 public ContainerPanel(JPanel content){ 036 // make the panel fullscreen 037 this.makePanelFullscreen(); 038 039 // get the child panel-references 040 m_warningPanel = this.generateWarningPanel(); 041 m_contentPanel = content; 042 043 // add the panels 044 this.add( m_warningPanel, BorderLayout.NORTH ); 045 this.add( m_contentPanel, BorderLayout.CENTER ); 046 047 // hide the warning panel by default 048 this.hideWarning(); 049 } 050 051 /** 052 * Show a warning-message for the RStore-changed event 053 * 054 * @author Arjen van Schie 055 * @date 16-3-2007 056 */ 057 public void showRstoreChangedWarning(){ 058 m_warningLabel.setText( constWarningChanged ); 059 m_warningPanel.setVisible(true); 060 } 061 062 /** 063 * Show a warning-message for the RStore-unloaded event 064 * 065 * @author Arjen van Schie 066 * @date 16-3-2007 067 */ 068 public void showRstoreUnloadedWarning(){ 069 m_warningLabel.setText( constWarningUnloaded ); 070 m_warningPanel.setVisible(true); 071 } 072 073 /** 074 * Hide the warning messages of a window 075 * 076 * @author Arjen van Schie 077 * @date 16-3-2007 078 */ 079 public void hideWarning(){ 080 m_warningPanel.setVisible(false); 081 } 082 083 /** 084 * Make the panel fullscreen 085 * 086 * @author Arjen van Schie 087 * @date 16-3-2007 088 */ 089 private void makePanelFullscreen(){ 090 BorderLayout layout = new BorderLayout(); 091 this.setLayout(layout); 092 } 093 094 /** 095 * Generate a panel for the warning messages 096 * @author Arjen van Schie 097 * @date 16-3-2007 098 */ 099 private JPanel generateWarningPanel(){ 100 // create a label and panel 101 JPanel warningArea = new JPanel(); 102 m_warningLabel=new JLabel(); 103 m_warningLabel.setForeground(java.awt.Color.red); 104 105 // add a button to hide the warnings 106 JButton hideWarningButton = new JButton(); 107 hideWarningButton.setText("Hide Warning"); 108 hideWarningButton.addActionListener(new ActionListener() { 109 public void actionPerformed(ActionEvent event) { 110 hideWarning(); 111 } 112 }); 113 114 // connect the label & button 115 warningArea.add(m_warningLabel); 116 warningArea.add(hideWarningButton); 117 118 return warningArea; 119 } 120 121 /** 122 * return a reference to the contentpanel 123 * @author Arjen van Schie 124 * @date 16-3-2007 125 */ 126 public JPanel getContentPanel() { 127 return m_contentPanel; 128 } 129 130 /** 131 * returns the current warning message (or "empty" in case it is invisible) 132 * @author Arjen van Schie 133 * @date 16-3-2007 134 */ 135 public String getCurrentWarning(){ 136 String warning="empty"; 137 if( m_warningPanel.isVisible() ){ 138 warning = m_warningLabel.getText(); 139 } 140 return warning; 141 } 142 143 }