1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.sdkuilib.internal.widgets; 18 19 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.graphics.Image; 22 import org.eclipse.swt.widgets.Composite; 23 24 /** 25 * A label that can display 2 images depending on its enabled/disabled state. 26 * This acts as a button by firing the {@link SWT#Selection} listener. 27 */ 28 public class ImgDisabledButton extends ToggleButton { 29 public ImgDisabledButton( 30 Composite parent, 31 int style, 32 Image imageEnabled, 33 Image imageDisabled, 34 String tooltipEnabled, 35 String tooltipDisabled) { 36 super(parent, 37 style, 38 imageEnabled, 39 imageDisabled, 40 tooltipEnabled, 41 tooltipDisabled); 42 } 43 44 @Override 45 public void setEnabled(boolean enabled) { 46 super.setEnabled(enabled); 47 updateImageAndTooltip(); 48 redraw(); 49 } 50 51 @Override 52 public void setState(int state) { 53 throw new UnsupportedOperationException(); // not available for this type of button 54 } 55 56 @Override 57 public int getState() { 58 return (isDisposed() || !isEnabled()) ? 1 : 0; 59 } 60 } 61