Exemple #1
0
  public void releaseInterfaceVisualizer(JPanel panel) {
    Observer observer = (Observer) panel.getClientProperty("intf_obs");
    if (observer == null) {
      logger.fatal("Error when releasing panel, observer is null");
      return;
    }

    this.deleteObserver(observer);
  }
Exemple #2
0
  public JPanel getInterfaceVisualizer() {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    final NumberFormat form = NumberFormat.getNumberInstance();

    final JLabel positionLabel = new JLabel();
    positionLabel.setText(
        "x="
            + form.format(getXCoordinate())
            + " "
            + "y="
            + form.format(getYCoordinate())
            + " "
            + "z="
            + form.format(getZCoordinate()));

    panel.add(positionLabel);

    Observer observer;
    this.addObserver(
        observer =
            new Observer() {
              public void update(Observable obs, Object obj) {
                positionLabel.setText(
                    "x="
                        + form.format(getXCoordinate())
                        + " "
                        + "y="
                        + form.format(getYCoordinate())
                        + " "
                        + "z="
                        + form.format(getZCoordinate()));
              }
            });

    // Saving observer reference for releaseInterfaceVisualizer
    panel.putClientProperty("intf_obs", observer);

    return panel;
  }