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);
}
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);
}
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);
}
}
}
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());
}
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);
}
Aggregations