Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 60142
Collapse All | Expand All

(-)core/startup/src/org/netbeans/core/startup/Splash.java (-28 / +164 lines)
 Lines 29-37    Link Here 
29
import java.awt.Frame;
29
import java.awt.Frame;
30
import java.awt.Graphics;
30
import java.awt.Graphics;
31
import java.awt.Graphics2D;
31
import java.awt.Graphics2D;
32
import java.awt.HeadlessException;
32
import java.awt.Image;
33
import java.awt.Image;
33
import java.awt.Rectangle;
34
import java.awt.Rectangle;
34
import java.awt.RenderingHints;
35
import java.awt.RenderingHints;
36
import java.awt.SplashScreen;
35
import java.awt.Window;
37
import java.awt.Window;
36
import java.awt.event.ActionEvent;
38
import java.awt.event.ActionEvent;
37
import java.awt.event.ActionListener;
39
import java.awt.event.ActionListener;
 Lines 97-104    Link Here 
97
	return Utilities.loadImage(Utilities.isLargeFrameIcons() ? ICON_BIG : ICON_SMALL, true);
99
	return Utilities.loadImage(Utilities.isLargeFrameIcons() ? ICON_BIG : ICON_SMALL, true);
98
    }
100
    }
99
    
101
    
100
    private Frame frame;
101
    
102
    private SplashComponent comp;
102
    private SplashComponent comp;
103
    
103
    
104
    private Splash() {
104
    private Splash() {
 Lines 113-135    Link Here 
113
	    return;
113
	    return;
114
	
114
	
115
	if (running) {
115
	if (running) {
116
	    if (frame == null) {
116
	    comp.start();
117
		frame = new Frame(NbBundle.getMessage(Splash.class, "LBL_splash_window_title")); // e.g. for window tray display
118
		frame.setIconImage(createIDEImage()); // again, only for possible window tray display
119
		frame.setUndecorated(true);
120
		// add splash component
121
		frame.setLayout (new BorderLayout());
122
		frame.add(comp, BorderLayout.CENTER);
123
		
124
		int width = Integer.parseInt(NbBundle.getMessage(Splash.class, "SPLASH_WIDTH"));
125
		int height = Integer.parseInt(NbBundle.getMessage(Splash.class, "SPLASH_HEIGHT"));
126
		frame.setPreferredSize(new Dimension(width, height));
127
		
128
		SwingUtilities.invokeLater (new SplashRunner(frame, true));
129
	    }
130
	}
117
	}
131
	else {
118
	else {
132
	    SwingUtilities.invokeLater (new SplashRunner(frame, false));
119
	    comp.stop();
133
	}
120
	}
134
    }
121
    }
135
    
122
    
 Lines 197-202    Link Here 
197
            return loadSplash();
184
            return loadSplash();
198
        }
185
        }
199
    }
186
    }
187
    
188
    private static class NativeSplash {
189
	
190
	
191
	void close() {
192
	    
193
	}
194
    }
