View Javadoc
1 /* 2 Bloof - visualize the evolution of your software project 3 Copyright ( C ) 2003 Lukasz Pekacki <lukasz@pekacki.de> 4 http://bloof.sf.net/ 5 6 This program is free software; you can redistribute it and/or modify it 7 under the terms of the GNU General Public License. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along with 15 this program; if not, write to the Free Software Foundation, Inc., 16 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18 $RCSfile: BrowserButton.java,v $ 19 Created on $Date: 2003/09/06 08:40:53 $ 20 */ 21 package net.sf.bloof.browser; 22 23 import java.awt.event.ActionEvent; 24 import java.awt.event.ActionListener; 25 import java.util.HashMap; 26 import java.util.HashSet; 27 import java.util.Iterator; 28 29 import javax.swing.ImageIcon; 30 import javax.swing.JButton; 31 32 import net.sf.bloof.browser.events.*; 33 34 /*** 35 * 36 * @author Lukasz Pekacki <pekacki@users.sourceforge.net> 37 * @version $Id: BrowserButton.java,v 1.4 2003/09/06 08:40:53 pekacki Exp $ 38 */ 39 public class BrowserButton extends JButton implements BrowserEventListener { 40 public BrowserButton(HashMap aParams) { 41 mControl = (GuiController) aParams.get(GuiConstants.PARAM_GUI_CONTROLLER); 42 mButtonAction = (BrowserAction) aParams.get(PARAM_ACTION); 43 if (aParams.containsKey(PARAM_ICON_FILENAME)) { 44 setPreferredSize(GuiConstants.METRIC_BUTTON_SIZE); 45 setIcon(new ImageIcon(ImageLoader.getImage((String) aParams.get(PARAM_ICON_FILENAME)))); 46 setBorderPainted(false); 47 setFocusPainted(false); 48 setRolloverEnabled(true); 49 } 50 if (aParams.containsKey(PARAM_TEXT)) { 51 super.setText((String)aParams.get(PARAM_TEXT)); 52 } 53 setToolTipText((String) aParams.get(PARAM_TOOL_TIP)); 54 mControl.addBrowserEventListener(this); 55 addBrowserActionListener(mControl); 56 addActionListener(new ActionListener() { 57 public void actionPerformed(ActionEvent e) { 58 tellButtonAction(); 59 60 } 61 }); 62 setupInitEnabled(); 63 } 64 65 public void addBrowserActionListener(BrowserActionListener aListener) { 66 mBrowserActionListeners.add(aListener); 67 } 68 public void browserEventOccured(BrowserEvent bE) { 69 switch (bE.getEventType()) { 70 case BrowserEvent.TYPE_NEW_METRIC_RUN : 71 { 72 setupNewMetricAdded(); 73 break; 74 } 75 case BrowserEvent.TYPE_PROJECT_CHANGED : 76 { 77 setupProjectChangedEnabled(); 78 break; 79 } 80 case BrowserEvent.TYPE_PROJECT_CLOSED : 81 { 82 setupInitEnabled(); 83 break; 84 } 85 } 86 } 87 protected void informBrowserActionListeners(BrowserAction aBrowserAction) { 88 for (Iterator iter = mBrowserActionListeners.iterator(); iter.hasNext();) { 89 BrowserActionListener element = (BrowserActionListener) iter.next(); 90 element.browserActionOccured(aBrowserAction); 91 } 92 } 93 94 /*** 95 * 96 */ 97 private void setupInitEnabled() { 98 switch (mButtonAction.getSwitchType()) { 99 case BrowserAction.TYPE_SHOW_DIALOG_CLOSE_PROJECT : 100 case BrowserAction.TYPE_SHOW_DIALOG_EXPORT : 101 case BrowserAction.TYPE_SHOW_DIALOG_METRIC : 102 case BrowserAction.TYPE_SHOW_DIALOG_UPDATE_PROJECT : 103 case BrowserAction.TYPE_SHOW_DIALOG_SQL_METRIC : 104 { 105 setEnabled(false); 106 break; 107 } 108 case BrowserAction.TYPE_SHOW_DIALOG_OPEN_PROJECT : 109 { 110 if (mControl.getConfigFile().getProjects().hasNext()) { 111 setEnabled(true); 112 } else { 113 setEnabled(false); 114 } 115 } 116 } 117 118 } 119 private void setupProjectChangedEnabled() { 120 switch (mButtonAction.getSwitchType()) { 121 case BrowserAction.TYPE_SHOW_DIALOG_CLOSE_PROJECT : 122 case BrowserAction.TYPE_SHOW_DIALOG_METRIC : 123 case BrowserAction.TYPE_SHOW_DIALOG_SQL_METRIC : 124 { 125 setEnabled(true); 126 break; 127 } 128 case BrowserAction.TYPE_SHOW_DIALOG_UPDATE_PROJECT : 129 { 130 if (mControl.getCurrentProject().getScmAccess().getLogfilePath() == null) { 131 setEnabled(true); 132 } else { 133 setEnabled(false); 134 } 135 break; 136 } 137 case BrowserAction.TYPE_SHOW_DIALOG_OPEN_PROJECT : 138 { 139 setEnabled(false); 140 break; 141 } 142 case BrowserAction.TYPE_SHOW_DIALOG_EXPORT : 143 { 144 setEnabled(false); 145 break; 146 } 147 } 148 149 } 150 151 private void setupNewMetricAdded() { 152 switch (mButtonAction.getSwitchType()) { 153 case BrowserAction.TYPE_SHOW_DIALOG_EXPORT : 154 { 155 setEnabled(true); 156 break; 157 } 158 } 159 160 } 161 162 private void tellButtonAction() { 163 informBrowserActionListeners(mButtonAction); 164 } 165 166 public static final String PARAM_ICON_FILENAME = "icon file", 167 PARAM_TOOL_TIP = "tooltip", 168 PARAM_TEXT = "text", 169 PARAM_ACTION = "button action"; 170 private HashSet mBrowserActionListeners = new HashSet(); 171 private BrowserAction mButtonAction; 172 protected GuiController mControl; 173 }

This page was automatically generated by Maven