@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(); }
public final void MakeElements() { Color ColorScheme = Driver.ColorScheme; MainFrame = new Frame( "Library", new DPair(0, 0, 0, 0), new DPair(1, 0, 1, 0), ColorExtension.Lighten(ColorScheme, 1), null); leftPanel = new Frame( "LeftPanel", new DPair(0, 0, 0, 0), new DPair(0, 150, 1, 0), Color.WHITE, MainFrame); new Frame( "Stripe1", new DPair(0, 0, 0, 0), new DPair(0, 60, 1, 0), ColorExtension.Lighten(ColorScheme, .7), leftPanel); new Frame( "Stripe2", new DPair(0, 72, 0, 0), new DPair(0, 6, 1, 0), ColorExtension.Lighten(ColorScheme, .7), leftPanel); new Frame( "Stripe3", new DPair(1, -18, 0, 0), new DPair(0, 18, 1, 0), ColorExtension.Lighten(ColorScheme, .7), leftPanel); new TextButton( "LibraryButton", new DPair(0, 0, 0, 12), new DPair(1, -18, 0, 36), ColorScheme, leftPanel, "Library", 18); new TextButton( "StoreButton", new DPair(0, 0, 0, 54), new DPair(1, -18, 0, 36), ColorScheme, leftPanel, "Store", 18); new TextButton( "ViewAlbums", new DPair(0, 18, 0, 96), new DPair(1, -18, 0, 24), ColorScheme, leftPanel, "Albums", 14); new TextButton( "ViewAudiobooks", new DPair(0, 18, 0, 126), new DPair(1, -18, 0, 24), ColorScheme, leftPanel, "Audiobooks", 14); new TextButton( "ViewFilms", new DPair(0, 18, 0, 156), new DPair(1, -18, 0, 24), ColorScheme, leftPanel, "Films", 14); ManagementButton = new TextButton( "ManagementButton", new DPair(0, 0, 0, 186), new DPair(1, -18, 0, 36), ColorScheme, leftPanel, "Mgmt Tools", 18); AccountCredit = new TextButton( "AccountCredit", new DPair(0, 0, 1, -30), new DPair(1, 0, 0, 24), ColorScheme, leftPanel, "Credit: $25.00", 14); new TextButton( "Help", new DPair(0, 0, 1, -60), new DPair(1, 0, 0, 24), ColorScheme, leftPanel, "Help", 14); CenterScrollFrame = new Frame( "CenterFrame", new DPair(0, leftPanel.GetSize().xOffset + 10, 0, 10), new DPair(1, -leftPanel.GetSize().xOffset - 50, 1, -20), Color.WHITE, MainFrame); LibScroll = new ScrollBar( "Scroll", new DPair(1, -30, 0, 10), new DPair(0, 20, 1, -20), ColorScheme, MainFrame, 2000, 200); CreditAdd = new Frame( "CreditAdd", new DPair(.5, -100, .5, -40), new DPair(0, 200, 0, 80), ColorScheme, null); new Frame( "InsideBorder", new DPair(0, 2, 0, 2), new DPair(1, -4, 1, -4), Color.WHITE, CreditAdd); TextLabel Request = new TextLabel( "Request", new DPair(0, 4, 0, 4), new DPair(1, -8, 0, 20), Color.WHITE, CreditAdd, "Add credit to account.", 12); Request.SetTextColor(Driver.ColorScheme); new TextBox( "Input", new DPair(0, 4, 0, 28), new DPair(1, -8, 0, 20), Color.WHITE, CreditAdd, "Credit", 14, Color.BLACK); new TextButton( "CreditAdd", new DPair(.5, -20, 1, -24), new DPair(0, 40, 0, 20), Driver.ColorScheme, CreditAdd, "OK", 14); ModifyItem = new Frame( "ModifyItem", new DPair(.5, -200, .5, -114), new DPair(0, 400, 0, 228), ColorScheme, null); new Frame( "InsideBorder", new DPair(0, 3, 0, 3), new DPair(1, -6, 1, -6), Color.WHITE, ModifyItem); new TextLabel( "Id", new DPair(0, 4, 0, 4), new DPair(0, 100, 0, 18), Color.WHITE, ModifyItem, "ID #000", 12) .SetTextColor(Driver.ColorScheme); new TextLabel( "Title", new DPair(0, 4, 0, 26), new DPair(0, 100, 0, 18), Color.WHITE, ModifyItem, "Title: ", 12) .SetTextColor(Driver.ColorScheme); new TextBox( "TitleInput", new DPair(0, 108, 0, 26), new DPair(1, -115, 0, 18), Color.WHITE, ModifyItem, "newtitle", 12, Driver.ColorScheme); new TextLabel( "Artist", new DPair(0, 4, 0, 48), new DPair(0, 100, 0, 18), Color.WHITE, ModifyItem, "Artist: ", 12) .SetTextColor(Driver.ColorScheme); new TextBox( "ArtistInput", new DPair(0, 108, 0, 48), new DPair(1, -115, 0, 18), Color.WHITE, ModifyItem, "newartist", 12, Driver.ColorScheme); new TextLabel( "Year", new DPair(0, 4, 0, 70), new DPair(0, 100, 0, 18), Color.WHITE, ModifyItem, "Year: ", 12) .SetTextColor(Driver.ColorScheme); new TextBox( "YearInput", new DPair(0, 108, 0, 70), new DPair(1, -115, 0, 18), Color.WHITE, ModifyItem, "newyear", 12, Driver.ColorScheme); new TextLabel( "Genre", new DPair(0, 4, 0, 92), new DPair(0, 100, 0, 18), Color.WHITE, ModifyItem, "Genre: ", 12) .SetTextColor(Driver.ColorScheme); new TextBox( "GenreInput", new DPair(0, 108, 0, 92), new DPair(1, -115, 0, 18), Color.WHITE, ModifyItem, "newgenre", 12, Driver.ColorScheme); new TextLabel( "Cost", new DPair(0, 4, 0, 114), new DPair(0, 100, 0, 18), Color.WHITE, ModifyItem, "Cost: ", 12) .SetTextColor(Driver.ColorScheme); new TextBox( "CostInput", new DPair(0, 108, 0, 114), new DPair(1, -115, 0, 18), Color.WHITE, ModifyItem, "newcost", 12, Driver.ColorScheme); new TextLabel( "Duration", new DPair(0, 4, 0, 136), new DPair(0, 100, 0, 18), Color.WHITE, ModifyItem, "Duration: ", 12) .SetTextColor(Driver.ColorScheme); new TextBox( "DurationInputH", new DPair(0, 108, 0, 136), new DPair(0, 40, 0, 18), Color.WHITE, ModifyItem, "newduration", 12, Driver.ColorScheme); new TextBox( "DurationInputM", new DPair(0, 152, 0, 136), new DPair(0, 40, 0, 18), Color.WHITE, ModifyItem, "newduration", 12, Driver.ColorScheme); new TextBox( "DurationInputS", new DPair(0, 194, 0, 136), new DPair(0, 40, 0, 18), Color.WHITE, ModifyItem, "newduration", 12, Driver.ColorScheme); new TextLabel( "Preview", new DPair(0, 4, 0, 158), new DPair(0, 100, 0, 18), Color.WHITE, ModifyItem, "Preview: ", 12) .SetTextColor(Driver.ColorScheme); new TextBox( "PreviewInput", new DPair(0, 108, 0, 158), new DPair(1, -115, 0, 18), Color.WHITE, ModifyItem, "newpreview", 12, Driver.ColorScheme); new TextLabel( "Hidden", new DPair(0, 4, 0, 180), new DPair(0, 100, 0, 18), Color.WHITE, ModifyItem, "Hidden: ", 12) .SetTextColor(Driver.ColorScheme); new CheckBox( "HiddenInput", new DPair(0, 108, 0, 180), new DPair(0, 100, 0, 18), Driver.ColorScheme, ModifyItem, "Hidden", 12); new TextButton( "SubmitChanges", new DPair(0, 4, 1, -26), new DPair(0, 140, 0, 20), Driver.ColorScheme, ModifyItem, "Submit Changes", 14); new TextButton( "CloseModifyWindow", new DPair(1, -30, 1, -26), new DPair(0, 26, 0, 20), Driver.ColorScheme, ModifyItem, "X", 14); Help = new Frame( "HelpFrame", new DPair(0.5, -150, 0.5, -200), new DPair(0, 300, 0, 400), Driver.ColorScheme, null); new Frame("InsideBorder", new DPair(0, 3, 0, 3), new DPair(1, -6, 1, -6), Color.WHITE, Help); String[] info = { "View your personal library by pressing the", "\"Library\" button to the left. View everything", "available in the store by pressing \"Store\",", "or filter your results down to albums,", "audiobooks, or films by pressing the", "respective buttons. Purchase items by", "pressing the “Buy” button.", "", "Need more credit? Click the button in the", "lower left showing how much credit you", "have." }; for (int i = 0; i < info.length; i++) { new TextLabel( "label", new DPair(0, 4, 0, i * 24 + 4), new DPair(1, -8, 0, 18), Color.WHITE, Help, info[i], 12) .SetTextColor(Driver.ColorScheme); } new TextButton( "CloseHelpWindow", new DPair(.7, -4, 1, -26), new DPair(.3, 0, 0, 20), Driver.ColorScheme, Help, "Close", 14); RatingWindow = new Frame( "Rating", new DPair(0, 0, 0, 0), new DPair(0, 120, 0, 146), Driver.ColorScheme, null); new TextLabel( "Rating", new DPair(0, 3, 0, 3), new DPair(1, -6, 0, 17), Color.WHITE, RatingWindow, "Rating", 12) .SetTextColor(Driver.ColorScheme); new TextButton( "1star", new DPair(0, 3, 0, 23), new DPair(1, -6, 0, 17), Driver.ColorScheme, RatingWindow, "*", 12); new TextButton( "2star", new DPair(0, 3, 0, 43), new DPair(1, -6, 0, 17), Driver.ColorScheme, RatingWindow, "**", 12); new TextButton( "3star", new DPair(0, 3, 0, 63), new DPair(1, -6, 0, 17), Driver.ColorScheme, RatingWindow, "***", 12); new TextButton( "4star", new DPair(0, 3, 0, 83), new DPair(1, -6, 0, 17), Driver.ColorScheme, RatingWindow, "****", 12); new TextButton( "5star", new DPair(0, 3, 0, 103), new DPair(1, -6, 0, 17), Driver.ColorScheme, RatingWindow, "*****", 12); new TextButton( "0star", new DPair(0, 3, 0, 123), new DPair(1, -6, 0, 17), Driver.ColorScheme, RatingWindow, "n/a", 12); }