001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package org.objectweb.salome_tmf.ihm;
025:
026: import java.awt.*;
027: import java.awt.event.*;
028: import java.net.*;
029:
030: import javax.swing.*;
031:
032: public class PanelAvecFond extends JPanel {
033: Image backGround = null;
034:
035: public PanelAvecFond(Image backGround) {
036: this .backGround = backGround;
037: setOpaque(false);
038: }
039:
040: public void paint(Graphics g) {
041: if (backGround != null)
042: g.drawImage(backGround, 0, 0, getSize().width,
043: getSize().height, this );
044: super .paint(g);
045: }
046:
047: public static void main(String[] args) {
048: JTextArea groupDescriptionArea = new JTextArea();
049: groupDescriptionArea.setPreferredSize(new Dimension(100, 50));
050:
051: JScrollPane groupDescriptionScrollPane = new JScrollPane(
052: groupDescriptionArea);
053:
054: groupDescriptionScrollPane.setBorder(BorderFactory
055: .createTitledBorder(BorderFactory
056: .createLineBorder(Color.BLACK), "Description"));
057: groupDescriptionScrollPane.setBounds(150, 150, 100, 100);
058: JFrame frm = new JFrame("test panel back ground");
059: frm.setBounds(100, 100, 500, 500);
060: frm.getContentPane().setLayout(new BorderLayout());
061: JPanel pnl = new PanelAvecFond(loadImages(frm,
062: ".//salome_intro.jpg"));
063: pnl.setLayout(null);//new GridLayout( 10, 10 ) );
064: JButton btn = new PanelAvecFond.ButtonAvecFond(loadImages(frm,
065: ".//icon31.jpg"));
066: btn.setForeground(Color.green);
067: btn.setText("TOTO");
068: pnl.add(btn);
069: pnl.add(groupDescriptionScrollPane);
070: btn.setBounds(0, 50, 100, 100);
071: frm.getContentPane().add(pnl, BorderLayout.CENTER);
072:
073: frm.setVisible(true);
074: frm.addWindowListener(new WindowAdapter() {
075: public void windowClosing(WindowEvent e) {
076: super .windowClosing(e);
077: System.exit(0);
078: }
079: });
080: }
081:
082: private static Image loadImages(JFrame frm, String imageFile) {
083: try {
084: MediaTracker mTrack = new MediaTracker(frm); // load les image avan de les afficher
085: Image image = frm.getToolkit().getImage(getURL(imageFile));
086: mTrack.addImage(image, 0);
087: mTrack.waitForAll();
088: return image;
089: } catch (Exception e) {
090: System.out.println(" getimages : " + e);
091: }
092: return null;
093: }
094:
095: public static URL getURL(String file) throws MalformedURLException {
096: URL documentBase = new URL("file:///"
097: + System.getProperty("user.dir") + "/");
098: return new URL(documentBase, file);
099: }
100:
101: public static class ButtonAvecFond extends JButton {
102: Image backGround = null;
103:
104: public ButtonAvecFond(Image backGround) {
105: this .backGround = backGround;
106: setOpaque(false);
107: }
108:
109: public void paint(Graphics g) {
110: if (backGround != null)
111: g.drawImage(backGround, 0, 0, getSize().width,
112: getSize().height, this );
113: // ButtonModel model = getModel();
114: // if ( !model.isArmed() )
115: super.paint(g);
116: }
117:
118: }
119: }
|