Announcement

Collapse
No announcement yet.

Get StatusBar value if data is downloading

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get StatusBar value if data is downloading

    Helo all!

    Is there a way to get StatusBar values, to be more specific "Downloading" label value?
    So, when in the right bottom of the window there is the red label "Downloading" I can somehow this detect and use.

    Click image for larger version

Name:	Untitled-1.png
Views:	1
Size:	267.8 KB
ID:	111984

    I've tryed this:
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);
    nasa.statusBar.list(ps);

    but this allways contains "Downloading" value, even if in the window there is not red label "Downloading":

    gov.nasa.worldwind.util.StatusBar[,0,468,733x16,layout=java.awt.GridLayout ,alignmentX=0.0,alignmentY=0.0,border=ja vax.swing.plaf.synth.SynthBorder@103333, flags=9,maximumSize=,minimumSize=,prefer redSize=]
    javax.swing.JLabel[,1,0,146x16,alignmentX=0.0,alignmentY=0. 0,border=javax.swing.plaf.synth.SynthBor der@191659c,flags=8388608,maximumSize=,m inimumSize=,preferredSize=,defaultIcon=, disabledIcon=,horizontalAlignment=CENTER ,horizontalTextPosition=TRAILING,iconTex tGap=4,labelFor=,text=Altitude 114 km,verticalAlignment=CENTER,verticalText Position=CENTER]
    javax.swing.JLabel[,147,0,146x16,alignmentX=0.0,alignmentY= 0.0,border=javax.swing.plaf.synth.SynthB order@a60d93,flags=8388608,maximumSize=, minimumSize=,preferredSize=,defaultIcon= ,disabledIcon=,horizontalAlignment=CENTE R,horizontalTextPosition=TRAILING,iconTe xtGap=4,labelFor=,text=,verticalAlignmen t=CENTER,verticalTextPosition=CENTER]
    javax.swing.JLabel[,293,0,146x16,alignmentX=0.0,alignmentY= 0.0,border=javax.swing.plaf.synth.SynthB order@1c55849,flags=8388608,maximumSize= ,minimumSize=,preferredSize=,defaultIcon =,disabledIcon=,horizontalAlignment=CENT ER,horizontalTextPosition=TRAILING,iconT extGap=4,labelFor=,text=Off Globe,verticalAlignment=CENTER,verticalT extPosition=CENTER]
    javax.swing.JLabel[,439,0,146x16,alignmentX=0.0,alignmentY= 0.0,border=javax.swing.plaf.synth.SynthB order@1272ac3,flags=8388608,maximumSize= ,minimumSize=,preferredSize=,defaultIcon =,disabledIcon=,horizontalAlignment=CENT ER,horizontalTextPosition=TRAILING,iconT extGap=4,labelFor=,text=,verticalAlignme nt=CENTER,verticalTextPosition=CENTER]
    javax.swing.JLabel[,585,0,146x16,alignmentX=0.0,alignmentY= 0.0,border=javax.swing.plaf.synth.SynthB order@6868cc,flags=8388608,maximumSize=, minimumSize=,preferredSize=,defaultIcon= ,disabledIcon=,horizontalAlignment=CENTE R,horizontalTextPosition=TRAILING,iconTe xtGap=4,labelFor=,text=Downloading,verti calAlignment=CENTER,verticalTextPosition =CENTER]

  • #2
    Solved

    Just use this line:
    if (isNetworkAvailable.get() && WorldWind.getRetrievalService().hasActiv eTasks())
    Last edited by Mario N; 10-06-2014, 03:57 PM.

    Comment


    • #3
      Yep, you can display the number of tiles/tasks remaining, with a bit of programming like :
      Code:
          int nb_tasks = WorldWind.getRetrievalService().getNumRetrieversPending();
      
          heartBeat.setText(Logging.getMessage("term.Downloading") + "(" + nb_tasks + ")" );
      You'll then discover the number of tiles remaining to download is generally around 200, when zooming to a brand new place.
      It may be even more but it is limited by the system for performance reasons.
      BTW, a progress-bar would be good, too.

      Comment


      • #4
        Hey, that's nice.. I didn't have time to investigate this a little bit more, but progress bar is cool suggestion. Thank you!
        Last edited by Mario N; 10-09-2014, 07:43 AM.

        Comment


        • #5
          Here is my private StatusBar java class, with a progress-bar implemented.... Enjoy !
          NB: there are for sure things that won't compile in a std environment (some stuff added by myself, like a '...' button), you'll have to remove these.
          Crucial things are bolded below
          Cheers


          Code:
          import java.awt.Color;
          import java.awt.FlowLayout;
          import java.awt.BorderLayout;
          import javax.swing.border.Border;
          import javax.swing.BorderFactory;
          import java.awt.GridLayout;
          import java.awt.EventQueue;
          import java.awt.event.ActionListener;
          import java.awt.event.ActionEvent;
          import java.beans.PropertyChangeListener;
          import java.beans.PropertyChangeEvent;
          import java.net.URL;
          import java.util.concurrent.atomic.AtomicBoolean;
          
          /**
           * @author tag
           * @version $Id: StatusBar.java 1 2011-07-16 23:22:47Z dcollins $
           */
          public class StatusBar extends JPanel implements PositionListener, RenderingListener
          {
              // Units constants TODO: Replace with UnitsFormat
              public final static String UNIT_METRIC = "Metric";
              public final static String UNIT_IMPERIAL = "Imperial";
          
              private static final int MAX_ALPHA = 254;
          
              private String altitudeUnit = UNIT_METRIC;
              private String elevationUnit = UNIT_METRIC;
              private String angleFormat = Angle.ANGLE_FORMAT_DMS;
          
              private final JButton paramsButton = new JButton();
          
              protected final JLabel altDisplay = new JLabel("");
              protected final JLabel latDisplay = new JLabel("");
              protected final JLabel lonDisplay = new JLabel("");
              protected final JLabel mgrsDisplay = new JLabel("");
              protected final JLabel xMeterDisplay = new JLabel("");
              protected final JLabel yMeterDisplay = new JLabel("");
              protected final JLabel eleDisplay = new JLabel("");
          
              private AtomicBoolean showNetworkStatus = new AtomicBoolean(true);
              private AtomicBoolean isNetworkAvailable = new AtomicBoolean(true);
              private Thread netCheckThread;
          
              private boolean displayMGRS = false ;
              private boolean displayMETERS = false ;
          
              private WorldWindow wwd_ = null ;
              private WWJPanel wwjPanel_ = null ;
          
              public StatusBar( WWJPanel wwjPanel )
              {
                  this( true, wwjPanel );
              }
          
              public StatusBar( boolean make_ui, WWJPanel wwjPanel )
              {
                  super(new BorderLayout());
          
                  wwjPanel_ = wwjPanel ;
          
                  if ( make_ui )
                  {
                      makeUI();
                  }
              }
          
              public void setMGRSDisplayed( boolean displayMGRS )
              {
                  this.displayMGRS = displayMGRS ;
              }
          
              public boolean isMGRSDisplayed()
              {
                  return this.displayMGRS ;
              }
          
              public void makeUI()
              {
                  final String download = "Downloaded"; //Logging.getMessage("term.Downloading");
          
                  final int max_tasks = WorldWind.getRetrievalService().getMaxRetrievers();
          
                  final JProgressBar heartBeat = new JProgressBar(0,100);
          
                  heartBeat.setBorderPainted(false);
                  heartBeat.setStringPainted(true);
          
                  //paramsButton.setIcon( new ImageIcon( getClass().getResource("/images/16x16-icon-earth.png")) );
                  paramsButton.setText("...");
                  paramsButton.setPreferredSize( new Dimension(16,16) );
          
                  paramsButton.addActionListener( new ActionListener()
                  {
                      public void actionPerformed(ActionEvent actionEvent)
                      {
                          popupStatusBarParametersPanel();
                      }
                  });
          
                  lonDisplay.setHorizontalAlignment(SwingConstants.CENTER);
                  latDisplay.setHorizontalAlignment(SwingConstants.CENTER);
                  altDisplay.setHorizontalAlignment(SwingConstants.CENTER);
                  mgrsDisplay.setHorizontalAlignment(SwingConstants.CENTER);
                  xMeterDisplay.setHorizontalAlignment(SwingConstants.CENTER);
                  yMeterDisplay.setHorizontalAlignment(SwingConstants.CENTER);
                  eleDisplay.setHorizontalAlignment(SwingConstants.CENTER);
          
                  JPanel panel = new JPanel( new GridLayout(0, 4, -1, -1) );
          
                  Color nice_blue = new Color(102, 153, 255); // no alpha possible on borders ?
          
                  Border border = BorderFactory.createLineBorder( nice_blue );
          
                  JPanel heartBeatPanel = new JPanel(new BorderLayout(0,0) );
          
                  lonDisplay.setBorder( border );
                  latDisplay.setBorder( border );
                  altDisplay.setBorder( border );
                  mgrsDisplay.setBorder( border );
                  xMeterDisplay.setBorder( border );
                  yMeterDisplay.setBorder( border );
                  eleDisplay.setBorder( border );
                  heartBeatPanel.setBorder( border );
          
                  heartBeatPanel.add( heartBeat, BorderLayout.CENTER );
          
                  panel.add( lonDisplay );
                  panel.add( latDisplay );
                  panel.add( altDisplay );
                  panel.add( eleDisplay );
                  panel.add( xMeterDisplay );
                  panel.add( yMeterDisplay );
                  panel.add( mgrsDisplay );
                  panel.add( heartBeatPanel );
          
                  this.add( paramsButton, BorderLayout.EAST );
                  this.add( panel, BorderLayout.CENTER );
          
                  heartBeat.setForeground( new Color(102, 153, 255, 0 ) );
          
                  Timer downloadTimer = new Timer(100, new ActionListener()
                  {
                      public void actionPerformed(ActionEvent actionEvent)
                      {
                          if (!showNetworkStatus.get())
                          {
                              if (heartBeat.getString().length() > 0)
                                  heartBeat.setString("No Download");
                              return;
                          }
          
                          if (!isNetworkAvailable.get())
                          {
                              heartBeat.setString(Logging.getMessage("term.NoNetwork"));
                              heartBeat.setForeground(new Color(255, 0, 0, MAX_ALPHA));
                              return;
                          }
          
                          Color color = heartBeat.getForeground();
                          int alpha = color.getAlpha();
          
                          if (isNetworkAvailable.get() && WorldWind.getRetrievalService().hasActiveTasks())
                          {
                              int nb_tasks = WorldWind.getRetrievalService().getNumRetrieversPending();
          
                              int done = Math.max( 0, 100 - (int) (100.0*nb_tasks/max_tasks) );
          
                              heartBeat.setValue( done );
          
                              String download_str = "" + done + "% " + download ;
          
                              heartBeat.setString( download_str );
          
                              if (alpha >= MAX_ALPHA)
                                  alpha = MAX_ALPHA;
                              else
                                  alpha = alpha < 16 ? 16 : Math.min(MAX_ALPHA, alpha + 20);
                          }
                          else
                          {
                              alpha = Math.max(0, alpha - 20);
                              heartBeat.setString("");
                          }
                          heartBeat.setForeground(new Color(102, 153, 255, alpha));
                      }
                  });
                  downloadTimer.start();
          
                  this.netCheckThread = this.startNetCheckThread();
          
                  WorldWind.getNetworkStatus().addPropertyChangeListener(NetworkStatus.HOST_UNAVAILABLE,
                      new PropertyChangeListener()
                      {
                          public void propertyChange(PropertyChangeEvent evt)
                          {
                              Object nv = evt.getNewValue();
                              String message = Logging.getMessage("NetworkStatus.UnavailableHost",
                                  nv != null && nv instanceof URL ? ((URL) nv).getHost() : "Unknown");
                              Logging.logger().info(message);
                          }
                      });
          
                  WorldWind.getNetworkStatus().addPropertyChangeListener(NetworkStatus.HOST_AVAILABLE,
                      new PropertyChangeListener()
                      {
                          public void propertyChange(PropertyChangeEvent evt)
                          {
                              Object nv = evt.getNewValue();
                              String message = Logging.getMessage("NetworkStatus.HostNowAvailable",
                                  nv != null && nv instanceof URL ? ((URL) nv).getHost() : "Unknown");
                              Logging.logger().info(message);
                          }
                      });
              }
          
              private void popupStatusBarParametersPanel()
              {
                  JFrame frame = new JFrame();
          
                  WorldWindow wwd = getEventSource() ;
          
                  StatusBarParametersPanel panel = new StatusBarParametersPanel( this, wwd, wwjPanel_ );
          
                  frame.getContentPane().add( panel, BorderLayout.CENTER );
          
                  int x = paramsButton.getLocationOnScreen().x - 100 ;
                  int y = paramsButton.getLocationOnScreen().y - 300 ;
                  frame.setLocation(x,y);
          
                  frame.setAlwaysOnTop(true);
          
                  frame.pack();
                  frame.setVisible(true);
              }
          
              private NetworkCheckThread startNetCheckThread()
              {
                  NetworkCheckThread nct = new NetworkCheckThread(this.showNetworkStatus, this.isNetworkAvailable, null);
                  nct.setDaemon(true);
                  nct.start();
          
                  return nct;
              }
          
              public void setEventSource(WorldWindow newEventSource)
              {
                  if (this.wwd_ != null)
                  {
                      this.wwd_.removePositionListener(this);
                      this.wwd_.removeRenderingListener(this);
                  }
          
                  if (newEventSource != null)
                  {
                      newEventSource.addPositionListener(this);
                      newEventSource.addRenderingListener(this);
                  }
          
                  this.wwd_ = newEventSource;
              }
          
              public boolean isShowNetworkStatus()
              {
                  return showNetworkStatus.get();
              }
          
              public void setShowNetworkStatus(boolean showNetworkStatus)
              {
                  this.showNetworkStatus.set(showNetworkStatus);
          
                  if (showNetworkStatus)
                  {
                      if (this.netCheckThread != null)
                          this.netCheckThread.interrupt();
          
                      this.netCheckThread = this.startNetCheckThread();
                  }
                  else
                  {
                      if (this.netCheckThread != null)
                          this.netCheckThread.interrupt();
          
                      this.netCheckThread = null;
                  }
              }
          
              public void moved(PositionEvent event)
              {
                  this.handleCursorPositionChange(event);
              }
          
              public WorldWindow getEventSource()
              {
                  return this.wwd_;
              }
          
              public String getAltitudeUnit()
              {
                  return this.altitudeUnit;
              }
          
              public void setAltitudeUnit(String unit)
              {
                  if (unit == null)
                  {
                      String message = Logging.getMessage("nullValue.StringIsNull");
                      Logging.logger().severe(message);
                      throw new IllegalArgumentException(message);
                  }
          
                  this.altitudeUnit = unit;
              }
          
              public String getElevationUnit()
              {
                  return this.elevationUnit;
              }
          
              public void setElevationUnit(String unit)
              {
                  if (unit == null)
                  {
                      String message = Logging.getMessage("nullValue.StringIsNull");
                      Logging.logger().severe(message);
                      throw new IllegalArgumentException(message);
                  }
          
                  this.elevationUnit = unit;
              }
          
              public String getAngleFormat()
              {
                  return this.angleFormat;
              }
          
              public void setAngleFormat(String format)
              {
                  if (format == null)
                  {
                      String message = Logging.getMessage("nullValue.StringIsNull");
                      Logging.logger().severe(message);
                      throw new IllegalArgumentException(message);
                  }
          
                  this.angleFormat = format;
              }
          
              protected String makeCursorElevationDescription(double metersElevation)
              {
                  String s;
                  String elev = Logging.getMessage("term.Elev");
                  if (UNIT_IMPERIAL.equals(elevationUnit))
                      s = String.format(elev + " : %,7d feet", (int) (WWMath.convertMetersToFeet(metersElevation)));
                  else // Default to metric units.
                      s = String.format(elev + " : %,7d m", (int) metersElevation);
                  return s;
              }
          
              private String makeEyeAltitudeDescription(double metersAltitude)
              {
                  String s;
          
                  //String altitude = Logging.getMessage("term.Altitude");
                  String altitude = "Eye Alt";
          
                  if (UNIT_IMPERIAL.equals(altitudeUnit))
                  {
                      double feetAltitude = WWMath.convertMetersToFeet(metersAltitude);
          
                      if ( feetAltitude > 100000 )
                          s = String.format(altitude + " :%,7d mi", (int) Math.round(feetAltitude / 1e5 ));
                      else
                          s = String.format(altitude + " :%,7d feet", (int) feetAltitude);
                  }
                  else
                  {
                      if ( metersAltitude > 1000 )
                          s = String.format(altitude + " :%,7d km", (int) Math.round(metersAltitude / 1e3));
                      else
                          s = String.format(altitude + " :%,7d m", (int) metersAltitude );
                  }
          
                  return s;
              }
          
              protected String makeAngleDescription(String label, Angle angle)
              {
                  String s;
                  if (Angle.ANGLE_FORMAT_DMS.equals(angleFormat))
                      s = String.format("%s : %s", label, angle.toDMSString());
                  else
                      s = String.format("%s : %7.4f\u00B0", label, angle.degrees);
                  return s;
              }
          
              private void handleCursorPositionChange(PositionEvent event)
              {
                  Position newPos = event.getPosition();
                  if (newPos != null)
                  {
                      String las = makeAngleDescription("Lat", newPos.getLatitude());
                      String los = makeAngleDescription("Lon", newPos.getLongitude());
                      String els = makeCursorElevationDescription( wwd_.getModel().getGlobe().getElevation(newPos.getLatitude(), newPos.getLongitude()));
                      lonDisplay.setText(los);
                      latDisplay.setText(las);
                      eleDisplay.setText(els);
                  }
                  else
                  {
                      lonDisplay.setText("");
                      latDisplay.setText(Logging.getMessage("term.OffGlobe"));
                      eleDisplay.setText("");
                  }
          
                  setMetersDisplay( newPos );    
          
                  setMGRSDisplay( newPos );    
              }
          
              public void stageChanged(RenderingEvent event)
              {
                  if (!event.getStage().equals(RenderingEvent.BEFORE_BUFFER_SWAP))
                      return;
          
                  EventQueue.invokeLater(new Runnable()
                  {
                      public void run()
                      {
                          if (wwd_.getView() != null && wwd_.getView().getEyePosition() != null)
                              altDisplay.setText(makeEyeAltitudeDescription(
                                  wwd_.getView().getEyePosition().getElevation()));
                          else
                              altDisplay.setText(Logging.getMessage("term.Altitude"));
                      }
                  });
              }
          
              private void setMetersDisplay( Position newPos )
              {
                  if ( newPos == null || displayMETERS == false )
                  {
                      xMeterDisplay.setText("");
                      yMeterDisplay.setText("");
                      return ;
                  }
          
                  Globe globe = getEventSource().getModel().getGlobe();
          
                  if ( globe instanceof FlatGlobe )
                  {
                      String projectionName = ((FlatGlobe) globe).getProjectionName();
                      String datumName = ((FlatGlobe) globe).getDatumName();
          
                      //System.out.println( "Using projectionName=" + projectionName + " datumName=" + datumName );
          
                      Projector proj = ProjectionMaker.getInstance().getProjector( projectionName, datumName );
          
                      double[] xy = proj.toRectangular( newPos.getLongitude().radians, newPos.getLatitude().radians );
          
                      xMeterDisplay.setText( String.format("X : %,7.1fm", xy[0]));
                      yMeterDisplay.setText( String.format("Y : %,7.1fm", xy[1]));
                  }
                  else if ( globe instanceof Earth )
                  {
                      UTMCoord utm = UTMCoord.fromLatLon( newPos.getLatitude(), newPos.getLongitude(), globe );
          
                      xMeterDisplay.setText( utm.getStringSector() + "/X : " + utm.getStringX() );
                      yMeterDisplay.setText( utm.getStringSector() + "/Y : " + utm.getStringY() );
                  }
                  else // Hey, we're on Mars, Venus... Let's ignore for now !
                  {
                      xMeterDisplay.setText( "" );
                      yMeterDisplay.setText( "" );
                  }
              }
          
              private void setMGRSDisplay( Position newPos )
              {
                  if ( newPos == null || displayMGRS == false )
                  {
                      mgrsDisplay.setText("");
                      return ;
                  }
          
                  Globe globe = getEventSource().getModel().getGlobe();
                  
                  if ( globe instanceof FlatGlobe || globe instanceof Earth )
                  {
                      MGRSCoord mgrs = MGRSCoord.fromLatLon(newPos.getLatitude(), newPos.getLongitude(), globe );
          
                      mgrsDisplay.setText( "MGRS : " + mgrs.toString() );
                  }
                  else // Hey, we're on Mars, Venus... Let's ignore for now !
                  {
                      mgrsDisplay.setText( "" );
                  }
              }
          
              public void setMetersDisplayed( boolean displayMeters )
              {
                  displayMETERS = displayMeters ;
              }
          
              public boolean isMetersDisplayed()
              {
                  return displayMETERS ;
              }
          }
          Attached Files

          Comment

          Working...
          X