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 104474
Collapse All | Expand All

(-)graph/examples/src/org/netbeans/modules/visual/examples/RunDialog.java (+1 lines)
Lines 105-110 Link Here
105
        "test.swingborder.SwingBorderTest",
105
        "test.swingborder.SwingBorderTest",
106
        "test.tool.CtrlKeySwitchToolTest",
106
        "test.tool.CtrlKeySwitchToolTest",
107
        "test.tool.ToolTest",
107
        "test.tool.ToolTest",
108
        "test.view.OffscreenRenderingTest",
108
        "test.visible.VisibilityTest",
109
        "test.visible.VisibilityTest",
109
        "test.vmd.VMDCollisionTest",
110
        "test.vmd.VMDCollisionTest",
110
        "test.vmd.VMDColorSchemeTest",
111
        "test.vmd.VMDColorSchemeTest",
(-)graph/examples/src/test/view/OffscreenRenderingTest.java (+65 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package test.view;
21
22
import org.netbeans.api.visual.border.BorderFactory;
23
import org.netbeans.api.visual.widget.LabelWidget;
24
import org.netbeans.api.visual.widget.Scene;
25
import test.SceneSupport;
26
27
import javax.swing.*;
28
import java.awt.*;
29
import java.awt.image.BufferedImage;
30
31
/**
32
 * @author David Kaspar
33
 */
34
public class OffscreenRenderingTest {
35
36
    public static void main (String[] args) {
37
        Scene scene = new Scene ();
38
39
        LabelWidget widget = new LabelWidget (scene, "Hi");
40
        widget.setVerticalAlignment (LabelWidget.VerticalAlignment.CENTER);
41
        widget.setAlignment (LabelWidget.Alignment.CENTER);
42
        widget.setBorder (BorderFactory.createLineBorder ());
43
        widget.setPreferredSize (new Dimension (40, 40));
44
        scene.addChild (widget);
45
46
        // validate the scene with a off-screen graphics
47
        BufferedImage emptyImage = new BufferedImage (1, 1, BufferedImage.TYPE_4BYTE_ABGR);
48
        Graphics2D emptyGraphics = emptyImage.createGraphics ();
49
        scene.validate (emptyGraphics);
50
        emptyGraphics.dispose ();
51
52
        // now the scene is calculated using the emptyGraphics, all widgets should be layout and scene has its size resolved
53
        // paint the scene with a off-screen graphics
54
        Rectangle viewBounds = scene.convertSceneToView (scene.getBounds ());
55
        BufferedImage image = new BufferedImage (viewBounds.width, viewBounds.height, BufferedImage.TYPE_4BYTE_ABGR);
56
        Graphics2D graphics = image.createGraphics ();
57
        double zoomFactor = scene.getZoomFactor ();
58
        graphics.scale (zoomFactor, zoomFactor);
59
        scene.paint (graphics);
60
        graphics.dispose ();
61
62
        SceneSupport.show (new JLabel (new ImageIcon (image)));
63
    }
64
65
}
(-)graph/lib/apichanges.xml (+15 lines)
Lines 444-449 Link Here
444
            <class package="org.netbeans.api.visual.widget" name="Widget" link="yes"/>
444
            <class package="org.netbeans.api.visual.widget" name="Widget" link="yes"/>
445
            <issue number="108856"/>
445
            <issue number="108856"/>
446
        </change>
446
        </change>
447
448
        <change>
449
            <api name="general"/>
450
            <summary>Widget.validate(Graphics2D) method added to support off-screen rendering</summary>
451
            <version major="2" minor="7"/>
452
            <date day="1" month="8" year="2007"/>
453
            <author login="dkaspar"/>
454
            <compatibility semantic="incompatible" modification="yes"/>
455
            <description>
456
                Scene.validate(Graphics2D) method has been added. It allows to validate a scene without having a main scene view created and shown on screen.
457
                See test.view.OffscreenRenderingTest example for usage.
458
            </description>
459
            <class package="org.netbeans.api.visual.widget" name="Widget" link="yes"/>
460
            <issue number="104474"/>
461
        </change>
447
    </changes>
462
    </changes>
448
463
449
    <htmlcontents>
464
    <htmlcontents>
(-)graph/lib/manifest.mf (-1 / +1 lines)
Lines 1-4 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.api.visual
2
OpenIDE-Module: org.netbeans.api.visual
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/visual/resources/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/visual/resources/Bundle.properties
4
OpenIDE-Module-Specification-Version: 2.6
4
OpenIDE-Module-Specification-Version: 2.7
(-)graph/lib/src/org/netbeans/api/visual/widget/Scene.java (-21 / +39 lines)
Lines 190-195 Link Here
190
    }
