228 if (b.isFocusPainted() && b.hasFocus()) {
229 // paint UI specific focus
230 paintFocus(g,b,viewRect,textRect,iconRect);
231 }
232 }
233
234 protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect){
235 AbstractButton b = (AbstractButton) c;
236 ButtonModel model = b.getModel();
237 Icon icon = b.getIcon();
238 Icon tmpIcon = null;
239
240 if(icon == null) {
241 return;
242 }
243
244 Icon selectedIcon = null;
245
246 /* the fallback icon should be based on the selected state */
247 if (model.isSelected()) {
248 selectedIcon = (Icon) b.getSelectedIcon();
249 if (selectedIcon != null) {
250 icon = selectedIcon;
251 }
252 }
253
254 if(!model.isEnabled()) {
255 if(model.isSelected()) {
256 tmpIcon = (Icon) b.getDisabledSelectedIcon();
257 if (tmpIcon == null) {
258 tmpIcon = selectedIcon;
259 }
260 }
261
262 if (tmpIcon == null) {
263 tmpIcon = (Icon) b.getDisabledIcon();
264 }
265 } else if(model.isPressed() && model.isArmed()) {
266 tmpIcon = (Icon) b.getPressedIcon();
267 if(tmpIcon != null) {
268 // revert back to 0 offset
269 clearTextShiftOffset();
270 }
271 } else if(b.isRolloverEnabled() && model.isRollover()) {
272 if(model.isSelected()) {
273 tmpIcon = (Icon) b.getRolloverSelectedIcon();
274 if (tmpIcon == null) {
275 tmpIcon = selectedIcon;
276 }
277 }
278
279 if (tmpIcon == null) {
280 tmpIcon = (Icon) b.getRolloverIcon();
281 }
282 }
283
284 if(tmpIcon != null) {
285 icon = tmpIcon;
286 }
287
288 if(model.isPressed() && model.isArmed()) {
289 icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(),
290 iconRect.y + getTextShiftOffset());
291 } else {
292 icon.paintIcon(c, g, iconRect.x, iconRect.y);
293 }
294
295 }
296
297 /**
298 * As of Java 2 platform v 1.4 this method should not be used or overriden.
299 * Use the paintText method which takes the AbstractButton argument.
300 */
442 textRect.x = textRect.y = textRect.width = textRect.height = 0;
443 iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
444
445 // layout the text and icon
446 return SwingUtilities.layoutCompoundLabel(
447 b, fm, b.getText(), b.getIcon(),
448 b.getVerticalAlignment(), b.getHorizontalAlignment(),
449 b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
450 viewRect, iconRect, textRect,
451 b.getText() == null ? 0 : b.getIconTextGap());
452 }
453
454 /**
455 * Returns the ButtonListener for the passed in Button, or null if one
456 * could not be found.
457 */
458 private BasicButtonListener getButtonListener(AbstractButton b) {
459 MouseMotionListener[] listeners = b.getMouseMotionListeners();
460
461 if (listeners != null) {
462 for (int counter = 0; counter < listeners.length; counter++) {
463 if (listeners[counter] instanceof BasicButtonListener) {
464 return (BasicButtonListener)listeners[counter];
465 }
466 }
467 }
468 return null;
469 }
470
471 }
|
228 if (b.isFocusPainted() && b.hasFocus()) {
229 // paint UI specific focus
230 paintFocus(g,b,viewRect,textRect,iconRect);
231 }
232 }
233
234 protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect){
235 AbstractButton b = (AbstractButton) c;
236 ButtonModel model = b.getModel();
237 Icon icon = b.getIcon();
238 Icon tmpIcon = null;
239
240 if(icon == null) {
241 return;
242 }
243
244 Icon selectedIcon = null;
245
246 /* the fallback icon should be based on the selected state */
247 if (model.isSelected()) {
248 selectedIcon = b.getSelectedIcon();
249 if (selectedIcon != null) {
250 icon = selectedIcon;
251 }
252 }
253
254 if(!model.isEnabled()) {
255 if(model.isSelected()) {
256 tmpIcon = b.getDisabledSelectedIcon();
257 if (tmpIcon == null) {
258 tmpIcon = selectedIcon;
259 }
260 }
261
262 if (tmpIcon == null) {
263 tmpIcon = b.getDisabledIcon();
264 }
265 } else if(model.isPressed() && model.isArmed()) {
266 tmpIcon = b.getPressedIcon();
267 if(tmpIcon != null) {
268 // revert back to 0 offset
269 clearTextShiftOffset();
270 }
271 } else if(b.isRolloverEnabled() && model.isRollover()) {
272 if(model.isSelected()) {
273 tmpIcon = b.getRolloverSelectedIcon();
274 if (tmpIcon == null) {
275 tmpIcon = selectedIcon;
276 }
277 }
278
279 if (tmpIcon == null) {
280 tmpIcon = b.getRolloverIcon();
281 }
282 }
283
284 if(tmpIcon != null) {
285 icon = tmpIcon;
286 }
287
288 if(model.isPressed() && model.isArmed()) {
289 icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(),
290 iconRect.y + getTextShiftOffset());
291 } else {
292 icon.paintIcon(c, g, iconRect.x, iconRect.y);
293 }
294
295 }
296
297 /**
298 * As of Java 2 platform v 1.4 this method should not be used or overriden.
299 * Use the paintText method which takes the AbstractButton argument.
300 */
442 textRect.x = textRect.y = textRect.width = textRect.height = 0;
443 iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
444
445 // layout the text and icon
446 return SwingUtilities.layoutCompoundLabel(
447 b, fm, b.getText(), b.getIcon(),
448 b.getVerticalAlignment(), b.getHorizontalAlignment(),
449 b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
450 viewRect, iconRect, textRect,
451 b.getText() == null ? 0 : b.getIconTextGap());
452 }
453
454 /**
455 * Returns the ButtonListener for the passed in Button, or null if one
456 * could not be found.
457 */
458 private BasicButtonListener getButtonListener(AbstractButton b) {
459 MouseMotionListener[] listeners = b.getMouseMotionListeners();
460
461 if (listeners != null) {
462 for (MouseMotionListener listener : listeners) {
463 if (listener instanceof BasicButtonListener) {
464 return (BasicButtonListener) listener;
465 }
466 }
467 }
468 return null;
469 }
470
471 }
|