1 19 20 package com.sshtools.ui.awt; 21 22 import java.awt.AWTEvent ; 23 import java.awt.BorderLayout ; 24 import java.awt.Color ; 25 import java.awt.Dimension ; 26 import java.awt.Font ; 27 import java.awt.Image ; 28 import java.awt.Label ; 29 30 35 public class ImageLabel 36 extends BevelPanel { 37 38 private ImageCanvas imageCanvas; 39 private Label textLabel; 40 41 44 public ImageLabel() { 45 this(null, null); 46 } 47 48 53 public ImageLabel(Image image) { 54 this(null, image); 55 } 56 57 62 public ImageLabel(String text) { 63 this(text, null); 64 } 65 66 72 public ImageLabel(String text, Image image) { 73 super(NONE, new BorderLayout (2, 0)); 74 imageCanvas = new ImageCanvas(); 75 textLabel = new Label () { 76 public Dimension getMinimumSize() { 77 return getPreferredSize(); 78 } 79 80 public void processEvent(AWTEvent evt) { 81 ImageLabel.this.dispatchEvent(evt); 82 } 83 }; 84 add(imageCanvas, BorderLayout.WEST); 85 add(textLabel, BorderLayout.CENTER); 86 setText(text); 87 setImage(image); 88 } 89 90 95 public void setImage(Image image) { 96 imageCanvas.setImage(image); 97 imageCanvas.setVisible(image != null); 98 } 99 100 105 public Image getImage() { 106 return imageCanvas.getImage(); 107 } 108 109 114 public void setText(String text) { 115 textLabel.setText(text); 116 textLabel.setVisible(text != null); 117 } 118 119 124 public void setFont(Font font) { 125 super.setFont(font); 126 textLabel.setFont(font); 127 } 128 129 134 public void setForeground(Color foreground) { 135 super.setForeground(foreground); 136 textLabel.setForeground(foreground); 137 } 138 } 139 | Popular Tags |