use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TerraCalendarButtonSkin method paint.
@Override
public void paint(Graphics2D graphics) {
CalendarButton calendarButton = (CalendarButton) getComponent();
int width = getWidth();
int height = getHeight();
Color backgroundColorLocal = null;
Color bevelColorLocal = null;
Color borderColorLocal = null;
if (calendarButton.isEnabled()) {
backgroundColorLocal = this.backgroundColor;
bevelColorLocal = (pressed || (calendarPopup.isOpen() && !calendarPopup.isClosing())) ? pressedBevelColor : this.bevelColor;
borderColorLocal = this.borderColor;
} else {
backgroundColorLocal = disabledBackgroundColor;
bevelColorLocal = disabledBevelColor;
borderColorLocal = disabledBorderColor;
}
// Paint the background
GraphicsUtilities.setAntialiasingOn(graphics);
if (!themeIsFlat()) {
graphics.setPaint(new GradientPaint(width / 2f, 0, bevelColorLocal, width / 2f, height / 2f, backgroundColorLocal));
} else {
graphics.setPaint(backgroundColorLocal);
}
graphics.fill(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
// Paint the content
GraphicsUtilities.setAntialiasingOff(graphics);
Bounds contentBounds = new Bounds(0, 0, Math.max(width - TRIGGER_WIDTH - 1, 0), Math.max(height - 1, 0));
Button.DataRenderer dataRenderer = calendarButton.getDataRenderer();
dataRenderer.render(calendarButton.getButtonData(), calendarButton, false);
dataRenderer.setSize(Math.max(contentBounds.width - (paddingWidth() - TRIGGER_WIDTH) + 1, 0), Math.max(contentBounds.height - paddingHeight() + 1, 0));
Graphics2D contentGraphics = (Graphics2D) graphics.create();
contentGraphics.translate(padding.left + 1, padding.top + 1);
contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
dataRenderer.paint(contentGraphics);
contentGraphics.dispose();
GraphicsUtilities.setAntialiasingOn(graphics);
if (!themeIsFlat()) {
// Paint the border
if (borderColorLocal != null) {
graphics.setPaint(borderColorLocal);
graphics.setStroke(new BasicStroke(1));
graphics.draw(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
}
}
// Paint the focus state
if (calendarButton.isFocused()) {
BasicStroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 0.0f, 2.0f }, 0.0f);
graphics.setStroke(dashStroke);
graphics.setColor(this.borderColor);
graphics.draw(new RoundRectangle2D.Double(2.5, 2.5, Math.max(width - 5, 0), Math.max(height - 5, 0), CORNER_RADIUS / 2, CORNER_RADIUS / 2));
}
GraphicsUtilities.setAntialiasingOff(graphics);
// Paint the trigger
GeneralPath triggerIconShape = new GeneralPath(Path2D.WIND_EVEN_ODD);
triggerIconShape.moveTo(0, 0);
triggerIconShape.lineTo(3, 3);
triggerIconShape.lineTo(6, 0);
triggerIconShape.closePath();
Graphics2D triggerGraphics = (Graphics2D) graphics.create();
triggerGraphics.setStroke(new BasicStroke(0));
triggerGraphics.setPaint(color);
Bounds triggerBounds = new Bounds(Math.max(width - (padding.right + TRIGGER_WIDTH), 0), 0, TRIGGER_WIDTH, Math.max(height - padding.getHeight(), 0));
int tx = triggerBounds.x + (triggerBounds.width - triggerIconShape.getBounds().width) / 2;
int ty = triggerBounds.y + (triggerBounds.height - triggerIconShape.getBounds().height) / 2;
triggerGraphics.translate(tx, ty);
triggerGraphics.draw(triggerIconShape);
triggerGraphics.fill(triggerIconShape);
triggerGraphics.dispose();
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class DropShadowDecorator method prepare.
@Override
public Graphics2D prepare(Component component, Graphics2D graphics) {
int width = component.getWidth();
int height = component.getHeight();
if (width > 0 && height > 0) {
if (shadowImage == null || shadowImage.getWidth() != width + 2 * blurRadius || shadowImage.getHeight() != height + 2 * blurRadius) {
// Recreate the shadow
BufferedImage rectangleImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D rectangleImageGraphics = rectangleImage.createGraphics();
rectangleImageGraphics.setColor(Color.BLACK);
rectangleImageGraphics.fillRect(0, 0, width, height);
rectangleImageGraphics.dispose();
shadowImage = createShadow(rectangleImage);
}
// Avoid drawing shadow if it will be covered by the component itself:
Bounds paintBounds = new Bounds(0, 0, width, height);
if (!component.isOpaque() || !paintBounds.contains(new Bounds(graphics.getClipBounds()))) {
graphics.drawImage(shadowImage, xOffset - blurRadius, yOffset - blurRadius, null);
}
} else {
shadowImage = null;
}
return graphics;
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class ListViewItemEditor method beginEdit.
@Override
public void beginEdit(ListView listViewArgument, int itemIndexArgument) {
this.listView = listViewArgument;
this.itemIndex = itemIndexArgument;
// Get the data being edited
List<?> listData = listViewArgument.getListData();
ListItem listItem = (ListItem) listData.get(itemIndexArgument);
String text = listItem.getText();
textInput.setText(text != null ? text : "");
textInput.selectAll();
// Get the item bounds
Bounds itemBounds = listViewArgument.getItemBounds(itemIndexArgument);
int itemIndent = listViewArgument.getItemIndent();
itemBounds = new Bounds(itemBounds.x + itemIndent, itemBounds.y, itemBounds.width - itemIndent, itemBounds.height);
// Render the item data
ListViewItemRenderer itemRenderer = (ListViewItemRenderer) listViewArgument.getItemRenderer();
itemRenderer.render(listItem, itemIndexArgument, listViewArgument, false, Button.State.UNSELECTED, false, false);
itemRenderer.setSize(itemBounds.width, itemBounds.height);
// Calculate the text bounds
Bounds textBounds = itemRenderer.getTextBounds();
// Calculate the bounds of what is being edited
Insets padding = (Insets) textInput.getStyles().get(Style.padding);
Bounds editBounds = new Bounds(itemBounds.x + textBounds.x - (padding.left + 1), itemBounds.y, itemBounds.width - textBounds.x + (padding.left + 1), itemBounds.height);
// Scroll to make the item as visible as possible
listViewArgument.scrollAreaToVisible(editBounds.x, editBounds.y, textBounds.width + padding.left + 1, editBounds.height);
// Constrain the bounds by what is visible through viewport ancestors
editBounds = listViewArgument.getVisibleArea(editBounds);
Point location = listViewArgument.mapPointToAncestor(listViewArgument.getDisplay(), editBounds.x, editBounds.y);
textInput.setPreferredWidth(editBounds.width);
setLocation(location.x, location.y + (editBounds.height - getPreferredHeight(-1)) / 2);
// Open the editor
open(listViewArgument.getWindow());
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TableViewRowEditor method beginEdit.
@Override
public void beginEdit(TableView tableViewArgument, int rowIndexArgument, int columnIndexArgument) {
this.tableView = tableViewArgument;
this.rowIndex = rowIndexArgument;
this.columnIndex = columnIndexArgument;
Container tableViewParent = tableViewArgument.getParent();
tableViewScrollPane = (tableViewParent instanceof ScrollPane) ? (ScrollPane) tableViewParent : null;
// Add/create the editor components
TableView.ColumnSequence tableViewColumns = tableViewArgument.getColumns();
TablePane.ColumnSequence tablePaneColumns = tablePane.getColumns();
for (int i = 0, n = tableViewColumns.getLength(); i < n; i++) {
// Add a new column to the table pane to match the table view column
TablePane.Column tablePaneColumn = new TablePane.Column();
tablePaneColumn.setWidth(tableViewArgument.getColumnBounds(i).width);
tablePaneColumns.add(tablePaneColumn);
// Determine which component to use as the editor for this column
String columnName = tableViewColumns.get(i).getName();
Component editorComponent = null;
if (columnName != null) {
editorComponent = cellEditors.get(columnName);
}
// Default to a read-only text input editor
if (editorComponent == null) {
TextInput editorTextInput = new TextInput();
editorTextInput.setTextKey(columnName);
editorTextInput.setEnabled(false);
editorTextInput.setTextBindType(BindType.LOAD);
editorComponent = editorTextInput;
}
// Add the editor component to the table pane
editorRow.add(editorComponent);
}
// Get the data being edited
List<?> tableData = tableViewArgument.getTableData();
Object tableRow = tableData.get(rowIndexArgument);
// Load the row data into the editor components
tablePane.load(tableRow);
// Get the row bounds
Bounds rowBounds = tableViewArgument.getRowBounds(rowIndexArgument);
rowImage.bounds = rowBounds;
// Scroll to make the row as visible as possible
tableViewArgument.scrollAreaToVisible(rowBounds.x, rowBounds.y, rowBounds.width, rowBounds.height);
// Constrain the bounds by what is visible through viewport ancestors
rowBounds = tableViewArgument.getVisibleArea(rowBounds);
Point location = tableViewArgument.mapPointToAncestor(tableViewArgument.getDisplay(), rowBounds.x, rowBounds.y);
// Set size and location and match scroll left
setPreferredWidth(rowBounds.width);
setLocation(location.x, location.y + (rowBounds.height - getPreferredHeight(-1)) / 2);
if (tableViewScrollPane != null) {
scrollPane.setScrollLeft(tableViewScrollPane.getScrollLeft());
}
// Open the editor
open(tableViewArgument.getWindow());
// Start the transition
cardPane.setSelectedIndex(EDITOR_CARD_INDEX);
}
use of org.apache.pivot.wtk.Bounds in project pivot by apache.
the class TagDecorator method getBounds.
@Override
public Bounds getBounds(Component component) {
Bounds localBounds;
if (tag == null) {
localBounds = null;
} else {
int x, y;
switch(horizontalAlignment) {
case LEFT:
{
x = xOffset;
break;
}
case RIGHT:
{
x = component.getWidth() - tag.getWidth() + xOffset;
break;
}
case CENTER:
{
x = (component.getWidth() - tag.getWidth()) / 2 + xOffset;
break;
}
default:
{
throw new UnsupportedOperationException();
}
}
switch(verticalAlignment) {
case TOP:
{
y = yOffset;
break;
}
case BOTTOM:
{
y = component.getHeight() - tag.getHeight() + yOffset;
break;
}
case CENTER:
{
y = (component.getHeight() - tag.getHeight()) / 2 + yOffset;
break;
}
default:
{
throw new UnsupportedOperationException();
}
}
localBounds = new Bounds(x, y, tag.getWidth(), tag.getHeight());
}
return localBounds;
}
Aggregations