Monday, March 9, 2009

Files Drag and Drop in SWT application.

Below is a snippet of code which will demonstrate Files Drag and Drop in SWT application.
It is an extension of Drag and drop code available at http://www.eclipse.org/swt/snippets/

/*
* example snippet: embed Swing/AWT in SWT
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*
* @since 3.0
*/
/*
* A sample demonstration of file drag and drop
*/
import java.awt.EventQueue;
import java.awt.Point;
import java.awt.datatransfer.Transferable;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.tree.TreePath;

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.dnd.ByteArrayTransfer;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.dnd.TransferData;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.ole.win32.COM;
import org.eclipse.swt.internal.win32.TCHAR;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.awt.SWT_AWT;




public class DragnDropSWT extends ByteArrayTransfer implements Runnable {


boolean returnFlag = false;
private int[] ids;
private String[] names;

Display display = null;
Shell shell = null;


public static void main(String[] args) {
new DragnDropSWT().run();
}


protected String[] getTypeNames() {
return names;
}

protected int[] getTypeIds() {
return ids;
}


public void run() {

display = new Display();
shell = new Shell(display);
shell.setText("SWT File Drag and Drop Example");

Listener exitListener = new Listener() {
public void handleEvent(Event e) {
MessageBox dialog = new MessageBox(shell, SWT.OK | SWT.CANCEL | SWT.ICON_QUESTION);
dialog.setText("Question");
dialog.setMessage("Exit?");
if (e.type == SWT.Close) e.doit = false;
if (dialog.open() != SWT.OK) return;
shell.dispose();
}
};
Listener aboutListener = new Listener() {
public void handleEvent(Event e) {
final Shell s = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
s.setText("About");
GridLayout layout = new GridLayout(1, false);
layout.verticalSpacing = 20;
layout.marginHeight = layout.marginWidth = 10;
s.setLayout(layout);
Label label = new Label(s, SWT.NONE);
label.setText("SWT and AWT Example.");
Button button = new Button(s, SWT.PUSH);
button.setText("OK");
GridData data = new GridData();
data.horizontalAlignment = GridData.CENTER;
button.setLayoutData(data);
button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
s.dispose();
}
});
s.pack();
Rectangle parentBounds = shell.getBounds();
Rectangle bounds = s.getBounds();
int x = parentBounds.x + (parentBounds.width - bounds.width) / 2;
int y = parentBounds.y + (parentBounds.height - bounds.height) / 2;
s.setLocation(x, y);
s.open();
while (!s.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
}
};
shell.addListener(SWT.Close, exitListener);
Menu mb = new Menu(shell, SWT.BAR);
MenuItem fileItem = new MenuItem(mb, SWT.CASCADE);
fileItem.setText("&File");
Menu fileMenu = new Menu(shell, SWT.DROP_DOWN);
fileItem.setMenu(fileMenu);
MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
exitItem.setText("&Exit\tCtrl+X");
exitItem.setAccelerator(SWT.CONTROL + 'X');
exitItem.addListener(SWT.Selection, exitListener);
MenuItem aboutItem = new MenuItem(fileMenu, SWT.PUSH);
aboutItem.setText("&About\tCtrl+A");
aboutItem.setAccelerator(SWT.CONTROL + 'A');
aboutItem.addListener(SWT.Selection, aboutListener);
shell.setMenuBar(mb);

RGB color = shell.getBackground().getRGB();



final Composite comp = new Composite(shell, SWT.NONE);
final Tree fileTree = new Tree(comp, SWT.SINGLE | SWT.BORDER);
Sash sash = new Sash(comp, SWT.VERTICAL);
Composite tableComp = new Composite(comp, SWT.EMBEDDED);
Label separator3 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
Composite statusComp = new Composite(shell, SWT.EMBEDDED);

sash.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
if (e.detail == SWT.DRAG) return;
GridData data = (GridData)fileTree.getLayoutData();
Rectangle trim = fileTree.computeTrim(0, 0, 0, 0);
data.widthHint = e.x - trim.width;
comp.layout();
}
});

File[] roots = File.listRoots();
for (int i = 0; i <>
File file = roots[i];
TreeItem treeItem = new TreeItem(fileTree, SWT.NONE);
treeItem.setText(file.getAbsolutePath());
treeItem.setData(file);
new TreeItem(treeItem, SWT.NONE);
}

