use of org.apache.pivot.wtk.effects.Decorator in project pivot by apache.
the class Component method repaint.
/**
* Flags an area as needing to be repainted.
*
* @param xValue Starting x-coordinate of area to repaint.
* @param yValue Starting y-coordinate.
* @param width Width of area to repaint.
* @param height Height of area.
* @param immediate Whether repaint should be done immediately.
*/
public void repaint(int xValue, int yValue, int width, int height, boolean immediate) {
Container.assertEventDispatchThread(this);
if (parent != null) {
int xLocation = xValue;
int yLocation = yValue;
int widthValue = width;
int heightValue = height;
// Constrain the repaint area to this component's bounds
int top = yLocation;
int left = xLocation;
int bottom = top + heightValue - 1;
int right = left + widthValue - 1;
xLocation = Math.max(left, 0);
yLocation = Math.max(top, 0);
widthValue = Math.min(right, getWidth() - 1) - xLocation + 1;
heightValue = Math.min(bottom, getHeight() - 1) - yLocation + 1;
if (widthValue > 0 && heightValue > 0) {
// Notify the parent that the region needs updating
parent.repaint(xLocation + this.x, yLocation + this.y, widthValue, heightValue, immediate);
// Repaint any affected decorators
for (Decorator decorator : decorators) {
AffineTransform transform = decorator.getTransform(this);
if (!transform.isIdentity()) {
// Apply the decorator's transform to the repaint area
Rectangle area = new Rectangle(xLocation, yLocation, widthValue, heightValue);
Shape transformedShape = transform.createTransformedShape(area);
Bounds tranformedBounds = new Bounds(transformedShape.getBounds());
// Limit the transformed area to the decorator's bounds
tranformedBounds = tranformedBounds.intersect(decorator.getBounds(this));
// Add the bounded area to the repaint region
parent.repaint(tranformedBounds.x + this.x, tranformedBounds.y + this.y, tranformedBounds.width, tranformedBounds.height, immediate);
}
}
}
}
}
use of org.apache.pivot.wtk.effects.Decorator in project pivot by apache.
the class Container method paint0.
private void paint0(Graphics2D graphics) {
int count = getLength();
// Determine the paint bounds
Bounds paintBounds = new Bounds(0, 0, getWidth(), getHeight());
Rectangle clipBounds = graphics.getClipBounds();
if (clipBounds != null) {
paintBounds = paintBounds.intersect(clipBounds);
}
// Determine if we need to paint the container, or if it's completely
// obscured by a child component.
boolean paintContainer = true;
for (int i = 0; i < count; i++) {
Component component = get(i);
if (component.isVisible() && component.isOpaque() && component.getBounds().contains(paintBounds)) {
paintContainer = false;
break;
}
}
if (paintContainer) {
// Give the base method a copy of the graphics context; otherwise,
// container skins can change the graphics state before it is passed
// to subcomponents
Graphics2D containerGraphics = (Graphics2D) graphics.create();
super.paint(containerGraphics);
containerGraphics.dispose();
}
for (int i = 0; i < count; i++) {
Component component = get(i);
// Calculate the decorated bounds
Bounds decoratedBounds = component.getDecoratedBounds();
// current clip rectangle
if (component.isVisible() && decoratedBounds.intersects(paintBounds)) {
Bounds componentBounds = component.getBounds();
// Create a copy of the current graphics context and
// translate to the component's coordinate system
Graphics2D decoratedGraphics = (Graphics2D) graphics.create();
decoratedGraphics.translate(componentBounds.x, componentBounds.y);
// Prepare the decorators
DecoratorSequence decorators = component.getDecorators();
int n = decorators.getLength();
for (int j = n - 1; j >= 0; j--) {
Decorator decorator = decorators.get(j);
decoratedGraphics = decorator.prepare(component, decoratedGraphics);
}
// Paint the component
Graphics2D componentGraphics = (Graphics2D) decoratedGraphics.create();
componentGraphics.clipRect(0, 0, componentBounds.width, componentBounds.height);
component.paint(componentGraphics);
componentGraphics.dispose();
// Update the decorators
for (int j = 0; j < n; j++) {
Decorator decorator = decorators.get(j);
decorator.update();
}
}
}
}
use of org.apache.pivot.wtk.effects.Decorator in project pivot by apache.
the class BXMLExplorerDocument method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
treeView.setSelectMode(SelectMode.SINGLE);
treeView.setNodeRenderer(new MyTreeViewNodeRenderer());
treeView.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {
private final Decorator focusDecorator = new ShadeDecorator(0.2f, Color.RED);
private Component previousSelectedComponent = null;
@Override
public void selectedNodeChanged(TreeView treeViewArgument, Object previousSelectedNode) {
TreeNode node = (TreeNode) treeViewArgument.getSelectedNode();
if (previousSelectedComponent != null && previousSelectedComponent.getDecorators().indexOf(focusDecorator) > -1) {
previousSelectedComponent.getDecorators().remove(focusDecorator);
previousSelectedComponent = null;
}
if (node == null || !(node.getUserData() instanceof Component)) {
// TODO make the inspectors able to deal with things like
// TablePane.Row
componentPropertyInspector.setSource(null);
componentStyleInspector.setSource(null);
return;
}
Component selectedComp = (Component) node.getUserData();
if (selectedComp != null && selectedComp.getDecorators().indexOf(focusDecorator) == -1) {
selectedComp.getDecorators().add(focusDecorator);
previousSelectedComponent = selectedComp;
}
if (selectedComp instanceof FakeWindow) {
selectedComp = ((FakeWindow) selectedComp).window;
}
componentPropertyInspector.setSource(selectedComp);
componentStyleInspector.setSource(selectedComp);
}
@Override
public void selectedPathsChanged(TreeView treeViewArgument, Sequence<Path> previousSelectedPaths) {
// if the selection becomes empty, remove the decorator
if (treeViewArgument.getSelectedNode() == null && previousSelectedComponent != null && previousSelectedComponent.getDecorators().indexOf(focusDecorator) > -1) {
previousSelectedComponent.getDecorators().remove(focusDecorator);
}
}
});
playgroundCardPane.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {
@Override
public boolean mouseClick(Component component, Button button, int x, int y, int count) {
if (count == 1) {
Component comp = playgroundCardPane.getDescendantAt(x, y);
if (comp != null) {
TreeNode treeNode = componentToTreeNode.get(comp);
Path path = getPathForNode(treeView, treeNode);
if (path != null) {
treeView.setSelectedPath(path);
return true;
}
}
}
return false;
}
});
reloadButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(org.apache.pivot.wtk.Button button) {
playgroundCardPane.remove(loadedComponent);
widgetToID = null;
componentToTreeNode = null;
loadedComponent = null;
try {
load(file);
} catch (RuntimeException exception) {
exception.printStackTrace();
BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
} catch (IOException exception) {
exception.printStackTrace();
BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
} catch (SerializationException exception) {
exception.printStackTrace();
BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
} catch (ParserConfigurationException exception) {
exception.printStackTrace();
BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
} catch (SAXException exception) {
exception.printStackTrace();
BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
}
}
});
}
Aggregations