200
195
201
    /**
196
    /**
202
     * This class implements double-buffered splash screen component.
197
     * This class implements double-buffered splash screen component.
 Lines 215-220    Link Here 
215
	private Rectangle rect = new Rectangle();
210
	private Rectangle rect = new Rectangle();
216
	private Rectangle bar = new Rectangle();
211
	private Rectangle bar = new Rectangle();
217
	private Rectangle bar_inc = new Rectangle();
212
	private Rectangle bar_inc = new Rectangle();
213
	final private Rectangle nativeClip;
218
	
214
	
219
	private int progress = 0;
215
	private int progress = 0;
220
	private int maxSteps = 0;
216
	private int maxSteps = 0;
 Lines 226-231    Link Here 
226
	private String text;
222
	private String text;
227
	private FontMetrics fm;
223
	private FontMetrics fm;
228
224
225
	private Frame frame;
226
	
227
	private Object nativeSplash;
228
        
229
        private boolean about; // flag about/splash
230
	
229
	/**
231
	/**
230
         * Creates a new splash screen component.
232
         * Creates a new splash screen component.
231
	 * param about true is this component will be used in about dialog
233
	 * param about true is this component will be used in about dialog
 Lines 277-292    Link Here 
277
	    } catch (NumberFormatException nfe) {
279
	    } catch (NumberFormatException nfe) {
278
		//ignore - use default size
280
		//ignore - use default size
279
	    }
281
	    }
282
            this.about = about;
280
	    
283
	    
281
	    image = new ImageIcon(about? loadAbout(): loadSplash()).getImage(); // load!
282
	
283
	    Font font = new Font("Dialog", Font.PLAIN, size);
284
	    Font font = new Font("Dialog", Font.PLAIN, size);
284
	    
285
	    
285
	    setFont(font); // NOI18N
286
	    setFont(font); // NOI18N
286
	    fm = getFontMetrics(font);
287
	    fm = getFontMetrics(font);
288
            nativeClip = bar.union(view);
287
        }
289
        }
288
290
289
        /**
291
	public void start() {
292
	    nativeSplash = getNative();
293
	    // we are already showing splash
294
	    if (nativeSplash != null) 
295
		return;
296
	    
297
	    if (frame == null) {
298
                image = new ImageIcon(about? loadAbout(): loadSplash()).getImage(); // load!
299
                
300
		frame = new Frame(NbBundle.getMessage(Splash.class, "LBL_splash_window_title")); // e.g. for window tray display
301
		frame.setIconImage(createIDEImage()); // again, only for possible window tray display
302
		frame.setUndecorated(true);
303
		// add splash component
304
		frame.setLayout (new BorderLayout());
305
		frame.add(this, BorderLayout.CENTER);
306
		
307
		int width = Integer.parseInt(NbBundle.getMessage(Splash.class, "SPLASH_WIDTH"));
308
		int height = Integer.parseInt(NbBundle.getMessage(Splash.class, "SPLASH_HEIGHT"));
309
		frame.setPreferredSize(new Dimension(width, height));
310
		
311
		SwingUtilities.invokeLater (new SplashRunner(frame, true));
312
	    }
313
	}
314
315
	private void stop() {
316
	    if (nativeSplash != null) {
317
		closeNative(nativeSplash);
318
		return;
319
	    }
320
	    SwingUtilities.invokeLater (new SplashRunner(frame, false));
321
	}
322
	
323
	/**
290
         * Defines the single line of text this component will display.
324
         * Defines the single line of text this component will display.
291
         */
325
         */
292
        public void setText(final String text) {
326
        public void setText(final String text) {
 Lines 312-318    Link Here 
312
                                                       view, new Rectangle(), rect, 0);
346
                                                       view, new Rectangle(), rect, 0);
313
                    dirty = dirty.union(rect);
347
                    dirty = dirty.union(rect);
314
                    // update screen (assume repaint manager optimizes unions;)
348
                    // update screen (assume repaint manager optimizes unions;)
315
                    repaint(dirty);
349
		    Object ss = getNative();
350
		    if (ss != null) {
351
			updateNative(ss, dirty);
352
                        nativeRepaintText = true;
353
		    }
354
		    else {
355
                        repaint(dirty);
356
		    }
316
                    dirty = new Rectangle(rect);
357
                    dirty = new Rectangle(rect);
317
                }
358
                }
318
            });
359
            });
 Lines 376-386    Link Here 
376
		progress = maxSteps;
417
		progress = maxSteps;
377
	    else if (maxSteps > 0) {
418
	    else if (maxSteps > 0) {
378
		int bl = bar.width * progress / maxSteps - barStart;
419
		int bl = bar.width * progress / maxSteps - barStart;
379
		if (bl > 1 || barStart % 2 == 0) {
420
		if (bl > 2) {
380
		    barLength = bl;
421
		    barLength = bl;
381
		    bar_inc = new Rectangle(bar.x + barStart, bar.y, barLength + 1, bar.height);
422
		    bar_inc = new Rectangle(bar.x + barStart, bar.y, barLength + 1, bar.height);
382
//System.out.println(this);
423
//System.out.println(this);
383
		    repaint(bar_inc);
424
		    Object ss = getNative();
425
		    if (ss != null) {
426
			updateNative(ss, bar);
427
                        nativeRepaintBar = true;
428
		    }
429
		    else {
430
        		repaint(bar_inc);
431
		    }
384
//System.out.println("(painting " + bar_inc + ")");
432
//System.out.println("(painting " + bar_inc + ")");
385
		}
433
		}
386
	    }
434
	    }
 Lines 393-399    Link Here 
