use of org.eclipse.swt.events.KeyAdapter in project bndtools by bndtools.
the class RepositoryBundleSelectionPart method createSection.
void createSection(Section section, FormToolkit toolkit) {
// Toolbar buttons
ToolBar toolbar = new ToolBar(section, SWT.FLAT);
section.setTextClient(toolbar);
fillToolBar(toolbar);
Composite composite = toolkit.createComposite(section);
section.setClient(composite);
table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL);
viewer = new TableViewer(table);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(getLabelProvider());
// Listeners
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ToolItem remove = getRemoveItemTool();
if (remove != null)
remove.setEnabled(isRemovable(event.getSelection()));
}
});
ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
event.detail = DND.DROP_COPY;
}
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
if (FileTransfer.getInstance().isSupportedType(transferType))
return true;
if (ResourceTransfer.getInstance().isSupportedType(transferType))
return true;
if (URLTransfer.getInstance().isSupportedType(transferType))
return true;
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
return false;
}
Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
while (iterator.hasNext()) {
if (!selectionIsDroppable(iterator.next())) {
return false;
}
}
return true;
}
private boolean selectionIsDroppable(Object element) {
return element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion || element instanceof ProjectBundle || element instanceof RepositoryResourceElement;
}
@Override
public boolean performDrop(Object data) {
TransferData transfer = getCurrentEvent().currentDataType;
if (URLTransfer.getInstance().isSupportedType(transfer)) {
String urlStr = (String) URLTransfer.getInstance().nativeToJava(transfer);
return handleURLDrop(urlStr);
} else if (data instanceof String[]) {
return handleFileNameDrop((String[]) data);
} else if (data instanceof IResource[]) {
return handleResourceDrop((IResource[]) data);
} else {
return handleSelectionDrop();
}
}
private boolean handleResourceDrop(IResource[] resources) {
File[] files = new File[resources.length];
for (int i = 0; i < resources.length; i++) {
files[i] = resources[i].getLocation().toFile();
}
return handleFileDrop(files);
}
private boolean handleFileNameDrop(String[] paths) {
File[] files = new File[paths.length];
for (int i = 0; i < paths.length; i++) {
files[i] = new File(paths[i]);
}
return handleFileDrop(files);
}
private boolean handleFileDrop(File[] files) {
if (files.length > 0) {
BndPreferences prefs = new BndPreferences();
boolean hideWarning = prefs.getHideWarningExternalFile();
if (!hideWarning) {
MessageDialogWithToggle dialog = MessageDialogWithToggle.openWarning(getSection().getShell(), "Add External Files", "External files cannot be directly added to a project, they must be added to a local repository first.", "Do not show this warning again.", false, null, null);
if (Window.CANCEL == dialog.getReturnCode())
return false;
if (dialog.getToggleState()) {
prefs.setHideWarningExternalFile(true);
}
}
AddFilesToRepositoryWizard wizard = new AddFilesToRepositoryWizard(null, files);
WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
if (Window.OK == dialog.open()) {
List<Pair<String, String>> addingBundles = wizard.getSelectedBundles();
List<VersionedClause> addingClauses = new ArrayList<VersionedClause>(addingBundles.size());
for (Pair<String, String> addingBundle : addingBundles) {
Attrs attribs = new Attrs();
attribs.put(Constants.VERSION_ATTRIBUTE, addingBundle.getSecond());
addingClauses.add(new VersionedClause(addingBundle.getFirst(), attribs));
}
handleAdd(addingClauses);
}
return true;
}
return false;
}
private boolean handleSelectionDrop() {
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
return false;
}
List<VersionedClause> adding = new LinkedList<VersionedClause>();
Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
while (iterator.hasNext()) {
Object item = iterator.next();
if (item instanceof RepositoryBundle) {
VersionedClause newClause = RepositoryBundleUtils.convertRepoBundle((RepositoryBundle) item);
adding.add(newClause);
} else if (item instanceof RepositoryBundleVersion) {
RepositoryBundleVersion bundleVersion = (RepositoryBundleVersion) item;
VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(bundleVersion, phase);
adding.add(newClause);
} else if (item instanceof RepositoryResourceElement) {
RepositoryResourceElement elt = (RepositoryResourceElement) item;
VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(elt.getRepositoryBundleVersion(), phase);
adding.add(newClause);
}
}
handleAdd(adding);
return true;
}
private boolean handleURLDrop(String urlStr) {
try {
URI uri = new URI(sanitizeUrl(urlStr));
AddJpmDependenciesWizard wizard = new AddJpmDependenciesWizard(uri);
WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
if (dialog.open() == Window.OK) {
Set<ResourceDescriptor> resources = wizard.getResult();
List<VersionedClause> newBundles = new ArrayList<VersionedClause>(resources.size());
for (ResourceDescriptor resource : resources) {
Attrs attrs = new Attrs();
attrs.put(Constants.VERSION_ATTRIBUTE, resource.version != null ? resource.version.toString() : Version.emptyVersion.toString());
VersionedClause clause = new VersionedClause(resource.bsn, attrs);
newBundles.add(clause);
}
handleAdd(newBundles);
return true;
}
return false;
} catch (URISyntaxException e) {
MessageDialog.openError(getSection().getShell(), "Error", "The dropped URL was invalid: " + urlStr);
return false;
}
}
private String sanitizeUrl(String urlStr) {
int newline = urlStr.indexOf('\n');
if (newline > -1)
return urlStr.substring(0, newline).trim();
return urlStr;
}
private void handleAdd(Collection<VersionedClause> newClauses) {
if (newClauses == null || newClauses.isEmpty())
return;
List<VersionedClause> toAdd = new LinkedList<VersionedClause>();
for (VersionedClause newClause : newClauses) {
boolean found = false;
for (ListIterator<VersionedClause> iter = bundles.listIterator(); iter.hasNext(); ) {
VersionedClause existing = iter.next();
if (newClause.getName().equals(existing.getName())) {
int index = iter.previousIndex();
iter.set(newClause);
viewer.replace(newClause, index);
found = true;
break;
}
}
if (!found)
toAdd.add(newClause);
}
bundles.addAll(toAdd);
viewer.add(toAdd.toArray());
markDirty();
}
};
dropAdapter.setFeedbackEnabled(false);
dropAdapter.setExpandEnabled(false);
viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), URLTransfer.getInstance() }, dropAdapter);
table.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.character == SWT.DEL) {
doRemove();
} else if (e.character == '+') {
doAdd();
}
}
});
// Layout
GridLayout layout = new GridLayout(1, false);
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.widthHint = 50;
gd.heightHint = getTableHeightHint();
table.setLayoutData(gd);
}
use of org.eclipse.swt.events.KeyAdapter in project bndtools by bndtools.
the class RunBlacklistPart method createSection.
private void createSection(Section section, FormToolkit tk) {
section.setText("Run Blacklist");
section.setDescription("The specified requirements will be excluded from the resolution.");
// Create toolbar
ToolBar toolbar = new ToolBar(section, SWT.FLAT);
section.setTextClient(toolbar);
fillToolBar(toolbar);
// Create main panel
Composite composite = tk.createComposite(section);
section.setClient(composite);
table = tk.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
viewer = new TableViewer(table);
viewer.setContentProvider(ArrayContentProvider.getInstance());
viewer.setLabelProvider(new RequirementLabelProvider());
// Listeners
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
removeTool.setEnabled(!viewer.getSelection().isEmpty());
}
});
table.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.character == SWT.DEL) {
doRemove();
} else if (e.character == '+') {
doAddBundle();
}
}
});
RequirementViewerDropAdapter dropper = new RequirementViewerDropAdapter();
dropper.install(viewer);
// Layout
GridLayout layout;
GridData gd;
layout = new GridLayout(2, false);
layout.horizontalSpacing = 0;
layout.verticalSpacing = 5;
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
gd.widthHint = 50;
gd.heightHint = 50;
table.setLayoutData(gd);
gd = new GridData(SWT.RIGHT, SWT.CENTER, true, false);
}
use of org.eclipse.swt.events.KeyAdapter in project eclipse.platform.text by eclipse.
the class SearchResultViewer method fillToolBar.
void fillToolBar(IToolBarManager tbm) {
tbm.add(fShowNextResultAction);
tbm.add(fShowPreviousResultAction);
// tbm.add(fGotoMarkerAction); see bug 15275
tbm.add(fRemoveSelectedMatchesAction);
tbm.add(fRemoveAllResultsAction);
tbm.add(new Separator());
tbm.add(new OpenSearchDialogAction());
tbm.add(fSearchDropDownAction);
// need to hook F5 to table
getTable().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.keyCode == SWT.F5) {
fSearchAgainAction.run();
// performance
return;
}
if (e.character == SWT.DEL) {
new RemoveResultAction(SearchResultViewer.this, true).run();
// performance
return;
}
}
});
}
use of org.eclipse.swt.events.KeyAdapter in project bndtools by bndtools.
the class PluginPathPart method createClient.
/**
* Fill the section.
*/
private void createClient(Section section, FormToolkit toolkit) {
section.setText("Plugin Path");
createToolBar(section);
Table table = new Table(section, SWT.BORDER | SWT.FULL_SELECTION);
toolkit.adapt(table);
toolkit.paintBordersFor(table);
section.setClient(table);
viewer = new TableViewer(table);
viewer.setContentProvider(ArrayContentProvider.getInstance());
viewer.setLabelProvider(new PluginPathLabelProvider());
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
boolean enable = !viewer.getSelection().isEmpty();
removeItem.setEnabled(enable);
}
});
table.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.character == SWT.DEL) {
doRemove();
} else if (e.character == '+') {
doAdd();
}
}
});
}
use of org.eclipse.swt.events.KeyAdapter in project eclipse.platform.swt by eclipse.
the class ImageAnalyzer method createWidgets.
void createWidgets() {
// Add the widgets to the shell in a grid layout.
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.numColumns = 2;
shell.setLayout(layout);
// Add a composite to contain some control widgets across the top.
Composite controls = new Composite(shell, SWT.NONE);
RowLayout rowLayout = new RowLayout();
rowLayout.marginTop = 5;
rowLayout.marginBottom = 5;
rowLayout.spacing = 8;
controls.setLayout(rowLayout);
GridData gridData = new GridData();
gridData.horizontalSpan = 2;
controls.setLayoutData(gridData);
// Combo to change the background.
Group group = new Group(controls, SWT.NONE);
group.setLayout(new RowLayout());
group.setText(bundle.getString("Background"));
backgroundCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
backgroundCombo.setItems(bundle.getString("None"), bundle.getString("White"), bundle.getString("Black"), bundle.getString("Red"), bundle.getString("Green"), bundle.getString("Blue"));
backgroundCombo.select(backgroundCombo.indexOf(bundle.getString("White")));
backgroundCombo.addSelectionListener(widgetSelectedAdapter(event -> changeBackground()));
// Combo to change the compression ratio.
group = new Group(controls, SWT.NONE);
group.setLayout(new GridLayout(3, true));
group.setText(bundle.getString("Save_group"));
imageTypeCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
String[] types = { "JPEG", "PNG", "GIF", "ICO", "TIFF", "BMP" };
for (String type : types) {
imageTypeCombo.add(type);
}
imageTypeCombo.select(imageTypeCombo.indexOf("JPEG"));
imageTypeCombo.addSelectionListener(widgetSelectedAdapter(event -> {
int index = imageTypeCombo.getSelectionIndex();
switch(index) {
case 0:
compressionCombo.setEnabled(true);
compressionRatioLabel.setEnabled(true);
if (compressionCombo.getItemCount() == 100)
break;
compressionCombo.removeAll();
for (int i = 0; i < 100; i++) {
compressionCombo.add(String.valueOf(i + 1));
}
compressionCombo.select(compressionCombo.indexOf("75"));
break;
case 1:
compressionCombo.setEnabled(true);
compressionRatioLabel.setEnabled(true);
if (compressionCombo.getItemCount() == 10)
break;
compressionCombo.removeAll();
for (int i = 0; i < 4; i++) {
compressionCombo.add(String.valueOf(i));
}
compressionCombo.select(0);
break;
case 2:
case 3:
case 4:
case 5:
compressionCombo.setEnabled(false);
compressionRatioLabel.setEnabled(false);
break;
}
}));
imageTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
compressionRatioLabel = new Label(group, SWT.NONE);
compressionRatioLabel.setText(bundle.getString("Compression"));
compressionRatioLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
compressionCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
for (int i = 0; i < 100; i++) {
compressionCombo.add(String.valueOf(i + 1));
}
compressionCombo.select(compressionCombo.indexOf("75"));
compressionCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
// Combo to change the x scale.
String[] values = { "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9", "1", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
group = new Group(controls, SWT.NONE);
group.setLayout(new RowLayout());
group.setText(bundle.getString("X_scale"));
scaleXCombo = new Combo(group, SWT.DROP_DOWN);
for (String value : values) {
scaleXCombo.add(value);
}
scaleXCombo.select(scaleXCombo.indexOf("1"));
scaleXCombo.addSelectionListener(widgetSelectedAdapter(event -> scaleX()));
// Combo to change the y scale.
group = new Group(controls, SWT.NONE);
group.setLayout(new RowLayout());
group.setText(bundle.getString("Y_scale"));
scaleYCombo = new Combo(group, SWT.DROP_DOWN);
for (String value : values) {
scaleYCombo.add(value);
}
scaleYCombo.select(scaleYCombo.indexOf("1"));
scaleYCombo.addSelectionListener(widgetSelectedAdapter(event -> scaleY()));
// Combo to change the alpha value.
group = new Group(controls, SWT.NONE);
group.setLayout(new RowLayout());
group.setText(bundle.getString("Alpha_K"));
alphaCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
for (int i = 0; i <= 255; i += 5) {
alphaCombo.add(String.valueOf(i));
}
alphaCombo.select(alphaCombo.indexOf("255"));
alphaCombo.addSelectionListener(widgetSelectedAdapter(event -> alpha()));
// Check box to request incremental display.
group = new Group(controls, SWT.NONE);
group.setLayout(new RowLayout());
group.setText(bundle.getString("Display"));
incrementalCheck = new Button(group, SWT.CHECK);
incrementalCheck.setText(bundle.getString("Incremental"));
incrementalCheck.setSelection(incremental);
incrementalCheck.addSelectionListener(widgetSelectedAdapter(event -> incremental = ((Button) event.widget).getSelection()));
// Check box to request transparent display.
transparentCheck = new Button(group, SWT.CHECK);
transparentCheck.setText(bundle.getString("Transparent"));
transparentCheck.setSelection(transparent);
transparentCheck.addSelectionListener(widgetSelectedAdapter(event -> {
transparent = ((Button) event.widget).getSelection();
if (image != null) {
imageCanvas.redraw();
}
}));
// Check box to request mask display.
maskCheck = new Button(group, SWT.CHECK);
maskCheck.setText(bundle.getString("Mask"));
maskCheck.setSelection(showMask);
maskCheck.addSelectionListener(widgetSelectedAdapter(event -> {
showMask = ((Button) event.widget).getSelection();
if (image != null) {
imageCanvas.redraw();
}
}));
// Check box to request background display.
backgroundCheck = new Button(group, SWT.CHECK);
backgroundCheck.setText(bundle.getString("Background"));
backgroundCheck.setSelection(showBackground);
backgroundCheck.addSelectionListener(widgetSelectedAdapter(event -> showBackground = ((Button) event.widget).getSelection()));
// Group the animation buttons.
group = new Group(controls, SWT.NONE);
group.setLayout(new RowLayout());
group.setText(bundle.getString("Animation"));
// Push button to display the previous image in a multi-image file.
previousButton = new Button(group, SWT.PUSH);
previousButton.setText(bundle.getString("Previous"));
previousButton.setEnabled(false);
previousButton.addSelectionListener(widgetSelectedAdapter(event -> previous()));
// Push button to display the next image in a multi-image file.
nextButton = new Button(group, SWT.PUSH);
nextButton.setText(bundle.getString("Next"));
nextButton.setEnabled(false);
nextButton.addSelectionListener(widgetSelectedAdapter(event -> next()));
// Push button to toggle animation of a multi-image file.
animateButton = new Button(group, SWT.PUSH);
animateButton.setText(bundle.getString("Animate"));
animateButton.setEnabled(false);
animateButton.addSelectionListener(widgetSelectedAdapter(event -> animate()));
// Label to show the image file type.
typeLabel = new Label(shell, SWT.NONE);
typeLabel.setText(bundle.getString("Type_initial"));
typeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
// Canvas to show the image.
imageCanvas = new Canvas(shell, SWT.V_SCROLL | SWT.H_SCROLL | SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
imageCanvas.setBackground(whiteColor);
imageCanvas.setCursor(crossCursor);
gridData = new GridData();
gridData.verticalSpan = 15;
gridData.horizontalAlignment = GridData.FILL;
gridData.verticalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
imageCanvas.setLayoutData(gridData);
imageCanvas.addPaintListener(event -> {
if (image == null) {
Rectangle bounds = imageCanvas.getBounds();
event.gc.fillRectangle(0, 0, bounds.width, bounds.height);
} else {
paintImage(event);
}
});
imageCanvas.addMouseMoveListener(event -> {
if (image != null) {
showColorAt(event.x, event.y);
}
});
// Set up the image canvas scroll bars.
ScrollBar horizontal = imageCanvas.getHorizontalBar();
horizontal.setVisible(true);
horizontal.setMinimum(0);
horizontal.setEnabled(false);
horizontal.addSelectionListener(widgetSelectedAdapter(event -> scrollHorizontally((ScrollBar) event.widget)));
ScrollBar vertical = imageCanvas.getVerticalBar();
vertical.setVisible(true);
vertical.setMinimum(0);
vertical.setEnabled(false);
vertical.addSelectionListener(widgetSelectedAdapter(event -> scrollVertically((ScrollBar) event.widget)));
// Label to show the image size.
sizeLabel = new Label(shell, SWT.NONE);
sizeLabel.setText(bundle.getString("Size_initial"));
sizeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
// Label to show the image depth.
depthLabel = new Label(shell, SWT.NONE);
depthLabel.setText(bundle.getString("Depth_initial"));
depthLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
// Label to show the transparent pixel.
transparentPixelLabel = new Label(shell, SWT.NONE);
transparentPixelLabel.setText(bundle.getString("Transparent_pixel_initial"));
transparentPixelLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
// Label to show the time to load.
timeToLoadLabel = new Label(shell, SWT.NONE);
timeToLoadLabel.setText(bundle.getString("Time_to_load_initial"));
timeToLoadLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
// Separate the animation fields from the rest of the fields.
Label separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
separator.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
// Label to show the logical screen size for animation.
screenSizeLabel = new Label(shell, SWT.NONE);
screenSizeLabel.setText(bundle.getString("Animation_size_initial"));
screenSizeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
// Label to show the background pixel.
backgroundPixelLabel = new Label(shell, SWT.NONE);
backgroundPixelLabel.setText(bundle.getString("Background_pixel_initial"));
backgroundPixelLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
// Label to show the image location (x, y).
locationLabel = new Label(shell, SWT.NONE);
locationLabel.setText(bundle.getString("Image_location_initial"));
locationLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
// Label to show the image disposal method.
disposalMethodLabel = new Label(shell, SWT.NONE);
disposalMethodLabel.setText(bundle.getString("Disposal_initial"));
disposalMethodLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
// Label to show the image delay time.
delayTimeLabel = new Label(shell, SWT.NONE);
delayTimeLabel.setText(bundle.getString("Delay_initial"));
delayTimeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
// Label to show the background pixel.
repeatCountLabel = new Label(shell, SWT.NONE);
repeatCountLabel.setText(bundle.getString("Repeats_initial"));
repeatCountLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
// Separate the animation fields from the palette.
separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
separator.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
// Label to show if the image has a direct or indexed palette.
paletteLabel = new Label(shell, SWT.NONE);
paletteLabel.setText(bundle.getString("Palette_initial"));
paletteLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
// Canvas to show the image's palette.
paletteCanvas = new Canvas(shell, SWT.BORDER | SWT.V_SCROLL | SWT.NO_REDRAW_RESIZE);
paletteCanvas.setFont(fixedWidthFont);
paletteCanvas.getVerticalBar().setVisible(true);
gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.verticalAlignment = GridData.FILL;
GC gc = new GC(paletteLabel);
paletteWidth = gc.stringExtent(bundle.getString("Max_length_string")).x;
gc.dispose();
gridData.widthHint = paletteWidth;
// show at least 16 colors
gridData.heightHint = 16 * 11;
paletteCanvas.setLayoutData(gridData);
paletteCanvas.addPaintListener(event -> {
if (image != null)
paintPalette(event);
});
// Set up the palette canvas scroll bar.
vertical = paletteCanvas.getVerticalBar();
vertical.setVisible(true);
vertical.setMinimum(0);
vertical.setIncrement(10);
vertical.setEnabled(false);
vertical.addSelectionListener(widgetSelectedAdapter(event -> scrollPalette((ScrollBar) event.widget)));
// Sash to see more of image or image data.
sash = new Sash(shell, SWT.HORIZONTAL);
gridData = new GridData();
gridData.horizontalSpan = 2;
gridData.horizontalAlignment = GridData.FILL;
sash.setLayoutData(gridData);
sash.addSelectionListener(widgetSelectedAdapter(event -> {
if (event.detail != SWT.DRAG) {
((GridData) paletteCanvas.getLayoutData()).heightHint = SWT.DEFAULT;
Rectangle paletteCanvasBounds = paletteCanvas.getBounds();
int minY = paletteCanvasBounds.y + 20;
Rectangle dataLabelBounds = dataLabel.getBounds();
int maxY = statusLabel.getBounds().y - dataLabelBounds.height - 20;
if (event.y > minY && event.y < maxY) {
Rectangle oldSash = sash.getBounds();
sash.setBounds(event.x, event.y, event.width, event.height);
int diff = event.y - oldSash.y;
Rectangle bounds = imageCanvas.getBounds();
imageCanvas.setBounds(bounds.x, bounds.y, bounds.width, bounds.height + diff);
bounds = paletteCanvasBounds;
paletteCanvas.setBounds(bounds.x, bounds.y, bounds.width, bounds.height + diff);
bounds = dataLabelBounds;
dataLabel.setBounds(bounds.x, bounds.y + diff, bounds.width, bounds.height);
bounds = dataText.getBounds();
dataText.setBounds(bounds.x, bounds.y + diff, bounds.width, bounds.height - diff);
// shell.layout(true);
}
}
}));
// Label to show data-specific fields.
dataLabel = new Label(shell, SWT.NONE);
dataLabel.setText(bundle.getString("Pixel_data_initial"));
gridData = new GridData();
gridData.horizontalSpan = 2;
gridData.horizontalAlignment = GridData.FILL;
dataLabel.setLayoutData(gridData);
// Text to show a dump of the data.
dataText = new StyledText(shell, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
dataText.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
dataText.setFont(fixedWidthFont);
gridData = new GridData();
gridData.horizontalSpan = 2;
gridData.horizontalAlignment = GridData.FILL;
gridData.verticalAlignment = GridData.FILL;
gridData.heightHint = 128;
gridData.grabExcessVerticalSpace = true;
dataText.setLayoutData(gridData);
dataText.addMouseListener(MouseListener.mouseDownAdapter(event -> {
if (image != null && event.button == 1) {
showColorForData();
}
}));
dataText.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if (image != null) {
showColorForData();
}
}
});
// Label to show status and cursor location in image.
statusLabel = new Label(shell, SWT.NONE);
statusLabel.setText("");
gridData = new GridData();
gridData.horizontalSpan = 2;
gridData.horizontalAlignment = GridData.FILL;
statusLabel.setLayoutData(gridData);
}
Aggregations