Win a copy of High Performance Python for Data Analytics this week in the Python forum!

Hetal Seth

Greenhorn
+ Follow
since Jun 18, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Hetal Seth

Hi,
Check if this helps you.
MouseMotionListener mml = new MouseMotionAdapter()
{
public void mouseMoved(MouseEvent e)
{
JTree tree = (JTree) e.getComponent();
TreePath path = tree.getPathForLocation(e.getX(), e.getY());
int selRow = tree.getRowForLocation(e.getX(), e.getY());
if(selRow != -1) {
NodeObj nodeObj = NodeManager.getNodeObj(path.getLastPathComponent());
tree.setSelectionPath(path);
}
else if (selRow == -1)
tree.clearSelection();
}
};
jTree.addMouseMotionListener(mml);
Good luck,
Hetal Seth
[ August 02, 2002: Message edited by: Hetal Seth ]
18 years ago
Hi,
The 'NodeObj' is my custom TreeNode. I guess I have put forth my question a bit wrong. As you can notice from the previous source code, I have a tree in which each treenode is a label comprising of an image + text. When I drag that node, I want a GHOSTLY image of that treenode(either text+image together or only image) to move along the cursor to the drop point, like the way it happens in windows explorer. My drag & drop implementation is working good presently without the above mentioned feature.
I have 3 different kinds of images that are red, green, blue color for different purposes. There are 2 possibilities.
1. Create a grey image replicating each of the above mentioned images & then call upon the 'grey' image in the dragEnter() of DRAG till drop() of DROP, I mean something like that.
-> OR <-
2. Write a code which would create that ghostly image on the fly with the help of BufferedImage, Graphics2D, etc. & suppy it to startDrag() in the dragGestureRecognised().
Implementation wise (2) is a little tricky, which i dont know how to do. But logically & functionality-wise, (2) is the right thing to do, I guess.
Let me know if I am thinking in the right direction.
Thanks,
Hetal Seh
18 years ago
Hi,
I agree with you. But this is how far I got. I am not sure how to proceed further. Any hints.
Thanks,
Hetal Seth
*************************************************
import java.io.*;
import java.awt.*;
import java.net.*;
import java.lang.*;
import java.util.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
public class NodeManager implements TreeModel, TreeCellRenderer
{
static TreeModelListener l;
static GetPropObj getPropObj;
static Set setOfListeners = new HashSet();
DefaultMutableTreeNode dmtnScene;
NodeManager(GetPropObj getPropObj)
{
this.getPropObj = getPropObj;
NodeObjAvecChildren.setGetPropObj(getPropObj);
}
NodeManager(Socket socket, String logFileName) throws IOException
{
this.getPropObj = new GetPropObj(socket, logFileName);
NodeObjAvecChildren.setGetPropObj(getPropObj);
}
NodeManager(Socket socket) throws IOException
{
this.getPropObj = new GetPropObj(socket);
NodeObjAvecChildren.setGetPropObj(getPropObj);
}
public void addTreeModelListener(TreeModelListener l)
{
this.l = l;
setOfListeners.add(l);
}
public void removeTreeModelListener(TreeModelListener l)
{
setOfListeners.remove(l);
}
public void valueForPathChanged(TreePath path, Object newValue) { }
public Object getChild(Object parent, int index)
{
DefaultMutableTreeNode dmtnParent
= (DefaultMutableTreeNode)parent;
NodeObj nodeObjParent = getNodeObj(parent);
int targetChildCount = nodeObjParent.getChildCount();
DefaultMutableTreeNode dmtnChild;
/****
ASSERT(
defaultMutableTreeNode_Parent.getChildCount() == 0
||
defaultMutableTreeNode_Parent.getChildCount() == targetChildCount);
ASSERT(0 <= index && index = targetChildCount);
****/
if (dmtnParent.getChildCount() != targetChildCount) {
// safety: should be a no-op
dmtnParent.removeAllChildren();
for(int i = 0; i < targetChildCount; i++) {
NodeObj nodeObjChild
= nodeObjParent.getChild(i);
//XXX: Race condition
// children might be removed from the real
// object (on smanager) since we got the childcount.
dmtnChild = new DefaultMutableTreeNode(nodeObjChild);
dmtnParent.add(dmtnChild);
}
}
return dmtnParent.getChildAt(index);
}
public Object getRoot()
{
if(dmtnScene == null) {
NodeObj nodeScene = new NodeScene(getPropObj.getScene());
dmtnScene = new DefaultMutableTreeNode(nodeScene);
}
return dmtnScene;
}
public boolean isLeaf(Object node)
{
return getNodeObj(node).isLeaf();
}
public int getChildCount(Object parent)
{
return getNodeObj(parent).getChildCount();
}
public int getIndexOfChild(Object parent, Object child)
{
return (getNodeObj(parent)).getIndexOfChild(getNodeObj(child));
}
public Component getTreeCellRendererComponent(
JTreetree,
Objectvalue,
booleanselected,
booleanexpanded,
booleanleaf,
introw,
booleanhasFocus)
{
JLabel jlabel = new JLabel();
NodeObj nodeObj = getNodeObj(value);
if (selected) {
jlabel.setOpaque(true);
jlabel.setBackground(Color.lightGray);
}
jlabel.setIcon(nodeObj.getIcon());
jlabel.setText(nodeObj.getDname());
return jlabel;
}
static NodeObj getNodeObj(Object object)
{
DefaultMutableTreeNode dmtn
= (DefaultMutableTreeNode)object;
return (NodeObj)dmtn.getUserObject();
}
}
18 years ago
Hi All,
I have an application that does the DnD operation within a JTree. But, I want to implement the functionality of Dragging & Dropping an image (which, of course, would be a node of that same JTree).
Your assistance would be of great help.
Thanks,
Hetal Seth
18 years ago
hi,
i am under the impression that ur tryin to use DragnDrop functionality for ur application. if it is true, then u might have to refer the java.awt.dnd package.
-hetal-
18 years ago
hey,
try the following in the dragGestureRecognised() method of ur DRAGGABLE:
Cursor cursor = new Cursor(Cursor.HANDCUR....);
event.startDrag(cursor, transferable(path), this);
good luck,
hetal seth
18 years ago
Hi,
Does it have to do anything with the DataFlavors ?
This things drivin me crazzy ....
Thanks,
Hetal
18 years ago
Hi,
Thanks for ur reply, but that is what I was tryin to do. The code below is used in the dragGestureRecognized() method:
JTree tree = (JTree)event.getComponent();
Point point = event.getDragOrigin();
//TreePath path = tree.getPathForLocation(toInt(point.getX()), toInt(point.getY()));
TreePath path = tree.getLeadSelectionPath();
Rectangle recPath = tree.getPathBounds(path);
Point pt = new Point();
pt.setLocation(toInt(point.getX())- toInt (recPath.getY()), toInt(point.getY())- toInt(recPath.getY()) );
System.out.println("dragGestureRecognized() ******************** 1");
// Get the tree cell renderer
JLabel jLabel = (JLabel) tree.getCellRenderer().getTreeCellRendererComponent
(
tree,
path.getLastPathComponent(),
false,
tree.isExpanded(path),
tree.getModel().isLeaf (path.getLastPathComponent()),
0,
false
);
jLabel.setSize((int)recPath.getWidth(), (int)recPath.getHeight());
System.out.println("dragGestureRecognized() ******************** 2");
// Get the ghostly image
BufferedImage bufImage = new BufferedImage
(
(int)recPath.getWidth(), (int)recPath.getHeight(),
BufferedImage.TYPE_INT_ARGB_PRE);
System.out.println("dragGestureRecognized() ******************** 3");
Graphics2D g2 = bufImage.createGraphics();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.5f));
jLabel.paint(g2);
System.out.println("dragGestureRecognized() ******************** 4");
//event.startDrag(DragSource.DefaultCopyDrop, new TransferWrap(path), this);