190
    }
191
191
192
    /**
192
    /**
193
     * This method invokes Scene.validate method with a specific Graphics2D instance. This is useful for rendering a scene off-screen
194
     * without creating and showning the main scene view. See test.view.OffscreenRenderingTest example for usages.
195
     * <p>
196
     * Note: Do not call this method unless you know the consequences. The scene is going to be validated using the specified Graphics2D
197
     * instance even after the method call therefore it may break scene layout when your main scene view is finally created and shown.
198
     * @param graphics the graphics instance used for validation
199
     * @since 2.7
200
     */
201
    public final void validate (Graphics2D graphics) {
202
        Graphics2D prevoiusGraphics = getGraphics ();
203
        setGraphics (graphics);
204
        validate ();
205
        setGraphics (prevoiusGraphics);
206
}
207
    /**
193
     * Paints the whole scene into the graphics instance. The method calls validate before rendering.
208
     * Paints the whole scene into the graphics instance. The method calls validate before rendering.
194
     * @param graphics the Graphics2D instance where the scene is going to be painted
209
     * @param graphics the Graphics2D instance where the scene is going to be painted
195
     */
210
     */
Lines 294-322 Link Here
294
309
295
        Dimension preferredSize = rect != null ? rect.getSize () : new Dimension ();
310
        Dimension preferredSize = rect != null ? rect.getSize () : new Dimension ();
296
        preferredSize = new Dimension ((int) (preferredSize.width * zoomFactor), (int) (preferredSize.height * zoomFactor));
311
        preferredSize = new Dimension ((int) (preferredSize.width * zoomFactor), (int) (preferredSize.height * zoomFactor));
297
        if (! preferredSize.equals (component.getPreferredSize ())) {
298
            component.setPreferredSize (preferredSize);
299
            component.revalidate ();
300
//            repaintSatellite ();
301
        }
302
303
        Dimension componentSize = component.getSize ();
304
        componentSize.width = (int) (componentSize.width / zoomFactor);
305
        componentSize.height = (int) (componentSize.height / zoomFactor);
306
        Rectangle bounds = getBounds ();
312
        Rectangle bounds = getBounds ();
313
        if (component != null) {
314
            if (! preferredSize.equals (component.getPreferredSize ())) {
315
                component.setPreferredSize (preferredSize);
316
                component.revalidate ();
317
                bounds = getBounds ();
318
//                repaintSatellite ();
319
            }
307
320
308
        boolean sceneResized = false;
321
            Dimension componentSize = component.getSize ();
309
        if (bounds.width < componentSize.width) {
322
            componentSize.width = (int) (componentSize.width / zoomFactor);
310
            bounds.width = componentSize.width;
323
            componentSize.height = (int) (componentSize.height / zoomFactor);
311
            sceneResized = true;
324
312
        }
325
            boolean sceneResized = false;
313
        if (bounds.height < componentSize.height) {
326
            if (bounds.width < componentSize.width) {
314
            bounds.height = componentSize.height;
327
                bounds.width = componentSize.width;
315
            sceneResized = true;
328
                sceneResized = true;
329
            }
330
            if (bounds.height < componentSize.height) {
331
                bounds.height = componentSize.height;
332
                sceneResized = true;
333
            }
334
            if (sceneResized)
335
                resolveBounds (getLocation (), bounds);
316
        }
336
        }
317
        if (sceneResized)
318
            resolveBounds (getLocation (), bounds);
