All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.jbotsim.ui.painting.UIComponent Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
/*
 * 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:

*
    *
  1. wrap the system UI component (say View) in the {@link UIComponent} when a (re)draw is prompted * by the system;
  2. *
  3. pass this {@link UIComponent} to the object able draw on it;
  4. *
  5. 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.
  6. *
* *
 *  {@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; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy