blob: 6aa0c17cc0c3d9576157ac765bfa58aeec2b8a08 [file] [log] [blame]
/*****************************************************************************
* Copyright (c) 2015, 2020 CEA LIST.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Dirk Fauth <dirk.fauth@googlemail.com> - Initial API and implementation
* Loris Securo <lorissek@gmail.com> - Bug 499508
*****************************************************************************/
package org.eclipse.nebula.widgets.nattable.fillhandle.action;
import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.fillhandle.config.FillHandleConfiguration;
import org.eclipse.nebula.widgets.nattable.ui.action.IMouseAction;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
/**
* Action to enable a custom cursor (small cross) on NatTable. Used when moving
* over the fill handle of a current selection.
*
* @see FillHandleConfiguration
*
* @since 1.4
*/
public class FillHandleCursorAction implements IMouseAction {
private Cursor fillHandleCursor;
@Override
public void run(NatTable natTable, MouseEvent event) {
if (this.fillHandleCursor == null) {
PaletteData paletteData = new PaletteData(new RGB[] {
new RGB(0, 0, 0), new RGB(255, 255, 255)
});
ImageData sourceData = new ImageData(16, 16, 1, paletteData);
ImageData maskData = new ImageData(16, 16, 1, paletteData);
byte[] cursorSource = new byte[] {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
1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
0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
sourceData.setPixels(0, 0, 256, cursorSource, 0);
maskData.setPixels(0, 0, 256, cursorMask, 0);
this.fillHandleCursor = new Cursor(Display.getDefault(), sourceData, maskData, 7, 7);
natTable.addDisposeListener(e -> FillHandleCursorAction.this.fillHandleCursor.dispose());
}
natTable.setCursor(this.fillHandleCursor);
}
}