use of org.apache.pivot.wtk.Point in project pivot by apache.
the class TerraListButtonSkin method paint.
@Override
public void paint(Graphics2D graphics) {
ListButton listButton = (ListButton) getComponent();
int width = getWidth();
int height = getHeight();
Color colorLocal = null;
Color backgroundColorLocal = null;
Color bevelColorLocal = null;
Color borderColorLocal = null;
if (listButton.isEnabled()) {
colorLocal = this.color;
backgroundColorLocal = this.backgroundColor;
bevelColorLocal = (pressed || (listViewPopup.isOpen() && !listViewPopup.isClosing())) ? pressedBevelColor : this.bevelColor;
borderColorLocal = this.borderColor;
} else {
colorLocal = disabledColor;
backgroundColorLocal = disabledBackgroundColor;
bevelColorLocal = disabledBevelColor;
borderColorLocal = disabledBorderColor;
}
graphics.setStroke(new BasicStroke());
// 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 = listButton.getDataRenderer();
dataRenderer.render(listButton.getButtonData(), listButton, false);
dataRenderer.setSize(Math.max(contentBounds.width - (padding.getWidth() + 2) + 1, 0), Math.max(contentBounds.height - (padding.getHeight() + 2) + 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);
// Paint the border
if (!themeIsFlat()) {
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));
graphics.draw(new Line2D.Double(contentBounds.x + contentBounds.width, 0.5, contentBounds.x + contentBounds.width, contentBounds.height));
}
// Paint the focus state
if (listButton.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(borderColorLocal);
graphics.draw(new RoundRectangle2D.Double(2.5, 2.5, Math.max(contentBounds.width - 4, 0), Math.max(contentBounds.height - 4, 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(colorLocal);
Bounds triggerBounds = getTriggerBounds();
int tx = triggerBounds.x + Math.round((triggerBounds.width - triggerIconShape.getBounds().width) / 2f) - 1;
int ty = triggerBounds.y + Math.round((triggerBounds.height - triggerIconShape.getBounds().height) / 2f) - 1;
triggerGraphics.translate(tx, ty);
triggerGraphics.draw(triggerIconShape);
triggerGraphics.fill(triggerIconShape);
triggerGraphics.dispose();
// Paint the trigger highlight
if (listButton.isRepeatable()) {
Point mouseLocation = listButton.getMouseLocation();
if (mouseLocation != null) {
graphics.setPaint(new Color(0, 0, 0, 0.25f));
if (triggerBounds.contains(mouseLocation)) {
graphics.clipRect(triggerBounds.x, triggerBounds.y, triggerBounds.width, height);
} else {
graphics.clipRect(0, 0, width - triggerBounds.width, height);
}
GraphicsUtilities.setAntialiasingOn(graphics);
graphics.fill(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
GraphicsUtilities.setAntialiasingOff(graphics);
}
}
}
use of org.apache.pivot.wtk.Point in project pivot by apache.
the class NativeDragDropTest method startup.
@Override
public void startup(final Display display, Map<String, String> properties) throws Exception {
final Label label = new Label("http://pivot.apache.org/");
label.getStyles().put(Style.font, new Font("Arial", Font.PLAIN, 24));
label.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
label.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
label.setDragSource(new DragSource() {
private LocalManifest content = null;
@Override
public boolean beginDrag(Component component, int x, int y) {
content = new LocalManifest();
content.putText(label.getText());
return true;
}
@Override
public void endDrag(Component component, DropAction dropAction) {
content = null;
}
@Override
public boolean isNative() {
return true;
}
@Override
public LocalManifest getContent() {
return content;
}
@Override
public Visual getRepresentation() {
return null;
}
@Override
public Point getOffset() {
return null;
}
@Override
public int getSupportedDropActions() {
return DropAction.COPY.getMask();
}
});
label.setDropTarget(new DropTarget() {
@Override
public DropAction dragEnter(Component component, Manifest dragContent, int supportedDropActions, DropAction userDropAction) {
DropAction dropAction = null;
if (dragContent.containsText()) {
frame.getStyles().put(Style.backgroundColor, "#ffcccc");
dropAction = DropAction.COPY;
}
return dropAction;
}
@Override
public void dragExit(Component component) {
frame.getStyles().put(Style.backgroundColor, "#ffffff");
}
@Override
public DropAction dragMove(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
return (dragContent.containsText() ? DropAction.COPY : null);
}
@Override
public DropAction userDropActionChange(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
return (dragContent.containsText() ? DropAction.COPY : null);
}
@Override
public DropAction drop(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
DropAction dropAction = null;
if (dragContent.containsText()) {
Label labelLocal = (Label) component;
try {
labelLocal.setText(dragContent.getText());
} catch (IOException exception) {
System.err.println(exception);
}
}
dragExit(component);
return dropAction;
}
});
frame = new Frame(label);
frame.open(display);
}
use of org.apache.pivot.wtk.Point in project pivot by apache.
the class ComponentSkin method tooltipTriggered.
@Override
public void tooltipTriggered(Component componentArgument, int x, int y) {
String tooltipText = component.getTooltipText();
if (tooltipText != null) {
Label tooltipLabel = new Label(tooltipText);
boolean tooltipWrapText = component.getTooltipWrapText();
tooltipLabel.getStyles().put(Style.wrapText, tooltipWrapText);
Tooltip tooltip = new Tooltip(tooltipLabel);
Display display = component.getDisplay();
Point location = component.mapPointToAncestor(display, x, y);
// Ensure that the tooltip stays on screen
int tooltipX = location.x + 16;
int tooltipY = location.y;
int tooltipWidth = tooltip.getPreferredWidth();
int tooltipHeight = tooltip.getPreferredHeight();
if (tooltipX + tooltipWidth > display.getWidth()) {
// the cursor
if (tooltipY > tooltipHeight) {
tooltipX = display.getWidth() - tooltipWidth;
} else {
tooltipX = location.x - tooltipWidth - 16;
}
if (tooltipX < 0) {
tooltipX = 0;
}
// these x adjustments
if (tooltipX < location.x && tooltipX + tooltipWidth > location.x) {
tooltipY -= tooltipHeight;
if (tooltipY < 0) {
tooltipY = 0;
}
}
}
if (tooltipY + tooltipHeight > display.getHeight()) {
tooltipY -= tooltipHeight;
}
tooltip.setLocation(tooltipX, tooltipY);
tooltip.open(component.getWindow());
}
}
use of org.apache.pivot.wtk.Point 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.Point 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);
}
Aggregations