// Set<Dish> getSelectedDishes = new HashSet<Dish>();
  public CheckoutImages(View view, DinnerModel model) {

    // store in the class the reference to the Android View
    this.view = view;
    this.model = model;
    // getSelectedDishes = model.getSelectedDishes(); FIX THIS LATER!

    result2 = model.getFullMenu();

    for (Dish d : result2) {
      imageString = d.getImage();
      dishName = d.getName();
    }

    if (imageString.indexOf(".") > 0) {
      imageString = imageString.substring(0, imageString.lastIndexOf("."));
    }
    TextView test = (TextView) view.findViewById(R.id.instructions);
    test.setText("Instructrions");

    TextView dname = (TextView) view.findViewById(R.id.dishName);
    dname.setText(dishName);

    /** THIS IS HOW WE DO WHEN WE DO THE IMAGE DONE!* */
    ImageView image = (ImageView) view.findViewById(R.id.smallImg);
    int resID =
        view.getResources()
            .getIdentifier(
                imageString, "drawable", ((Activity) view.getContext()).getPackageName());
    image.setImageResource(resID);

    // Setup the rest of the view layout
  }
  public Desert(View view, DinnerModel model) {

    this.view = view;
    this.model = model;
    getDishes = model.getDishes();

    // get all deserts
    getDishes = model.getDishes();
    for (Dish d : getDishes) {
      if (d.getType() == 3) {
        deserts.add(d);
      }
    }

    imgName = (TextView) view.findViewById(R.id.desertImgName);
    if (deserts.isEmpty()) {
      imgFileName = "icecream.jpg";
      imgName.setText("Ice cream");
    } else {
        /** TODO: choose the correct image according to the image ID! * */
      for (Dish s : deserts) {
        // get the name
        imgName.setText(s.getName());
        // get the image
        imgFileName = s.getImage();

        if (imgFileName.equals("")) {
          imgFileName = "toast.jpg";
        }
      }
    }

    if (imgFileName.indexOf(".") > 0) {
      // delete .jpg
      imgFileName = imgFileName.substring(0, imgFileName.lastIndexOf("."));
    }

    /** IMAGE AS DRAWABLE! * */
    image = (ImageView) view.findViewById(R.id.desertImg);
    int resID =
        view.getResources()
            .getIdentifier(
                imgFileName, "drawable", ((Activity) view.getContext()).getPackageName());

    image.setImageResource(resID);
  }
