Thursday, June 20, 2013

How to print selected area in zk

Step 1.
 add <zk xmlns:w="client">  tag.

Step 2.

    <button label="Print">
        <attribute w:name="onClick">
            print(this,'group',500,800,true);//
        </attribute>
    </button>
Parameter group box.
1. "group" id of groupbox.
2. 500 windows height.
3. 800 windows width.
4. true for style if true style will apply otherwise style not apply.




Full Page


 Print listbox with style
 code
    print Listbox with style:
    <button label="Print">
        <attribute w:name="onClick">
            print(this,'box1',500,800,true);
        </attribute>
    </button>
    <listbox id="box1" multiple="true" checkmark="true">

 Print Groupbox.

code.
Print Box Area:
    <button label="Print">
        <attribute w:name="onClick">
            print(this,'group',500,800,true);
        </attribute>
    </button>
<groupbox id="group" >
 Print Grid.
code.
        print Grid:
    <button label="Print">
        <attribute w:name="onClick">
            print(this,'grid',500,800,true);
        </attribute>
    </button>
    <grid id="grid">
 Print Listbox without style
code.
    print Listbox without style:
    <button label="Print">
        <attribute w:name="onClick">
            print(this,'box',500,800,false);
        </attribute>
    </button>
    <listbox id="box" multiple="true" checkmark="true">




 Full source code.
print.zul

