mirror of
https://github.com/macocianradu/javaGUItoolkit.git
synced 2026-03-18 21:50:04 +00:00
added merge tu grid Panel
moved borders to external components added text field for one line with select
This commit is contained in:
@@ -6,46 +6,27 @@ import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import guiTree.Helper.Point2;
|
||||
|
||||
public class GridPanel extends Visual {
|
||||
private int columnCount;
|
||||
private int rowsCount;
|
||||
private Map<Integer, List<Visual>> childrenCols;
|
||||
private Map<Integer, List<Visual>> childrenRows;
|
||||
private Map<Integer, Integer> rowSizes;
|
||||
private Map<Integer, Integer> columnSizes;
|
||||
private Map<Visual, Point2<Integer>>children;
|
||||
private Map<Integer, Integer> fixedRows;
|
||||
private Map<Integer, Integer> fixedColumns;
|
||||
private List<Integer> rowSizes;
|
||||
private List<Integer> columnSizes;
|
||||
private Map<Point2<Integer>, Integer> rowPadding;
|
||||
private Map<Point2<Integer>, Integer> columnPadding;
|
||||
|
||||
public GridPanel(){
|
||||
super();
|
||||
childrenCols = new TreeMap<>();
|
||||
childrenRows = new TreeMap<>();
|
||||
rowsCount = 0;
|
||||
columnCount = 0;
|
||||
rowSizes = new HashMap<>();
|
||||
columnSizes = new HashMap<>();
|
||||
children = new HashMap<>();
|
||||
rowSizes = new ArrayList<>();
|
||||
columnSizes = new ArrayList<>();
|
||||
rowPadding = new HashMap<>();
|
||||
columnPadding = new HashMap<>();
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
rowsCount = 0;
|
||||
columnCount = 0;
|
||||
for(int i: childrenRows.keySet()) {
|
||||
if(childrenRows.get(i).size() != 0 && !rowSizes.containsKey(i)) {
|
||||
rowsCount++;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i: childrenCols.keySet()) {
|
||||
if(childrenCols.get(i).size() != 0 && !columnSizes.containsKey(i)) {
|
||||
columnCount++;
|
||||
}
|
||||
}
|
||||
|
||||
updateSize();
|
||||
fixedRows = new HashMap<>();
|
||||
fixedColumns = new HashMap<>();
|
||||
}
|
||||
|
||||
public void setSize() {
|
||||
@@ -53,71 +34,132 @@ public class GridPanel extends Visual {
|
||||
updateSize();
|
||||
}
|
||||
|
||||
public void updateSize() {
|
||||
if(rowsCount == 0 && columnCount == 0) {
|
||||
private void updateSize() {
|
||||
if(rowSizes.size() == 0 && columnSizes.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int setHeights = 0;
|
||||
int setWidths = 0;
|
||||
for(int i: rowSizes.keySet()) {
|
||||
setHeights += rowSizes.get(i);
|
||||
for(int i: fixedRows.keySet()) {
|
||||
rowSizes.set(i, fixedRows.get(i));
|
||||
setHeights += fixedRows.get(i);
|
||||
}
|
||||
for(int i: columnSizes.keySet()) {
|
||||
setWidths += columnSizes.get(i);
|
||||
for(int i: fixedColumns.keySet()) {
|
||||
columnSizes.set(i, fixedColumns.get(i));
|
||||
setWidths += fixedColumns.get(i);
|
||||
}
|
||||
|
||||
int height = (getHeight() - setHeights) / rowsCount;
|
||||
int width = (getWidth() - setWidths) / columnCount;
|
||||
int height = 0;
|
||||
int width = 0;
|
||||
if(fixedRows.size() != rowSizes.size()) {
|
||||
height = (getHeight() - setHeights) / (rowSizes.size() - fixedRows.size());
|
||||
}
|
||||
if(fixedColumns.size() != columnSizes.size()) {
|
||||
width = (getWidth() - setWidths) / (columnSizes.size() - fixedColumns.size());
|
||||
}
|
||||
|
||||
int locationY = 0;
|
||||
for(int i: childrenRows.keySet()) {
|
||||
int actualHeight = rowSizes.getOrDefault(i, height);
|
||||
for(Visual v: childrenRows.get(i)) {
|
||||
|
||||
v.setHeight(actualHeight);
|
||||
v.setLocationY(locationY);
|
||||
for(int i = 0; i < rowSizes.size(); i++) {
|
||||
if(!fixedRows.containsKey(i)) {
|
||||
rowSizes.set(i, height);
|
||||
}
|
||||
locationY += actualHeight;
|
||||
}
|
||||
|
||||
int locationX = 0;
|
||||
for(int i: childrenCols.keySet()) {
|
||||
int actualWidth = columnSizes.getOrDefault(i, width);
|
||||
for(Visual v: childrenCols.get(i)) {
|
||||
v.setWidth(actualWidth);
|
||||
v.setLocationX(locationX);
|
||||
for(int i = 0; i < columnSizes.size(); i++) {
|
||||
if(!fixedColumns.containsKey(i)) {
|
||||
columnSizes.set(i, width);
|
||||
}
|
||||
locationX += actualWidth;
|
||||
}
|
||||
|
||||
for(Visual v : children.keySet()) {
|
||||
Point2<Integer> cell = children.get(v);
|
||||
Point2<Integer> location = getGridLocation(cell);
|
||||
v.setLocation(location.x, location.y);
|
||||
int cellWidth = columnSizes.get(cell.x);
|
||||
int cellHeight = rowSizes.get(cell.y);
|
||||
int rowPad = rowPadding.getOrDefault(cell, 0);
|
||||
int colPad = columnPadding.getOrDefault(cell, 0);
|
||||
|
||||
for(int i = 0; i < colPad; i++) {
|
||||
cellWidth += columnSizes.get(cell.x + i + 1);
|
||||
}
|
||||
for(int i = 0; i < rowPad; i++) {
|
||||
cellHeight += rowSizes.get(cell.y + i + 1);
|
||||
}
|
||||
v.setSize(cellWidth, cellHeight);
|
||||
if(v.getWidth() != cellWidth) {
|
||||
v.setWidth(-1.0f);
|
||||
v.setWidth(cellWidth);
|
||||
}
|
||||
if(v.getHeight() != cellHeight) {
|
||||
v.setHeight(-1.0f);
|
||||
v.setHeight(cellHeight);
|
||||
}
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
public void setRowPadding(int row, int col, int padding) {
|
||||
rowPadding.put(new Point2<>(row, col), padding);
|
||||
rowPadding.put(new Point2<>(col, row), padding);
|
||||
for(int i = rowSizes.size(); i <= row + padding; i++) {
|
||||
rowSizes.add(0);
|
||||
}
|
||||
updateSize();
|
||||
}
|
||||
|
||||
public void setColumnPadding(int row, int col, int padding) {
|
||||
columnPadding.put(new Point2<>(row, col), padding);
|
||||
columnPadding.put(new Point2<>(col, row), padding);
|
||||
for(int i = columnSizes.size(); i <= col + padding; i++) {
|
||||
columnSizes.add(0);
|
||||
}
|
||||
updateSize();
|
||||
}
|
||||
|
||||
public void setRowSize(int row, int height) {
|
||||
rowSizes.put(row, height);
|
||||
refresh();
|
||||
fixedRows.put(row, height);
|
||||
updateSize();
|
||||
}
|
||||
|
||||
public void setColumnSize(int column, int width) {
|
||||
columnSizes.put(column, width);
|
||||
refresh();
|
||||
fixedColumns.put(column, width);
|
||||
updateSize();
|
||||
}
|
||||
|
||||
private Point2<Integer> getGridLocation(Point2<Integer> grid) {
|
||||
int locationX = 0;
|
||||
int locationY = 0;
|
||||
for(int i = 0; i < grid.x; i++) {
|
||||
locationX += columnSizes.get(i);
|
||||
}
|
||||
for(int i = 0; i < grid.y; i++) {
|
||||
locationY += rowSizes.get(i);
|
||||
}
|
||||
return new Point2<>(locationX, locationY);
|
||||
}
|
||||
|
||||
public void addVisual(Visual v) {
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
if(v.getAttribute("row") != null) {
|
||||
x = Integer.parseInt(v.getAttribute("row"));
|
||||
}
|
||||
if(v.getAttribute("column") != null) {
|
||||
y = Integer.parseInt(v.getAttribute("column"));
|
||||
}
|
||||
this.addVisual(v, x, y);
|
||||
}
|
||||
|
||||
public void addVisual(Visual v, int row, int col) {
|
||||
super.addVisual(v);
|
||||
childrenCols.computeIfAbsent(col, k -> new ArrayList<>());
|
||||
childrenRows.computeIfAbsent(row, k -> new ArrayList<>());
|
||||
childrenCols.get(col).add(v);
|
||||
childrenRows.get(row).add(v);
|
||||
children.put(v, new Point2<>(col, row));
|
||||
v.setLocation(-1.0f, -1.0f);
|
||||
refresh();
|
||||
for(int i = rowSizes.size(); i <= row; i++) {
|
||||
rowSizes.add(0);
|
||||
}
|
||||
for(int i = columnSizes.size(); i <= col; i++) {
|
||||
columnSizes.add(0);
|
||||
}
|
||||
updateSize();
|
||||
}
|
||||
|
||||
public void paint(BufferedImage imageBuffer) {
|
||||
|
||||
Reference in New Issue
Block a user