How to trigger BorderLayoutContainer center ContentPanel to resize when other regions collapse/expand? - gxt

I would like the BorderLayoutContainer Center region Content Panel to fill to the available space when the other regions collapse/expend.
Right now, the center region moves to the collapsed space but does not resize.

I've figured this out from a bunch of digging thru the api, source, and hints in the Sencha forums.
My setup is a center BorderLayoutContainer ContentPanel with a MPV View Composite VerticalLayoutContainer surrounding two Toolbars and a Grid.
The issue is the toolbars and grid would not resize to fill the space when the center ContentPanel resized.
My solution is for the View VerticalLayoutContainer Composite to implement the HasLayout interface and to add a ResizeHandler() to the surrounding ContentPanel.
centerContentPanel.addResizeHandler( new ResizeHandler() {
#Override
public void onResize(ResizeEvent event) {
Widget w = centerContentPanel.getWidget();
if (w instanceof HasLayout) {
((HasLayout) w).forceLayout();
}
}
});

I know this answer is very late ... but try putting your BorderLayoutContainer inside a ViewPort. Here's the JavaDoc for the ViewPort widget: GXT ViewPort.

Related

Ignore transparent pixels on sprite

So I need the sprite to get bigger when I hover over the sprite with the mouse. But the problem is that the sprite has an unusual shape, which leaves a lot of transparent space. And the mouse reacts to this transparent space.
override public function create()
{
image = new FlxSprite(100, 100).loadGraphic("assets/images/freeplay.png");
add(image);
}
override public function update(elapsed:Float)
{
image.scale.set(1, 1);
if (FlxG.mouse.overlaps(image))
{
image.scale.set(1.1, 1.1);
}
super.update(elapsed);
}
How can I make the sprite not react on a transparent background?
FlxSprite has pixelsOverlapPoint for one-off things.
FlxExtendedSprite has enableMouseClicks for more complex setups.

Parent View Scaling OnClickListener

Solution
Original: Window Service > Parent Layout > Views
Fixed: Window Service > Parent Layout > Parent Layout 2 > Views
You cannot use a parent layout that is not a child to another layout before being added to window service. Only graphics will scale if you do so.
Issue
I have a RelativeLayout that parents some views like a TextView, SeekBar, and a Button. Using setScaleX/Y, I am successfully able to scale the views visually. A problem I now have is that although the graphics have scaled, the onClickListeners touch area have not scaled along with the graphics. I need to touch the original position in order to trigger any of these events. I want the touch area to scale with the graphics without scaling the children individually.
Current Scaling Code:
size.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
/** Max Progress is 100 **/
float scale = 1.0f;
scale = scale + 0.01f * progress;
/** mLayout is Parent Layout **/
mLayout.setScaleX(scale);
mLayout.setScaleY(scale);
mLayout.invalidate();
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
Solution
Original: Window Service > Parent Layout > Views
Fixed: Window Service > Parent Layout > Parent Layout 2 > Views
You cannot use a parent layout that is not a child to another layout before being added to window service. Only graphics will scale if you do so.

Layouting problems with JavaFX Region

I want to write a new class that extends Region containing a StackPane inside. But I'm getting into trouble when I add insets to it like padding or a border. Here is a simplified example of the class:
public class CustomPane extends Region
{
private ToggleButton testControl = new ToggleButton("just a test control");
private StackPane rootPane = new StackPane(testControl);
public CustomPane()
{
getChildren().add(rootPane);
setStyle("-fx-border-color: #257165; -fx-border-width: 10;");
}
}
And that is how the result looks like:
If I try to move the StackPane by calling
rootPane.setLayoutX(10);
rootPane.setLayoutY(10);
then the Region just grows:
But really I wanted it to look like this:
(The third image was created by extending StackPane instead of Region, which already manages the layouting stuff correctly. Unfortunately I have to extend Region since I want to keep getChildren() protected.)
Okay, I tried to handle the layout calculation but I didn't come up with it. Could experts give me some advise?
StackPane uses the insets for layouting the (managed) children. Region doesn't do this by default. Therefore you need to override the layoutChildren with something that uses these insets, e.g.:
#Override
protected void layoutChildren() {
Insets insets = getInsets();
double top = insets.getTop(),
left = insets.getLeft(),
width = getWidth() - left - insets.getRight(),
height = getHeight() - top - insets.getBottom();
// layout all managed children (there's only rootPane in this case)
layoutInArea(rootPane,
left, top, // offset of layout area
width, height, // available size for content
0,
HPos.LEFT,
VPos.TOP);
}

Scale background image during screen rotation in android using Tabris