319
320
        if (! getLocation ().equals (preLocation)  ||  ! bounds.equals (preBounds)) {
337
        if (! getLocation ().equals (preLocation)  ||  ! bounds.equals (preBounds)) {
321
            Rectangle rectangle = convertLocalToScene (getBounds ());
338
            Rectangle rectangle = convertLocalToScene (getBounds ());
322
            if (repaintRegion == null)
339
            if (repaintRegion == null)
Lines 363-369 Link Here
363
            if (repaintRegion != null) {
380
            if (repaintRegion != null) {
364
                Rectangle r = convertSceneToView (repaintRegion);
381
                Rectangle r = convertSceneToView (repaintRegion);
365
                r.grow (1, 1);
382
                r.grow (1, 1);
366
                component.repaint (r);
383
                if (component != null)
384
                    component.repaint (r);
367
                repaintSatellite ();
385
                repaintSatellite ();
368
                repaintRegion = null;
386
                repaintRegion = null;
369
            }
387
            }
(-)graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html (+3 lines)
Lines 521-526 Link Here
521
<td>validate
521
<td>validate
522
<td>This method validates whole scene with all widgets. Usually it is called automatically e.g. at the end of event processing. See <a href="#ValidationProcess">Validation Process</a> section.
522
<td>This method validates whole scene with all widgets. Usually it is called automatically e.g. at the end of event processing. See <a href="#ValidationProcess">Validation Process</a> section.
523
<tr>
523
<tr>
524
<td>validate(Graphics2D)
525
<td>This method validates whole scene with all widgets using specified Graphics2D. This is used for off-screen rendering when you do not have a main scene view created yet. Be aware that the scene is going to remain validated with specified font metrics after the method call. This may break scene layout when your main scene view is finally created and shown. See <a href="#ValidationProcess">Validation Process</a> section.
526
<tr>
524
<td>getMaximumBounds<br>setMaximumBounds
527
<td>getMaximumBounds<br>setMaximumBounds
525
<td>Controls the maximum bounds of the scene. By default it is <code>[-Integer.MAX_VALUE/2,-Integer.MAX_VALUE/2,Integer.MAX_VALUE,Integer.MAX_VALUE]</code>. This is used to limit the scene bounds e.g. to positive values only.
528
<td>Controls the maximum bounds of the scene. By default it is <code>[-Integer.MAX_VALUE/2,-Integer.MAX_VALUE/2,Integer.MAX_VALUE,Integer.MAX_VALUE]</code>. This is used to limit the scene bounds e.g. to positive values only.
526
<tr>
529
<tr>
(-)graph/www/documentation.html (+1 lines)
Lines 175-180 Link Here
175
<li><strong>test.swingborder.SwingBorderTest</strong> - how to use borders for Swing
175
<li><strong>test.swingborder.SwingBorderTest</strong> - how to use borders for Swing
176
<li><strong>test.tool.CtrlKeySwitchToolTest</strong> - how to create active-tool switching using ctrl key
176
<li><strong>test.tool.CtrlKeySwitchToolTest</strong> - how to create active-tool switching using ctrl key
177
<li><strong>test.tool.ToolTest</strong> - how to use action-tools
177
<li><strong>test.tool.ToolTest</strong> - how to use action-tools
178
<li><strong>test.view.OffscreenRenderingTest</strong> - how to off-screen render a scene
178
<li><strong>test.visible.NotifyAddedRemovedTest</strong> - test of <code>Widget.notifyAdded</code> and <code>Widget.notifyRemoved</code> methods
179
<li><strong>test.visible.NotifyAddedRemovedTest</strong> - test of <code>Widget.notifyAdded</code> and <code>Widget.notifyRemoved</code> methods
179
<li><strong>test.visible.VisibilityTest</strong> - compatibility test of <code>Layout</code> implementations with <code>Widget.visible</code> property
180
<li><strong>test.visible.VisibilityTest</strong> - compatibility test of <code>Layout</code> implementations with <code>Widget.visible</code> property
180
<li><strong>test.vmd.VMDCollisionTest</strong> - test of <code>WidgetCollisionCollector</code>
181
<li><strong>test.vmd.VMDCollisionTest</strong> - test of <code>WidgetCollisionCollector</code>

Return to bug 104474