<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk xmlns:w="client">
<script><![CDATA[
function print(obj,id,height,width,style) {
DispWin = window.open('', '', 'toolbar=no,memubar=no,scrollbars=yes,status=no,width='+width+'px,height='+height+"px'");

DispWin.document.write('<html><head>');
if(style==true){
for(var i=0;i<document.styleSheets.length;i++){
    if(document.styleSheets[i].href != null)        {
        DispWin.document.write('<link rel="stylesheet" type="text/css" href="'+document.styleSheets[i].href+'">');
    }
}
}
DispWin.document.write('</head>');
DispWin.document.write('<body>');
DispWin.document.write('<p align="center"><input type="button" value="Close" onclick="window.close()"/>&nbsp&nbsp&nbsp&nbsp<input type="button" value="Print" onclick="print()"/></p>');
DispWin.document.write($(obj.$f(id)).formhtml());
DispWin.document.write('</body></html>');
DispWin.document.close();
//DispWin.close();
//DispWin.print();


(function($) {
      var oldHTML = $.fn.html;

      $.fn.formhtml = function() {
        if (arguments.length) return oldHTML.apply(this,arguments);
        $("input,button", this).each(function() {
          this.setAttribute('value',this.value);   
          this.setAttribute('readonly',true);
        });
        $("textarea", this).each(function() {
          // updated - thanks Raja!
          this.innerHTML = this.value;
        });
        $("input:radio,input:checkbox", this).each(function() {
          // im not really even sure you need to do this for "checked"
          // but what the heck, better safe than sorry
          if (this.checked) this.setAttribute('checked', 'checked');
          else this.removeAttribute('checked');
        });
        $("option", this).each(function() {
          // also not sure, but, better safe...
          if (this.selected) this.setAttribute('selected', 'selected');
          else this.removeAttribute('selected');
        });
        return oldHTML.apply(this);
      };

      //optional to override real .html() if you want
      // $.fn.html = $.fn.formhtml;
    })(jQuery);


]]></script>
Print Box Area:
    <button label="Print">
        <attribute w:name="onClick">
            print(this,'group',500,800,true);
        </attribute>
    </button>
<groupbox id="group" >
<caption
                label="Box"
                sclass="group-header"/>
    print Listbox with style:
    <button label="Print">
        <attribute w:name="onClick">
            print(this,'box1',500,800,true);
        </attribute>
    </button>
    <listbox id="box1" multiple="true" checkmark="true">
        <listhead>
            <listheader label="Name" />
            <listheader label="Gender" />
            <listheader label="Age" />
        </listhead>
        <listitem>
            <listcell label="Mary" />
            <listcell label="FEMALE" />
            <listcell label="18" />
        </listitem>
        <listitem>
            <listcell label="John" />
            <listcell label="MALE" />
            <listcell label="20" />
        </listitem>
        <listitem>
            <listcell label="Jane" />
            <listcell label="FEMALE" />
            <listcell label="32" />
        </listitem>
        <listitem>
            <listcell label="Henry" />
            <listcell label="MALE" />
            <listcell label="29" />
        </listitem>
        <listitem>
            <listcell label="Mark" />
            <listcell label="MALE" />
            <listcell label="15" />
        </listitem>
    </listbox>
    print Listbox without style:
    <button label="Print">
        <attribute w:name="onClick">
            print(this,'box',500,800,false);
        </attribute>
    </button>
    <listbox id="box" multiple="true" checkmark="true">
        <listhead>
            <listheader label="Name" />
            <listheader label="Gender" />
            <listheader label="Age" />
        </listhead>
        <listitem>
            <listcell label="Mary" />
            <listcell label="FEMALE" />
            <listcell label="18" />
        </listitem>
        <listitem>
            <listcell label="John" />
            <listcell label="MALE" />
            <listcell label="20" />
        </listitem>
        <listitem>
            <listcell label="Henry" />
            <listcell label="MALE" />
            <listcell label="29" />
        </listitem>
        <listitem>
            <listcell label="Mark" />
            <listcell label="MALE" />
            <listcell label="15" />
        </listitem>
        <listitem>
            <listcell label="Jeffery" />
            <listcell label="MALE" />
            <listcell label="17" />
        </listitem>
    </listbox>
        print Grid:
    <button label="Print">
        <attribute w:name="onClick">
            print(this,'grid',500,800,true);
        </attribute>
    </button>
    <grid id="grid">
    <auxhead>
        <auxheader label="H1'07" colspan="6"/>
        <auxheader label="H2'07" colspan="6"/>
    </auxhead>
    <auxhead>
        <auxheader label="Q1" colspan="3"/>
        <auxheader label="Q2" colspan="3"/>
        <auxheader label="Q3" colspan="3"/>
        <auxheader label="Q4" colspan="3"/>
    </auxhead>
    <columns>
        <column label="Jan"/><column label="Feb"/><column label="Mar"/>
        <column label="Apr"/><column label="May"/><column label="Jun"/>
        <column label="Jul"/><column label="Aug"/><column label="Sep"/>
        <column label="Oct"/><column label="Nov"/><column label="Dec"/>
    </columns>
    <rows>
        <row>
            <label value="1,000"/><label value="1,100"/><label value="1,200"/>
            <label value="1,300"/><label value="1,400"/><label value="1,500"/>
            <label value="1,600"/><label value="1,700"/><label value="1,800"/>
            <label value="1,900"/><label value="2,000"/><label value="2,100"/>
        </row>
        <row>
            <label value="1,500"/><label value="2,100"/><label value="1,200"/>
            <label value="1,100"/><label value="2,400"/><label value="1,700"/>
            <label value="1,500"/><label value="3,700"/><label value="1,800"/>
            <label value="1,300"/><label value="2,000"/><label value="2,500"/>
        </row>
    </rows>
</grid>
    </groupbox>
</zk>




Tuesday, June 18, 2013

How to Drop your file using dropupload in zk




index.zul


<?page title="Auto Generated index.zul"?>
<window title="Drop here" border="normal" width="100%" height="100%"
    apply="org.zkoss.bind.BindComposer"
    viewModel="@id('vm') @init('com.demo.DropFileViewModel')">

    <dropupload maxsize="5120" detection="none"
        onUpload="@command('doUpload')">
    </dropupload>
   
    <button label="Download" onClick="@command('doDownload')"></button>


</window>

DropFileViewModel.java

package com.demo;

import org.zkoss.bind.BindContext;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.util.media.Media;
import org.zkoss.zhtml.Filedownload;
import org.zkoss.zk.ui.event.UploadEvent;
import org.zkoss.zul.Messagebox;

public class DropFileViewModel {
    Media media;

    @Command
    public void doUpload(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) {
        UploadEvent upEvent = null;
        Object objUploadEvent = ctx.getTriggerEvent();
        if (objUploadEvent != null && (objUploadEvent instanceof UploadEvent)) {
            upEvent = (UploadEvent) objUploadEvent;
        }
        if (upEvent != null) {
            media = upEvent.getMedia();
            Messagebox.show("File Uploaded: " + media.getName());

        }
    }

    @Command
    public void doDownload() {
        if (media != null)
            Filedownload.save(media);
        else
            Messagebox.show("First Drop Your File");

    }
}

Check online demo here

how to create menu in android

menu.xml
<?xml version="1.0" encoding="utf-8"?>
    <!-- Single menu item
         Set id, icon and Title for each menu item
    -->
    <item android:id="@+id/menu_bookmark"
          android:icon="@drawable/icon_bookmark"
          android:title="Bookmark" />
    <item android:id="@+id/menu_save"
          android:icon="@drawable/icon_save"
          android:title="Save" />
    <item android:id="@+id/menu_search"
          android:icon="@drawable/icon_search"
          android:title="Search" />
    <item android:id="@+id/menu_share"
          android:icon="@drawable/icon_share"
          android:title="Share" />
    <item android:id="@+id/menu_delete"
          android:icon="@drawable/icon_delete"
          android:title="Delete" /> 
    <item android:id="@+id/menu_preferences"
          android:icon="@drawable/icon_preferences"
          android:title="Preferences" />
</menu>


///////////////////////////////

 // Initiating Menu XML file (menu.xml)
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.layout.menu, menu);
        return true;
    }
     
    /**
     * Event Handling for Individual menu item selected
     * Identify single menu item by it's id
     * */
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
         
        switch (item.getItemId())
        {
        case R.id.menu_bookmark:
            // Single menu item is selected do something
            // Ex: launching new activity/screen or show alert message
            Toast.makeText(AndroidMenusActivity.this, "Bookmark is Selected", Toast.LENGTH_SHORT).show();
            return true;
        case R.id.menu_save:
            Toast.makeText(AndroidMenusActivity.this, "Save is Selected", Toast.LENGTH_SHORT).show();
            return true;
        case R.id.menu_search:
            Toast.makeText(AndroidMenusActivity.this, "Search is Selected", Toast.LENGTH_SHORT).show();
            return true;
        case R.id.menu_share:
            Toast.makeText(AndroidMenusActivity.this, "Share is Selected", Toast.LENGTH_SHORT).show();
            return true;
        case R.id.menu_delete:
            Toast.makeText(AndroidMenusActivity.this, "Delete is Selected", Toast.LENGTH_SHORT).show();
            return true;
        case R.id.menu_preferences:
            Toast.makeText(AndroidMenusActivity.this, "Preferences is Selected", Toast.LENGTH_SHORT).show();
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }   
}







































