001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.swing;
019:
020: import java.awt.Component;
021: import java.awt.Container;
022: import java.awt.Graphics;
023: import java.awt.Rectangle;
024: import javax.accessibility.Accessible;
025: import javax.accessibility.AccessibleContext;
026: import javax.accessibility.AccessibleRole;
027:
028: /**
029: * <p>
030: * <i>CellRendererPane</i>
031: * </p>
032: * <h3>Implementation Notes:</h3>
033: * <ul>
034: * <li>The <code>serialVersionUID</code> fields are explicitly declared as a performance
035: * optimization, not as a guarantee of serialization compatibility.</li>
036: * </ul>
037: */
038: public class CellRendererPane extends Container implements Accessible {
039: private static final long serialVersionUID = -7642183829532984273L;
040:
041: protected AccessibleContext accessibleContext;
042:
043: protected class AccessibleCellRendererPane extends
044: AccessibleAWTContainer {
045: private static final long serialVersionUID = 1L;
046:
047: @Override
048: public AccessibleRole getAccessibleRole() {
049: return AccessibleRole.PANEL;
050: }
051: }
052:
053: @Override
054: public AccessibleContext getAccessibleContext() {
055: if (accessibleContext == null) {
056: accessibleContext = new AccessibleCellRendererPane();
057: }
058: return accessibleContext;
059: }
060:
061: @Override
062: public void invalidate() {
063: }
064:
065: @Override
066: public void paint(Graphics g) {
067: }
068:
069: @Override
070: public void update(Graphics g) {
071: }
072:
073: public void paintComponent(Graphics g, Component c, Container p,
074: int x, int y, int w, int h) {
075: paintComponent(g, c, p, x, y, w, h, false);
076: }
077:
078: public void paintComponent(Graphics g, Component c, Container p,
079: Rectangle r) {
080: paintComponent(g, c, p, r.x, r.y, r.width, r.height);
081: }
082:
083: public void paintComponent(Graphics g, Component c, Container p,
084: int x, int y, int w, int h, boolean shouldValidate) {
085: if (g == null || c == null)
086: return;
087: add(c);
088: c.setBounds(x, y, w, h);
089: if (shouldValidate) {
090: c.validate();
091: }
092: Graphics newGraphics = g.create(x, y, w, h);
093: if (c instanceof JComponent) {
094: JComponent jc = (JComponent) c;
095: boolean isDoubleBuffered = jc.isDoubleBuffered();
096: jc.setDoubleBuffered(false);
097: jc.paint(jc.getComponentGraphics(newGraphics));
098: jc.setDoubleBuffered(isDoubleBuffered);
099: } else {
100: c.paint(newGraphics);
101: }
102: newGraphics.dispose();
103: c.setBounds(-w, -h, 0, 0);
104: }
105:
106: @Override
107: protected void addImpl(Component c, Object constraints, int index) {
108: Component[] components = getComponents();
109: for (int i = 0; i < components.length; i++) {
110: if (c == components[i]) {
111: return;
112: }
113: }
114: super.addImpl(c, constraints, index);
115: }
116: }
|