393
	 */
441
	 */
394
	private void addToMaxSteps(int steps) {
442
	private void addToMaxSteps(int steps) {
395
	    int max = maxSteps + steps;
443
	    int max = maxSteps + steps;
396
	    int prog = progress / maxSteps * max;
444
	    int prog = progress * max / maxSteps ;
397
	    maxSteps = max;
445
	    maxSteps = max;
398
	    progress = prog;
446
	    progress = prog;
399
	    // do repaint on next increment
447
	    // do repaint on next increment
 Lines 410-417    Link Here 
410
         * Renders this component to the given graphics.
458
         * Renders this component to the given graphics.
411
         */
459
         */
412
        public void paint(Graphics graphics) {
460
        public void paint(Graphics graphics) {
461
            paint(graphics, false);
462
        }
463
        
464
        /**
465
         * Renders this component to the given graphics.
466
         */
467
        private void paint(Graphics graphics, boolean toNative) {
413
            graphics.setColor(color_text);
468
            graphics.setColor(color_text);
414
            graphics.drawImage(image, 0, 0, null);
469
            if (!toNative) {
470
                graphics.drawImage(image, 0, 0, null);
471
            }
415
472
416
            if (text != null) {
473
            if (text != null) {
417
		if (fm == null) {
474
		if (fm == null) {
 Lines 419-424    Link Here 
419
		    // fully understand why
476
		    // fully understand why
420
		    return;
477
		    return;
421
		}
478
		}
479
                Rectangle clip = graphics.getClipBounds();
480
                if ((clip == null || clip.intersects(view)) && (!toNative || nativeRepaintText)) { 
422
		
481
		
423
		SwingUtilities.layoutCompoundLabel(fm, text, null,
482
		SwingUtilities.layoutCompoundLabel(fm, text, null,
424
			BOTTOM, LEFT, BOTTOM, LEFT,
483
			BOTTOM, LEFT, BOTTOM, LEFT,
 Lines 428-437    Link Here 
428
		g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
487
		g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
429
			RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
488
			RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
430
		graphics.drawString(text, rect.x, rect.y + fm.getAscent());
489
		graphics.drawString(text, rect.x, rect.y + fm.getAscent());
490
                }
491
//                else {
492
//                    System.out.println("skipping text painting");
493
//                }
431
            }
494
            }
432
495
433
            // Draw progress bar if applicable
496
            // Draw progress bar if applicable
434
            if (!noBar && maxSteps > 0/* && barLength > 0*/)
497
            if (!noBar && maxSteps > 0/* && barLength > 0*/ && (!toNative || nativeRepaintBar))
435
            {
498
            {
436
                graphics.setColor(color_bar);
499
                graphics.setColor(color_bar);
437
                graphics.fillRect(bar.x, bar.y, barStart + barLength, bar.height);
500
                graphics.fillRect(bar.x, bar.y, barStart + barLength, bar.height);
 Lines 439-449    Link Here 
439
                graphics.drawLine(bar.x, bar.y, bar.x, bar.y + bar.height);
502
                graphics.drawLine(bar.x, bar.y, bar.x, bar.y + bar.height);
440
                graphics.drawLine(bar.x + barStart + barLength, bar.y, bar.x + barStart + barLength, bar.y + bar.height);
503
                graphics.drawLine(bar.x + barStart + barLength, bar.y, bar.x + barStart + barLength, bar.y + bar.height);
441
                graphics.setColor(color_edge);
504
                graphics.setColor(color_edge);
442
                graphics.drawLine(bar.x, bar.y + bar.height / 2, bar.x, bar.y + bar.height / 2);
505
                graphics.drawLine(bar.x, bar.y + bar.height / 2, bar.x, bar.y + bar.height - bar.height / 2);
443
                graphics.drawLine(bar.x + barStart + barLength, bar.y + bar.height / 2, bar.x + barStart + barLength, bar.y + bar.height / 2);
506
                graphics.drawLine(bar.x + barStart + barLength, bar.y + bar.height / 2, bar.x + barStart + barLength, bar.y + bar.height - bar.height / 2);
444
                barStart += barLength;
507
                barStart += barLength;
445
                barLength = 0;
508
                barLength = 0;
446
            }            
509
            }            
510
            nativeRepaintScheduled = false;
511
            nativeRepaintBar = false;
512
            nativeRepaintText = false;
447
        }
513
        }
448
514
449
        public Dimension getPreferredSize() {
515
        public Dimension getPreferredSize() {
 Lines 454-464    Link Here 
454
            return true;
520
            return true;
455
        }
521
        }
456
        
522
        
523
	private Object getNative () {
524
            if (ss == null) {
525
                try {
526
                    ss = SplashScreen.getSplashScreen();
527
                    if (ss != null) {
528
                        nativeGraphics = ss.createGraphics();
529
                        nativeGraphics.setClip(nativeClip);
530
                    }
531
                } catch (UnsupportedOperationException ex) { // OK, not supported
532
                }
533
            }
534
	    
535
	    return ss;
536
	}
537
	
538
	private void closeNative(Object ss) {
539
            System.out.println("counter "+counter);
540
	    if (ss != null) {
541
		try {
542
                    ((SplashScreen)ss).close();
543
                }
544
                catch (IllegalStateException ise) {
545
                    ss = null;
546
                    nativeGraphics = null;
547
                }
548
	    }
549
	}
550
        
551
        private boolean nativeRepaintScheduled = false;
552
        private boolean nativeRepaintBar = false;
553
        private boolean nativeRepaintText = false;
554
555
        private SplashScreen ss = null;
556
        private Graphics2D nativeGraphics;
557
        
558
        private static int counter = 0;
559
	
560
	private void updateNative(Object ss, final Rectangle clip) {
561
            if (nativeRepaintScheduled)
562
                return;
563
	    final SplashScreen s = (SplashScreen)ss;
564
            nativeRepaintScheduled = true;
565
            SwingUtilities.invokeLater(new Runnable() {
566
                public void run() {
567
                    try {
568
                        long t0 = System.currentTimeMillis();
569
//                        g.setClip(clip);
570
                        Graphics2D g = nativeGraphics;
571
                        if (g == null) 
572
                            return;
573
                        paint(g, true);
574
                        long t1 = System.currentTimeMillis();
575
//                        g.setClip(nativeClip);
576
                        s.update();
577
                        long t2 = System.currentTimeMillis();
578
                        ++counter;
579
//                        System.out.println("splash update "+counter+": "+(t1-t0)+",\t"+(t2-t1)+", "+System.identityHashCode(nativeGraphics));
580
                    } 
581
                    catch (IllegalStateException ex) {} // ignore
582
                }
583
                
584
            });
585
	}
586
	
587
	
457
	public String toString() {
588
	public String toString() {
458
	    return "SplashComponent - " +
589
	    return "SplashComponent - " +
459
		    "progress: " + progress + "/" + maxSteps +
590
		    "progress: " + progress + "/" + maxSteps +
460
		    " text: " + text;
591
		    " text: " + text;
461
	}
592
	}
593
462
    }
594
    }
463
595
464
    private static class SplashDialog extends JDialog implements ActionListener {
596
    private static class SplashDialog extends JDialog implements ActionListener {
 Lines 523-527    Link Here 
523
            }
655
            }
524
        }
656
        }
525
    }
657
    }
658
659
	public org.netbeans.core.startup.Splash.SplashComponent getComp() {
660
		return comp;
661
	}
526
662
527
}
663
}

Return to bug 60142
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo