I'm trying to create a couple of methods to let tinyMCE move the cursor to some SPANS in the text, and this works ok if all the spans are in the visible part of text, but for long documents, when a span isn't visible (have to scroll to view it), it move the caret, but the text is not scrolled:
This question shows how to move the caret, but it doesn't scroll. How can I force the editor to scroll to the caret position?.
I've found the solution, just after setting the caret position, add some text, and the editor will scroll automatically to the new position:
ed.execCommand('mceInsertContent', false, "");
#leonardorame 's answer works, but it scrolls the text into view only at the bottom of the page like so:
......
......
|
If you would rather have the caret at the top...
|
......
......
then you need a bit extra:
//save the current position
var bm = ed.selection.getBookmark(2, true);
//scroll to the end
ed.selection.select(ed.getBody(), true);
ed.selection.collapse(false);
ed.execCommand('mceInsertContent', false, ");
//scroll back up, so that the caret is now at the top
ed.selection.moveToBookmark(bm);
ed.selection.collapse(false);
ed.execCommand('mceInsertContent', false, "");
Related
I'm using iTextSharp version 4.1.6.16. I have a PdfPTable with two columns (1 row).
There is a lot of content in right cell so it spans across whole page and reaches next page.
In the left cell I only want to put some small PdfPTable at its bottom. To do it I use cell.VerticalAlignment = Element.ALIGN_BOTTOM; on the left cell of topmost table. This works well if the row is not bigger than a page.
If the row reaches next page, then the content of the left cell is indeed aligned to bottom, but to bottom of first page. So the right cell's content still continues on the next page, but the left cell is empty there (I tested with background color that it spans to next page also).
I tried setting KeepTogether on the inner table but it doesn't have any effect. I also thought about doing it with CellEvent but I couldn't find so far how to position IElement (not only Image or text) absolutely in the cell.
Is it a bug or designed behavior, that the content is aligned to the bottom of the first page the cell occupies? Is there a workaround or some better way to put content at the bottom of the cell no matter where it ends?
I've finally solved the issue with following workaround.
I created a CellEvent that gets PdfPTable and shifts it upwards as much as its content takes:
class BottomFix : IPdfPCellEvent
{
private readonly PdfPTable _content;
public BottomFix(PdfPTable content)
{
_content = content;
}
public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases)
{
_content?.WriteSelectedRows(0, -1, position.Left, position.Top + _content.TotalHeight, canvases[PdfPTable.BACKGROUNDCANVAS]);
}
}
Then to my original two-row table I added second row, and I add there a cell of height equal to 0, where instead of putting content into, I use this CellEvent. The original left cell is left empty, so the content of next row is pushed onto it and it looks as it was originally there. I don't have borders in this table so they are not an issue, but it can also be solved by setting border of this 1px cell to none.
var cell = new PdfPCell();
var table = new PdfPTable(1) { /* some content etc... */ };
cell.FixedHeight = 0;
cell.CellEvent = new BottomFix(table);
// such prepared cell goes to top level table, second row, left column
I show a context menu on right click but for every second click the right side of the menu gets clipped (about 1 to 2 character width) The basics that I can put here:
void initialise(Handler eventHandler) {
addMenuItem(eventHandler, "New", new NewAction(shell),false);
addMenuItem(eventHandler, "Edit", new EditAction(shell),false);
menuItems.add(new SeparatorMenuItem());
... more items
}
void addMenuItem(Handler eventHandler, String text, Action action, boolean isCheck) {
actions.add(action);
MenuItem it = isCheck ? new CheckMenuItem() : new MenuItem();
it.setText(text);
it.setData(action);
it.setDisable(true);
menuItems.add(it);
}
....
menu = new ContextMenu();
menu.getItems().clear();
menu.getItems().addAll(getMenuItems(getSelection()));
menu.setAutoHide(true);
...
What I've figured out is that it happens on every second right click and although the menu occupy the same rectangle, the drawn part is shifted by 12 pixels, giving the appearance that it's been clipped
You need to set the effect style to null in the code or the css file
I have a loading popup that I need to display on the top of the page, even if the user scroll down.
What I tried so far is to set the popup position as follows
setPopupPosition(Window.getClientWidth()/2 , 0);
The popup shows up on the absolut top.
The situation can be resolved easily if you view it from a different angle: Not the popup position should adjust to the page - instead, the page should scroll behind the centering popup, e.g.:
final ScrollPanel scrollPanel = new ScrollPanel();
RootLayoutPanel.get().add(scrollPanel);
pagePanel = new FlowPanel();
scrollPanel.setWidget(pagePanel);
pagePanel.add(...);
Now add the entire page contents to pagePanel (instead of adding them directly to rootPanel).
Then you can create popups like this:
final PopupPanel popupPanel = new PopupPanel();
popupPanel.add(...);
popupPanel.center();
You'll still have to re-center the popup when the window resizes, but apart from that, the popup will always be at the center in front of the scrolling page.
To achieve this you can implement Window.addWindowScrollHandler. It will always be on top whatever you do.
DialogBox dialog = new DialogBox();
dialog.setWidget(...);
Window.addWindowScrollHandler(new ScrollHandler() {
#Override
public void onWindowScroll(ScrollEvent event) {
dialog.setPopupPosition((Window.getClientWidth() - widthOfDialog) / 2, event.getScrollTop());
}
});
Hope this helps.. Thanks..
The solution that worked for me is this
setPopupPosition(Window.getClientWidth()/2 , Window.getScrollTop());
I'm creating a vertical SWT ToolBar:
ToolBar toolBar = new ToolBar( parent, SWT.RIGHT | SWT.VERTICAL );
And then adding items to it:
for ( MyObject myObject: myObjects ) {
ToolItem toolItem = new ToolItem( toolBar, SWT.NONE );
toolItem.setText( myObject.getLabel() );
toolItem.setImage( myObject.getImage() );
}
The toolbar is created correctly, but as some labels are too long, there are some cases in which new items are created on a second column, in front of the previous item.
So, instead of getting a toolbar that looks like
Item with a very long label
Tiny item
Little item
I get a toolbar that looks like
Item with a very long label
Tiny item Little item
If the long label is long enough, a third column will appear.
Does anyone know if there's a way to prevent the creation of a new column on the toolbar?
Thank you.
In my eclipse RCP application there are a few buttons & few input boxes & this below Text component. My problem is as soon as I press one of the buttons a cursor starts blinking in the below test component. Can you please let me know how to solve this.
I tried:
setting focus to false for Text.
SWT.READ_ONLY for Text .
Code:
Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_NO);
protocolFilterDescription.setCursor(cursor);
Nothing seems to get rid of this unnecessary cursor.
protocolFilterDescription = new Text(parent, SWT.NONE | SWT.READ_ONLY );
FormData protocolFilterDescriptionLData = new FormData();
protocolFilterDescriptionLData.left = new FormAttachment(0, 1000, 650);
protocolFilterDescriptionLData.top = new FormAttachment(0, 1000, 290);
protocolFilterDescriptionLData.width = 450;
protocolFilterDescriptionLData.height = 12;
protocolFilterDescription.setLayoutData(protocolFilterDescriptionLData);
protocolFilterDescription.setForeground(new Color(parent.getDisplay(),
204, 153, 0));
protocolFilterDescription.setBackground(Display.getCurrent()
.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
protocolFilterDescription.setFont(new Font(parent.getDisplay(),"Verdana",
6, 1));
protocolFilterDescription
.setText("captured");
You have to set the focus of some other SWT component to true to remove the focus from the Text component.
You'll probably have to do this in an ActionListener.
If you want to completely remove the cursor from the Text control (which implies inability to perform a selection there, etc), try calling setEnabled(false) on it.
Also, such requirement suggests that you maybe don't need Text component at all, and could use Label instead.