Thursday, June 13, 2013

how to set alt tag in zk

<zk xmlns:ca="client/attribute">

<image src="abc" ca:alt="image not found" ca:title="image title" />

</zk>

how to get after 5 days date

Calendar currentDate = Calendar.getInstance();
        Calendar prevDay = (Calendar) currentDate.clone();
        prevDay.add (Calendar.DAY_OF_YEAR, 5);
        System.out.println ("After 5 Day: " + prevDay.getTime());

How to get previous 7 day Date

Calendar currentDate = Calendar.getInstance();
        Calendar prevDay = (Calendar) currentDate.clone();
        prevDay.add (Calendar.DAY_OF_YEAR, -7);
        System.out.println ("Previous 7 Day: " + prevDay.getTime());

Thursday, May 30, 2013

How to fixed first tab and rest tab will be scroll in zk.

<zk xmlns:w="client">
    <tabbox width="200px">
        <tabs>
            <attribute w:name="bind_"><![CDATA[
                function (a, b, c) {
                    this.$bind_(a, b, c);
                    var first = this.firstChild,
                        second;
                    if (first) {
                        second = first.nextSibling;
                        if (second) {
                            var header = this.$n('header'),
                                fn = first.$n(),
                                $fn = jq(fn),
                                fofs = $fn.offset(),
                                fnstyle = fn.style;
                            fnstyle.position = 'absolute';
                            fnstyle.zIndex = 9999;
                            second.$n().style.marginLeft = $fn.outerWidth() + 'px';
                            header.onscroll = function () {
                                fnstyle.left = header.scrollLeft + 'px';
                            };
                        }
                    }
                }
            ]]></attribute>
            <attribute w:name="_doClick"><![CDATA[
                function(evt) {
                    var cave = this.$n("cave"),
                        allTab =  jq(cave).children(),
                        count = allTab.length;
                   
                    if (!allTab.length) return; // nothing to do   
                   
                    var ele = evt.domTarget,
                        move = 0,
                        tabbox = this.getTabbox(),
                        head = this.$n("header"),
                        scrollLength = tabbox.isVertical() ? head.scrollTop : head.scrollLeft;
                    if (ele.id == this.uuid + "-left") {//Scroll to next left tab
                        if (count > 0)
                            scrollLength += jq(allTab[0]).outerWidth();
                        for (var i = 0; i < count; i++) {
                            if (allTab[i].offsetLeft >= scrollLength) {
                                //if no Sibling tab no sroll
                                var tabli = jq(allTab[i]).prev("li")[0];
                                if (!tabli)  return;
                                move = scrollLength - tabli.offsetLeft;
                                if (isNaN(move)) return;
                                this._doScroll("left", move);
                                return;
                            };
                        };
                        move = scrollLength - allTab[allTab.length-1].offsetLeft;
                        if (isNaN(move)) return;
                        this._doScroll("left", move);
                        return;
                    } else {
                        this.$_doClick(evt);
                    }
                }
            ]]></attribute>
            <tab label="tab 1" />
            <tab label="tab 2 long" />
            <tab label="tab 3 long long long" />
            <tab label="tab 4 long" />
            <tab label="tab 5" />
            <tab label="tab 6" />
            <tab label="tab 7" />
        </tabs>
        <tabpanels>
            <tabpanel>tabpanel 1</tabpanel>
            <tabpanel>tabpanel 2</tabpanel>
            <tabpanel>tabpanel 3</tabpanel>
            <tabpanel>tabpanel 4</tabpanel>
            <tabpanel>tabpanel 5</tabpanel>
            <tabpanel>tabpanel 6</tabpanel>
            <tabpanel>tabpanel 7</tabpanel>
        </tabpanels>
    </tabbox>
</zk>

How ChatGPT can Benefit Coding: Your Guide to Leveraging an AI Language Model

 Introduction: Hello, coders! Welcome to this blog post on how ChatGPT, an AI language model, can benefit your coding skills and projects. A...