示例#1
0
  private Chart createChart(int points) {
    Chart chart = new Chart(ChartType.SCATTER);
    Configuration conf = chart.getConfiguration();

    conf.getChart().setZoomType(ZoomType.XY);
    conf.disableCredits();
    conf.setTitle("Height vs Weight");
    conf.setSubTitle("Polygon series in Vaadin Charts.");

    Tooltip tooltip = conf.getTooltip();
    tooltip.setHeaderFormat("{series.name}");
    tooltip.setPointFormat("{point.x} cm, {point.y} kg");

    XAxis xAxis = conf.getxAxis();
    xAxis.setStartOnTick(true);
    xAxis.setEndOnTick(true);
    xAxis.setShowLastLabel(true);
    xAxis.setTitle("Height (cm)");

    YAxis yAxis = conf.getyAxis();
    yAxis.setTitle("Weight (kg)");

    AbstractLinePlotOptions plotOptions = new PlotOptionsScatter();
    plotOptions.setThreshold(0);
    DataSeries scatter = new DataSeries();
    scatter.setPlotOptions(plotOptions);
    scatter.setName("Observations");
    fillScatter(scatter, points);
    conf.addSeries(scatter);
    return chart;
  }
示例#2
0
	/**
	 * Toggles {@link Tooltip} between show and dismiss.
	 *
	 * @param rect   {@link Rect} containing the bounds of last clicked entry
	 * @param value   Value of the last entry clicked
	 */
	private void toggleTooltip(Rect rect, float value){

		if(!mTooltip.on()) {
			mTooltip.prepare(rect, value);
			showTooltip(mTooltip, true);
		}else {
			dismissTooltip(mTooltip, rect, value);
		}
	}
示例#3
0
	/**
	 * Adds a tooltip to {@link ChartView}. If is not the case already,
	 * the whole tooltip is forced to be inside {@link ChartView} bounds.
	 *
	 * @param tooltip   {@link Tooltip} view to be added
	 * @param correctPos   False if tooltip should not be forced to be inside ChartView.
	 *               You may want to take care of it
	 */
	public void showTooltip(Tooltip tooltip, boolean correctPos) {

		if (correctPos) {
			tooltip.correctPosition(mChartLeft - getPaddingLeft(),
					mChartTop - getPaddingTop(),
					mChartRight - getPaddingRight(),
					(int) (getInnerChartBottom() - getPaddingBottom()));
		}

		if(tooltip.hasEnterAnimation())
			tooltip.animateEnter();

		this.addTooltip(tooltip);

	}
示例#4
0
	/**
	 * The method listens chart clicks and checks whether it intercepts
	 * a known Region. It will then use the registered Listener.onClick 
	 * to return the region's index. 
	 */
	@Override
	public boolean onTouchEvent(@NonNull MotionEvent event) {

		if(mAnim == null || !mAnim.isPlaying())

			if(event.getAction() == MotionEvent.ACTION_DOWN &&
					mEntryListener != null&&
					(mTooltip != null ) &&
					mRegions != null){

				//Check if ACTION_DOWN over any ScreenPoint region.
				int nSets = mRegions.size();
				int nEntries = mRegions.get(0).size();
				for(int i = 0; i < nSets ; i++){
					for(int j = 0; j < nEntries; j++){

						if(mRegions.get(i).get(j)
								.contains((int) event.getX(),
										(int) event.getY())){
							mSetClicked = i;
							mIndexClicked = j;
						}
					}
				}

			}else if(event.getAction() == MotionEvent.ACTION_UP){

				if(mSetClicked != -1 &&
						mIndexClicked != -1){
					if(mRegions.get(mSetClicked).get(mIndexClicked)
							.contains((int) event.getX(),
									(int) event.getY())){

						if(mEntryListener != null){
							mEntryListener.onClick(mSetClicked,
									mIndexClicked,
									new Rect(getEntryRect(mRegions.get(mSetClicked).get(mIndexClicked))));
						}

						if(mTooltip != null){
							toggleTooltip(getEntryRect(mRegions.get(mSetClicked).get(mIndexClicked)),
									data.get(mSetClicked).getValue(mIndexClicked));
						}

					}
					mSetClicked = -1;
					mIndexClicked = -1;

				}else{

					if(mChartListener != null)
						mChartListener.onClick(this);

					if(mTooltip != null && mTooltip.on())
						dismissTooltip(mTooltip);
				}
			}

		return true;
	}
