// Used by paintComponent() only private void LoadScreenshotImage() { int imageWidth, imageHeight; double aspectRatio; if (lstGames.hasNoGames()) { biScreenshot = InstallHintScreenshot(); scaledScrLeft = currTheme.getScreenshotLeft(); scaledScrTop = currTheme.getScreenshotTop(); scaledScrHeight = screenshotHeight; scaledScrWidth = screenshotWidth; return; } File screenshotFile = new File(screenshotsPath, lstGames.getSelectedGameId() + ".png"); if (screenshotFile.isFile()) { biScreenshot = UIHelpers.LoadBufferedImage(screenshotFile); } else { // TODO: Create "Screenshot Not Available" image in memory or load it from .jar file biScreenshot = UIHelpers.LoadBufferedImage(new File(screenshotsPath, "noscreenshot.png")); } imageWidth = biScreenshot.getWidth(); imageHeight = biScreenshot.getHeight(); aspectRatio = imageWidth / (double) imageHeight; scaledScrLeft = currTheme.getScreenshotLeft(); scaledScrTop = currTheme.getScreenshotTop(); if (aspectRatio < 1) { // => screenshot PNG image is in portrait mode. // Scale the PNG image such that its height becomes = Screenshot window height scaledScrHeight = screenshotHeight; scaledScrWidth = (int) Math.ceil(aspectRatio * screenshotHeight); scaledScrLeft += (screenshotWidth - scaledScrWidth) / 2; } else { // => screenshot PNG image is in landscape mode. // Scale the PNG image such that its width becomes = Screenshot window width scaledScrWidth = screenshotWidth; scaledScrHeight = (int) Math.ceil(screenshotWidth / (double) aspectRatio); scaledScrTop += (screenshotHeight - scaledScrHeight) / 2; } }
public void DoCommand(ActionEvent e) { String currAction = e.getActionCommand(); if (currAction.equals(ArcadeTheme.UP_BUTTON_ACTION)) { if (lstGames.ScrollDown()) { bLoadScreenshot = true; // Position is important! this.repaint(); } } else if (currAction.equals(ArcadeTheme.DOWN_BUTTON_ACTION)) { if (lstGames.ScrollUp()) { bLoadScreenshot = true; // Position is important! this.repaint(); } } else if (currAction.equals(ArcadeTheme.LOAD_GAME_BUTTON_ACTION)) { if (lstGames.hasNoGames()) JOptionPane.showMessageDialog( this, "You need to install at least " + "one game before trying to load.", "No Game Installed", JOptionPane.WARNING_MESSAGE); else parentFrame.BurnUsingProgrammer( lstGames.getSelectedGameId(), lstGames.getSelectedGameName()); } else if (currAction.equals(ArcadeTheme.HOW_TO_PLAY_BUTTON_ACTION)) { if (lstGames.hasNoGames()) JOptionPane.showMessageDialog( this, "No games are installed", "No Game Installed", JOptionPane.WARNING_MESSAGE); else { if (dlgHowtoPlay == null) dlgHowtoPlay = new HowtoPlayDialog(parentFrame); dlgHowtoPlay.PopulateNShow( lstGames.getSelectedGameId(), lstGames.getSelectedGameName(), selJoystickId); } } else if (currAction.equals(ArcadeTheme.INSTALL_GAME_BUTTON_ACTION)) { File romZipFile = UIHelpers.ShowFileOpen( "Open Zip file containing game rom files", zipFileFilter, ".zip", null, null); if (romZipFile != null) { if (InstallGame(romZipFile)) { if (!bReinstalledGame) { File logoImageFile; BufferedImage biLogo = null; logoImageFile = new File(monogramsPath, installedGameId + ".png"); if (logoImageFile.isFile()) biLogo = UIHelpers.LoadBufferedImage(logoImageFile); else biLogo = UIHelpers.LoadBufferedImage(new File(monogramsPath, "nologo.png")); lstGames.AddInstalledGame( installedGameIndex, new GamesListbox.GameStruct(installedGameId, installedGameName, biLogo)); bLoadScreenshot = true; // Position is important! this.repaint(); } } } } else if (currAction.equals(ArcadeTheme.PREFERENCES_BUTTON_ACTION)) { // Always instantiate dlgPreferences dlgPreferences = new PreferencesDialog(parentFrame, docPlatformXML); dlgPreferences.PopulateForm(); if (dlgPreferences.isOKClicked()) { // Propogate changed application settings to required settings variables. selJoystickId = programSettings.getStringProperty("JoystickId"); parentFrame.setSelectedPlatformId(programSettings.getStringProperty("PlatformId")); parentFrame.setWrite2Target(programSettings.getStringProperty("Writeto")); } /* User is not likely to invoke Preferences dialogbox many times, so it makes no sense to cache it in memory. Further, the dialogbox does not have to free any external resources such as files, etc. Hence, it is best to dispose it when user dismisses it. */ dlgPreferences.dispose(); } else if (currAction.equals(ArcadeTheme.UPDATE_BUTTON_ACTION)) { parentFrame.PlaceGlassPane("Checking for Updates"); new SwingWorker<List<Boolean>, Void>() { /* It is tempting to declare List<Boolean> alPossibleErrors here - as class level variable. This way, it will be available to doInBackground() as well as done(). But bear in mind that said procedures are being executed on 2 different threads. Thus, accessing alPossibleErrors becomes a cross-thread issue. Even though it is possible that no issue will arise, it is better to let Java handle it. So, return alPossibleErrors in doInBackground() and retrieve it using get() in done(). */ // Executed on a worker (background) thread // Should never touch any Swing component @Override protected List<Boolean> doInBackground() { List<Boolean> alPossibleErrors = new ArrayList<Boolean>(3); if (UpdateDialog.CheckForUpdates(alPossibleErrors)) { return alPossibleErrors; } else return null; } // Executed on EDT @Override protected void done() { try { parentFrame.RemoveGlassPane(); List<Boolean> alPossibleErrors = get(); if (alPossibleErrors == null) JOptionPane.showMessageDialog( parentFrame, "There was an error connecting Gadgetfactory website", "Update Error", JOptionPane.ERROR_MESSAGE); else if (alPossibleErrors.get(0).equals(Boolean.TRUE)) JOptionPane.showMessageDialog( parentFrame, "You are not connected to Internet. " + "Please connect before updating", "Update Error", JOptionPane.ERROR_MESSAGE); else if (alPossibleErrors.get(1).equals(Boolean.TRUE)) JOptionPane.showMessageDialog( parentFrame, "It is taking too long to connect to Gadgetfactory " + "website, aborting update", "Update Error", JOptionPane.ERROR_MESSAGE); else { /* User is not likely to invoke Update dialogbox many times, so it makes sense to use it on "on-demand" basis - so that unnecessary memory will not be allocated. Hence, it is best to instantiate it and dispose it when user dismisses it. */ dlgUpdate = new UpdateDialog( parentFrame, docGameXML, docHardwareXML, romsFolder, imagesFolder); dlgUpdate.PopulateForm(); // if (dlgPreferences.isOKClicked()) { // } dlgUpdate.dispose(); } } catch (InterruptedException e) { System.err.println("(Anonymous).done\t" + e.getMessage()); } catch (ExecutionException e) { System.err.println("(Anonymous).done\t" + e.getMessage()); } } }.execute(); } else if (currAction.equals(ArcadeTheme.HELP_BUTTON_ACTION)) { File helpFile = new File(AppPath, "help/index.html"); HelperFunctions.BrowseURL(helpFile.toURI().toString(), runningonWindows); } else if (currAction.equals(ArcadeTheme.EXIT_BUTTON_ACTION)) { parentFrame.CleanupAndExit(); } }