1 19 package org.openide.actions; 20 21 import org.openide.util.HelpCtx; 22 import org.openide.util.NbBundle; 23 import org.openide.util.RequestProcessor; 24 import org.openide.util.actions.CallableSystemAction; 25 26 import java.awt.*; 27 import java.awt.event.*; 28 29 30 import javax.swing.*; 31 32 33 40 44 public class GarbageCollectAction extends CallableSystemAction { 45 public String getName() { 46 return NbBundle.getBundle(GarbageCollectAction.class).getString("CTL_GarbageCollect"); } 48 49 public HelpCtx getHelpCtx() { 50 return new HelpCtx(GarbageCollectAction.class); 51 } 52 53 public void performAction() { 54 gc(); 55 } 56 57 private static void gc() { 58 RequestProcessor.getDefault().post( 60 new Runnable () { 61 public void run() { 62 System.gc(); 63 System.runFinalization(); 64 System.gc(); 65 } 66 } 67 ); 68 } 69 70 protected boolean asynchronous() { 71 return false; 72 } 73 74 public Component getToolbarPresenter() { 75 return new HeapViewWrapper(); 76 } 78 79 private static final class HeapViewWrapper extends JComponent { 80 public HeapViewWrapper() { 81 add(new HeapView()); 82 setLayout(null); 83 } 84 85 public boolean isOpaque() { 86 return false; 87 } 88 89 public Dimension getMinimumSize() { 90 return calcPreferredSize(); 91 } 92 93 public Dimension getPreferredSize() { 94 return calcPreferredSize(); 95 } 96 97 public Dimension getMaximumSize() { 98 Dimension pref = calcPreferredSize(); 99 Container parent = getParent(); 100 if (parent != null && parent.getHeight() > 0) { 101 pref.height = parent.getHeight(); 102 } 103 return pref; 104 } 105 106 public Dimension calcPreferredSize() { 107 Dimension pref = getHeapView().heapViewPreferredSize(); 108 pref.height += 1; 109 pref.width += 6; 110 return pref; 111 } 112 113 public void layout() { 114 int w = getWidth(); 115 int h = getHeight(); 116 HeapView heapView = getHeapView(); 117 heapView.setBounds(4, 2, w - 6, h - 4); 118 } 119 120 private HeapView getHeapView() { 121 return (HeapView)getComponent(0); 122 } 123 } 124 125 } 126 | Popular Tags |