示例#5
0
 public NPC(String gamertag, boolean isPlayerOne, Map map, Unit[] units) {
   super(gamertag, isPlayerOne, map, units);
   Tooltip.turnOff(isPlayerOne);
   vis = new ArrayList<GPoint>();
   newTurn = true;
   UnitNoCombat = new boolean[units.length];
   respondedToHits = new boolean[units.length];
 }
示例#6
0
 public void enablePreview() {
   //        if (null != itemDescription) {
   //            itemDescription.activate();
   //            return;
   //        }
   itemDescription =
       new Tooltip(
           this,
           new HTML(
               constants.previewHtml(item.getTitle(), item.getYear(), item.getCreator()), true),
           this.getAbsoluteLeft(),
           this.getAbsoluteTop(),
           dimensions.thumbnailWidth(),
           dimensions.thumbnailHeight());
   itemDescription.setStyleName("tooltip-item");
   itemDescription.addStyleName("invisible");
   itemDescription.setWidth(dimensions.thumbnailWidth() + "px");
   itemDescription.activate();
 }
示例#7
0
	/**
	 * Dismiss tooltip from {@link ChartView}.
	 *
	 * @param tooltip   View to be dismissed
	 */
	private void dismissTooltip(final Tooltip tooltip, final Rect rect, final float value){

		if(tooltip.hasExitAnimation()) {
			tooltip.animateExit( new Runnable(){
				@Override
				public void run() {

					removeTooltip(tooltip);
					if(rect != null)
						toggleTooltip(rect, value);
				}
			});
		}else{
			this.removeTooltip(tooltip);
			if(rect != null)
				this.toggleTooltip(rect, value);
		}



	}
示例#8
0
 // Explicit implementation of readObject, but called implicitly as a result of recursive calls to
 // readObject() based on Serializable interface
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   name = new SimpleStringProperty((String) in.readObject());
   strength = new SimpleDoubleProperty(in.readDouble());
   health = new SimpleDoubleProperty(in.readDouble());
   speed = new SimpleDoubleProperty(in.readDouble());
   createAvatar();
   getAvatar().setTranslateX(in.readDouble());
   getAvatar().setTranslateY(in.readDouble());
   tooltip = new Tooltip(toString());
   Tooltip.install(getAvatar(), tooltip);
   resetAvatarAttributes();
 } // end readObject() to support serialization
示例#9
0
  public void addImageTab(Path imagePath) {

    TabPane previewTabPane = controller.getPreviewTabPane();

    ImageTab tab = new ImageTab();
    tab.setPath(imagePath);
    tab.setText(imagePath.getFileName().toString());

    if (previewTabPane.getTabs().contains(tab)) {
      previewTabPane.getSelectionModel().select(tab);
      return;
    }

    Image image = new Image(IOHelper.pathToUrl(imagePath));
    ImageView imageView = new ImageView(image);
    imageView.setPreserveRatio(true);

    imageView.setFitWidth(previewTabPane.getWidth());

    previewTabPane
        .widthProperty()
        .addListener(
            (observable, oldValue, newValue) -> {
              imageView.setFitWidth(previewTabPane.getWidth());
            });

    Tooltip tip = new Tooltip(imagePath.toString());
    Tooltip.install(tab.getGraphic(), tip);

    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
    scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
    scrollPane.setContent(imageView);
    scrollPane.addEventFilter(
        ScrollEvent.SCROLL,
        e -> {
          if (e.isControlDown() && e.getDeltaY() > 0) {
            // zoom in
            imageView.setFitWidth(imageView.getFitWidth() + 16.0);
          } else if (e.isControlDown() && e.getDeltaY() < 0) {
            // zoom out
            imageView.setFitWidth(imageView.getFitWidth() - 16.0);
          }
        });

    tab.setContent(scrollPane);

    TabPane tabPane = previewTabPane;
    tabPane.getTabs().add(tab);
    tabPane.getSelectionModel().select(tab);
  }
示例#10
0
 @Override
 public void deactivate() {
   if (!active) {
     return;
   }
   active = false;
   removeStyleName("mouse-cursor");
   dispatchEvent(ItemPreviewEvent.DEACTIVATED);
   for (ItemListener<ItemPreview, ItemPreviewEvent> listener : listeners) {
     listener.deactivated(this);
   }
   if (null != itemDescription) {
     itemDescription.hide();
   }
 }
