Resizing GXT Window When Browser Window Resizes - gxt

Developing using GXT 2.2.5 on GWT 2.3.0.
The application I'm working on displays a resizable Window with auto scrollbars. I want to make sure the Window size does not exceed the size of the browser window it gets displayed in. To that effect, I added the following code:
addWindowListener(new WindowListener()
{
public void windowActivate(WindowEvent we)
{
super.windowActivate();
Window window = we.getWindow();
window.layout(true);
int width = window.getWidth();
int height = window.getHeight();
int maxWidth = XDOM.getViewportWidth();
int maxHeight = XDOM.getViewportHeight();
window.setSize(Math.min(width, maxWidth), Math.min(height, maxHeight));
window.center();
}
};
This manages sizing the Window to fit in the browser when it gets opened quite nicely.
My problem is that if the user then resizes the browser window, the open Window does not adjust and ends up being clipped.
Is there some way for me to either force the Window to stay within the boundaries of the browser, or capture the resize event so that I can tell the Window to resize accordingly?
Thanks.

You need to add the listener (actually handler -- listeners got depreciated) to the browser window.
So if you have several different windows you show at different times that all need to be resized with the window, you need to have a listener for each window and add it to the browser window when the window is shown.
To add a listener to the browser Window, use:
com.google.gwt.user.client.Window.addResizeHandler(handler);
So for example to resize ContentPanel cp:
com.google.gwt.event.logical.shared.ResizeHandler handler = new ResizeHandler() {
#Override public void onResize(com.google.gwt.event.logical.shared.ResizeEvent event) {
cp.setWidth(event.getWidth());
cp.setHeight(event.getHeight());
}
};
So then if you switch to a new view or ContentPanel you need to register that...
com.google.gwt.user.client.Window.addResizeHandler(handler2);
com.google.gwt.event.logical.shared.ResizeHandler handler2 = new ResizeHandler() {
#Override public void onResize(com.google.gwt.event.logical.shared.ResizeEvent event) {
cp2.setWidth(event.getWidth());
cp2.setHeight(event.getHeight());
}
};
NOTE:
You can't do event.getWindow() for the ResizeEvent you need to handle that another way.
Actually I tend to do it in a constructor like:
com.google.gwt.event.logical.shared.ResizeHandler handler2;
public MyDialog(){
handler2 = new ResizeHandler() {
#Override public void onResize(com.google.gwt.event.logical.shared.ResizeEvent event) {
setWidth(event.getWidth());
setHeight(event.getHeight());
}
};

Related

How to Scroll pdfView automatically with button click or volume buttons

I'm using barteksc pdf viewer library to load pdf in my application.
pdfView = findViewById(R.id.pdfView);
pdfView.fromAsset(getResources().getString(R.string.pdfname))
.enableDoubletap(true)
.enableSwipe(true)
.defaultPage(pageNumber)
.onPageChange(mainreading.this)
.pageFitPolicy(FitPolicy.WIDTH)
.pageFling(true)
.linkHandler(null)
.enableAnnotationRendering(true)
.swipeHorizontal(true)
.scrollHandle(new DefaultScrollHandlenew(mainreading.this))
.enableAntialiasing(true)
.load();
}
I want pdf to start scroll automatically when user click the button of volume up and down buttons to start stop. I tried with below code while wrapping it in the handler with handler.performClick(); but it shows blank screen while scrolling up and down.
scrollbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
pdfView.scrollTo(0, pdfView.getScrollY() + 24);
}
});
Example :
https://play.google.com/store/apps/details?id=com.emptysheet.pdfreader_autoscroll&hl=en&gl=US
I want to make as like this. Can anyone help please.
Also tried with this. But it shows blank page after some scrolls.
#Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_DOWN) {
pdfView.scrollTo(0, pdfView.getScrollY() -24);
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_DOWN) {
pdfView.scrollTo(0, pdfView.getScrollY() + 24);
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}
You can simply use this PDF viewer from github.
It's based on the same 'barsteksc' pdf viewer with the feature to jump to any pages.
It's MagicalPdfViewer and you can use 'jumpTo(pageNo)' method to simply jump to the specific page. It also gives you the option to animate to the specific page with the same method, just pass 'true' as the 2nd parameter.
Moreover, if you pass the values like '-1' and 'bigger than pageNo', It will automatically scroll to the 0 & last page respectively.
Give it a try & let me know if you got what you wanted.

