/* * AppleCommander - An Apple ][ image utility. * Copyright (C) 2002-2022 by Robert Greene * robgreene at users.sourceforge.net * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package com.webcodepro.applecommander.ui.swt; import com.webcodepro.applecommander.storage.Disk; import com.webcodepro.applecommander.storage.Disk.FilenameFilter; import com.webcodepro.applecommander.storage.DiskUnrecognizedException; import com.webcodepro.applecommander.storage.FormattedDisk; import com.webcodepro.applecommander.ui.AppleCommander; import com.webcodepro.applecommander.ui.UiBundle; import com.webcodepro.applecommander.ui.UserPreferences; import com.webcodepro.applecommander.ui.swt.util.ImageCanvas; import com.webcodepro.applecommander.ui.swt.util.ImageManager; import com.webcodepro.applecommander.ui.swt.wizard.comparedisks.CompareDisksWizard; import com.webcodepro.applecommander.ui.swt.wizard.diskimage.DiskImageWizard; import com.webcodepro.applecommander.util.Host; import com.webcodepro.applecommander.util.TextBundle; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.*; import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; /** * Main class for the SwtAppleCommander interface. *

* Date created: Oct 7, 2002 9:43:37 PM * @author Rob Greene */ public class SwtAppleCommander implements Listener { private Shell shell; private ToolBar toolBar; private UserPreferences userPreferences = UserPreferences.getInstance(); private TextBundle textBundle = UiBundle.getInstance(); private ImageCanvas imageCanvas; private static ImageManager imageManager; /** * Launch SwtAppleCommander. */ public static void main(String[] args) { new SwtAppleCommander().launch(args); } /** * Launch SwtAppleCommander. */ public void launch(String[] args) { Display.setAppName("AppleCommander"); Display.setAppVersion(AppleCommander.VERSION); Display display = new Display(); display.setData("org.eclipse.swt.internal.theme.useSystemColors", true); display.asyncExec(() -> { for (String arg : args) { open(arg); } }); launch(display); } /** * Open a specific file. */ public void open(String fullpath) { try { Disk disk = new Disk(fullpath); FormattedDisk[] formattedDisks = disk.getFormattedDisks(); DiskWindow window = new DiskWindow(shell, formattedDisks, imageManager); window.open(); } catch (DiskUnrecognizedException e) { showUnrecognizedDiskFormatMessage(fullpath); } catch (Exception ignored) { ignored.printStackTrace(); showUnexpectedErrorMessage(fullpath); } } /** * Launch SwtAppleCommander with a given display. * Primary motivation is getting S-Leak to work! */ public void launch(Display display) { imageManager = new ImageManager(display); SwtAppleCommander application = new SwtAppleCommander(); Shell shell = application.open(display); shell.forceActive(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } UserPreferences.getInstance().save(); } /** * Constructor for SwtAppleCommander. */ public SwtAppleCommander() { super(); } /** * Opens the main program. */ protected Shell open(Display display) { Display.setAppName(textBundle.get("SwtAppleCommander.AppleCommander")); //$NON-NLS-1$ // Find the system About menu on Mac OS X. // See https://www.eclipse.org/swt/R3_7/new_and_noteworthy.html#m6 if (display.getSystemMenu() != null) { for (MenuItem item : display.getSystemMenu().getItems()) { if (item.getID() == SWT.ID_ABOUT) { item.addSelectionListener(widgetSelectedAdapter(e -> showAboutAppleCommander())); } } } shell = new Shell(display, SWT.BORDER | SWT.CLOSE | SWT.MIN | SWT.TITLE); shell.setText(textBundle.get("SwtAppleCommander.AppleCommander")); //$NON-NLS-1$ shell.setImage(imageManager.get(ImageManager.ICON_DISK)); shell.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent event) { dispose(event); } }); GridLayout gridLayout = new GridLayout(); gridLayout.marginHeight = 5; gridLayout.marginWidth = 5; shell.setLayout(gridLayout); GridData gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.grabExcessHorizontalSpace = true; createToolBar(shell, gridData); gridData = new GridData(); Image logoImage = imageManager.get(ImageManager.LOGO_APPLECOMMANDER); gridData.widthHint = logoImage.getImageData().width; gridData.heightHint = logoImage.getImageData().height; imageCanvas = new ImageCanvas(shell, SWT.BORDER, logoImage, gridData); imageCanvas.addListener(SWT.KeyUp, this); imageCanvas.setFocus(); shell.pack(); shell.open(); return shell; } /** * Dispose of all shared resources. */ protected void dispose(DisposeEvent event) { imageCanvas.dispose(); toolBar.dispose(); imageManager.dispose(); if (System.getProperty("os.name").startsWith("Mac OS X")) { System.exit(0); } } /** * Open a file. */ protected void openFile() { FileDialog fileDialog = new FileDialog(shell, SWT.OPEN); FilenameFilter[] fileFilters = Disk.getFilenameFilters(); String[] names = new String[fileFilters.length]; String[] extensions = new String[fileFilters.length]; for (int i=0; i