Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spreadsheet Rows Headers Not Resizing #358

Closed
JonathanGiles opened this issue Sep 1, 2014 · 8 comments
Closed

Spreadsheet Rows Headers Not Resizing #358

JonathanGiles opened this issue Sep 1, 2014 · 8 comments
Labels
bug Something isn't working SpreadsheetView
Milestone

Comments

@JonathanGiles
Copy link
Collaborator

Original report by Dennis Remme (Bitbucket: deso88, GitHub: deso88).


Issue #324 still exists if any rows become visible after resizeRowsToDefault() has been called.

At the moment you have to call resizeRowsToDefault() again to resize them properly.

paia_tool_1.jpg

Row headers G and H have not been resized because they have been invisible before.

paia_tool_2.jpg

@JonathanGiles
Copy link
Collaborator Author

Original comment by Samir Hadzic (Bitbucket: shadzic, GitHub: shadzic).


Can you link or write a self-contained test application to demonstrate the issue please?

@JonathanGiles
Copy link
Collaborator Author

Original comment by Dennis Remme (Bitbucket: deso88, GitHub: deso88).


Alright I will do that later.

@JonathanGiles
Copy link
Collaborator Author

Original comment by Dennis Remme (Bitbucket: deso88, GitHub: deso88).


I created a little test application. If you press 50% the first time it works. If you click 100% and then 50% again it doesn't scale the row headers properly.

This requires the current 8.20.7 snapshot of ControlsFX.

Am I missing something?

#!java


import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.controlsfx.control.spreadsheet.GridBase;
import org.controlsfx.control.spreadsheet.SpreadsheetCell;
import org.controlsfx.control.spreadsheet.SpreadsheetCellBase;
import org.controlsfx.control.spreadsheet.SpreadsheetView;

public class SpreadsheetTest extends Application {

    private double scaleFactor = 1.0;

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        // create the grid
        final ObservableList<ObservableList<SpreadsheetCell>> rows
                = FXCollections.<ObservableList<SpreadsheetCell>>observableArrayList();
        for (int row = 0; row < 20; row++) {
            final ObservableList<SpreadsheetCell> cells = FXCollections.<SpreadsheetCell>observableArrayList();
            for (int col = 0; col < 20; col++) {
                SpreadsheetCellBase cell = new SpreadsheetCellBase(row, col, 1, 1);
                cell.setItem(Math.random());
                cells.add(cell);
            }
            rows.add(cells);
        }
        final GridBase grid = new GridBase(20, 20);
        grid.setRows(rows);
        grid.setRowHeightCallback(index -> {
            return 75 * scaleFactor;
        });

        final SpreadsheetView spreadsheet = new SpreadsheetView(grid);
        VBox.setVgrow(spreadsheet, Priority.ALWAYS);

        // create scaling buttons
        final Button scale50 = new Button("50%");
        scale50.setOnAction(e -> {
            scaleFactor = 0.5;
            spreadsheet.resizeRowsToDefault();
        });
        final Button scale100 = new Button("100%");
        scale100.setOnAction(e -> {
            scaleFactor = 1.0;
            spreadsheet.resizeRowsToDefault();
        });

        primaryStage.setScene(new Scene(new VBox(new HBox(scale50, scale100), spreadsheet)));
        primaryStage.setWidth(800);
        primaryStage.setHeight(600);
        primaryStage.show();
    }
}

@JonathanGiles
Copy link
Collaborator Author

Original comment by Samir Hadzic (Bitbucket: shadzic, GitHub: shadzic).


The problem is complex because when I change the height of the visible rows (actually going from 100% to 50%), it adds some rows at the bottom because we give extra space. But these new rows appear afterward.

So a solution is to check when rows are stacked and become visible, this problem is solved.

Now I have another problem, it's that the calculation is wrong because it calculates that 3 rows have to be added. But since I shrank them, I can actually put 5 rows. Therefore we have a blank space at the bottom. It's kind of a recursive problem because I shrink rows, then it adds some more, I detect it, then shrink them, then it again allows some more rows to be there etc etc.

I'm working on the blank space at the bottom trying to find a solution.

@JonathanGiles
Copy link
Collaborator Author

Original comment by Jonathan Giles (Bitbucket: JonathanGiles, GitHub: JonathanGiles).


Resolving #358 : Invisible rows are now resized, and a "layoutChildren" call is given in order to add some rows if necessary.

@JonathanGiles
Copy link
Collaborator Author

Original comment by Samir Hadzic (Bitbucket: shadzic, GitHub: shadzic).


Issue has been re-introduced.

@JonathanGiles
Copy link
Collaborator Author

Original comment by Samir Hadzic (Bitbucket: shadzic, GitHub: shadzic).


Issue will be fixed in next pull request, I've made a test to prevent regression using TestFX, it's on my computer right now and when we will be using TestFX, it will be pushed:

#!java

@Test
    public void resizeToDefault_Issue358() throws TimeoutException {
        final GridBase grid = (GridBase) view.getGrid();

        grid.setRowHeightCallback(index -> {
            return 37.5;
        });
        

        FxToolkit.setupFixture(() -> {
            view.resizeRowsToDefault();
        });

        verifyHeight(view, 37.5);

        grid.setRowHeightCallback(index -> {
            return 75.0;
        });

        FxToolkit.setupFixture(() -> {
            view.resizeRowsToDefault();
        });

        verifyHeight(view, 75.0);

        grid.setRowHeightCallback(index -> {
            return 37.5;
        });

        FxToolkit.setupFixture(() -> {
            view.resizeRowsToDefault();
        });

        verifyHeight(view, 37.5);
    }


/**
     * Verify the height of all visible rows in the SpreadsheetView.
     * @param view
     * @param height 
     */
    private void verifyHeight(SpreadsheetView view, double height){
        for(Node row : from(view).lookup(new Predicate<Node>() {

            @Override
            public boolean apply(Node row) {
                return row instanceof GridRow && ((GridRow)row).getIndex() >= 0 && row.isVisible();
            }
        }).queryAll()){
            Assert.assertEquals(height, ((GridRow)row).getPrefHeight(), 0);
        }
    }

@JonathanGiles
Copy link
Collaborator Author

Original comment by Jonathan Giles (Bitbucket: JonathanGiles, GitHub: JonathanGiles).


Resolving Issue #358 with resizing issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SpreadsheetView
Projects
None yet
Development

No branches or pull requests

1 participant