57 lines
2.0 KiB
Java
57 lines
2.0 KiB
Java
package ProjectElectricLocomotive.src.CollectionGenericObjects;
|
|
|
|
import ProjectElectricLocomotive.src.Drawnings.DrawingLocomotive;
|
|
|
|
import java.awt.*;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.AbstractMap;
|
|
|
|
public class LocomotiveDepotService extends AbstractCompany
|
|
{
|
|
private List<AbstractMap.SimpleEntry<Integer, Integer>> locCoord = new ArrayList<>();
|
|
private int countInRow;
|
|
|
|
public LocomotiveDepotService(int picWidth, int picHeight, ICollectionGenericObjects<DrawingLocomotive> collection)
|
|
{
|
|
super(picWidth, picHeight, collection);
|
|
}
|
|
@Override
|
|
protected void DrawBackground(Graphics g)
|
|
{
|
|
Color brown = new Color(52, 22, 22);
|
|
g.setColor(brown);
|
|
int x = 1, y = 0;
|
|
while (y + _placeSizeHeight <= _pictureHeight) {
|
|
int count = 0;
|
|
while (x + _placeSizeWidth <= _pictureWidth) {
|
|
count++;
|
|
g.drawLine(x, y, x + _placeSizeWidth, y);
|
|
g.drawLine(x, y, x, y + _placeSizeHeight);
|
|
g.drawLine(x, y + _placeSizeHeight, x + _placeSizeWidth, y + _placeSizeHeight);
|
|
locCoord.add(new AbstractMap.SimpleEntry<>(x, y));
|
|
x += _placeSizeWidth + 2;
|
|
}
|
|
countInRow = count;
|
|
x = 1;
|
|
y += _placeSizeHeight + 5;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void SetObjectsPosition() {
|
|
if (locCoord == null || _collection == null) return;
|
|
int row = countInRow, col = 1;
|
|
for (int i = 0; i < _collection.getCount(); i++, col++) {
|
|
if (_collection.get(i) == null) continue;
|
|
_collection.get(i).SetPictureSize(_pictureWidth, _pictureHeight);
|
|
_collection.get(i).SetPosition(locCoord.get((row - 1) * countInRow + (col - 1)).getKey() + 5, locCoord.get((row - 1) * countInRow + (col - 1)).getValue() + 5);
|
|
if (col == countInRow) {
|
|
col = 0;
|
|
row--;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|