Example #1
0
 private void SetModify(int itemIndex) {
   Item current = DataLoader.getItemById(itemIndex);
   if (current != null) {
     CurrentModifyWindowId = itemIndex;
     ModifyItem.SetParent(MainFrame);
     Driver.GetGuiMain().GetTextBoxes();
     ((TextLabel) ModifyItem.GetChild("Id")).SetText("ID #" + itemIndex);
     ((TextBox) ModifyItem.GetChild("TitleInput")).SetText(current.getName());
     ((TextBox) ModifyItem.GetChild("ArtistInput")).SetText(current.getCreator());
     ((TextBox) ModifyItem.GetChild("YearInput")).SetText("" + current.getYearOfRelease());
     ((TextBox) ModifyItem.GetChild("GenreInput")).SetText(current.getGenre());
     ((TextBox) ModifyItem.GetChild("CostInput")).SetText("" + current.getPrice());
     ((TextBox) ModifyItem.GetChild("DurationInputH")).SetText("" + current.getHour());
     ((TextBox) ModifyItem.GetChild("DurationInputM")).SetText("" + current.getMinute());
     ((TextBox) ModifyItem.GetChild("DurationInputS")).SetText("" + current.getSecond());
     ((TextBox) ModifyItem.GetChild("PreviewInput")).SetText("" + current.getPreview());
     ((CheckBox) ModifyItem.GetChild("HiddenInput")).SetSelected(current.isVisible());
     ((CheckBox) ModifyItem.GetChild("HiddenInput"))
         .SetText(
             ((CheckBox) ModifyItem.GetChild("HiddenInput")).GetSelected() ? "true" : "false");
   }
 }
