4 * Created on 09 October 2001, 05:06
\r
5 * $Header: /VisTA/CID/VistaFilter.java 2 31/10/01 5:12 Tj $
\r
7 * $History: VistaFilter.java $
\r
9 * ***************** Version 2 *****************
\r
10 * User: Tj Date: 31/10/01 Time: 5:12
\r
11 * Updated in $/VisTA/CID
\r
14 package org.tjworld.vista.cid;
\r
16 import javax.swing.*;
\r
17 import javax.swing.event.MouseInputAdapter;
\r
19 import java.awt.event.*;
\r
22 * Transparent filter that can be attached to a container. Usually placed closest
\r
23 * to the User so that other visual components appear behind it.
\r
26 * @version 1.1 20 Oct 2001
\r
28 public class VistaFilter extends javax.swing.JComponent {
\r
29 protected AlphaComposite ac;
\r
30 protected boolean ignoreEvents = false;
\r
32 /** Creates new VistaFilter */
\r
33 public VistaFilter() {
\r
34 this(0.5f); // default; alpha channel with 50% transparency
\r
37 /** Create a Vista Filter with transparency
\r
39 * @param alpha Transparency value; 0.0 == transparent, 1.0 == opaque
\r
41 public VistaFilter(float alpha) {
\r
42 // create an Alpha Channel
\r
43 ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
\r
44 ignoreEvents = true; // be 'invisible' to mouse-related events
\r
47 /** Pretend not to be covering any points
\r
48 * Allow Events to 'go through' filter to menus and other components without
\r
49 * complicated Event redispatching code by over-riding method
\r
51 * @param x The x co-ordinate
\r
52 * @param y The y co-ordinate
\r
53 * @see javax.swing.JComponent#contains
\r
55 public boolean contains(int x, int y) {
\r
56 return !ignoreEvents;
\r
58 /** Change the degree of transparency
\r
59 * @param alpha 0.0 to 1.0; full transparency to opaque
\r
61 public void setAlpha(float alpha) {
\r
62 ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
\r
66 /** Get the transparency setting
\r
67 * @return 0.0 to 1.0; full transparency to opaque
\r
69 public float getAlpha() {
\r
70 return ac.getAlpha();
\r
73 /** Paint the filter using the alpha-channel transparency and background colour
\r
75 * @param g Graphics object
\r
77 public void paint(Graphics g) {
\r
78 Graphics2D g2 = (Graphics2D) g; // convert to a 2D context
\r
79 g2.setComposite(ac); // set the transparency
\r
80 java.awt.Dimension dim = getSize(); // get the size
\r
81 g2.setColor(getBackground()); // use the background colour
\r
82 g2.fillRect(0,0,dim.width, dim.height); // paint the entire component
\r