use of org.apache.pivot.wtk.media.Image in project pivot by apache.
the class LinkButtonTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
BoxPane boxPane = new BoxPane();
boxPane.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
boxPane.getStyles().put(Style.spacing, 8);
boxPane.getComponentMouseListeners().add(new ComponentMouseListener() {
@Override
public boolean mouseMove(Component component, int x, int y) {
System.out.println("BOX PANE " + x + ", " + y);
return false;
}
@Override
public void mouseOver(Component component) {
// empty block
}
@Override
public void mouseOut(Component component) {
// empty block
}
});
Image image = Image.load(getClass().getResource("go-home.png"));
LinkButton linkButton = null;
linkButton = new LinkButton("ABCDE");
boxPane.add(linkButton);
linkButton.getComponentMouseListeners().add(new ComponentMouseListener() {
@Override
public boolean mouseMove(Component component, int x, int y) {
return true;
}
@Override
public void mouseOver(Component component) {
// empty block
}
@Override
public void mouseOut(Component component) {
// empty block
}
});
linkButton = new LinkButton(image);
boxPane.add(linkButton);
linkButton = new LinkButton(new ButtonData(image, "12345"));
boxPane.add(linkButton);
window.setContent(boxPane);
window.open(display);
}
use of org.apache.pivot.wtk.media.Image in project pivot by apache.
the class TerraTableViewHeaderSkin method paint.
@Override
public void paint(Graphics2D graphics) {
int width = getWidth();
int height = getHeight();
TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
Color backgroundColorLocal = null;
Color bevelColorLocal = null;
Color borderColorLocal = null;
if (tableViewHeader.isEnabled()) {
backgroundColorLocal = this.backgroundColor;
bevelColorLocal = this.bevelColor;
borderColorLocal = this.borderColor;
} else {
backgroundColorLocal = disabledBackgroundColor;
bevelColorLocal = disabledBevelColor;
borderColorLocal = disabledBorderColor;
}
// Paint the background
if (!themeIsFlat()) {
graphics.setPaint(new GradientPaint(width / 2f, 0, bevelColorLocal, width / 2f, height, backgroundColorLocal));
} else {
graphics.setPaint(backgroundColorLocal);
}
graphics.fillRect(0, 0, width, height);
// Paint the border
if (!themeIsFlat()) {
graphics.setPaint(borderColorLocal);
graphics.setStroke(new BasicStroke(1));
graphics.draw(new Line2D.Double(0.5, height - 0.5, width - 0.5, height - 0.5));
}
// Paint the content
TableView tableView = tableViewHeader.getTableView();
if (tableView != null) {
TableView.ColumnSequence columns = tableView.getColumns();
int headerX = 0;
for (int columnIndex = 0, columnCount = columns.getLength(); columnIndex < columnCount; columnIndex++) {
TableView.Column column = columns.get(columnIndex);
int headerWidth = headerWidths.get(columnIndex).intValue();
// Paint the pressed bevel
if (columnIndex == pressedHeaderIndex) {
graphics.setPaint(new GradientPaint(width / 2f, 0, pressedBevelColor, width / 2f, height, backgroundColorLocal));
graphics.fillRect(headerX, 0, headerWidth, height - 1);
}
// Paint the header data
Object headerData = column.getHeaderData();
TableView.HeaderDataRenderer headerDataRenderer = column.getHeaderDataRenderer();
headerDataRenderer.render(headerData, columnIndex, tableViewHeader, column.getName(), false);
headerDataRenderer.setSize(headerWidth, height - 1);
Graphics2D rendererGraphics = (Graphics2D) graphics.create(headerX, 0, headerWidth, height - 1);
headerDataRenderer.paint(rendererGraphics);
rendererGraphics.dispose();
// Draw the sort image
Image sortImage = null;
String columnName = column.getName();
SortDirection sortDirection = tableView.getSort().get(columnName);
if (sortDirection != null) {
switch(sortDirection) {
case ASCENDING:
{
sortImage = sortAscendingImage;
break;
}
case DESCENDING:
{
sortImage = sortDescendingImage;
break;
}
default:
{
break;
}
}
}
if (sortImage != null) {
int sortImageMargin = sortImage.getWidth() + SORT_INDICATOR_PADDING * 2;
if (headerWidth >= headerDataRenderer.getPreferredWidth(-1) + sortImageMargin) {
Graphics2D sortImageGraphics = (Graphics2D) graphics.create();
sortImageGraphics.translate(headerX + headerWidth - sortImageMargin, (height - sortImage.getHeight()) / 2);
sortImage.paint(sortImageGraphics);
sortImageGraphics.dispose();
}
}
// Draw the divider
headerX += headerWidth;
if (columnIndex < columnCount - 1 || includeTrailingVerticalGridLine) {
if (!themeIsFlat()) {
graphics.setPaint(borderColorLocal);
graphics.draw(new Line2D.Double(headerX + 0.5, 0.5, headerX + 0.5, height - 0.5));
}
}
headerX++;
}
}
}
use of org.apache.pivot.wtk.media.Image in project pivot by apache.
the class TerraFormSkin method paint.
@Override
public void paint(Graphics2D graphics) {
super.paint(graphics);
GraphicsUtilities.setAntialiasingOn(graphics);
Form form = (Form) getComponent();
Form.SectionSequence sections = form.getSections();
for (int sectionIndex = 0, sectionCount = sections.getLength(); sectionIndex < sectionCount; sectionIndex++) {
Form.Section section = sections.get(sectionIndex);
for (int fieldIndex = 0, fieldCount = section.getLength(); fieldIndex < fieldCount; fieldIndex++) {
Component field = section.get(fieldIndex);
if (field.isVisible()) {
Form.Flag flag = Form.getFlag(field);
if (flag != null) {
if (showFlagIcons) {
MessageType messageType = flag.getMessageType();
Image flagIcon = null;
switch(messageType) {
case ERROR:
{
flagIcon = errorIcon;
break;
}
case WARNING:
{
flagIcon = warningIcon;
break;
}
case QUESTION:
{
flagIcon = questionIcon;
break;
}
case INFO:
{
flagIcon = infoIcon;
break;
}
default:
{
flagIcon = infoIcon;
break;
}
}
Label label = labels.get(sectionIndex).get(fieldIndex);
int flagIconX = label.getX() - (flagIcon.getWidth() + flagIconOffset);
int flagIconY = label.getY() + (label.getHeight() - flagIcon.getHeight()) / 2;
graphics.translate(flagIconX, flagIconY);
flagIcon.paint(graphics);
graphics.translate(-flagIconX, -flagIconY);
}
if (showFlagHighlight) {
MessageType messageType = flag.getMessageType();
Color highlightColor = null;
switch(messageType) {
case ERROR:
{
highlightColor = errorHighlightColor;
break;
}
case WARNING:
{
highlightColor = warningHighlightColor;
break;
}
case QUESTION:
{
highlightColor = questionHighlightColor;
break;
}
case INFO:
{
highlightColor = infoHighlightColor;
break;
}
default:
{
break;
}
}
Bounds fieldBounds = field.getBounds();
graphics.setColor(highlightColor);
graphics.setStroke(new BasicStroke(1));
graphics.drawRect(fieldBounds.x - FLAG_HIGHLIGHT_PADDING, fieldBounds.y - FLAG_HIGHLIGHT_PADDING, fieldBounds.width + FLAG_HIGHLIGHT_PADDING * 2 - 1, fieldBounds.height + FLAG_HIGHLIGHT_PADDING * 2 - 1);
}
}
}
}
}
}
use of org.apache.pivot.wtk.media.Image in project pivot by apache.
the class TagDecoratorTest method startup.
@Override
public void startup(final Display display, final Map<String, String> properties) throws Exception {
frame = new Frame();
frame.setTitle("Tag Decorator Test");
frame.setPreferredSize(480, 360);
Image tag = Image.load(getClass().getResource("go-home.png"));
frame.getDecorators().add(new TagDecorator(tag, HorizontalAlignment.RIGHT, VerticalAlignment.TOP, 10, -10));
frame.open(display);
}
use of org.apache.pivot.wtk.media.Image in project pivot by apache.
the class TableViewHeaderDataRenderer method render.
@Override
public void render(Object data, int columnIndex, TableViewHeader tableViewHeader, String columnName, boolean highlighted) {
Image icon = null;
String text = null;
if (data instanceof BaseContent) {
BaseContent baseContent = (BaseContent) data;
icon = baseContent.getIcon();
} else if (data instanceof Image) {
icon = (Image) data;
}
text = toString(data);
// Update the icon image view
imageView.setImage(icon);
if (icon == null) {
imageView.setVisible(false);
} else {
imageView.setVisible(true);
imageView.getStyles().put(Style.opacity, tableViewHeader.isEnabled() ? 1.0f : 0.5f);
}
// Show/hide the label
label.setText(text != null ? text : "");
if (text == null) {
label.setVisible(false);
} else {
label.setVisible(true);
// Update the label styles
Component.StyleDictionary labelStyles = label.getStyles();
Object labelFont = tableViewHeader.getStyles().get(Style.font);
if (labelFont instanceof Font) {
labelStyles.put(Style.font, labelFont);
}
Object color = null;
if (tableViewHeader.isEnabled()) {
color = tableViewHeader.getStyles().get(Style.color);
} else {
color = tableViewHeader.getStyles().get(Style.disabledColor);
}
if (color instanceof Color) {
labelStyles.put(Style.color, color);
}
}
}
Aggregations