I have following server side code in the top level page to set background image for all pages in the app.
#Override
public void createContent(final Composite parent, final PageData oData) {
Image bg = ResourceManager.getImage( LnfSettings.IMAGE_PAGE_BACKGROUND );
Composite comp = parent.getParent();
int width = comp.getDisplay().getClientArea().width;
int height = comp.getDisplay().getClientArea().height;
comp.setBackgroundImage( new Image( bg.getDevice(), bg.getImageData().scaledTo(
width, height ) ) );
... more code here to create layout and contents
}
Above code correctly sets background for all pages and also scaled image to fit with the different screen sizes. But if I rotate the screen, image doesn't get scaled according to the new screen dimension. How to deal with this issue? I am using Tabris 1.4.
You can add a resize listener to your composite like this:
comp.addListener(SWT.Resize, listenerComp);
Listener listenerComp = new Listener() {
#Override
public void handleEvent(Event event) {
...
}
};
Just get sure you cache your scaled Images so you do not scale and create new images on every rotation.

Scaling in JavaFX and ScrollPanes

I've been trying to work with the scaling transform in JavaFX, but haven't quite been able to wrap my head around it. Basically, I have a Pane containing a complex graph and would like to be able to rescale it. The scaling part itself works fine, however, the enclosing scroll pane will not adapt to the graph.
For simplicity's sake, i'll post a short example in which my graph is replaced by a label:
public class TestApp extends Application {
#Override public void start(final Stage stage) throws Exception {
final Label label = new Label("Hello World");
label.getTransforms().setAll(new Scale(0.5, 0.5));
label.setStyle("-fx-background-color:blue");
label.setFont(new Font(200));
final ScrollPane scrollPane = new ScrollPane();
scrollPane.setContent(label);
stage.setScene(new Scene(scrollPane));
stage.setWidth(200);
stage.setHeight(100);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
The label will scale correctly, but the enclosing scroll pane's bars will still accomodate a component of the original size.
I've tried so far:
Playing around with the labels min and pref size
wrapping the label inside a Group (no scrollbars will appear whatsoever)
scaling the enclosing Group rather than the label
What am I missing? What can I do to make the ScrollPane adapt to the content view?
Thanks for your help.
According to the ScrollPane document you might try to wrap a Pane in a Group so the ScrollPane is scroll by visual bound not the actual layout bound.
ScrollPane layout calculations are based on the layoutBounds rather than the
boundsInParent (visual bounds) of the scroll node. If an application wants the
scrolling to be based on the visual bounds of the node (for scaled content etc.),
they need to wrap the scroll node in a Group.
I implemented scaling in a ScrollPane for Graphs and other nodes in
this example of scrollpane viewports, transforms and layout bounds in JavaFX.
The code was implemented when I was first learning JavaFX, so certainly the code could be cleaner and perhaps there are simpler ways to accomplish this (e.g. using a Group as the container for the scaled node as suggested in the ScrollPane documentation).
One key to getting the solution I wanted (ScrollBars only appearing when you are zoomed in and the node is larger than the visible viewport), was this code:
// create a container for the viewable node.
final StackPane nodeContainer = new StackPane();
nodeContainer.getChildren().add(node);
// place the container in the scrollpane and adjust the pane's viewports as required.
final ScrollPane scrollPane = new ScrollPane();
scrollPane.setContent(nodeContainer);
scrollPane.viewportBoundsProperty().addListener(
new ChangeListener<Bounds>() {
#Override public void changed(ObservableValue<? extends Bounds> observableValue, Bounds oldBounds, Bounds newBounds) {
nodeContainer.setPrefSize(
Math.max(node.getBoundsInParent().getMaxX(), newBounds.getWidth()),
Math.max(node.getBoundsInParent().getMaxY(), newBounds.getHeight())
);
}
});
...
// adjust the view layout based on the node scalefactor.
final ToggleButton scale = new ToggleButton("Scale");
scale.setOnAction(new EventHandler<ActionEvent>() {
#Override public void handle(ActionEvent actionEvent) {
if (scale.isSelected()) {
node.setScaleX(3); node.setScaleY(3);
} else {
node.setScaleX(1); node.setScaleY(1);
}
// runlater as we want to size the container after a layout pass has been performed on the scaled node.
Platform.runLater(new Runnable() {
#Override public void run() {
nodeContainer.setPrefSize(
Math.max(nodeContainer.getBoundsInParent().getMaxX(), scrollPane.getViewportBounds().getWidth()),
Math.max(nodeContainer.getBoundsInParent().getMaxY(), scrollPane.getViewportBounds().getHeight())
);
}
});
}
});

Resources