示例#11
0
 /**
  * <i>Actor</i> constructor is used when building <i>Actor</i> objects automatically:
  * <i>strength</i>, <i>health</i>, <i>speed</i> fields are given randomly generated values within
  * their range; <i>name</i> is given a sequentially numbered name: <i>Auto:<b>n</b></i> where
  * <i><b>n</b></i> is the sequence number. The <i>name</i> can be edited to create an unique
  * <i>Actor</i>.
  *
  * @param subclassCount used to support automatic naming (which includes a unique serial number).
  * @param armyAllegiance used to support the <i>Army</i>-specific <i>DropShadow</i> glow around
  *     this Actor object.
  */
 public Actor(int subclassCount, Army armyAllegiance) {
   this.armyAllegiance = armyAllegiance;
   ++actorSerialNumber; // static class-oriented variable. There is one-and-only-one instance of
                        // this variable regardless of the number of Actor objects in existence
                        // (from none to infinity).
   setName(
       String.format(
           "%d:%s:%d:",
           actorSerialNumber,
           getClass().getSimpleName(),
           subclassCount)); // An alternate way to assemble a String to use as a name. Because of
                            // polymorphism "getClass().getName()" will return the subclass name
                            // when they exist.
   setStrength(SingletonRandom.instance.getNormalDistribution(MIN_STRENGTH, MAX_STRENGTH, 2.0));
   setHealth(SingletonRandom.instance.getNormalDistribution(MIN_HEALTH, MAX_HEALTH, 2.0));
   setSpeed(SingletonRandom.instance.getNormalDistribution(MIN_SPEED, MAX_SPEED, 2.0));
   createAvatar();
   tooltip = new Tooltip(toString());
   Tooltip.install(getAvatar(), tooltip);
   tt = new TranslateTransition();
   tt.setNode(getAvatar()); // reuse
 } // end Actor constructor
示例#12
0
 public void resetAvatarAttributes() {
   tooltip.setText(toString());
 } // Note: This updates the text in the Tooltip that was installed earlier. We re-use the
示例#13
0
	/**
	 * Add {@link Tooltip}/{@link View}. to chart/parent view.
	 *
	 * @param tip   tooltip to be added to chart
	 */
	private void addTooltip(Tooltip tip){

		this.addView(tip);
		tip.setOn(true);
	}
示例#14
0
  /**
   * Drawing function for Circles and Lines
   *
   * @param drawPane
   * @param coords Circle Coordinates
   * @param edges array of edges
   * @param startIndex NumberOfNodes
   */
  private void drawShapes(Pane drawPane, double[][] coords, int[][] edges, int startIndex) {

    // clear previous pane
    drawPane.getChildren().clear();
    circleList = new ArrayList<>();

    // generate Circles
    for (int i = 0; i < coords.length; i++) {
      Circle currentCircle = new Circle(coords[i][0], coords[i][1], nodeSize, Color.BLACK);
      String toolTipText = "Node " + Integer.toString(i + 1);
      // expand toolTip text with nucleotide and Circle color, if possible
      if (sequenceField.getText().length() > i) {
        toolTipText += ": " + sequenceField.getText().charAt(i);
        currentCircle.setFill(getNodeColor(sequenceField.getText().charAt(i)));
      }
      Tooltip.install(currentCircle, new Tooltip(toolTipText));
      if (isAnimated) {
        currentCircle.setOnMousePressed(circleOnMousePressedEventHandler);
        currentCircle.setOnMouseDragged(circleOnMouseDraggedEventHandler);
        currentCircle.setOnMouseReleased(circleOnMouseReleasedEventHandler);
      }

      circleList.add(currentCircle);
    }

    // generate  basic Lines
    ArrayList<Line> lineList = new ArrayList<>();
    for (int i = 0; i < circleList.size() - 1; i++) {
      Line line = new Line();
      line.setStroke(Color.BLACK);
      line.setFill(Color.BLACK);
      Circle circle1 = circleList.get(i);
      Circle circle2 = circleList.get(i + 1);

      // bind ends of line:
      line.startXProperty().bind(circle1.centerXProperty().add(circle1.translateXProperty()));
      line.startYProperty().bind(circle1.centerYProperty().add(circle1.translateYProperty()));
      line.endXProperty().bind(circle2.centerXProperty().add(circle2.translateXProperty()));
      line.endYProperty().bind(circle2.centerYProperty().add(circle2.translateYProperty()));

      lineList.add(line);
    }

    // generate edges
    for (int i = startIndex - 1; i < edges.length; i++) {
      Line line = new Line();
      line.setStroke(Color.ORANGE);
      Circle circle1 = circleList.get(edges[i][0]);
      Circle circle2 = circleList.get(edges[i][1]);

      line.startXProperty().bind(circle1.centerXProperty().add(circle1.translateXProperty()));
      line.startYProperty().bind(circle1.centerYProperty().add(circle1.translateYProperty()));
      line.endXProperty().bind(circle2.centerXProperty().add(circle2.translateXProperty()));
      line.endYProperty().bind(circle2.centerYProperty().add(circle2.translateYProperty()));

      lineList.add(line);
    }

    drawPane.getChildren().addAll(lineList);
    drawPane.getChildren().addAll(circleList);
  }
