file_name
stringlengths 6
86
| file_path
stringlengths 45
249
| content
stringlengths 47
6.26M
| file_size
int64 47
6.26M
| language
stringclasses 1
value | extension
stringclasses 1
value | repo_name
stringclasses 767
values | repo_stars
int64 8
14.4k
| repo_forks
int64 0
1.17k
| repo_open_issues
int64 0
788
| repo_created_at
stringclasses 767
values | repo_pushed_at
stringclasses 767
values |
---|---|---|---|---|---|---|---|---|---|---|---|
ViewportSelectColumnCommandHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/viewport/command/ViewportSelectColumnCommandHandler.java | package net.sourceforge.nattable.viewport.command;
import net.sourceforge.nattable.command.AbstractLayerCommandHandler;
import net.sourceforge.nattable.layer.IUniqueIndexLayer;
import net.sourceforge.nattable.selection.command.SelectColumnCommand;
import net.sourceforge.nattable.viewport.ViewportLayer;
public class ViewportSelectColumnCommandHandler extends AbstractLayerCommandHandler<ViewportSelectColumnCommand> {
private final ViewportLayer viewportLayer;
public ViewportSelectColumnCommandHandler(ViewportLayer viewportLayer) {
this.viewportLayer = viewportLayer;
}
public Class<ViewportSelectColumnCommand> getCommandClass() {
return ViewportSelectColumnCommand.class;
}
@Override
protected boolean doCommand(ViewportSelectColumnCommand command) {
IUniqueIndexLayer scrollableLayer = viewportLayer.getScrollableLayer();
int scrollableColumnPosition = viewportLayer.localToUnderlyingColumnPosition(command.getColumnPosition());
int scrollableRowPosition = viewportLayer.getOriginRowPosition();
scrollableLayer.doCommand(new SelectColumnCommand(scrollableLayer, scrollableColumnPosition, scrollableRowPosition, command.isWithShiftMask(), command.isWithControlMask()));
return true;
}
}
| 1,228 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ShowCellInViewportCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/viewport/command/ShowCellInViewportCommand.java | package net.sourceforge.nattable.viewport.command;
import net.sourceforge.nattable.command.AbstractPositionCommand;
import net.sourceforge.nattable.layer.ILayer;
public class ShowCellInViewportCommand extends AbstractPositionCommand {
public ShowCellInViewportCommand(ILayer layer, int columnPosition, int rowPosition) {
super(layer, columnPosition, rowPosition);
}
protected ShowCellInViewportCommand(ShowCellInViewportCommand command) {
super(command);
}
public ShowCellInViewportCommand cloneCommand() {
return new ShowCellInViewportCommand(this);
}
}
| 596 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ShowRowInViewportCommandHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/viewport/command/ShowRowInViewportCommandHandler.java | package net.sourceforge.nattable.viewport.command;
import net.sourceforge.nattable.command.AbstractLayerCommandHandler;
import net.sourceforge.nattable.viewport.ViewportLayer;
public class ShowRowInViewportCommandHandler extends AbstractLayerCommandHandler<ShowRowInViewportCommand> {
private final ViewportLayer viewportLayer;
public ShowRowInViewportCommandHandler(ViewportLayer viewportLayer) {
this.viewportLayer = viewportLayer;
}
public Class<ShowRowInViewportCommand> getCommandClass() {
return ShowRowInViewportCommand.class;
}
@Override
protected boolean doCommand(ShowRowInViewportCommand command) {
viewportLayer.moveRowPositionIntoViewport(command.getRowPosition(), false);
return true;
}
}
| 728 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ShowColumnInViewportCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/viewport/command/ShowColumnInViewportCommand.java | package net.sourceforge.nattable.viewport.command;
import net.sourceforge.nattable.command.AbstractColumnCommand;
import net.sourceforge.nattable.layer.ILayer;
public class ShowColumnInViewportCommand extends AbstractColumnCommand {
public ShowColumnInViewportCommand(ILayer layer, int columnPosition) {
super(layer, columnPosition);
}
protected ShowColumnInViewportCommand(ShowColumnInViewportCommand command) {
super(command);
}
public ShowColumnInViewportCommand cloneCommand() {
return new ShowColumnInViewportCommand(this);
}
}
| 574 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
RecalculateScrollBarsCommandHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/viewport/command/RecalculateScrollBarsCommandHandler.java | package net.sourceforge.nattable.viewport.command;
import net.sourceforge.nattable.command.AbstractLayerCommandHandler;
import net.sourceforge.nattable.viewport.ViewportLayer;
public class RecalculateScrollBarsCommandHandler extends AbstractLayerCommandHandler<RecalculateScrollBarsCommand> {
private final ViewportLayer viewportLayer;
public RecalculateScrollBarsCommandHandler(ViewportLayer viewportLayer) {
this.viewportLayer = viewportLayer;
}
public Class<RecalculateScrollBarsCommand> getCommandClass() {
return RecalculateScrollBarsCommand.class;
}
@Override
protected boolean doCommand(RecalculateScrollBarsCommand command) {
viewportLayer.recalculateScrollBars();
return true;
}
}
| 715 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ViewportSelectColumnCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/viewport/command/ViewportSelectColumnCommand.java | package net.sourceforge.nattable.viewport.command;
import net.sourceforge.nattable.command.AbstractColumnCommand;
import net.sourceforge.nattable.layer.ILayer;
public class ViewportSelectColumnCommand extends AbstractColumnCommand {
private final boolean withShiftMask;
private final boolean withControlMask;
public ViewportSelectColumnCommand(ILayer layer, int columnPosition, boolean withShiftMask, boolean withControlMask) {
super(layer, columnPosition);
this.withShiftMask = withShiftMask;
this.withControlMask = withControlMask;
}
protected ViewportSelectColumnCommand(ViewportSelectColumnCommand command) {
super(command);
this.withShiftMask = command.withShiftMask;
this.withControlMask = command.withControlMask;
}
public boolean isWithShiftMask() {
return withShiftMask;
}
public boolean isWithControlMask() {
return withControlMask;
}
public ViewportSelectColumnCommand cloneCommand() {
return new ViewportSelectColumnCommand(this);
}
}
| 1,026 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ScrollEvent.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/viewport/event/ScrollEvent.java | package net.sourceforge.nattable.viewport.event;
import java.util.Collection;
import net.sourceforge.nattable.layer.event.StructuralDiff;
import net.sourceforge.nattable.layer.event.StructuralRefreshEvent;
import net.sourceforge.nattable.viewport.ViewportLayer;
public class ScrollEvent extends StructuralRefreshEvent {
public ScrollEvent(ViewportLayer viewportLayer) {
super(viewportLayer);
}
protected ScrollEvent(ScrollEvent event) {
super(event);
}
public ScrollEvent cloneEvent() {
return new ScrollEvent(this);
}
public Collection<StructuralDiff> getColumnDiffs() {
// TODO this is bogus - should have a horiz/vert scroll event instead that are multi col/row structural changes
return null;
}
public Collection<StructuralDiff> getRowDiffs() {
// TODO this is bogus - should have a horiz/vert scroll event instead that are multi col/row structural changes
return null;
}
} | 947 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ViewportEventHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/viewport/event/ViewportEventHandler.java | package net.sourceforge.nattable.viewport.event;
import java.util.Collection;
import net.sourceforge.nattable.coordinate.Range;
import net.sourceforge.nattable.layer.event.ILayerEventHandler;
import net.sourceforge.nattable.layer.event.IStructuralChangeEvent;
import net.sourceforge.nattable.layer.event.StructuralDiff;
import net.sourceforge.nattable.viewport.ViewportLayer;
public class ViewportEventHandler implements ILayerEventHandler<IStructuralChangeEvent> {
private final ViewportLayer viewportLayer;
public ViewportEventHandler(ViewportLayer viewportLayer) {
this.viewportLayer = viewportLayer;
}
public Class<IStructuralChangeEvent> getLayerEventClass() {
return IStructuralChangeEvent.class;
}
public void handleLayerEvent(IStructuralChangeEvent event) {
if (event.isHorizontalStructureChanged()) {
viewportLayer.invalidateHorizontalStructure();
}
if (event.isVerticalStructureChanged()) {
viewportLayer.invalidateVerticalStructure();
}
Collection<StructuralDiff> columnDiffs = event.getColumnDiffs();
if (columnDiffs != null) {
int columnOffset = 0;
int minimumOriginColumnPosition = viewportLayer.getMinimumOriginColumnPosition();
for (StructuralDiff columnDiff : columnDiffs) {
switch (columnDiff.getDiffType()) {
case ADD:
Range afterPositionRange = columnDiff.getAfterPositionRange();
if (afterPositionRange.start < minimumOriginColumnPosition) {
columnOffset += afterPositionRange.size();
}
break;
case DELETE:
Range beforePositionRange = columnDiff.getBeforePositionRange();
if (beforePositionRange.start < minimumOriginColumnPosition) {
columnOffset -= Math.min(beforePositionRange.end, minimumOriginColumnPosition + 1) - beforePositionRange.start;
}
break;
}
}
viewportLayer.setMinimumOriginColumnPosition(minimumOriginColumnPosition + columnOffset);
}
Collection<StructuralDiff> rowDiffs = event.getRowDiffs();
if (rowDiffs != null) {
int rowOffset = 0;
int minimumOriginRowPosition = viewportLayer.getMinimumOriginRowPosition();
for (StructuralDiff rowDiff : rowDiffs) {
switch (rowDiff.getDiffType()) {
case ADD:
Range afterPositionRange = rowDiff.getAfterPositionRange();
if (afterPositionRange.start < minimumOriginRowPosition) {
rowOffset += afterPositionRange.size();
}
break;
case DELETE:
Range beforePositionRange = rowDiff.getBeforePositionRange();
if (beforePositionRange.start < minimumOriginRowPosition) {
rowOffset -= Math.min(beforePositionRange.end, minimumOriginRowPosition + 1) - beforePositionRange.start;
}
break;
}
}
viewportLayer.setMinimumOriginRowPosition(minimumOriginRowPosition + rowOffset);
}
}
}
| 2,861 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IOverlayPainter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/IOverlayPainter.java | package net.sourceforge.nattable.painter;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.layer.ILayer;
import org.eclipse.swt.graphics.GC;
/**
* An overlay painter is given a chance to paint the canvas once<br/>
* the layers have finished rendering.
*
* @see NatTable#addOverlayPainter(IOverlayPainter)
*/
public interface IOverlayPainter {
public void paintOverlay(GC gc, ILayer layer);
}
| 449 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
CheckBoxPainter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/CheckBoxPainter.java | package net.sourceforge.nattable.painter.cell;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.util.GUIHelper;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
public class CheckBoxPainter extends ImagePainter {
private final Image checkedImg;
private final Image uncheckedImg;
public CheckBoxPainter() {
checkedImg = GUIHelper.getImage("checked");
uncheckedImg = GUIHelper.getImage("unchecked");
}
public CheckBoxPainter(Image checkedImg, Image uncheckedImg) {
super();
this.checkedImg = checkedImg;
this.uncheckedImg = uncheckedImg;
}
public int getPreferredWidth(boolean checked) {
return checked ? checkedImg.getBounds().width : uncheckedImg.getBounds().width;
}
public int getPreferredHeight(boolean checked) {
return checked ? checkedImg.getBounds().height : uncheckedImg.getBounds().height;
}
public void paintIconImage(GC gc, Rectangle rectangle, int yOffset, boolean checked) {
Image checkBoxImage = checked ? checkedImg : uncheckedImg;
// Center image
int x = rectangle.x + (rectangle.width / 2) - (checkBoxImage.getBounds().width/2);
gc.drawImage(checkBoxImage, x, rectangle.y + yOffset);
}
@Override
protected Image getImage(LayerCell cell, IConfigRegistry configRegistry) {
return isChecked(cell, configRegistry) ? checkedImg : uncheckedImg;
}
protected boolean isChecked(LayerCell cell, IConfigRegistry configRegistry) {
return ((Boolean) cell.getDataValue()).booleanValue();
}
}
| 1,614 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ImagePainter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/ImagePainter.java | package net.sourceforge.nattable.painter.cell;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.style.CellStyleAttributes;
import net.sourceforge.nattable.style.CellStyleUtil;
import net.sourceforge.nattable.style.IStyle;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
/**
* Paints an image. If no image is provided, it will attempt to look up an image from the cell style.
*/
public class ImagePainter extends BackgroundPainter {
private final Image image;
private final boolean paintBg;
public ImagePainter() {
this(null);
}
public ImagePainter(Image image) {
this(image, true);
}
public ImagePainter(Image image, boolean paintBg) {
this.image = image;
this.paintBg = paintBg;
}
@Override
public int getPreferredWidth(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
Image image = getImage(cell, configRegistry);
if (image != null) {
return image.getBounds().width;
} else {
return 0;
}
}
@Override
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
Image image = getImage(cell, configRegistry);
if (image != null) {
return image.getBounds().height;
} else {
return 0;
}
}
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
if (paintBg) {
super.paintCell(cell, gc, bounds, configRegistry);
}
Image image = getImage(cell, configRegistry);
if (image != null) {
Rectangle imageBounds = image.getBounds();
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
gc.drawImage(image, bounds.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width), bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height));
}
}
protected Image getImage(LayerCell cell, IConfigRegistry configRegistry) {
if (image != null) {
return image;
} else {
return CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyleAttributes.IMAGE);
}
}
}
| 2,180 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
BackgroundPainter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/BackgroundPainter.java | package net.sourceforge.nattable.painter.cell;
import net.sourceforge.nattable.config.ConfigRegistry;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.style.CellStyleAttributes;
import net.sourceforge.nattable.style.CellStyleUtil;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
/**
* Paints the background of the cell using the color from the cell style.<br/>
* If no background color is registered in the {@link ConfigRegistry} the painting
* is skipped.<br/>
*
* Example: The {@link TextPainter} inherits this and uses the paint method<br/>
* in this class to paint the background of the cell.
*
* Can be used as a cell painter or a decorator.
*/
public class BackgroundPainter extends CellPainterWrapper {
public BackgroundPainter() {}
public BackgroundPainter(ICellPainter painter) {
super(painter);
}
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
Color backgroundColor = CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);
if (backgroundColor != null) {
Color originalBackground = gc.getBackground();
gc.setBackground(backgroundColor);
gc.fillRectangle(bounds);
gc.setBackground(originalBackground);
}
super.paintCell(cell, gc, bounds, configRegistry);
}
}
| 1,488 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ComboBoxPainter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/ComboBoxPainter.java | package net.sourceforge.nattable.painter.cell;
import net.sourceforge.nattable.painter.cell.decorator.CellPainterDecorator;
import net.sourceforge.nattable.ui.util.CellEdgeEnum;
import net.sourceforge.nattable.util.GUIHelper;
public class ComboBoxPainter extends CellPainterWrapper {
public ComboBoxPainter() {
setWrappedPainter(new CellPainterDecorator(new TextPainter(), CellEdgeEnum.RIGHT, new ImagePainter(GUIHelper.getImage("down_2"))));
}
}
| 469 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ICellPainter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/ICellPainter.java | package net.sourceforge.nattable.painter.cell;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.cell.LayerCell;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
/**
* Implementations are responsible for painting a cell.<br/>
*
* Custom {@link ICellPainter} can be registered in the {@link IConfigRegistry}.
* This is a mechanism for plugging in custom cell painting.
*
* @see PercentageBarCellPainter
*/
public interface ICellPainter {
/**
*
* @param gc SWT graphics context used to draw the cell
* @param rectangle cell bounds
* @param natTable :-)
* @param cellRenderer
* @param rowIndex of the cell to paint
* @param colIndex of the cell to paint
* @param selected is the cell selected ?
*/
public void paintCell(LayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry);
/**
* Get the preferred width of the cell when rendered by this painter. Used for auto-resize.
* @param cell
* @param gc
* @param configRegistry
* @return
*/
public int getPreferredWidth(LayerCell cell, GC gc, IConfigRegistry configRegistry);
/**
* Get the preferred height of the cell when rendered by this painter. Used for auto-resize.
* @param cell
* @param gc
* @param configRegistry
* @return
*/
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry);
}
| 1,471 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
TextPainter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/TextPainter.java | package net.sourceforge.nattable.painter.cell;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.nattable.config.CellConfigAttributes;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.data.convert.IDisplayConverter;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.style.CellStyleAttributes;
import net.sourceforge.nattable.style.CellStyleUtil;
import net.sourceforge.nattable.style.IStyle;
import net.sourceforge.nattable.util.GUIHelper;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
public class TextPainter extends BackgroundPainter {
private static final Pattern endOfPreviousWordPattern = Pattern.compile("\\S\\s+\\S+\\s*$");
public static final String EMPTY = "";
public static final String DOT = "...";
private static Map<String,Integer> temporaryMap = new WeakHashMap<String,Integer>();
private static Map<org.eclipse.swt.graphics.Font,FontData[]> fontDataCache = new WeakHashMap<org.eclipse.swt.graphics.Font,FontData[]>();
private final boolean wrapText;
private final boolean paintBg;
public TextPainter() {
this(false, true);
}
/**
* @param wrapText split text over multiple lines
* @param paintBg skips painting the background if is FALSE
*/
public TextPainter(boolean wrapText, boolean paintBg) {
this.wrapText = wrapText;
this.paintBg = paintBg;
}
@Override
public int getPreferredWidth(LayerCell cell, GC gc, IConfigRegistry configRegistry){
setupGCFromConfig(gc, CellStyleUtil.getCellStyle(cell, configRegistry));
return getWidthFromCache(gc, convertDataType(cell, configRegistry));
}
@Override
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
setupGCFromConfig(gc, CellStyleUtil.getCellStyle(cell, configRegistry));
return gc.textExtent(convertDataType(cell, configRegistry)).y;
}
/**
* Convert the data value of the cell using the {@link IDisplayConverter} from the {@link IConfigRegistry}
*/
protected String convertDataType(LayerCell cell, IConfigRegistry configRegistry) {
IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
String text = displayConverter != null ? (String) displayConverter.canonicalToDisplayValue(cell.getDataValue()) : null;
text = (text == null) ? "" : text;
return text;
}
public void setupGCFromConfig(GC gc, IStyle cellStyle) {
Color fg = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);
Color bg = cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);
Font font = cellStyle.getAttributeValue(CellStyleAttributes.FONT);
gc.setAntialias(GUIHelper.DEFAULT_ANTIALIAS);
gc.setTextAntialias(GUIHelper.DEFAULT_TEXT_ANTIALIAS);
gc.setFont(font);
gc.setForeground(fg != null ? fg : GUIHelper.COLOR_LIST_FOREGROUND);
gc.setBackground(bg != null ? bg : GUIHelper.COLOR_LIST_BACKGROUND);
}
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
if (paintBg) {
super.paintCell(cell, gc, rectangle, configRegistry);
}
Rectangle originalClipping = gc.getClipping();
gc.setClipping(rectangle.intersection(originalClipping));
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
setupGCFromConfig(gc, cellStyle);
String text = convertDataType(cell, configRegistry);
// Draw Text
String originalText = text;
int originalTextWidth = getWidthFromCache(gc, originalText);
text = getAvailableTextToDisplay(gc, rectangle, text);
int contentWidth = Math.min(originalTextWidth, rectangle.width);
int fontHeight = gc.getFontMetrics().getHeight();
int contentHeight = fontHeight * getNumberOfNewLines(text);
gc.drawText(
text,
rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth),
rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight),
true
);
gc.setClipping(originalClipping);
}
private int getNumberOfNewLines(String text) {
char[] charArray = text.toCharArray();
int lineCount = 1;
for (char c : charArray) {
if (c == '\n') {
lineCount++;
}
}
return lineCount;
}
private int getWidthFromCache(GC gc, String text) {
String originalString = text;
StringBuilder buffer = new StringBuilder();
buffer.append(text);
if (gc.getFont() != null) {
FontData[] datas = fontDataCache.get(gc.getFont());
if (datas == null) {
datas = gc.getFont().getFontData();
fontDataCache.put(gc.getFont(), datas);
}
if (datas != null && datas.length > 0) {
buffer.append(datas[0].getName());
buffer.append(",");
buffer.append(datas[0].getHeight());
buffer.append(",");
buffer.append(datas[0].getStyle());
}
}
text = buffer.toString();
Integer width = temporaryMap.get(text);
if (width == null) {
width = Integer.valueOf(gc.textExtent(originalString).x);
temporaryMap.put(text, width);
}
return width.intValue();
}
private String getAvailableTextToDisplay(GC gc, Rectangle bounds, String text) {
StringBuilder output = new StringBuilder();
text = text.trim();
while (text.length() > 0) {
String line;
int nextLineBreakIndex;
int indexOfNewline = text.indexOf('\n');
if (indexOfNewline > 0) {
nextLineBreakIndex = indexOfNewline;
line = text.substring(0, nextLineBreakIndex);
} else {
nextLineBreakIndex = -1;
line = text;
}
int textWidth = getWidthFromCache(gc, line);
if (wrapText) {
while (textWidth > bounds.width + 1) {
Matcher matcher = endOfPreviousWordPattern.matcher(line);
if (matcher.find()) {
nextLineBreakIndex = matcher.start() + 1;
line = line.substring(0, nextLineBreakIndex);
textWidth = getWidthFromCache(gc, line);
} else {
nextLineBreakIndex = -1;
break;
}
}
}
if (textWidth > bounds.width + 1) {
int textLen = line.length();
for (int i = textLen - 1; i >= 0; i--) {
String temp = line.substring(0, i) + DOT;
textWidth = getWidthFromCache(gc, temp);
if (textWidth < bounds.width) {
line = temp;
break;
} else if (i == 0) {
line = EMPTY;
}
}
}
output.append(line);
if (nextLineBreakIndex > 0) {
text = text.substring(nextLineBreakIndex).trim();
if (text.length() > 0) {
output.append("\n");
}
} else {
break;
}
}
return output.toString();
}
}
| 6,778 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
CellPainterWrapper.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/CellPainterWrapper.java | package net.sourceforge.nattable.painter.cell;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.cell.LayerCell;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
public abstract class CellPainterWrapper implements ICellPainter {
private ICellPainter wrappedPainter;
public CellPainterWrapper() {}
public CellPainterWrapper(ICellPainter painter) {
this.wrappedPainter = painter;
}
public void setWrappedPainter(ICellPainter painter) {
this.wrappedPainter = painter;
}
public ICellPainter getWrappedPainter() {
return wrappedPainter;
}
public int getPreferredWidth(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
return wrappedPainter != null ? wrappedPainter.getPreferredWidth(cell, gc, configRegistry) : 0;
}
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
return wrappedPainter != null ? wrappedPainter.getPreferredHeight(cell, gc, configRegistry) : 0;
}
public void paintCell(LayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
if (wrappedPainter != null) {
wrappedPainter.paintCell(cell, gc, bounds, configRegistry);
}
}
}
| 1,214 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
PercentageBarCellPainter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/PercentageBarCellPainter.java | package net.sourceforge.nattable.painter.cell;
import net.sourceforge.nattable.painter.cell.decorator.LineBorderDecorator;
import net.sourceforge.nattable.painter.cell.decorator.PaddingDecorator;
import net.sourceforge.nattable.painter.cell.decorator.PercentageBarDecorator;
import net.sourceforge.nattable.style.BorderStyle;
public class PercentageBarCellPainter extends CellPainterWrapper {
public PercentageBarCellPainter() {
super(new PaddingDecorator(new LineBorderDecorator(new PercentageBarDecorator(new TextPainter()), new BorderStyle())));
}
}
| 561 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
BackgroundImagePainter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/BackgroundImagePainter.java | package net.sourceforge.nattable.painter.cell;
import static net.sourceforge.nattable.util.ObjectUtils.isNotNull;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.cell.LayerCell;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Pattern;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
/**
* Paints the cell background using an image.<br/>
* Image is repeated to cover the background. Similar to HTML table painting.
*/
public class BackgroundImagePainter extends CellPainterWrapper {
public final Color separatorColor;
private final Image bgImage;
/**
* @param interiorPainter used for painting the cell contents
* @param bgImage to be used for painting the background
* @param separatorColor to be used for drawing left and right borders for the cell.
* Set to null if the borders are not required.
*/
public BackgroundImagePainter(ICellPainter interiorPainter, Image bgImage, Color separatorColor) {
super(interiorPainter);
this.bgImage = bgImage;
this.separatorColor = separatorColor;
}
@Override
public int getPreferredWidth(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
return super.getPreferredWidth(cell, gc, configRegistry) + 4;
}
@Override
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
return super.getPreferredHeight(cell, gc, configRegistry) + 4;
}
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
// Save GC settings
Color originalBackground = gc.getBackground();
Color originalForeground = gc.getForeground();
gc.setBackgroundPattern(new Pattern(Display.getCurrent(), bgImage));
gc.fillRectangle(rectangle);
gc.setBackgroundPattern(null);
if (isNotNull(separatorColor)) {
gc.setForeground(separatorColor);
gc.drawLine(rectangle.x - 1, rectangle.y, rectangle.x - 1, rectangle.y + rectangle.height);
gc.drawLine(rectangle.x - 1 + rectangle.width, rectangle.y, rectangle.x - 1 + rectangle.width, rectangle.y + rectangle.height);
}
// Restore original GC settings
gc.setBackground(originalBackground);
gc.setForeground(originalForeground);
// Draw interior
Rectangle interiorBounds = new Rectangle(rectangle.x + 2, rectangle.y + 2, rectangle.width - 4, rectangle.height - 4);
super.paintCell(cell, gc, interiorBounds, configRegistry);
}
}
| 2,598 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ButtonCellPainter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/ButtonCellPainter.java | package net.sourceforge.nattable.painter.cell;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.layer.event.CellVisualChangeEvent;
import net.sourceforge.nattable.painter.cell.decorator.BeveledBorderDecorator;
import net.sourceforge.nattable.ui.NatEventData;
import net.sourceforge.nattable.ui.action.IMouseAction;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
/**
* Paints a button and simulates a button click. It also notifies its listeners when it is clicked.
*/
public class ButtonCellPainter implements ICellPainter, IMouseAction {
private final ICellPainter buttonRaisedPainter;
private final ICellPainter buttonPressedPainter;
private int buttonFlashTime = 150;
private int columnPosClicked;
private int rowPosClicked;
private boolean recentlyClicked;
private final List<IMouseAction> clickLiseners = new ArrayList<IMouseAction>();
/**
* @param interiorPainter to paint the contents of the cell.
* This will be decorated with a button like look and feel.
*/
public ButtonCellPainter(ICellPainter interiorPainter) {
this.buttonPressedPainter = interiorPainter;
this.buttonRaisedPainter = new BeveledBorderDecorator(interiorPainter);
}
/**
* @param buttonRaisedPainter cell painter to use for painting the button raised state.
* @param buttonPressedPainter cell painter to use for painting the button pressed state.
*/
public ButtonCellPainter(ICellPainter buttonRaisedPainter, ICellPainter buttonPressedPainter) {
this.buttonRaisedPainter = buttonRaisedPainter;
this.buttonPressedPainter = buttonPressedPainter;
}
public void paintCell(final LayerCell cell, final GC gc, final Rectangle bounds, final IConfigRegistry configRegistry) {
if (recentlyClicked && columnPosClicked == cell.getColumnPosition() && rowPosClicked == cell.getRowPosition()){
buttonPressedPainter.paintCell(cell, gc, bounds, configRegistry);
} else {
buttonRaisedPainter.paintCell(cell, gc, bounds, configRegistry);
}
}
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
return cell.getBounds().height;
}
public int getPreferredWidth(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
return cell.getBounds().width;
}
private TimerTask getButtonFlashTimerTask(final ILayer layer){
return new TimerTask() {
@Override
public void run() {
recentlyClicked = false;
Display.getDefault().asyncExec(new Runnable() {
public void run() {
layer.fireLayerEvent(new CellVisualChangeEvent(layer, columnPosClicked, rowPosClicked));
}
});
}
};
}
/**
* Respond to mouse click. Simulate button press.
*/
public void run(final NatTable natTable, MouseEvent event) {
NatEventData eventData = (NatEventData) event.data;
columnPosClicked = eventData.getColumnPosition();
rowPosClicked = eventData.getRowPosition();
recentlyClicked = true;
new Timer().schedule(getButtonFlashTimerTask(natTable), buttonFlashTime);
natTable.fireLayerEvent(new CellVisualChangeEvent(natTable, columnPosClicked, rowPosClicked));
for (IMouseAction listener : clickLiseners) {
listener.run(natTable, event);
}
}
public void addClickListener(IMouseAction mouseAction){
clickLiseners.add(mouseAction);
}
public void removeClickListener(IMouseAction mouseAction){
clickLiseners.remove(mouseAction);
}
public void setButtonFlashTime(int flashTimeInMS) {
buttonFlashTime = flashTimeInMS;
}
}
| 3,935 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DisabledCheckboxPainter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/DisabledCheckboxPainter.java | package net.sourceforge.nattable.painter.cell;
import net.sourceforge.nattable.util.GUIHelper;
import org.eclipse.swt.graphics.Image;
public class DisabledCheckboxPainter extends CheckBoxPainter {
public DisabledCheckboxPainter() {
super(GUIHelper.getImage("checked_disabled"), GUIHelper.getImage("unchecked_disabled"));
}
public DisabledCheckboxPainter(Image checkedImg, Image uncheckedImg) {
super(checkedImg, uncheckedImg);
}
}
| 460 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
CellPainterDecorator.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/decorator/CellPainterDecorator.java | package net.sourceforge.nattable.painter.cell.decorator;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.painter.cell.ICellPainter;
import net.sourceforge.nattable.ui.util.CellEdgeEnum;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
/**
* Decorates a cell painter with another cell painter.
*/
public class CellPainterDecorator implements ICellPainter {
private final ICellPainter baseCellPainter;
private final CellEdgeEnum cellEdge;
private final int spacing;
private final ICellPainter decoratorCellPainter;
public CellPainterDecorator(ICellPainter baseCellPainter, CellEdgeEnum cellEdge, ICellPainter decoratorCellPainter) {
this(baseCellPainter, cellEdge, 2, decoratorCellPainter);
}
public CellPainterDecorator(ICellPainter baseCellPainter, CellEdgeEnum cellEdge, int spacing, ICellPainter decoratorCellPainter) {
this.baseCellPainter = baseCellPainter;
this.cellEdge = cellEdge;
this.spacing = spacing;
this.decoratorCellPainter = decoratorCellPainter;
}
public int getPreferredWidth(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
return baseCellPainter.getPreferredWidth(cell, gc, configRegistry) + spacing + decoratorCellPainter.getPreferredWidth(cell, gc, configRegistry);
}
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
return baseCellPainter.getPreferredHeight(cell, gc, configRegistry) + spacing + decoratorCellPainter.getPreferredHeight(cell, gc, configRegistry);
}
public void paintCell(LayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
int x = bounds.x + (cellEdge == CellEdgeEnum.LEFT ? decoratorCellPainter.getPreferredWidth(cell, gc, configRegistry) + spacing : 0);
int y = bounds.y + (cellEdge == CellEdgeEnum.TOP ? decoratorCellPainter.getPreferredHeight(cell, gc, configRegistry) + spacing : 0);
Rectangle baseCellPainterBounds = new Rectangle(x, y, bounds.width, bounds.height).intersection(bounds);
baseCellPainter.paintCell(cell, gc, baseCellPainterBounds, configRegistry);
x = bounds.x + (cellEdge == CellEdgeEnum.RIGHT ? bounds.width - spacing - decoratorCellPainter.getPreferredWidth(cell, gc, configRegistry) : 0);
y = bounds.y + (cellEdge == CellEdgeEnum.BOTTOM ? bounds.height - spacing - decoratorCellPainter.getPreferredHeight(cell, gc, configRegistry) : 0);
Rectangle decoratorCellPainterBounds = new Rectangle(x, y, bounds.width, bounds.height).intersection(bounds);
decoratorCellPainter.paintCell(cell, gc, decoratorCellPainterBounds, configRegistry);
}
}
| 2,656 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
PercentageBarDecorator.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/decorator/PercentageBarDecorator.java | package net.sourceforge.nattable.painter.cell.decorator;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.painter.cell.CellPainterWrapper;
import net.sourceforge.nattable.painter.cell.ICellPainter;
import net.sourceforge.nattable.util.GUIHelper;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Pattern;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
/**
* Draws a rectangular bar in cell proportional to the value of the cell.
*/
public class PercentageBarDecorator extends CellPainterWrapper {
public PercentageBarDecorator(ICellPainter interiorPainter) {
super(interiorPainter);
}
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
Color originalBackground = gc.getBackground();
double factor = Math.min(1.0, ((Double) cell.getDataValue()).doubleValue());
factor = Math.max(0.0, factor);
Rectangle bar = new Rectangle(rectangle.x, rectangle.y, (int)(rectangle.width * factor), rectangle.height);
Rectangle bounds = cell.getBounds();
gc.setBackgroundPattern(new Pattern(Display.getCurrent(),
bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height,
GUIHelper.getColor(new RGB(187, 216, 254)),
GUIHelper.getColor(new RGB(255, 255, 255))));
gc.fillRectangle(bar);
gc.setBackground(originalBackground);
super.paintCell(cell, gc, rectangle, configRegistry);
}
}
| 1,606 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
LineBorderDecorator.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/decorator/LineBorderDecorator.java | package net.sourceforge.nattable.painter.cell.decorator;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.painter.cell.CellPainterWrapper;
import net.sourceforge.nattable.painter.cell.ICellPainter;
import net.sourceforge.nattable.style.BorderStyle;
import net.sourceforge.nattable.style.CellStyleAttributes;
import net.sourceforge.nattable.style.CellStyleUtil;
import net.sourceforge.nattable.style.IStyle;
import net.sourceforge.nattable.style.BorderStyle.LineStyleEnum;
public class LineBorderDecorator extends CellPainterWrapper {
private final BorderStyle defaultBorderStyle;
public LineBorderDecorator(ICellPainter interiorPainter) {
this(interiorPainter, null);
}
public LineBorderDecorator(ICellPainter interiorPainter, BorderStyle defaultBorderStyle) {
super(interiorPainter);
this.defaultBorderStyle = defaultBorderStyle;
}
public int getPreferredWidth(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
BorderStyle borderStyle = getBorderStyle(cell, configRegistry);
int borderThickness = borderStyle != null ? borderStyle.getThickness() : 0;
return super.getPreferredWidth(cell, gc, configRegistry) + (borderThickness * 2);
}
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
BorderStyle borderStyle = getBorderStyle(cell, configRegistry);
int borderThickness = borderStyle != null ? borderStyle.getThickness() : 0;
return super.getPreferredHeight(cell, gc, configRegistry) + (borderThickness * 2);
}
private BorderStyle getBorderStyle(LayerCell cell, IConfigRegistry configRegistry) {
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
BorderStyle borderStyle = cellStyle.getAttributeValue(CellStyleAttributes.BORDER_STYLE);
if (borderStyle == null) {
borderStyle = defaultBorderStyle;
}
return borderStyle;
}
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
BorderStyle borderStyle = getBorderStyle(cell, configRegistry);
int borderThickness = borderStyle != null ? borderStyle.getThickness() : 0;
Rectangle interiorBounds =
new Rectangle(
rectangle.x + borderThickness,
rectangle.y + borderThickness,
rectangle.width - (borderThickness * 2),
rectangle.height - (borderThickness * 2)
);
super.paintCell(cell, gc, interiorBounds, configRegistry);
if (borderStyle == null || borderThickness <= 0) {
return;
}
// Save GC settings
Color originalForeground = gc.getForeground();
int originalLineWidth = gc.getLineWidth();
int originalLineStyle = gc.getLineStyle();
gc.setLineWidth(borderThickness);
Rectangle borderArea = new Rectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
if (borderThickness >= 1) {
int shift = 0;
int areaShift = 0;
if ((borderThickness % 2) == 0) {
shift = borderThickness / 2;
areaShift = (shift * 2);
} else {
shift = borderThickness / 2;
areaShift = (shift * 2) + 1;
}
borderArea.x += shift;
borderArea.y += shift;
borderArea.width -= areaShift;
borderArea.height -= areaShift;
}
gc.setLineStyle(LineStyleEnum.toSWT(borderStyle.getLineStyle()));
gc.setForeground(borderStyle.getColor());
gc.drawRectangle(borderArea);
// Restore GC settings
gc.setForeground(originalForeground);
gc.setLineWidth(originalLineWidth);
gc.setLineStyle(originalLineStyle);
}
}
| 3,625 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
BeveledBorderDecorator.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/decorator/BeveledBorderDecorator.java | package net.sourceforge.nattable.painter.cell.decorator;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.painter.cell.CellPainterWrapper;
import net.sourceforge.nattable.painter.cell.ICellPainter;
import net.sourceforge.nattable.util.GUIHelper;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
public class BeveledBorderDecorator extends CellPainterWrapper {
public BeveledBorderDecorator(ICellPainter interiorPainter) {
super(interiorPainter);
}
public int getPreferredWidth(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
return super.getPreferredWidth(cell, gc, configRegistry) + 4;
}
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
return super.getPreferredHeight(cell, gc, configRegistry) + 4;
}
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
Rectangle interiorBounds = new Rectangle(rectangle.x + 2, rectangle.y + 2, rectangle.width - 4, rectangle.height - 4);
super.paintCell(cell, gc, interiorBounds, configRegistry);
// Save GC settings
Color originalForeground = gc.getForeground();
//TODO: Need to look at the border style
// Up
gc.setForeground(GUIHelper.COLOR_WIDGET_LIGHT_SHADOW);
gc.drawLine(rectangle.x, rectangle.y, rectangle.x + rectangle.width - 1, rectangle.y);
gc.drawLine(rectangle.x, rectangle.y, rectangle.x, rectangle.y + rectangle.height - 1);
gc.setForeground(GUIHelper.COLOR_WIDGET_HIGHLIGHT_SHADOW);
gc.drawLine(rectangle.x + 1, rectangle.y + 1, rectangle.x + rectangle.width - 1, rectangle.y + 1);
gc.drawLine(rectangle.x + 1, rectangle.y + 1, rectangle.x + 1, rectangle.y + rectangle.height - 1);
// Down
gc.setForeground(GUIHelper.COLOR_WIDGET_DARK_SHADOW);
gc.drawLine(rectangle.x, rectangle.y + rectangle.height - 1, rectangle.x + rectangle.width - 1, rectangle.y + rectangle.height - 1);
gc.drawLine(rectangle.x + rectangle.width - 1, rectangle.y, rectangle.x + rectangle.width - 1, rectangle.y + rectangle.height - 1);
gc.setForeground(GUIHelper.COLOR_WIDGET_NORMAL_SHADOW);
gc.drawLine(rectangle.x, rectangle.y + rectangle.height - 2, rectangle.x + rectangle.width - 1, rectangle.y + rectangle.height - 2);
gc.drawLine(rectangle.x + rectangle.width - 2, rectangle.y, rectangle.x + rectangle.width - 2, rectangle.y + rectangle.height - 2);
// Restore GC settings
gc.setForeground(originalForeground);
}
}
| 2,586 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
PaddingDecorator.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/decorator/PaddingDecorator.java | package net.sourceforge.nattable.painter.cell.decorator;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.painter.cell.CellPainterWrapper;
import net.sourceforge.nattable.painter.cell.ICellPainter;
public class PaddingDecorator extends CellPainterWrapper {
private final int topPadding;
private final int rightPadding;
private final int bottomPadding;
private final int leftPadding;
public PaddingDecorator(ICellPainter interiorPainter) {
this(interiorPainter, 2);
}
public PaddingDecorator(ICellPainter interiorPainter, int padding) {
this(interiorPainter, padding, padding, padding, padding);
}
public PaddingDecorator(ICellPainter interiorPainter, int topPadding, int rightPadding, int bottomPadding, int leftPadding) {
super(interiorPainter);
this.topPadding = topPadding;
this.rightPadding = rightPadding;
this.bottomPadding = bottomPadding;
this.leftPadding = leftPadding;
}
public int getPreferredWidth(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
return leftPadding + super.getPreferredWidth(cell, gc, configRegistry) + rightPadding;
}
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
return topPadding + super.getPreferredHeight(cell, gc, configRegistry) + bottomPadding;
}
public void paintCell(LayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
Rectangle interiorBounds =
new Rectangle(
bounds.x + leftPadding,
bounds.y + topPadding,
bounds.width - leftPadding - rightPadding,
bounds.height - topPadding - bottomPadding
);
super.paintCell(cell, gc, interiorBounds, configRegistry);
}
}
| 1,826 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
XPBackgroundDecorator.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/cell/decorator/XPBackgroundDecorator.java | package net.sourceforge.nattable.painter.cell.decorator;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.painter.cell.BackgroundPainter;
import net.sourceforge.nattable.painter.cell.ICellPainter;
import net.sourceforge.nattable.util.GUIHelper;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
public class XPBackgroundDecorator extends BackgroundPainter {
public final Color separatorColor;
public final Color gradientColor1;
public final Color gradientColor2;
public final Color gradientColor3;
public final Color highlightColor1;
public final Color highlightColor2;
public final Color highlightColor3;
public XPBackgroundDecorator(ICellPainter interiorPainter) {
super(interiorPainter);
separatorColor = GUIHelper.getColor(199, 197, 178);
gradientColor1 = GUIHelper.getColor(226, 222, 205);
gradientColor2 = GUIHelper.getColor(214, 210, 194);
gradientColor3 = GUIHelper.getColor(203, 199, 184);
highlightColor1 = GUIHelper.getColor(250, 171, 0);
highlightColor2 = GUIHelper.getColor(252, 194, 71);
highlightColor3 = GUIHelper.getColor(250, 178, 24);
}
public int getPreferredWidth(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
return super.getPreferredWidth(cell, gc, configRegistry) + 4;
}
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
return super.getPreferredHeight(cell, gc, configRegistry) + 4;
}
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
// Draw background
super.paintCell(cell, gc, rectangle, configRegistry);
// Draw interior
Rectangle interiorBounds = new Rectangle(rectangle.x + 2, rectangle.y + 2, rectangle.width - 4, rectangle.height - 4);
super.paintCell(cell, gc, interiorBounds, configRegistry);
// Save GC settings
Color originalBackground = gc.getBackground();
Color originalForeground = gc.getForeground();
// Draw separator
int x = rectangle.x;
gc.setForeground(GUIHelper.COLOR_WHITE);
gc.drawLine(x, rectangle.y + 3, x, rectangle.y + rectangle.height - 6);
x = rectangle.x + rectangle.width - 1;
gc.setForeground(separatorColor);
gc.drawLine(x, rectangle.y + 3, x, rectangle.y + rectangle.height - 6);
// Restore GC settings
gc.setBackground(originalBackground);
gc.setForeground(originalForeground);
// Draw bottom edge
boolean isHighlight = false;
int y = rectangle.y + rectangle.height - 3;
gc.setForeground(isHighlight ? highlightColor1 : gradientColor1);
gc.drawLine(rectangle.x, y, rectangle.x + rectangle.width, y);
y++;
gc.setForeground(isHighlight ? highlightColor2 : gradientColor2);
gc.drawLine(rectangle.x, y, rectangle.x + rectangle.width, y);
y++;
gc.setForeground(isHighlight ? highlightColor3 : gradientColor3);
gc.drawLine(rectangle.x, y, rectangle.x + rectangle.width, y);
}
}
| 3,027 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
GridLineCellLayerPainter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/layer/GridLineCellLayerPainter.java | package net.sourceforge.nattable.painter.layer;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.util.GUIHelper;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
public class GridLineCellLayerPainter extends CellLayerPainter {
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle rectangle, IConfigRegistry configRegistry) {
//Draw GridLines
drawGridLines(natLayer, gc, rectangle);
super.paintLayer(natLayer, gc, xOffset, yOffset, rectangle, configRegistry);
}
@Override
public Rectangle adjustCellBounds(Rectangle bounds) {
return new Rectangle(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1);
}
protected void drawGridLines(ILayer natLayer, GC gc, Rectangle rectangle) {
gc.setForeground(GUIHelper.COLOR_GRAY);
drawHorizontalLines(natLayer, gc, rectangle);
drawVerticalLines(natLayer, gc, rectangle);
// paint far bottom left corner pixel
gc.drawPoint(natLayer.getWidth() - 1, natLayer.getHeight() - 1);
}
private void drawHorizontalLines(ILayer natLayer, GC gc, Rectangle rectangle) {
int gridWidth = Math.min(natLayer.getWidth() - 1, rectangle.width);
int rowPositionByY = natLayer.getRowPositionByY(rectangle.y + rectangle.height);
int maxRowPosition = rowPositionByY > 0 ? Math.min(natLayer.getRowCount(), rowPositionByY) : natLayer.getRowCount();
for (int rowPosition = natLayer.getRowPositionByY(rectangle.y); rowPosition < maxRowPosition; rowPosition++) {
int y = natLayer.getStartYOfRowPosition(rowPosition) + natLayer.getRowHeightByPosition(rowPosition) - 1;
gc.drawLine(rectangle.x, y, rectangle.x + gridWidth, y);
}
}
private void drawVerticalLines(ILayer natLayer, GC gc, Rectangle rectangle) {
int gridHeight = Math.min(natLayer.getHeight() - 1, rectangle.height);
int columnPositionByX = natLayer.getColumnPositionByX(rectangle.x + rectangle.width);
int maxColumnPosition = columnPositionByX > 0 ? Math.min(natLayer.getColumnCount(), columnPositionByX) : natLayer.getColumnCount();
for (int columnPosition = natLayer.getColumnPositionByX(rectangle.x); columnPosition < maxColumnPosition; columnPosition++) {
int x = natLayer.getStartXOfColumnPosition(columnPosition) + natLayer.getColumnWidthByPosition(columnPosition) - 1;
gc.drawLine(x, rectangle.y, x, rectangle.y + gridHeight);
}
}
}
| 2,497 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
CellLayerPainter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/layer/CellLayerPainter.java | package net.sourceforge.nattable.painter.layer;
import java.util.Collection;
import java.util.HashSet;
import net.sourceforge.nattable.config.CellConfigAttributes;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.painter.cell.ICellPainter;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
public class CellLayerPainter implements ILayerPainter {
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle pixelRectangle, IConfigRegistry configRegistry) {
if (pixelRectangle.width <= 0 || pixelRectangle.height <= 0) {
return;
}
Collection<LayerCell> spannedCells = new HashSet<LayerCell>();
Rectangle positionRectangle = getPositionRectangleFromPixelRectangle(natLayer, pixelRectangle);
for (int columnPosition = positionRectangle.x; columnPosition < positionRectangle.x + positionRectangle.width; columnPosition++) {
for (int rowPosition = positionRectangle.y; rowPosition < positionRectangle.y + positionRectangle.height; rowPosition++) {
LayerCell cell = natLayer.getCellByPosition(columnPosition, rowPosition);
if (cell != null) {
if (cell.isSpannedCell()) {
spannedCells.add(cell);
} else {
paintCell(cell, gc, configRegistry);
}
}
}
}
for (LayerCell cell : spannedCells) {
paintCell(cell, gc, configRegistry);
}
}
public Rectangle adjustCellBounds(Rectangle cellBounds) {
return cellBounds;
}
protected Rectangle getPositionRectangleFromPixelRectangle(ILayer natLayer, Rectangle pixelRectangle) {
int columnPositionOffset = natLayer.getColumnPositionByX(pixelRectangle.x);
int rowPositionOffset = natLayer.getRowPositionByY(pixelRectangle.y);
int numColumns = natLayer.getColumnPositionByX(Math.min(natLayer.getWidth(), pixelRectangle.x + pixelRectangle.width) - 1) - columnPositionOffset + 1;
int numRows = natLayer.getRowPositionByY(Math.min(natLayer.getHeight(), pixelRectangle.y + pixelRectangle.height) - 1) - rowPositionOffset + 1;
return new Rectangle(columnPositionOffset, rowPositionOffset, numColumns, numRows);
}
protected void paintCell(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
ICellPainter cellPainter = configRegistry.getConfigAttribute(CellConfigAttributes.CELL_PAINTER, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
Rectangle adjustedCellBounds = adjustCellBounds(cell.getBounds());
cellPainter.paintCell(cell, gc, adjustedCellBounds, configRegistry);
}
}
| 2,683 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ILayerPainter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/painter/layer/ILayerPainter.java | package net.sourceforge.nattable.painter.layer;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.ILayer;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
/**
* Classes implementing this interface are responsible for painting to the relevant {@link Device}.<br/>
* Every layer has a layer painter. A layer can contribute to painting by providing its own painter.
*
*/
public interface ILayerPainter {
/**
* @param natLayer
* @param gc GC used for painting
* @param xOffset of the layer from the origin of the table
* @param yOffset of the layer from the origin of the table
* @param rectangle area the layer can paint in
* @param configuration in use by NatTable. Useful for looking up associated painters.
*/
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle rectangle, IConfigRegistry configuration);
/**
* This method is used to adjust the cell bounds when painting the layer. This is most often used to reduce the size
* of the cell to accommodate grid lines.
*/
public Rectangle adjustCellBounds(Rectangle cellBounds);
}
| 1,245 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
NatEventData.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/NatEventData.java | package net.sourceforge.nattable.ui;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.layer.LabelStack;
import org.eclipse.swt.events.MouseEvent;
public class NatEventData {
private Object originalEventData;
private final NatTable natTable;
private final LabelStack regionLabels;
int columnPosition;
int rowPosition;
public static NatEventData createInstanceFromEvent(MouseEvent event) {
NatTable natTable = (NatTable) event.widget;
int columnPosition = natTable.getColumnPositionByX(event.x);
int rowPosition = natTable.getRowPositionByY(event.y);
return new NatEventData(
natTable,
natTable.getRegionLabelsByXY(event.x, event.y),
columnPosition,
rowPosition,
event.data
);
}
public NatEventData(NatTable natTable, LabelStack regionLabels, int columnPosition, int rowPosition, Object originalEventData) {
this.natTable = natTable;
this.regionLabels = regionLabels;
this.columnPosition = columnPosition;
this.rowPosition = rowPosition;
this.originalEventData = originalEventData;
}
public NatTable getNatTable() {
return natTable;
}
public LabelStack getRegionLabels() {
return regionLabels;
}
public int getColumnPosition() {
return columnPosition;
}
public int getRowPosition() {
return rowPosition;
}
public Object getOriginalEventData() {
return originalEventData;
}
} | 1,457 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IMenuItemProvider.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/menu/IMenuItemProvider.java | package net.sourceforge.nattable.ui.menu;
import net.sourceforge.nattable.NatTable;
import org.eclipse.swt.widgets.Menu;
public interface IMenuItemProvider {
/**
* Add an item to the popup menu.
*
* @param natTable active table instance.
* @param popupMenu the SWT {@link Menu} which popus up.
*/
public void addMenuItem(final NatTable natTable, final Menu popupMenu);
}
| 408 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DebugMenuConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/menu/DebugMenuConfiguration.java | package net.sourceforge.nattable.ui.menu;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.config.AbstractUiBindingConfiguration;
import net.sourceforge.nattable.ui.binding.UiBindingRegistry;
import net.sourceforge.nattable.ui.matcher.MouseEventMatcher;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Menu;
public class DebugMenuConfiguration extends AbstractUiBindingConfiguration {
private final Menu debugMenu;
public DebugMenuConfiguration(NatTable natTable) {
debugMenu = new PopupMenuBuilder(natTable)
.withInspectLabelsMenuItem()
.build();
natTable.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
debugMenu.dispose();
}
});
}
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerMouseDownBinding(
new MouseEventMatcher(SWT.NONE, null, 3),
new PopupMenuAction(debugMenu));
}
}
| 1,085 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
BodyMenuConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/menu/BodyMenuConfiguration.java | package net.sourceforge.nattable.ui.menu;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.config.AbstractUiBindingConfiguration;
import net.sourceforge.nattable.grid.GridRegion;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.ui.binding.UiBindingRegistry;
import net.sourceforge.nattable.ui.matcher.MouseEventMatcher;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Menu;
public class BodyMenuConfiguration extends AbstractUiBindingConfiguration {
private final Menu colHeaderMenu;
public BodyMenuConfiguration(NatTable natTable, ILayer bodyLayer) {
colHeaderMenu = new PopupMenuBuilder(natTable)
.withColumnStyleEditor("Customize blotter")
.build();
natTable.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
colHeaderMenu.dispose();
}
});
}
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerMouseDownBinding(
new MouseEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, 3),
new PopupMenuAction(colHeaderMenu));
}
}
| 1,264 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
PopupMenuBuilder.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/menu/PopupMenuBuilder.java | package net.sourceforge.nattable.ui.menu;
import net.sourceforge.nattable.NatTable;
import org.eclipse.swt.widgets.Menu;
public class PopupMenuBuilder {
NatTable natTable;
Menu popupMenu;
public PopupMenuBuilder(NatTable parent) {
this.natTable = parent;
popupMenu = new Menu(parent.getShell());
}
/**
* Use this to add your own item to the popup menu.
*/
public PopupMenuBuilder withMenuItemProvider(IMenuItemProvider meuItemProvider){
meuItemProvider.addMenuItem(natTable, popupMenu);
return this;
}
public PopupMenuBuilder withHideColumnMenuItem() {
return withMenuItemProvider(MenuItemProviders.hideColumnMenuItemProvider());
}
public PopupMenuBuilder withShowAllColumnsMenuItem() {
return withMenuItemProvider(MenuItemProviders.showAllColumnMenuItemProvider());
}
public PopupMenuBuilder withAutoResizeSelectedColumnsMenuItem() {
return withMenuItemProvider(MenuItemProviders.autoResizeColumnMenuItemProvider());
}
public PopupMenuBuilder withAutoResizeSelectedRowsMenuItem() {
return withMenuItemProvider(MenuItemProviders.autoResizeRowMenuItemProvider());
}
public PopupMenuBuilder withColumnChooserMenuItem() {
return withMenuItemProvider(MenuItemProviders.columnChooserMenuItemProvider());
}
public PopupMenuBuilder withColumnChooserMenuItem(String menuLabel) {
return withMenuItemProvider(MenuItemProviders.columnChooserMenuItemProvider(menuLabel));
}
public PopupMenuBuilder withColumnStyleEditor(String menuLabel) {
return withMenuItemProvider(MenuItemProviders.columnStyleEditorMenuItemProvider(menuLabel));
}
public PopupMenuBuilder withColumnRenameDialog(String menuLabel) {
return withMenuItemProvider(MenuItemProviders.renameColumnMenuItemProvider(menuLabel));
}
public PopupMenuBuilder withCreateColumnGroupsMenuItem() {
return withMenuItemProvider(MenuItemProviders.createColumnGroupMenuItemProvider());
}
public PopupMenuBuilder withUngroupColumnsMenuItem() {
return withMenuItemProvider(MenuItemProviders.ungroupColumnsMenuItemProvider());
}
public PopupMenuBuilder withInspectLabelsMenuItem() {
return withMenuItemProvider(MenuItemProviders.inspectLabelsMenuItemProvider());
}
public PopupMenuBuilder withCategoriesBasesColumnChooser(String menuLabel) {
return withMenuItemProvider(MenuItemProviders.categoriesBasedColumnChooserMenuItemProvider(menuLabel));
}
public PopupMenuBuilder withClearAllFilters(String menuLabel) {
return withMenuItemProvider(MenuItemProviders.clearAllFiltersMenuItemProvider(menuLabel));
}
public PopupMenuBuilder withToggleFilterRow(String menuLabel) {
return withMenuItemProvider(MenuItemProviders.clearToggleFilterRowMenuItemProvider(menuLabel));
}
public PopupMenuBuilder withSeparator(){
return withMenuItemProvider(MenuItemProviders.separatorMenuItemProvider()); }
public Menu build(){
return popupMenu;
}
}
| 2,958 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
MenuItemProviders.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/menu/MenuItemProviders.java | package net.sourceforge.nattable.ui.menu;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.columnCategories.ChooseColumnsFromCategoriesCommand;
import net.sourceforge.nattable.columnChooser.command.DisplayColumnChooserCommand;
import net.sourceforge.nattable.columnRename.DisplayColumnRenameDialogCommand;
import net.sourceforge.nattable.filterrow.command.ClearAllFiltersCommand;
import net.sourceforge.nattable.filterrow.command.ToggleFilterRowCommand;
import net.sourceforge.nattable.group.command.OpenCreateColumnGroupDialog;
import net.sourceforge.nattable.group.command.UngroupColumnCommand;
import net.sourceforge.nattable.hideshow.command.ColumnHideCommand;
import net.sourceforge.nattable.hideshow.command.ShowAllColumnsCommand;
import net.sourceforge.nattable.resize.command.InitializeAutoResizeColumnsCommand;
import net.sourceforge.nattable.resize.command.InitializeAutoResizeRowsCommand;
import net.sourceforge.nattable.style.editor.command.DisplayColumnStyleEditorCommand;
import net.sourceforge.nattable.ui.NatEventData;
import net.sourceforge.nattable.util.GUIHelper;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Widget;
public class MenuItemProviders {
/**
* Walk up the MenuItems (in case they are nested) and find the parent {@link Menu}
*
* @param selectionEvent
* on the {@link MenuItem}
* @return data associated with the parent {@link Menu}
*/
public static NatEventData getNatEventData(SelectionEvent selectionEvent) {
Widget widget = selectionEvent.widget;
if (widget == null || !(widget instanceof MenuItem)) {
return null;
}
MenuItem menuItem = (MenuItem) widget;
Menu parentMenu = menuItem.getParent();
Object data = null;
while (parentMenu != null) {
if (parentMenu.getData() == null) {
parentMenu = parentMenu.getParentMenu();
} else {
data = parentMenu.getData();
break;
}
}
return data != null ? (NatEventData) data : null;
}
public static IMenuItemProvider hideColumnMenuItemProvider() {
return new IMenuItemProvider() {
public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
MenuItem menuItem = new MenuItem(popupMenu, SWT.PUSH);
menuItem.setText("Hide column");
menuItem.setImage(GUIHelper.getImage("hide_column"));
menuItem.setEnabled(true);
menuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
int columnPosition = getNatEventData(event).getColumnPosition();
natTable.doCommand(new ColumnHideCommand(natTable, columnPosition));
}
});
}
};
}
public static IMenuItemProvider showAllColumnMenuItemProvider() {
return new IMenuItemProvider() {
public void addMenuItem(final NatTable natTable, Menu popupMenu) {
MenuItem showAllColumns = new MenuItem(popupMenu, SWT.PUSH);
showAllColumns.setText("Show all columns");
showAllColumns.setImage(GUIHelper.getImage("show_column"));
showAllColumns.setEnabled(true);
showAllColumns.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new ShowAllColumnsCommand());
}
});
}
};
}
public static IMenuItemProvider autoResizeColumnMenuItemProvider() {
return new IMenuItemProvider() {
public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
MenuItem autoResizeColumns = new MenuItem(popupMenu, SWT.PUSH);
autoResizeColumns.setText("Auto resize column");
autoResizeColumns.setImage(GUIHelper.getImage("auto_resize"));
autoResizeColumns.setEnabled(true);
autoResizeColumns.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
int columnPosition = getNatEventData(event).getColumnPosition();
natTable.doCommand(new InitializeAutoResizeColumnsCommand(natTable, columnPosition, natTable.getConfigRegistry(), new GC(natTable)));
}
});
}
};
}
public static IMenuItemProvider autoResizeRowMenuItemProvider() {
return new IMenuItemProvider() {
public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
MenuItem autoResizeRows = new MenuItem(popupMenu, SWT.PUSH);
autoResizeRows.setText("Auto resize row");
autoResizeRows.setEnabled(true);
autoResizeRows.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
int rowPosition = getNatEventData(event).getRowPosition();
natTable.doCommand(new InitializeAutoResizeRowsCommand(natTable, rowPosition, natTable.getConfigRegistry(), new GC(natTable)));
}
});
}
};
}
public static IMenuItemProvider autoResizeAllSelectedColumnMenuItemProvider() {
return new IMenuItemProvider() {
public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
MenuItem autoResizeColumns = new MenuItem(popupMenu, SWT.PUSH);
autoResizeColumns.setText("Auto resize all selected columns");
autoResizeColumns.setEnabled(true);
autoResizeColumns.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
int columnPosition = getNatEventData(event).getColumnPosition();
natTable.doCommand(new InitializeAutoResizeColumnsCommand(natTable, columnPosition, natTable.getConfigRegistry(), new GC(natTable)));
}
});
}
};
}
public static IMenuItemProvider columnChooserMenuItemProvider(final String menuLabel) {
return new IMenuItemProvider() {
public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
MenuItem columnChooser = new MenuItem(popupMenu, SWT.PUSH);
columnChooser.setText(menuLabel);
columnChooser.setImage(GUIHelper.getImage("column_chooser"));
columnChooser.setEnabled(true);
columnChooser.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new DisplayColumnChooserCommand(natTable));
}
});
}
};
}
public static IMenuItemProvider columnChooserMenuItemProvider() {
return columnChooserMenuItemProvider("Choose columns");
}
public static IMenuItemProvider columnStyleEditorMenuItemProvider(final String menuLabel) {
return new IMenuItemProvider() {
public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
MenuItem columnStyleEditor = new MenuItem(popupMenu, SWT.PUSH);
columnStyleEditor.setText(menuLabel);
columnStyleEditor.setImage(GUIHelper.getImage("preferences"));
columnStyleEditor.setEnabled(true);
columnStyleEditor.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
int rowPosition = getNatEventData(event).getRowPosition();
int columnPosition = getNatEventData(event).getColumnPosition();
natTable.doCommand(new DisplayColumnStyleEditorCommand(natTable, natTable.getConfigRegistry(), columnPosition, rowPosition));
}
});
}
};
}
public static IMenuItemProvider renameColumnMenuItemProvider(final String label) {
return new IMenuItemProvider() {
public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
MenuItem menuItem = new MenuItem(popupMenu, SWT.PUSH);
menuItem.setText(label);
menuItem.setEnabled(true);
menuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
natTable.doCommand(new DisplayColumnRenameDialogCommand(natTable, getNatEventData(event).getColumnPosition()));
}
});
}
};
}
public static IMenuItemProvider createColumnGroupMenuItemProvider() {
return new IMenuItemProvider() {
public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
MenuItem columnStyleEditor = new MenuItem(popupMenu, SWT.PUSH);
columnStyleEditor.setText("Create column group");
columnStyleEditor.setEnabled(true);
columnStyleEditor.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new OpenCreateColumnGroupDialog(natTable.getShell()));
}
});
}
};
}
public static IMenuItemProvider ungroupColumnsMenuItemProvider() {
return new IMenuItemProvider() {
public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
MenuItem columnStyleEditor = new MenuItem(popupMenu, SWT.PUSH);
columnStyleEditor.setText("Ungroup columns");
columnStyleEditor.setEnabled(true);
columnStyleEditor.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new UngroupColumnCommand());
}
});
}
};
}
public static IMenuItemProvider inspectLabelsMenuItemProvider() {
return new IMenuItemProvider() {
public void addMenuItem(NatTable natTable, Menu popupMenu) {
MenuItem inspectLabelsMenuItem = new MenuItem(popupMenu, SWT.PUSH);
inspectLabelsMenuItem.setText("Debug info");
inspectLabelsMenuItem.setEnabled(true);
inspectLabelsMenuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
NatEventData natEventData = getNatEventData(e);
NatTable natTable = natEventData.getNatTable();
int columnPosition = natEventData.getColumnPosition();
int rowPosition = natEventData.getRowPosition();
String msg = "Display mode: " + natTable.getDisplayModeByPosition(columnPosition, rowPosition) + "\nConfig labels: "
+ natTable.getConfigLabelsByPosition(columnPosition, rowPosition) + "\nData value: "
+ natTable.getDataValueByPosition(columnPosition, rowPosition) + "\n\nColumn position: " + columnPosition + "\nColumn index: "
+ natTable.getColumnIndexByPosition(columnPosition) + "\n\nRow position: " + rowPosition + "\nRow index: "
+ natTable.getRowIndexByPosition(rowPosition);
MessageBox messageBox = new MessageBox(natTable.getShell(), SWT.ICON_INFORMATION | SWT.OK);
messageBox.setText("Debug Information");
messageBox.setMessage(msg);
messageBox.open();
}
});
}
};
}
public static IMenuItemProvider categoriesBasedColumnChooserMenuItemProvider(final String menuLabel) {
return new IMenuItemProvider() {
public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
MenuItem columnChooser = new MenuItem(popupMenu, SWT.PUSH);
columnChooser.setText(menuLabel);
columnChooser.setImage(GUIHelper.getImage("column_categories_chooser"));
columnChooser.setEnabled(true);
columnChooser.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new ChooseColumnsFromCategoriesCommand(natTable));
}
});
}
};
}
public static IMenuItemProvider clearAllFiltersMenuItemProvider(final String menuLabel) {
return new IMenuItemProvider() {
public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
MenuItem menuItem = new MenuItem(popupMenu, SWT.PUSH);
menuItem.setText(menuLabel);
menuItem.setImage(GUIHelper.getImage("remove_filter"));
menuItem.setEnabled(true);
menuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new ClearAllFiltersCommand());
}
});
}
};
}
public static IMenuItemProvider clearToggleFilterRowMenuItemProvider(final String menuLabel) {
return new IMenuItemProvider() {
public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
MenuItem menuItem = new MenuItem(popupMenu, SWT.PUSH);
menuItem.setText(menuLabel);
menuItem.setImage(GUIHelper.getImage("toggle_filter"));
menuItem.setEnabled(true);
menuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new ToggleFilterRowCommand());
}
});
}
};
}
public static IMenuItemProvider separatorMenuItemProvider() {
return new IMenuItemProvider() {
public void addMenuItem(NatTable natTable, Menu popupMenu) {
new MenuItem(popupMenu, SWT.SEPARATOR);
}
};
}
} | 12,983 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
HeaderMenuConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/menu/HeaderMenuConfiguration.java | package net.sourceforge.nattable.ui.menu;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.config.AbstractUiBindingConfiguration;
import net.sourceforge.nattable.grid.GridRegion;
import net.sourceforge.nattable.ui.binding.UiBindingRegistry;
import net.sourceforge.nattable.ui.matcher.MouseEventMatcher;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Menu;
public class HeaderMenuConfiguration extends AbstractUiBindingConfiguration {
private final Menu colHeaderMenu;
private final Menu rowHeaderMenu;
public enum MenuOptions {HideColumn, ShowColumn};
public HeaderMenuConfiguration(NatTable natTable) {
colHeaderMenu = new PopupMenuBuilder(natTable)
.withHideColumnMenuItem()
.withShowAllColumnsMenuItem()
.withCreateColumnGroupsMenuItem()
.withUngroupColumnsMenuItem()
.withColumnChooserMenuItem()
.withAutoResizeSelectedColumnsMenuItem()
.withColumnStyleEditor("Edit styles")
.withColumnRenameDialog("Rename column")
.withCategoriesBasesColumnChooser("Choose columns")
.withClearAllFilters("Clear all filters")
.build();
rowHeaderMenu = new PopupMenuBuilder(natTable)
.withAutoResizeSelectedRowsMenuItem()
.build();
natTable.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
colHeaderMenu.dispose();
rowHeaderMenu.dispose();
}
});
}
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerMouseDownBinding(
new MouseEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, 3),
new PopupMenuAction(colHeaderMenu));
uiBindingRegistry.registerMouseDownBinding(
new MouseEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, 3),
new PopupMenuAction(rowHeaderMenu));
}
}
| 1,983 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
PopupMenuAction.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/menu/PopupMenuAction.java | package net.sourceforge.nattable.ui.menu;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.ui.action.IMouseAction;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.widgets.Menu;
public class PopupMenuAction implements IMouseAction {
private Menu menu;
public PopupMenuAction(Menu menu) {
this.menu = menu;
}
public void run(NatTable natTable, MouseEvent event) {
menu.setData(event.data);
menu.setVisible(true);
}
} | 496 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ClearCursorAction.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/action/ClearCursorAction.java | package net.sourceforge.nattable.ui.action;
import net.sourceforge.nattable.NatTable;
import org.eclipse.swt.events.MouseEvent;
public class ClearCursorAction implements IMouseAction {
public void run(NatTable natTable, MouseEvent event) {
natTable.setCursor(null);
}
}
| 293 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IKeyAction.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/action/IKeyAction.java | package net.sourceforge.nattable.ui.action;
import net.sourceforge.nattable.NatTable;
import org.eclipse.swt.events.KeyEvent;
public interface IKeyAction {
public void run(NatTable natTable, KeyEvent event);
}
| 228 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IDragMode.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/action/IDragMode.java | package net.sourceforge.nattable.ui.action;
import net.sourceforge.nattable.NatTable;
import org.eclipse.swt.events.MouseEvent;
public interface IDragMode {
public void mouseDown(NatTable natTable, MouseEvent event);
public void mouseMove(NatTable natTable, MouseEvent event);
public void mouseUp(NatTable natTable, MouseEvent event);
}
| 365 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DragModeEventHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/action/DragModeEventHandler.java | package net.sourceforge.nattable.ui.action;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.ui.mode.AbstractModeEventHandler;
import net.sourceforge.nattable.ui.mode.Mode;
import net.sourceforge.nattable.ui.mode.ModeSupport;
import org.eclipse.swt.events.MouseEvent;
public class DragModeEventHandler extends AbstractModeEventHandler {
private final NatTable natTable;
private final IDragMode dragMode;
public DragModeEventHandler(ModeSupport modeSupport, NatTable natTable, IDragMode dragMode) {
super(modeSupport);
this.natTable = natTable;
this.dragMode = dragMode;
}
@Override
public void mouseMove(MouseEvent event) {
dragMode.mouseMove(natTable, event);
}
@Override
public void mouseUp(MouseEvent event) {
dragMode.mouseUp(natTable, event);
switchMode(Mode.NORMAL_MODE);
}
}
| 880 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IMouseAction.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/action/IMouseAction.java | package net.sourceforge.nattable.ui.action;
import net.sourceforge.nattable.NatTable;
import org.eclipse.swt.events.MouseEvent;
public interface IMouseAction {
public void run(NatTable natTable, MouseEvent event);
}
| 234 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
NoOpMouseAction.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/action/NoOpMouseAction.java | package net.sourceforge.nattable.ui.action;
import net.sourceforge.nattable.NatTable;
import org.eclipse.swt.events.MouseEvent;
public class NoOpMouseAction implements IMouseAction {
public void run(NatTable natTable, MouseEvent event) {}
}
| 258 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IMouseEventMatcher.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/matcher/IMouseEventMatcher.java | package net.sourceforge.nattable.ui.matcher;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.layer.LabelStack;
import org.eclipse.swt.events.MouseEvent;
public interface IMouseEventMatcher {
/**
* Figures out if the mouse event occured in the suplied region.
*
* @param event SWT mouse event
* @param region Region object indicating a regoin of the NatTable display area. Example: body, header etc.
*/
public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels);
}
| 553 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IKeyEventMatcher.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/matcher/IKeyEventMatcher.java | package net.sourceforge.nattable.ui.matcher;
import org.eclipse.swt.events.KeyEvent;
/**
* Determines if a SWT {@link KeyEvent} matches the given criteria.
*/
public interface IKeyEventMatcher {
public boolean matches(KeyEvent event);
}
| 257 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
BodyCellEditorMouseEventMatcher.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/matcher/BodyCellEditorMouseEventMatcher.java | package net.sourceforge.nattable.ui.matcher;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.edit.EditConfigAttributes;
import net.sourceforge.nattable.edit.editor.ICellEditor;
import net.sourceforge.nattable.grid.GridRegion;
import net.sourceforge.nattable.layer.LabelStack;
import net.sourceforge.nattable.layer.cell.LayerCell;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.eclipse.swt.events.MouseEvent;
public class BodyCellEditorMouseEventMatcher implements IMouseEventMatcher {
private Class<?> cellEditorClass;
public BodyCellEditorMouseEventMatcher(Class<?> cellEditorClass) {
this.cellEditorClass = cellEditorClass;
}
public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels) {
if (regionLabels != null && regionLabels.hasLabel(GridRegion.BODY)) {
LayerCell cell = natTable.getCellByPosition(natTable.getColumnPositionByX(event.x), natTable.getRowPositionByY(event.y));
ICellEditor cellEditor = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CELL_EDITOR, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
if (cellEditorClass.isInstance(cellEditor)) {
return true;
}
}
return false;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof BodyCellEditorMouseEventMatcher == false) {
return false;
}
if (this == obj) {
return true;
}
BodyCellEditorMouseEventMatcher rhs = (BodyCellEditorMouseEventMatcher) obj;
return new EqualsBuilder()
.append(cellEditorClass, rhs.cellEditorClass)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(43, 21)
.append(cellEditorClass)
.toHashCode();
}
}
| 1,847 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
CellLabelMouseEventMatcher.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/matcher/CellLabelMouseEventMatcher.java | package net.sourceforge.nattable.ui.matcher;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.layer.LabelStack;
import net.sourceforge.nattable.ui.NatEventData;
import org.eclipse.swt.events.MouseEvent;
/**
* Matches mouse clicks on cells to which a specified configuration label has been applied.
*/
public class CellLabelMouseEventMatcher extends MouseEventMatcher {
private final String labelToMatch;
public CellLabelMouseEventMatcher(String regionName, int button, String labelToMatch) {
super(regionName, button);
this.labelToMatch = labelToMatch;
}
public CellLabelMouseEventMatcher(int stateMask, String regionName, int button, String labelToMatch) {
super(stateMask, regionName, button);
this.labelToMatch = labelToMatch;
}
@Override
public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels) {
NatEventData eventData = NatEventData.createInstanceFromEvent(event);
LabelStack customLabels = natTable.getConfigLabelsByPosition(eventData.getColumnPosition(), eventData.getRowPosition());
return super.matches(natTable, event, regionLabels) && customLabels.getLabels().contains(labelToMatch);
}
}
| 1,220 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
LetterOrDigitKeyEventMatcher.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/matcher/LetterOrDigitKeyEventMatcher.java | package net.sourceforge.nattable.ui.matcher;
import org.eclipse.swt.events.KeyEvent;
public class LetterOrDigitKeyEventMatcher implements IKeyEventMatcher {
public static boolean isLetterOrDigit(char character) {
return Character.isLetterOrDigit(character) || character == '.';
}
public boolean matches(KeyEvent event) {
return isLetterOrDigit(event.character);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof LetterOrDigitKeyEventMatcher == false) {
return false;
}
return true;
}
public int hashCode() {
return 317;
}
}
| 606 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
KeyEventMatcher.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/matcher/KeyEventMatcher.java | package net.sourceforge.nattable.ui.matcher;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.eclipse.swt.events.KeyEvent;
public class KeyEventMatcher implements IKeyEventMatcher {
private int stateMask;
private int keyCode;
public KeyEventMatcher(int keyCode) {
this(0, keyCode);
}
public KeyEventMatcher(int stateMask, int keyCode) {
this.stateMask = stateMask;
this.keyCode = keyCode;
}
public int getStateMask() {
return stateMask;
}
public int getKeyCode() {
return keyCode;
}
public boolean matches(KeyEvent event) {
boolean stateMaskMatches = stateMask == event.stateMask;
boolean keyCodeMatches = keyCode == event.keyCode;
return stateMaskMatches && keyCodeMatches;
}
public boolean equals(Object obj) {
if (obj instanceof KeyEventMatcher == false) {
return false;
}
if (this == obj) {
return true;
}
KeyEventMatcher rhs = (KeyEventMatcher) obj;
return new EqualsBuilder()
.append(stateMask, rhs.stateMask)
.append(keyCode, rhs.keyCode)
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder(71, 7)
.append(stateMask)
.append(keyCode)
.toHashCode();
}
}
| 1,316 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
MouseEventMatcher.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/matcher/MouseEventMatcher.java | package net.sourceforge.nattable.ui.matcher;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.grid.GridRegion;
import net.sourceforge.nattable.layer.LabelStack;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.eclipse.swt.events.MouseEvent;
public class MouseEventMatcher implements IMouseEventMatcher {
public static final int LEFT_BUTTON = 1;
public static final int RIGHT_BUTTON = 3;
private final int stateMask;
private final String regionName;
private final int button;
public MouseEventMatcher() {
this(0, null, 0);
}
public MouseEventMatcher(String eventRegionName) {
this(0, eventRegionName, 0);
}
public MouseEventMatcher(String eventRegion, int button) {
this(0, eventRegion, button);
}
/**
* Constructor
* @param stateMask @see "org.eclipse.swt.events.MouseEvent.stateMask"
* @param eventRegion {@linkplain net.sourceforge.nattable.grid.GridRegionEnum}
* @param button @see "org.eclipse.swt.events.MouseEvent.button"<br/>
* {@link MouseEventMatcher#LEFT_BUTTON}, {@link MouseEventMatcher#RIGHT_BUTTON}
* can be used for convenience
*/
public MouseEventMatcher(int stateMask, String eventRegion, int button) {
this.stateMask = stateMask;
this.regionName = eventRegion;
this.button = button;
}
public boolean matches(NatTable natTable, MouseEvent event, LabelStack regionLabels) {
if (regionLabels == null) {
return false;
}
boolean stateMaskMatches;
if (stateMask != 0) {
stateMaskMatches = (event.stateMask == stateMask) ? true : false;
} else {
stateMaskMatches = event.stateMask == 0;
}
boolean eventRegionMatches;
if (this.regionName != null) {
eventRegionMatches = regionLabels.hasLabel(regionName);
} else {
eventRegionMatches = true;
}
boolean buttonMatches = button == event.button;
return stateMaskMatches && eventRegionMatches && buttonMatches;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof MouseEventMatcher == false) {
return false;
}
if (this == obj) {
return true;
}
MouseEventMatcher rhs = (MouseEventMatcher) obj;
return new EqualsBuilder()
.append(stateMask, rhs.stateMask)
.append(regionName, rhs.regionName)
.append(button, rhs.button)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(43, 21)
.append(stateMask)
.append(regionName)
.append(button)
.toHashCode();
}
public int getStateMask() {
return stateMask;
}
public String getEventRegion() {
return regionName;
}
public int getButton() {
return button;
}
public static MouseEventMatcher columnHeaderLeftClick(int mask) {
return new MouseEventMatcher(mask, GridRegion.COLUMN_HEADER, LEFT_BUTTON);
}
public static MouseEventMatcher rowHeaderLeftClick(int mask) {
return new MouseEventMatcher(mask, GridRegion.ROW_HEADER, LEFT_BUTTON);
}
public static MouseEventMatcher bodyLeftClick(int mask) {
return new MouseEventMatcher(mask, GridRegion.BODY, LEFT_BUTTON);
}
public static MouseEventMatcher columnGroupHeaderLeftClick(int mask) {
return new MouseEventMatcher(mask, GridRegion.COLUMN_GROUP_HEADER, LEFT_BUTTON);
}
}
| 3,377 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
MouseModeEventHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/mode/MouseModeEventHandler.java | package net.sourceforge.nattable.ui.mode;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.ui.NatEventData;
import net.sourceforge.nattable.ui.action.DragModeEventHandler;
import net.sourceforge.nattable.ui.action.IDragMode;
import net.sourceforge.nattable.ui.action.IMouseAction;
import net.sourceforge.nattable.ui.util.CancelableRunnable;
import org.eclipse.swt.events.MouseEvent;
public class MouseModeEventHandler extends AbstractModeEventHandler {
private final NatTable natTable;
private MouseEvent initialMouseDownEvent;
private IMouseAction singleClickAction;
private IMouseAction doubleClickAction;
private boolean mouseDown;
private IDragMode dragMode;
private SingleClickRunnable singleClickRunnable;
// TODO Placeholder to enable single/double click disambiguation
private boolean exclusive = false;
public MouseModeEventHandler(ModeSupport modeSupport, NatTable natTable, MouseEvent initialMouseDownEvent, IMouseAction singleClickAction, IMouseAction doubleClickAction, IDragMode dragMode) {
super(modeSupport);
this.natTable = natTable;
mouseDown = true;
this.initialMouseDownEvent = initialMouseDownEvent;
this.singleClickAction = singleClickAction;
this.doubleClickAction = doubleClickAction;
this.dragMode = dragMode;
}
@Override
public void mouseUp(MouseEvent event) {
mouseDown = false;
if (singleClickAction != null) {
if (exclusive && doubleClickAction != null) {
// If a doubleClick action is registered, wait to see if this mouseUp is part of a doubleClick or not.
singleClickRunnable = new SingleClickRunnable(singleClickAction, event);
event.display.timerExec(event.display.getDoubleClickTime(), singleClickRunnable);
} else {
executeSingleClickAction(singleClickAction, event);
}
} else if (doubleClickAction == null) {
// No single or double click action registered when mouseUp detected. Switch back to normal mode.
switchMode(Mode.NORMAL_MODE);
}
}
@Override
public void mouseDoubleClick(MouseEvent event) {
if (doubleClickAction != null) {
if (singleClickRunnable != null) {
// Cancel any pending singleClick action.
singleClickRunnable.cancel();
}
event.data = NatEventData.createInstanceFromEvent(event);
doubleClickAction.run(natTable, event);
// Double click action complete. Switch back to normal mode.
switchMode(Mode.NORMAL_MODE);
}
}
@Override
public synchronized void mouseMove(MouseEvent event) {
if (mouseDown && dragMode != null) {
dragMode.mouseDown(natTable, initialMouseDownEvent);
switchMode(new DragModeEventHandler(getModeSupport(), natTable, dragMode));
} else {
// No drag mode registered when mouseMove detected. Switch back to normal mode.
switchMode(Mode.NORMAL_MODE);
}
}
private void executeSingleClickAction(IMouseAction action, MouseEvent event) {
event.data = NatEventData.createInstanceFromEvent(event);
action.run(natTable, event);
// Single click action complete. Switch back to normal mode.
switchMode(Mode.NORMAL_MODE);
}
class SingleClickRunnable extends CancelableRunnable {
private IMouseAction action;
private MouseEvent event;
public SingleClickRunnable(IMouseAction action, MouseEvent event) {
this.action = action;
this.event = event;
}
public void run() {
if (!isCancelled()) {
executeSingleClickAction(action, event);
}
}
}
}
| 3,564 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ModeSupport.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/mode/ModeSupport.java | package net.sourceforge.nattable.ui.mode;
import java.util.HashMap;
import java.util.Map;
import net.sourceforge.nattable.NatTable;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
/**
* Modal event handler for NatTable. This class acts as a proxy event listener.
* It manages a set of IModeEventHandler instances which control the actual
* event handling for a given mode. This allows the event handling behavior for
* different modes to be grouped together and isolated from each other.
*/
public class ModeSupport implements KeyListener, MouseListener,
MouseMoveListener, FocusListener {
private Map<String, IModeEventHandler> modeEventHandlerMap = new HashMap<String, IModeEventHandler>();
private IModeEventHandler currentModeEventHandler;
public ModeSupport(NatTable natTable) {
natTable.addKeyListener(this);
natTable.addMouseListener(this);
natTable.addMouseMoveListener(this);
natTable.addFocusListener(this);
}
/**
* Register an event handler to handle events for a given mode.
*
* @param mode
* The mode.
* @param modeEventHandler
* An IModeEventHandler instance that will handle events in the
* given mode.
*
* @see IModeEventHandler
*/
public void registerModeEventHandler(String mode,
IModeEventHandler modeEventHandler) {
modeEventHandlerMap.put(mode, modeEventHandler);
}
/**
* Switch to the given mode.
*
* @param mode
* The target mode to switch to.
*/
public void switchMode(String mode) {
if (currentModeEventHandler != null) {
currentModeEventHandler.cleanup();
}
currentModeEventHandler = modeEventHandlerMap.get(mode);
}
public void switchMode(IModeEventHandler modeEventHandler) {
if (currentModeEventHandler != null) {
currentModeEventHandler.cleanup();
}
currentModeEventHandler = modeEventHandler;
}
public void keyPressed(KeyEvent event) {
currentModeEventHandler.keyPressed(event);
}
public void keyReleased(KeyEvent event) {
currentModeEventHandler.keyReleased(event);
}
public void mouseDoubleClick(MouseEvent event) {
currentModeEventHandler.mouseDoubleClick(event);
}
public void mouseDown(MouseEvent event) {
currentModeEventHandler.mouseDown(event);
}
public void mouseUp(MouseEvent event) {
currentModeEventHandler.mouseUp(event);
}
public void mouseMove(MouseEvent event) {
currentModeEventHandler.mouseMove(event);
}
public void focusGained(FocusEvent event) {
currentModeEventHandler.focusGained(event);
}
public void focusLost(FocusEvent event) {
currentModeEventHandler.focusLost(event);
}
}
| 2,973 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
Mode.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/mode/Mode.java | package net.sourceforge.nattable.ui.mode;
public interface Mode {
public static final String NORMAL_MODE = "NORMAL_MODE";
public static final String COLUMN_RESIZE_MODE = "COLUMN_RESIZE_MODE";
public static final String COLUMN_SORT_MODE = "COLUMN_SORT_MODE";
public static final String COLUMN_REORDER_MODE = "COLUMN_REORDER_MODE";
public static final String COLUMN_HEADER_MODE = "COLUMN_HEADER_MODE";
public static final String COLUMN_GROUP_MODE = "COLUMN_GROUP_MODE";
public static final String ROW_RESIZE_MODE = "ROW_RESIZE_MODE";
public static final String MOUSE_SELECTION_MODE = "MOUSE_SELECTION_MODE";
}
| 634 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ConfigurableModeEventHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/mode/ConfigurableModeEventHandler.java | package net.sourceforge.nattable.ui.mode;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.ui.NatEventData;
import net.sourceforge.nattable.ui.action.IDragMode;
import net.sourceforge.nattable.ui.action.IKeyAction;
import net.sourceforge.nattable.ui.action.IMouseAction;
import net.sourceforge.nattable.ui.binding.IUiBindingRegistry;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseEvent;
public class ConfigurableModeEventHandler extends AbstractModeEventHandler {
private final NatTable natTable;
private IUiBindingRegistry uiBindingRegistry;
public ConfigurableModeEventHandler(ModeSupport modeSupport, NatTable natTable) {
super(modeSupport);
this.natTable = natTable;
this.uiBindingRegistry = natTable.getUiBindingRegistry();
}
// Event handling /////////////////////////////////////////////////////////
@Override
public void keyPressed(KeyEvent event) {
IKeyAction keyAction = uiBindingRegistry.getKeyEventAction(event);
if (keyAction != null) {
natTable.forceFocus();
keyAction.run(natTable, event);
}
}
@Override
public void mouseDown(MouseEvent event) {
IMouseAction mouseDownAction = uiBindingRegistry.getMouseDownAction(event);
if (mouseDownAction != null) {
event.data = NatEventData.createInstanceFromEvent(event);
mouseDownAction.run(natTable, event);
}
IMouseAction singleClickAction = uiBindingRegistry.getSingleClickAction(event);
IMouseAction doubleClickAction = uiBindingRegistry.getDoubleClickAction(event);
IDragMode dragMode = uiBindingRegistry.getDragMode(event);
if (singleClickAction != null || doubleClickAction != null || dragMode != null) {
switchMode(new MouseModeEventHandler(getModeSupport(), natTable, event, singleClickAction, doubleClickAction, dragMode));
}
}
@Override
public synchronized void mouseMove(MouseEvent event) {
IMouseAction mouseMoveAction = uiBindingRegistry.getMouseMoveAction(event);
if (mouseMoveAction != null) {
event.data = NatEventData.createInstanceFromEvent(event);
mouseMoveAction.run(natTable, event);
}
}
}
| 2,178 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AbstractModeEventHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/mode/AbstractModeEventHandler.java | package net.sourceforge.nattable.ui.mode;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseEvent;
public class AbstractModeEventHandler implements IModeEventHandler {
private ModeSupport modeSupport;
public AbstractModeEventHandler(ModeSupport modeSupport) {
this.modeSupport = modeSupport;
}
protected ModeSupport getModeSupport() {
return modeSupport;
}
protected void switchMode(String mode) {
modeSupport.switchMode(mode);
}
protected void switchMode(IModeEventHandler modeEventHandler) {
modeSupport.switchMode(modeEventHandler);
}
public void cleanup() {
}
public void keyPressed(KeyEvent event) {
}
public void keyReleased(KeyEvent event) {
}
public void mouseDoubleClick(MouseEvent event) {
}
public void mouseDown(MouseEvent event) {
}
public void mouseUp(MouseEvent event) {
}
public void mouseMove(MouseEvent event) {
}
public void focusGained(FocusEvent event) {
}
public void focusLost(FocusEvent event) {
switchMode(Mode.NORMAL_MODE);
}
}
| 1,138 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IModeEventHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/mode/IModeEventHandler.java | package net.sourceforge.nattable.ui.mode;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
public interface IModeEventHandler extends KeyListener, MouseListener, MouseMoveListener, FocusListener {
public void cleanup();
}
| 373 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
KeyBinding.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/binding/KeyBinding.java | package net.sourceforge.nattable.ui.binding;
import net.sourceforge.nattable.ui.action.IKeyAction;
import net.sourceforge.nattable.ui.matcher.IKeyEventMatcher;
public class KeyBinding {
private IKeyEventMatcher keyEventMatcher;
private IKeyAction action;
public KeyBinding(IKeyEventMatcher keyEventMatcher, IKeyAction action) {
this.keyEventMatcher = keyEventMatcher;
this.action = action;
}
public IKeyEventMatcher getKeyEventMatcher() {
return keyEventMatcher;
}
public IKeyAction getAction() {
return action;
}
}
| 570 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IUiBindingRegistry.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/binding/IUiBindingRegistry.java | package net.sourceforge.nattable.ui.binding;
import net.sourceforge.nattable.ui.action.IDragMode;
import net.sourceforge.nattable.ui.action.IKeyAction;
import net.sourceforge.nattable.ui.action.IMouseAction;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseEvent;
public interface IUiBindingRegistry {
public IKeyAction getKeyEventAction(KeyEvent event);
public IDragMode getDragMode(MouseEvent event);
public IMouseAction getMouseMoveAction(MouseEvent event);
public IMouseAction getMouseDownAction(MouseEvent event);
public IMouseAction getSingleClickAction(MouseEvent event);
public IMouseAction getDoubleClickAction(MouseEvent event);
}
| 713 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DragBinding.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/binding/DragBinding.java | package net.sourceforge.nattable.ui.binding;
import net.sourceforge.nattable.ui.action.IDragMode;
import net.sourceforge.nattable.ui.matcher.IMouseEventMatcher;
public class DragBinding {
private IMouseEventMatcher mouseEventMatcher;
private IDragMode dragMode;
public DragBinding(IMouseEventMatcher mouseEventMatcher, IDragMode dragMode) {
this.mouseEventMatcher = mouseEventMatcher;
this.dragMode = dragMode;
}
public IMouseEventMatcher getMouseEventMatcher() {
return mouseEventMatcher;
}
public IDragMode getDragMode() {
return dragMode;
}
}
| 601 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
UiBindingRegistry.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/binding/UiBindingRegistry.java | package net.sourceforge.nattable.ui.binding;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.layer.LabelStack;
import net.sourceforge.nattable.ui.action.IDragMode;
import net.sourceforge.nattable.ui.action.IKeyAction;
import net.sourceforge.nattable.ui.action.IMouseAction;
import net.sourceforge.nattable.ui.matcher.IKeyEventMatcher;
import net.sourceforge.nattable.ui.matcher.IMouseEventMatcher;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseEvent;
public class UiBindingRegistry implements IUiBindingRegistry {
private NatTable natTable;
private LinkedList<KeyBinding> keyBindings = new LinkedList<KeyBinding>();
private Map<MouseEventTypeEnum, LinkedList<MouseBinding>> mouseBindingsMap = new HashMap<MouseEventTypeEnum, LinkedList<MouseBinding>>();
private LinkedList<DragBinding> dragBindings = new LinkedList<DragBinding>();
public UiBindingRegistry(NatTable natTable) {
this.natTable = natTable;
}
// Lookup /////////////////////////////////////////////////////////////////
public IKeyAction getKeyEventAction(KeyEvent event) {
for (KeyBinding keyBinding : keyBindings) {
if (keyBinding.getKeyEventMatcher().matches(event)) {
return keyBinding.getAction();
}
}
return null;
}
public IDragMode getDragMode(MouseEvent event) {
LabelStack regionLabels = natTable.getRegionLabelsByXY(event.x, event.y);
for (DragBinding dragBinding : dragBindings) {
if (dragBinding.getMouseEventMatcher().matches(natTable, event, regionLabels)) {
return dragBinding.getDragMode();
}
}
return null;
}
public IMouseAction getMouseMoveAction(MouseEvent event) {
return getMouseEventAction(MouseEventTypeEnum.MOUSE_MOVE, event);
}
public IMouseAction getMouseDownAction(MouseEvent event) {
return getMouseEventAction(MouseEventTypeEnum.MOUSE_DOWN, event);
}
public IMouseAction getSingleClickAction(MouseEvent event) {
return getMouseEventAction(MouseEventTypeEnum.MOUSE_SINGLE_CLICK, event);
}
public IMouseAction getDoubleClickAction(MouseEvent event) {
return getMouseEventAction(MouseEventTypeEnum.MOUSE_DOUBLE_CLICK, event);
}
///////////////////////////////////////////////////////////////////////////
private IMouseAction getMouseEventAction(MouseEventTypeEnum mouseEventType, MouseEvent event) {
// TODO: This code can be made more performant by mapping mouse bindings not only to the mouseEventType but
// also to the region that they are interested in. That way, given an area and an event we can narrow down the
// list of mouse bindings that need to be searched. -- Azubuko.Obele
try {
LinkedList<MouseBinding> mouseEventBindings = mouseBindingsMap.get(mouseEventType);
if (mouseEventBindings != null) {
LabelStack regionLabels = natTable.getRegionLabelsByXY(event.x, event.y);
for (MouseBinding mouseBinding : mouseEventBindings) {
if (mouseBinding.getMouseEventMatcher().matches(natTable, event, regionLabels)) {
return mouseBinding.getAction();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
// Registration ///////////////////////////////////////////////////////////
// Key
public void registerFirstKeyBinding(IKeyEventMatcher keyMatcher, IKeyAction action) {
keyBindings.addFirst(new KeyBinding(keyMatcher, action));
}
public void registerKeyBinding(IKeyEventMatcher keyMatcher, IKeyAction action) {
keyBindings.addLast(new KeyBinding(keyMatcher, action));
}
public void unregisterKeyBinding(IKeyEventMatcher keyMatcher) {
for (KeyBinding keyBinding : keyBindings) {
if (keyBinding.getKeyEventMatcher().equals(keyMatcher)) {
keyBindings.remove(keyBinding);
return;
}
}
}
// Drag
public void registerFirstMouseDragMode(IMouseEventMatcher mouseEventMatcher, IDragMode dragMode) {
dragBindings.addFirst(new DragBinding(mouseEventMatcher, dragMode));
}
public void registerMouseDragMode(IMouseEventMatcher mouseEventMatcher, IDragMode dragMode) {
dragBindings.addLast(new DragBinding(mouseEventMatcher, dragMode));
}
public void unregisterMouseDragMode(IMouseEventMatcher mouseEventMatcher) {
for (DragBinding dragBinding : dragBindings) {
if (dragBinding.getMouseEventMatcher().equals(mouseEventMatcher)) {
dragBindings.remove(dragBinding);
return;
}
}
}
// Mouse move
public void registerFirstMouseMoveBinding(IMouseEventMatcher mouseEventMatcher, IMouseAction action) {
registerMouseBinding(true, MouseEventTypeEnum.MOUSE_MOVE, mouseEventMatcher, action);
}
public void registerMouseMoveBinding(IMouseEventMatcher mouseEventMatcher, IMouseAction action) {
registerMouseBinding(false, MouseEventTypeEnum.MOUSE_MOVE, mouseEventMatcher, action);
}
public void unregisterMouseMoveBinding(IMouseEventMatcher mouseEventMatcher) {
unregisterMouseBinding(MouseEventTypeEnum.MOUSE_MOVE, mouseEventMatcher);
}
// Mouse down
public void registerFirstMouseDownBinding(IMouseEventMatcher mouseEventMatcher, IMouseAction action) {
registerMouseBinding(true, MouseEventTypeEnum.MOUSE_DOWN, mouseEventMatcher, action);
}
public void registerMouseDownBinding(IMouseEventMatcher mouseEventMatcher, IMouseAction action) {
registerMouseBinding(false, MouseEventTypeEnum.MOUSE_DOWN, mouseEventMatcher, action);
}
public void unregisterMouseDownBinding(IMouseEventMatcher mouseEventMatcher) {
unregisterMouseBinding(MouseEventTypeEnum.MOUSE_DOWN, mouseEventMatcher);
}
// Single click
public void registerFirstSingleClickBinding(IMouseEventMatcher mouseEventMatcher, IMouseAction action) {
registerMouseBinding(true, MouseEventTypeEnum.MOUSE_SINGLE_CLICK, mouseEventMatcher, action);
}
public void registerSingleClickBinding(IMouseEventMatcher mouseEventMatcher, IMouseAction action) {
registerMouseBinding(false, MouseEventTypeEnum.MOUSE_SINGLE_CLICK, mouseEventMatcher, action);
}
public void unregisterSingleClickBinding(IMouseEventMatcher mouseEventMatcher) {
unregisterMouseBinding(MouseEventTypeEnum.MOUSE_SINGLE_CLICK, mouseEventMatcher);
}
// Double click
public void registerFirstDoubleClickBinding(IMouseEventMatcher mouseEventMatcher, IMouseAction action) {
registerMouseBinding(true, MouseEventTypeEnum.MOUSE_DOUBLE_CLICK, mouseEventMatcher, action);
}
public void registerDoubleClickBinding(IMouseEventMatcher mouseEventMatcher, IMouseAction action) {
registerMouseBinding(false, MouseEventTypeEnum.MOUSE_DOUBLE_CLICK, mouseEventMatcher, action);
}
public void unregisterDoubleClickBinding(IMouseEventMatcher mouseEventMatcher) {
unregisterMouseBinding(MouseEventTypeEnum.MOUSE_DOUBLE_CLICK, mouseEventMatcher);
}
///////////////////////////////////////////////////////////////////////////
private void registerMouseBinding(boolean first, MouseEventTypeEnum mouseEventType, IMouseEventMatcher mouseEventMatcher, IMouseAction action) {
LinkedList<MouseBinding> mouseEventBindings = mouseBindingsMap.get(mouseEventType);
if (mouseEventBindings == null) {
mouseEventBindings = new LinkedList<MouseBinding>();
mouseBindingsMap.put(mouseEventType, mouseEventBindings);
}
if (first) {
mouseEventBindings.addFirst(new MouseBinding(mouseEventMatcher, action));
} else {
mouseEventBindings.addLast(new MouseBinding(mouseEventMatcher, action));
}
}
private void unregisterMouseBinding(MouseEventTypeEnum mouseEventType, IMouseEventMatcher mouseEventMatcher) {
LinkedList<MouseBinding> mouseBindings = mouseBindingsMap.get(mouseEventType);
for (MouseBinding mouseBinding : mouseBindings) {
if (mouseBinding.getMouseEventMatcher().equals(mouseEventMatcher)) {
mouseBindings.remove(mouseBinding);
return;
}
}
}
private enum MouseEventTypeEnum {
MOUSE_DOWN,
MOUSE_MOVE,
MOUSE_SINGLE_CLICK,
MOUSE_DOUBLE_CLICK
}
}
| 8,252 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
MouseBinding.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/binding/MouseBinding.java | package net.sourceforge.nattable.ui.binding;
import net.sourceforge.nattable.ui.action.IMouseAction;
import net.sourceforge.nattable.ui.matcher.IMouseEventMatcher;
public class MouseBinding {
private IMouseEventMatcher mouseEventMatcher;
private IMouseAction action;
public MouseBinding(IMouseEventMatcher mouseEventMatcher, IMouseAction action) {
this.mouseEventMatcher = mouseEventMatcher;
this.action = action;
}
public IMouseEventMatcher getMouseEventMatcher() {
return mouseEventMatcher;
}
public IMouseAction getAction() {
return action;
}
@Override
public String toString() {
return getClass().getSimpleName() + "[mouseEventMatcher=" + mouseEventMatcher + " action=" + action + "]";
}
}
| 764 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
CellEdgeEnum.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/util/CellEdgeEnum.java | package net.sourceforge.nattable.ui.util;
public enum CellEdgeEnum {
LEFT,
RIGHT,
TOP,
BOTTOM,
NONE
}
| 117 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
CancelableRunnable.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/util/CancelableRunnable.java | package net.sourceforge.nattable.ui.util;
import java.util.concurrent.atomic.AtomicBoolean;
public abstract class CancelableRunnable implements Runnable {
private final AtomicBoolean cancel = new AtomicBoolean(false);
public void cancel() {
cancel.set(true);
}
protected final boolean isCancelled() {
return cancel.get();
}
}
| 361 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
CellEdgeDetectUtil.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/ui/util/CellEdgeDetectUtil.java | package net.sourceforge.nattable.ui.util;
import static net.sourceforge.nattable.ui.util.CellEdgeEnum.BOTTOM;
import static net.sourceforge.nattable.ui.util.CellEdgeEnum.LEFT;
import static net.sourceforge.nattable.ui.util.CellEdgeEnum.NONE;
import static net.sourceforge.nattable.ui.util.CellEdgeEnum.RIGHT;
import static net.sourceforge.nattable.ui.util.CellEdgeEnum.TOP;
import static net.sourceforge.nattable.util.GUIHelper.DEFAULT_RESIZE_HANDLE_SIZE;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.cell.LayerCell;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
public class CellEdgeDetectUtil {
/**
* Calculate the column position to resize depending on the cursor's position
* on the left/right edges of the cell.
* Does <i>not</i> take into account columns which are not allowed to be resized.
*/
public static int getColumnPositionToResize(ILayer layer, Point clickPoint) {
int columnPosition = layer.getColumnPositionByX(clickPoint.x);
if (columnPosition >= 0) {
switch (getHorizontalCellEdge(layer, clickPoint, DEFAULT_RESIZE_HANDLE_SIZE)) {
case LEFT:
if (columnPosition == 1) {
// can't resize left edge of first column
break;
}
return columnPosition - 1;
case RIGHT:
return columnPosition;
}
}
return -1;
}
/**
* Calculate the row position to resize depending on the cursor's position
* on the top/bottom edges of the cell.
* Does not take into account rows which are not allowed to be resized.
*/
public static int getRowPositionToResize(ILayer layer, Point clickPt) {
int rowPosition = layer.getRowPositionByY(clickPt.y);
if (rowPosition >= 0) {
switch (getVerticalCellEdge(layer, clickPt, DEFAULT_RESIZE_HANDLE_SIZE)) {
case TOP:
if (rowPosition == 1) {
// can't resize top edge of first row
break;
}
return rowPosition - 1;
case BOTTOM:
return rowPosition;
}
}
return -1;
}
/**
* Gets the edge (left/right) of the cell which is closer to the click point.
* @param cellBounds bounds of the cell containing the click
* @param clickPt usually the coordinates of a mouse click
*/
public static CellEdgeEnum getHorizontalCellEdge(Rectangle cellBounds, Point clickPt) {
return getHorizontalCellEdge(cellBounds, clickPt, -1);
}
public static CellEdgeEnum getHorizontalCellEdge(ILayer layer, Point clickPt) {
return getHorizontalCellEdge(layer, clickPt, -1);
}
public static CellEdgeEnum getHorizontalCellEdge(ILayer layer, Point clickPt, int handleWidth) {
LayerCell cell = layer.getCellByPosition(
layer.getColumnPositionByX(clickPt.x),
layer.getRowPositionByY(clickPt.y)
);
if (cell != null) {
return getHorizontalCellEdge(cell.getBounds(), clickPt, handleWidth);
} else {
return CellEdgeEnum.NONE;
}
}
/**
* Figure out if the click point is closer to the left/right edge of the cell.
* @param cellBounds of the table cell containing the click
* @param clickPt
* @param distanceFromEdge distance from the edge to qualify as <i>close</i> to the cell edge
*/
public static CellEdgeEnum getHorizontalCellEdge(Rectangle cellBounds, Point clickPt, int distanceFromEdge) {
if (distanceFromEdge < 0) {
distanceFromEdge = cellBounds.width / 2;
}
Rectangle left = new Rectangle(cellBounds.x, cellBounds.y, distanceFromEdge, cellBounds.height);
Rectangle right = new Rectangle(cellBounds.x + cellBounds.width - distanceFromEdge, cellBounds.y,
distanceFromEdge, cellBounds.height);
if (left.contains(clickPt)) {
return LEFT;
} else if (right.contains(clickPt)) {
return RIGHT;
} else {
return NONE;
}
}
public static CellEdgeEnum getVerticalCellEdge(ILayer layer, Point clickPt, int handleHeight) {
LayerCell cell = layer.getCellByPosition(
layer.getColumnPositionByX(clickPt.x),
layer.getRowPositionByY(clickPt.y)
);
return getVerticalCellEdge(cell.getBounds(), clickPt, handleHeight);
}
/**
* @see CellEdgeDetectUtil#getHorizontalCellEdge(Rectangle, Point, int)
*/
private static CellEdgeEnum getVerticalCellEdge(Rectangle cellBounds, Point clickPt, int distanceFromEdge) {
if (distanceFromEdge < 0) {
distanceFromEdge = cellBounds.height / 2;
}
Rectangle top = new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, distanceFromEdge);
Rectangle bottom = new Rectangle(cellBounds.x, cellBounds.y + cellBounds.height - distanceFromEdge, cellBounds.width, distanceFromEdge);
if (top.contains(clickPt)) {
return TOP;
} else if (bottom.contains(clickPt)) {
return BOTTOM;
} else {
return NONE;
}
}
}
| 4,794 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
NatCombo.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/widget/NatCombo.java | package net.sourceforge.nattable.widget;
import java.util.Arrays;
import net.sourceforge.nattable.style.CellStyleAttributes;
import net.sourceforge.nattable.style.CellStyleUtil;
import net.sourceforge.nattable.style.HorizontalAlignmentEnum;
import net.sourceforge.nattable.style.IStyle;
import net.sourceforge.nattable.style.VerticalAlignmentEnum;
import net.sourceforge.nattable.util.GUIHelper;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class NatCombo extends Composite {
public static final int DEFAULT_NUM_OF_VISIBLE_ITEMS = 5;
private final IStyle cellStyle;
private int maxVisibleItems = 10;
private String[] items;
private Text text;
private Shell dropdownShell;
private List dropdownList;
private Image iconImage;
public NatCombo(Composite parent, IStyle cellStyle) {
this(parent, cellStyle, DEFAULT_NUM_OF_VISIBLE_ITEMS);
}
public NatCombo(Composite parent, IStyle cellStyle, int maxVisibleItems) {
super(parent, SWT.NONE);
this.cellStyle = cellStyle;
this.maxVisibleItems = maxVisibleItems;
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
gridLayout.horizontalSpacing = 0;
setLayout(gridLayout);
addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent event) {
resizeDropdownControl();
}
});
addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
dropdownShell.dispose();
text.dispose();
}
});
createTextControl();
createDropdownControl();
}
public void setItems(String[] items) {
if (items != null) {
this.items = items;
if (!dropdownList.isDisposed() && items != null && items.length > 0) {
dropdownList.setItems(items);
}
resizeDropdownControl();
}
}
public void setSelection(String[] items) {
if(items != null){
if (!dropdownList.isDisposed()) {
dropdownList.setSelection(items);
}
}
if(items[0] != null){
text.setText(items[0]);
}
}
public int getSelectionIndex() {
if (!dropdownList.isDisposed()) {
return dropdownList.getSelectionIndex();
} else {
return Arrays.asList(items).indexOf(text.getText());
}
}
@Override
public void addKeyListener(KeyListener listener) {
text.addKeyListener(listener);
dropdownList.addKeyListener(listener);
}
@Override
public void addTraverseListener(TraverseListener listener) {
text.addTraverseListener(listener);
dropdownList.addTraverseListener(listener);
}
@Override
public void addMouseListener(MouseListener listener) {
text.addMouseListener(listener);
dropdownList.addMouseListener(listener);
}
@Override
public void notifyListeners(int eventType, Event event) {
dropdownList.notifyListeners(eventType, event);
}
private void createTextControl() {
text = new Text(this, HorizontalAlignmentEnum.getSWTStyle(cellStyle));
text.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
text.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
text.setFont(cellStyle.getAttributeValue(CellStyleAttributes.FONT));
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
text.setLayoutData(gridData);
text.forceFocus();
text.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_UP) {
showDropdownControl();
int selectionIndex = dropdownList.getSelectionIndex();
selectionIndex += event.keyCode == SWT.ARROW_DOWN ? 1 : -1;
if (selectionIndex < 0) {
selectionIndex = 0;
}
dropdownList.select(selectionIndex);
text.setText(dropdownList.getSelection()[0]);
}
}
});
iconImage = GUIHelper.getImage("down_2");
final Canvas iconCanvas = new Canvas(this, SWT.NONE) {
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
Rectangle iconImageBounds = iconImage.getBounds();
return new Point(iconImageBounds.width + 2, iconImageBounds.height + 2);
}
};
gridData = new GridData(GridData.BEGINNING, SWT.FILL, false, true);
iconCanvas.setLayoutData(gridData);
iconCanvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
GC gc = event.gc;
Rectangle iconCanvasBounds = iconCanvas.getBounds();
Rectangle iconImageBounds = iconImage.getBounds();
int horizontalAlignmentPadding = CellStyleUtil.getHorizontalAlignmentPadding(HorizontalAlignmentEnum.CENTER, iconCanvasBounds, iconImageBounds.width);
int verticalAlignmentPadding = CellStyleUtil.getVerticalAlignmentPadding(VerticalAlignmentEnum.MIDDLE, iconCanvasBounds, iconImageBounds.height);
gc.drawImage(iconImage, horizontalAlignmentPadding, verticalAlignmentPadding);
Color originalFg = gc.getForeground();
gc.setForeground(GUIHelper.COLOR_WIDGET_BORDER);
gc.drawRectangle(0, 0, iconCanvasBounds.width - 1, iconCanvasBounds.height - 1);
gc.setForeground(originalFg);
}
});
iconCanvas.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
showDropdownControl();
}
});
}
private void showDropdownControl() {
if (dropdownShell.isDisposed()) {
createDropdownControl();
}
resizeDropdownControl();
}
private void createDropdownControl() {
dropdownShell = new Shell(getShell(), SWT.MODELESS);
dropdownShell.setLayout(new FillLayout());
dropdownList = new List(dropdownShell, SWT.V_SCROLL | HorizontalAlignmentEnum.getSWTStyle(cellStyle));
dropdownList.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
dropdownList.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
dropdownList.setFont(cellStyle.getAttributeValue(CellStyleAttributes.FONT));
dropdownShell.addShellListener(new ShellAdapter() {
@Override
public void shellClosed(ShellEvent event) {
text.forceFocus();
}
});
dropdownList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (dropdownList.getSelectionCount() > 0) {
text.setText(dropdownList.getSelection()[0]);
}
}
});
setItems(items);
dropdownList.setSelection(new String[] { text.getText() });
}
private void resizeDropdownControl() {
if (dropdownShell != null && !dropdownShell.isDisposed() && !dropdownShell.isVisible()) {
Point size = getSize();
int itemCount = dropdownList.getItemCount();
if (itemCount > 0 && size.x > 0 && size.y > 0) {
int listHeight = Math.min(itemCount, maxVisibleItems) * dropdownList.getItemHeight();
dropdownList.setSize(size.x, listHeight);
Point point = toDisplay(0, 0);
int shellHeight = dropdownShell.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
dropdownShell.setBounds(point.x, point.y + size.y, size.x, shellHeight);
dropdownShell.open();
}
}
}
public void select(int index) {
dropdownList.select(index);
}
}
| 8,626 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
WaitDialog.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/widget/WaitDialog.java | package net.sourceforge.nattable.widget;
import static org.eclipse.swt.layout.GridData.CENTER;
import net.sourceforge.nattable.util.GUIHelper;
import net.sourceforge.nattable.util.ObjectUtils;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class WaitDialog extends Dialog {
private String msg;
private Image iconImage;
private Label textLabel;
public WaitDialog(Shell parent, int shellStyle, String msg, Image iconImg) {
super(parent);
this.msg = msg;
this.iconImage = iconImg;
setShellStyle(shellStyle | SWT.APPLICATION_MODAL);
}
private void centerDialogOnScreen(Shell shell) {
shell.setSize(250, 75);
Rectangle parentSize = getParentShell().getBounds();
Rectangle mySize = shell.getBounds();
int locationX, locationY;
locationX = (parentSize.width - mySize.width)/2+parentSize.x;
locationY = (parentSize.height - mySize.height)/2+parentSize.y;
shell.setLocation(locationX, locationY);
}
@Override
protected Control createContents(Composite parent) {
centerDialogOnScreen(getShell());
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
composite.setLayoutData(new GridData(CENTER, CENTER, true, true));
composite.setRedraw(true);
Label imgLabel = new Label(composite, SWT.NONE);
imgLabel.setImage(iconImage);
textLabel = new Label(composite, SWT.NONE);
textLabel.setLayoutData(new GridData(CENTER, CENTER, true, true));
textLabel.setFont(GUIHelper.getFont(new FontData("Arial", 9, SWT.BOLD)));
textLabel.setRedraw(true);
textLabel.setText(msg);
return composite;
}
public void setMsg(String msg) {
this.msg = msg;
textLabel.setText(msg);
getShell().layout(new Control[]{textLabel});
}
@Override
public boolean close() {
if(ObjectUtils.isNotNull(iconImage)){
iconImage.dispose();
}
return super.close();
}
} | 2,322 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
EditConfigAttributes.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/EditConfigAttributes.java | package net.sourceforge.nattable.edit;
import net.sourceforge.nattable.config.IEditableRule;
import net.sourceforge.nattable.data.validate.IDataValidator;
import net.sourceforge.nattable.edit.editor.ICellEditor;
import net.sourceforge.nattable.style.ConfigAttribute;
public interface EditConfigAttributes {
public static final ConfigAttribute<IEditableRule> CELL_EDITABLE_RULE = new ConfigAttribute<IEditableRule>();
public static final ConfigAttribute<ICellEditor> CELL_EDITOR = new ConfigAttribute<ICellEditor>();
public static final ConfigAttribute<IDataValidator> DATA_VALIDATOR = new ConfigAttribute<IDataValidator>();
}
| 637 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
MultiCellEditController.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/MultiCellEditController.java | package net.sourceforge.nattable.edit;
import java.util.List;
import net.sourceforge.nattable.config.CellConfigAttributes;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.coordinate.PositionCoordinate;
import net.sourceforge.nattable.data.convert.IDisplayConverter;
import net.sourceforge.nattable.data.validate.IDataValidator;
import net.sourceforge.nattable.edit.command.EditUtils;
import net.sourceforge.nattable.edit.command.UpdateDataCommand;
import net.sourceforge.nattable.edit.editor.ICellEditor;
import net.sourceforge.nattable.edit.event.InlineCellEditEvent;
import net.sourceforge.nattable.edit.gui.MultiCellEditDialog;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.selection.SelectionLayer;
import net.sourceforge.nattable.style.CellStyleProxy;
import net.sourceforge.nattable.style.DisplayMode;
import net.sourceforge.nattable.style.IStyle;
import net.sourceforge.nattable.tickupdate.ITickUpdateHandler;
import net.sourceforge.nattable.tickupdate.TickUpdateConfigAttributes;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.widgets.Composite;
public class MultiCellEditController {
public static boolean editSelectedCells(SelectionLayer selectionLayer, Character initialEditValue, Composite parent, IConfigRegistry configRegistry) {
LayerCell lastSelectedCell = EditUtils.getLastSelectedCell(selectionLayer);
// IF cell is selected
if (lastSelectedCell != null) {
final List<String> lastSelectedCellLabelsArray = lastSelectedCell.getConfigLabels().getLabels();
PositionCoordinate[] selectedCells = selectionLayer.getSelectedCells();
// AND selected cell count > 1
if (selectedCells.length > 1) {
ICellEditor lastSelectedCellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, lastSelectedCellLabelsArray);
// AND all selected cells are of the same editor type
// AND all selected cells are editable
if (EditUtils.isEditorSame(selectionLayer, configRegistry, lastSelectedCellEditor)
&& EditUtils.allCellsEditable(selectionLayer, configRegistry)) {
// THEN use multi commit handler and populate editor in popup
ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, lastSelectedCellLabelsArray);
IDisplayConverter dataTypeConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, lastSelectedCellLabelsArray);
IStyle cellStyle = new CellStyleProxy(configRegistry, DisplayMode.EDIT, lastSelectedCellLabelsArray);
IDataValidator dataValidator = configRegistry.getConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, lastSelectedCellLabelsArray);
Object originalCanonicalValue = lastSelectedCell.getDataValue();
for (PositionCoordinate selectedCell : selectedCells) {
Object cellValue = selectionLayer.getCellByPosition(selectedCell.columnPosition, selectedCell.rowPosition).getDataValue();
if (!cellValue.equals(originalCanonicalValue)) {
originalCanonicalValue = null;
break;
}
}
ITickUpdateHandler tickUpdateHandler = configRegistry.getConfigAttribute(TickUpdateConfigAttributes.UPDATE_HANDLER, DisplayMode.EDIT, lastSelectedCellLabelsArray);
boolean allowIncrementDecrement = tickUpdateHandler != null && tickUpdateHandler.isApplicableFor(originalCanonicalValue);
MultiCellEditDialog dialog = new MultiCellEditDialog(parent.getShell(), cellEditor, dataTypeConverter, cellStyle, dataValidator, originalCanonicalValue, initialEditValue, allowIncrementDecrement);
int returnValue = dialog.open();
ActiveCellEditor.close();
if (returnValue == Dialog.OK) {
Object editorValue = dialog.getEditorValue();
Object newValue = editorValue;
if (allowIncrementDecrement) {
switch (dialog.getEditType()) {
case INCREASE:
newValue = tickUpdateHandler.getIncrementedValue(originalCanonicalValue);
break;
case DECREASE:
newValue = tickUpdateHandler.getDecrementedValue(originalCanonicalValue);
break;
}
}
for (PositionCoordinate selectedCell : selectedCells) {
selectionLayer.doCommand(new UpdateDataCommand(selectionLayer, selectedCell.columnPosition, selectedCell.rowPosition, newValue));
}
}
}
} else {
// ELSE use single commit handler and populate editor inline in cell rectangle
selectionLayer.fireLayerEvent(new InlineCellEditEvent(selectionLayer, new PositionCoordinate(selectionLayer, lastSelectedCell.getColumnPosition(), lastSelectedCell.getRowPosition()), parent, configRegistry, initialEditValue));
}
return true;
}
return false;
}
}
| 4,972 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ActiveCellEditor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/ActiveCellEditor.java | package net.sourceforge.nattable.edit;
import net.sourceforge.nattable.data.convert.IDisplayConverter;
import net.sourceforge.nattable.data.validate.IDataValidator;
import net.sourceforge.nattable.edit.editor.ICellEditor;
import net.sourceforge.nattable.selection.SelectionLayer.MoveDirectionEnum;
import net.sourceforge.nattable.style.IStyle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
public class ActiveCellEditor {
private static ICellEditor cellEditor;
private static ICellEditHandler editHandler;
private static IDataValidator dataValidator;
private static Control activeCellEditorControl;
private static int columnPosition = -1;
private static int rowPosition = -1;
private static int columnIndex = -1;
private static int rowIndex = -1;
public static void activate(ICellEditor cellEditor, Composite parent, Object originalCanonicalValue, Character initialEditValue, IDisplayConverter displayConverter, IStyle cellStyle, IDataValidator dataValidator, ICellEditHandler editHandler, int columnPosition, int rowPosition, int columnIndex, int rowIndex) {
close();
ActiveCellEditor.cellEditor = cellEditor;
ActiveCellEditor.editHandler = editHandler;
ActiveCellEditor.dataValidator = dataValidator;
ActiveCellEditor.columnPosition = columnPosition;
ActiveCellEditor.rowPosition = rowPosition;
ActiveCellEditor.columnIndex = columnIndex;
ActiveCellEditor.rowIndex = rowIndex;
activeCellEditorControl = cellEditor.activateCell(parent, originalCanonicalValue, initialEditValue, displayConverter, cellStyle, dataValidator, editHandler, columnIndex, rowIndex);
}
public static void commit() {
if (isValid() && validateCanonicalValue()) {
editHandler.commit(MoveDirectionEnum.NONE, true);
}
close();
}
public static void close() {
if (cellEditor != null && !cellEditor.isClosed()) {
cellEditor.close();
}
cellEditor = null;
editHandler = null;
dataValidator = null;
if (activeCellEditorControl != null && !activeCellEditorControl.isDisposed()) {
activeCellEditorControl.dispose();
}
activeCellEditorControl = null;
columnPosition = -1;
rowPosition = -1;
columnIndex = -1;
rowIndex = -1;
}
public static ICellEditor getCellEditor() {
return cellEditor;
}
public static Control getControl() {
if (isValid()) {
return activeCellEditorControl;
} else {
return null;
}
}
public static int getColumnPosition() {
return columnPosition;
}
public static int getRowPosition() {
return rowPosition;
}
public static int getColumnIndex() {
return columnIndex;
}
public static int getRowIndex() {
return rowIndex;
}
public static Object getCanonicalValue() {
if (isValid()) {
return cellEditor.getCanonicalValue();
} else {
return null;
}
}
public static boolean validateCanonicalValue() {
if (dataValidator != null) {
return dataValidator.validate(columnIndex, rowIndex, getCanonicalValue());
} else {
return true;
}
}
public static boolean isValid() {
return cellEditor != null && !cellEditor.isClosed();
}
}
| 3,220 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
InlineCellEditController.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/InlineCellEditController.java | package net.sourceforge.nattable.edit;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sourceforge.nattable.config.CellConfigAttributes;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.data.convert.IDisplayConverter;
import net.sourceforge.nattable.data.validate.IDataValidator;
import net.sourceforge.nattable.edit.editor.ICellEditor;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.ILayerListener;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.layer.event.ILayerEvent;
import net.sourceforge.nattable.selection.event.CellSelectionEvent;
import net.sourceforge.nattable.style.CellStyleProxy;
import net.sourceforge.nattable.style.DisplayMode;
import net.sourceforge.nattable.style.IStyle;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
public class InlineCellEditController {
private static Map<ILayer, ILayerListener> layerListenerMap = new HashMap<ILayer, ILayerListener>();
public static boolean editCellInline(LayerCell cell, Character initialEditValue, Composite parent, IConfigRegistry configRegistry) {
try {
ActiveCellEditor.commit();
final List<String> configLabels = cell.getConfigLabels().getLabels();
Rectangle cellBounds = cell.getBounds();
ILayer layer = cell.getLayer();
int columnPosition = layer.getColumnPositionByX(cellBounds.x);
int columnIndex = layer.getColumnIndexByPosition(columnPosition);
int rowPosition = layer.getRowPositionByY(cellBounds.y);
int rowIndex = layer.getRowIndexByPosition(rowPosition);
boolean editable = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, configLabels).isEditable(columnIndex, rowIndex);
if (!editable) {
return false;
}
ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, configLabels);
IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, configLabels);
IStyle cellStyle = new CellStyleProxy(configRegistry, DisplayMode.EDIT, configLabels);
IDataValidator dataValidator = configRegistry.getConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, configLabels);
ICellEditHandler editHandler = new SingleEditHandler(
cellEditor,
layer,
columnPosition,
rowPosition);
final Rectangle editorBounds = layer.getLayerPainter().adjustCellBounds(new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height));
Object originalCanonicalValue = cell.getDataValue();
ActiveCellEditor.activate(cellEditor, parent, originalCanonicalValue, initialEditValue, displayConverter, cellStyle, dataValidator, editHandler, columnPosition, rowPosition, columnIndex, rowIndex);
Control editorControl = ActiveCellEditor.getControl();
if (editorControl != null) {
editorControl.setBounds(editorBounds);
ILayerListener layerListener = layerListenerMap.get(layer);
if (layerListener == null) {
layerListener = new InlineCellEditLayerListener(layer);
layerListenerMap.put(layer, layerListener);
layer.addLayerListener(layerListener);
}
}
} catch (Exception e) {
if(cell == null){
System.err.println("Cell being edited is no longer available. " + "Character: " + initialEditValue);
} else {
System.err.println("Error while editing cell (inline): " + "Cell: " + cell + "; Character: " + initialEditValue);
e.printStackTrace(System.err);
}
}
return true;
}
public static void dispose() {
layerListenerMap.clear();
}
static class InlineCellEditLayerListener implements ILayerListener {
private final ILayer layer;
InlineCellEditLayerListener(ILayer layer) {
this.layer = layer;
}
public void handleLayerEvent(ILayerEvent event) {
// if (ActiveCellEditor.isValid()) {
// int editorColumnPosition = ActiveCellEditor.getColumnPosition();
// int editorRowPosition = ActiveCellEditor.getRowPosition();
// int editorColumnIndex = ActiveCellEditor.getColumnIndex();
// int editorRowIndex = ActiveCellEditor.getRowIndex();
// Control editorControl = ActiveCellEditor.getControl();
//
// int columnIndex = layer.getColumnIndexByPosition(editorColumnPosition);
// int rowIndex = layer.getRowIndexByPosition(editorRowPosition);
//
// if (columnIndex != editorColumnIndex || rowIndex != editorRowIndex) {
// ActiveCellEditor.close();
// } else if (editorControl != null && !editorControl.isDisposed()) {
// Rectangle cellBounds = layer.getBoundsByPosition(editorColumnPosition, editorRowPosition);
// Rectangle adjustedCellBounds = layer.getLayerPainter().adjustCellBounds(cellBounds);
// editorControl.setBounds(adjustedCellBounds);
// }
// }
}
}
}
| 4,949 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
EditTypeEnum.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/EditTypeEnum.java | package net.sourceforge.nattable.edit;
public enum EditTypeEnum {
SET,
INCREASE,
DECREASE
}
| 108 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
SingleEditHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/SingleEditHandler.java | package net.sourceforge.nattable.edit;
import net.sourceforge.nattable.edit.command.UpdateDataCommand;
import net.sourceforge.nattable.edit.editor.ICellEditor;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.selection.SelectionLayer.MoveDirectionEnum;
import net.sourceforge.nattable.selection.command.MoveSelectionCommand;
public class SingleEditHandler implements ICellEditHandler {
private final ICellEditor cellEditor;
private final ILayer layer;
private final int columnPosition;
private final int rowPosition;
public SingleEditHandler(ICellEditor cellEditor, ILayer layer, int columnPosition, int rowPosition) {
this.cellEditor = cellEditor;
this.layer = layer;
this.columnPosition = columnPosition;
this.rowPosition = rowPosition;
}
/**
* {@inheritDoc}
* Note: Assumes that the value is valid.<br/>
*/
public boolean commit(MoveDirectionEnum direction, boolean closeEditorAfterCommit) {
Object canonicalValue = cellEditor.getCanonicalValue();
switch (direction) {
case LEFT:
layer.doCommand(new MoveSelectionCommand(MoveDirectionEnum.LEFT, 1, false, false));
break;
case RIGHT:
layer.doCommand(new MoveSelectionCommand(MoveDirectionEnum.RIGHT, 1, false, false));
break;
}
boolean committed = layer.doCommand(new UpdateDataCommand(layer, columnPosition, rowPosition, canonicalValue));
if(committed && closeEditorAfterCommit){
cellEditor.close();
return true;
}
return committed;
}
} | 1,530 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ICellEditHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/ICellEditHandler.java | package net.sourceforge.nattable.edit;
import net.sourceforge.nattable.edit.editor.ICellEditor;
import net.sourceforge.nattable.selection.SelectionLayer.MoveDirectionEnum;
/**
* Handles the updating of the data bean with the new value provided<br/>
* by the {@link ICellEditor}
*/
public interface ICellEditHandler {
/**
* Commit the new value.<br/>
*
* @param direction to move the selection after the commit.<br/>
* Example: when TAB key is pressed, we commit and move the selection.
* @return TRUE if the data source was successfully updated
*/
public boolean commit(MoveDirectionEnum direction, boolean closeEditorAfterCommit);
}
| 680 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
CellEditDragMode.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/action/CellEditDragMode.java | package net.sourceforge.nattable.edit.action;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.edit.command.EditCellCommand;
import net.sourceforge.nattable.selection.action.CellSelectionDragMode;
import org.eclipse.swt.events.MouseEvent;
public class CellEditDragMode extends CellSelectionDragMode {
private int originalColumnPosition;
private int originalRowPosition;
public void mouseDown(NatTable natTable, MouseEvent event) {
super.mouseDown(natTable, event);
originalColumnPosition = natTable.getColumnPositionByX(event.x);
originalRowPosition = natTable.getRowPositionByY(event.y);
}
@Override
public void mouseMove(NatTable natTable, MouseEvent event) {
super.mouseMove(natTable, event);
int columnPosition = natTable.getColumnPositionByX(event.x);
int rowPosition = natTable.getRowPositionByY(event.y);
if (columnPosition != originalColumnPosition || rowPosition != originalRowPosition) {
// Left original cell, cancel edit
originalColumnPosition = -1;
originalRowPosition = -1;
}
}
public void mouseUp(NatTable natTable, MouseEvent event) {
super.mouseUp(natTable, event);
int columnPosition = natTable.getColumnPositionByX(event.x);
int rowPosition = natTable.getRowPositionByY(event.y);
if (columnPosition == originalColumnPosition && rowPosition == originalRowPosition) {
natTable.doCommand(
new EditCellCommand(
natTable,
natTable.getConfigRegistry(),
natTable.getCellByPosition(columnPosition, rowPosition)));
}
}
}
| 1,555 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
KeyEditAction.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/action/KeyEditAction.java | package net.sourceforge.nattable.edit.action;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.edit.command.EditSelectionCommand;
import net.sourceforge.nattable.ui.action.IKeyAction;
import net.sourceforge.nattable.ui.matcher.LetterOrDigitKeyEventMatcher;
import org.eclipse.swt.events.KeyEvent;
public class KeyEditAction implements IKeyAction {
public void run(NatTable natTable, KeyEvent event) {
Character character = null;
if (LetterOrDigitKeyEventMatcher.isLetterOrDigit(event.character)) {
character = Character.valueOf(event.character);
}
natTable.doCommand(new EditSelectionCommand(natTable, natTable.getConfigRegistry(), character));
}
} | 710 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
MouseEditAction.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/action/MouseEditAction.java | package net.sourceforge.nattable.edit.action;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.edit.command.EditCellCommand;
import net.sourceforge.nattable.selection.command.SelectCellCommand;
import net.sourceforge.nattable.ui.action.IMouseAction;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
public class MouseEditAction implements IMouseAction {
public void run(NatTable natTable, MouseEvent event) {
int columnPosition = natTable.getColumnPositionByX(event.x);
int rowPosition = natTable.getRowPositionByY(event.y);
boolean withShiftMask = (event.stateMask & SWT.SHIFT) != 0;
boolean withCtrlMask = (event.stateMask & SWT.CTRL) != 0;
natTable.doCommand(new SelectCellCommand(natTable, columnPosition, rowPosition, withShiftMask, withCtrlMask));
natTable.doCommand(
new EditCellCommand(
natTable,
natTable.getConfigRegistry(),
natTable.getCellByPosition(columnPosition, rowPosition)));
}
} | 1,013 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultEditBindings.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/config/DefaultEditBindings.java | package net.sourceforge.nattable.edit.config;
import net.sourceforge.nattable.config.AbstractUiBindingConfiguration;
import net.sourceforge.nattable.edit.action.CellEditDragMode;
import net.sourceforge.nattable.edit.action.KeyEditAction;
import net.sourceforge.nattable.edit.action.MouseEditAction;
import net.sourceforge.nattable.edit.editor.CheckBoxCellEditor;
import net.sourceforge.nattable.edit.editor.ComboBoxCellEditor;
import net.sourceforge.nattable.edit.editor.TextCellEditor;
import net.sourceforge.nattable.ui.binding.UiBindingRegistry;
import net.sourceforge.nattable.ui.matcher.BodyCellEditorMouseEventMatcher;
import net.sourceforge.nattable.ui.matcher.KeyEventMatcher;
import net.sourceforge.nattable.ui.matcher.LetterOrDigitKeyEventMatcher;
import org.eclipse.swt.SWT;
public class DefaultEditBindings extends AbstractUiBindingConfiguration {
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.NONE, SWT.F2), new KeyEditAction());
uiBindingRegistry.registerKeyBinding(new LetterOrDigitKeyEventMatcher(), new KeyEditAction());
uiBindingRegistry.registerFirstSingleClickBinding(
new BodyCellEditorMouseEventMatcher(TextCellEditor.class),
new MouseEditAction());
uiBindingRegistry.registerFirstMouseDragMode(
new BodyCellEditorMouseEventMatcher(TextCellEditor.class),
new CellEditDragMode());
uiBindingRegistry.registerFirstSingleClickBinding(
new BodyCellEditorMouseEventMatcher(CheckBoxCellEditor.class),
new MouseEditAction());
uiBindingRegistry.registerFirstMouseDragMode(
new BodyCellEditorMouseEventMatcher(CheckBoxCellEditor.class),
new CellEditDragMode());
uiBindingRegistry.registerFirstSingleClickBinding(
new BodyCellEditorMouseEventMatcher(ComboBoxCellEditor.class),
new MouseEditAction());
uiBindingRegistry.registerFirstMouseDragMode(
new BodyCellEditorMouseEventMatcher(ComboBoxCellEditor.class),
new CellEditDragMode());
}
}
| 2,094 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultEditConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/config/DefaultEditConfiguration.java | package net.sourceforge.nattable.edit.config;
import net.sourceforge.nattable.config.AbstractLayerConfiguration;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.config.IEditableRule;
import net.sourceforge.nattable.data.validate.DefaultDataValidator;
import net.sourceforge.nattable.edit.EditConfigAttributes;
import net.sourceforge.nattable.edit.command.EditCellCommandHandler;
import net.sourceforge.nattable.edit.editor.TextCellEditor;
import net.sourceforge.nattable.edit.event.InlineCellEditEventHandler;
import net.sourceforge.nattable.grid.layer.GridLayer;
public class DefaultEditConfiguration extends AbstractLayerConfiguration<GridLayer> {
@Override
public void configureTypedLayer(GridLayer gridLayer) {
gridLayer.registerCommandHandler(new EditCellCommandHandler());
gridLayer.registerEventHandler(new InlineCellEditEventHandler(gridLayer));
}
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new TextCellEditor());
configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, new DefaultDataValidator());
}
}
| 1,337 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ComboBoxCellEditor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/editor/ComboBoxCellEditor.java | package net.sourceforge.nattable.edit.editor;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.nattable.data.convert.IDisplayConverter;
import net.sourceforge.nattable.selection.SelectionLayer.MoveDirectionEnum;
import net.sourceforge.nattable.util.ArrayUtil;
import net.sourceforge.nattable.widget.NatCombo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
/**
* Renders an SWT combo box.
* Users can select from the drop down or enter their own values.
*/
public class ComboBoxCellEditor extends AbstractCellEditor {
private NatCombo combo;
private int maxVisibleItems = 10;
private Object originalCanonicalValue;
private final List<?> canonicalValues;
/**
* @see this{@link #ComboBoxCellEditor(List, int)}
*/
public ComboBoxCellEditor(List<?> canonicalValues){
this(canonicalValues, NatCombo.DEFAULT_NUM_OF_VISIBLE_ITEMS);
}
/**
* @see this{@link #ComboBoxCellEditor(List, int)}
*/
public ComboBoxCellEditor(IComboBoxDataProvider dataProvider){
this(dataProvider.getValues(), NatCombo.DEFAULT_NUM_OF_VISIBLE_ITEMS);
}
/**
* @param canonicalValues Array of items to be shown in the drop down box. These will be
* converted using the {@link IDisplayConverter} for display purposes
* @param maxVisibleItems the max items the drop down will show before introducing a scroll bar.
*/
public ComboBoxCellEditor(List<?> canonicalValues, int maxVisibleItems) {
this.canonicalValues = canonicalValues;
this.maxVisibleItems = maxVisibleItems;
}
@Override
protected Control activateCell(Composite parent, Object originalCanonicalValue, Character initialEditValue) {
this.originalCanonicalValue = originalCanonicalValue;
combo = new NatCombo(parent, getCellStyle(), maxVisibleItems);
combo.setItems(getDisplayValues());
if (originalCanonicalValue != null) {
combo.setSelection(new String[] { getDisplayValue() });
}
combo.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if ((event.keyCode == SWT.CR && event.stateMask == 0)
|| (event.keyCode == SWT.KEYPAD_CR && event.stateMask == 0)) {
commit(MoveDirectionEnum.NONE);
} else if (event.keyCode == SWT.ESC && event.stateMask == 0){
close();
}
}
});
combo.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent event) {
if (event.keyCode == SWT.TAB && event.stateMask == SWT.SHIFT) {
commit(MoveDirectionEnum.LEFT);
} else if (event.keyCode == SWT.TAB && event.stateMask == 0) {
commit(MoveDirectionEnum.RIGHT);
}
}
});
combo.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
commit(MoveDirectionEnum.NONE);
}
});
return combo;
}
public Object getCanonicalValue() {
int selectionIndex = combo.getSelectionIndex();
//Item selected from list
if (selectionIndex >= 0) {
return canonicalValues.get(selectionIndex);
} else {
return originalCanonicalValue;
}
}
public void select(int index){
combo.select(index);
}
public void setCanonicalValue(Object value) {
//No op - combo is not dynamic
}
@Override
public void close() {
super.close();
if (combo != null && !combo.isDisposed()) {
combo.dispose();
}
}
private String getDisplayValue() {
return (String) getDataTypeConverter().canonicalToDisplayValue(originalCanonicalValue);
}
private String[] getDisplayValues() {
List<String> displayValues = new ArrayList<String>();
for (Object canonicalValue : canonicalValues) {
displayValues.add((String) getDataTypeConverter().canonicalToDisplayValue(canonicalValue));
}
return displayValues.toArray(ArrayUtil.STRING_TYPE_ARRAY);
}
}
| 4,195 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ICellEditor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/editor/ICellEditor.java | package net.sourceforge.nattable.edit.editor;
import net.sourceforge.nattable.data.convert.IDisplayConverter;
import net.sourceforge.nattable.data.validate.IDataValidator;
import net.sourceforge.nattable.edit.ICellEditHandler;
import net.sourceforge.nattable.style.IStyle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
/**
* Implementations are responsible for capturing new cell value during cell edit.
*/
public interface ICellEditor {
/**
* Invoked by the action handlers to initialize the editor
* @param parent
* @param originalCanonicalValue of the cell being edited
* @param initialEditValue the initial key press char which triggered editing
* @return the SWT {@link Control} to be used for capturing the new cell value
*/
public Control activateCell(
Composite parent,
Object originalCanonicalValue,
Character initialEditValue,
IDisplayConverter displayConverter,
IStyle cellStyle,
IDataValidator dataValidator,
ICellEditHandler editHandler,
int colIndex,
int rowIndex
);
/**
* @param canonicalValue the data value to be set in the backing bean.
* Note: This should be converted using the {@link IDisplayConverter} for display.
*/
public void setCanonicalValue(Object canonicalValue);
public Object getCanonicalValue();
/**
* Close/dispose the contained {@link Control}
*/
public void close();
public boolean isClosed();
}
| 1,492 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
EditorSelectionEnum.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/editor/EditorSelectionEnum.java | package net.sourceforge.nattable.edit.editor;
public enum EditorSelectionEnum {
ALL,
START,
END
}
| 114 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IComboBoxDataProvider.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/editor/IComboBoxDataProvider.java | package net.sourceforge.nattable.edit.editor;
import java.util.List;
import net.sourceforge.nattable.data.convert.IDisplayConverter;
public interface IComboBoxDataProvider {
/**
* List of values to used as a data source in a {@link ComboBoxCellEditor}.
* Note: these will be converted using the {@link IDisplayConverter} for display
*/
public List<?> getValues();
}
| 393 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
CheckBoxCellEditor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/editor/CheckBoxCellEditor.java | package net.sourceforge.nattable.edit.editor;
import net.sourceforge.nattable.painter.cell.CheckBoxPainter;
import net.sourceforge.nattable.selection.SelectionLayer.MoveDirectionEnum;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
public class CheckBoxCellEditor extends AbstractCellEditor {
private boolean checked;
private Canvas canvas;
private final CheckBoxPainter checkBoxCellPainter;
public CheckBoxCellEditor() {
this.checkBoxCellPainter = new CheckBoxPainter();
}
public CheckBoxCellEditor(Image checkedImg, Image uncheckedImg) {
this.checkBoxCellPainter = new CheckBoxPainter(checkedImg, uncheckedImg);
}
/**
* As soon as the editor is activated, flip the current data value and commit it.<br/>
* The repaint will pick up the new value and flip the image.
*/
@Override
protected Control activateCell(Composite parent, Object originalCanonicalValue, Character initialEditValue) {
setCanonicalValue(originalCanonicalValue);
checked = !checked;
canvas = new Canvas(parent, SWT.NONE);
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent paintEvent) {
Rectangle bounds = canvas.getBounds();
Rectangle rect = new Rectangle(0, 0, bounds.width, bounds.height);
checkBoxCellPainter.paintIconImage(paintEvent.gc, rect, bounds.height / 2 - checkBoxCellPainter.getPreferredHeight(checked) / 2, checked);
}
});
canvas.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
checked = !checked;
canvas.redraw();
}
});
commit(MoveDirectionEnum.NONE, false);
return canvas;
}
public Object getCanonicalValue() {
return getDataTypeConverter().displayToCanonicalValue(Boolean.valueOf(checked));
}
public void setCanonicalValue(Object canonicalValue) {
if (canonicalValue == null) {
checked = false;
} else {
checked = Boolean.valueOf((String) getDataTypeConverter().canonicalToDisplayValue(canonicalValue)).booleanValue();
}
}
@Override
public void close() {
super.close();
if (canvas != null && !canvas.isDisposed()) {
canvas.dispose();
}
}
}
| 2,562 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
TextCellEditor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/editor/TextCellEditor.java | package net.sourceforge.nattable.edit.editor;
import net.sourceforge.nattable.selection.SelectionLayer.MoveDirectionEnum;
import net.sourceforge.nattable.style.CellStyleAttributes;
import net.sourceforge.nattable.style.HorizontalAlignmentEnum;
import net.sourceforge.nattable.style.IStyle;
import net.sourceforge.nattable.util.GUIHelper;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
public class TextCellEditor extends AbstractCellEditor {
private EditorSelectionEnum selectionMode = EditorSelectionEnum.ALL;
private Text text = null;
private boolean editable = true;
public boolean isEditable() {
return editable;
}
public void setEditable(boolean editable) {
this.editable = editable;
}
public final void setSelectionMode(EditorSelectionEnum selectionMode) {
this.selectionMode = selectionMode;
}
public final EditorSelectionEnum getSelectionMode() {
return selectionMode;
}
@Override
protected Control activateCell(final Composite parent, Object originalCanonicalValue, Character initialEditValue) {
text = createTextControl(parent);
// If we have an initial value, then
if (initialEditValue != null) {
selectionMode = EditorSelectionEnum.END;
text.setText(initialEditValue.toString());
selectText();
} else {
setCanonicalValue(originalCanonicalValue);
}
if (!isEditable()) {
text.setEditable(false);
}
text.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if ((event.keyCode == SWT.CR && event.stateMask == 0)
|| (event.keyCode == SWT.KEYPAD_CR && event.stateMask == 0)) {
commit(MoveDirectionEnum.NONE);
}
else if (event.keyCode == SWT.ESC && event.stateMask == 0){
close();
}
}
});
text.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent event) {
boolean committed = false;
if (event.keyCode == SWT.TAB && event.stateMask == SWT.SHIFT) {
committed = commit(MoveDirectionEnum.LEFT);
} else if (event.keyCode == SWT.TAB && event.stateMask == 0) {
committed = commit(MoveDirectionEnum.RIGHT);
}
if (!committed) {
event.doit = false;
}
}
});
text.forceFocus();
return text;
}
private void selectText() {
int textLength = text.getText().length();
if (textLength > 0) {
EditorSelectionEnum selectionMode = getSelectionMode();
if (selectionMode == EditorSelectionEnum.ALL) {
text.setSelection(0, textLength);
} else if (selectionMode == EditorSelectionEnum.END) {
text.setSelection(textLength, textLength);
}
}
}
protected Text createTextControl(Composite parent) {
IStyle cellStyle = getCellStyle();
final Text textControl = new Text(parent, HorizontalAlignmentEnum.getSWTStyle(cellStyle));
textControl.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
textControl.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
textControl.setFont(cellStyle.getAttributeValue(CellStyleAttributes.FONT));
textControl.addKeyListener(new KeyAdapter() {
private final Color originalColor = textControl.getForeground();
@Override
public void keyReleased(KeyEvent e) {
if (!validateCanonicalValue()) {
textControl.setForeground(GUIHelper.COLOR_RED);
} else {
textControl.setForeground(originalColor);
}
};
});
return textControl;
}
public Object getCanonicalValue() {
return getDataTypeConverter().displayToCanonicalValue(text.getText());
}
public void setCanonicalValue(Object canonicalValue) {
String displayValue = (String) getDataTypeConverter().canonicalToDisplayValue(canonicalValue);
text.setText(displayValue != null && displayValue.length() > 0 ? displayValue.toString() : "");
selectText();
}
@Override
public void close() {
super.close();
if (text != null && !text.isDisposed()) {
text.dispose();
}
}
}
| 4,400 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AbstractCellEditor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/editor/AbstractCellEditor.java | package net.sourceforge.nattable.edit.editor;
import net.sourceforge.nattable.data.convert.IDisplayConverter;
import net.sourceforge.nattable.data.validate.IDataValidator;
import net.sourceforge.nattable.edit.ICellEditHandler;
import net.sourceforge.nattable.selection.SelectionLayer.MoveDirectionEnum;
import net.sourceforge.nattable.style.IStyle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
public abstract class AbstractCellEditor implements ICellEditor {
private boolean closed;
private Composite parent;
private ICellEditHandler editHandler;
private IDisplayConverter displayConverter;
private IStyle cellStyle;
private IDataValidator dataValidator;
private int columnIndex;
private int rowIndex;
public final Control activateCell(Composite parent, Object originalCanonicalValue, Character initialEditValue,
IDisplayConverter displayConverter, IStyle cellStyle, IDataValidator dataValidator,
ICellEditHandler editHandler, int columnIndex, int rowIndex) {
this.closed = false;
this.parent = parent;
this.editHandler = editHandler;
this.displayConverter = displayConverter;
this.cellStyle = cellStyle;
this.dataValidator = dataValidator;
this.columnIndex = columnIndex;
this.rowIndex = rowIndex;
return activateCell(parent, originalCanonicalValue, initialEditValue);
}
protected abstract Control activateCell(Composite parent, Object originalCanonicalValue, Character initialEditValue);
protected boolean validateCanonicalValue() {
if (dataValidator != null) {
return dataValidator.validate(columnIndex, rowIndex, getCanonicalValue());
} else {
return true;
}
}
protected IDisplayConverter getDataTypeConverter() {
return displayConverter;
}
protected IStyle getCellStyle() {
return cellStyle;
}
protected IDataValidator getDataValidator() {
return dataValidator;
}
/**
* Commit and close editor.
* @see AbstractCellEditor#commit(MoveDirectionEnum, boolean)
*/
protected final boolean commit(MoveDirectionEnum direction) {
return commit(direction, true);
}
/**
* Commit change - after validation.
* @param direction to move the selection in after a successful commit
* @param closeAfterCommit close the editor after a successful commit
*/
protected final boolean commit(MoveDirectionEnum direction, boolean closeAfterCommit) {
if (editHandler != null) {
if (validateCanonicalValue()) {
return (editHandler.commit(direction, closeAfterCommit));
}
}
return false;
}
public void close() {
if (parent != null && !parent.isDisposed()) {
parent.forceFocus();
}
closed = true;
}
public boolean isClosed() {
return closed;
}
}
| 2,784 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
MultiCellEditDialog.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/gui/MultiCellEditDialog.java | package net.sourceforge.nattable.edit.gui;
import net.sourceforge.nattable.data.convert.IDisplayConverter;
import net.sourceforge.nattable.data.validate.IDataValidator;
import net.sourceforge.nattable.edit.ActiveCellEditor;
import net.sourceforge.nattable.edit.EditTypeEnum;
import net.sourceforge.nattable.edit.ICellEditHandler;
import net.sourceforge.nattable.edit.editor.ICellEditor;
import net.sourceforge.nattable.selection.SelectionLayer.MoveDirectionEnum;
import net.sourceforge.nattable.style.IStyle;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
public class MultiCellEditDialog extends Dialog {
private static final String SET = "Set";
private static final String INCREASE_BY = "Increase by";
private static final String DECREASE_BY = "Decrease by";
private static final String [] OPTIONS = {SET, INCREASE_BY, DECREASE_BY};
private final ICellEditor cellEditor;
private final Object originalCanonicalValue;
private final Character initialEditValue;
private final IDisplayConverter dataTypeConverter;
private final IStyle cellStyle;
private final IDataValidator dataValidator;
private final boolean allowIncrementDecrement;
private Combo updateCombo;
private int lastSelectedIndex = 0;
private Object editorValue;
public MultiCellEditDialog(Shell parentShell,
final ICellEditor cellEditor,
final IDisplayConverter dataTypeConverter,
final IStyle cellStyle,
final IDataValidator dataValidator,
final Object originalCanonicalValue,
final Character initialEditValue,
final boolean allowIncrementDecrement) {
super(parentShell);
setShellStyle(SWT.RESIZE | SWT.APPLICATION_MODAL| SWT.DIALOG_TRIM);
this.cellEditor = cellEditor;
this.dataTypeConverter = dataTypeConverter;
this.cellStyle = cellStyle;
this.dataValidator = dataValidator;
this.originalCanonicalValue = originalCanonicalValue;
this.initialEditValue = initialEditValue;
this.allowIncrementDecrement = allowIncrementDecrement;
}
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("Enter new value");
}
@Override
protected Control createDialogArea(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
GridLayout panelLayout = new GridLayout(allowIncrementDecrement ? 2 : 1,false);
panel.setLayout(panelLayout);
if (allowIncrementDecrement) {
createUpdateCombo(panel);
}
ActiveCellEditor.close();
ActiveCellEditor.activate(cellEditor, panel, originalCanonicalValue, initialEditValue, dataTypeConverter, cellStyle, dataValidator, new MultiEditHandler(), 0, 0, 0, 0);
Control editorControl = ActiveCellEditor.getControl();
// propagate the ESC event from the editor to the dialog
editorControl.addKeyListener(getEscKeyListener());
final GridDataFactory layoutData = GridDataFactory.fillDefaults().grab(true, false).hint(100, 20);
if (allowIncrementDecrement) {
layoutData.indent(5, 0);
}
layoutData.applyTo(editorControl);
return panel;
}
/**
* Create a listener for the ESC key. Cancel and dispose dialog.
*/
private KeyListener getEscKeyListener() {
return new KeyListener() {
public void keyReleased(KeyEvent e) {
if (e.keyCode == SWT.ESC) {
closeDialog();
}
}
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.ESC) {
closeDialog();
}
}
private void closeDialog() {
setReturnCode(SWT.CANCEL);
close();
}
};
}
private void createUpdateCombo(Composite composite) {
updateCombo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.BORDER);
for (String option : OPTIONS) {
updateCombo.add(option);
}
updateCombo.select(0);
updateCombo.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent arg0) {
lastSelectedIndex = updateCombo.getSelectionIndex();
}
});
GridDataFactory.swtDefaults().applyTo(updateCombo);
}
@Override
protected void okPressed() {
if (ActiveCellEditor.isValid()) {
Object canonicalValue = ActiveCellEditor.getCanonicalValue();
if (ActiveCellEditor.validateCanonicalValue()) {
editorValue = canonicalValue;
super.okPressed();
}
}
}
public EditTypeEnum getEditType() {
if (allowIncrementDecrement && updateCombo != null) {
int selectionIndex = updateCombo.isDisposed() ? lastSelectedIndex : updateCombo.getSelectionIndex();
switch (selectionIndex) {
case 0:
return EditTypeEnum.SET;
case 1:
return EditTypeEnum.INCREASE;
case 2:
return EditTypeEnum.DECREASE;
}
}
return EditTypeEnum.SET;
}
public Object getEditorValue() {
return editorValue;
}
class MultiEditHandler implements ICellEditHandler {
public boolean commit(MoveDirectionEnum direction, boolean closeAfterCommit) {
if (direction == MoveDirectionEnum.NONE) {
if (closeAfterCommit) {
okPressed();
return true;
}
}
return false;
}
}
}
| 5,614 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
EditCellCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/command/EditCellCommand.java | package net.sourceforge.nattable.edit.command;
import net.sourceforge.nattable.command.AbstractContextFreeCommand;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.cell.LayerCell;
import org.eclipse.swt.widgets.Composite;
public class EditCellCommand extends AbstractContextFreeCommand {
private final IConfigRegistry configRegistry;
private final Composite parent;
private LayerCell cell;
public EditCellCommand(Composite parent, IConfigRegistry configRegistry, LayerCell cell) {
this.configRegistry = configRegistry;
this.parent = parent;
this.cell = cell;
}
public IConfigRegistry getConfigRegistry() {
return configRegistry;
}
public Composite getParent() {
return parent;
}
public LayerCell getCell() {
return cell;
}
}
| 838 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
EditSelectionCommandHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/command/EditSelectionCommandHandler.java | package net.sourceforge.nattable.edit.command;
import net.sourceforge.nattable.command.AbstractLayerCommandHandler;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.edit.MultiCellEditController;
import net.sourceforge.nattable.selection.SelectionLayer;
import org.eclipse.swt.widgets.Composite;
public class EditSelectionCommandHandler extends AbstractLayerCommandHandler<EditSelectionCommand> {
private SelectionLayer selectionLayer;
public EditSelectionCommandHandler(SelectionLayer selectionLayer) {
this.selectionLayer = selectionLayer;
}
public Class<EditSelectionCommand> getCommandClass() {
return EditSelectionCommand.class;
}
public boolean doCommand(EditSelectionCommand command) {
Composite parent = command.getParent();
IConfigRegistry configRegistry = command.getConfigRegistry();
Character initialValue = command.getCharacter();
return MultiCellEditController.editSelectedCells(selectionLayer, initialValue, parent, configRegistry);
}
}
| 1,051 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
EditSelectionCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/command/EditSelectionCommand.java | package net.sourceforge.nattable.edit.command;
import net.sourceforge.nattable.command.AbstractContextFreeCommand;
import net.sourceforge.nattable.config.IConfigRegistry;
import org.eclipse.swt.widgets.Composite;
public class EditSelectionCommand extends AbstractContextFreeCommand {
private final IConfigRegistry configRegistry;
private final Character character;
private final Composite parent;
public EditSelectionCommand(Composite parent, IConfigRegistry configRegistry, Character character) {
this.parent = parent;
this.configRegistry = configRegistry;
this.character = character;
}
public IConfigRegistry getConfigRegistry() {
return configRegistry;
}
public Character getCharacter() {
return character;
}
public Composite getParent() {
return parent;
}
}
| 835 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
EditUtils.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/command/EditUtils.java | package net.sourceforge.nattable.edit.command;
import java.util.List;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.config.IEditableRule;
import net.sourceforge.nattable.coordinate.PositionCoordinate;
import net.sourceforge.nattable.edit.EditConfigAttributes;
import net.sourceforge.nattable.edit.editor.ICellEditor;
import net.sourceforge.nattable.layer.LabelStack;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.selection.SelectionLayer;
import net.sourceforge.nattable.style.DisplayMode;
public class EditUtils {
public static LayerCell getLastSelectedCell(SelectionLayer selectionLayer) {
PositionCoordinate selectionAnchor = selectionLayer.getSelectionAnchor();
return selectionLayer.getCellByPosition(selectionAnchor.columnPosition, selectionAnchor.rowPosition);
}
public static ICellEditor lastSelectedCellEditor(SelectionLayer selectionLayer, IConfigRegistry configRegistry) {
final List<String> lastSelectedCellLabelsArray = EditUtils.getLastSelectedCell(selectionLayer).getConfigLabels().getLabels();
return configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, lastSelectedCellLabelsArray);
}
public static boolean allCellsEditable(SelectionLayer selectionLayer, IConfigRegistry configRegistry) {
PositionCoordinate[] selectedCells = selectionLayer.getSelectedCells();
for (PositionCoordinate cell : selectedCells) {
LabelStack labelStack = selectionLayer.getConfigLabelsByPosition(cell.columnPosition, cell.rowPosition);
IEditableRule editableRule = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, labelStack.getLabels());
int columnIndex = selectionLayer.getColumnIndexByPosition(cell.columnPosition);
int rowIndex = selectionLayer.getRowIndexByPosition(cell.rowPosition);
if (!editableRule.isEditable(columnIndex, rowIndex)) {
return false;
}
}
return true;
}
public static boolean isEditorSame(SelectionLayer selectionLayer, IConfigRegistry configRegistry, ICellEditor lastSelectedCellEditor) {
PositionCoordinate[] selectedCells = selectionLayer.getSelectedCells();
boolean isAllSelectedCellsHaveSameEditor = true;
for (PositionCoordinate selectedCell : selectedCells) {
LabelStack labelStack = selectionLayer.getConfigLabelsByPosition(selectedCell.columnPosition, selectedCell.rowPosition);
ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, labelStack.getLabels());
if (cellEditor != lastSelectedCellEditor) {
isAllSelectedCellsHaveSameEditor = false;
}
}
return isAllSelectedCellsHaveSameEditor;
}
}
| 2,779 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
EditCellCommandHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/command/EditCellCommandHandler.java | package net.sourceforge.nattable.edit.command;
import net.sourceforge.nattable.command.AbstractLayerCommandHandler;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.edit.InlineCellEditController;
import net.sourceforge.nattable.layer.cell.LayerCell;
import org.eclipse.swt.widgets.Composite;
public class EditCellCommandHandler extends AbstractLayerCommandHandler<EditCellCommand> {
public Class<EditCellCommand> getCommandClass() {
return EditCellCommand.class;
}
@Override
public boolean doCommand(EditCellCommand command) {
LayerCell cell = command.getCell();
Composite parent = command.getParent();
IConfigRegistry configRegistry = command.getConfigRegistry();
return InlineCellEditController.editCellInline(cell, null, parent, configRegistry);
}
} | 839 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
UpdateDataCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/command/UpdateDataCommand.java | package net.sourceforge.nattable.edit.command;
import net.sourceforge.nattable.command.AbstractPositionCommand;
import net.sourceforge.nattable.layer.ILayer;
public class UpdateDataCommand extends AbstractPositionCommand {
private Object newValue;
public UpdateDataCommand(ILayer layer, int columnPosition, int rowPosition, Object newValue) {
super(layer, columnPosition, rowPosition);
this.newValue = newValue;
}
protected UpdateDataCommand(UpdateDataCommand command) {
super(command);
this.newValue = command.newValue;
}
public Object getNewValue() {
// if (newValue instanceof String) {
// String value = (String)newValue;
// value = value.replaceAll("&", "&");
// value = value.replaceAll("<", "<");
// value = value.replaceAll(">", ">");
// this.newValue = value;
// }
return newValue;
}
public UpdateDataCommand cloneCommand() {
return new UpdateDataCommand(this);
}
}
| 964 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
UpdateDataCommandHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/command/UpdateDataCommandHandler.java | package net.sourceforge.nattable.edit.command;
import net.sourceforge.nattable.command.AbstractLayerCommandHandler;
import net.sourceforge.nattable.layer.DataLayer;
import net.sourceforge.nattable.layer.event.CellVisualChangeEvent;
public class UpdateDataCommandHandler extends AbstractLayerCommandHandler<UpdateDataCommand> {
private final DataLayer dataLayer;
public UpdateDataCommandHandler(DataLayer dataLayer) {
this.dataLayer = dataLayer;
}
public Class<UpdateDataCommand> getCommandClass() {
return UpdateDataCommand.class;
}
@Override
protected boolean doCommand(UpdateDataCommand command) {
try {
int columnPosition = command.getColumnPosition();
int rowPosition = command.getRowPosition();
dataLayer.getDataProvider().setDataValue(columnPosition, rowPosition, command.getNewValue());
dataLayer.fireLayerEvent(new CellVisualChangeEvent(dataLayer, columnPosition, rowPosition));
return true;
} catch (UnsupportedOperationException e) {
e.printStackTrace(System.err);
System.err.println("Failed to update value to: "+command.getNewValue());
return false;
}
}
}
| 1,118 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
InlineCellEditEvent.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/event/InlineCellEditEvent.java | package net.sourceforge.nattable.edit.event;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.coordinate.PositionCoordinate;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.event.ILayerEvent;
import org.eclipse.swt.widgets.Composite;
public class InlineCellEditEvent implements ILayerEvent {
private final PositionCoordinate cellCoordinate;
private ILayer layer;
private final Composite parent;
private final IConfigRegistry configRegistry;
private final Character initialValue;
public InlineCellEditEvent(ILayer layer, PositionCoordinate cellCoordinate, Composite parent, IConfigRegistry configRegistry, Character initialValue) {
this.layer = layer;
this.cellCoordinate = cellCoordinate;
this.parent = parent;
this.configRegistry = configRegistry;
this.initialValue = initialValue;
}
public boolean convertToLocal(ILayer localLayer) {
cellCoordinate.columnPosition = localLayer.underlyingToLocalColumnPosition(layer, cellCoordinate.columnPosition);
if (cellCoordinate.columnPosition < 0 || cellCoordinate.columnPosition >= localLayer.getColumnCount()) {
return false;
}
cellCoordinate.rowPosition = localLayer.underlyingToLocalRowPosition(layer, cellCoordinate.rowPosition);
if (cellCoordinate.rowPosition < 0 || cellCoordinate.rowPosition >= localLayer.getRowCount()) {
return false;
}
this.layer = localLayer;
return true;
}
public int getColumnPosition() {
return cellCoordinate.columnPosition;
}
public int getRowPosition() {
return cellCoordinate.rowPosition;
}
public Composite getParent() {
return parent;
}
public IConfigRegistry getConfigRegistry() {
return configRegistry;
}
public Character getInitialValue() {
return initialValue;
}
public InlineCellEditEvent cloneEvent() {
return new InlineCellEditEvent(layer, cellCoordinate, parent, configRegistry, initialValue);
}
} | 2,014 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
InlineCellEditEventHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/edit/event/InlineCellEditEventHandler.java | package net.sourceforge.nattable.edit.event;
import net.sourceforge.nattable.edit.InlineCellEditController;
import net.sourceforge.nattable.grid.layer.GridLayer;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.layer.event.ILayerEventHandler;
public class InlineCellEditEventHandler implements ILayerEventHandler<InlineCellEditEvent> {
private final GridLayer gridLayer;
public InlineCellEditEventHandler(GridLayer gridLayer) {
this.gridLayer = gridLayer;
}
public Class<InlineCellEditEvent> getLayerEventClass() {
return InlineCellEditEvent.class;
}
public void handleLayerEvent(InlineCellEditEvent event) {
if (event.convertToLocal(gridLayer)) {
LayerCell cell = gridLayer.getCellByPosition(event.getColumnPosition(), event.getRowPosition());
InlineCellEditController.editCellInline(cell, event.getInitialValue(), event.getParent(), event.getConfigRegistry());
}
}
}
| 960 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ColumnHideShowLayer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/hideshow/ColumnHideShowLayer.java | package net.sourceforge.nattable.hideshow;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import net.sourceforge.nattable.hideshow.command.ColumnHideCommandHandler;
import net.sourceforge.nattable.hideshow.command.MultiColumnHideCommandHandler;
import net.sourceforge.nattable.hideshow.command.MultiColumnShowCommandHandler;
import net.sourceforge.nattable.hideshow.command.ShowAllColumnsCommandHandler;
import net.sourceforge.nattable.hideshow.event.HideColumnPositionsEvent;
import net.sourceforge.nattable.hideshow.event.ShowColumnPositionsEvent;
import net.sourceforge.nattable.layer.IUniqueIndexLayer;
public class ColumnHideShowLayer extends AbstractColumnHideShowLayer {
public static final String PERSISTENCE_KEY_HIDDEN_COLUMN_INDEXES = ".hiddenColumnIndexes";
private final Set<Integer> hiddenColumnIndexes;
public ColumnHideShowLayer(IUniqueIndexLayer underlyingLayer) {
super(underlyingLayer);
this.hiddenColumnIndexes = new TreeSet<Integer>();
registerCommandHandler(new MultiColumnHideCommandHandler(this));
registerCommandHandler(new ColumnHideCommandHandler(this));
registerCommandHandler(new ShowAllColumnsCommandHandler(this));
registerCommandHandler(new MultiColumnShowCommandHandler(this));
}
// Persistence
@Override
public void saveState(String prefix, Properties properties) {
if (hiddenColumnIndexes.size() > 0) {
StringBuilder strBuilder = new StringBuilder();
for (Integer index : hiddenColumnIndexes) {
strBuilder.append(index);
strBuilder.append(',');
}
properties.setProperty(prefix + PERSISTENCE_KEY_HIDDEN_COLUMN_INDEXES, strBuilder.toString());
}
super.saveState(prefix, properties);
}
@Override
public void loadState(String prefix, Properties properties) {
String property = properties.getProperty(prefix + PERSISTENCE_KEY_HIDDEN_COLUMN_INDEXES);
if (property != null) {
hiddenColumnIndexes.clear();
StringTokenizer tok = new StringTokenizer(property, ",");
while (tok.hasMoreTokens()) {
String index = tok.nextToken();
hiddenColumnIndexes.add(Integer.valueOf(index));
}
}
super.loadState(prefix, properties);
}
// Hide/show
@Override
public boolean isColumnIndexHidden(int columnIndex) {
return hiddenColumnIndexes.contains(Integer.valueOf(columnIndex));
}
@Override
public Collection<Integer> getHiddenColumnIndexes(){
return hiddenColumnIndexes;
}
public void hideColumnPositions(Collection<Integer> columnPositions) {
Set<Integer> columnIndexes = new HashSet<Integer>();
for (Integer columnPosition : columnPositions) {
columnIndexes.add(Integer.valueOf(getColumnIndexByPosition(columnPosition.intValue())));
}
hiddenColumnIndexes.addAll(columnIndexes);
invalidateCache();
fireLayerEvent(new HideColumnPositionsEvent(this, columnPositions));
}
public void showColumnIndexes(int[] columnIndexes) {
Set<Integer> columnIndexesSet = new HashSet<Integer>();
for (int i = 0; i < columnIndexes.length; i++) {
columnIndexesSet.add(Integer.valueOf(columnIndexes[i]));
}
hiddenColumnIndexes.removeAll(columnIndexesSet);
invalidateCache();
fireLayerEvent(new ShowColumnPositionsEvent(this, getColumnPositionsByIndexes(columnIndexes)));
}
protected void showColumnIndexes(Collection<Integer> columnIndexes) {
for (int columnIndex : columnIndexes) {
hiddenColumnIndexes.remove(Integer.valueOf(columnIndex));
}
invalidateCache();
// Since we are exposing this method for showing individual columns, a structure event must be fired here.
fireLayerEvent(new ShowColumnPositionsEvent(this, columnIndexes));
}
public void showAllColumns() {
Collection<Integer> hiddenColumns = new ArrayList<Integer>(hiddenColumnIndexes);
hiddenColumnIndexes.clear();
invalidateCache();
fireLayerEvent(new ShowColumnPositionsEvent(this, hiddenColumns));
}
private Collection<Integer> getColumnPositionsByIndexes(int[] columnIndexes) {
Collection<Integer> columnPositions = new HashSet<Integer>();
for (int columnIndex : columnIndexes) {
columnPositions.add(Integer.valueOf(getColumnPositionByIndex(columnIndex)));
}
return columnPositions;
}
}
| 4,413 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AbstractColumnHideShowLayer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/hideshow/AbstractColumnHideShowLayer.java | package net.sourceforge.nattable.hideshow;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import net.sourceforge.nattable.coordinate.Range;
import net.sourceforge.nattable.layer.AbstractLayerTransform;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.IUniqueIndexLayer;
import net.sourceforge.nattable.layer.LayerUtil;
import net.sourceforge.nattable.layer.event.ILayerEvent;
import net.sourceforge.nattable.layer.event.IStructuralChangeEvent;
import net.sourceforge.nattable.layer.event.RowStructuralRefreshEvent;
public abstract class AbstractColumnHideShowLayer extends AbstractLayerTransform implements IUniqueIndexLayer {
private List<Integer> cachedVisibleColumnIndexOrder;
private Map<Integer, Integer> cachedHiddenColumnIndexToPositionMap;
private final Map<Integer, Integer> startXCache = new HashMap<Integer, Integer>();
public AbstractColumnHideShowLayer(IUniqueIndexLayer underlyingLayer) {
super(underlyingLayer);
}
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof IStructuralChangeEvent) {
IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
if (structuralChangeEvent.isHorizontalStructureChanged()) {
invalidateCache();
}
}
super.handleLayerEvent(event);
}
@Override
public void loadState(String prefix, Properties properties) {
super.loadState(prefix, properties);
fireLayerEvent(new RowStructuralRefreshEvent(this));
}
// Horizontal features
// Columns
@Override
public int getColumnCount() {
return getCachedVisibleColumnIndexes().size();
}
@Override
public int getColumnIndexByPosition(int columnPosition) {
if (columnPosition < 0 || columnPosition >= getColumnCount()) {
return -1;
}
Integer columnIndex = getCachedVisibleColumnIndexes().get(columnPosition);
if (columnIndex != null) {
return columnIndex.intValue();
} else {
return -1;
}
}
public int getColumnPositionByIndex(int columnIndex) {
return getCachedVisibleColumnIndexes().indexOf(Integer.valueOf(columnIndex));
}
@Override
public int localToUnderlyingColumnPosition(int localColumnPosition) {
int columnIndex = getColumnIndexByPosition(localColumnPosition);
return ((IUniqueIndexLayer) getUnderlyingLayer()).getColumnPositionByIndex(columnIndex);
}
@Override
public int underlyingToLocalColumnPosition(ILayer sourceUnderlyingLayer, int underlyingColumnPosition) {
int columnIndex = getUnderlyingLayer().getColumnIndexByPosition(underlyingColumnPosition);
int columnPosition = getColumnPositionByIndex(columnIndex);
if (columnPosition >= 0) {
return columnPosition;
} else {
Integer hiddenColumnPosition = cachedHiddenColumnIndexToPositionMap.get(Integer.valueOf(columnIndex));
if (hiddenColumnPosition != null) {
return hiddenColumnPosition.intValue();
} else {
return -1;
}
}
}
@Override
public Collection<Range> underlyingToLocalColumnPositions(ILayer sourceUnderlyingLayer, Collection<Range> underlyingColumnPositionRanges) {
Collection<Range> localColumnPositionRanges = new ArrayList<Range>();
for (Range underlyingColumnPositionRange : underlyingColumnPositionRanges) {
int startColumnPosition = getAdjustedUnderlyingToLocalStartPosition(sourceUnderlyingLayer, underlyingColumnPositionRange.start, underlyingColumnPositionRange.end);
int endColumnPosition = getAdjustedUnderlyingToLocalEndPosition(sourceUnderlyingLayer, underlyingColumnPositionRange.end, underlyingColumnPositionRange.start);
// teichstaedt: fixes the problem that ranges where added even if the
// corresponding startPosition weren't found in the underlying layer.
// Without that fix a bunch of ranges of kind Range [-1, 180] which
// causes strange behaviour in Freeze- and other Layers were returned.
if (startColumnPosition > -1) {
localColumnPositionRanges.add(new Range(startColumnPosition, endColumnPosition));
}
}
return localColumnPositionRanges;
}
private int getAdjustedUnderlyingToLocalStartPosition(ILayer sourceUnderlyingLayer, int startUnderlyingPosition, int endUnderlyingPosition) {
int localStartColumnPosition = underlyingToLocalColumnPosition(sourceUnderlyingLayer, startUnderlyingPosition);
int offset = 0;
while (localStartColumnPosition < 0 && (startUnderlyingPosition + offset < endUnderlyingPosition)) {
localStartColumnPosition = underlyingToLocalColumnPosition(sourceUnderlyingLayer, startUnderlyingPosition + offset++);
}
return localStartColumnPosition;
}
private int getAdjustedUnderlyingToLocalEndPosition(ILayer sourceUnderlyingLayer, int endUnderlyingPosition, int startUnderlyingPosition) {
int localEndColumnPosition = underlyingToLocalColumnPosition(sourceUnderlyingLayer, endUnderlyingPosition - 1);
int offset = 0;
while (localEndColumnPosition < 0 && (endUnderlyingPosition - offset > startUnderlyingPosition)) {
localEndColumnPosition = underlyingToLocalColumnPosition(sourceUnderlyingLayer, endUnderlyingPosition - offset++);
}
return localEndColumnPosition + 1;
}
// Width
@Override
public int getWidth() {
int lastColumnPosition = getColumnCount() - 1;
return getStartXOfColumnPosition(lastColumnPosition) + getColumnWidthByPosition(lastColumnPosition);
}
// X
@Override
public int getColumnPositionByX(int x) {
return LayerUtil.getColumnPositionByX(this, x);
}
@Override
public int getStartXOfColumnPosition(int localColumnPosition) {
Integer cachedStartX = startXCache.get(Integer.valueOf(localColumnPosition));
if (cachedStartX != null) {
return cachedStartX.intValue();
}
IUniqueIndexLayer underlyingLayer = (IUniqueIndexLayer) getUnderlyingLayer();
int underlyingPosition = localToUnderlyingColumnPosition(localColumnPosition);
int underlyingStartX = underlyingLayer.getStartXOfColumnPosition(underlyingPosition);
for (Integer hiddenIndex : getHiddenColumnIndexes()) {
int hiddenPosition = underlyingLayer.getColumnPositionByIndex(hiddenIndex.intValue());
if (hiddenPosition <= underlyingPosition) {
underlyingStartX -= underlyingLayer.getColumnWidthByPosition(hiddenPosition);
}
}
startXCache.put(Integer.valueOf(localColumnPosition), Integer.valueOf(underlyingStartX));
return underlyingStartX;
}
// Vertical features
// Rows
public int getRowPositionByIndex(int rowIndex) {
return ((IUniqueIndexLayer) getUnderlyingLayer()).getRowPositionByIndex(rowIndex);
}
// Hide/show
public abstract boolean isColumnIndexHidden(int columnIndex);
public abstract Collection<Integer> getHiddenColumnIndexes();
// Cache
protected void invalidateCache() {
cachedVisibleColumnIndexOrder = null;
startXCache.clear();
}
private List<Integer> getCachedVisibleColumnIndexes() {
if (cachedVisibleColumnIndexOrder == null) {
cacheVisibleColumnIndexes();
}
return cachedVisibleColumnIndexOrder;
}
private void cacheVisibleColumnIndexes() {
cachedVisibleColumnIndexOrder = new ArrayList<Integer>();
cachedHiddenColumnIndexToPositionMap = new HashMap<Integer, Integer>();
startXCache.clear();
ILayer underlyingLayer = getUnderlyingLayer();
int columnPosition = 0;
for (int parentColumnPosition = 0; parentColumnPosition < underlyingLayer.getColumnCount(); parentColumnPosition++) {
int columnIndex = underlyingLayer.getColumnIndexByPosition(parentColumnPosition);
if (!isColumnIndexHidden(columnIndex)) {
cachedVisibleColumnIndexOrder.add(Integer.valueOf(columnIndex));
columnPosition++;
} else {
cachedHiddenColumnIndexToPositionMap.put(Integer.valueOf(columnIndex), Integer.valueOf(columnPosition));
}
}
}
}
| 7,963 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ColumnHideCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/hideshow/command/ColumnHideCommand.java | package net.sourceforge.nattable.hideshow.command;
import net.sourceforge.nattable.command.AbstractColumnCommand;
import net.sourceforge.nattable.layer.ILayer;
public class ColumnHideCommand extends AbstractColumnCommand {
public ColumnHideCommand(ILayer layer, int columnPosition) {
super(layer, columnPosition);
}
protected ColumnHideCommand(ColumnHideCommand command) {
super(command);
}
public ColumnHideCommand cloneCommand() {
return new ColumnHideCommand(this);
}
}
| 513 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
MultiColumnHideCommandHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/hideshow/command/MultiColumnHideCommandHandler.java | package net.sourceforge.nattable.hideshow.command;
import net.sourceforge.nattable.command.AbstractLayerCommandHandler;
import net.sourceforge.nattable.hideshow.ColumnHideShowLayer;
public class MultiColumnHideCommandHandler extends AbstractLayerCommandHandler<MultiColumnHideCommand> {
private final ColumnHideShowLayer columnHideShowLayer;
public MultiColumnHideCommandHandler(ColumnHideShowLayer columnHideShowLayer) {
this.columnHideShowLayer = columnHideShowLayer;
}
public Class<MultiColumnHideCommand> getCommandClass() {
return MultiColumnHideCommand.class;
}
@Override
protected boolean doCommand(MultiColumnHideCommand command) {
columnHideShowLayer.hideColumnPositions(command.getColumnPositions());
return true;
}
}
| 752 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
MultiColumnShowCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/hideshow/command/MultiColumnShowCommand.java | package net.sourceforge.nattable.hideshow.command;
import net.sourceforge.nattable.command.AbstractContextFreeCommand;
public class MultiColumnShowCommand extends AbstractContextFreeCommand{
private final int[] columnIndexes;
public MultiColumnShowCommand(int[] columnIndexes) {
this.columnIndexes = columnIndexes;
}
protected MultiColumnShowCommand(MultiColumnShowCommand command) {
columnIndexes = new int[command.columnIndexes.length];
System.arraycopy(command.columnIndexes, 0, columnIndexes, 0, command.columnIndexes.length);
}
public int[] getColumnIndexes() {
return columnIndexes;
}
} | 635 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.