示例#3
0
  /** Create the panel. */
  public DishView(DinnerModel model, Dish dish) {
    setBounds(100, 100, 680, 400);

    SpringLayout springLayout = new SpringLayout();
    setLayout(springLayout);

    try {
      bi = ImageIO.read(new File("images/" + dish.getImage()));
    } catch (IOException e) {
      e.printStackTrace();
    }

    JSplitPane splitPane =
        new JSplitPane(
            JSplitPane.HORIZONTAL_SPLIT,
            true,
            new PreparationView(dish),
            new IngredientView(dish.getIngredients()));
    springLayout.putConstraint(SpringLayout.NORTH, splitPane, 130, SpringLayout.NORTH, this);
    springLayout.putConstraint(SpringLayout.WEST, splitPane, 10, SpringLayout.WEST, this);
    springLayout.putConstraint(SpringLayout.SOUTH, splitPane, -10, SpringLayout.SOUTH, this);
    springLayout.putConstraint(SpringLayout.EAST, splitPane, -10, SpringLayout.EAST, this);
    splitPane.setDividerLocation(340);
    add(splitPane);

    JLabel lblDishName = new JLabel(dish.getName());
    springLayout.putConstraint(SpringLayout.NORTH, lblDishName, 25, SpringLayout.NORTH, this);
    lblDishName.setFont(new Font("Tahoma", Font.PLAIN, 22));
    add(lblDishName);

    JLabel lblPriceFor =
        new JLabel(
            "$ " + model.getDishPrice(dish) + " for " + model.getNumberOfGuests() + " persons");
    springLayout.putConstraint(SpringLayout.WEST, lblDishName, 0, SpringLayout.WEST, lblPriceFor);
    springLayout.putConstraint(SpringLayout.WEST, lblPriceFor, 150, SpringLayout.WEST, this);
    springLayout.putConstraint(SpringLayout.SOUTH, lblPriceFor, -36, SpringLayout.NORTH, splitPane);
    add(lblPriceFor);
  }
    public MenuListItem(Dish d, int id) {
      this.id = id;
      this.dish = d;
      this.imageLabel.setPreferredSize(
          new Dimension(Constants.menuEntryPicWidth, Constants.menuEntryPicWidth));
      Image img =
          new ImageIcon(Constants.homeDir + Constants.pictureDir + dish.getImage()).getImage();
      Image newImg =
          img.getScaledInstance(
              Constants.menuEntryPicWidth, Constants.menuEntryPicWidth, Image.SCALE_SMOOTH);
      this.imageLabel.setIcon(new ImageIcon(newImg));
      this.imageLabel.setBorder(BorderFactory.createRaisedBevelBorder());

      this.nameLabel.setText("   " + dish.getypeStr() + " : " + dish.getName());
      this.nameLabel.setPreferredSize(
          new Dimension(Constants.menuEntryLabelWidth, Constants.menuEntryLabelHeight));
      this.costLabel.setText("   Cost : $ " + dish.getCost());
      this.costLabel.setPreferredSize(
          new Dimension(Constants.menuEntryLabelWidth, Constants.menuEntryLabelHeight));
      this.labelPanel.setLayout(new BorderLayout());
      this.labelPanel.add(nameLabel, BorderLayout.NORTH);
      this.labelPanel.add(costLabel, BorderLayout.SOUTH);
      this.labelPanel.setPreferredSize(
          new Dimension(Constants.menuEntryLabelWidth, Constants.menuEntryHeight));

      img = new ImageIcon(Constants.homeDir + Constants.pictureDir + "remove.jpg").getImage();
      newImg =
          img.getScaledInstance(
              Constants.menuEntryPicWidth, Constants.menuEntryPicWidth, Image.SCALE_SMOOTH);
      this.removeButton.setIcon(new ImageIcon(newImg));
      this.removeButton.setPreferredSize(
          new Dimension(Constants.menuEntryPicWidth, Constants.menuEntryPicWidth));
      // this.removeButton.setBackground(Color.RED);
      this.removeButton.addMouseListener(
          new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
              InformationDisplayPanel.this.removeFromList(MenuListItem.this.dish);
            }

            @Override
            public void mouseEntered(MouseEvent e) {
              MenuListItem.this.removeButton.setBorder(BorderFactory.createRaisedBevelBorder());
            }

            public void mouseExited(MouseEvent e) {
              MenuListItem.this.removeButton.setBorder(null);
            }
          });

      this.setPreferredSize(new Dimension(Constants.menuEntryWidth, Constants.menuEntryHeight));
      this.setLayout(new BorderLayout());
      this.add(imageLabel, BorderLayout.WEST);
      this.add(this.labelPanel, BorderLayout.CENTER);
      this.add(removeButton, BorderLayout.EAST);
      this.setBorder(BorderFactory.createEtchedBorder());
      this.addMouseListener(
          new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
              DishNameDisplayWindow dndw =
                  new DishNameDisplayWindow(
                      MenuListItem.this.dish, InformationDisplayPanel.this.getGuestNum());
              dndw.setVisible(true);
            }

            @Override
            public void mouseEntered(MouseEvent e) {
              MenuListItem.this.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 3));
            }

            @Override
            public void mouseExited(MouseEvent e) {
              MenuListItem.this.setBorder(BorderFactory.createEtchedBorder());
            }
          });
    }