@Override public boolean addComponent(int x, int y, Component component) { Position in = Position.of(x, y); Position old = this.components.put(component, in); if (old != null) { if (!Objects.equals(old, in)) { this.components.put(component, old); } getHolder().getLogger().info("Duplicate component registry in " + getDefaultName()); return false; } for (int j = y; j < y + component.getHeight(); j++) { for (int i = x; i < x + component.getWidth(); i++) { if (bySlot[j][i] != null) { getHolder() .getLogger() .info("Component cannot be registered due to overlap" + getDefaultName()); this.components.remove(component); return false; // Nope } } } fill(component, null); component.setParent(this); return true; }
private void fill(Component component, Position where) { Component what = component; if (where == null) { where = this.components.get(component); } else { what = null; } int x = where.x; int y = where.y; for (int j = y; j < y + component.getHeight(); j++) { for (int i = x; i < x + component.getWidth(); i++) { this.bySlot[j][i] = what; } } }