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

(-)progress/api/doc/changes/apichanges.xml (-1 / +19 lines)
Lines 84-90 Link Here
84
  <changes>
84
  <changes>
85
    <change>
85
    <change>
86
        <api name="progress_api"/>
86
        <api name="progress_api"/>
87
        <summary>Split APi and implementation of progress compoennt</summary>
87
        <summary>Add methods to create main/detail labels for an custom placed progress component.</summary>
88
        <version major="1" minor="8"/>
89
        <date day="2" month="8" year="2006"/>
90
        <author login="mkleint"/>
91
        <compatibility addition="yes"/>
92
        <description>
93
            <p>Adding <code>createMainLabelComponent(ProgressHandle)</code> and 
94
                      <code>createDetailLabelComponent(ProgressHandle)</code> to <code>ProgressHandleFactory, AggregateProgressHandleFactory</code> classes.
95
              These are complimentary to the <code>extractProgressComponent(ProgressHandle)</code> method and allow to 
96
              externalize the display of task's display name and detail messages when embedded in custom UI components.
97
            </p>
98
        </description>
99
        <class package="org.netbeans.api.progress" name="ProgressHandleFactory"/>
100
        <class package="org.netbeans.api.progress.aggregate" name="AggregateProgressHandleFactory"/>
101
        <issue number="58889"/>
102
    </change>      
103
    <change>
104
        <api name="progress_api"/>
105
        <summary>Split API and implementation of progress component</summary>
88
        <version major="1" minor="7"/>
106
        <version major="1" minor="7"/>
89
        <date day="24" month="7" year="2006"/>
107
        <date day="24" month="7" year="2006"/>
90
        <author login="mkleint"/>
108
        <author login="mkleint"/>
(-)progress/src/org/netbeans/api/progress/ProgressHandle.java (-1 / +10 lines)
Lines 25-30 Link Here
25
import java.util.Collections;
25
import java.util.Collections;
26
import java.util.List;
26
import java.util.List;
27
import javax.swing.JComponent;
27
import javax.swing.JComponent;
28
import javax.swing.JLabel;
28
import javax.swing.JProgressBar;
29
import javax.swing.JProgressBar;
29
import org.netbeans.progress.spi.InternalHandle;
30
import org.netbeans.progress.spi.InternalHandle;
30
31
Lines 148-154 Link Here
148
    /**
149
    /**
149
     * change the display name of the progress task. Use with care, please make sure the changed name is not completely different,
150
     * change the display name of the progress task. Use with care, please make sure the changed name is not completely different,
150
     * or otherwise it might appear to the user as a different task.
151
     * or otherwise it might appear to the user as a different task.
151
     * @since 1.5
152
     * @since org.netbeans.api.progress 1.5
152
     */
153
     */
153
    public void setDisplayName(String newDisplayName) {
154
    public void setDisplayName(String newDisplayName) {
154
        internal.requestDisplayNameChange(newDisplayName);
155
        internal.requestDisplayNameChange(newDisplayName);
Lines 167-172 Link Here
167
     */
168
     */
168
    InternalHandle getInternalHandle() {
169
    InternalHandle getInternalHandle() {
169
        return internal;
170
        return internal;
171
    }
172
173
    JLabel extractDetailLabel() {
174
        return internal.extractDetailLabel();
175
    }
176
177
    JLabel extractMainLabel() {
178
        return internal.extractMainLabel();
170
    }
179
    }
171
    
180
    
172
181
(-)progress/src/org/netbeans/api/progress/ProgressHandleFactory.java (+21 lines)
Lines 21-26 Link Here
21
21
22
import javax.swing.Action;
22
import javax.swing.Action;
23
import javax.swing.JComponent;
23
import javax.swing.JComponent;
24
import javax.swing.JLabel;
24
import org.netbeans.progress.spi.InternalHandle;
25
import org.netbeans.progress.spi.InternalHandle;
25
import org.openide.util.Cancellable;
26
import org.openide.util.Cancellable;
26
27
Lines 91-96 Link Here
91
     */
92
     */
92
    public static JComponent createProgressComponent(ProgressHandle handle) {
93
    public static JComponent createProgressComponent(ProgressHandle handle) {
93
        return handle.extractComponent();
94
        return handle.extractComponent();
95
    }
96
    
97
    /**
98
     * Get the task title component for use in custom dialogs, the task won't 
99
     * show in the progress bar anymore. The text of the label is changed by calls to <code>ProgressHandle.setDisplayName()</code> method
100
     * @return the component to use in custom UI.
101
     * @since org.netbeans.api.progress 1.8
102
     */
103
    public static JLabel createMainLabelComponent(ProgressHandle handle) {
104
        return handle.extractMainLabel();
105
    }
106
    
107
    /**
108
     * Get the detail messages component for use in custom dialogs, the task won't 
109
     * show in the progress bar anymore. The text of the label is changed by calls to <code>ProgressHandle.progress(String)</code> method.
110
     * @return the component to use in custom UI.
111
     * @since org.netbeans.api.progress 1.8
112
     */
113
    public static JLabel createDetailLabelComponent(ProgressHandle handle) {
114
        return handle.extractDetailLabel();
94
    }
115
    }
95
    
116
    
96
    /**
117
    /**
(-)progress/src/org/netbeans/api/progress/aggregate/AggregateProgressFactory.java (-2 / +23 lines)
Lines 21-27 Link Here
21
21
22
import javax.swing.Action;
22
import javax.swing.Action;
23
import javax.swing.JComponent;
23
import javax.swing.JComponent;
24
import org.netbeans.progress.spi.InternalHandle;
24
import javax.swing.JLabel;
25
import org.netbeans.api.progress.ProgressHandle;
25
import org.openide.util.Cancellable;
26
import org.openide.util.Cancellable;
26
27
27
/**
28
/**
Lines 77-87 Link Here
77
    /**
78
    /**
78
     * Get the progress bar component for use in custom dialogs, the task won't 
79
     * Get the progress bar component for use in custom dialogs, the task won't 
79
     * show in the progress bar anymore.
80
     * show in the progress bar anymore.
80
     * @since 1.3
81
     * @since org.netbeans.api.progress 1.3
81
     * @return the component to use in custom UI.
82
     * @return the component to use in custom UI.
82
     */
83
     */
83
    public static JComponent createProgressComponent(AggregateProgressHandle handle) {
84
    public static JComponent createProgressComponent(AggregateProgressHandle handle) {
84
        return handle.extractComponent();
85
        return handle.extractComponent();
85
    }    
86
    }    
87
    
88
    /**
89
     * Get the task title component for use in custom dialogs, the task won't 
90
     * show in the progress bar anymore. The text of the label is changed by calls to handle's <code>setDisplayName()</code> method.
91
     * @return the component to use in custom UI.
92
     * @since org.netbeans.api.progress 1.8
93
     */
94
    public static JLabel createMainLabelComponent(AggregateProgressHandle handle) {
95
        return handle.extractMainLabel();
96
    }
97
    
98
    /**
99
     * Get the detail messages component for use in custom dialogs, the task won't 
100
     * show in the progress bar anymore.The text of the label is changed by calls to contributors' <code>progress(String)</code> methods.
101
     * @return the component to use in custom UI.
102
     * @since org.netbeans.api.progress 1.8
103
     */
104
    public static JLabel createDetailLabelComponent(AggregateProgressHandle handle) {
105
        return handle.extractDetailLabel();
106
    }
86
    
107
    
87
}
108
}
(-)progress/src/org/netbeans/api/progress/aggregate/AggregateProgressHandle.java (+9 lines)
Lines 24-29 Link Here
24
import java.util.Iterator;
24
import java.util.Iterator;
25
import javax.swing.Action;
25
import javax.swing.Action;
26
import javax.swing.JComponent;
26
import javax.swing.JComponent;
27
import javax.swing.JLabel;
27
import org.netbeans.api.progress.ProgressHandle;
28
import org.netbeans.api.progress.ProgressHandle;
28
import org.netbeans.api.progress.ProgressHandleFactory;
29
import org.netbeans.api.progress.ProgressHandleFactory;
29
import org.openide.util.Cancellable;
30
import org.openide.util.Cancellable;
Lines 226-229 Link Here
226
    JComponent extractComponent() {
227
    JComponent extractComponent() {
227
        return ProgressHandleFactory.createProgressComponent(handle);
228
        return ProgressHandleFactory.createProgressComponent(handle);
228
    }    
229
    }    
