Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ingmar.forsberg/lab4
  • Leon.Dammann/lab-4-inf-101
  • markus.trohjell/lab4
  • Viktor.Yordanov/lab4
  • Anders.Sortun/lab-4-v-23
  • amilia.storm/lab4
  • Ola.Kristoffersen/lab-4-2
  • Malvika.Singh/lab4
  • ii/inf101/23v/students/lab4
  • Henrik.Dalsto/lab4
  • Olav.Eikanger/lab4
  • shahnaz.mhethawy/lab4
  • ole-andreas.jensen/lab4
  • Qingle.Xu/lab4
  • Axel.Lundeby/lab4
  • Emma.Wergedahl/lab4
  • Kai.Waloen/lab4
  • R.Bortne/lab4
  • Thomas.T.Jensen/lab4
  • Halfdan.Hesthammer/lab-4-inf-101-v-23
  • Natanem.Hailu/lab4
  • Julie.Mikkelsen/lab-4-jm
  • Stine.Fanebust/lab4
  • Martin.Aasenhuus/lab4
  • Oscar.Stromsli/inf-101-lab-4
  • Jan.Brunner/lab-4-2023
  • Mathias.Handeland/lab4
  • Theodor.Nissen-Meyer/lab4
  • V.Larsen/lab4
  • Havard.Kolve/lab4
  • Dag.Himle/lab4
  • Benjamin.Fossbakken/lab4
  • Martin.Fausa/lab4
  • Fernando.Aguilar/lab4
  • Mattias.Nordahl/lab-4-v-23
  • Olav.Skogen/lab4
  • Marius.Jorgensen/lab4
  • David.Mo/lab4
  • Henrik.Tennebekk/lab4
  • Cecilie.Tveter/lab-4-inf-101-v-23
  • Lauritz.Angeltveit/lab4
  • Kristian.Roynestad/lab4
  • Julie.Hallan/lab4
  • Stian.Bekkeheien/lab-4-inf-101
  • Mattias.Nordahl/lab-4-v-23-1
  • Jacob.Grahm-Haga/lab4
  • Elias.Aronsen/lab-4-23-v
  • Henrik.Skjeret/lab-4-v-23
48 results
Show changes
package no.uib.inf101.colorgrid;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
public class ColorGrid {
// TODO: Implement this class
public class ColorGrid implements IColorGrid {
// Field variables
private int rows;
private int cols;
private List<ArrayList<Color>> grid;
// konstruktør med to parameter
public ColorGrid (int rows, int cols) {
>>>>>>> a0874c07fa65f11d31fa7236e60b23f914d4e05b
this.rows = rows;
this.cols = cols;
gridList = new ArrayList<ArrayList<Color>> ();
for (int i =0; i < rows; i++) {
ArrayList<Color> gridRow = new ArrayList<Color>();
for (int j=0; j < cols; j++) {
gridRow.add(null);
}
gridList.add(gridRow);
}
}
@Override
public int rows() {
return this.rows;
}
@Override
public int cols() {
return this.cols;
}
@Override
public Color get(CellPosition pos) {
int i = pos.row();
int j = pos.col();
return gridList.get(i).get(j); }
@Override
public void set(CellPosition pos, Color color) {
int i = pos.row();
int j = pos.col();
gridList.get(i).set(j, color);
}
@Override
public List<CellColor> getCells() {
List<CellColor> cellList = new ArrayList<CellColor>();
for (int i =0; i < gridList.size(); i++) {
for (int j=0; j < gridList.get(i).size(); j++) {
Color color = gridList.get(i).get(j);
CellPosition pos = new CellPosition(i, j);
CellColor cell = new CellColor(pos, color);
cellList.add(cell);
}
}
return cellList;
}
}
package no.uib.inf101.gridview;
import no.uib.inf101.colorgrid.CellPosition;
import no.uib.inf101.colorgrid.GridDimension;
import java.awt.geom.Rectangle2D;
public class CellPositionToPixelConverter {
// TODO: Implement this class
//koordinater i rutenettet til et rektangel
//med posisjon og størrelse beskrevet som piksler
Rectangle2D box;
GridDimension gd;
double margin;
public CellPositionToPixelConverter(Rectangle2D box, GridDimension gd, double margin) {
this.box = box;
this.gd = gd;
this.margin = margin;
}
public Rectangle2D getBoundsForCell(CellPosition cp){
double cellHeight = (box.getHeight() - ((gd.rows() + 1)*margin))/gd.rows();
double cellWidth = (box.getWidth() - ((gd.cols() + 1)*margin))/gd.cols();
double cellY = box.getY() + margin + (cellHeight + margin)*(cp.row());
double cellX = box.getX() + margin + (cellWidth + margin)*(cp.col());
Rectangle2D box = new Rectangle2D.Double(cellX, cellY, cellWidth, cellHeight);
return box;
}
}
package no.uib.inf101.gridview;
public class GridView {
// TODO: Implement this class
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;
import no.uib.inf101.colorgrid.CellColor;
import no.uib.inf101.colorgrid.CellColorCollection;
import no.uib.inf101.colorgrid.IColorGrid;
import java.awt.geom.Rectangle2D;
import java.util.List;
import java.awt.Color;
import no.uib.inf101.colorgrid.CellPosition;
public class GridView extends JPanel{
//Field variables
IColorGrid grid;
private static final double OUTERMARGIN = 30;
private static final Color MARGINCOLOR = Color.LIGHT_GRAY;
//Constructor
public GridView(IColorGrid grid) {
this.setPreferredSize(new Dimension(400,300));
this.grid = grid;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
drawGrid(g2);
}
private static void drawCells(Graphics2D g, CellColorCollection c, CellPositionToPixelConverter cp) {
List<CellColor> cellList = c.getCells();
for (CellColor cell : cellList) {
Color color = cell.color();
CellPosition pos = cell.cellPosition();
if (color==null) {
color = Color.DARK_GRAY;
}
Rectangle2D g2 = cp.getBoundsForCell(pos);
g.setColor(color);
g.fill(g2);
}
}
public void drawGrid(Graphics2D g){
double width = this.getWidth() - 2 * OUTERMARGIN;
double height = this.getHeight() - 2 * OUTERMARGIN;
Rectangle2D g2 = new Rectangle2D.Double(OUTERMARGIN, OUTERMARGIN, width, height);
g.setColor(MARGINCOLOR);
g.fill(g2);
CellPositionToPixelConverter cp = new CellPositionToPixelConverter(g2, grid, OUTERMARGIN);
drawCells(g, grid, cp);
}
}