io.jbotsim.ui.painting.UIComponent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbotsim-ui-common Show documentation
Show all versions of jbotsim-ui-common Show documentation
Platform-independent UI classes for JBotSim.
/*
* Copyright 2008 - 2019, Arnaud Casteigts and the JBotSim contributors
*
*
* This file is part of JBotSim.
*
* JBotSim is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JBotSim is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JBotSim. If not, see .
*
*/
package io.jbotsim.ui.painting;
/**
* The {@link UIComponent} contains a platform-dependent object to be used for displaying graphical elements.
*
* Its sole member is a simple {@link Object}. The typical usage is:
*
* - wrap the system UI component (say
View
) in the {@link UIComponent} when a (re)draw is prompted
* by the system;
* - pass this {@link UIComponent} to the object able draw on it;
* - in this object, cast the result of {@link #getComponent()} back to the system UI component type
* (
View
) and use it normally, see DefaultBackgroundPainter
example below.
*
*
*
* {@code
*
* public class DefaultBackgroundPainter implements BackgroundPainter {
*
* public void paintBackground(UIComponent uiComponent, Topology tp) {
* Graphics2D g2d = (Graphics2D) uiComponent.getComponent();
* g2d.setStroke(new BasicStroke(1));
* for (Node n : tp.getNodes()) {
* double sR = n.getSensingRange();
* if (sR > 0) {
* g2d.setColor(Color.gray);
* g2d.drawOval((int) n.getX() - (int) sR, (int) n.getY() - (int) sR, 2 * (int) sR, 2 * (int) sR);
* }
* }
* }
* }
* }
*
*/
public class UIComponent {
private Object component;
/**
* Creates a {@link UIComponent} by wrapping the provided system {@link Object}
* @param component the {@link Object} to be wrapped
*/
public UIComponent(Object component) {
this.component = component;
}
/**
* Gets the {@link Object} that has been provided upon creation.
*
* @return the component, as an {@link Object} to be cast
*/
public Object getComponent()
{
return component;
}
}