230
231
    JLabel extractDetailLabel() {
232
        return ProgressHandleFactory.createDetailLabelComponent(handle);
233
    }
234
235
    JLabel extractMainLabel() {
236
        return ProgressHandleFactory.createMainLabelComponent(handle);
237
    }
229
}
238
}
(-)progress/src/org/netbeans/progress/module/Controller.java (+1 lines)
Lines 86-91 Link Here
86
        return defaultInstance;
86
        return defaultInstance;
87
    }
87
    }
88
    
88
    
89
    // to be called on the default instance only..
89
    Component getVisualComponent() {
90
    Component getVisualComponent() {
90
        if (component instanceof Component) {
91
        if (component instanceof Component) {
91
            return (Component)component;
92
            return (Component)component;
(-)progress/src/org/netbeans/progress/spi/ExtractedProgressUIWorker.java (+34 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 2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.progress.spi;
21
22
import javax.swing.JComponent;
23
import javax.swing.JLabel;
24
25
/**
26
 *
27
 * @author mkleint
28
 */
29
public interface ExtractedProgressUIWorker extends ProgressUIWorker {
30
    
31
    JComponent getProgressComponent();
32
    JLabel getMainLabelComponent();
33
    JLabel getDetailLabelComponent();
34
}
(-)progress/src/org/netbeans/progress/spi/InternalHandle.java (-11 / +43 lines)
Lines 29-34 Link Here
29
import java.util.logging.Logger;
29
import java.util.logging.Logger;
30
import javax.swing.Action;
30
import javax.swing.Action;
31
import javax.swing.JComponent;
31
import javax.swing.JComponent;
32
import javax.swing.JLabel;
32
import javax.swing.JProgressBar;
33
import javax.swing.JProgressBar;
33
import javax.swing.SwingUtilities;
34
import javax.swing.SwingUtilities;
34
import org.netbeans.progress.module.*;
35
import org.netbeans.progress.module.*;
Lines 45-51 Link Here
45
    private String displayName;
46
    private String displayName;
46
    private boolean allowCancel;
47
    private boolean allowCancel;
47
    private boolean allowBackground;
48
    private boolean allowBackground;
48
    private boolean customPlaced = false;
49
    private boolean customPlaced1 = false;
50
    private boolean customPlaced2 = false;
51
    private boolean customPlaced3 = false;
49
    private int state;
52
    private int state;
50
    private int totalUnits;
53
    private int totalUnits;
51
    private int currentUnit;
54
    private int currentUnit;
Lines 58-63 Link Here
58
    private final boolean userInitiated;
61
    private final boolean userInitiated;
59
    private int initialDelay = Controller.INITIAL_DELAY;
62
    private int initialDelay = Controller.INITIAL_DELAY;
60
    private Controller controller;
63
    private Controller controller;
64
    private ExtractedProgressUIWorker component;
61
    
65
    
62
    public static final int STATE_INITIALIZED = 0;
66
    public static final int STATE_INITIALIZED = 0;
63
    public static final int STATE_RUNNING = 1;
67
    public static final int STATE_RUNNING = 1;
Lines 103-109 Link Here
103
    
107
    
104
    
108
    
105
    public boolean isCustomPlaced() {
109
    public boolean isCustomPlaced() {
106
        return customPlaced;
110
        return component != null;
107
    }
111
    }
108
    
112
    
109
    public boolean isUserInitialized() {
113
    public boolean isUserInitialized() {
Lines 180-186 Link Here
180
        timeStarted = System.currentTimeMillis();
184
        timeStarted = System.currentTimeMillis();
181
        timeLastProgress = timeStarted;
185
        timeLastProgress = timeStarted;
182
186
183
        if (! customPlaced) {
187
        if (controller == null) {
184
            controller = Controller.getDefault();
188
            controller = Controller.getDefault();
185
        }
189
        }
186
        
190
        
Lines 294-318 Link Here
294
                            (initialEstimate == -1 ? -1 : calculateFinishEstimate()));
298
                            (initialEstimate == -1 ? -1 : calculateFinishEstimate()));
295
    }
299
    }
296
    
300
    
301
    private void createExtractedWorker() {
302
        if (component == null) {
303
            ProgressUIWorkerProvider prov = (ProgressUIWorkerProvider)Lookup.getDefault().lookup(ProgressUIWorkerProvider.class); 
304
            assert prov != null;
305
            component = prov.getExtractedComponentWorker();
306
            controller = new Controller(component);
307
        }
308
    }
297
    /**
309
    /**
298
     * have the component in custom location, don't include in the status bar.
310
     * have the component in custom location, don't include in the status bar.
299
     */
311
     */
300
    public synchronized JComponent extractComponent() {
312
    public synchronized JComponent extractComponent() {
301
        if (customPlaced) {
313
        if (customPlaced1) {
302
            throw new IllegalStateException("Cannot retrieve progress component multiple times");
314
            throw new IllegalStateException("Cannot retrieve progress component multiple times");
303
        }
315
        }
304
        if (state != STATE_INITIALIZED) {
316
        if (state != STATE_INITIALIZED) {
305
            throw new IllegalStateException("You can request custom placement of progress component only before starting the task");
317
            throw new IllegalStateException("You can request custom placement of progress component only before starting the task");
306
        }
318
        }
307
        customPlaced = true;
319
        customPlaced1 = true;
308
        ProgressUIWorkerProvider prov = (ProgressUIWorkerProvider)Lookup.getDefault().lookup(ProgressUIWorkerProvider.class); 
320
        createExtractedWorker();
309
        assert prov != null;
321
        return component.getProgressComponent();
310
        ProgressUIWorker component = prov.getExtractedComponentWorker();
311
        controller = new Controller(component);
312
        return (JComponent)component;
313
    }
322
    }
314
    
323
    
315
    
324
    public JLabel extractDetailLabel() {
325
        if (customPlaced2) {
326
            throw new IllegalStateException("Cannot retrieve progress detail label component multiple times");
327
        }
328
        if (state != STATE_INITIALIZED) {
329
            throw new IllegalStateException("You can request custom placement of progress component only before starting the task");
330
        }
331
        customPlaced2 = true;
332
        createExtractedWorker();
333
        return component.getDetailLabelComponent();
334
    }
335
336
    public JLabel extractMainLabel() {
337
        if (customPlaced3) {
338
            throw new IllegalStateException("Cannot retrieve progress main label component multiple times");
339
        }
340
        if (state != STATE_INITIALIZED) {
341
            throw new IllegalStateException("You can request custom placement of progress component only before starting the task");
342
        }
343
        customPlaced3 = true;
344
        createExtractedWorker();
345
        return component.getMainLabelComponent();
346
    }
347
316
    long calculateFinishEstimate() {
348
    long calculateFinishEstimate() {
317
        
349
        
318
        // we are interested in seconds only
350
        // we are interested in seconds only
(-)progress/src/org/netbeans/progress/spi/ProgressUIWorkerProvider.java (-1 / +1 lines)
Lines 27-31 Link Here
27
    
27
    
28
    public ProgressUIWorkerWithModel getDefaultWorker();
28
    public ProgressUIWorkerWithModel getDefaultWorker();
29
    
29
    
30
    public ProgressUIWorker getExtractedComponentWorker();
30
    public ExtractedProgressUIWorker getExtractedComponentWorker();
31
}
31
}
(-)progress/test/unit/src/org/netbeans/api/progress/ProgressHandleTest.java (+30 lines)
Lines 22-27 Link Here
22
import java.lang.reflect.Method;
22
import java.lang.reflect.Method;
23
import javax.swing.JComponent;
23
import javax.swing.JComponent;
24
import javax.swing.JFrame;
24
import javax.swing.JFrame;
25
import javax.swing.JLabel;
25
import javax.swing.SwingUtilities;
26
import javax.swing.SwingUtilities;
26
import org.netbeans.junit.NbTestCase;
27
import org.netbeans.junit.NbTestCase;
27
import org.netbeans.progress.module.Controller;
28
import org.netbeans.progress.module.Controller;
Lines 115-120 Link Here
115
        assertFalse(handle.isCustomPlaced());
116
        assertFalse(handle.isCustomPlaced());
116
        JComponent comp = ProgressHandleFactory.createProgressComponent(proghandle);
117
        JComponent comp = ProgressHandleFactory.createProgressComponent(proghandle);
117
        assertTrue(handle.isCustomPlaced());
118
        assertTrue(handle.isCustomPlaced());
119
        JLabel main = ProgressHandleFactory.createMainLabelComponent(proghandle);
120
        assertTrue(handle.isCustomPlaced());
121
        assertNotNull(main);
122
        JLabel detail = ProgressHandleFactory.createDetailLabelComponent(proghandle);
123
        assertTrue(handle.isCustomPlaced());
124
        assertNotNull(detail);
125
                
118
        boolean ok = false;
126
        boolean ok = false;
119
        try {
127
        try {
120
            // cannot get the custom component multiple times..
128
            // cannot get the custom component multiple times..
Lines 125-130 Link Here
125
        
133
        
126
        assertTrue(ok);
134
        assertTrue(ok);
127
    }
135
    }
136
    
137
    /**
138
     * Test of custom placed labels of class org.netbeans.progress.api.ProgressHandle.
139
     */
140
    public void testCustomPlacedLabels() {
141
        assertFalse(handle.isCustomPlaced());
142
        JComponent comp = ProgressHandleFactory.createProgressComponent(proghandle);
143
        JLabel main = ProgressHandleFactory.createMainLabelComponent(proghandle);
144
        JLabel detail = ProgressHandleFactory.createDetailLabelComponent(proghandle);
145
        proghandle.start();
146
        proghandle.setDisplayName("test1");
147
        proghandle.progress("message1");
148
        // kind of bad to have the wait here to overcome the scheduling..
149
        try {
150
            Thread.sleep(300);
151
        } catch (InterruptedException exc) {
152
            System.out.println("interrupted");
153
        }
154
        assertEquals("test1", main.getText());
155
        assertEquals("message1", detail.getText());
156
    }
157
    
128
    
158
    
129
    // tasks shorter than the InternalHandle.INITIAL_DELAY should be discarded.
159
    // tasks shorter than the InternalHandle.INITIAL_DELAY should be discarded.
130
    public void testIfShortOnesGetDiscarded() throws Exception {
160
    public void testIfShortOnesGetDiscarded() throws Exception {
(-)progressui/src/org/netbeans/modules/progress/ui/NbProgressBar.java (-1 / +27 lines)
Lines 21-28 Link Here
21
21
22
import java.awt.Color;
22
import java.awt.Color;
23
import java.awt.Dimension;
23
import java.awt.Dimension;
24
import javax.swing.JComponent;
25
import javax.swing.JLabel;
24
import javax.swing.JProgressBar;
26
import javax.swing.JProgressBar;
25
import javax.swing.UIManager;
27
import javax.swing.UIManager;
28
import org.netbeans.progress.spi.ExtractedProgressUIWorker;
26
import org.netbeans.progress.spi.InternalHandle;
29
import org.netbeans.progress.spi.InternalHandle;
27
import org.netbeans.progress.spi.ProgressUIWorker;
30
import org.netbeans.progress.spi.ProgressUIWorker;
28
import org.netbeans.progress.spi.ProgressEvent;
31
import org.netbeans.progress.spi.ProgressEvent;
Lines 33-41 Link Here
33
36
34
 * @author mkleint
37
 * @author mkleint
35
 */
38
 */
36
public class NbProgressBar extends JProgressBar implements ProgressUIWorker {
39
public class NbProgressBar extends JProgressBar implements ExtractedProgressUIWorker {
37
    boolean isSetup = false;
40
    boolean isSetup = false;
38
    boolean usedInStatusBar = false;
41
    boolean usedInStatusBar = false;
42
    //TODO these two ought to be created only when the the bar is used externally..
43
    private JLabel detailLabel = new JLabel();
44
    private JLabel mainLabel = new JLabel();
39
    
45
    
40
    /** Creates a new instance of NbProgressBar */
46
    /** Creates a new instance of NbProgressBar */
41
    public NbProgressBar() {
47
    public NbProgressBar() {
Lines 72-77 Link Here
72
    public void processProgressEvent(ProgressEvent event) {
78
    public void processProgressEvent(ProgressEvent event) {
73
        if (event.getType() == ProgressEvent.TYPE_START || !isSetup  || event.isSwitched()) {
79
        if (event.getType() == ProgressEvent.TYPE_START || !isSetup  || event.isSwitched()) {
74
            setupBar(event.getSource(), this);
80
            setupBar(event.getSource(), this);
81
            mainLabel.setText(event.getSource().getDisplayName());
75
            isSetup = true;
82
            isSetup = true;
76
        } 
83
        } 
77
        if (event.getType() == ProgressEvent.TYPE_PROGRESS) {
84
        if (event.getType() == ProgressEvent.TYPE_PROGRESS) {
Lines 79-84 Link Here
79
                setValue(event.getWorkunitsDone());
86
                setValue(event.getWorkunitsDone());
80
            }
87
            }
81
            setString(StatusLineComponent.getBarString(event.getPercentageDone(), event.getEstimatedCompletion()));
88
            setString(StatusLineComponent.getBarString(event.getPercentageDone(), event.getEstimatedCompletion()));
89
            if (event.getDisplayName() != null) {
90
                mainLabel.setText(event.getDisplayName());
91
            }
92
            if (event.getMessage() != null) {
93
                detailLabel.setText(event.getMessage());
94
            }
95
            
82
        } else if (event.getType() == ProgressEvent.TYPE_FINISH) {
96
        } else if (event.getType() == ProgressEvent.TYPE_FINISH) {
83
            boolean wasIndetermenite = isIndeterminate();
97
            boolean wasIndetermenite = isIndeterminate();
84
            setIndeterminate(false);
98
            setIndeterminate(false);
Lines 113-116 Link Here
113
        }
127
        }
114
        bar.setString(" ");
128
        bar.setString(" ");
115
    }    
129
    }    
130
131
    public JComponent getProgressComponent() {
132
        return this;
133
    }
134
135
    public JLabel getMainLabelComponent() {
136
        return mainLabel;
137
    }
138
139
    public JLabel getDetailLabelComponent() {
140
        return detailLabel;
141
    }
116
}
142
}
(-)progressui/src/org/netbeans/modules/progress/ui/ProviderImpl.java (-1 / +2 lines)
Lines 19-24 Link Here
19
19
20
package org.netbeans.modules.progress.ui;
20
package org.netbeans.modules.progress.ui;
21
21
22
import org.netbeans.progress.spi.ExtractedProgressUIWorker;
22
import org.netbeans.progress.spi.ProgressUIWorker;
23
import org.netbeans.progress.spi.ProgressUIWorker;
23
import org.netbeans.progress.spi.ProgressUIWorkerProvider;
24
import org.netbeans.progress.spi.ProgressUIWorkerProvider;
24
import org.netbeans.progress.spi.ProgressUIWorkerWithModel;
25
import org.netbeans.progress.spi.ProgressUIWorkerWithModel;
Lines 37-43 Link Here
37
        return new StatusLineComponent();
38
        return new StatusLineComponent();
38
    }
39
    }
39
40
40
    public ProgressUIWorker getExtractedComponentWorker() {
41
    public ExtractedProgressUIWorker getExtractedComponentWorker() {
41
        return new NbProgressBar();
42
        return new NbProgressBar();
42
    }
43
    }
43
    
44
    

Return to bug 58889