Revit Dockable pane does not react for min width

I have dockable pane with DockPosition=Rigth and MinWidth=300.
When pane is attached to Revit everything fine, but when i move it using mouse and DockPosition is changed to Floating , the panel do not react for MinWidth and change width to ~100.
xaml behind
xaml
How do you register the panel? You can try to register the panel after application is initialized if you haven't already tried that.
UIControlledApplication _uiControlledApplication = null;
public Result OnStartup(UIControlledApplication application)
{
_uiControlledApplication = application;
application.ControlledApplication.ApplicationInitialized += OnApplicationInitialized;
return Result.Succeeded;
}
private void OnApplicationInitialized(object sender, EventArgs e)
{
RegisterDockableWindow(_uiControlledApplication);
}
private void RegisterDockableWindow(UIControlledApplication app)
{
//app.RegisterDockablePane(....)
}

JDialog doesn't size correctly with wrapped JTextArea

While making a program, I noticed a bug with the JOptionPane.showMessageDialog() call. I use a button to create a JTextArea that wraps and then display a dialog containing this text area.
If the text area is too large, however, the dialog does not size itself correctly to the height of the JTextArea. The Dialog cuts off the OK button in this example.
I replicated the bug in the following code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DialogBug {
public static void main(String[] args) {
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final String text = "looooooooooooooooooooooong text looooooooooooooooooooooooooooooooooooooong text";
JButton button = new JButton();
button.setPreferredSize(new Dimension(30, 30));
button.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
JTextArea area = new JTextArea(text, 0, 50);
area.setEditable(false);
area.setLineWrap(true);
area.setWrapStyleWord(true);
area.append(text);
area.append(text);
area.append(text);
JOptionPane.showMessageDialog(frame, area, "why does it do this", JOptionPane.WARNING_MESSAGE);
}
});
frame.add(button);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
I would post a picture, but I don't have enough reputation...
Is there a way to fix this without having to use a JScrollPane?
Here's a screenshot:
If you run the pack command on the dialog (a function in the Window class) it will resize based on subcomponents. For your case you will have to rewrite without using the showMessageDialog() to get the resize to work (so make the dialog first, add the text, pack, then show it)
Dialog b = new Dialog();
// add stuff
b.pack();
For my test code it worked perfectly to get the dialogs to be the right sizes
Without pack()
With pack()

How to keep a TableView's selection when focus is lost?

How can I keep a TableView's selection when focus is lost to the Windows?
When a the focus to a window is lost, the selected item is still visibly selected in the window; however, I cannot find a way to access the selected object from its controllers.
I have tried using the TableView's methods getSelectionModel().selectedItemProperty().get() and getSelectionModel().getSelectedItem() but both of these return null if the focus to the window and/or table is lost.
Use a variable and set it in a change listener. I use labels for debugging.
table.getSelectionModel().getSelectedCells().addListener(new ListChangeListener<TablePosition>() {
#Override
public void onChanged(ListChangeListener.Change<? extends TablePosition> c) {
label1.setText(String.valueOf(c.getList().get(0).getRow()));
}
});
java 8
table.getSelectionModel().getSelectedCells().addListener((ListChangeListener.Change<? extends TablePosition> c) -> {
label1.setText(String.valueOf(c.getList().get(0).getRow()));
});

Extend View and Custom Dialogs

I am working on a game where I am extending the view and performing operations in the class. I need to have a popup in the game which will have 3 buttons inside it. I have managed to have the popup show-up using custom dialogs but when I configure the onClick as follows:
private void popUp() {
Context mContext = getContext();
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.custom_fullimage_dialog);
dialog.setTitle("Cheese Market");
Button one = (Button)findViewById(R.id.firstpack);
one.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
cheeseLeft = cheeseLeft + 10;
masterMoveLock = false;
return;
}
});
}
It force closes giving a nullpointerexeption even though it is defined in the custom_fullimage_dialog layout.
Can someone help me figure out how to have the button click detected in this scenario?
Thank you.
Try calling dialog.findViewById instead.
You're setting the contentView for the dialog, but by calling findViewById you're looking for it under your activity's content view.

Resources