This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 37256
Collapse All | Expand All

(-)src/org/netbeans/core/actions/MemoryMeterAction.java (-140 / +168 lines)
Lines 13-18 Link Here
13
13
14
package org.netbeans.core.actions;
14
package org.netbeans.core.actions;
15
15
16
import java.awt.*;
16
import java.awt.Graphics;
17
import java.awt.Graphics;
17
import java.awt.Dimension;
18
import java.awt.Dimension;
18
import java.awt.Color;
19
import java.awt.Color;
Lines 32-185 Link Here
32
 *
33
 *
33
 * @author  Petr Hrebejk
34
 * @author  Petr Hrebejk
34
 */
35
 */
35
public class MemoryMeterAction extends CallableSystemAction {
36
public class MemoryMeterAction extends CallableSystemAction 
37
{
36
    
38
    
37
    private static long mark = -1;
39
	private static long mark = -1;
38
40
39
    public String getName() {
41
	public String getName() 
40
        return NbBundle.getBundle(MemoryMeterAction.class).getString("CTL_MemoryMeterAction");
42
	{
41
    }
43
		return NbBundle.getBundle(MemoryMeterAction.class).getString("CTL_MemoryMeterAction");
44
	}
42
45
43
    public HelpCtx getHelpCtx() {
46
	public HelpCtx getHelpCtx() 
44
        return new HelpCtx(MemoryMeterAction.class);
47
	{
45
    }
48
		return new HelpCtx(MemoryMeterAction.class);
49
	}
46
50
47
    public void performAction() {
51
	public void performAction() 
48
        mark = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
52
	{
49
    }
53
		mark = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
50
    
54
	}
51
    protected boolean asynchronous() {
55
    
52
        return false;
56
	protected boolean asynchronous() 
53
    }
57
	{
54
    
58
		return false;
55
    public java.awt.Component getToolbarPresenter() {
59
	}
56
        return new MemoryMeterPresenter(this);
60
    
57
    }
61
	public java.awt.Component getToolbarPresenter() 
58
    
62
	{
59
    
63
		return new MemoryMeterPresenter(this);
60
    public static class MemoryMeterPresenter extends Actions.ToolbarButton {
64
	}
61
        
65
    
62
        private static final int UPDATE_TIME = 1000;
66
    
63
    
67
	public static class MemoryMeterPresenter extends Actions.ToolbarButton 
64
        private Timer timer;
68
	{
65
            
69
        
66
        private Dimension prefSize;
70
		private static final int UPDATE_TIME = 1000;
67
        
71
    
68
        //private static Color nbGreen = new Color( 100, 210, 100 );
72
		private Timer timer;
69
        private static Color nbBlue = new Color( 153, 153, 204 );
73
            
70
        
74
		private Dimension prefSize;
71
        public MemoryMeterPresenter( CallableSystemAction a ) {
75
        
72
            super( a );
76
		//private static Color nbGreen = new Color( 100, 210, 100 );
73
            timer = new Timer ( UPDATE_TIME, new ActionListener () {
77
		private static Color nbBlue = new Color( 153, 153, 204 );
74
                               public void actionPerformed (ActionEvent ev) {
78
        
75
                                   updateStatus ();
79
		public MemoryMeterPresenter( CallableSystemAction a ) 
76
                               }
80
		{
77
                           });
81
			super( a );
78
        }
82
			timer = new Timer ( UPDATE_TIME, new ActionListener () 
79
        
83
			{
80
        public void paint( Graphics g ) {
84
				public void actionPerformed (ActionEvent ev) 
81
            Dimension size = getSize();;
85
				{
82
            int width = size.width -  16; 
86
					updateStatus ();
83
            int height = size.height - 12;         
87
				}
84
            long allocated =  Runtime.getRuntime().totalMemory();
88
			});
85
            long taken = allocated - Runtime.getRuntime().freeMemory() ;
89
		}
86
            
90
        
87
            // Clear button
91
		public void paint( Graphics g ) 
88
            g.clearRect( 0, 0, size.width, size.width );
92
		{
89
            
93
			Dimension size = getSize();;
90
            // Paint bevel around the memory meter
94
			int width = size.width -  16; 
91
            g.setColor( UIManager.getDefaults ().getColor ("Button.background") ); // NOI18N
95
			int height = size.height - 12;         
92
            g.draw3DRect( 7, 5, width + 1, height + 1, false );
96
			long allocated =  Runtime.getRuntime().totalMemory();
93
            
97
			long taken = allocated - Runtime.getRuntime().freeMemory() ;
94
            if ( isBorderPainted() ) {
98
            
95
                paintBorder( g );
99
			// Clear button
96
            }
100
			g.setColor(SystemColor.control);
101
			g.fillRect (0, 0, size.width, size.width);
102
            
103
			// Paint bevel around the memory meter
104
			g.setColor( UIManager.getDefaults ().getColor (Color.LIGHT_GRAY) ); // NOI18N
105
			g.draw3DRect( 7, 5, width + 1, height + 1, false );
106
            
107
			if ( isBorderPainted() ) 
108
			{
109
				paintBorder( g );
110
			}
97
                        
111
                        
98
            // Paint allocated memory
112
			// Paint allocated memory
99
            // g.setColor( nbGreen );
113
			// g.setColor( nbGreen );
100
            // g.fillRect( 8, 6, width, height );
114
			// g.fillRect( 8, 6, width, height );
101
            
115
            
102
            double ratio = (double)taken / (double)allocated;
116
			double ratio = (double)taken / (double)allocated;
103
            
117
            
104
            // Paint taken memory
118
			// Paint taken memory
105
            g.setColor( nbBlue );
119
			g.setColor( nbBlue );
106
            g.fillRect( 8, 6, (int) (width * ratio), height );
120
			g.fillRect( 8, 6, (int) (width * ratio), height );
107
            
121
            
108
            // Paint last mark
122
			// Paint last mark
109
            if ( mark != -1 ) {
123
			if ( mark != -1 ) 
110
                g.setColor( java.awt.Color.black );
124
			{
111
                ratio = (double)mark / (double)allocated;
125
				g.setColor( java.awt.Color.black );
126
				ratio = (double)mark / (double)allocated;
112
                
127
                
113
                // Marking line
128
				// Marking line
114
                g.drawLine( 8 + (int) (width * ratio), 6, 8 + (int) (width * ratio), 5 + height );
129
				g.drawLine( 8 + (int) (width * ratio), 6, 8 + (int) (width * ratio), 5 + height );
115
                g.setColor( java.awt.Color.darkGray.darker() );
130
				g.setColor( java.awt.Color.darkGray.darker() );
116
                // Upper triangle
131
				// Upper triangle
117
                g.drawLine( 8 + (int) (width * ratio), 5, 8 + (int) (width * ratio), 5 );
132
				g.drawLine( 8 + (int) (width * ratio), 5, 8 + (int) (width * ratio), 5 );
118
                g.drawLine( 8 + (int) (width * ratio) - 1, 4, 8 + (int) (width * ratio) + 1, 4 );
133
				g.drawLine( 8 + (int) (width * ratio) - 1, 4, 8 + (int) (width * ratio) + 1, 4 );
119
                g.drawLine( 8 + (int) (width * ratio) - 2, 3, 8 + (int) (width * ratio) + 2, 3 );
134
				g.drawLine( 8 + (int) (width * ratio) - 2, 3, 8 + (int) (width * ratio) + 2, 3 );
120
                // Lower triangle
135
				// Lower triangle
121
                g.drawLine( 8 + (int) (width * ratio), 6 + height, 8 + (int) (width * ratio), 6 + height );
136
				g.drawLine( 8 + (int) (width * ratio), 6 + height, 8 + (int) (width * ratio), 6 + height );
122
                g.drawLine( 8 + (int) (width * ratio) - 1, 7 + height, 8 + (int) (width * ratio) + 1, 7 + height );
137
				g.drawLine( 8 + (int) (width * ratio) - 1, 7 + height, 8 + (int) (width * ratio) + 1, 7 + height );
123
                g.drawLine( 8 + (int) (width * ratio) - 2, 8 + height, 8 + (int) (width * ratio) + 2, 8 + height );
138
				g.drawLine( 8 + (int) (width * ratio) - 2, 8 + height, 8 + (int) (width * ratio) + 2, 8 + height );
124
            }
139
			}
125
            
140
            
126
            
141
            
127
        }
142
		}
128
        
143
        
129
        public Dimension getPreferredSize() {
144
		public Dimension getPreferredSize() 
130
            
145
		{
131
            if ( prefSize == null ) {
146
            
132
                prefSize = new Dimension( 72, super.getPreferredSize().height );
147
			if ( prefSize == null ) 
133
            }
148
			{
134
            
149
				prefSize = new Dimension( 72, super.getPreferredSize().height );
135
            return prefSize;
150
			}
136
        }
151
            
137
        
152
			return prefSize;
138
        public String getToolTipText( MouseEvent e ) {
153
		}
139
            if ( e.isShiftDown() ) {
154
        
140
                return getToolTipText( false );
155
		public String getToolTipText( MouseEvent e ) 
141
            }
156
		{
142
            else {
157
			if ( e.isShiftDown() ) 
143
                return getToolTipText( true );
158
			{
144
            }
159
				return getToolTipText( false );
160
			}
161
			else 
162
			{
163
				return getToolTipText( true );
164
			}
145
                
165
                
146
        }
166
		}
147
        
167
        
148
        private String getToolTipText( boolean kilos ) {
168
		private String getToolTipText( boolean kilos ) 
149
            long allocated =  Runtime.getRuntime().totalMemory();
169
		{
150
            long taken = allocated - Runtime.getRuntime().freeMemory() ;
170
			long allocated =  Runtime.getRuntime().totalMemory();
151
            
171
			long taken = allocated - Runtime.getRuntime().freeMemory() ;
152
            if ( kilos ) {
172
            
153
                return " " + ( taken / 1024 ) + "K / " + ( allocated / 1024 ) + "K ";
173
			if ( kilos ) 
154
            }
174
			{
155
            else {
175
				return " " + ( taken / 1024 ) + "K / " + ( allocated / 1024 ) + "K ";
156
                return " " + ( taken ) + " / " + ( allocated ) + " ";
176
			}
157
            }
177
			else 
158
            
178
			{
159
        }
179
				return " " + ( taken ) + " / " + ( allocated ) + " ";
160
        
180
			}
161
        private void updateStatus() {
181
            
162
            invalidate();
182
		}
163
            validate();
183
        
164
            repaint();
184
		private void updateStatus() 
165
        }
185
		{
166
        
186
			invalidate();
167
        public void addNotify() {
187
			validate();
168
            super.addNotify();
188
			repaint();
169
            if ( getParent().isVisible() ) {
189
		}
170
                timer.start();
190
        
171
            }
191
		public void addNotify() 
172
            else {
192
		{
173
                timer.stop();
193
			super.addNotify();
174
            }
194
			if ( getParent().isVisible() ) 
175
            
195
			{
176
        }
196
				timer.start();
177
        
197
			}
178
        public void removeNotify() {
198
			else 
179
            super.removeNotify();
199
			{
180
            timer.stop();
200
				timer.stop();
181
        }
201
			}
202
            
203
		}
204
        
205
		public void removeNotify() 
206
		{
207
			super.removeNotify();
208
			timer.stop();
209
		}
182
        
210
        
183
    }
211
	}
184
    
212
    
185
}
213
}

Return to bug 37256