001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.common.ui;
027:
028: import java.awt.Color;
029: import java.awt.Dimension;
030: import java.awt.Graphics;
031: import java.awt.Insets;
032:
033: import javax.swing.JPanel;
034:
035: /**
036: *
037: *
038: * @author $author$
039: * @version $Revision: 1.17 $
040: */
041: public class ImagePanel extends JPanel {
042: private ResourceIcon icon;
043: private boolean alignBottomRight = false;
044:
045: /**
046: * Creates a new ImagePanel object.
047: *
048: * @param imageName
049: */
050: public ImagePanel(String imageName) {
051: icon = new ResourceIcon(imageName);
052: }
053:
054: /**
055: * Creates a new ImagePanel object.
056: *
057: * @param icon
058: * @param bottom
059: */
060: public ImagePanel(ResourceIcon icon, int bottom) {
061: this .icon = icon;
062: alignBottomRight = true;
063: }
064:
065: /**
066: * Creates a new ImagePanel object.
067: *
068: * @param imageName
069: * @param bottom
070: */
071: public ImagePanel(String imageName, int bottom) {
072: icon = new ResourceIcon(imageName);
073: alignBottomRight = true;
074: }
075:
076: /**
077: * Creates a new ImagePanel object.
078: */
079: public ImagePanel() {
080: try {
081: jbInit();
082: } catch (Exception e) {
083: e.printStackTrace();
084: }
085: }
086:
087: /**
088: *
089: *
090: * @return
091: */
092: public Dimension getPreferedSize() {
093: Insets insets = getInsets();
094:
095: return new Dimension(icon.getIconWidth() + insets.left
096: + insets.right, icon.getIconHeight() + insets.top
097: + insets.bottom);
098: }
099:
100: /**
101: *
102: *
103: * @param g
104: */
105: public void paintComponent(Graphics g) {
106: super .paintComponent(g);
107:
108: if (icon != null) {
109: Insets insets = getInsets();
110:
111: if (!alignBottomRight) {
112: // Paint the image at the top left hand side of the panel
113: icon.paintIcon(this , g, insets.left, insets.top);
114: } else {
115: // Paint the image at the bottom right hand side of the panel
116: icon.paintIcon(this , g, (this .getWidth() - icon
117: .getIconWidth()), (this .getHeight() - icon
118: .getIconHeight()));
119: }
120: }
121: }
122:
123: private void jbInit() throws Exception {
124: this.setBackground(Color.white);
125: }
126: }
|