/* License see bottom */
package jtrackbase.gui;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JTree;
import javax.swing.tree.TreePath;
import jtrackbase.gui.tree.TrackbaseNode;
import jtrackbase.gui.tree.TrackbaseTreeModel;
public class TrackbaseTree extends JTree
implements MouseListener {
public TrackbaseTree() {
super();
setModel(new TrackbaseTreeModel());
addMouseListener(this);
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) {
findAndDisplayPopup(e);
}
}
private void findAndDisplayPopup(MouseEvent e) {
int cnt=getSelectionCount();
if (cnt==0 || cnt==1) {
setSelectionPath(getPathForLocation(e.getX(), e.getY()));
}
if (getSelectionCount()==1) {
TreePath tp=getSelectionPath();
Object comp=tp.getLastPathComponent();
if (!(comp instanceof TrackbaseNode)) {
return;
}
TrackbaseNode tbn=(TrackbaseNode)comp;
tbn.getPopup().show(this, e.getX(), e.getY());
} else if (getSelectionCount()>1){
//TreePath[] tp=getSelectionPaths();
}
}
@Override
public void mouseReleased(MouseEvent e) {
}
}
/*
Copyright (C) 2008 Onkobu Tanaake
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program (gplv3.txt).
*/