Skip to content

Commit

Permalink
Refactorization, first part
Browse files Browse the repository at this point in the history
  • Loading branch information
miachm committed Dec 15, 2019
1 parent 4044881 commit 2f6aeb1
Show file tree
Hide file tree
Showing 11 changed files with 360 additions and 140 deletions.
6 changes: 3 additions & 3 deletions src/com/github/miachm/sods/Cell.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.miachm.sods;

class Cell implements Cloneable {
class Cell extends TableItem {
private Object value;
private String formula;
private Style style = new Style();
Expand Down Expand Up @@ -128,7 +128,7 @@ public String toString() {
}

@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
public boolean isBlank() {
return group == null && this.equals(new Cell());
}
}
19 changes: 19 additions & 0 deletions src/com/github/miachm/sods/CellCollection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.github.miachm.sods;

class CellCollection extends TableCollection<Cell> {

public boolean isEmpty()
{
for (Cell cell : items.values()) {
if (!cell.isBlank())
return false;
}

return true;
}

@Override
protected Cell createItem() {
return new Cell();
}
}
23 changes: 23 additions & 0 deletions src/com/github/miachm/sods/Column.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.github.miachm.sods;

class Column extends TableItem {
private ColumnStyle style;

@Override
public Column clone() throws CloneNotSupportedException {
return (Column) super.clone();
}

@Override
public boolean isBlank() {
return style.isDefault();
}

public ColumnStyle getStyle() {
return style;
}

public void setStyle(ColumnStyle style) {
this.style = style;
}
}
28 changes: 28 additions & 0 deletions src/com/github/miachm/sods/ColumnCollection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.miachm.sods;

class ColumnCollection extends TableCollection<Column> {
private RowCollection rows;
public ColumnCollection(RowCollection rows)
{
this.rows = rows;
}

@Override
public void remove(int index, int howmany)
{
super.remove(index, howmany);
rows.deleteCells(index, howmany);
}

@Override
public void addItems(int index, int howmany)
{
super.addItems(index, howmany);
rows.addCells(index, howmany);
}

@Override
protected Column createItem() {
return new Column();
}
}
5 changes: 5 additions & 0 deletions src/com/github/miachm/sods/ColumnStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class ColumnStyle {
private static final double EQUIVALENCE_PT = 72.0 / 25.4;
private static final double EQUIVALENCE_PC = 6.0 / 25.4;

public boolean isDefault()
{
return this.equals(new ColumnStyle());
}

public Double getWidth() {
return width;
}
Expand Down
28 changes: 28 additions & 0 deletions src/com/github/miachm/sods/Row.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.miachm.sods;

class Row extends TableItem {
private RowStyle style;
private CellCollection cells = new CellCollection();

public RowStyle getStyle() {
return style;
}

public void setStyle(RowStyle style) {
this.style = style;
}

public CellCollection getCells() {
return cells;
}

@Override
public Row clone() throws CloneNotSupportedException {
return (Row) super.clone();
}

@Override
public boolean isBlank() {
return style.isDefault() && cells.isEmpty();
}
}
52 changes: 52 additions & 0 deletions src/com/github/miachm/sods/RowCollection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.github.miachm.sods;

import java.util.Map;

public class RowCollection extends TableCollection<Row> {
private int numColumns = 0;

@Override
public void addItems(int index, int howmany)
{
boolean isEmpty = items.isEmpty();
super.addItems(index, howmany);
if (isEmpty) {
addCells(0, numColumns);
numColumns /= 2; // Remove useless sum
}
}

public void deleteCells(int index, int howmany)
{
for (Map.Entry<Integer, Row> rowEntry : items.entrySet()) {
Row row = rowEntry.getValue();
CellCollection cells = row.getCells();
cells.remove(index, howmany);
}
}

public void addCells(int index, int howmany) {
for (Map.Entry<Integer, Row> rowEntry : items.entrySet()) {
Row row = rowEntry.getValue();
CellCollection cells = row.getCells();
cells.addItems(index, howmany);
}
numColumns += howmany;
}

@Override
public Row getItemForEdit(int index)
{
Row row = super.getItemForEdit(index);
CellCollection cells = row.getCells();
if (cells.isEmpty())
cells.addItems(0, numColumns);

return row;
}

@Override
protected Row createItem() {
return new Row();
}
}
4 changes: 4 additions & 0 deletions src/com/github/miachm/sods/RowStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ public String toString() {
", isHidden=" + isHidden +
'}';
}

public boolean isDefault() {
return this.equals(new RowStyle());
}
}

0 comments on commit 2f6aeb1

Please sign in to comment.