Example #2
0
 @Override
 public void ButtonClicked(GuiObject button, int x, int y) {
   switch (button.GetName()) {
     case "LibraryButton":
       CurrentList = 0;
       break;
     case "StoreButton":
       CurrentList = 4;
       break;
     case "ViewAlbums":
       CurrentList = 1;
       break;
     case "ViewAudiobooks":
       CurrentList = 2;
       break;
     case "ViewFilms":
       CurrentList = 3;
       break;
     case "ManagementButton":
       currentUser = Driver.CurrentUser;
       if (currentUser.getAdministrator()) {
         Driver.SetFrame("Management");
       } else {
         JOptionPane.showMessageDialog(
             null, "Access denied - Admin only", "", JOptionPane.WARNING_MESSAGE);
       }
       break;
     case "Action":
       // "Buy" or "Play" button pressed.
       if (button instanceof TextButton
           && ((TextButton) button).GetText().equals("Buy")
           && CurrentList >= 1
           && CurrentList <= 3) {
         int id = GetItemIdOfFrame((Frame) button.GetParent());
         System.out.println("Pressed buy for item: " + id);
         boolean success = Driver.CurrentUser.purchaseItem(id);
         if (success) {
           ((TextButton) button).SetText("Play");
         } else {
           System.out.println("Buy failed.");
         }
       } else if (button instanceof TextButton
           && ((TextButton) button).GetText().equals("Play")
           && CurrentList == 0) {
         int id = GetItemIdOfFrame((Frame) button.GetParent());
         if (CurrentPlayingItem != null) {
           CurrentPlayingItem.stopAudio();
         }
         CurrentPlayingItem = DataLoader.getItemById(id);
         CurrentPlayingItem.playAudioFull();
       } else if (button instanceof TextButton
           && ((TextButton) button).GetText().equals("Stop")
           && CurrentPlayingItem != null) {
         CurrentPlayingItem.stopAudio();
         CurrentPlayingItem = null;
       } else if (button instanceof TextButton
           && ((TextButton) button).GetText().equals("Play")
           && CurrentList >= 1
           && CurrentList <= 3) {
         int id = GetItemIdOfFrame((Frame) button.GetParent());
         CurrentPlayingItem = DataLoader.getItemById(id);
         CurrentPlayingItem.playAudioPreview();
       }
       AccountCredit.SetText(String.format("Credit: $%.2f", Driver.CurrentUser.getCredit()));
       break;
     case "AccountCredit":
       MainFrame.AddChild(CreditAdd);
       Driver.GetGuiMain().GetTextBoxes();
       break;
     case "CreditAdd":
       double amount = 0;
       try {
         amount = Double.parseDouble(((TextBox) CreditAdd.GetChild("Input")).GetText());
       } catch (Exception e) {
       }
       Driver.CurrentUser.grantCredit(amount);
       MainFrame.RemoveChild(CreditAdd);
       Driver.GetGuiMain().GetTextBoxes();
       break;
     case "Input":
       if (button instanceof TextBox && ((TextBox) button).GetText().equals("Credit")) {
         ((TextBox) button).SetText("");
       }
       break;
     case "Action2":
       if (button instanceof TextButton
           && ((TextButton) button).GetText().equals("Edit")
           && CurrentList >= 0
           && CurrentList <= 4) {
         int id = GetItemIdOfFrame((Frame) button.GetParent());
         SetModify(id);
       } else if (button instanceof TextButton
           && ((TextButton) button).GetText().equals("Rate")
           && CurrentList == 0) {
         CurrentRatingId = GetItemIdOfFrame((Frame) button.GetParent());
         RatingWindow.SetParent(MainFrame);
         RatingWindow.SetPosition(new DPair(0, x - RatingWindow.GetSize().xOffset, 0, y));
         Driver.GetGuiMain().GetTextBoxes();
       }
       break;
     case "HiddenInput":
       ((CheckBox) button).SetText(((CheckBox) button).GetSelected() ? "true" : "false");
       break;
     case "SubmitChanges":
       Item current = DataLoader.getItemById(CurrentModifyWindowId);
       if (current != null) {
         current.setCreator(((TextBox) ModifyItem.GetChild("ArtistInput")).GetText());
         current.setName(((TextBox) ModifyItem.GetChild("TitleInput")).GetText());
         try {
           current.setYearOfRelease(
               Integer.parseInt(((TextBox) ModifyItem.GetChild("YearInput")).GetText()));
         } catch (Exception e) {
         }
         current.setGenre(((TextBox) ModifyItem.GetChild("GenreInput")).GetText());
         try {
           current.setPrice(
               Double.parseDouble(((TextBox) ModifyItem.GetChild("CostInput")).GetText()));
         } catch (Exception e) {
         }
         int d = 0;
         try {
           d +=
               Integer.parseInt(((TextBox) ModifyItem.GetChild("DurationInputH")).GetText())
                   * 3600;
         } catch (Exception e) {
         }
         try {
           d += Integer.parseInt(((TextBox) ModifyItem.GetChild("DurationInputM")).GetText()) * 60;
         } catch (Exception e) {
         }
         try {
           d += Integer.parseInt(((TextBox) ModifyItem.GetChild("DurationInputS")).GetText());
         } catch (Exception e) {
         }
         current.setDuration(d);
         current.setPreview(((TextBox) ModifyItem.GetChild("PreviewInput")).GetText());
         current.setHidden(((CheckBox) ModifyItem.GetChild("HiddenInput")).GetSelected());
       }
       ModifyItem.SetParent(null);
       Driver.GetGuiMain().GetTextBoxes();
       break;
     case "CloseModifyWindow":
       ModifyItem.SetParent(null);
       Driver.GetGuiMain().GetTextBoxes();
       break;
     case "CloseHelpWindow":
       Help.SetParent(null);
       Driver.GetGuiMain().GetTextBoxes();
       break;
     case "Help":
       Help.SetParent(MainFrame);
       Driver.GetGuiMain().GetTextBoxes();
       break;
     case "1star":
       System.out.println("CurrentRatingId: " + CurrentRatingId);
       Driver.CurrentUser.rateItem(CurrentRatingId, 1);
       RatingWindow.SetParent(null);
       Driver.GetGuiMain().GetTextBoxes();
       break;
     case "2star":
       Driver.CurrentUser.rateItem(CurrentRatingId, 2);
       RatingWindow.SetParent(null);
       Driver.GetGuiMain().GetTextBoxes();
       break;
     case "3star":
       Driver.CurrentUser.rateItem(CurrentRatingId, 3);
       RatingWindow.SetParent(null);
       Driver.GetGuiMain().GetTextBoxes();
       break;
     case "4star":
       Driver.CurrentUser.rateItem(CurrentRatingId, 4);
       RatingWindow.SetParent(null);
       Driver.GetGuiMain().GetTextBoxes();
       break;
     case "5star":
       Driver.CurrentUser.rateItem(CurrentRatingId, 5);
       RatingWindow.SetParent(null);
       Driver.GetGuiMain().GetTextBoxes();
       break;
     case "0star":
       Driver.CurrentUser.rateItem(CurrentRatingId, 0);
       RatingWindow.SetParent(null);
       Driver.GetGuiMain().GetTextBoxes();
       break;
   }
   SetFrames();
 }