Beispiel #1
0
  private ChoiceButton createButton(Element xmlButton, Game window) {
    String label = xmlButton.getAttribute("label");
    String target = xmlButton.getAttribute("target");

    ChoiceButton button;
    if (xmlButton.hasAttribute("image")) {
      try {
        BufferedImage img = ImageIO.read(getClass().getResource(xmlButton.getAttribute("image")));
        ImageIcon image = new ImageIcon(img.getScaledInstance(150, 150, Image.SCALE_SMOOTH));

        button = new ChoiceButton(image, label, target, window);
      } catch (IOException ex) {
        button = new ChoiceButton(label, target, window);
        Logger.getLogger(StoryModel.class.getName()).log(Level.SEVERE, null, ex);
      }

    } else {
      button = new ChoiceButton(label, target, window);
    }

    NodeList actions = xmlButton.getElementsByTagName("action");
    for (int i = 0; i < actions.getLength(); i++) {
      Element xmlAction = (Element) actions.item(i);
      Action action = actionFactory.createAction(xmlAction.getAttribute("type"));
      action.createFromXML(xmlAction);

      button.addAction(action);
    }
    button.addActionListener(button);

    return button;
  }
Beispiel #2
0
  @Override
  public void mouseWheelMoved(MouseWheelEvent e) {
    int nbClicks = e.getWheelRotation(); // La vitesse à laquelle on a tourné la roulette

    for (IFormeEditable forme : this.pan.getFormesEditables())
      Action.agrandir(forme, new Point2D(e.getX(), e.getY()), 1 + 0.1 * nbClicks);

    this.pan.repaint();
  }
Beispiel #3
0
  @Override
  public void mouseClicked(MouseEvent e) {
    IFormeEditable courbePrecSelect = null;
    if (this.pan.getFormeSelectionnee() != null) courbePrecSelect = this.pan.getFormeSelectionnee();

    if (SwingUtilities.isRightMouseButton(e)) Action.selectionner(this.pan, e.getX(), e.getY());

    switch (Action.getActionCourante()) {
      case Action.AJOUTER:
        if (SwingUtilities.isLeftMouseButton(e)) Action.ajouter(this.pan, e.getX(), e.getY());
        break;
      case Action.COMBINER:
        if (SwingUtilities.isRightMouseButton(e))
          Action.combiner(courbePrecSelect, this.pan.getFormeSelectionnee());
        break;
      case Action.SUPPRIMER:
        if (SwingUtilities.isLeftMouseButton(e)) Action.supprimer(pan);
        break;
      case Action.ROTATION:
        if (SwingUtilities.isLeftMouseButton(e))
          Action.deplacer(this.pan.getFormeSelectionnee().getCentreRot(), e.getX(), e.getY());
        break;
    }

    this.pan.repaint();
  }
Beispiel #4
0
  @Override
  public void mouseDragged(MouseEvent e) {
    this.nouvPos = new Point2D(e.getX(), e.getY());

    switch (Action.getActionCourante()) {
      case Action.DEPLACER:
        if (SwingUtilities.isLeftMouseButton(e))
          Action.deplacer(this.pan.getFormeSelectionnee(), e.getX(), e.getY());
        break;
      case Action.ROTATION:
        if (SwingUtilities.isLeftMouseButton(e))
          Action.rotation(
              this.pan.getFormeSelectionnee().getCentreRot(),
              this.pan.getFormeSelectionnee(),
              this.nouvPos,
              this.anciennePos);
        break;
    }

    this.pan.repaint();

    this.anciennePos = new Point2D(this.nouvPos);
  }