Skip to content

Commit

Permalink
Column container's component order fix (closes #181, closes #183)
Browse files Browse the repository at this point in the history
  • Loading branch information
danchanka committed Oct 8, 2019
1 parent 51b200e commit c4d9905
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,46 +80,38 @@ public Dimension getMaxPreferredSize(Map<ClientContainer, ClientContainerView> c

@Override
public void addImpl(int index, ClientComponent child, JComponentPanel view) {
// view.setBorder(SwingUtils.randomBorder());

// panel.add(view, new ColumnsConstraints(child.getAlignment()), index);

int childCount = container.children.size();
int childIndex = container.children.indexOf(child);
int colIndex = childIndex % columnsCount;
int rowIndex = 0;

List<ClientComponent> columnChildren = columnsChildren[colIndex];
if (columnChildren.size() != 0) {
int currentRowIndex = 0;
ClientComponent currentRowChild = columnChildren.get(0);
for (int i = colIndex; i < childCount; i += columnsCount) {
ClientComponent existingChild = container.children.get(i);
if (existingChild == child) {
rowIndex = currentRowIndex;
break;
}
if (currentRowChild == existingChild) {
currentRowIndex++;
if (currentRowIndex == columnChildren.size()) {
rowIndex = currentRowIndex;
break;
}
currentRowChild = columnChildren.get(currentRowIndex);
}
}
}

columns[colIndex].add(view, new FlexConstraints(child.getAlignment(), 0), rowIndex);
columnChildren.add(rowIndex, child);
rebuildColumnCollections();
}

@Override
public void removeImpl(int index, ClientComponent child, JComponentPanel view) {
int childIndex = container.children.indexOf(child);
int colIndex = childIndex % columnsCount;
columnsChildren[colIndex].remove(child);
columns[colIndex].remove(view);
rebuildColumnCollections();
}

private void rebuildColumnCollections() {
clearColumnsCollections();

int cnt = 0;
for (ClientComponent child : container.children) {
int index = children.indexOf(child);
if (index >= 0) {
int colIndex = cnt % columnsCount;
int rowIndex = cnt / columnsCount;
columns[colIndex].add(childrenViews.get(index), new FlexConstraints(child.getAlignment(), 0), rowIndex);
columnsChildren[colIndex].add(rowIndex, child);
++cnt;
}
}
}

private void clearColumnsCollections() {
for (JPanel panel : columns) {
panel.removeAll();
}

for (List<ClientComponent> components : columnsChildren) {
components.clear();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,56 +66,45 @@ private double getColumnFlex(GContainer container) {

@Override
protected void addImpl(int index, GComponent child, Widget view) {
// panel.add(view, index, child.getFlexAlignment(false), child.getFlexFill(false));

int childCount = container.children.size();
int childIndex = container.children.indexOf(child);
int colIndex = childIndex % columnsCount;
int rowIndex = 0;

List<GComponent> columnChildren = columnsChildren[colIndex];
if (columnChildren.size() != 0) {
int currentRowIndex = 0;
GComponent currentRowChild = columnChildren.get(0);
for (int i = colIndex; i < childCount; i += columnsCount) {
GComponent existingChild = container.children.get(i);
if (existingChild == child) {
rowIndex = currentRowIndex;
break;
}
if (currentRowChild == existingChild) {
currentRowIndex++;
if (currentRowIndex == columnChildren.size()) {
rowIndex = currentRowIndex;
break;
}
currentRowChild = columnChildren.get(currentRowIndex);
}
}
}

columnChildren.add(rowIndex, child);

columns[colIndex].add(new ProxyPanel(child, view), child.getAlignment());
rebuildColumnCollections();
}

@Override
protected void removeImpl(int index, GComponent child, Widget view) {
int childIndex = container.children.indexOf(child);
int colIndex = childIndex % columnsCount;
columnsChildren[colIndex].remove(child);

rebuildColumnCollections();

Object columnsProxy = view.getElement().getPropertyObject(COLUMN_PROXY_KEY);
if (!(columnsProxy instanceof ProxyPanel)) {
throw new IllegalStateException("Trying to delete something, that wasn't added");
}
}

FlexPanel column = columns[colIndex];
int proxyIndex = column.getWidgetIndex((Widget) columnsProxy);

column.remove(proxyIndex);
private void rebuildColumnCollections() {
clearColumnsCollections();

int cnt = 0;
for (GComponent child : container.children) {
int index = children.indexOf(child);
if (index >= 0) {
int colIndex = cnt % columnsCount;
int rowIndex = cnt / columnsCount;
columns[colIndex].add(new ProxyPanel(child, childrenViews.get(index)), child.getAlignment());
columnsChildren[colIndex].add(rowIndex, child);
++cnt;
}
}
}

private void clearColumnsCollections() {
for (FlexPanel panel : columns) {
panel.clear();
}

for (List<GComponent> components : columnsChildren) {
components.clear();
}
}

@Override
public Widget getView() {
return view;
Expand Down

0 comments on commit c4d9905

Please sign in to comment.