0

Ctrl+C, Ctrl+V event

asked 2008-09-03 13:35:34 +0800

redchris gravatar image redchris
96 1

Hi,

I'm trying to set an event on a spreadsheet (ZK spreadsheet), that when I press Ctrl+C to copy the content of the cell and, when I press Ctrl+V to paste it in other cell. I'm doing this in Java.

if (event instanceof KeyEvent)
{
int code = ((KeyEvent)event).getKeyCode();
Position pos;
if(67 == code)
{//mark copy
pos = spreadSheet.getCellFocus();
copyrow = pos.getRow();
copycol = pos.getColumn();
}
if(86 == code)
{//do paste
pos = spreadSheet.getCellFocus();
int row = pos.getRow();
int col = pos.getColumn();
Cell cell = sheet.getCell(copyrow,copycol);
if(cell!=null)
{
sheet.copyCell(cell,row,col);
}
}
}

And on the spreadsheet I put this : spreadSheet.addEventListener(Events.ON_CTRL_KEY, this);

In ZK script I saw how to do it.. but in Java... I don't know how to put the right listener. If anyone can help me...

Thanks!

Best regards,
Cristina

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2008-09-03 14:13:25 +0800

redchris gravatar image redchris
96 1

updated 2013-01-28 06:17:35 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

This is the example in ZK:

<window>        
    <zscript>
        int copyrow;
        int copycol;
        boolean copy = false;
    </zscript>
    <hbox>Key Event:<label id="lab2"/></hbox>
    <spreadsheet id="ss1" src="/WEB-INF/xls/demo/travel.xls" maxrows="11" maxcolumns="20" height="246px" width="98%" >
        <attribute name="ctrlKeys">@c^c^v</attribute>
        <attribute name="onCtrlKey">
            lab2.value = "Key Code:"+event.keyCode+" , "+"Ctrl:"+event.ctrlKey+" , "+"Alt:"+event.altKey;

            if(event.keyCode==67){//mark copy 
                copy=true;
                var pos = ss1.cellFocus;
                copyrow = pos.row;
                copycol = pos.column;
            }
            if(event.keyCode==86){//do paste
                var pos = ss1.cellFocus;
                int row = pos.row;
                int col = pos.column;
                var sheet = ss1.getSelectedSheet();
                var cell = sheet.getCell(copyrow,copycol);
                if(cell!=null){
                    sheet.copyCell(cell,row,col);
                }
            }
        </attribute>
    </spreadsheet>
</window>

And I am trying to do the same in java. The part with behavior it's ok, but I don't know How to put the event on spreadsheet

link publish delete flag offensive edit

answered 2008-09-03 15:56:27 +0800

robertpic71 gravatar image robertpic71
1275 1

updated 2008-09-03 16:03:22 +0800

I use your example to "test" my composerknowledge.

You have 2 choices to implement javacode to you zul-file:
1.) extends a GUI-Component with the use-attribute (use="package.class")
2.) use a composer, i.e. install with apply="package.class" in the rootwindow


Each variant has advantages. When you override the GUI-Component you can create your own variant of the spreadsheet component (including copy/paste).
You can use it with: <spreadsheet use="package.yourclass..> or override do a fix override in the lang-addon.xml or create a macrocomponent...

On the other side: a central eventhandler like the composer, make the developers life easier (and reduces the references between the components)

/Robert

@ZK Team:
I'm not sure about the

   public void onCtrlKey$ss1(ForwardEvent genericEvent) {
	KeyEvent event = (KeyEvent) genericEvent.getOrigin();

but i get errors, when i try onCtrlKey$ss1(KeyEvent event) or ..(Event event) and cast to KeyEvent.
Is there a smarter way?

link publish delete flag offensive edit

answered 2008-09-03 15:58:38 +0800

robertpic71 gravatar image robertpic71
1275 1

Here are the examples:
1.) extends the GUI-Component:

<spreadsheet id="ss1" src="/WEB-INF/xls/OD-IP-Adressen.xls"  maxcolumns="20" height="600px" width="98%" 
    use="Spread1" ctrlKeys="@c^c^v"/>

the Javaclass has to extend the gui-component
public class Spread1 extends Spreadsheet implements AfterCompose {

    int copyrow;
    int copycol;
    boolean copy = false;
    Label lab2; // autowired

    public void afterCompose() {
	Components.wireVariables(this, this); // wire components

    }
    public void onCtrlKey(KeyEvent event) {
	lab2.setValue("Key Code:"+ event.getKeyCode() + " , "+"Ctrl:"+ event.isCtrlKey() +" , "+"Alt:"+ event.isAltKey());

	if(event.getKeyCode()==67){//mark copy
	    copy=true;
	    Position pos = this.getCellFocus();
	    copyrow = pos.getRow();
	    copycol = pos.getColumn();
	}
	if(event.getKeyCode()==86){//do paste
	    Position pos = this.getCellFocus();
	    int row = pos.getRow();
	    int col = pos.getColumn();
	    Sheet sheet = this.getSelectedSheet();
	    Cell cell = sheet.getCell(copyrow,copycol);
	    if(cell!=null){
		sheet.copyCell(cell,row,col);
	    }
	}
    }
}

link publish delete flag offensive edit

answered 2008-09-03 16:00:45 +0800

robertpic71 gravatar image robertpic71
1275 1
Variant 2, use the generic composer
<window apply="Spread2">
<zscript>
int copyrow;
int copycol;
boolean copy = false;
</zscript>
<hbox>Key Event:<label id="lab2"/></hbox>
<spreadsheet id="ss1" src="/WEB-INF/xls/OD-IP-Adressen.xls"  maxcolumns="20" height="600px" width="98%" ctrlKeys="@c^c^v"/>
</window>
public class Spread2 extends GenericForwardComposer {

    int copyrow;
    int copycol;
    boolean copy = false;
    Label lab2;       // autowired
    Spreadsheet ss1;  // autowired
   
 
    public void onCtrlKey$ss1(ForwardEvent genericEvent) {
	KeyEvent event = (KeyEvent) genericEvent.getOrigin();
	lab2.setValue("Key Code:"+ event.getKeyCode() + " , "+"Ctrl:"+ event.isCtrlKey() +" , "+"Alt:"+ event.isAltKey());

	if(event.getKeyCode()==67){//mark copy
	    copy=true;
	    Position pos = ss1.getCellFocus();
	    copyrow = pos.getRow();
	    copycol = pos.getColumn();
	}
	if(event.getKeyCode()==86){//do paste
	    Position pos = ss1.getCellFocus();
	    int row = pos.getRow();
	    int col = pos.getColumn();
	    Sheet sheet = ss1.getSelectedSheet();
	    Cell cell = sheet.getCell(copyrow,copycol);
	    if(cell!=null){
		sheet.copyCell(cell,row,col);
	    }
	}
    }
}
link publish delete flag offensive edit

answered 2008-09-04 01:07:05 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

Robert,

I know what you mean. I will see if we can "unwrap" the ForwardEvent automatically.

I think I will only "unwarp" the ForwardEvent if and only if the developer say so by giving specific Event class in their event listener.
That is, only in such case:

onCtrlKey$ss1(KeyEvent event) 

But not in such cases:

onCtrlKey$ss1(Event event)

or

onCtrlKey$ss1(ForwardEvent event)

What do you think?

link publish delete flag offensive edit

answered 2008-09-04 03:51:23 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

Follow this feature tracker.

https://sourceforge.net/tracker/index.php?func=detail&aid=2092356&group_id=152762&atid=785194

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2008-09-03 13:35:34 +0800

Seen: 524 times

Last updated: Jan 28 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More