2003-12-08 05:06:24 +00:00
|
|
|
/*
|
|
|
|
* AppleCommander - An Apple ][ image utility.
|
|
|
|
* Copyright (C) 2003 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;
|
|
|
|
|
2004-06-16 03:21:49 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2003-12-08 05:06:24 +00:00
|
|
|
|
|
|
|
import org.eclipse.swt.SWT;
|
|
|
|
import org.eclipse.swt.custom.ScrolledComposite;
|
|
|
|
import org.eclipse.swt.events.DisposeEvent;
|
|
|
|
import org.eclipse.swt.events.DisposeListener;
|
2003-12-10 04:49:29 +00:00
|
|
|
import org.eclipse.swt.events.SelectionAdapter;
|
|
|
|
import org.eclipse.swt.events.SelectionEvent;
|
2003-12-08 05:06:24 +00:00
|
|
|
import org.eclipse.swt.graphics.Color;
|
2003-12-10 07:08:24 +00:00
|
|
|
import org.eclipse.swt.graphics.Font;
|
2003-12-08 05:06:24 +00:00
|
|
|
import org.eclipse.swt.layout.FillLayout;
|
|
|
|
import org.eclipse.swt.layout.GridData;
|
|
|
|
import org.eclipse.swt.layout.GridLayout;
|
|
|
|
import org.eclipse.swt.widgets.Composite;
|
2003-12-10 07:08:24 +00:00
|
|
|
import org.eclipse.swt.widgets.Event;
|
|
|
|
import org.eclipse.swt.widgets.Listener;
|
2003-12-08 05:06:24 +00:00
|
|
|
import org.eclipse.swt.widgets.Shell;
|
2003-12-10 04:49:29 +00:00
|
|
|
import org.eclipse.swt.widgets.ToolBar;
|
|
|
|
import org.eclipse.swt.widgets.ToolItem;
|
2003-12-08 05:06:24 +00:00
|
|
|
|
2004-06-09 03:58:00 +00:00
|
|
|
import com.webcodepro.applecommander.storage.FileEntry;
|
|
|
|
import com.webcodepro.applecommander.storage.FileFilter;
|
|
|
|
import com.webcodepro.applecommander.storage.filters.AppleWorksDataBaseFileFilter;
|
|
|
|
import com.webcodepro.applecommander.storage.filters.AppleWorksSpreadSheetFileFilter;
|
|
|
|
import com.webcodepro.applecommander.storage.filters.AppleWorksWordProcessorFileFilter;
|
|
|
|
import com.webcodepro.applecommander.storage.filters.ApplesoftFileFilter;
|
2004-06-10 02:54:55 +00:00
|
|
|
import com.webcodepro.applecommander.storage.filters.AssemblySourceFileFilter;
|
2008-12-16 05:07:36 +00:00
|
|
|
import com.webcodepro.applecommander.storage.filters.BusinessBASICFileFilter;
|
2004-06-09 03:58:00 +00:00
|
|
|
import com.webcodepro.applecommander.storage.filters.GraphicsFileFilter;
|
|
|
|
import com.webcodepro.applecommander.storage.filters.IntegerBasicFileFilter;
|
2004-06-17 03:07:58 +00:00
|
|
|
import com.webcodepro.applecommander.storage.filters.PascalTextFileFilter;
|
2004-06-09 03:58:00 +00:00
|
|
|
import com.webcodepro.applecommander.storage.filters.TextFileFilter;
|
2008-12-26 20:36:47 +00:00
|
|
|
import com.webcodepro.applecommander.storage.filters.GutenbergFileFilter;
|
2004-07-11 15:07:56 +00:00
|
|
|
import com.webcodepro.applecommander.ui.UiBundle;
|
2004-06-16 03:21:49 +00:00
|
|
|
import com.webcodepro.applecommander.ui.swt.filteradapter.ApplesoftFilterAdapter;
|
2008-12-16 05:07:36 +00:00
|
|
|
import com.webcodepro.applecommander.ui.swt.filteradapter.BusinessBASICFilterAdapter;
|
2004-06-16 03:21:49 +00:00
|
|
|
import com.webcodepro.applecommander.ui.swt.filteradapter.FilterAdapter;
|
|
|
|
import com.webcodepro.applecommander.ui.swt.filteradapter.GraphicsFilterAdapter;
|
|
|
|
import com.webcodepro.applecommander.ui.swt.filteradapter.HexFilterAdapter;
|
|
|
|
import com.webcodepro.applecommander.ui.swt.filteradapter.RawDumpFilterAdapter;
|
|
|
|
import com.webcodepro.applecommander.ui.swt.filteradapter.TextFilterAdapter;
|
2004-06-09 03:58:00 +00:00
|
|
|
import com.webcodepro.applecommander.ui.swt.util.ImageManager;
|
2004-06-10 03:31:45 +00:00
|
|
|
import com.webcodepro.applecommander.ui.swt.util.SwtUtil;
|
2004-06-13 03:34:26 +00:00
|
|
|
import com.webcodepro.applecommander.ui.swt.util.contentadapter.ContentTypeAdapter;
|
2004-07-11 15:07:56 +00:00
|
|
|
import com.webcodepro.applecommander.util.TextBundle;
|
2004-06-09 03:58:00 +00:00
|
|
|
|
2003-12-08 05:06:24 +00:00
|
|
|
/**
|
|
|
|
* View a particular files content.
|
|
|
|
* <p>
|
|
|
|
* Date created: Dec 7, 2003
|
2004-06-18 05:15:33 +00:00
|
|
|
* @author Rob Greene
|
2003-12-08 05:06:24 +00:00
|
|
|
*/
|
|
|
|
public class FileViewerWindow {
|
2003-12-12 04:24:47 +00:00
|
|
|
private static final char CTRL_A = 'A' - '@';
|
2003-12-11 05:34:28 +00:00
|
|
|
private static final char CTRL_P = 'P' - '@';
|
|
|
|
private static final char CTRL_C = 'C' - '@';
|
2004-07-11 15:07:56 +00:00
|
|
|
|
|
|
|
private TextBundle textBundle = UiBundle.getInstance();
|
2003-12-11 05:34:28 +00:00
|
|
|
|
2003-12-08 05:06:24 +00:00
|
|
|
private Shell parentShell;
|
|
|
|
private ImageManager imageManager;
|
|
|
|
|
|
|
|
private Shell shell;
|
|
|
|
private FileEntry fileEntry;
|
2003-12-10 07:08:24 +00:00
|
|
|
private FileFilter nativeFilter;
|
2003-12-08 05:06:24 +00:00
|
|
|
|
|
|
|
private ScrolledComposite content;
|
2003-12-10 04:49:29 +00:00
|
|
|
private ToolBar toolBar;
|
2003-12-10 07:08:24 +00:00
|
|
|
private ToolItem nativeToolItem;
|
2003-12-10 04:49:29 +00:00
|
|
|
private ToolItem hexDumpToolItem;
|
2003-12-10 07:08:24 +00:00
|
|
|
private ToolItem rawDumpToolItem;
|
2003-12-11 05:34:28 +00:00
|
|
|
private ToolItem copyToolItem;
|
2003-12-10 07:08:24 +00:00
|
|
|
|
|
|
|
private Font courier;
|
|
|
|
private Color black;
|
|
|
|
private Color blue;
|
|
|
|
private Color green;
|
2004-06-13 03:34:26 +00:00
|
|
|
|
2004-06-16 03:21:49 +00:00
|
|
|
private ContentTypeAdapter contentTypeAdapter;
|
2017-11-09 21:03:03 +00:00
|
|
|
private Map<Class<?>,FilterAdapter> nativeFilterAdapterMap;
|
2004-06-16 03:21:49 +00:00
|
|
|
private FilterAdapter nativeFilterAdapter;
|
|
|
|
private FilterAdapter hexFilterAdapter;
|
|
|
|
private FilterAdapter rawDumpFilterAdapter;
|
|
|
|
|
2003-12-08 05:06:24 +00:00
|
|
|
/**
|
|
|
|
* Construct the file viewer window.
|
|
|
|
*/
|
|
|
|
public FileViewerWindow(Shell parentShell, FileEntry fileEntry, ImageManager imageManager) {
|
2004-06-16 03:21:49 +00:00
|
|
|
this(parentShell, fileEntry, imageManager, fileEntry.getSuggestedFilter());
|
2003-12-08 05:06:24 +00:00
|
|
|
}
|
2004-06-06 02:13:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the file viewer window.
|
|
|
|
*/
|
|
|
|
public FileViewerWindow(Shell parentShell, FileEntry fileEntry, ImageManager imageManager, FileFilter nativeFilter) {
|
|
|
|
this.parentShell = shell;
|
|
|
|
this.fileEntry = fileEntry;
|
|
|
|
this.imageManager = imageManager;
|
|
|
|
this.nativeFilter = nativeFilter;
|
2004-06-16 03:21:49 +00:00
|
|
|
|
|
|
|
createFilterAdapterMap();
|
2004-06-06 02:13:58 +00:00
|
|
|
}
|
2003-12-08 05:06:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the File Viewer window and display (open) it.
|
|
|
|
*/
|
|
|
|
public void open() {
|
|
|
|
shell = new Shell(parentShell, SWT.SHELL_TRIM);
|
|
|
|
shell.setLayout(new FillLayout());
|
2003-12-10 04:49:29 +00:00
|
|
|
shell.setImage(imageManager.get(ImageManager.ICON_DISK));
|
2004-07-11 15:07:56 +00:00
|
|
|
shell.setText(textBundle.format("FileViewerWindow.Title", //$NON-NLS-1$
|
|
|
|
fileEntry.getFilename()));
|
2003-12-08 05:06:24 +00:00
|
|
|
shell.addDisposeListener(new DisposeListener() {
|
|
|
|
public void widgetDisposed(DisposeEvent event) {
|
|
|
|
dispose(event);
|
|
|
|
}
|
|
|
|
});
|
2003-12-10 04:49:29 +00:00
|
|
|
|
|
|
|
Composite composite = new Composite(shell, SWT.NULL);
|
|
|
|
GridLayout gridLayout = new GridLayout(1, false);
|
|
|
|
composite.setLayout(gridLayout);
|
|
|
|
|
|
|
|
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
|
2004-06-16 03:21:49 +00:00
|
|
|
createToolBar(composite, gridData);
|
2003-12-10 04:49:29 +00:00
|
|
|
|
|
|
|
content = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
|
|
|
|
gridData = new GridData(GridData.FILL_BOTH);
|
|
|
|
content.setLayoutData(gridData);
|
2003-12-11 05:34:28 +00:00
|
|
|
content.addListener(SWT.KeyUp, createToolbarCommandHandler());
|
2003-12-08 05:06:24 +00:00
|
|
|
|
2004-07-11 15:07:56 +00:00
|
|
|
courier = new Font(shell.getDisplay(), "Courier", 10, SWT.NORMAL); //$NON-NLS-1$
|
2003-12-10 07:08:24 +00:00
|
|
|
black = new Color(shell.getDisplay(), 0, 0, 0);
|
|
|
|
blue = new Color(shell.getDisplay(), 0, 0, 192);
|
|
|
|
green = new Color(shell.getDisplay(), 0, 192, 0);
|
|
|
|
|
2004-06-16 03:21:49 +00:00
|
|
|
nativeFilterAdapter.display();
|
2003-12-08 05:06:24 +00:00
|
|
|
|
|
|
|
shell.open();
|
2004-06-10 03:31:45 +00:00
|
|
|
SwtUtil.setupPagingInformation(content);
|
2003-12-08 05:06:24 +00:00
|
|
|
}
|
2004-06-16 03:21:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup all possible specialized FilterAdapters.
|
|
|
|
*/
|
|
|
|
protected void createFilterAdapterMap() {
|
2017-11-09 21:03:03 +00:00
|
|
|
nativeFilterAdapterMap = new HashMap<>();
|
2004-06-16 03:21:49 +00:00
|
|
|
|
|
|
|
nativeFilterAdapterMap.put(ApplesoftFileFilter.class,
|
2004-07-11 15:07:56 +00:00
|
|
|
new ApplesoftFilterAdapter(this, textBundle.get("FileViewerWindow.ApplesoftButton"), //$NON-NLS-1$
|
|
|
|
textBundle.get("FileViewerWindow.ApplesoftTooltip"), //$NON-NLS-1$
|
2004-06-16 03:21:49 +00:00
|
|
|
imageManager.get(ImageManager.ICON_VIEW_AS_BASIC_PROGRAM)
|
|
|
|
));
|
2008-12-16 05:07:36 +00:00
|
|
|
nativeFilterAdapterMap.put(BusinessBASICFileFilter.class,
|
2008-12-16 05:27:17 +00:00
|
|
|
new BusinessBASICFilterAdapter(this, textBundle.get("FileViewerWindow.BusinessBASICButton"), //$NON-NLS-1$
|
|
|
|
textBundle.get("FileViewerWindow.BusinessBASICTooltip"), //$NON-NLS-1$
|
2008-12-16 05:07:36 +00:00
|
|
|
imageManager.get(ImageManager.ICON_VIEW_AS_BASIC_PROGRAM)
|
|
|
|
));
|
2004-06-16 03:21:49 +00:00
|
|
|
nativeFilterAdapterMap.put(AppleWorksDataBaseFileFilter.class,
|
2004-07-11 15:07:56 +00:00
|
|
|
new TextFilterAdapter(this, textBundle.get("FileViewerWindow.DatabaseButton"), //$NON-NLS-1$
|
|
|
|
textBundle.get("FileViewerWindow.DatabaseTooltip"), //$NON-NLS-1$
|
2004-06-16 03:21:49 +00:00
|
|
|
imageManager.get(ImageManager.ICON_VIEW_AS_DATABASE)
|
|
|
|
));
|
|
|
|
nativeFilterAdapterMap.put(AppleWorksSpreadSheetFileFilter.class,
|
2004-07-11 15:07:56 +00:00
|
|
|
new TextFilterAdapter(this, textBundle.get("FileViewerWindow.SpreadsheetButton"), //$NON-NLS-1$
|
|
|
|
textBundle.get("FileViewerWindow.SpreadsheetTooltip"), //$NON-NLS-1$
|
2004-06-16 03:21:49 +00:00
|
|
|
imageManager.get(ImageManager.ICON_VIEW_AS_SPREADSHEET)
|
|
|
|
));
|
|
|
|
nativeFilterAdapterMap.put(AppleWorksWordProcessorFileFilter.class,
|
2008-12-26 20:36:47 +00:00
|
|
|
new TextFilterAdapter(this, textBundle.get("FileViewerWindow.WordprocessorButton"), //$NON-NLS-1$
|
|
|
|
textBundle.get("FileViewerWindow.WordprocessorTooltip"), //$NON-NLS-1$
|
|
|
|
imageManager.get(ImageManager.ICON_VIEW_AS_WORDPROCESSOR)
|
|
|
|
));
|
|
|
|
nativeFilterAdapterMap.put(GutenbergFileFilter.class,
|
|
|
|
new TextFilterAdapter(this, textBundle.get("FileViewerWindow.WordprocessorButton"), //$NON-NLS-1$
|
|
|
|
textBundle.get("FileViewerWindow.WordprocessorTooltip"), //$NON-NLS-1$
|
|
|
|
imageManager.get(ImageManager.ICON_VIEW_AS_WORDPROCESSOR)
|
|
|
|
));
|
2004-06-16 03:21:49 +00:00
|
|
|
nativeFilterAdapterMap.put(AssemblySourceFileFilter.class,
|
2004-07-11 15:07:56 +00:00
|
|
|
new TextFilterAdapter(this, textBundle.get("FileViewerWindow.AssemblyButton"), //$NON-NLS-1$
|
|
|
|
textBundle.get("FileViewerWindow.AssemblyTooltip"), //$NON-NLS-1$
|
2004-06-16 03:21:49 +00:00
|
|
|
imageManager.get(ImageManager.ICON_VIEW_AS_TEXTFILE)
|
|
|
|
));
|
|
|
|
nativeFilterAdapterMap.put(GraphicsFileFilter.class,
|
2004-07-11 15:07:56 +00:00
|
|
|
new GraphicsFilterAdapter(this, textBundle.get("FileViewerWindow.ImageButton"), //$NON-NLS-1$
|
|
|
|
textBundle.get("FileViewerWindow.ImageTooltip"), //$NON-NLS-1$
|
2004-06-16 03:21:49 +00:00
|
|
|
imageManager.get(ImageManager.ICON_VIEW_AS_IMAGE)
|
|
|
|
));
|
|
|
|
nativeFilterAdapterMap.put(IntegerBasicFileFilter.class,
|
2004-07-11 15:07:56 +00:00
|
|
|
new TextFilterAdapter(this, textBundle.get("FileViewerWindow.IntegerBasicButton"), //$NON-NLS-1$
|
|
|
|
textBundle.get("FileViewerWindow.IntegerBasicTooltip"), //$NON-NLS-1$
|
2004-06-16 03:21:49 +00:00
|
|
|
imageManager.get(ImageManager.ICON_VIEW_AS_BASIC_PROGRAM)
|
|
|
|
));
|
2004-06-17 03:07:58 +00:00
|
|
|
nativeFilterAdapterMap.put(PascalTextFileFilter.class,
|
2004-07-11 15:07:56 +00:00
|
|
|
new TextFilterAdapter(this, textBundle.get("FileViewerWindow.PascalTextButton"), //$NON-NLS-1$
|
|
|
|
textBundle.get("FileViewerWindow.PascalTextTooltip"), //$NON-NLS-1$
|
2004-06-17 03:07:58 +00:00
|
|
|
imageManager.get(ImageManager.ICON_VIEW_AS_TEXTFILE)
|
|
|
|
));
|
2004-06-16 03:21:49 +00:00
|
|
|
nativeFilterAdapterMap.put(TextFileFilter.class,
|
2004-07-11 15:07:56 +00:00
|
|
|
new TextFilterAdapter(this, textBundle.get("FileViewerWindow.TextButton"), //$NON-NLS-1$
|
|
|
|
textBundle.get("FileViewerWindow.TextTooltip"), //$NON-NLS-1$
|
2004-06-16 03:21:49 +00:00
|
|
|
imageManager.get(ImageManager.ICON_VIEW_AS_TEXTFILE)
|
|
|
|
));
|
|
|
|
}
|
2003-12-08 05:06:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispose of all shared resources.
|
|
|
|
*/
|
2004-07-11 15:07:56 +00:00
|
|
|
protected void dispose(DisposeEvent event) {
|
2003-12-10 07:08:24 +00:00
|
|
|
courier.dispose();
|
|
|
|
black.dispose();
|
|
|
|
blue.dispose();
|
|
|
|
green.dispose();
|
2004-06-19 21:17:18 +00:00
|
|
|
if (nativeFilterAdapter != null) nativeFilterAdapter.dispose();
|
|
|
|
hexFilterAdapter.dispose();
|
|
|
|
rawDumpFilterAdapter.dispose();
|
2003-12-08 05:06:24 +00:00
|
|
|
System.gc();
|
|
|
|
}
|
2003-12-10 04:49:29 +00:00
|
|
|
|
|
|
|
/**
|
2004-06-16 03:21:49 +00:00
|
|
|
* Creates the toolbar.
|
2003-12-10 04:49:29 +00:00
|
|
|
*/
|
2004-06-16 03:21:49 +00:00
|
|
|
private void createToolBar(Composite composite, Object layoutData) {
|
2003-12-10 04:49:29 +00:00
|
|
|
toolBar = new ToolBar(composite, SWT.FLAT);
|
2003-12-10 07:08:24 +00:00
|
|
|
toolBar.addListener(SWT.KeyUp, createToolbarCommandHandler());
|
2003-12-10 04:49:29 +00:00
|
|
|
if (layoutData != null) toolBar.setLayoutData(layoutData);
|
2003-12-11 05:34:28 +00:00
|
|
|
|
2004-06-16 03:21:49 +00:00
|
|
|
if (nativeFilter != null) {
|
|
|
|
nativeFilterAdapter = (FilterAdapter) nativeFilterAdapterMap.get(nativeFilter.getClass());
|
|
|
|
if (nativeFilterAdapter != null) {
|
|
|
|
nativeToolItem = nativeFilterAdapter.create(toolBar);
|
|
|
|
nativeToolItem.setSelection(true);
|
|
|
|
}
|
2004-06-13 03:34:26 +00:00
|
|
|
}
|
2004-06-16 03:21:49 +00:00
|
|
|
hexDumpToolItem = createHexDumpToolItem();
|
|
|
|
if (nativeFilterAdapter == null) {
|
|
|
|
// Default button changes for these instances.
|
|
|
|
hexDumpToolItem.setSelection(true);
|
|
|
|
// Prevent NullPointerExceptions if the nativeFilterAdapter does not apply.
|
|
|
|
nativeFilterAdapter = hexFilterAdapter;
|
2003-12-10 07:08:24 +00:00
|
|
|
}
|
2004-06-16 03:21:49 +00:00
|
|
|
rawDumpToolItem = createRawDumpToolItem();
|
2003-12-10 04:49:29 +00:00
|
|
|
new ToolItem(toolBar, SWT.SEPARATOR);
|
2004-06-16 03:21:49 +00:00
|
|
|
copyToolItem = createCopyToolItem();
|
2003-12-10 04:49:29 +00:00
|
|
|
new ToolItem(toolBar, SWT.SEPARATOR);
|
2004-07-11 15:07:56 +00:00
|
|
|
createPrintToolItem();
|
2003-12-10 04:49:29 +00:00
|
|
|
toolBar.pack();
|
|
|
|
}
|
2003-12-12 04:24:47 +00:00
|
|
|
|
|
|
|
/**
|
2004-06-16 03:21:49 +00:00
|
|
|
* Create the hex dump tool item (button).
|
2003-12-12 04:24:47 +00:00
|
|
|
*/
|
2004-06-16 03:21:49 +00:00
|
|
|
protected ToolItem createHexDumpToolItem() {
|
2004-07-11 15:07:56 +00:00
|
|
|
hexFilterAdapter = new HexFilterAdapter(this, textBundle.get("FileViewerWindow.HexDumpButton"), //$NON-NLS-1$
|
|
|
|
textBundle.get("FileViewerWindow.HexDumpTooltip"), //$NON-NLS-1$
|
2004-06-16 03:21:49 +00:00
|
|
|
imageManager.get(ImageManager.ICON_VIEW_IN_HEX));
|
|
|
|
hexFilterAdapter.setHexSelected();
|
|
|
|
ToolItem toolItem = hexFilterAdapter.create(toolBar);
|
|
|
|
return toolItem;
|
2003-12-12 04:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-06-16 03:21:49 +00:00
|
|
|
* Create the raw dump tool item (button).
|
2003-12-12 04:24:47 +00:00
|
|
|
*/
|
2004-06-16 03:21:49 +00:00
|
|
|
protected ToolItem createRawDumpToolItem() {
|
2004-07-11 15:07:56 +00:00
|
|
|
rawDumpFilterAdapter = new RawDumpFilterAdapter(this, textBundle.get("FileViewerWindow.RawDumpButton"), //$NON-NLS-1$
|
|
|
|
textBundle.get("FileViewerWindow.RawDumpTooltip"), //$NON-NLS-1$
|
2004-06-16 03:21:49 +00:00
|
|
|
imageManager.get(ImageManager.ICON_VIEW_IN_RAW_HEX));
|
|
|
|
rawDumpFilterAdapter.setDumpSelected();
|
|
|
|
ToolItem toolItem = rawDumpFilterAdapter.create(toolBar);
|
|
|
|
return toolItem;
|
2003-12-11 05:34:28 +00:00
|
|
|
}
|
2003-12-12 04:24:47 +00:00
|
|
|
|
|
|
|
/**
|
2004-06-16 03:21:49 +00:00
|
|
|
* Create the copy tool item (button).
|
2003-12-12 04:24:47 +00:00
|
|
|
*/
|
2004-06-16 03:21:49 +00:00
|
|
|
protected ToolItem createCopyToolItem() {
|
|
|
|
ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH);
|
|
|
|
toolItem.setImage(imageManager.get(ImageManager.ICON_COPY));
|
2004-07-11 15:07:56 +00:00
|
|
|
toolItem.setText(textBundle.get("FileViewerWindow.CopyButton")); //$NON-NLS-1$
|
|
|
|
toolItem.setToolTipText(textBundle.get("FileViewerWindow.CopyTooltip")); //$NON-NLS-1$
|
2004-06-16 03:21:49 +00:00
|
|
|
toolItem.setEnabled(true);
|
|
|
|
toolItem.addSelectionListener(new SelectionAdapter() {
|
|
|
|
public void widgetSelected(SelectionEvent e) {
|
2004-07-11 15:07:56 +00:00
|
|
|
getContentTypeAdapter().copy();
|
2003-12-10 07:08:24 +00:00
|
|
|
}
|
2004-06-16 03:21:49 +00:00
|
|
|
});
|
|
|
|
return toolItem;
|
2003-12-10 07:08:24 +00:00
|
|
|
}
|
2003-12-12 04:24:47 +00:00
|
|
|
|
|
|
|
/**
|
2004-06-16 03:21:49 +00:00
|
|
|
* Create the print tool item (button).
|
2003-12-12 04:24:47 +00:00
|
|
|
*/
|
2004-06-16 03:21:49 +00:00
|
|
|
protected ToolItem createPrintToolItem() {
|
|
|
|
ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH);
|
|
|
|
toolItem.setImage(imageManager.get(ImageManager.ICON_PRINT_FILE));
|
2004-07-11 15:07:56 +00:00
|
|
|
toolItem.setText(textBundle.get("PrintButton")); //$NON-NLS-1$
|
|
|
|
toolItem.setToolTipText(textBundle.get("FileViewerWindow.PrintTooltip")); //$NON-NLS-1$
|
2004-06-16 03:21:49 +00:00
|
|
|
toolItem.setEnabled(true);
|
|
|
|
toolItem.addSelectionListener(new SelectionAdapter () {
|
|
|
|
public void widgetSelected(SelectionEvent e) {
|
2004-07-11 15:07:56 +00:00
|
|
|
getContentTypeAdapter().print();
|
2004-06-16 03:21:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return toolItem;
|
2003-12-10 07:08:24 +00:00
|
|
|
}
|
2003-12-12 04:24:47 +00:00
|
|
|
|
2003-12-10 07:08:24 +00:00
|
|
|
/**
|
|
|
|
* The toolbar command handler contains the global toolbar
|
|
|
|
* actions. The intent is that the listener is then added to
|
|
|
|
* multiple visual components.
|
|
|
|
*/
|
2004-06-16 03:21:49 +00:00
|
|
|
public Listener createToolbarCommandHandler() {
|
2003-12-10 07:08:24 +00:00
|
|
|
return new Listener() {
|
|
|
|
public void handleEvent(Event event) {
|
|
|
|
if (event.type == SWT.KeyUp) {
|
2003-12-12 04:24:47 +00:00
|
|
|
if ((event.stateMask & SWT.CTRL) != 0) { // CTRL+key
|
|
|
|
switch (event.character) {
|
2003-12-11 05:34:28 +00:00
|
|
|
case CTRL_C:
|
2004-07-11 15:07:56 +00:00
|
|
|
getContentTypeAdapter().copy();
|
2003-12-11 05:34:28 +00:00
|
|
|
break;
|
2003-12-12 04:24:47 +00:00
|
|
|
case CTRL_A:
|
2004-07-11 15:07:56 +00:00
|
|
|
getContentTypeAdapter().selectAll();
|
2003-12-12 04:24:47 +00:00
|
|
|
break;
|
2003-12-11 05:34:28 +00:00
|
|
|
case CTRL_P:
|
2004-07-11 15:07:56 +00:00
|
|
|
getContentTypeAdapter().print();
|
2003-12-11 05:34:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-12-12 04:24:47 +00:00
|
|
|
} else if ((event.stateMask & SWT.ALT) == 0) { // key alone
|
2003-12-11 05:34:28 +00:00
|
|
|
switch (event.keyCode) {
|
|
|
|
case SWT.F2: // the "native" file format (image, text, etc)
|
2004-07-11 15:07:56 +00:00
|
|
|
getNativeFilterAdapter().display();
|
2004-06-16 03:21:49 +00:00
|
|
|
setFilterToolItemSelection(true, false, false);
|
2003-12-11 05:34:28 +00:00
|
|
|
break;
|
|
|
|
case SWT.F3: // Hex format
|
2004-07-11 15:07:56 +00:00
|
|
|
getHexFilterAdapter().display();
|
2004-06-16 03:21:49 +00:00
|
|
|
setFilterToolItemSelection(false, true, false);
|
2003-12-11 05:34:28 +00:00
|
|
|
break;
|
|
|
|
case SWT.F4: // "Raw" hex format
|
2004-07-11 15:07:56 +00:00
|
|
|
getRawDumpFilterAdapter().display();
|
2004-06-16 03:21:49 +00:00
|
|
|
setFilterToolItemSelection(false, false, true);
|
2003-12-11 05:34:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-12-10 07:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2004-06-16 03:21:49 +00:00
|
|
|
|
|
|
|
public FileFilter getFileFilter() {
|
|
|
|
return nativeFilter;
|
|
|
|
}
|
|
|
|
public FileEntry getFileEntry() {
|
|
|
|
return fileEntry;
|
|
|
|
}
|
|
|
|
public ToolItem getCopyToolItem() {
|
|
|
|
return copyToolItem;
|
|
|
|
}
|
|
|
|
public ScrolledComposite getComposite() {
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
public void setContentTypeAdapter(ContentTypeAdapter adapter) {
|
|
|
|
this.contentTypeAdapter = adapter;
|
|
|
|
}
|
|
|
|
public Font getCourierFont() {
|
|
|
|
return courier;
|
|
|
|
}
|
|
|
|
public Color getBlackColor() {
|
|
|
|
return black;
|
|
|
|
}
|
|
|
|
public Color getGreenColor() {
|
|
|
|
return green;
|
|
|
|
}
|
|
|
|
public Color getBlueColor() {
|
|
|
|
return blue;
|
|
|
|
}
|
|
|
|
public void setFilterToolItemSelection(boolean nativeSelected, boolean hexSelected, boolean dumpSelected) {
|
|
|
|
if (nativeToolItem != null) nativeToolItem.setSelection(nativeSelected);
|
|
|
|
hexDumpToolItem.setSelection(hexSelected);
|
|
|
|
rawDumpToolItem.setSelection(dumpSelected);
|
|
|
|
}
|
2004-07-11 15:07:56 +00:00
|
|
|
protected ContentTypeAdapter getContentTypeAdapter() {
|
|
|
|
return contentTypeAdapter;
|
|
|
|
}
|
|
|
|
protected FilterAdapter getHexFilterAdapter() {
|
|
|
|
return hexFilterAdapter;
|
|
|
|
}
|
|
|
|
protected FilterAdapter getNativeFilterAdapter() {
|
|
|
|
return nativeFilterAdapter;
|
|
|
|
}
|
|
|
|
protected FilterAdapter getRawDumpFilterAdapter() {
|
|
|
|
return rawDumpFilterAdapter;
|
|
|
|
}
|
2003-12-08 05:06:24 +00:00
|
|
|
}
|