fileTree.addListener(SWT.Expand, new Listener() {
public void handleEvent(Event e) {
TreeItem item = (TreeItem)e.item;
if (item == null) return;
if (item.getItemCount() == 1) {
TreeItem firstItem = item.getItems()[0];
if (firstItem.getData() != null) return;
firstItem.dispose();
} else {
return;
}
File root = (File)item.getData();
File[] files = root.listFiles();
if (files == null) return;
for (int i = 0; i <>
File file = files[i];
//if (file.isDirectory()) {
TreeItem treeItem = new TreeItem(item, SWT.NONE);
treeItem.setText(file.getName());
treeItem.setData(file);
if (file.isDirectory()){
new TreeItem(treeItem, SWT.NONE);
}
//}
}
}
});
fileTree.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
TreeItem item = (TreeItem)e.item;
if (item == null) return;
final File root1 = (File)item.getData();
final File root = new File("c:\\temp");
System.out.println("Root " + item.getData());
EventQueue.invokeLater(new Runnable() {
public void run() {
//statusLabel.setText(root1.getAbsolutePath());
//locationText.setText(root1.getAbsolutePath());
}
});
}
});

Transfer[] types = new Transfer[] { FileTransfer.getInstance() };
int operations = DND.DROP_DEFAULT | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_MOVE;
final DragSource dragSource = new DragSource(fileTree, DND.DROP_COPY | DND.DROP_MOVE);
dragSource.setTransfer(types);
final TreeItem[] dragSourceItem = new TreeItem[1];
final File dragFiles = new File("C:\\temp\\test");
dragSource.addDragListener(new DragSourceListener() {
TreeItem[] dndSelection = null;

String[] sourceNames = null;

public void dragStart(DragSourceEvent event) {
dndSelection = fileTree.getSelection();
sourceNames = null;
event.doit = dndSelection.length > 0;
}

public void dragFinished(DragSourceEvent event) {
dndSelection = null;
sourceNames = null;

}

public void dragSetData(DragSourceEvent event) {
if (dndSelection == null || dndSelection.length == 0)
return;
if (!FileTransfer.getInstance().isSupportedType(event.dataType))
return;

sourceNames = new String[dndSelection.length];
for (int i = 0; i <>
File file = (File) dndSelection[i].getData();
sourceNames[i] = file.getAbsolutePath();
}
event.data = sourceNames;
}
});
DropTarget target = new DropTarget(fileTree, operations);
target.setTransfer(new Transfer[] { FileTransfer.getInstance() });
target.addDropListener(new DropTargetAdapter() {

public void dragOver(DropTargetEvent event) {
System.out.println("Dargged Over");

}

public void drop(DropTargetEvent event) {

System.out.println("DROOPED Over" + event.item.getData());
if (event.detail == DND.DROP_DEFAULT) {
if ((event.operations & DND.DROP_COPY) != 0) {
event.detail = DND.DROP_COPY;
} else if ((event.operations & DND.DROP_LINK) != 0) {
event.detail = DND.DROP_LINK;
} else if ((event.operations & DND.DROP_MOVE) != 0) {
event.detail = DND.DROP_MOVE;
}

}

String fileList[] = null;
FileTransfer ft = FileTransfer.getInstance();
if (ft.isSupportedType(event.currentDataType)) {
fileList = (String[])event.data;
}

for (int i = 0; i <>
File file = new File(fileList[i]);

TreeItem item = (TreeItem)event.item;
TreeItem treeItem = new TreeItem(item, SWT.NONE);

File f2 = new File(event.item.getData()+ "\\" + file.getName());
treeItem.setText(f2.getName());
treeItem.setData(f2);
try {
BufferedInputStream is = new BufferedInputStream(new FileInputStream(file.getAbsolutePath()));
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(f2));
int size = 4096;
byte[] buffer = new byte[size];
int len;
while ((len = is.read(buffer, 0, size)) > 0) {
os.write(buffer, 0, len);
}


} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

public void dragEnter(DropTargetEvent event)
{
System.out.println("DROOPED Enter");

if (event.detail == DND.DROP_DEFAULT) {
if ((event.operations & DND.DROP_COPY) != 0) {
event.detail = DND.DROP_COPY;
} else if ((event.operations & DND.DROP_LINK) != 0) {
event.detail = DND.DROP_LINK;
} else if ((event.operations & DND.DROP_MOVE) != 0) {
event.detail = DND.DROP_MOVE;
}
}

}


});

GridLayout layout = new GridLayout(1, false);
layout.marginWidth = layout.marginHeight = 0;
layout.horizontalSpacing = layout.verticalSpacing = 1;
shell.setLayout(layout);
GridData data;
//
layout = new GridLayout(1, false);
layout.marginWidth = layout.marginHeight = 0;
layout.horizontalSpacing = layout.verticalSpacing = 1;
shell.setLayout(layout);
comp.setLayout(layout);
data = new GridData(GridData.FILL_VERTICAL);
data.widthHint = 200;
data.heightHint = 300;
fileTree.setLayoutData(data);
data = new GridData(GridData.FILL_VERTICAL);
sash.setLayoutData(data);
data = new GridData(GridData.FILL_BOTH);
tableComp.setLayoutData(data);

shell.open();
shell.setSize(250,500);

while(!shell.isDisposed()) {

if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

}

Life of mountain

As told in TPM CHURCH, ROYAPETTA 08-MAR-2009 SUNDAY SERVICE

1 King 18:42 "So Ahab went off to eat and drink, but Elijah climbed to the top of Carmel, bent down to the ground and put his face between his knees."

Here we read, when Elijah climbed to the top of the mountain,there are lot of things happened in the land. Our lord will do great things to the people who have the experience of climbing to the top of mountain for praying.

What does Climbing to the top of mountain reveals?
It reveals four things in the life of the child of God.


1 Kings 18:42 First it reveals a Life of Suffering. Climbing to the top of mountain is not an easy job. While climbing you can hear the beats of heart. A child of God must be ready to take the suffering.

Second it brings Peace
Psalm 72:3 "The mountains will bring prosperity to the people, the hills the fruit of righteousness."
Psalm 119:165 "Great peace have they who love your law, and nothing can make them stumble."

Third it shows Life of Prayer
Luke 6:12 "The Twelve Apostles One of those days Jesus went out to a mountainside to pray, and spent the night praying to God".

Fourth it shows Holiness in Life
Zechariah 8:3 This is what the LORD says: "I will return to Zion and dwell in Jerusalem. Then Jerusalem will be called the City of Truth, and the mountain of the LORD Almighty will be called the Holy Mountain."

Again we read in 1 Kings 18:45 "Meanwhile, the sky grew black with clouds, the wind rose, a heavy rain came on and Ahab rode off to Jezreel".

Here we see that while Elijah prayed three changes happened to the land. We will examine them one by one.

First, "the sky grew black with clouds".What does the sign of clouds reveals?

First it shows a Leading in the life of Gods child.
Numbers 9:17 "Whenever the cloud lifted from above the Tent, the Israelites set out; wherever the cloud settled, the Israelites encamped."

Second it shows Life of testimony.
Hebrews 12 :1 "Therefore, since we are surrounded by such a great cloud of witnesses, "
What kind of testimony we have in our life?
In John 1:36 John , the baptist is saying "When he saw Jesus passing by, he said, "Look, the Lamb of God!"
Whether we are witness to God in our life? In what all ways a child of God should be witness to Lord?
In Acts 1:8 "But you will receive power when the Holy Spirit comes on you; and you will be my witnesses in Jerusalem, and in all Judea and Samaria, and to the ends of the earth."
Here Jerusalem shows , witness in the church, Judea shows witness in the home, samria shows witness in the land and ends to the earth shows all over the world.

Third it shows "caught up in the soon coming of Jesus"
1 Thessolians 4:17 17 "After that, we who are still alive and are left will be caught up together with them in the clouds to meet the Lord in the air."

The wind revelas Holy Sprit
Song of Solomon 4:16 16 "Awake, north wind, and come, south wind! Blow on my garden, that its fragrance may spread abroad. Let my lover come into his garden and taste its choice fruits."
Our lover is Jesus Christ.The church is the garden of the lord and we are the fruits. It oue duty to bear good fruits to our master when north wind and south wind blows.

The Great Rain shows Revival:
In Psalms 68:9 "You gave abundant showers, O God; you refreshed your weary inheritance.

Lets have a life of mountain , the Lord will do great things for us.
May the Lord bless you.


Tuesday, March 3, 2009

In the year that King Uzziah died

As told in TPM CHURCH, ROYAPETTA 22-FEB-2009 SUNDAY SERVICE

Isaiah 6:1-2
1 In the year that King Uzziah died, I saw the Lord seated on a throne, high and exalted, and the train of his robe filled the temple. 2 Above him were seraphs, each with six wings: With two wings they covered their faces, with two they covered their feet, and with two they were flying.

Inorder for us to saw the Lord seated on a throne, high and exalted, the King Uzziah in our life should be died. Below we will examine 4 important characters of Uzziah in our life.

2 Chronicles 26:16 "But after Uzziah became powerful, his pride led to his downfall".
His pride was one of the main reason for the downfall of Uzziah. Once we are in pride we will start speaking against God, servants of God and his people. The devil will start work in us.

2 Chronicles 26:16 "He was unfaithful to the LORD his God, and entered the temple of the LORD to burn incense on the altar of incense."
Next is he was unfaithful to God. The next step that will proceed is Unfaithfulness. Lets examine whether we are faithful in the eyes of the Lord. Lets analyze we are able to fulfill the promise s you had with the Lord. Eventhough the Lord i faithful we are unfaithful to Lord.

2 Chronicles 26:19 "Uzziah, who had a censer in his hand ready to burn incense, became angry"
He became angry at the altar. Lets analyse whether we rae anger at God, servants of God and your fellow belivers. if so repent and come back.

2 Chronicles 26:20 "When Azariah the chief priest and all the other priests looked at him, they saw that he had leprosy on his forehead,21 He lived in a separate house [d] —leprous, and excluded from the temple of the LORD."
He lived separate. He lost the fellowship with the God and lived separately from God.

Dear, the lord will give us a chance for repentance if we are not able to utilize the chance we will become a leprosy and we wil lose the fellowship with the God.

2 Timothy 2:15
Do your best to present yourself to God as one approved, a workman who does not need to be ashamed and who correctly handles the word of truth.
2 Corinthians 7:1
Since we have these promises, dear friends, let us purify ourselves from everything that contaminates body and spirit, perfecting holiness out of reverence for God.

May GOD bless you.

Whom the Lord cares and what we have to do if we want us to be cared by the Lord.

As told in TPM CHURCH, ROYAPETTA 01-MAR-2009 SUNDAY SERVICE

Nahum 1:7 The LORD is good, a refuge in times of trouble.

He cares for those who trust in him,

Lets see Whom the Lord cares and what we have to do if we want us to be cared by the Lord.
The lord cares the person whom he knows. For us to known and cared by the Lord we have to posses five characteristics.

In John 10:27; it is written; "My sheep listen to my voice; I know them, and they follow me."

Here it is talking about a shepherd and his sheep. A good sheperd will lay down his life for his sheep and he will know them by name.He goes on ahead of them, and his sheep follow him because they
know his voice. David was a shepehred and he look after his fathers sheep. When a bear and lion came he fought for his sheep by laying down his life. JESUS is our shepherd and we are his sheep. If we are able to listen to his voice , he will know us and we will be able to follow him. If we are giving room for strange voice, then our life will be in the hands of the devil.

Genesis 22:12; it is written; "Do not lay a hand on the boy," he said. "Do not do anything to him. Now I know that you fear God, because you have not withheld from me your son, your only son."

The second point is God knows the man who fears him and able to execute his commandes without questioning. Abraham had only one son , Issac and he is the only son at his old age. God commanded
him to give his one and only one son as a sacrifice. In normal common sense he can argue with the God and he may not sacrifice his son. But he had a strong beliefe and fear in God that he exeuted what God has said to him without questioning.

Exodus 33:17; it is written; And the LORD said to Moses, "I will do the very thing you have asked, because I am pleased with you and I know you by name."

The third point is God knows the man whom he is pleased with. For the Lord to be pleased with us first we have to humbled in the presence of God. We should be hide under the arms of God. We should not reveal ourselves and we should wait until the Day of God Comes. In the life of Moses, he tried to show himslef befor the day fo God comes. One day he went outside from the palace of Paroha and saw on Egyptian and Isralian on fighting. He interfere in their matter and killed the Egyptian. Since he did this without the consent of God, God have to hid him in forty years at the land of Midian until the day of God comes.

1 Corinthians 8:3; it is written; "But the man who loves God is known by God."
The fourth point is God knows the man who loves him. Lets analyse whether we are loving the God or we are loving the world. If we are loving the world or any earthly matters we are not able to love our
God.

Nahum 1:7 The LORD is good, a refuge in times of trouble. He cares(knows) for those who trust in him

The last point is God knows the man who trust in him. Lets analyse where we are putting our trust in GOD or in World. Lets lay all your burdens on the Lord rather than carrying on your shoulders. Lets the God will take care and be hide under the arms of God.

Be silent in the presence of GOD and the Lord will fight for you.

May GOD bless you