示例#15
0
 public void disablePreview() {
   itemDescription.deactivate();
 }
示例#16
0
 /** Destroy item */
 public void tearDown() {
   removeStyleName("mouse-cursor");
   if (null != itemDescription) {
     itemDescription.deactivate();
   }
 }
示例#17
0
	/**
	 * Remove {@link Tooltip}/{@link View} to chart/parent view.
	 *
	 * @param tip   tooltip to be removed to chart
	 */
	private void removeTooltip(Tooltip tip){
		this.removeView(tip);
		tip.setOn(false);
	}
示例#18
0
	/**
	 * Removes all tooltips currently presented in the chart.
	 */
	public void dismissAllTooltips(){
		this.removeAllViews();
		if(mTooltip != null)
			mTooltip.setOn(false);
	}
示例#19
0
  public void addTab(Path path, Runnable... runnables) {

    ObservableList<String> recentFiles = controller.getRecentFilesList();
    if (Files.notExists(path)) {
      recentFiles.remove(path.toString());
      return;
    }

    ObservableList<Tab> tabs = controller.getTabPane().getTabs();
    for (Tab tab : tabs) {
      MyTab myTab = (MyTab) tab;
      Path currentPath = myTab.getPath();
      if (Objects.nonNull(currentPath))
        if (currentPath.equals(path)) {
          myTab.select(); // Select already added tab
          return;
        }
    }

    AnchorPane anchorPane = new AnchorPane();
    EditorPane editorPane = webviewService.createWebView();

    MyTab tab = createTab();
    tab.setEditorPane(editorPane);
    tab.setTabText(path.getFileName().toString());

    editorPane.confirmHandler(
        param -> {
          if ("command:ready".equals(param)) {
            JSObject window = editorPane.getWindow();
            window.setMember("afx", controller);
            window.call("updateOptions", new Object[] {});
            Map<String, String> shortCuts = controller.getShortCuts();
            Set<String> keySet = shortCuts.keySet();
            for (String key : keySet) {
              window.call("addNewCommand", new Object[] {key, shortCuts.get(key)});
            }
            if (Objects.isNull(path)) return true;
            threadService.runTaskLater(
                () -> {
                  String content = IOHelper.readFile(path);
                  threadService.runActionLater(
                      () -> {
                        window.call("changeEditorMode", path.toUri().toString());
                        window.call("setInitialized");
                        window.call("setEditorValue", new Object[] {content});
                        for (Runnable runnable : runnables) {
                          runnable.run();
                        }
                      });
                });
          }
          return false;
        });

    threadService.runActionLater(
        () -> {
          TabPane tabPane = controller.getTabPane();
          tabPane.getTabs().add(tab);
          tab.select();
        });

    Node editorVBox = editorService.createEditorVBox(editorPane, tab);
    controller.fitToParent(editorVBox);

    anchorPane.getChildren().add(editorVBox);
    tab.setContent(anchorPane);
    tab.setPath(path);

    Tooltip tip = new Tooltip(path.toString());
    Tooltip.install(tab.getGraphic(), tip);

    recentFiles.remove(path.toString());
    recentFiles.add(0, path.toString());

    editorPane.focus();
  }
