Search in sources :

Example 1 with Mode

use of org.pepsoft.worldpainter.MixedMaterial.Mode in project WorldPainter by Captain-Chaos.

the class MixedMaterialTableModel method setMode.

public void setMode(Mode mode) {
    if (mode != this.mode) {
        Mode previousMode = this.mode;
        this.mode = mode;
        if (mode == Mode.LAYERED) {
            for (int i = 0; i < rows.length; i++) {
                rows[i] = new Row(rows[i].material, Math.max(rows[i].occurrence / 100, 3), rows[i].scale);
            }
            COLUMN_NAMES[COLUMN_OCCURRENCE] = "Thickness";
        } else {
            if (previousMode == Mode.LAYERED) {
                int total = 0;
                for (Row row : rows) {
                    total += row.occurrence;
                }
                int remaining = 1000;
                for (int i = 0; i < rows.length; i++) {
                    if (i < rows.length - 1) {
                        int newOccurrence = rows[i].occurrence * 1000 / total;
                        rows[i] = new Row(rows[i].material, newOccurrence, rows[i].scale);
                        remaining -= newOccurrence;
                    } else {
                        rows[i] = new Row(rows[i].material, remaining, rows[i].scale);
                    }
                }
            }
            COLUMN_NAMES[COLUMN_OCCURRENCE] = "Occurrence (in ‰)";
        }
        TableModelEvent event = new TableModelEvent(this, TableModelEvent.HEADER_ROW);
        fireEvent(event);
    }
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) Mode(org.pepsoft.worldpainter.MixedMaterial.Mode) Row(org.pepsoft.worldpainter.MixedMaterial.Row)

Aggregations

TableModelEvent (javax.swing.event.TableModelEvent)1 Mode (org.pepsoft.worldpainter.MixedMaterial.Mode)1 Row (org.pepsoft.worldpainter.MixedMaterial.Row)1