Search in sources :

Example 6 with GridPane

use of org.apache.pivot.wtk.GridPane in project pivot by apache.

the class GridPaneSkin method getRowBounds.

@Override
public Bounds getRowBounds(int row) {
    GridPane gridPane = (GridPane) getComponent();
    GridPane.RowSequence rows = gridPane.getRows();
    int rowCount = rows.getLength();
    if (row < 0 || row >= rowCount) {
        throw new IndexOutOfBoundsException(String.valueOf(row));
    }
    int rowY = padding.top;
    for (int i = 0; i < row; i++) {
        rowY += cellHeight + verticalSpacing;
    }
    return new Bounds(0, rowY, getWidth(), cellHeight);
}
Also used : GridPane(org.apache.pivot.wtk.GridPane) Bounds(org.apache.pivot.wtk.Bounds)

Example 7 with GridPane

use of org.apache.pivot.wtk.GridPane in project pivot by apache.

the class GridPaneSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    GridPane gridPane = (GridPane) getComponent();
    GridPane.RowSequence rows = gridPane.getRows();
    int columnCount = gridPane.getColumnCount();
    int rowCount = rows.getLength();
    Metadata metadata = new Metadata();
    // calculate the maximum preferred cellWidth and cellHeight
    int preferredCellHeight = 0;
    int preferredCellWidth = 0;
    for (int i = 0; i < rowCount; i++) {
        GridPane.Row row = rows.get(i);
        for (int j = 0, n = row.getLength(); j < n && j < columnCount; j++) {
            Component component = row.get(j);
            if (component != null && component.isVisible()) {
                Dimensions d = component.getPreferredSize();
                preferredCellHeight = Math.max(preferredCellHeight, d.height);
                preferredCellWidth = Math.max(preferredCellWidth, d.width);
            }
        }
    }
    // The preferred width of the grid pane is the sum of the column
    // widths, plus padding and spacing
    int preferredWidth = (metadata.visibleColumnCount * preferredCellWidth) + padding.getWidth();
    if (metadata.visibleColumnCount > 1) {
        preferredWidth += (metadata.visibleColumnCount - 1) * horizontalSpacing;
    }
    // The preferred height of the grid pane is the sum of the row
    // heights, plus padding and spacing
    int preferredHeight = (metadata.visibleRowCount * preferredCellHeight) + padding.getHeight();
    if (metadata.visibleRowCount > 1) {
        preferredHeight += (metadata.visibleRowCount - 1) * verticalSpacing;
    }
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : GridPane(org.apache.pivot.wtk.GridPane) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component)

Example 8 with GridPane

use of org.apache.pivot.wtk.GridPane in project pivot by apache.

the class GridPaneSkin method layout.

@Override
public void layout() {
    GridPane gridPane = (GridPane) getComponent();
    GridPane.RowSequence rows = gridPane.getRows();
    int columnCount = gridPane.getColumnCount();
    int rowCount = rows.getLength();
    int width = getWidth();
    int height = getHeight();
    Metadata metadata = new Metadata();
    cellWidth = getCellWidth(width, metadata);
    cellHeight = getCellHeight(height, metadata);
    int componentY = padding.top;
    for (int i = 0; i < rowCount; i++) {
        if (metadata.isRowVisible(i)) {
            GridPane.Row row = rows.get(i);
            int componentX = padding.left;
            for (int j = 0, n = row.getLength(); j < n && j < columnCount; j++) {
                Component component = row.get(j);
                if (component != null && component.isVisible()) {
                    component.setLocation(componentX, componentY);
                    component.setSize(cellWidth, cellHeight);
                }
                if (metadata.isColumnVisible(j)) {
                    componentX += (cellWidth + horizontalSpacing);
                }
            }
            componentY += (cellHeight + verticalSpacing);
        }
    }
}
Also used : GridPane(org.apache.pivot.wtk.GridPane) Component(org.apache.pivot.wtk.Component)

Example 9 with GridPane

use of org.apache.pivot.wtk.GridPane in project pivot by apache.

the class GridPaneSkin method getColumnBounds.

@Override
public Bounds getColumnBounds(int column) {
    GridPane gridPane = (GridPane) getComponent();
    int columnCount = gridPane.getColumnCount();
    if (column < 0 || column >= columnCount) {
        throw new IndexOutOfBoundsException(String.valueOf(column));
    }
    int columnX = padding.left;
    for (int j = 0; j < column; j++) {
        columnX += cellWidth + horizontalSpacing;
    }
    return new Bounds(columnX, 0, cellWidth, getHeight());
}
Also used : GridPane(org.apache.pivot.wtk.GridPane) Bounds(org.apache.pivot.wtk.Bounds)

