mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2024-12-22 23:29:34 +00:00
Added early toolbar setup. Also updated due to ImageManager
changes.
This commit is contained in:
parent
72fce3b275
commit
b4e4758fcf
@ -21,6 +21,7 @@ package com.webcodepro.applecommander.ui.swt;
|
||||
|
||||
import com.webcodepro.applecommander.storage.FileEntry;
|
||||
import com.webcodepro.applecommander.storage.FileFilter;
|
||||
import com.webcodepro.applecommander.storage.FormattedDisk;
|
||||
import com.webcodepro.applecommander.storage.GraphicsFileFilter;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@ -29,6 +30,8 @@ import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.ScrolledComposite;
|
||||
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.Color;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.ImageData;
|
||||
@ -38,8 +41,9 @@ import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.ToolBar;
|
||||
import org.eclipse.swt.widgets.ToolItem;
|
||||
|
||||
/**
|
||||
* View a particular files content.
|
||||
@ -55,6 +59,10 @@ public class FileViewerWindow {
|
||||
private FileEntry fileEntry;
|
||||
|
||||
private ScrolledComposite content;
|
||||
private ToolBar toolBar;
|
||||
private ToolItem imageToolItem;
|
||||
private ToolItem hexDumpToolItem;
|
||||
private ToolItem printToolItem;
|
||||
|
||||
/**
|
||||
* Construct the file viewer window.
|
||||
@ -71,29 +79,37 @@ public class FileViewerWindow {
|
||||
public void open() {
|
||||
shell = new Shell(parentShell, SWT.SHELL_TRIM);
|
||||
shell.setLayout(new FillLayout());
|
||||
shell.setImage(imageManager.getDiskIcon());
|
||||
shell.setImage(imageManager.get(ImageManager.ICON_DISK));
|
||||
shell.setText("File Viewer - " + fileEntry.getFilename());
|
||||
shell.addDisposeListener(new DisposeListener() {
|
||||
public void widgetDisposed(DisposeEvent event) {
|
||||
dispose(event);
|
||||
}
|
||||
});
|
||||
|
||||
content = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
|
||||
|
||||
Composite composite = new Composite(shell, SWT.NULL);
|
||||
GridLayout gridLayout = new GridLayout(1, false);
|
||||
composite.setLayout(gridLayout);
|
||||
|
||||
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
|
||||
createFileToolBar(composite, gridData);
|
||||
|
||||
content = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
|
||||
gridData = new GridData(GridData.FILL_BOTH);
|
||||
content.setLayoutData(gridData);
|
||||
|
||||
FileFilter filter = fileEntry.getSuggestedFilter();
|
||||
Color red = new Color(shell.getDisplay(), 255, 0, 0);
|
||||
if (filter instanceof GraphicsFileFilter) {
|
||||
byte[] imageBytes = filter.filter(fileEntry);
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(imageBytes);
|
||||
// final Image image = new Image(shell.getDisplay(), inputStream);
|
||||
ImageLoader imageLoader = new ImageLoader();
|
||||
ImageData[] imageData = imageLoader.load(inputStream);
|
||||
final Image image = new Image(shell.getDisplay(), imageData[0]);
|
||||
|
||||
GridLayout layout = new GridLayout();
|
||||
content.setLayout(layout);
|
||||
GridData gridData = new GridData();
|
||||
gridData = new GridData();
|
||||
gridData.widthHint = imageData[0].width;
|
||||
gridData.heightHint = imageData[0].height;
|
||||
ImageCanvas imageCanvas = new ImageCanvas(content, SWT.NONE, image, gridData);
|
||||
@ -141,4 +157,57 @@ public class FileViewerWindow {
|
||||
private void dispose(DisposeEvent event) {
|
||||
System.gc();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the FILE tab toolbar.
|
||||
*/
|
||||
private void createFileToolBar(Composite composite, Object layoutData) {
|
||||
toolBar = new ToolBar(composite, SWT.FLAT);
|
||||
// toolBar.addListener(SWT.KeyUp, createToolbarCommandHandler());
|
||||
if (layoutData != null) toolBar.setLayoutData(layoutData);
|
||||
|
||||
imageToolItem = new ToolItem(toolBar, SWT.RADIO);
|
||||
imageToolItem.setImage(imageManager.get(ImageManager.ICON_VIEW_AS_IMAGE));
|
||||
imageToolItem.setText("Image");
|
||||
imageToolItem.setToolTipText("Displays file as an image");
|
||||
imageToolItem.setSelection(true);
|
||||
imageToolItem.addSelectionListener(new SelectionAdapter () {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
//changeCurrentFormat(FormattedDisk.FILE_DISPLAY_STANDARD);
|
||||
}
|
||||
});
|
||||
|
||||
hexDumpToolItem = new ToolItem(toolBar, SWT.RADIO);
|
||||
hexDumpToolItem.setImage(imageManager.get(ImageManager.ICON_VIEW_IN_HEX));
|
||||
hexDumpToolItem.setText("Hex Dump");
|
||||
hexDumpToolItem.setToolTipText("Displays file as a hex dump");
|
||||
hexDumpToolItem.setSelection(false);
|
||||
hexDumpToolItem.addSelectionListener(new SelectionAdapter () {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
//changeCurrentFormat(FormattedDisk.FILE_DISPLAY_STANDARD);
|
||||
}
|
||||
});
|
||||
|
||||
new ToolItem(toolBar, SWT.SEPARATOR);
|
||||
|
||||
ToolItem copy = new ToolItem(toolBar, SWT.PUSH);
|
||||
copy.setText("Copy");
|
||||
copy.setText("Copies selection to the clipboard");
|
||||
copy.setEnabled(false);
|
||||
|
||||
new ToolItem(toolBar, SWT.SEPARATOR);
|
||||
|
||||
printToolItem = new ToolItem(toolBar, SWT.PUSH);
|
||||
printToolItem.setImage(imageManager.get(ImageManager.ICON_PRINT_FILE));
|
||||
printToolItem.setText("Print");
|
||||
printToolItem.setToolTipText("Print contents...");
|
||||
printToolItem.setEnabled(true);
|
||||
printToolItem.addSelectionListener(new SelectionAdapter () {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
//saveAs();
|
||||
}
|
||||
});
|
||||
|
||||
toolBar.pack();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user