Appreciate ur input.
Thanks,
Hetal Seth
18 years ago
Hi Friends,
I am looking to add greyish/ghosted drag images to the tree. What I mean is, when u drag & drop a folder in windows, the object becomes greyish/ghosted. I am trying to implement the same functionality in my project, but unsuccessful.
Any clues ?
Thanks,
Hetal Seth
[ July 11, 2002: Message edited by: Hetal Seth ]
18 years ago
hi friend,
thanx a lot for ur valuable info. infact i was usin the SwingUtilities.invokeLater() in the drop() method. this solves my curiousness.
thanx,
hetal
18 years ago
Hi Friends,
I am using a JOptionPane during a dragndrop (DnD) operation. In my application, if either the source or the target is an invalid object, then i pop up
JOptionPane.showMessageDialog(null, "Invalid Operation", "Alert", JOptionPane.INFORMATION_MESSAGE);
The message pops up and the entire application freezes ! You can't even click the 'ok' button.
Any clues ?
Appreciate ur assistance.
Hetal Seth
18 years ago
hi friends:
i am half way. i create a gif file with the foggy kind of image that i needed. now the problem is how do i set it, That is, if i set it in the JPanel only, it works !
but my JPanel has JSplitPane, which in turn has JTabbedPane. how do i set it for this ?
i would appreciate ur assistance.
thanx,
hetal

Originally posted by Hetal Seth:
hi friends :
i want to create a dual-colored window, which starts as a blue color at the bottom and gradually fades and becomes into white when it reaches the top of the window. precisely, sayin, it would lok foggy. that is what is need.
any kind of help would be appreciated.
thanx,
hetal


19 years ago
hi friends :
i want to create a dual-colored window, which starts as a blue color at the bottom and gradually fades and becomes into white when it reaches the top of the window. precisely, sayin, it would lok foggy. that is what is need.
any kind of help would be appreciated.
thanx,
hetal
19 years ago
Hi All:
I have written a report error class and am using the JOptionPane. Now the JOP soimetimes does not display the error messages on its window, though the window pops up with the title on the title bar and the 'ok' button. If there was no display of the messages at all, I can understand that there must have been somethin wrong with my code, but that is not the case, as I mentioned earlier.
Alternatively,
I developed a modal dialog for similar purpose and found the some reaction as the JOP.
Does anyone have a clue as to what is the problem ?
Thanks,
Hetal
[This message has been edited by Hetal Seth (edited October 30, 2001).]
19 years ago
Hi All:
I have to write an error log program. Can anyone help me with any kind of information about Error Logs.
Thanks in advance,
Hetal Seth
19 years ago