Example 10 with GridPane

use of org.apache.pivot.wtk.GridPane in project pivot by apache.

the class Pivot894 method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    System.out.println("public startup(...)");
    System.out.println("\n" + "Attention: now the application will go in an infinite loop, to be able to see the memory leak.\n" + "Note that probably you'll have to kill the application from outside (kill the Java process).\n" + "\n");
    // add some sleep to let users see the warning messages in console ...
    Thread.sleep(2000);
    final CardPane cardPane = new CardPane();
    cardPane.getStyles().put(Style.selectionChangeEffect, CardPaneSkin.SelectionChangeEffect.HORIZONTAL_SLIDE);
    final Window window = new Window(cardPane);
    window.open(display);
    ApplicationContext.scheduleRecurringCallback(new Runnable() {

        @Override
        public void run() {
            Thread.currentThread().setName("switcher-thread");
            // temp
            System.out.println("Run num " + num++);
            // 
            try {
                // Before the fixes for PIVOT-861 (part two) it was causing
                // out of memory ...
                // 
                // Note that this has been moved to another issue, but the
                // problem is due to the usage
                // of dataRenderer tags (and then instancing
                // ButtonDataRenderer) in the loaded bxml,
                // so probably even this test will be updated ...
                // 
                final GridPane grid = (GridPane) new BXMLSerializer().readObject(Pivot894.class, "btn_grid.bxml");
                EventQueue.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        Iterator<Component> iterator = cardPane.iterator();
                        List<Component> componentList = new ArrayList<>();
                        while (iterator.hasNext()) {
                            Component card = iterator.next();
                            if (!card.isShowing()) {
                                componentList.add(card);
                            }
                        }
                        for (Component card : componentList) {
                            cardPane.remove(card);
                        }
                        cardPane.setSelectedIndex(cardPane.add(grid));
                        System.out.println(cardPane.getSelectedIndex());
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @SuppressWarnings("unused")
        private Row createGridRow() {
            Row row = new Row();
            try {
                // note that this method doesn't use ApplicationContext
                // cache for images ...
                row.add(new PushButton(new ButtonData(Image.load(new File("clock_icon.png").toURI().toURL()), "Clock")));
                row.add(new PushButton(new ButtonData(Image.load(new File("clock_icon.png").toURI().toURL()), "Clock")));
                row.add(new PushButton(new ButtonData(Image.load(new File("clock_icon.png").toURI().toURL()), "Clock")));
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (TaskExecutionException e) {
                e.printStackTrace();
            }
            return row;
        }
    }, 100);
}
Also used : Window(org.apache.pivot.wtk.Window) CardPane(org.apache.pivot.wtk.CardPane) MalformedURLException(java.net.MalformedURLException) GridPane(org.apache.pivot.wtk.GridPane) ArrayList(java.util.ArrayList) MalformedURLException(java.net.MalformedURLException) TaskExecutionException(org.apache.pivot.util.concurrent.TaskExecutionException) TaskExecutionException(org.apache.pivot.util.concurrent.TaskExecutionException) ButtonData(org.apache.pivot.wtk.content.ButtonData) Row(org.apache.pivot.wtk.GridPane.Row) Component(org.apache.pivot.wtk.Component) PushButton(org.apache.pivot.wtk.PushButton) File(java.io.File) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Aggregations

GridPane (org.apache.pivot.wtk.GridPane)13 Component (org.apache.pivot.wtk.Component)6 Bounds (org.apache.pivot.wtk.Bounds)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 FileObject (org.apache.commons.vfs2.FileObject)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 Dictionary (org.apache.pivot.collections.Dictionary)1 Task (org.apache.pivot.util.concurrent.Task)1 TaskExecutionException (org.apache.pivot.util.concurrent.TaskExecutionException)1 TaskListener (org.apache.pivot.util.concurrent.TaskListener)1 ActivityIndicator (org.apache.pivot.wtk.ActivityIndicator)1 CardPane (org.apache.pivot.wtk.CardPane)1 Dimensions (org.apache.pivot.wtk.Dimensions)1 Row (org.apache.pivot.wtk.GridPane.Row)1 Point (org.apache.pivot.wtk.Point)1 PushButton (org.apache.pivot.wtk.PushButton)1 SortDirection (org.apache.pivot.wtk.SortDirection)1 TableView (org.apache.pivot.wtk.TableView)1