Lines 146-151
Link Here
|
146 |
private Preferences preferences = NbPreferences.forModule(getClass()).node("debugging"); // NOI18N |
146 |
private Preferences preferences = NbPreferences.forModule(getClass()).node("debugging"); // NOI18N |
147 |
private PreferenceChangeListener prefListener; |
147 |
private PreferenceChangeListener prefListener; |
148 |
private SessionsComboBoxListener sessionsComboListener; |
148 |
private SessionsComboBoxListener sessionsComboListener; |
|
|
149 |
private VisibleTreePosition visibleTreePosition = null; |
149 |
|
150 |
|
150 |
private transient ImageIcon resumeIcon; |
151 |
private transient ImageIcon resumeIcon; |
151 |
private transient ImageIcon focusedResumeIcon; |
152 |
private transient ImageIcon focusedResumeIcon; |
Lines 265-270
Link Here
|
265 |
treeScrollBar.addAdjustmentListener(this); |
266 |
treeScrollBar.addAdjustmentListener(this); |
266 |
|
267 |
|
267 |
setSuspendTableVisible(preferences.getBoolean(FiltersDescriptor.SHOW_SUSPEND_TABLE, true)); |
268 |
setSuspendTableVisible(preferences.getBoolean(FiltersDescriptor.SHOW_SUSPEND_TABLE, true)); |
|
|
269 |
|
270 |
mainScrollPane.getVerticalScrollBar().addAdjustmentListener( |
271 |
new AdjustmentListener() { |
272 |
|
273 |
@Override |
274 |
public void adjustmentValueChanged(AdjustmentEvent e) { |
275 |
if (e.getValueIsAdjusting()) { |
276 |
storeScrollPosition(); |
277 |
} |
278 |
} |
279 |
}); |
268 |
} |
280 |
} |
269 |
|
281 |
|
270 |
/** This method is called from within the constructor to |
282 |
/** This method is called from within the constructor to |
Lines 577-584
Link Here
|
577 |
} |
589 |
} |
578 |
if (currentThread != null) { |
590 |
if (currentThread != null) { |
579 |
DVThread thread = threadMadeCurrentRef != null ? threadMadeCurrentRef.get() : null; |
591 |
DVThread thread = threadMadeCurrentRef != null ? threadMadeCurrentRef.get() : null; |
580 |
if (thread == currentThread) { |
592 |
if (thread != currentThread) { |
581 |
threadToScrollRef = new WeakReference(thread); |
593 |
threadToScrollRef = new WeakReference(currentThread); |
582 |
} |
594 |
} |
583 |
} |
595 |
} |
584 |
refreshView(); |
596 |
refreshView(); |
Lines 682-690
Link Here
|
682 |
|
694 |
|
683 |
@Override |
695 |
@Override |
684 |
public void treeExpanded(TreeExpansionEvent event) { |
696 |
public void treeExpanded(TreeExpansionEvent event) { |
|
|
697 |
TreePath path = event.getPath(); |
698 |
checkIfWeShouldScrollToCurrentThread(path); |
685 |
refreshView(); |
699 |
refreshView(); |
686 |
} |
700 |
} |
687 |
|
701 |
|
|
|
702 |
/** |
703 |
* Check whether we should scroll to the current thread. |
704 |
* |
705 |
* @param path Path of node that has been just expanded, or that has new |
706 |
* children. |
707 |
*/ |
708 |
private void checkIfWeShouldScrollToCurrentThread(TreePath path) { |
709 |
Node node = Visualizer.findNode(path.getLastPathComponent()); |
710 |
if (node == null) { |
711 |
return; |
712 |
} |
713 |
DVThread dvThread = node.getLookup().lookup(DVThread.class); |
714 |
DVThread currentThread; |
715 |
synchronized (lock) { |
716 |
currentThread = (debugger != null) ? debugger.getCurrentThread() : null; |
717 |
} |
718 |
if (currentThread != null && currentThread == dvThread) { |
719 |
threadToScrollRef = new WeakReference<DVThread>(dvThread); |
720 |
} |
721 |
} |
722 |
|
688 |
@Override |
723 |
@Override |
689 |
public void treeCollapsed(TreeExpansionEvent event) { |
724 |
public void treeCollapsed(TreeExpansionEvent event) { |
690 |
refreshView(); |
725 |
refreshView(); |
Lines 697-702
Link Here
|
697 |
|
732 |
|
698 |
@Override |
733 |
@Override |
699 |
public void treeNodesInserted(TreeModelEvent e) { |
734 |
public void treeNodesInserted(TreeModelEvent e) { |
|
|
735 |
TreePath path = e.getTreePath(); |
736 |
checkIfWeShouldScrollToCurrentThread(path); |
700 |
refreshView(); |
737 |
refreshView(); |
701 |
} |
738 |
} |
702 |
|
739 |
|
Lines 856-861
Link Here
|
856 |
setRootContext(compoundModel, de); |
893 |
setRootContext(compoundModel, de); |
857 |
} |
894 |
} |
858 |
|
895 |
|
|
|
896 |
/** |
897 |
* Store first visible node and its offset. Called when the view is scrolled |
898 |
* by the user. |
899 |
*/ |
900 |
private void storeScrollPosition() { |
901 |
|
902 |
JTree tree = getJTree(); |
903 |
if (tree != null) { |
904 |
int scrollTop = mainScrollPane.getViewport().getViewPosition().y; |
905 |
int row = tree.getRowForLocation(tree.getRowBounds(0).x + 1, |
906 |
scrollTop); |
907 |
if (row >= 0) { |
908 |
TreePath path = tree.getPathForRow(row); |
909 |
if (path != null) { |
910 |
int offset = tree.getRowBounds(row).y - scrollTop; |
911 |
visibleTreePosition = new VisibleTreePosition( |
912 |
path, offset); |
913 |
return; |
914 |
} |
915 |
} |
916 |
} |
917 |
visibleTreePosition = null; |
918 |
} |
919 |
|
920 |
/** |
921 |
* Store visible offset of an important node. Called when the view is |
922 |
* scrolled by ViewRefresher |
923 |
* |
924 |
* @param path Path to a node that should stay visible at the same position. |
925 |
*/ |
926 |
private void storeScrollPosition(TreePath path) { |
927 |
JTree tree = getJTree(); |
928 |
if (tree != null && path != null) { |
929 |
int row = tree.getRowForPath(path); |
930 |
if (row > 0) { |
931 |
int scrollTop = mainScrollPane.getViewport().getViewPosition().y; |
932 |
int offset = tree.getRowBounds(row).y - scrollTop; |
933 |
visibleTreePosition = new VisibleTreePosition( |
934 |
path, offset); |
935 |
return; |
936 |
} |
937 |
} |
938 |
visibleTreePosition = null; |
939 |
} |
940 |
|
941 |
private JTree getJTree() { |
942 |
DebugTreeView treeView1 = getTreeView(); |
943 |
if (treeView1 != null) { |
944 |
JTree tree = treeView1.getTree(); |
945 |
if (tree != null && tree.getRowCount() > 0) { |
946 |
return tree; |
947 |
} |
948 |
} |
949 |
return null; |
950 |
} |
951 |
|
952 |
/** |
953 |
* Restore stored scroll position. |
954 |
*/ |
955 |
private void restoreScrollPosition() { |
956 |
if (visibleTreePosition != null) { |
957 |
JTree tree = getJTree(); |
958 |
if (tree != null) { |
959 |
int row = tree.getRowForPath(visibleTreePosition.getPath()); |
960 |
if (row != -1) { |
961 |
Rectangle bounds = tree.getRowBounds(row); |
962 |
if (bounds != null) { |
963 |
int scrollY = bounds.y - visibleTreePosition.getOffset(); |
964 |
JViewport viewport = mainScrollPane.getViewport(); |
965 |
Rectangle rect = viewport.getViewRect(); |
966 |
rect.y = scrollY; |
967 |
if (!rect.isEmpty()) { |
968 |
((JComponent) viewport.getView()).scrollRectToVisible( |
969 |
rect); |
970 |
} |
971 |
} |
972 |
} |
973 |
} |
974 |
} |
975 |
} |
976 |
|
859 |
// ************************************************************************** |
977 |
// ************************************************************************** |
860 |
// inner classes |
978 |
// inner classes |
861 |
// ************************************************************************** |
979 |
// ************************************************************************** |
Lines 893-899
Link Here
|
893 |
DVThread threadToScroll = threadToScrollRef != null ? threadToScrollRef.get() : null; |
1011 |
DVThread threadToScroll = threadToScrollRef != null ? threadToScrollRef.get() : null; |
894 |
threadToScrollRef = null; |
1012 |
threadToScrollRef = null; |
895 |
int scrollStart = -1, scrollEnd = -1; |
1013 |
int scrollStart = -1, scrollEnd = -1; |
896 |
boolean pathToScrollSearching = false; |
|
|
897 |
|
1014 |
|
898 |
int mainPanelHeight = 0; |
1015 |
int mainPanelHeight = 0; |
899 |
int treeViewWidth = 0; |
1016 |
int treeViewWidth = 0; |
Lines 904-909
Link Here
|
904 |
Object currentObject = null; |
1021 |
Object currentObject = null; |
905 |
int currentSY = 0; |
1022 |
int currentSY = 0; |
906 |
int height = 0; |
1023 |
int height = 0; |
|
|
1024 |
TreePath scrollPath = null; |
907 |
|
1025 |
|
908 |
if (tView != null) { |
1026 |
if (tView != null) { |
909 |
for (TreePath path : tView.getVisiblePaths()) { |
1027 |
for (TreePath path : tView.getVisiblePaths()) { |
Lines 916-924
Link Here
|
916 |
height = rect != null ? (int) Math.round(rect.getHeight()) : 0; |
1034 |
height = rect != null ? (int) Math.round(rect.getHeight()) : 0; |
917 |
|
1035 |
|
918 |
if (dvThread != null || dvThreadGroup != null) { |
1036 |
if (dvThread != null || dvThreadGroup != null) { |
919 |
pathToScrollSearching = dvThread == threadToScroll; |
1037 |
if (dvThread == threadToScroll) { |
920 |
if (pathToScrollSearching) { |
|
|
921 |
scrollStart = mainPanelHeight; |
1038 |
scrollStart = mainPanelHeight; |
|
|
1039 |
scrollEnd = scrollStart + height; |
1040 |
scrollPath = path; |
922 |
} |
1041 |
} |
923 |
if (currentObject != null) { |
1042 |
if (currentObject != null) { |
924 |
addPanels(currentObject, isCurrent, isAtBreakpoint, isInDeadlock, |
1043 |
addPanels(currentObject, isCurrent, isAtBreakpoint, isInDeadlock, |
Lines 946-953
Link Here
|
946 |
leftBarHeight += height; |
1065 |
leftBarHeight += height; |
947 |
sy += height; |
1066 |
sy += height; |
948 |
|
1067 |
|
949 |
if (pathToScrollSearching) { |
1068 |
if (scrollPath != null && scrollPath.equals(path.getParentPath())) { |
950 |
scrollEnd = mainPanelHeight; |
1069 |
scrollEnd += height; |
951 |
} |
1070 |
} |
952 |
} // for |
1071 |
} // for |
953 |
} // if |
1072 |
} // if |
Lines 977-983
Link Here
|
977 |
Rectangle aRect = new Rectangle(0, scrollStart, 1, aRectHeight); |
1096 |
Rectangle aRect = new Rectangle(0, scrollStart, 1, aRectHeight); |
978 |
if (!aRect.isEmpty()) { |
1097 |
if (!aRect.isEmpty()) { |
979 |
((JComponent)viewport.getView()).scrollRectToVisible(aRect); |
1098 |
((JComponent)viewport.getView()).scrollRectToVisible(aRect); |
|
|
1099 |
storeScrollPosition(scrollPath); |
980 |
} |
1100 |
} |
|
|
1101 |
} else { |
1102 |
restoreScrollPosition(); |
981 |
} |
1103 |
} |
982 |
} |
1104 |
} |
983 |
|
1105 |
|
Lines 1279-1282
Link Here
|
1279 |
|
1401 |
|
1280 |
} |
1402 |
} |
1281 |
|
1403 |
|
|
|
1404 |
private class VisibleTreePosition { |
1405 |
|
1406 |
final TreePath path; |
1407 |
final int offset; |
1408 |
|
1409 |
public VisibleTreePosition(TreePath path, int offset) { |
1410 |
this.path = path; |
1411 |
this.offset = offset; |
1412 |
} |
1413 |
|
1414 |
public TreePath getPath() { |
1415 |
return path; |
1416 |
} |
1417 |
|
1418 |
public int getOffset() { |
1419 |
return offset; |
1420 |
} |
1421 |
|
1422 |
@Override |
1423 |
public String toString() { |
1424 |
return "VisibleTreePosition[" + path + ", " + offset + "]"; //NOI18N |
1425 |
} |
1426 |
} |
1282 |
} |
1427 |
} |