Skip to content

Commit 46dd220

Browse files
committed
Some success on memory leak; integrating Wolfgang's changes in Tracker
and TrackerIO
1 parent 4951671 commit 46dd220

24 files changed

+902
-693
lines changed

src/org/opensourcephysics/cabrillo/tracker/AutoTracker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ protected void dispose() {
12851285

12861286
@Override
12871287
public void finalize() {
1288-
OSPLog.finer(getClass().getSimpleName() + " recycled by garbage collector"); //$NON-NLS-1$
1288+
OSPLog.finalized(this);
12891289
}
12901290

12911291
/**

src/org/opensourcephysics/cabrillo/tracker/ExportDataDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public void itemStateChanged(ItemEvent e) {
184184
public void actionPerformed(ActionEvent e) {
185185
JFileChooser chooser = TrackerIO.getChooser();
186186
chooser.setSelectedFile(lastTXT); //$NON-NLS-1$
187-
TrackerIO.getChooserFilesAsync("save data", new Function<File[], Void>() { // $NON-NLS-1$
187+
TrackerIO.getChooserFilesAsync(trackerPanel.getTFrame(), "save data", new Function<File[], Void>() { // $NON-NLS-1$
188188

189189
@Override
190190
public Void apply(File[] files) {

src/org/opensourcephysics/cabrillo/tracker/ExportZipDialog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ public void actionPerformed(ActionEvent e) {
11081108
chooser.setFileFilter(LaunchBuilder.getPDFFilter());
11091109
}
11101110

1111-
TrackerIO.getChooserFilesAsync("open any", new Function<File[], Void>() { //$NON-NLS-1$
1111+
TrackerIO.getChooserFilesAsync(frame, "open any", new Function<File[], Void>() { //$NON-NLS-1$
11121112

11131113
@Override
11141114
public Void apply(File[] files) {
@@ -1249,7 +1249,7 @@ public void actionPerformed(ActionEvent e) {
12491249
chooser.setDialogTitle(TrackerRes.getString("ZipResourceDialog.FileChooser.OpenHTML.Title")); //$NON-NLS-1$
12501250
chooser.setFileFilter(LaunchBuilder.getHTMLFilter());
12511251

1252-
File[] files = TrackerIO.getChooserFilesAsync("open any", new Function<File[], Void>() { //$NON-NLS-1$
1252+
File[] files = TrackerIO.getChooserFilesAsync(frame, "open any", new Function<File[], Void>() { //$NON-NLS-1$
12531253

12541254
@Override
12551255
public Void apply(File[] files) {

src/org/opensourcephysics/cabrillo/tracker/LineProfile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public void itemStateChanged(ItemEvent e) {
209209
if (!loading)
210210
Undo.postTrackEdit(LineProfile.this, control);
211211
}
212-
trackerPanel.getTFrame().getToolBar(trackerPanel).refresh(TToolBar.REFRESH_LINEPROFILE);
212+
trackerPanel.getTFrame().getToolbar(trackerPanel).refresh(TToolBar.REFRESH_LINEPROFILE);
213213
invalidateData(null);
214214
}
215215
});

src/org/opensourcephysics/cabrillo/tracker/MainTView.java

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ public class MainTView extends JPanel implements TView {
7272
private JToolBar playerBar;
7373
private MouseAdapter mouseAdapter;
7474
KeyAdapter keyAdapter;
75+
Dimension lastDim;
76+
private ComponentAdapter listener = new ComponentAdapter() {
77+
@Override
78+
public void componentResized(ComponentEvent e) {
79+
doResized();
80+
}
81+
};
7582

7683
/**
7784
* Constructs a main view of a tracker panel.
@@ -82,33 +89,20 @@ public MainTView(TrackerPanel panel) {
8289
trackerPanel = panel;
8390
init();
8491
setLayout(new BorderLayout());
92+
playerBar = new JToolBar();
93+
add(playerBar, BorderLayout.SOUTH);
8594
scrollPane = new JScrollPane();
86-
scrollPane.addComponentListener(new ComponentAdapter() {
87-
Dimension lastDim;
88-
@Override
89-
public void componentResized(ComponentEvent e) {
90-
if (!getTopLevelAncestor().isVisible())
91-
return;
92-
Dimension d;
93-
if ((d = scrollPane.getSize()).equals(lastDim))
94-
return;
95-
lastDim = d;
96-
TToolBar.getToolbar(trackerPanel).refreshZoomButton();
97-
trackerPanel.eraseAll();
98-
//OSPLog.debug("MainTView testing no repaint");
99-
//TFrame.repaintT(trackerPanel);
100-
}
101-
});
95+
scrollPane.addComponentListener(listener);
10296
SwingUtilities.replaceUIActionMap(scrollPane, null);
10397
add(scrollPane, BorderLayout.CENTER);
10498

10599
// add trackbar north
100+
101+
//TEST_BH MEMORY LEAK HERE
106102
add(TTrackBar.getTrackbar(trackerPanel), BorderLayout.NORTH);
107103

108104
// add player to the playerBar
109-
playerBar = new JToolBar();
110105
playerBar.setFloatable(false);
111-
add(playerBar, BorderLayout.SOUTH);
112106
trackerPanel.getPlayer().setBorder(null);
113107
trackerPanel.setPlayerVisible(false);
114108
playerBar.add(trackerPanel.getPlayer());
@@ -165,7 +159,7 @@ public void mouseWheelMoved(MouseWheelEvent e) {
165159
keyAdapter = new KeyAdapter() {
166160
@Override
167161
public void keyPressed(KeyEvent e) {
168-
JButton z = trackerPanel.getTFrame().getToolBar(trackerPanel).zoomButton;
162+
JButton z = trackerPanel.getTFrame().getToolbar(trackerPanel).zoomButton;
169163
int d = trackerPanel.getSelectedPoint() == null ? 10 : 0;
170164
Rectangle rect = scrollPane.getViewport().getViewRect();
171165
switch (e.getKeyCode()) {
@@ -239,7 +233,7 @@ public void keyPressed(KeyEvent e) {
239233

240234
@Override
241235
public void keyReleased(final KeyEvent e) {
242-
final JButton z = trackerPanel.getTFrame().getToolBar(trackerPanel).zoomButton;
236+
final JButton z = trackerPanel.getTFrame().getToolbar(trackerPanel).zoomButton;
243237
if (e.getKeyCode() == KeyEvent.VK_Z) {
244238
z.setSelected(false);
245239
trackerPanel.setCursor(Cursor.getDefaultCursor());
@@ -266,6 +260,17 @@ public synchronized void run() {
266260

267261
}
268262

263+
protected void doResized() {
264+
if (!getTopLevelAncestor().isVisible())
265+
return;
266+
Dimension d;
267+
if ((d = scrollPane.getSize()).equals(lastDim))
268+
return;
269+
lastDim = d;
270+
TToolBar.getToolbar(trackerPanel).refreshZoomButton();
271+
trackerPanel.eraseAll();
272+
}
273+
269274
/**
270275
* Gets the popup menu when right-clicked.
271276
*
@@ -401,13 +406,21 @@ public void dispose() {
401406
}
402407
playerBar.removeAll();
403408
playerBar = null;
409+
trackerPanel.clearTemp();
404410

405411
// DB! maybe don't need below here
406412
// remove mouse and key listeners
407413
trackerPanel.removeMouseListener(mouseAdapter);
408414
trackerPanel.removeMouseWheelListener(mouseAdapter);
409415
trackerPanel.removeKeyListener(keyAdapter);
410416

417+
mouseAdapter = null;
418+
keyAdapter = null;
419+
420+
scrollPane.removeComponentListener(listener);
421+
trackerPanel.setScrollPane(null);
422+
423+
listener = null;
411424
scrollPane.setViewportView(null);
412425
scrollPane = null;
413426
removeAll();
@@ -416,7 +429,7 @@ public void dispose() {
416429

417430
@Override
418431
public void finalize() {
419-
OSPLog.finer(getClass().getSimpleName() + " recycled by garbage collector"); //$NON-NLS-1$
432+
OSPLog.finalized(this);
420433
}
421434

422435
/**

src/org/opensourcephysics/cabrillo/tracker/ModelBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public void propertyChange(PropertyChangeEvent e) {
247247

248248
@Override
249249
public void finalize() {
250-
OSPLog.finer(getClass().getSimpleName() + " recycled by garbage collector"); //$NON-NLS-1$
250+
OSPLog.finalized(this);
251251
}
252252

253253
@Override

src/org/opensourcephysics/cabrillo/tracker/PageTView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ protected void refreshTabs() {
525525

526526
@Override
527527
public void finalize() {
528-
OSPLog.finest(getClass().getSimpleName() + " recycled by garbage collector"); //$NON-NLS-1$
528+
OSPLog.finalized(this);
529529
}
530530

531531
/**

src/org/opensourcephysics/cabrillo/tracker/TActions.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ public static void clear() {
9797
* @return the Map
9898
*/
9999
public static Map<String, AbstractAction> getActions(TrackerPanel trackerPanel) {
100+
return getActions(trackerPanel, false);
101+
}
102+
103+
public static Map<String, AbstractAction> getActions(TrackerPanel trackerPanel, boolean allowNull) {
100104
Map<String, AbstractAction> actions = actionMaps.get(trackerPanel);
101-
if (actions != null)
105+
if (actions != null || allowNull)
102106
return actions;
103107
// create new actionMap
104108
actions = new HashMap<String, AbstractAction>();
@@ -151,7 +155,6 @@ public void actionPerformed(ActionEvent e) {
151155
public void actionPerformed(ActionEvent e) {
152156
trackerPanel.setSelectedPoint(null);
153157
trackerPanel.selectedSteps.clear();
154-
trackerPanel.setMouseCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
155158
TFrame frame = trackerPanel.getTFrame();
156159
if (frame != null) {
157160
frame.doOpenFileFromDialog();
@@ -204,7 +207,7 @@ public void actionPerformed(ActionEvent e) {
204207
public void actionPerformed(ActionEvent e) {
205208
TFrame frame = trackerPanel.getTFrame();
206209
if (frame != null) {
207-
frame.removeTab(trackerPanel);
210+
frame.doCloseAction(trackerPanel);
208211
}
209212
}
210213
});
@@ -706,8 +709,9 @@ protected static void pointMassAction(TrackerPanel trackerPanel) {
706709

707710
protected static void dataTrackActionAsync(TrackerPanel trackerPanel) {
708711
// choose file and import data
709-
TrackerIO.getChooserFilesAsync("open data", //$NON-NLS-1$
710-
(files) -> {
712+
TFrame frame = trackerPanel.getTFrame();
713+
TrackerIO.getChooserFilesAsync(frame, //$NON-NLS-1$
714+
"open data", (files) -> {
711715
if (files == null) {
712716
return null;
713717
}

0 commit comments

Comments
 (0)