use of org.apache.pivot.wtk.TablePane in project pivot by apache.
the class Pivot964Pivot method startup.
@Override
public void startup(Display display, Map<String, String> properties) {
// force dimensions for host frame
display.getHostWindow().setSize(1028, 600);
window = new Window();
prepareSVG();
final ImageView image = new ImageView(new Drawing(diagram));
BoxPane bp = new BoxPane();
TablePane tp = new TablePane();
setStyles(tp, "{padding: 4}");
TablePane.Column c1 = new TablePane.Column(-1);
TablePane.Column c2 = new TablePane.Column(-1);
tp.getColumns().add(c1);
tp.getColumns().add(c2);
TablePane.Row r1 = new TablePane.Row(-1);
TablePane.Row r2 = new TablePane.Row(-1);
TablePane.Row r3 = new TablePane.Row(-1);
PushButton pb1 = new PushButton("Visible");
PushButton pb2 = new PushButton("Invisible (bug)");
r1.add(pb1);
r1.add(pb2);
final Spinner sp1 = new Spinner(new ListAdapter<>(spinnerData));
sp1.setPreferredWidth(80);
sp1.setSelectedIndex(0);
final Spinner sp2 = new Spinner(new ListAdapter<>(spinnerData));
sp2.setPreferredWidth(80);
sp2.setSelectedIndex(0);
BoxPane bp1 = new BoxPane();
setStyles(bp1, "{verticalAlignment:'center', padding: 4, spacing: 2}");
bp1.add(new Label("X:"));
bp1.add(sp1);
r2.add(bp1);
BoxPane bp2 = new BoxPane();
setStyles(bp2, "{verticalAlignment:'center', padding: 4, spacing: 2}");
bp2.add(new Label("Y:"));
bp2.add(sp2);
r2.add(bp2);
tp.getRows().add(r1);
tp.getRows().add(r2);
r3.add(new Label(" Max X=507"));
r3.add(new Label(" Max Y=269"));
tp.getRows().add(r3);
bp.add(image);
bp.add(tp);
pb1.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button arg0) {
try {
root.setAttribute("viewBox", AnimationElement.AT_XML, "0 0 2368 1652");
root.updateTime(0f);
image.repaint();
} catch (SVGElementException e) {
e.printStackTrace();
} catch (SVGException e) {
e.printStackTrace();
}
}
});
pb2.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button arg0) {
try {
String xOffset = (String) sp1.getSelectedItem();
String yOffset = (String) sp2.getSelectedItem();
String viewBox = String.format("%1$s %2$s 2368 1652", xOffset, yOffset);
root.setAttribute("viewBox", AnimationElement.AT_XML, viewBox);
root.updateTime(0f);
image.repaint();
} catch (SVGElementException e) {
e.printStackTrace();
} catch (SVGException e) {
e.printStackTrace();
}
}
});
window.setContent(bp);
window.setMaximized(true);
window.open(display);
}
use of org.apache.pivot.wtk.TablePane in project pivot by apache.
the class BXMLExplorerDocument method setComponentIconOnTreeNode.
private static void setComponentIconOnTreeNode(TreeNode treeNode, Object comp) {
String resource = null;
if (comp instanceof Label) {
resource = "label.png";
}
if (comp instanceof ImageView) {
resource = "/org/apache/pivot/tutorials/IMG_0725_2.jpg";
}
if (comp instanceof PushButton) {
resource = "pushbutton.png";
}
if (comp instanceof RadioButton) {
resource = "radiobutton.png";
}
if (comp instanceof Checkbox) {
resource = "checkbox.png";
}
if (comp instanceof LinkButton) {
resource = "linkbutton.png";
}
if (comp instanceof TablePane) {
resource = "tablepane.png";
}
if (resource != null) {
URL url = BXMLExplorerDocument.class.getResource(resource);
if (url == null) {
throw new IllegalStateException("could not load resource " + resource);
}
treeNode.setIcon(url);
}
}
use of org.apache.pivot.wtk.TablePane in project pivot by apache.
the class BXMLExplorerDocument method analyseObjectTree.
@SuppressWarnings("unchecked")
private TreeNode analyseObjectTree(Object container) {
// doesn't look neat
if (container instanceof TablePane) {
TreeBranch branch = new TreeBranch(nameForObject(container));
TablePane table = (TablePane) container;
for (TablePane.Row row : table.getRows()) {
TreeNode childBranch = analyseObjectTree(row);
branch.add(childBranch);
}
setComponentIconOnTreeNode(container, branch);
return branch;
}
// We don't want to analyse the components that are added as part of the
// skin, so use similar logic to BXMLSerializer
DefaultProperty defaultProperty = container.getClass().getAnnotation(DefaultProperty.class);
if (defaultProperty != null) {
TreeBranch branch = new TreeBranch(nameForObject(container));
String defaultPropertyName = defaultProperty.value();
BeanAdapter beanAdapter = new BeanAdapter(container);
if (!beanAdapter.containsKey(defaultPropertyName)) {
throw new IllegalStateException("default property " + defaultPropertyName + " not found on " + container);
}
Object defaultPropertyValue = beanAdapter.get(defaultPropertyName);
if (defaultPropertyValue != null) {
if (defaultPropertyValue instanceof Component) {
TreeNode childBranch = analyseObjectTree(defaultPropertyValue);
branch.add(childBranch);
}
}
// so make empty branches into nodes.
if (branch.isEmpty()) {
TreeNode node = new TreeNode(branch.getText());
setComponentIconOnTreeNode(container, node);
return node;
}
setComponentIconOnTreeNode(container, branch);
return branch;
}
if (container instanceof Sequence<?>) {
TreeBranch branch = new TreeBranch(nameForObject(container));
Iterable<Object> sequence = (Iterable<Object>) container;
for (Object child : sequence) {
TreeNode childBranch = analyseObjectTree(child);
branch.add(childBranch);
}
setComponentIconOnTreeNode(container, branch);
return branch;
}
TreeNode node = new TreeNode(nameForObject(container));
setComponentIconOnTreeNode(container, node);
return node;
}
use of org.apache.pivot.wtk.TablePane in project pivot by apache.
the class TablePaneSkin method getPreferredRowHeight.
/**
* Gets the preferred height of a table pane row, which is defined as the
* maximum preferred height of the row's visible components. The preferred
* height of each constituent component will be constrained by the width of
* the column that the component occupies (as specified in the array of
* column widths). <p> Because their preferred height relates to the
* preferred heights of other rows, components that span multiple rows will
* not be considered in this calculation (even if they live in the column
* directly). It is up to the caller to factor such components into the row
* heights calculation.
*
* @param rowIndex The index of the row whose preferred height we're
* calculating
* @param columnWidthsArgument An array of column width values corresponding
* to the columns of the table pane
*/
private int getPreferredRowHeight(int rowIndex, int[] columnWidthsArgument) {
Utils.checkNull(columnWidthsArgument, "columnWidths");
TablePane tablePane = (TablePane) getComponent();
TablePane.ColumnSequence columns = tablePane.getColumns();
TablePane.Row row = tablePane.getRows().get(rowIndex);
int preferredHeight = 0;
for (int j = 0, n = row.getLength(), m = columns.getLength(); j < n && j < m; j++) {
Component component = row.get(j);
if (component != null && component.isVisible() && TablePane.getRowSpan(component) == 1) {
preferredHeight = Math.max(preferredHeight, component.getPreferredHeight(columnWidthsArgument[j]));
}
}
return preferredHeight;
}
use of org.apache.pivot.wtk.TablePane in project pivot by apache.
the class TablePaneSkin method paint.
@Override
public void paint(Graphics2D graphics) {
super.paint(graphics);
TablePane tablePane = (TablePane) getComponent();
TablePane.RowSequence rows = tablePane.getRows();
TablePane.ColumnSequence columns = tablePane.getColumns();
int rowCount = rows.getLength();
int columnCount = columns.getLength();
int width = getWidth();
int height = getHeight();
graphics.setPaint(highlightBackgroundColor);
// Paint the highlighted rows
for (int i = 0, rowY = padding.top; i < rowCount; i++) {
TablePane.Row row = rows.get(i);
if (row.isHighlighted()) {
graphics.fillRect(0, rowY, width, rowHeights[i]);
}
rowY += rowHeights[i] + verticalSpacing;
}
// Paint the highlighted columns
for (int j = 0, columnX = padding.left; j < columnCount; j++) {
TablePane.Column column = columns.get(j);
if (column.isHighlighted()) {
graphics.fillRect(columnX, 0, columnWidths[j], height);
}
columnX += columnWidths[j] + horizontalSpacing;
}
// Paint the grid lines
if ((showHorizontalGridLines && verticalSpacing > 0) || (showVerticalGridLines && horizontalSpacing > 0)) {
Graphics2D gridGraphics = (Graphics2D) graphics.create();
gridGraphics.setStroke(new BasicStroke());
GraphicsUtilities.setAntialiasingOn(graphics);
// Find any components that span multiple rows or columns, and
// ensure that the grid lines don't get painted through their
// cells. We'll only instantiate gridClip if we find such cells
Area gridClip = null;
for (int i = 0, componentY = padding.top; i < rowCount; i++) {
for (int j = 0, componentX = padding.left; j < columnCount; j++) {
Component component = tablePane.getCellComponent(i, j);
if (component != null) {
int rowSpan = TablePane.getRowSpan(component);
int columnSpan = TablePane.getColumnSpan(component);
if (rowSpan > 1 || columnSpan > 1) {
int rowY = componentY;
int columnX = componentX;
int rowHeight = rowHeights[i];
int columnWidth = columnWidths[j];
for (int k = i + 1; k < i + rowSpan && k < rowCount; k++) {
rowHeight += rowHeights[k] + verticalSpacing;
}
for (int k = j + 1; k < j + columnSpan && k < columnCount; k++) {
columnWidth += columnWidths[k] + horizontalSpacing;
}
if (gridClip == null) {
gridClip = new Area(graphics.getClip());
}
if (horizontalSpacing > 1) {
columnWidth += horizontalSpacing - 1;
columnX -= (int) ((horizontalSpacing * 0.5f) - 0.5f);
}
if (verticalSpacing > 1) {
rowHeight += verticalSpacing - 1;
rowY -= (int) ((verticalSpacing * 0.5f) - 0.5f);
}
Rectangle2D.Float bounds = new Rectangle2D.Float(columnX, rowY, columnWidth, rowHeight);
gridClip.subtract(new Area(bounds));
}
}
componentX += columnWidths[j] + horizontalSpacing;
}
componentY += rowHeights[i] + verticalSpacing;
}
if (gridClip != null) {
gridGraphics.clip(gridClip);
}
boolean[][] occupiedCells = getOccupiedCells();
if (showHorizontalGridLines && verticalSpacing > 0 && rowCount > 1) {
gridGraphics.setPaint(horizontalGridColor);
int rowY = padding.top;
int visibleRowCount = 0;
for (int i = 0; i < rowCount; i++) {
boolean rowVisible = false;
for (int j = 0; j < columnCount; j++) {
if (occupiedCells[i][j]) {
rowVisible = true;
break;
}
}
if (rowVisible) {
if (visibleRowCount++ > 0) {
int gridY = Math.max(rowY - (int) Math.ceil(verticalSpacing * 0.5f), 0);
GraphicsUtilities.drawLine(gridGraphics, 0, gridY, width, Orientation.HORIZONTAL);
}
rowY += (rowHeights[i] + verticalSpacing);
}
}
}
if (showVerticalGridLines && horizontalSpacing > 0 && columnCount > 1) {
gridGraphics.setPaint(verticalGridColor);
int columnX = padding.left;
int visibleColumnCount = 0;
for (int j = 0; j < columnCount; j++) {
boolean columnVisible = false;
for (int i = 0; i < rowCount; i++) {
if (occupiedCells[i][j]) {
columnVisible = true;
break;
}
}
if (columnVisible) {
if (visibleColumnCount++ > 0) {
int gridX = Math.max(columnX - (int) Math.ceil(horizontalSpacing * 0.5), 0);
GraphicsUtilities.drawLine(gridGraphics, gridX, 0, height, Orientation.VERTICAL);
}
columnX += (columnWidths[j] + horizontalSpacing);
}
}
}
gridGraphics.dispose();
}
}
Aggregations