/**
  * Switches views based on the passed enum.
  *
  * @param v the View to switch to
  * @param o A BattleField if switching to BattleView.
  */
 public void changeView(Views v, Object o) {
   switch (v) {
     case PREVIOUS:
       CardLayout cl = (CardLayout) body.getLayout();
       JPanel temp = currentPanel;
       panels.pop();
       currentPanel = panels.peek();
       cl.show(body, currentPanel.toString());
       cl.removeLayoutComponent(temp);
       break;
     case BATTLE:
       currentPanel = new BattleView(this, (BattleField) o);
       panels.push(currentPanel);
       body.add(currentPanel, v.name());
       CardLayout cl1 = (CardLayout) body.getLayout();
       cl1.show(body, v.name());
       for (Component c : body.getComponents()) {
         if (c == currentPanel) {
           c.requestFocusInWindow();
         }
       }
       break;
     case TITLE:
       currentPanel = new TitleView(this);
       panels.push(currentPanel);
       body.add(currentPanel, v.name());
       CardLayout cl2 = (CardLayout) body.getLayout();
       cl2.show(body, v.name());
       break;
     default:
       // Do nothing
   }
 }
 // Switches between live and test data
 public static void toggleLiveData() {
   if (liveData) {
     liveData = false;
     view.setLines(testLines);
   } else {
     liveData = true;
     update();
     view.setLines(liveLines);
     // createUpdateTask();
   }
 }
Exemple #3
0
  @Test
  public void removeFromParent_whenViewsParentIsNull_shouldPass() throws Exception {
    assertThat(subject.getParent()).isNull();

    Views.removeFromParent(subject);

    // pass
  }
  @Test
  public void testSetHeight() throws Exception {
    final View view = new View(RuntimeEnvironment.application);
    view.setLayoutParams(new ViewGroup.LayoutParams(25, 50));
    assertThat(view.getLayoutParams()).hasHeight(50);

    Views.setHeight(view, 500);
    assertThat(view.getLayoutParams()).hasHeight(500);
  }
Exemple #5
0
  @Test
  public void removeFromParent_shouldRemoveViewFromParent() throws Exception {
    assertThat(parent.getChildCount()).isEqualTo(0);

    parent.addView(subject);
    assertThat(parent.getChildCount()).isEqualTo(1);
    assertThat(subject.getParent()).isEqualTo(parent);

    Views.removeFromParent(subject);

    assertThat(parent.getChildCount()).isEqualTo(0);
    assertThat(subject.getParent()).isNull();
  }
Exemple #6
0
  @Test
  public void removeFromParent_withMultipleChildren_shouldRemoveCorrectChild() throws Exception {
    parent.addView(new TextView(context));

    assertThat(parent.getChildCount()).isEqualTo(1);

    parent.addView(subject);

    assertThat(parent.getChildCount()).isEqualTo(2);

    Views.removeFromParent(subject);
    assertThat(parent.getChildCount()).isEqualTo(1);

    assertThat(parent.getChildAt(0)).isInstanceOf(TextView.class);
  }
 @Test
 public void testRoot() throws Exception {
   final Activity activity = Robolectric.buildActivity(Activity.class).create().get();
   assertThat(Views.root(activity)).isNotNull().hasId(android.R.id.content);
 }
  // change the return type to Img<FloatType> and adjust the code accordingly
  public <T extends RealType<T>> Img<T> gradient(Img<T> img) {
    // create a new ImgLib2 image of same dimensions, but FloatType
    // to to that, create a new PlanarImgFactory and instantiate a new
    // Img<FloatType>
    /**
     * ImgFactory<T> imgFactory = img.factory(); Img<T> gradientImg = imgFactory.create( img,
     * img.firstElement() );
     */

    // create a localizing cursor on the GradientImg, it will iterate all pixels
    // and is able to efficiently return its position at each pixel, at each
    // pixel we will compute the gradient
    /** Cursor<T> cursor = gradientImg.localizingCursor(); */

    // We extend the input image by a mirroring out of bounds strategy so
    // that we can access pixels outside of the image
    RandomAccessible<T> view = Views.extendMirrorSingle(img);

    // instantiate a RandomAccess on the extended view, it will be used to
    // compute the gradient locally at each pixel location
    RandomAccess<T> randomAccess = view.randomAccess();

    // iterate over all pixels
    while (cursor.hasNext()) {
      // move the cursor to the next pixel
      cursor.fwd();

      // compute gradient in each dimension
      double gradient = 0;

      for (int d = 0; d < img.numDimensions(); ++d) {
        // set the randomaccess to the location of the cursor
        randomAccess.setPosition(cursor);

        // move one pixel back in dimension d
        randomAccess.bck(d);

        // get the value
        double v1 = randomAccess.get().getRealDouble();

        // move twice forward in dimension d, i.e.
        // one pixel above the location of the cursor
        randomAccess.fwd(d);
        randomAccess.fwd(d);

        // get the value
        double v2 = randomAccess.get().getRealDouble();

        // add the square of the magnitude of the gradient
        gradient += ((v2 - v1) * (v2 - v1)) / 4;
      }

      // the square root of all quadratic sums yields
      // the magnitude of the gradient at this location,
      // set the pixel value of the gradient image

      // change the value to float, otherwise it will not be
      // compatible
      cursor.get().setReal(Math.sqrt(gradient));
    }

    return gradientImg;
  }
Exemple #9
0
  @Test
  public void removeFromParent_whenViewIsNull_shouldPass() throws Exception {
    Views.removeFromParent(null);

    // pass
  }