@Nullable public Image getImage(Class<?> type) { checkInitialized(); return imageRegistry.get(type.getName()); }
public void initialize(Device d) { flushCache(d); }
@Before public void setup() { rgbA = new RGB(255, 0, 0); rgbB = new RGB(0, 255, 0); schema1 = new UiSchema(false); schema1.add(A.class, rgbA); schema1.add(B.class, rgbB); display = new Display(); schema1.initialize(display); schema2 = new UiSchema(false); }
final int radius = 4; final int outerRadius = 10; uiSchema.initialize(gc.getDevice()); gc.setBackground(uiSchema.getDefaultColor()); final Point p = entry.getValue(); final Class<?> type = entry.getKey().getClass(); final Image image = uiSchema.getImage(type); final int x = vp.toCoordX(p.x) - radius; final int y = vp.toCoordY(p.y) - radius; gc.drawImage(image, offsetX, offsetY); } else { final Color color = uiSchema.getColor(type); if (color == null) { continue;
@Override public void renderDynamic(GC gc, ViewPort vp, long time) { uiSchema.initialize(gc.getDevice()); final Collection<Parcel> parcels = pdpModel.getParcels( ParcelState.values()); final Image image = uiSchema.getImage(Box.class); checkState(image != null); synchronized (pdpModel) { final Set<Vehicle> vehicles = pdpModel.getVehicles(); final Map<Parcel, Vehicle> mapping = new LinkedHashMap<>(); for (final Vehicle v : vehicles) { for (final Parcel p : pdpModel.getContents(v)) { mapping.put(p, v); } if (pdpModel.getVehicleState(v) != VehicleState.IDLE) { final PDPModel.VehicleParcelActionInfo vpai = pdpModel .getVehicleActionInfo(v); mapping.put(vpai.getParcel(), vpai.getVehicle()); } } for (final Parcel p : parcels) { drawBox(p, gc, vp, time, image, mapping); } } }
/** * Looks up the {@link Color} which is associated to the specified type. Note * that the {@link Color} instance is derived from the {@link RGB} instance * which was added through {@link #add(Class, RGB)}. If there is no * {@link Color} associated to the type, its superclass is checked instead. * This is continued recursively until a {@link Color} is found. If no * {@link Color} is found, either the default color is returned or * <code>null</code>. * @param type The {@link Class} which is checked for a {@link Color} * association. * @return A {@link Color} instance if it exists, or <code>null</code> * otherwise. * @see #add(Class, RGB) */ @Nullable public Color getColor(Class<?> type) { checkInitialized(); final Color color = colorRegistry.get(type.getName()); if (color == null && type.getSuperclass() != null) { final Color tmp = getColor(type.getSuperclass()); if (tmp != null) { colorRegistry.put(type.getName(), tmp); return tmp; } } if (color == null && useDefault) { return colorRegistry.get(DEFAULT); } return color; }
@Test(expected = IllegalStateException.class) public void getColorFail() { schema2.getColor(A.class); }
@Override public void renderDynamic(GC gc, ViewPort vp, long time) { uiSchema.initialize(gc.getDevice()); final Collection<Parcel> parcels = pdpModel.getParcels( ParcelState.values()); final Image image = uiSchema.getImage(Box.class); checkState(image != null); synchronized (pdpModel) { final Set<Vehicle> vehicles = pdpModel.getVehicles(); final Map<Parcel, Vehicle> mapping = new LinkedHashMap<>(); for (final Vehicle v : vehicles) { for (final Parcel p : pdpModel.getContents(v)) { mapping.put(p, v); } if (pdpModel.getVehicleState(v) != VehicleState.IDLE) { final PDPModel.VehicleParcelActionInfo vpai = pdpModel .getVehicleActionInfo(v); mapping.put(vpai.getParcel(), vpai.getVehicle()); } } for (final Parcel p : parcels) { drawBox(p, gc, vp, time, image, mapping); } } }
@Test public void getColor() { assertEquals(rgbA, schema1.getColor(A.class).getRGB()); assertNull(schema1.colorRegistry.get(AA.class.getName())); assertEquals(rgbA, schema1.getColor(AA.class).getRGB()); assertEquals(rgbA, schema1.colorRegistry.get(AA.class.getName()).getRGB()); assertEquals(rgbB, schema1.getColor(B.class).getRGB()); assertNull(schema1.colorRegistry.get(BB.class.getName())); assertNull(schema1.colorRegistry.get(BBB.class.getName())); assertEquals(rgbB, schema1.getColor(BBB.class).getRGB()); assertEquals(rgbB, schema1.colorRegistry.get(BBB.class.getName()).getRGB()); assertEquals(rgbB, schema1.colorRegistry.get(BB.class.getName()).getRGB()); }
@Override public RoadUserRenderer build(DependencyProvider dependencyProvider) { final RoadModel rm = dependencyProvider.get(RoadModel.class); final UiSchema uis = new UiSchema(colorMap().isEmpty() && imageMap().isEmpty()); for (final Entry<Class<?>, RGB> entry : colorMap().entrySet()) { uis.add(entry.getKey(), entry.getValue()); } for (final Entry<Class<?>, String> entry : imageMap().entrySet()) { uis.add(entry.getKey(), entry.getValue()); } return new RoadUserRenderer(rm, uis, useEncirclement(), useTextLabel()); }