> Split the implementation and APIs of progress component. >
>comp
to the layout,
< * associating it
< * with the string specified by name
.
< *
< * @param name the string to be associated with the component
< * @param comp the component to be added
< */
< public void addLayoutComponent(String name, java.awt.Component comp) {
< }
<
< /**
< * Calculates the preferred size dimensions for the specified
< * container, given the components it contains.
< * @param parent the container to be laid out
< *
< * @see #minimumLayoutSize
< */
< public Dimension preferredLayoutSize(java.awt.Container parent) {
< int height = UPPERMARGIN + mainHeight + BETWEENTEXTMARGIN + dynaHeight + BOTTOMMARGIN;
< return new Dimension(ITEM_WIDTH, height);
< }
<
< /**
< *
< * Lays out the specified container.
< * @param parent the container to be laid out
< */
< public void layoutContainer(java.awt.Container parent) {
< int parentWidth = parent.getWidth();
< int parentHeight = parent.getHeight();
< int offset = parentWidth - 18;
< if (closeButton != null) {
< closeButton.setBounds(offset, UPPERMARGIN, 18, mainHeight);
< }
< // have the bar approx 30 percent of the width
< int barOffset = offset - (ITEM_WIDTH / 3);
< bar.setBounds(barOffset, UPPERMARGIN, offset - barOffset, mainHeight);
< mainLabel.setBounds(LEFTMARGIN, UPPERMARGIN, barOffset - LEFTMARGIN, mainHeight);
< dynaLabel.setBounds(LEFTMARGIN, mainHeight + UPPERMARGIN + BETWEENTEXTMARGIN,
< parentWidth - LEFTMARGIN, dynaHeight);
< }
<
< /**
< *
< * Calculates the minimum size dimensions for the specified
< * container, given the components it contains.
< * @param parent the component to be laid out
< * @see #preferredLayoutSize
< */
< public Dimension minimumLayoutSize(java.awt.Container parent) {
< return preferredLayoutSize(parent);
< }
<
< /**
< * Removes the specified component from the layout.
< * @param comp the component to be removed
< */
< public void removeLayoutComponent(java.awt.Component comp) {
< }
<
<
< }
< }
\ No newline at end of file
Index: progress/src/org/netbeans/progress/module/ui/NbProgressBar.java
===================================================================
RCS file: progress/src/org/netbeans/progress/module/ui/NbProgressBar.java
diff -N progress/src/org/netbeans/progress/module/ui/NbProgressBar.java
1,116d0
< /*
< * The contents of this file are subject to the terms of the Common Development
< * and Distribution License (the License). You may not use this file except in
< * compliance with the License.
< *
< * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
< * or http://www.netbeans.org/cddl.txt.
< *
< * When distributing Covered Code, include this CDDL Header Notice in each file
< * and include the License file at http://www.netbeans.org/cddl.txt.
< * If applicable, add the following below the CDDL Header, with the fields
< * enclosed by brackets [] replaced by your own identifying information:
< * "Portions Copyrighted [year] [name of copyright owner]"
< *
< * The Original Software is NetBeans. The Initial Developer of the Original
< * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
< * Microsystems, Inc. All Rights Reserved.
< */
<
< package org.netbeans.progress.module.ui;
<
< import java.awt.Color;
< import java.awt.Dimension;
< import javax.swing.JProgressBar;
< import javax.swing.UIManager;
< import org.netbeans.progress.module.InternalHandle;
< import org.netbeans.progress.module.ProgressUIWorker;
< import org.netbeans.progress.module.ProgressEvent;
<
<
< /**
< * progress component, let just put the UI related issues here, update the state from outside
<
< * @author mkleint
< */
< public class NbProgressBar extends JProgressBar implements ProgressUIWorker {
< boolean isSetup = false;
< boolean usedInStatusBar = false;
<
< /** Creates a new instance of NbProgressBar */
< public NbProgressBar() {
< super();
< setOrientation(JProgressBar.HORIZONTAL);
< setAlignmentX(0.5f);
< setAlignmentY(0.5f);
< Color fg = UIManager.getColor ("nbProgressBar.Foreground");
< if (fg != null) {
< setForeground(fg);
< }
< Color bg = UIManager.getColor ("nbProgressBar.Background");
< if (bg != null) {
< setBackground(bg);
< }
< }
<
< public void setUseInStatusBar(boolean use) {
< usedInStatusBar = use;
< }
<
< public Dimension getPreferredSize() {
< Dimension supers = super.getPreferredSize();
< if (usedInStatusBar) {
< supers.width = ListComponent.ITEM_WIDTH / 3;
< }
< return supers;
< }
<
<
< //--- these are used only when dealing with extracted component, when in status bar this is not used.
< //------------------------------------
<
< public void processProgressEvent(ProgressEvent event) {
< if (event.getType() == ProgressEvent.TYPE_START || !isSetup || event.isSwitched()) {
< setupBar(event.getSource(), this);
< isSetup = true;
< }
< if (event.getType() == ProgressEvent.TYPE_PROGRESS) {
< if (event.getWorkunitsDone() > 0) {
< setValue(event.getWorkunitsDone());
< }
< setString(StatusLineComponent.getBarString(event.getPercentageDone(), event.getEstimatedCompletion()));
< } else if (event.getType() == ProgressEvent.TYPE_FINISH) {
< boolean wasIndetermenite = isIndeterminate();
< setIndeterminate(false);
< setMaximum(event.getSource().getTotalUnits());
< setValue(event.getSource().getTotalUnits());
< if (wasIndetermenite) {
< setStringPainted(false);
< } else {
< setString(StatusLineComponent.getBarString(100, -1));
< }
< }
< }
<
< public void processSelectedProgressEvent(ProgressEvent event) {
< // ignore we'return always processing just one selected component
< }
<
<
< static void setupBar(InternalHandle handle, NbProgressBar bar) {
< int total = handle.getTotalUnits();
< if (total < 1) {
< // macosx workaround..
< bar.setValue(bar.getMaximum());
< bar.setIndeterminate(true);
< bar.setStringPainted(false);
< } else {
< bar.setStringPainted(true);
< bar.setIndeterminate(false);
< bar.setMaximum(total);
< bar.setMinimum(0);
< bar.setValue(0);
< }
< bar.setString(" ");
< }
< }
\ No newline at end of file
Index: progress/src/org/netbeans/progress/module/ui/PopupPane.java
===================================================================
RCS file: progress/src/org/netbeans/progress/module/ui/PopupPane.java
diff -N progress/src/org/netbeans/progress/module/ui/PopupPane.java
1,278d0
< /*
< * The contents of this file are subject to the terms of the Common Development
< * and Distribution License (the License). You may not use this file except in
< * compliance with the License.
< *
< * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
< * or http://www.netbeans.org/cddl.txt.
< *
< * When distributing Covered Code, include this CDDL Header Notice in each file
< * and include the License file at http://www.netbeans.org/cddl.txt.
< * If applicable, add the following below the CDDL Header, with the fields
< * enclosed by brackets [] replaced by your own identifying information:
< * "Portions Copyrighted [year] [name of copyright owner]"
< *
< * The Original Software is NetBeans. The Initial Developer of the Original
< * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
< * Microsystems, Inc. All Rights Reserved.
< */
<
<
< package org.netbeans.progress.module.ui;
<
< import java.awt.Color;
< import java.awt.Component;
< import java.awt.Dimension;
< import java.awt.Graphics;
< import java.awt.GridLayout;
< import java.awt.Insets;
< import java.awt.Toolkit;
< import java.awt.event.ActionEvent;
< import java.awt.event.KeyEvent;
< import java.util.HashSet;
< import java.util.Iterator;
< import javax.swing.AbstractAction;
< import javax.swing.Action;
< import javax.swing.BorderFactory;
< import javax.swing.JComponent;
< import javax.swing.JPanel;
< import javax.swing.JScrollPane;
< import javax.swing.KeyStroke;
< import javax.swing.UIManager;
< import javax.swing.border.Border;
< import org.netbeans.progress.module.InternalHandle;
<
< /**
< *
< * @author mkleint
< */
< public class PopupPane extends JScrollPane {
< private JPanel view;
< private HashSetcomp
to the layout,
> * associating it
> * with the string specified by name
.
> *
> * @param name the string to be associated with the component
> * @param comp the component to be added
> */
> public void addLayoutComponent(String name, java.awt.Component comp) {
> }
>
> /**
> * Calculates the preferred size dimensions for the specified
> * container, given the components it contains.
> * @param parent the container to be laid out
> *
> * @see #minimumLayoutSize
> */
> public Dimension preferredLayoutSize(java.awt.Container parent) {
> int height = UPPERMARGIN + mainHeight + BETWEENTEXTMARGIN + dynaHeight + BOTTOMMARGIN;
> return new Dimension(ITEM_WIDTH, height);
> }
>
> /**
> *
> * Lays out the specified container.
> * @param parent the container to be laid out
> */
> public void layoutContainer(java.awt.Container parent) {
> int parentWidth = parent.getWidth();
> int parentHeight = parent.getHeight();
> int offset = parentWidth - 18;
> if (closeButton != null) {
> closeButton.setBounds(offset, UPPERMARGIN, 18, mainHeight);
> }
> // have the bar approx 30 percent of the width
> int barOffset = offset - (ITEM_WIDTH / 3);
> bar.setBounds(barOffset, UPPERMARGIN, offset - barOffset, mainHeight);
> mainLabel.setBounds(LEFTMARGIN, UPPERMARGIN, barOffset - LEFTMARGIN, mainHeight);
> dynaLabel.setBounds(LEFTMARGIN, mainHeight + UPPERMARGIN + BETWEENTEXTMARGIN,
> parentWidth - LEFTMARGIN, dynaHeight);
> }
>
> /**
> *
> * Calculates the minimum size dimensions for the specified
> * container, given the components it contains.
> * @param parent the component to be laid out
> * @see #preferredLayoutSize
> */
> public Dimension minimumLayoutSize(java.awt.Container parent) {
> return preferredLayoutSize(parent);
> }
>
> /**
> * Removes the specified component from the layout.
> * @param comp the component to be removed
> */
> public void removeLayoutComponent(java.awt.Component comp) {
> }
>
>
> }
> }
\ No newline at end of file
Index: progressui/src/org/netbeans/modules/progress/ui/NbProgressBar.java
===================================================================
RCS file: progressui/src/org/netbeans/modules/progress/ui/NbProgressBar.java
diff -N progressui/src/org/netbeans/modules/progress/ui/NbProgressBar.java
0a1,116
> /*
> * The contents of this file are subject to the terms of the Common Development
> * and Distribution License (the License). You may not use this file except in
> * compliance with the License.
> *
> * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
> * or http://www.netbeans.org/cddl.txt.
> *
> * When distributing Covered Code, include this CDDL Header Notice in each file
> * and include the License file at http://www.netbeans.org/cddl.txt.
> * If applicable, add the following below the CDDL Header, with the fields
> * enclosed by brackets [] replaced by your own identifying information:
> * "Portions Copyrighted [year] [name of copyright owner]"
> *
> * The Original Software is NetBeans. The Initial Developer of the Original
> * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
> * Microsystems, Inc. All Rights Reserved.
> */
>
> package org.netbeans.modules.progress.ui;
>
> import java.awt.Color;
> import java.awt.Dimension;
> import javax.swing.JProgressBar;
> import javax.swing.UIManager;
> import org.netbeans.progress.spi.InternalHandle;
> import org.netbeans.progress.spi.ProgressUIWorker;
> import org.netbeans.progress.spi.ProgressEvent;
>
>
> /**
> * progress component, let just put the UI related issues here, update the state from outside
>
> * @author mkleint
> */
> public class NbProgressBar extends JProgressBar implements ProgressUIWorker {
> boolean isSetup = false;
> boolean usedInStatusBar = false;
>
> /** Creates a new instance of NbProgressBar */
> public NbProgressBar() {
> super();
> setOrientation(JProgressBar.HORIZONTAL);
> setAlignmentX(0.5f);
> setAlignmentY(0.5f);
> Color fg = UIManager.getColor ("nbProgressBar.Foreground");
> if (fg != null) {
> setForeground(fg);
> }
> Color bg = UIManager.getColor ("nbProgressBar.Background");
> if (bg != null) {
> setBackground(bg);
> }
> }
>
> public void setUseInStatusBar(boolean use) {
> usedInStatusBar = use;
> }
>
> public Dimension getPreferredSize() {
> Dimension supers = super.getPreferredSize();
> if (usedInStatusBar) {
> supers.width = ListComponent.ITEM_WIDTH / 3;
> }
> return supers;
> }
>
>
> //--- these are used only when dealing with extracted component, when in status bar this is not used.
> //------------------------------------
>
> public void processProgressEvent(ProgressEvent event) {
> if (event.getType() == ProgressEvent.TYPE_START || !isSetup || event.isSwitched()) {
> setupBar(event.getSource(), this);
> isSetup = true;
> }
> if (event.getType() == ProgressEvent.TYPE_PROGRESS) {
> if (event.getWorkunitsDone() > 0) {
> setValue(event.getWorkunitsDone());
> }
> setString(StatusLineComponent.getBarString(event.getPercentageDone(), event.getEstimatedCompletion()));
> } else if (event.getType() == ProgressEvent.TYPE_FINISH) {
> boolean wasIndetermenite = isIndeterminate();
> setIndeterminate(false);
> setMaximum(event.getSource().getTotalUnits());
> setValue(event.getSource().getTotalUnits());
> if (wasIndetermenite) {
> setStringPainted(false);
> } else {
> setString(StatusLineComponent.getBarString(100, -1));
> }
> }
> }
>
> public void processSelectedProgressEvent(ProgressEvent event) {
> // ignore we'return always processing just one selected component
> }
>
>
> static void setupBar(InternalHandle handle, NbProgressBar bar) {
> int total = handle.getTotalUnits();
> if (total < 1) {
> // macosx workaround..
> bar.setValue(bar.getMaximum());
> bar.setIndeterminate(true);
> bar.setStringPainted(false);
> } else {
> bar.setStringPainted(true);
> bar.setIndeterminate(false);
> bar.setMaximum(total);
> bar.setMinimum(0);
> bar.setValue(0);
> }
> bar.setString(" ");
> }
> }
\ No newline at end of file
Index: progressui/src/org/netbeans/modules/progress/ui/PopupPane.java
===================================================================
RCS file: progressui/src/org/netbeans/modules/progress/ui/PopupPane.java
diff -N progressui/src/org/netbeans/modules/progress/ui/PopupPane.java
0a1,278
> /*
> * The contents of this file are subject to the terms of the Common Development
> * and Distribution License (the License). You may not use this file except in
> * compliance with the License.
> *
> * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
> * or http://www.netbeans.org/cddl.txt.
> *
> * When distributing Covered Code, include this CDDL Header Notice in each file
> * and include the License file at http://www.netbeans.org/cddl.txt.
> * If applicable, add the following below the CDDL Header, with the fields
> * enclosed by brackets [] replaced by your own identifying information:
> * "Portions Copyrighted [year] [name of copyright owner]"
> *
> * The Original Software is NetBeans. The Initial Developer of the Original
> * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
> * Microsystems, Inc. All Rights Reserved.
> */
>
>
> package org.netbeans.modules.progress.ui;
>
> import java.awt.Color;
> import java.awt.Component;
> import java.awt.Dimension;
> import java.awt.Graphics;
> import java.awt.GridLayout;
> import java.awt.Insets;
> import java.awt.Toolkit;
> import java.awt.event.ActionEvent;
> import java.awt.event.KeyEvent;
> import java.util.HashSet;
> import java.util.Iterator;
> import javax.swing.AbstractAction;
> import javax.swing.Action;
> import javax.swing.BorderFactory;
> import javax.swing.JComponent;
> import javax.swing.JPanel;
> import javax.swing.JScrollPane;
> import javax.swing.KeyStroke;
> import javax.swing.UIManager;
> import javax.swing.border.Border;
> import org.netbeans.progress.spi.InternalHandle;
>
> /**
> *
> * @author mkleint
> */
> public class PopupPane extends JScrollPane {
> private JPanel view;
> private HashSet