示例#20
0
  // drawing
  public void drawGraph() {

    Timeline timeline = new Timeline();

    if (graph != null && finalCoordinates != null) {

      // reset pane
      drawing.getChildren().clear();
      SpringEmbedder.centerCoordinates(finalCoordinates, 20, 380, 20, 380);
      SpringEmbedder.centerCoordinates(startingCoordinates, 20, 380, 20, 380);

      // draw nucleotides
      circles = new Circle[finalCoordinates.length];
      for (int i = 0; i < finalCoordinates.length; i++) {
        // create nodes
        Circle circle = new Circle(5);
        circle.setCenterX(finalCoordinates[i][0]);
        circle.setCenterY(finalCoordinates[i][1]);
        switch (graph.getSequence().charAt(i)) {
          case 'A':
            circle.setFill(Color.YELLOW);
            break;
          case 'a':
            circle.setFill(Color.YELLOW);
            break;
          case 'U':
            circle.setFill(Color.GREEN);
            break;
          case 'u':
            circle.setFill(Color.GREEN);
            break;
          case 'C':
            circle.setFill(Color.BLUE);
            break;
          case 'c':
            circle.setFill(Color.BLUE);
            break;
          case 'G':
            circle.setFill(Color.RED);
            break;
          case 'g':
            circle.setFill(Color.RED);
            break;
        }
        circle.setStroke(Color.BLACK);
        // add tooltip
        Tooltip t =
            new Tooltip("Nucleotide: " + graph.getSequence().charAt(i) + "\nPosition: " + i);
        Tooltip.install(circle, t);

        // add drag-and-drop behaviour
        circle.setOnMousePressed(
            event -> {
              if (isAnimationActivated) {
                dragStartX = circle.getCenterX();
                dragStartY = circle.getCenterY();
              }
            });

        circle.setOnMouseDragged(
            event -> {
              if (isAnimationActivated) {
                circle.setCenterX(event.getX());
                circle.setCenterY(event.getY());
              }
            });

        circle.setOnMouseReleased(
            event -> {
              if (isAnimationActivated) {
                Timeline dragTimeline = new Timeline();
                KeyValue circlePositionXKey = new KeyValue(circle.centerXProperty(), dragStartX);
                KeyValue circlePositionYKey = new KeyValue(circle.centerYProperty(), dragStartY);
                dragTimeline
                    .getKeyFrames()
                    .add(new KeyFrame(Duration.millis(animationTime), circlePositionXKey));
                dragTimeline
                    .getKeyFrames()
                    .add(new KeyFrame(Duration.millis(animationTime), circlePositionYKey));
                dragTimeline.play();
              }
            });

        // save circle locally
        circles[i] = circle;

        // animate circles
        KeyValue startingXKey = new KeyValue(circle.centerXProperty(), startingCoordinates[i][0]);
        KeyValue finalXKey = new KeyValue(circle.centerXProperty(), circle.getCenterX());
        KeyValue startingYKey = new KeyValue(circle.centerYProperty(), startingCoordinates[i][1]);
        KeyValue finalYKey = new KeyValue(circle.centerYProperty(), circle.getCenterY());
        timeline.getKeyFrames().add(new KeyFrame(Duration.millis(0), startingXKey));
        timeline.getKeyFrames().add(new KeyFrame(Duration.millis(0), startingYKey));
        timeline.getKeyFrames().add(new KeyFrame(Duration.millis(animationTime), finalXKey));
        timeline.getKeyFrames().add(new KeyFrame(Duration.millis(animationTime), finalYKey));
      }

      // create edges
      int[][] edges = graph.getEdges();
      for (int i = 0; i < edges.length; i++) {
        // bind edges to nodes
        Line line =
            new Line(
                finalCoordinates[edges[i][0]][0],
                finalCoordinates[edges[i][0]][1],
                finalCoordinates[edges[i][1]][0],
                finalCoordinates[edges[i][1]][1]);
        line.startYProperty().bind(circles[edges[i][0]].centerYProperty());
        line.startXProperty().bind(circles[edges[i][0]].centerXProperty());
        line.endYProperty().bind(circles[edges[i][1]].centerYProperty());
        line.endXProperty().bind(circles[edges[i][1]].centerXProperty());

        // draw edges
        if (edges[i][1] - edges[i][0] != 1) {
          line.setStroke(Color.CADETBLUE);
        } else {
          line.setFill(Color.DARKGRAY);
        }
        drawing.getChildren().add(line);
      }

      // draw all circles in order to overlap the edges
      drawing.getChildren().addAll(circles);

      if (isAnimationActivated) {
        timeline.play();
      }

    } else {
      throw new IllegalArgumentException(
          "graph is null: "
              + graph.equals(null)
              + "\ncoordinates is null: "
              + finalCoordinates.equals(null));
    }
  }