0N/A/*
2362N/A * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing;
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport java.io.*;
0N/Aimport java.beans.PropertyChangeListener;
0N/Aimport java.util.Locale;
0N/Aimport java.util.Vector;
0N/A
0N/Aimport javax.accessibility.*;
0N/A
0N/A/**
0N/A * This class is inserted in between cell renderers and the components that
0N/A * use them. It just exists to thwart the repaint() and invalidate() methods
0N/A * which would otherwise propagate up the tree when the renderer was configured.
0N/A * It's used by the implementations of JTable, JTree, and JList. For example,
0N/A * here's how CellRendererPane is used in the code the paints each row
0N/A * in a JList:
0N/A * <pre>
0N/A * cellRendererPane = new CellRendererPane();
0N/A * ...
0N/A * Component rendererComponent = renderer.getListCellRendererComponent();
0N/A * renderer.configureListCellRenderer(dataModel.getElementAt(row), row);
0N/A * cellRendererPane.paintComponent(g, rendererComponent, this, x, y, w, h);
0N/A * </pre>
0N/A * <p>
0N/A * A renderer component must override isShowing() and unconditionally return
0N/A * true to work correctly because the Swing paint does nothing for components
0N/A * with isShowing false.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @author Hans Muller
0N/A */
0N/Apublic class CellRendererPane extends Container implements Accessible
0N/A{
0N/A /**
0N/A * Construct a CellRendererPane object.
0N/A */
0N/A public CellRendererPane() {
0N/A super();
0N/A setLayout(null);
0N/A setVisible(false);
0N/A }
0N/A
0N/A /**
0N/A * Overridden to avoid propagating a invalidate up the tree when the
0N/A * cell renderer child is configured.
0N/A */
0N/A public void invalidate() { }
0N/A
0N/A
0N/A /**
0N/A * Shouldn't be called.
0N/A */
0N/A public void paint(Graphics g) { }
0N/A
0N/A
0N/A /**
0N/A * Shouldn't be called.
0N/A */
0N/A public void update(Graphics g) { }
0N/A
0N/A
0N/A /**
0N/A * If the specified component is already a child of this then we don't
0N/A * bother doing anything - stacking order doesn't matter for cell
0N/A * renderer components (CellRendererPane doesn't paint anyway).<
0N/A */
0N/A protected void addImpl(Component x, Object constraints, int index) {
0N/A if (x.getParent() == this) {
0N/A return;
0N/A }
0N/A else {
0N/A super.addImpl(x, constraints, index);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Paint a cell renderer component c on graphics object g. Before the component
0N/A * is drawn it's reparented to this (if that's necessary), it's bounds
0N/A * are set to w,h and the graphics object is (effectively) translated to x,y.
0N/A * If it's a JComponent, double buffering is temporarily turned off. After
0N/A * the component is painted it's bounds are reset to -w, -h, 0, 0 so that, if
0N/A * it's the last renderer component painted, it will not start consuming input.
0N/A * The Container p is the component we're actually drawing on, typically it's
0N/A * equal to this.getParent(). If shouldValidate is true the component c will be
0N/A * validated before painted.
0N/A */
0N/A public void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h, boolean shouldValidate) {
0N/A if (c == null) {
0N/A if (p != null) {
0N/A Color oldColor = g.getColor();
0N/A g.setColor(p.getBackground());
0N/A g.fillRect(x, y, w, h);
0N/A g.setColor(oldColor);
0N/A }
0N/A return;
0N/A }
0N/A
0N/A if (c.getParent() != this) {
0N/A this.add(c);
0N/A }
0N/A
0N/A c.setBounds(x, y, w, h);
0N/A
0N/A if(shouldValidate) {
0N/A c.validate();
0N/A }
0N/A
0N/A boolean wasDoubleBuffered = false;
0N/A if ((c instanceof JComponent) && ((JComponent)c).isDoubleBuffered()) {
0N/A wasDoubleBuffered = true;
0N/A ((JComponent)c).setDoubleBuffered(false);
0N/A }
0N/A
0N/A Graphics cg = g.create(x, y, w, h);
0N/A try {
0N/A c.paint(cg);
0N/A }
0N/A finally {
0N/A cg.dispose();
0N/A }
0N/A
0N/A if (wasDoubleBuffered && (c instanceof JComponent)) {
0N/A ((JComponent)c).setDoubleBuffered(true);
0N/A }
0N/A
0N/A c.setBounds(-w, -h, 0, 0);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Calls this.paintComponent(g, c, p, x, y, w, h, false).
0N/A */
0N/A public void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h) {
0N/A paintComponent(g, c, p, x, y, w, h, false);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Calls this.paintComponent() with the rectangles x,y,width,height fields.
0N/A */
0N/A public void paintComponent(Graphics g, Component c, Container p, Rectangle r) {
0N/A paintComponent(g, c, p, r.x, r.y, r.width, r.height);
0N/A }
0N/A
0N/A
0N/A private void writeObject(ObjectOutputStream s) throws IOException {
0N/A removeAll();
0N/A s.defaultWriteObject();
0N/A }
0N/A
0N/A
0N/A/////////////////
0N/A// Accessibility support
0N/A////////////////
0N/A
0N/A protected AccessibleContext accessibleContext = null;
0N/A
0N/A /**
0N/A * Gets the AccessibleContext associated with this CellRendererPane.
0N/A * For CellRendererPanes, the AccessibleContext takes the form of an
0N/A * AccessibleCellRendererPane.
0N/A * A new AccessibleCellRendererPane instance is created if necessary.
0N/A *
0N/A * @return an AccessibleCellRendererPane that serves as the
0N/A * AccessibleContext of this CellRendererPane
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A if (accessibleContext == null) {
0N/A accessibleContext = new AccessibleCellRendererPane();
0N/A }
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * This class implements accessibility support for the
0N/A * <code>CellRendererPane</code> class.
0N/A */
0N/A protected class AccessibleCellRendererPane extends AccessibleAWTContainer {
0N/A // AccessibleContext methods
0N/A //
0N/A /**
0N/A * Get the role of this object.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of the
0N/A * object
0N/A * @see AccessibleRole
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.PANEL;
0N/A }
0N/A } // inner class AccessibleCellRendererPane
0N/A}