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 |
---|---|---|---|---|---|---|---|---|---|---|---|
Md5Encode.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/heartsome.java.tools.plugin/src/cn/org/tools/utils/encrypt/Md5Encode.java | /**
* Md5Encode.java
*
* Version information :
*
* Date:Jan 13, 2010
*
* Copyright notice :
*/
package cn.org.tools.utils.encrypt;
import java.security.MessageDigest;
/**
* 使用 MD5 标准对数据进行加密的工具类.
* @author Terry
* @version
* @since JDK1.6
*/
public class Md5Encode {
/**
* 构造方法.
*/
protected Md5Encode() {
throw new UnsupportedOperationException(); // prevents calls from subclass
}
/**
* The main method.
* @param args
* the arguments
*/
public static void main(String[] args) {
String tmp = "123fadfafasfafadfafafhajkldfhdasjlkhfjlfasdf;ajs fk;lasjf ;asjf; as";
System.out.println(encode(tmp));
}
/**
* 加密.
* @param s
* 要加密的字符串
* @return String
* 加密后的字符串
*/
public static final String encode(String s) {
char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
try {
byte[] strTemp = s.getBytes();
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
mdTemp.update(strTemp);
byte[] md = mdTemp.digest();
int j = md.length;
char[] str = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
return null;
}
}
}
| 1,427 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DESImpl.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/heartsome.java.tools.plugin/src/cn/org/tools/utils/encrypt/DESImpl.java | /**
* DESImpl.java
*
* Version information :
*
* Date:Jan 13, 2010
*
* Copyright notice :
*/
package cn.org.tools.utils.encrypt;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
/**
* 使用 DES 标准对数据进行加密的工具类.
* @author Terry
* @version
* @since JDK1.6
*/
public class DESImpl {
/**
* 构造方法.
*/
protected DESImpl() {
throw new UnsupportedOperationException(); // prevents calls from subclass
}
/** The Constant PASSWORD_CRYPT_KEY. */
private static final String PASSWORD_CRYPT_KEY = "ty7hia89wesyr98sar9d8teg";
/** The Constant DES. */
private static final String DES = "DES";
/**
* 加密.
* @param src
* 数据源
* @param key
* 密钥,长度必须是8的倍数
* @return byte[]
* 加密后的数据
* @throws Exception
* the exception
*/
public static byte[] encrypt(byte[] src, byte[] key) throws Exception {
SecureRandom sr = new SecureRandom();
DESKeySpec dks = new DESKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance(DES);
cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
return cipher.doFinal(src);
}
/**
* 解密.
* @param src
* 数据源
* @param key
* 密钥,长度必须是8的倍数
* @return byte[]
* 解密后的原始数据
* @throws Exception
* the exception
*/
public static byte[] decrypt(byte[] src, byte[] key) throws Exception {
SecureRandom sr = new SecureRandom();
DESKeySpec dks = new DESKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance(DES);
cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
return cipher.doFinal(src);
}
/**
* 密码解密.
* @param data
* 数据
* @return String
* 解密后的原始数据
* @throws Exception
*/
public static final String decrypt(String data) {
try {
return new String(decrypt(hex2byte(data.getBytes()), PASSWORD_CRYPT_KEY.getBytes()));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 密码加密.
* @param password
* 密码
* @return String
* 加密后的数据,如果加密过程中出现异常,返回 null
*/
public static final String encrypt(String password) {
try {
return byte2hex(encrypt(password.getBytes(), PASSWORD_CRYPT_KEY.getBytes()));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 将 byte 数组转化为十六进制字符串.
* @param b
* 字节数组
* @return String
* 字节数组转换成的字符串
*/
public static String byte2hex(byte[] b) {
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++) {
stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1) {
hs = hs + "0" + stmp;
} else {
hs = hs + stmp;
}
}
return hs.toUpperCase();
}
/**
* 将十六进制字节数组转化为有符号的整数字节数组
* @param b
* 字节数组
* @return byte[]
* 转化后的有符号的整数字节数组,如果 b 的长度为奇数,抛出异常
*/
public static byte[] hex2byte(byte[] b) {
if ((b.length % 2) != 0) {
throw new IllegalArgumentException("");
}
byte[] b2 = new byte[b.length / 2];
for (int n = 0; n < b.length; n += 2) {
String item = new String(b, n, 2);
b2[n / 2] = (byte) Integer.parseInt(item, 16);
}
return b2;
}
/**
* The main method.
* @param args
* the arguments
*/
public static void main(String[] args) {
String a = DESImpl.encrypt("abc");
System.out.println(a);
String b = DESImpl.decrypt(a);
System.out.println(b);
}
}
| 4,039 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
Constants.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/heartsome.java.tools.plugin/src/cn/org/tools/utils/constant/Constants.java | /**
* Constants.java
*
* Version information :
*
* Date:Jan 13, 2010
*
* Copyright notice :
*/
package cn.org.tools.utils.constant;
/**
* The Class Constants.
* @author Terry
* @version
* @since JDK1.6
*/
public class Constants {
/**
* 构造方法.
*/
protected Constants() {
throw new UnsupportedOperationException(); // prevents calls from subclass
}
/** The DEBUG. */
public static final boolean DEBUG = true;
/** The DATABAS e_ type. */
public static final int DATABASE_TYPE = 0;
/** The Constant DATABASE_TYPE_MYSQL. */
public static final int DATABASE_TYPE_MYSQL = 0;
/** The Constant DATABASE_TYPE_MSSQL. */
public static final int DATABASE_TYPE_MSSQL = 1;
/** The Constant DATABASE_TYPE_OROCALE. */
public static final int DATABASE_TYPE_OROCALE = 2;
/** The Constant DATABASE_TYPE_CONFIG. */
public static final String DATABASE_TYPE_CONFIG = "mysql";
}
| 914 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
SimpleModelExample.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/examples/table/SimpleModelExample.java | /*
* File: SimpleModelExample.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.examples.table;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IJaretTableModel;
import de.jaret.util.ui.table.model.ITableViewState;
import de.jaret.util.ui.table.model.simple.SimpleJaretTableModel;
import de.jaret.util.ui.table.util.action.JaretTableActionFactory;
/**
* Simple exmaple for demonstrating the use of the jaret table.
*
* @author Peter Kliem
* @version $Id: SimpleModelExample.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class SimpleModelExample {
// private static final int NUMCOLS = 5;
// private static final int NUMROWS = 5;
private static final int NUMCOLS = 100;
private static final int NUMROWS = 200;
Shell _shell;
IJaretTableModel _tableModel;
public SimpleModelExample(IJaretTableModel tableModel) {
_tableModel = tableModel;
_shell = new Shell(Display.getCurrent());
_shell.setText("simple jaret table example");
createControls();
_shell.open();
Display display;
display = _shell.getDisplay();
_shell.pack();
_shell.setSize(1000, 700);
/*
* do the event loop until the shell is closed to block the call
*/
while (_shell != null && !_shell.isDisposed()) {
try {
if (!display.readAndDispatch())
display.sleep();
} catch (Throwable e) {
e.printStackTrace();
}
}
display.update();
}
JaretTable _jt;
/**
* Create the controls that compose the console test.
*
*/
protected void createControls() {
GridLayout gl = new GridLayout();
gl.numColumns = 1;
_shell.setLayout(gl);
GridData gd = new GridData(GridData.FILL_BOTH);
_jt = new JaretTable(_shell, SWT.V_SCROLL | SWT.H_SCROLL);
_jt.setLayoutData(gd);
if (_tableModel == null) {
SimpleJaretTableModel model = new SimpleJaretTableModel();
for (int x = 0; x <= NUMCOLS; x++) {
model.setHeaderLabel(x, "" + x);
for (int y = 0; y <= NUMROWS; y++) {
model.setValueAt(x, y, x + "/" + y);
}
}
_tableModel = model;
}
_jt.setTableModel(_tableModel);
// set rowheight mode to variable .. optimal would be quite expensive on each col resize
_jt.getTableViewState().setRowHeightMode(ITableViewState.RowHeightMode.VARIABLE);
for (int i = 0; i < NUMCOLS; i++) {
IColumn col = _tableModel.getColumn(i);
_jt.getTableViewState().setColumnWidth(col, 40);
}
JaretTableActionFactory af = new JaretTableActionFactory();
MenuManager mm = new MenuManager();
mm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_CONFIGURECOLUMNS));
_jt.setHeaderContextMenu(mm.createContextMenu(_jt));
MenuManager rm = new MenuManager();
rm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_OPTROWHEIGHT));
rm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_OPTALLROWHEIGHTS));
_jt.setRowContextMenu(rm.createContextMenu(_jt));
TableControlPanel ctrlPanel = new TableControlPanel(_shell, SWT.NULL, _jt);
}
public static void main(String args[]) {
SimpleModelExample te = new SimpleModelExample(null);
}
}
| 4,276 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
StyleTextCellRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/examples/table/StyleTextCellRenderer.java | package de.jaret.examples.table;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.TextLayout;
import org.eclipse.swt.graphics.TextStyle;
import org.eclipse.swt.widgets.Display;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
import de.jaret.util.ui.table.renderer.ICellStyle;
import de.jaret.util.ui.table.renderer.TextCellRenderer;
public class StyleTextCellRenderer extends TextCellRenderer {
private TextLayout textLayout;
/** 添加样式的文本 */
private String strStyleText;
/** 设置样式时是否区分大小写 */
private boolean blnIsCaseSensitive;
private TextStyle style;
public StyleTextCellRenderer(String strStyleText, boolean blnIsCaseSensitive) {
super();
this.strStyleText = strStyleText;
this.blnIsCaseSensitive = blnIsCaseSensitive;
}
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
IColumn column, boolean drawFocus, boolean selected, boolean printing) {
super.draw(gc, jaretTable, cellStyle, drawingArea, row, column, drawFocus, selected, printing);
Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
Rectangle rect = applyInsets(drect);
String s = convertValue(row, column);
if (s != null && strStyleText != null) {
int index = -1;
if (blnIsCaseSensitive) {
index = s.toUpperCase().indexOf(strStyleText.toUpperCase());
} else {
index = s.indexOf(strStyleText);
}
if (index != -1) {
if (textLayout == null) {
textLayout = new TextLayout(gc.getDevice());
jaretTable.getParent().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
textLayout.dispose();
}
});
}
textLayout.setText(s);
textLayout.setFont(gc.getFont());
textLayout.setWidth(rect.width);
if (style == null) {
final Color color = new Color(gc.getDevice(), 150, 100, 100);
final Font font = new Font(gc.getDevice(), gc.getFont().getFontData()[0].getName(), gc.getFont()
.getFontData()[0].getHeight(), SWT.ITALIC);
style = new TextStyle(font, color, null);
jaretTable.getParent().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
color.dispose();
font.dispose();
}
});
}
for (int i = 1; i < strStyleText.length(); i++) {
int j = indexOf(s, strStyleText, i, blnIsCaseSensitive);
if (j != -1) {
textLayout.setStyle(style, j, j + strStyleText.length() - 1);
} else {
break;
}
}
gc.fillRectangle(rect);
textLayout.draw(gc, rect.x, rect.y);
gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
}
}
}
public int indexOf(String srcStr, String str, int index, boolean isCaseSensitive) {
if (index == 0) {
return -1;
}
if (index == 1) {
if (isCaseSensitive) {
return srcStr.indexOf(str);
} else {
return srcStr.toUpperCase().indexOf(str.toUpperCase());
}
}
if (isCaseSensitive) {
return srcStr.indexOf(str, indexOf(srcStr, str, index - 1, isCaseSensitive) + str.length());
} else {
return srcStr.toUpperCase().indexOf(str.toUpperCase(),
indexOf(srcStr, str, index - 1, isCaseSensitive) + str.length());
}
}
}
| 3,606 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
TableControlPanel.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/examples/table/TableControlPanel.java | /*
* File: TableControlPanel.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.examples.table;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.HTMLTransfer;
import org.eclipse.swt.dnd.RTFTransfer;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.printing.PrinterData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Scale;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.JaretTablePrinter;
import de.jaret.util.ui.table.model.AbstractRowFilter;
import de.jaret.util.ui.table.model.AbstractRowSorter;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IJaretTableModel;
import de.jaret.util.ui.table.model.IRow;
import de.jaret.util.ui.table.model.ITableViewState;
import de.jaret.util.ui.table.model.simple.SimpleJaretTableModel;
import de.jaret.util.ui.table.print.JaretTablePrintConfiguration;
import de.jaret.util.ui.table.print.JaretTablePrintDialog;
import de.jaret.util.ui.table.renderer.DefaultTableHeaderRenderer;
import de.jaret.util.ui.table.renderer.ICellStyle;
import de.jaret.util.ui.table.renderer.IStyleStrategy;
import de.jaret.util.ui.table.strategies.DefaultCCPStrategy;
/**
* Simple controlpanel for a jaret table (demonstration and test).
*
* @author Peter Kliem
* @version $Id: TableControlPanel.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class TableControlPanel extends Composite {
private JaretTable _table;
public TableControlPanel(Composite arg0, int arg1, JaretTable table) {
super(arg0, arg1);
_table = table;
createControls();
}
/**
* @param panel
*/
private void createControls() {
RowLayout rl = new RowLayout();
rl.type = SWT.HORIZONTAL;
this.setLayout(rl);
Composite col1 = new Composite(this, SWT.NULL);
rl = new RowLayout();
rl.type = SWT.VERTICAL;
col1.setLayout(rl);
Composite col2 = new Composite(this, SWT.NULL);
rl = new RowLayout();
rl.type = SWT.VERTICAL;
col2.setLayout(rl);
Composite col3 = new Composite(this, SWT.NULL);
rl = new RowLayout();
rl.type = SWT.VERTICAL;
col3.setLayout(rl);
final Button autoFilterCheck = new Button(col1, SWT.CHECK);
autoFilterCheck.setText("AutoFilter");
autoFilterCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setAutoFilterEnable(autoFilterCheck.getSelection());
}
});
final Button drawHeaderCheck = new Button(col1, SWT.CHECK);
drawHeaderCheck.setSelection(_table.getDrawHeader());
drawHeaderCheck.setText("Draw header");
drawHeaderCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setDrawHeader(drawHeaderCheck.getSelection());
}
});
final Button fillDragCheck = new Button(col1, SWT.CHECK);
fillDragCheck.setSelection(_table.isSupportFillDragging());
fillDragCheck.setText("Support fill dragging");
fillDragCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setSupportFillDragging(fillDragCheck.getSelection());
}
});
Button b = new Button(col2, SWT.PUSH);
b.setText("Print");
b.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
print();
}
});
final Scale headerRotationScale = new Scale(col2, SWT.HORIZONTAL);
headerRotationScale.setMaximum(90);
headerRotationScale.setMinimum(0);
headerRotationScale.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent ev) {
int val = headerRotationScale.getSelection();
((DefaultTableHeaderRenderer) _table.getHeaderRenderer()).setRotation(val);
if (val > 0) {
_table.setHeaderHeight(50);
} else {
_table.setHeaderHeight(18);
}
_table.redraw();
}
});
final Button allowHeaderResizeCheck = new Button(col1, SWT.CHECK);
allowHeaderResizeCheck.setSelection(_table.getDrawHeader());
allowHeaderResizeCheck.setText("Allow header resize");
allowHeaderResizeCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setHeaderResizeAllowed(allowHeaderResizeCheck.getSelection());
}
});
final Button allowRowResizeCheck = new Button(col1, SWT.CHECK);
allowRowResizeCheck.setSelection(_table.getDrawHeader());
allowRowResizeCheck.setText("Allow row resize");
allowRowResizeCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setRowResizeAllowed(allowRowResizeCheck.getSelection());
}
});
final Button allowColResizeCheck = new Button(col1, SWT.CHECK);
allowColResizeCheck.setSelection(_table.getDrawHeader());
allowColResizeCheck.setText("Allow column resize");
allowColResizeCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setColumnResizeAllowed(allowColResizeCheck.getSelection());
}
});
Label l = new Label(col2, SWT.NULL);
l.setText("Fixed columns");
final Combo fixedColCombo = new Combo(col2, SWT.BORDER | SWT.READ_ONLY);
fixedColCombo.setItems(new String[] {"0", "1", "2", "3", "4"});
fixedColCombo.select(0);
fixedColCombo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setFixedColumns(fixedColCombo.getSelectionIndex());
}
});
l = new Label(col2, SWT.NULL);
l.setText("Fixed rows");
final Combo fixedRowCombo = new Combo(col2, SWT.BORDER | SWT.READ_ONLY);
fixedRowCombo.setItems(new String[] {"0", "1", "2", "3", "4"});
fixedRowCombo.select(0);
fixedRowCombo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setFixedRows(fixedRowCombo.getSelectionIndex());
}
});
final Button resizeRestrictionCheck = new Button(col1, SWT.CHECK);
resizeRestrictionCheck.setSelection(_table.getResizeRestriction());
resizeRestrictionCheck.setText("Restrict resizing to headers/row headers");
resizeRestrictionCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setResizeRestriction(resizeRestrictionCheck.getSelection());
}
});
final Button excludeFixedRowsCheck = new Button(col1, SWT.CHECK);
excludeFixedRowsCheck.setSelection(_table.getExcludeFixedRowsFromSorting());
excludeFixedRowsCheck.setText("Exclude fixed rows from sorting");
excludeFixedRowsCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.setExcludeFixedRowsFromSorting(excludeFixedRowsCheck.getSelection());
}
});
final Button rowFilterCheck = new Button(col1, SWT.CHECK);
rowFilterCheck.setSelection(false);
rowFilterCheck.setText("Set rowfilter (even char count on col2)");
rowFilterCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
boolean sel = rowFilterCheck.getSelection();
if (sel) {
_table.setRowFilter(new AbstractRowFilter() {
public boolean isInResult(IRow row) {
return ((DummyRow) row).getT2() != null && ((DummyRow) row).getT2().length() % 2 == 0;
}
});
} else {
_table.setRowFilter(null);
}
}
});
final Button rowSorterCheck = new Button(col1, SWT.CHECK);
rowSorterCheck.setSelection(false);
rowSorterCheck.setText("Set rowsorter (char count on col3)");
rowSorterCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
boolean sel = rowSorterCheck.getSelection();
if (sel) {
_table.setRowSorter(new AbstractRowSorter() {
public int compare(IRow o1, IRow o2) {
int c1 = ((DummyRow) o1).getT3() != null ? ((DummyRow) o1).getT3().length() : 0;
int c2 = ((DummyRow) o2).getT3() != null ? ((DummyRow) o2).getT3().length() : 0;
return c1 - c2;
}
});
} else {
_table.setRowSorter(null);
}
}
});
final Button onlyRowSelectionCheck = new Button(col1, SWT.CHECK);
onlyRowSelectionCheck.setSelection(false);
onlyRowSelectionCheck.setText("Only row selection allowed");
onlyRowSelectionCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
boolean sel = onlyRowSelectionCheck.getSelection();
_table.getSelectionModel().setOnlyRowSelectionAllowed(sel);
_table.getSelectionModel().clearSelection();
}
});
final Button optimizeScrollingCheck = new Button(col1, SWT.CHECK);
optimizeScrollingCheck.setSelection(_table.getOptimizeScrolling());
optimizeScrollingCheck.setText("Optimize scrolling");
optimizeScrollingCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
boolean sel = optimizeScrollingCheck.getSelection();
_table.setOptimizeScrolling(sel);
}
});
/**
* Style strategy coloring the background of odd row indizes. The implementation is brute force creating
* tons of objects underway ... so be careful.
*/
final IStyleStrategy _styleStrategy = new IStyleStrategy() {
public ICellStyle getCellStyle(IRow row, IColumn column, ICellStyle incomingStyle,
ICellStyle defaultCellStyle) {
if (_table.getInternalRowIndex(row) % 2 == 0) {
return incomingStyle;
} else {
ICellStyle s = incomingStyle.copy();
s.setBackgroundColor(new RGB(230, 230, 230));
return s;
}
}
};
final Button bgColoringCheck = new Button(col1, SWT.CHECK);
bgColoringCheck.setSelection(_table.getTableViewState().getCellStyleProvider().getStyleStrategy() != null);
bgColoringCheck.setText("BG coloring (IStyleStrategy)");
bgColoringCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
boolean sel = bgColoringCheck.getSelection();
if (!sel) {
_table.getTableViewState().getCellStyleProvider().setStyleStrategy(null);
_table.redraw();
} else {
_table.getTableViewState().getCellStyleProvider().setStyleStrategy(_styleStrategy);
_table.redraw();
}
}
});
Button b2 = new Button(col2, SWT.PUSH);
b2.setText("Spawn new window");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
// hack
if (_table.getHierarchicalModel() == null) {
if (_table.getTableModel() instanceof SimpleJaretTableModel) {
new SimpleModelExample(_table.getTableModel());
} else {
new TableExample(_table.getTableModel());
}
} else {
new TableHierarchicalExample(_table.getHierarchicalModel());
}
}
});
b2 = new Button(col2, SWT.PUSH);
b2.setText("Start changing bars");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
for (int i = 0; i < _table.getTableModel().getRowCount(); i++) {
Runnable r = new Changer(_table.getTableModel(), i);
Thread t = new Thread(r);
t.start();
}
}
});
b2 = new Button(col3, SWT.PUSH);
b2.setText("Set heightmode OPTIMAL");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.getTableViewState().setRowHeightMode(ITableViewState.RowHeightMode.OPTIMAL);
}
});
b2 = new Button(col3, SWT.PUSH);
b2.setText("Set heightmode OPTANDVAR");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.getTableViewState().setRowHeightMode(ITableViewState.RowHeightMode.OPTANDVAR);
}
});
b2 = new Button(col3, SWT.PUSH);
b2.setText("Set heightmode VARIABLE");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.getTableViewState().setRowHeightMode(ITableViewState.RowHeightMode.VARIABLE);
}
});
b2 = new Button(col3, SWT.PUSH);
b2.setText("Set heightmode FIXED");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
_table.getTableViewState().setRowHeightMode(ITableViewState.RowHeightMode.FIXED);
}
});
l = new Label(col3, SWT.NULL);
l.setText("Column resize mode");
final Combo colModeCombo = new Combo(col3, SWT.BORDER | SWT.READ_ONLY);
colModeCombo.setItems(new String[] {"NONE", "SUBSEQUENT", "ALLSUBSEQUENT", "ALL"});
colModeCombo.select(0);
colModeCombo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
String sel = colModeCombo.getText();
_table.getTableViewState().setColumnResizeMode(ITableViewState.ColumnResizeMode.valueOf(sel));
}
});
b2 = new Button(col3, SWT.PUSH);
b2.setText("Clipboard info");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
Clipboard cb = new Clipboard(Display.getCurrent());
System.out.println("Clipboard info");
TextTransfer textTransfer = TextTransfer.getInstance();
Object content = cb.getContents(textTransfer);
if (content != null) {
System.out.println("TEXT: " + content.getClass() + ":" + content.toString());
}
RTFTransfer rtfTransfer = RTFTransfer.getInstance();
content = cb.getContents(rtfTransfer);
if (content != null) {
System.out.println("RTF: " + content.getClass() + ":" + content.toString());
}
HTMLTransfer htmlTransfer = HTMLTransfer.getInstance();
content = cb.getContents(htmlTransfer);
if (content != null) {
System.out.println("HTML: " + content.getClass() + ":" + content.toString());
}
}
});
final Button includeColHeadingsWhenCopying = new Button(col3, SWT.CHECK);
includeColHeadingsWhenCopying.setText("Include col header when copying");
if (_table.getCcpStrategy() instanceof DefaultCCPStrategy) {
DefaultCCPStrategy stategy = (DefaultCCPStrategy) _table.getCcpStrategy();
includeColHeadingsWhenCopying.setSelection(stategy.getIncludeHeadersInCopy());
includeColHeadingsWhenCopying.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
boolean sel = includeColHeadingsWhenCopying.getSelection();
DefaultCCPStrategy stategy = (DefaultCCPStrategy) _table.getCcpStrategy();
stategy.setIncludeHeadersInCopy(sel);
}
});
} else {
includeColHeadingsWhenCopying.setEnabled(false);
}
}
public class Changer implements Runnable {
IJaretTableModel _model;
int _idx;
public Changer(IJaretTableModel model, int idx) {
_model = model;
_idx = idx;
}
public void run() {
DummyRow r = (DummyRow) _model.getRow(_idx);
while (r.getInteger() < 100) {
System.out.println("Index " + _idx + " val " + r.getInteger());
r.setInteger(r.getInteger() + 1);
try {
Thread.sleep((long) (Math.random() * 1000));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public void print() {
JaretTablePrinter jtp = new JaretTablePrinter(null, _table);
JaretTablePrintDialog pDialog = new JaretTablePrintDialog(Display.getCurrent().getActiveShell(), null, jtp,
null);
pDialog.open();
if (pDialog.getReturnCode() == Dialog.OK) {
PrinterData pdata = pDialog.getPrinterData();
JaretTablePrintConfiguration conf = pDialog.getConfiguration();
Printer printer = new Printer(pdata);
jtp.setPrinter(printer);
jtp.print(conf);
printer.dispose();
}
jtp.dispose();
}
}
| 19,953 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DummyRow.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/examples/table/DummyRow.java | /*
* File: DummyRow.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.examples.table;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import org.eclipse.swt.graphics.Image;
import de.jaret.util.misc.PropertyObservableBase;
import de.jaret.util.ui.table.model.IRow;
/**
* Simple test row.
*
* @author Peter Kliem
* @version $Id: DummyRow.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class DummyRow extends PropertyObservableBase implements IRow {
public static enum TestEnum {
ENUMVAL1, ENUMVAL2, ENUMVAL3
};
private String t1;
private String t2;
private String t3;
private boolean b1;
private Date d1;
private Image img;
private int integer = 0;
private double adouble = 0.0;
private TestEnum enumProperty = TestEnum.ENUMVAL1;
private String x1;
private int _riskProb = 1;
private int _riskSeverity = 1;
private Risk _risk = new Risk(_riskProb, _riskSeverity);
public class Risk {
private int _riskProb = 1;
private int _riskSeverity = 1;
public Risk(int riskProb, int riskSeverity) {
_riskProb = riskProb;
_riskSeverity = riskSeverity;
}
/**
* @return the riskProb
*/
public int getRiskProb() {
return _riskProb;
}
/**
* @return the riskSeverity
*/
public int getRiskSeverity() {
return _riskSeverity;
}
@Override
public String toString() {
return "Risk " + _riskProb * _riskSeverity;
}
}
public DummyRow(String t1, String t2, String t3, boolean b1, Date d1) {
this(t1, t2, t3, b1, d1, null);
}
public DummyRow(String t1, String t2, String t3, boolean b1, Date d1, Image img) {
this.t1 = t1;
this.t2 = t2;
this.t3 = t3;
this.b1 = b1;
this.d1 = d1;
this.img = img;
integer = (int) (Math.random() * 100);
}
/**
* @return Returns the t1.
*/
public String getT1() {
return t1;
}
/**
* @param t1 The t1 to set.
*/
public void setT1(String t1) {
this.t1 = t1;
firePropertyChange("T1", null, t1);
}
/**
* @return Returns the t2.
*/
public String getT2() {
return t2;
}
/**
* @param t2 The t2 to set.
*/
public void setT2(String t2) {
this.t2 = t2;
firePropertyChange("T2", null, t2);
}
public String getId() {
return Integer.toString(hashCode());
}
/**
* @return Returns the t3.
*/
public String getT3() {
return t3;
}
/**
* @param t3 The t3 to set.
*/
public void setT3(String t3) {
this.t3 = t3;
firePropertyChange("T3", null, t3);
}
public String getX1() {
return x1;
}
public void setX1(String x1) {
this.x1 = x1;
firePropertyChange("X1", null, x1);
}
/**
* @return Returns the b1.
*/
public boolean getB1() {
return b1;
}
/**
* @param b1 The b1 to set.
*/
public void setB1(boolean b1) {
this.b1 = b1;
firePropertyChange("B1", null, b1);
}
/**
* @return Returns the d1.
*/
public Date getD1() {
return d1;
}
/**
* @param d1 The d1 to set.
*/
public void setD1(Date d1) {
this.d1 = d1;
firePropertyChange("D1", null, d1);
}
/**
* Setter for d1 trying to parse a string.
*
* @param dateString
*/
public void setD1(String dateString) {
Date d = null;
if (dateString == null || dateString.trim().length() == 0) {
setD1(d);
return;
}
try {
DateFormat df = DateFormat.getDateInstance();
d = df.parse(dateString);
} catch (ParseException e) {
// ignore
}
if (d == null) {
try {
DateFormat df = DateFormat.getDateTimeInstance();
d = df.parse(dateString);
} catch (ParseException e) {
// ignore
}
}
if (d != null) {
setD1(d);
} else {
throw new RuntimeException("could not parse date");
}
}
/**
* @return Returns the img.
*/
public Image getImg() {
return img;
}
/**
* @param img The img to set.
*/
public void setImg(Image img) {
this.img = img;
firePropertyChange("Img", null, img);
}
/**
* @return Returns the adouble.
*/
public double getAdouble() {
return adouble;
}
/**
* @param adouble The adouble to set.
*/
public void setAdouble(double adouble) {
this.adouble = adouble;
firePropertyChange("Adouble", null, adouble);
}
/**
* @return Returns the integer.
*/
public int getInteger() {
return integer;
}
/**
* @param integer The integer to set.
*/
public void setInteger(int integer) {
this.integer = integer;
firePropertyChange("Integer", null, integer);
}
/**
* @return the enumProperty
*/
public TestEnum getEnumProperty() {
return enumProperty;
}
/**
* @param enumProperty the enumProperty to set
*/
public void setEnumProperty(TestEnum enumProperty) {
this.enumProperty = enumProperty;
firePropertyChange("EnumProperty", null, enumProperty);
}
/**
* @return the risk
*/
public Risk getRisk() {
return _risk;
}
/**
* @param risk the risk to set
*/
public void setRisk(Risk risk) {
_risk = risk;
firePropertyChange("Risk", null, risk);
setRiskProb(risk.getRiskProb());
setRiskSeverity(risk.getRiskSeverity());
}
/**
* @return the riskProb
*/
public int getRiskProb() {
return _riskProb;
}
/**
* @param riskProb the riskProb to set
*/
public void setRiskProb(int riskProb) {
if (riskProb != _riskProb) {
_riskProb = riskProb;
firePropertyChange("RiskProb", null, riskProb);
setRisk(new Risk(_riskProb, _riskSeverity));
}
}
/**
* @return the riskSeverity
*/
public int getRiskSeverity() {
return _riskSeverity;
}
/**
* @param riskSeverity the riskSeverity to set
*/
public void setRiskSeverity(int riskSeverity) {
if (riskSeverity != _riskSeverity) {
_riskSeverity = riskSeverity;
firePropertyChange("RiskSeverity", null, riskSeverity);
setRisk(new Risk(_riskProb, _riskSeverity));
}
}
}
| 7,561 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
SampleTextAutoFilter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/examples/table/SampleTextAutoFilter.java | package de.jaret.examples.table;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
import de.jaret.util.ui.table.filter.AbstractAutoFilter;
import de.jaret.util.ui.table.model.IRow;
/**
* Sample autofilter rendering as a textbox and filters everything that does not contain the entered String.
*
* @author kliem
* @version $Id: SampleTextAutoFilter.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class SampleTextAutoFilter extends AbstractAutoFilter implements ModifyListener {
private Text _text;
public void dispose() {
if (_text != null) {
_text.dispose();
}
}
public Control getControl() {
return _text;
}
public void update() {
if (_text == null) {
_text = new Text(_table, SWT.NULL);
_text.addModifyListener(this);
}
}
public boolean isInResult(IRow row) {
String filter = _text.getText().trim();
if (filter.length()>0) {
Object value = _column.getValue(row);
String valString = value != null ? value.toString() : "";
return valString.indexOf(filter) != -1;
}
return true;
}
/**
* {@inheritDoc}
*/
public void reset() {
_text.setText("");
firePropertyChange("FILTER", null, "x");
}
public void modifyText(ModifyEvent e) {
firePropertyChange("FILTER", null, "x");
}
}
| 1,684 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
SampleIntegerAutoFilter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/examples/table/SampleIntegerAutoFilter.java | package de.jaret.examples.table;
import java.util.Set;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Control;
import de.jaret.util.ui.table.filter.AbstractAutoFilter;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Sample auto filter implementation for selecting int values <50, >50.
*
* @author kliem
* @version $Id: SampleIntegerAutoFilter.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class SampleIntegerAutoFilter extends AbstractAutoFilter implements SelectionListener {
protected CCombo _combo;
protected static String FILTER_ALL = "(all)";
protected static String FILTER_LT50 = "<50";
protected static String FILTER_GT50 = ">=50";
public void dispose() {
if (_combo != null) {
_combo.dispose();
}
}
public Control getControl() {
return _combo;
}
public boolean isInResult(IRow row) {
String filter = _combo.getText();
Object value = _column.getValue(row);
int intVal = 0;
if (value != null && value instanceof Integer) {
intVal = ((Integer)value).intValue();
}
if (!filter.equals(FILTER_ALL)) {
if (filter.equals(FILTER_LT50)) {
return intVal < 50;
}
if (filter.equals(FILTER_GT50)) {
return intVal >= 50;
}
}
return true;
}
public void update() {
if (_combo == null) {
_combo = new CCombo(_table, SWT.BORDER | SWT.READ_ONLY);
_combo.addSelectionListener(this);
}
String[] items = new String[3];
int idx = 0;
items[idx++] = FILTER_ALL;
items[idx++] = FILTER_LT50;
items[idx++] = FILTER_GT50;
_combo.setItems(items);
_combo.select(0);
}
/**
* {@inheritDoc}
*/
public void reset() {
_combo.select(0);
firePropertyChange("FILTER", null, "x");
}
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
firePropertyChange("FILTER", null, "x");
}
}
| 2,403 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DummyTableNode.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/examples/table/DummyTableNode.java | /*
* File: DummyTableNode.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.examples.table;
import de.jaret.util.ui.table.model.AbstractTableNode;
/**
* Dummy table node class for test and demonstarting purposes.
*
* @author Peter Kliem
* @version $Id: DummyTableNode.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class DummyTableNode extends AbstractTableNode {
protected String _id;
private String t1;
private String t2;
private String t3;
private boolean b1;
public DummyTableNode(String id, String t1, String t2, String t3) {
_id = id;
this.t1 = t1;
this.t2 = t2;
this.t3 = t3;
}
public String getId() {
return _id;
}
/**
* @return Returns the t1.
*/
public String getT1() {
return t1;
}
/**
* @param t1 The t1 to set.
*/
public void setT1(String t1) {
this.t1 = t1;
firePropertyChange("T1", null, t1);
}
/**
* @return Returns the t2.
*/
public String getT2() {
return t2;
}
/**
* @param t2 The t2 to set.
*/
public void setT2(String t2) {
this.t2 = t2;
firePropertyChange("T2", null, t2);
}
/**
* @return Returns the t3.
*/
public String getT3() {
return t3;
}
/**
* @param t3 The t3 to set.
*/
public void setT3(String t3) {
this.t3 = t3;
firePropertyChange("T3", null, t3);
}
/**
* @return the b1
*/
public boolean getB1() {
return b1;
}
/**
* @param b1 the b1 to set
*/
public void setB1(boolean b1) {
this.b1 = b1;
firePropertyChange("B3", null, b1);
}
}
| 2,194 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
TableExample.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/examples/table/TableExample.java | /*
* File: TableExample.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.examples.table;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import de.jaret.examples.table.renderer.RiskCellEditor;
import de.jaret.examples.table.renderer.RiskRenderer;
import de.jaret.util.ui.ResourceImageDescriptor;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.editor.IntegerCellEditor;
import de.jaret.util.ui.table.editor.ObjectComboEditor;
import de.jaret.util.ui.table.model.DefaultJaretTableModel;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IJaretTableModel;
import de.jaret.util.ui.table.model.ITableViewState;
import de.jaret.util.ui.table.model.PropCol;
import de.jaret.util.ui.table.model.PropListeningTableModel;
import de.jaret.util.ui.table.renderer.BarCellRenderer;
import de.jaret.util.ui.table.renderer.DefaultCellStyle;
import de.jaret.util.ui.table.renderer.ObjectImageRenderer;
import de.jaret.util.ui.table.renderer.SmileyCellRenderer;
import de.jaret.util.ui.table.util.action.JaretTableActionFactory;
/**
* Simple example for demonstrating the use of the jaret table.
*
* @author Peter Kliem
* @version $Id: TableExample.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class TableExample {
Shell _shell;
IJaretTableModel _tableModel;
public TableExample(IJaretTableModel tableModel) {
_tableModel = tableModel;
_shell = new Shell(Display.getCurrent());
_shell.setText("jaret table example");
createControls();
_shell.open();
Display display;
display = _shell.getDisplay();
_shell.pack();
_shell.setSize(1000, 700);
/*
* do the event loop until the shell is closed to block the call
*/
while (_shell != null && !_shell.isDisposed()) {
try {
if (!display.readAndDispatch())
display.sleep();
} catch (Throwable e) {
e.printStackTrace();
}
}
display.update();
}
JaretTable _jt;
/**
* Create the controls that compose the console test.
*
*/
protected void createControls() {
GridLayout gl = new GridLayout();
gl.numColumns = 1;
_shell.setLayout(gl);
GridData gd = new GridData(GridData.FILL_BOTH);
_jt = new JaretTable(_shell, SWT.V_SCROLL | SWT.H_SCROLL);
_jt.setLayoutData(gd);
if (_tableModel == null) {
DefaultJaretTableModel model = new PropListeningTableModel();
model.addRow(new DummyRow("r1", "The quick brown fox jumps over the crazy dog.", "Mars", true, new Date(),
TableExample.getImageRegistry().get("splash")));
model.addRow(new DummyRow("r2", "Dogma i am god", "Venus", true, new Date()));
model
.addRow(new DummyRow(
"r3",
"Wenn der kleine Blindtext einmal gro� und wichtig geworden ist, wird er bedeutungsschwanger die Welt erorbern.",
"Jupiter", true, new Date(), TableExample.getImageRegistry().get("keyboard")));
model.addRow(new DummyRow("r4", "wewe we wew e we we we w ewe", "Uranus", true, new Date()));
model.addRow(new DummyRow("r5", "sdjg sd jhgd dsh hjsgfjhgdf", "Pluto", true, new Date()));
model.addRow(new DummyRow("r6", "wewe we wew e we we we w ewe", "Earth", true, new Date()));
model.addRow(new DummyRow("r7", "wewe we wew e we we we w ewe", "Mars", false, new Date()));
model.addRow(new DummyRow("r8", "wewe we wew e we we we w ewe", "Sun", false, new Date()));
model.addRow(new DummyRow("r9", "wewe we wew e we we we w ewe", "Earth", true, new Date()));
model.addRow(new DummyRow("ra", "wewe we wew e we we we w ewe", "Saturn", true, new Date()));
model.addRow(new DummyRow("rb", "wewe we wew e we we we w ewe", "Saturn", true, new Date()));
model.addRow(new DummyRow("rc", "wewe we wew e we we we w ewe", "Pluto", true, new Date()));
model.addRow(new DummyRow("rd", "wewe we wew e we we we w ewe", "Jupiter", true, new Date()));
model.addRow(new DummyRow("re", "This is the last row in the sort order of the model!", "Mars", true,
new Date()));
IColumn ct1 = new PropCol("t1", "column 1", "T1");
model.addColumn(ct1);
model.addColumn(new PropCol("d1", "Date", "D1"));
model.addColumn(new PropCol("t2", "column 2", "T2"));
model.addColumn(new PropCol("t3", "column 3", "T3"));
model.addColumn(new PropCol("b1", "column 4", "B1"));
model.addColumn(new PropCol("i1", "column 5", "Img"));
model.addColumn(new PropCol("integer", "column 6", "Integer", Integer.class));
model.addColumn(new PropCol("integer2", "Integer", "Integer", Integer.class));
model.addColumn(new PropCol("integer3", "Smiley", "Integer", Integer.class));
model.addColumn(new PropCol("Risk", "Risk", "Risk"));
model.addColumn(new PropCol("RiskProb", "RProb", "RiskProb"));
model.addColumn(new PropCol("RiskSeverity", "RSeverity", "RiskSeverity"));
model.addColumn(new PropCol("Enum", "EnumTest", "EnumProperty"));
model.addColumn(new PropCol("double", "Double", "Adouble"));
model.addColumn(new PropCol("x1", "ComboEdit", "X1"));
model.addColumn(new PropCol("Enum2", "EnumImage", "EnumProperty"));
_tableModel = model;
}
DefaultCellStyle cs = (DefaultCellStyle) _jt.getTableViewState().getCellStyleProvider().getDefaultCellStyle()
.copy();
cs.setHorizontalAlignment(ITableViewState.HAlignment.RIGHT);
_jt.getTableViewState().getCellStyleProvider().setColumnCellStyle(_tableModel.getColumn(0), cs);
_jt.getTableViewState().getCellStyleProvider().setColumnCellStyle(_tableModel.getColumn(7), cs);
_jt.getTableViewState().getCellStyleProvider().setColumnCellStyle(_tableModel.getColumn(10), cs);
_jt.registerCellRenderer(_tableModel.getColumn(2), new StyleTextCellRenderer("we", false));
_jt.registerCellRenderer(_tableModel.getColumn(6), new BarCellRenderer());
_jt.registerCellRenderer(_tableModel.getColumn(8), new SmileyCellRenderer());
// risk renderer and editor
_jt.registerCellRenderer(DummyRow.Risk.class, new RiskRenderer());
_jt.registerCellEditor(DummyRow.Risk.class, new RiskCellEditor());
// risk values 1 to 3
_jt.registerCellEditor(_tableModel.getColumn(10), new IntegerCellEditor(1, 3));
_jt.registerCellEditor(_tableModel.getColumn(11), new IntegerCellEditor(1, 3));
ObjectImageRenderer oiRenderer = new ObjectImageRenderer();
oiRenderer.addObjectRessourceNameMapping(DummyRow.TestEnum.ENUMVAL1, "1",
"/de/jaret/examples/table/warning.gif");
oiRenderer.addObjectRessourceNameMapping(DummyRow.TestEnum.ENUMVAL2, "2", "/de/jaret/examples/table/error.gif");
oiRenderer.addObjectRessourceNameMapping(DummyRow.TestEnum.ENUMVAL3, "3",
"/de/jaret/examples/table/information.gif");
_jt.registerCellRenderer(_tableModel.getColumn(15), oiRenderer);
List<Object> l = new ArrayList<Object>();
l.add("first text");
l.add("second text");
l.add("third text");
ObjectComboEditor oce = new ObjectComboEditor(l, null, true, "this is null");
_jt.registerCellEditor(((DefaultJaretTableModel) _tableModel).getColumn("x1"), oce);
_jt.setTableModel(_tableModel);
// register autofilters
_jt.registerAutoFilterForClass(Integer.class, SampleIntegerAutoFilter.class);
_jt.registerAutoFilterForColumn(_tableModel.getColumn(2), SampleTextAutoFilter.class);
JaretTableActionFactory af = new JaretTableActionFactory();
MenuManager mm = new MenuManager();
mm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_CONFIGURECOLUMNS));
_jt.setHeaderContextMenu(mm.createContextMenu(_jt));
MenuManager rm = new MenuManager();
rm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_OPTROWHEIGHT));
rm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_OPTALLROWHEIGHTS));
_jt.setRowContextMenu(rm.createContextMenu(_jt));
TableControlPanel ctrlPanel = new TableControlPanel(_shell, SWT.NULL, _jt);
}
static ImageRegistry _imageRegistry;
public static ImageRegistry getImageRegistry() {
if (_imageRegistry == null) {
_imageRegistry = new ImageRegistry();
ImageDescriptor imgDesc = new ResourceImageDescriptor("/de/jaret/examples/table/splash.bmp");
_imageRegistry.put("splash", imgDesc);
imgDesc = new ResourceImageDescriptor("/de/jaret/examples/table/keyboard.png");
_imageRegistry.put("keyboard", imgDesc);
}
return _imageRegistry;
}
public static void main(String args[]) {
TableExample te = new TableExample(null);
}
}
| 10,216 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
TableHierarchicalExample.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/examples/table/TableHierarchicalExample.java | /*
* File: TableHierarchicalExample.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.examples.table;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.DropTargetListener;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell;
import de.jaret.util.ui.ResourceImageDescriptor;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.DefaultHierarchicalTableModel;
import de.jaret.util.ui.table.model.HierarchyColumn;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IHierarchicalJaretTableModel;
import de.jaret.util.ui.table.model.IRow;
import de.jaret.util.ui.table.model.ITableNode;
import de.jaret.util.ui.table.model.PropCol;
import de.jaret.util.ui.table.model.StdHierarchicalTableModel;
import de.jaret.util.ui.table.renderer.TableHierarchyRenderer;
import de.jaret.util.ui.table.util.action.JaretTableActionFactory;
/**
* Simple example showing the hierarchical model. Shows a very simple darg and drop handling allowing to move single
* rows in the table.
*
* @author kliem
* @version $Id: TableHierarchicalExample.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class TableHierarchicalExample {
/**
* If set to true, simple node drag and drop will be enabled. This is disabledin the example by default, since it is
* far from perfect.
*/
private static final boolean SUPPORT_DND = false;
private Shell _shell;
private JaretTable _jt;
public TableHierarchicalExample(IHierarchicalJaretTableModel hierarchicalModel) {
_shell = new Shell(Display.getCurrent());
_shell.setText("jaret table hierarchical example");
createControls(hierarchicalModel);
_shell.open();
Display display;
display = _shell.getDisplay();
_shell.pack();
_shell.setSize(400, 700);
/*
* do the event loop until the shell is closed to block the call
*/
while (_shell != null && !_shell.isDisposed()) {
try {
if (!display.readAndDispatch())
display.sleep();
} catch (Throwable e) {
e.printStackTrace();
}
}
display.update();
}
/**
* Create the controls that compose the console test.
*
*/
protected void createControls(IHierarchicalJaretTableModel hierarchicalModel) {
GridLayout gl = new GridLayout();
gl.numColumns = 1;
_shell.setLayout(gl);
GridData gd = new GridData(GridData.FILL_BOTH);
_jt = new JaretTable(_shell, SWT.V_SCROLL | SWT.H_SCROLL);
_jt.setLayoutData(gd);
IHierarchicalJaretTableModel hmodel = hierarchicalModel;
if (hierarchicalModel == null) {
ITableNode root = new DummyTableNode("tn1", "tn1", "Root", "This the root node");
ITableNode r1 = new DummyTableNode("tn11", "tn12", "1", "Child 1 of the root");
ITableNode r2 = new DummyTableNode("tn12", "tn12", "2", "Child 2 of the root");
ITableNode r3 = new DummyTableNode("tn13", "tn13", "3", "Child 3 of the root");
root.addNode(r1);
root.addNode(r2);
root.addNode(r3);
r1.addNode(new DummyTableNode("tn111", "tn111", "1", "A second level child"));
r1.addNode(new DummyTableNode("tn112", "tn112", "2", "Another second level child"));
ITableNode n1 = new DummyTableNode("tn131", "tn131", "1", "A second level child");
r3.addNode(n1);
ITableNode n2 = new DummyTableNode("tn132", "tn132", "2", "Another second level child");
r3.addNode(n2);
n1.addNode(new DummyTableNode("tn1311", "tn1311", "1", "A third level child"));
n1.addNode(new DummyTableNode("tn1312", "tn1312", "2", "Another third level child"));
DefaultHierarchicalTableModel dhmodel = new DefaultHierarchicalTableModel(root);
hmodel = dhmodel;
if (SUPPORT_DND) {
// init the simple drag and drop handling
initDND(_jt, _shell);
}
}
_jt.setTableModel(hmodel);
StdHierarchicalTableModel model = (StdHierarchicalTableModel) _jt.getTableModel();
IColumn hcol = new HierarchyColumn();
// create and setup hierarchy renderer
final TableHierarchyRenderer hierarchyRenderer = new TableHierarchyRenderer();
hierarchyRenderer.setLabelProvider(new LabelProvider());
hierarchyRenderer.setDrawIcons(true);
hierarchyRenderer.setDrawLabels(true);
_jt.registerCellRenderer(hcol, hierarchyRenderer);
model.addColumn(hcol);
model.addColumn(new PropCol("b1", "column 1", "B1"));
model.addColumn(new PropCol("t1", "column 2", "T1"));
model.addColumn(new PropCol("t2", "column 3", "T2"));
model.addColumn(new PropCol("t3", "column 4", "T3"));
JaretTableActionFactory af = new JaretTableActionFactory();
MenuManager mm = new MenuManager();
mm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_CONFIGURECOLUMNS));
_jt.setHeaderContextMenu(mm.createContextMenu(_jt));
MenuManager rm = new MenuManager();
rm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_OPTROWHEIGHT));
rm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_OPTALLROWHEIGHTS));
_jt.setRowContextMenu(rm.createContextMenu(_jt));
TableControlPanel ctrlPanel = new TableControlPanel(_shell, SWT.NULL, _jt);
Label l = new Label(_shell, SWT.NONE);
l.setText("Level width:");
final Scale levelWidthScale = new Scale(_shell, SWT.HORIZONTAL);
levelWidthScale.setMaximum(40);
levelWidthScale.setMinimum(0);
levelWidthScale.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent ev) {
int val = levelWidthScale.getSelection();
hierarchyRenderer.setLevelWidth(val);
_jt.redraw();
}
});
}
public static void main(String args[]) {
TableHierarchicalExample te = new TableHierarchicalExample(null);
}
public class LabelProvider implements ILabelProvider {
public Image getImage(Object element) {
DummyTableNode node = (DummyTableNode) element;
return node.getB1() ? getImageRegistry().get("true") : getImageRegistry().get("false");
}
public String getText(Object element) {
DummyTableNode node = (DummyTableNode) element;
return node.getId();
}
public void addListener(ILabelProviderListener listener) {
}
public void dispose() {
if (_imageRegistry != null) {
_imageRegistry.dispose();
}
}
public boolean isLabelProperty(Object element, String property) {
return false;
}
public void removeListener(ILabelProviderListener listener) {
}
ImageRegistry _imageRegistry;
public ImageRegistry getImageRegistry() {
if (_imageRegistry == null) {
_imageRegistry = new ImageRegistry();
ImageDescriptor imgDesc = new ResourceImageDescriptor("/de/jaret/examples/table/true.gif");
_imageRegistry.put("true", imgDesc);
imgDesc = new ResourceImageDescriptor("/de/jaret/examples/table/false.gif");
_imageRegistry.put("false", imgDesc);
}
return _imageRegistry;
}
}
IRow _draggedRow;
ITableNode _parentTableNode;
/**
* Init a simple drag and drop operation for moving rows in the table.
*
* @param table
* @param parent
*/
private void initDND(final JaretTable table, Composite parent) {
// support move only
int operations = DND.DROP_MOVE;
final DragSource source = new DragSource(table, operations);
// Provide data in Text format
Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
source.setTransfer(types);
source.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
// check whether drag occured on the hierarchy column
IColumn column = table.colForX(event.x);
if (column != null && table.isHierarchyColumn(column)) { // TODO check whether a resize may have
// higher priority
// possible row drag
IRow row = table.rowForY(event.y);
if (row != null) {
// row hit, start row drag
_draggedRow = row;
// capture the data for internal use
// row drag: use row at starting position
_parentTableNode = getParent(table.getHierarchicalModel().getRootNode(), (ITableNode) row);
} else {
event.doit = false;
}
}
}
public void dragSetData(DragSourceEvent event) {
// Provide the data of the requested type.
if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
if (_draggedRow != null) {
event.data = "row: " + _draggedRow.getId();
}
}
}
public void dragFinished(DragSourceEvent event) {
// for this simple case we do all the manipulations in the drop
// target
// this is more of a hack ...
_draggedRow = null;
}
});
// ////////////////////
// Drop target
// moved to the drop target
operations = DND.DROP_MOVE;
final DropTarget target = new DropTarget(table, operations);
// Receive data in Text
final TextTransfer textTransfer = TextTransfer.getInstance();
types = new Transfer[] {textTransfer};
target.setTransfer(types);
target.addDropListener(new DropTargetListener() {
public void dragEnter(DropTargetEvent event) {
}
public void dragOver(DropTargetEvent event) {
// event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
if (_draggedRow != null) {
// no drag over effect right now
}
}
public void dragOperationChanged(DropTargetEvent event) {
}
public void dragLeave(DropTargetEvent event) {
}
public void dropAccept(DropTargetEvent event) {
}
public void drop(DropTargetEvent event) {
// this simple drop implementation takes care of the complete
// operation
// this is kind of a hack ...
if (textTransfer.isSupportedType(event.currentDataType)) {
String text = (String) event.data;
System.out.println("DROP: " + text);
if (_draggedRow != null) {
int destY = Display.getCurrent().map(null, table, event.x, event.y).y;
int destX = Display.getCurrent().map(null, table, event.x, event.y).x;
IRow overRow = table.rowForY(destY);
if (overRow != null) {
System.out.println("over row " + overRow.getId());
// this is an action from the drag source listener
// ...
// this has to be done right here because otherwise
// the node would be at two places
// at the same time causing some redraw trouble ...
_parentTableNode.remNode((ITableNode) _draggedRow);
ITableNode node = (ITableNode) overRow;
node.addNode((ITableNode) _draggedRow);
}
}
}
}
});
// Dispose listener on parent of timebar viewer to dispose the
// dragsource and dragtarget BEFORE the timebar
// viewer
// this prevents an exception beeing thrown by SWT
parent.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
source.dispose();
target.dispose();
}
});
}
private ITableNode getParent(ITableNode root, ITableNode draggedRow) {
if (root.getChildren().contains(draggedRow)) {
return root;
} else {
for (ITableNode node : root.getChildren()) {
ITableNode result = getParent(node, draggedRow);
if (result != null) {
return result;
}
}
}
return null;
}
}
| 14,923 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
RiskCellEditor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/examples/table/renderer/RiskCellEditor.java | /*
* File: RiskCellEditor.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.examples.table.renderer;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
import de.jaret.examples.table.DummyRow;
import de.jaret.examples.table.DummyRow.Risk;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.editor.CellEditorBase;
import de.jaret.util.ui.table.editor.ICellEditor;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* CellEditor for a risk. Does only process clicks and key strokes. Keybindings are
* <ul>
* <li>'p': roll risk probability</li>
* <li>'s': roll risk severity</li>
* </ul>
*
* @author Peter Kliem
* @version $Id: RiskCellEditor.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class RiskCellEditor extends CellEditorBase implements ICellEditor {
protected boolean _singleClick = false;
public RiskCellEditor() {
}
public RiskCellEditor(boolean singleClick) {
_singleClick = singleClick;
}
public Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey) {
if (typedKey == 'p' || typedKey == 'P') {
rollProb(row, column);
} else if (typedKey == 's' || typedKey == 'S') {
rollSeverity(row, column);
}
return null;
}
/**
* {@inheritDoc}
*/
public void stopEditing(boolean storeInput) {
// nothing to do
}
public boolean handleClick(JaretTable table, IRow row, IColumn column, Rectangle drawingArea, int x, int y) {
boolean change = checkClick(table, row, column, drawingArea, x, y);
return change;
}
boolean _forceSquare = true;
private boolean checkClick(JaretTable table, IRow row, IColumn column, Rectangle rect, int x, int y) {
if (_forceSquare) {
int a = Math.min(rect.width, rect.height);
Rectangle nrect = new Rectangle(0, 0, a, a);
nrect.x = rect.x + (rect.width - a) / 2;
nrect.y = rect.y + (rect.height - a) / 2;
rect = nrect;
}
if (!rect.contains(x, y)) {
return false;
}
int width = rect.width;
int height = rect.height;
int sWidth = (width - RiskRenderer.AXISOFFSET) / 3;
int sHeight = (height - RiskRenderer.AXISOFFSET) / 3;
int xx = x - rect.x;
int yy = y - rect.y;
int prob = xx / sWidth;
int sev = yy / sHeight;
if (prob >= 0 && sev >= 0) {
sev = 2 - sev;
Risk risk = ((DummyRow) row).new Risk(prob + 1, sev + 1);
column.setValue(row, risk);
return true;
}
return false;
}
private void rollProb(IRow row, IColumn column) {
DummyRow.Risk risk = (Risk) column.getValue(row);
int newProb = risk.getRiskProb() + 1;
newProb = newProb > 3 ? 1 : newProb;
column.setValue(row, ((DummyRow) row).new Risk(newProb, risk.getRiskSeverity()));
}
private void rollSeverity(IRow row, IColumn column) {
DummyRow.Risk risk = (Risk) column.getValue(row);
int newSev = risk.getRiskSeverity() + 1;
newSev = newSev > 3 ? 1 : newSev;
column.setValue(row, ((DummyRow) row).new Risk(risk.getRiskProb(), newSev));
}
/**
* {@inheritDoc}
*/
public void dispose() {
super.dispose();
}
}
| 3,922 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
RiskRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/examples/table/renderer/RiskRenderer.java | /*
* File: RiskRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.examples.table.renderer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.widgets.Display;
import de.jaret.examples.table.DummyRow;
import de.jaret.examples.table.DummyRow.Risk;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
import de.jaret.util.ui.table.renderer.CellRendererBase;
import de.jaret.util.ui.table.renderer.ICellRenderer;
import de.jaret.util.ui.table.renderer.ICellStyle;
/**
* Fun renderer rendering a risk as a grid.
*
* @TODO Printing
*
* @author Peter Kliem
* @version $Id: RiskRenderer.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class RiskRenderer extends CellRendererBase implements ICellRenderer {
/** offset fo rthe axis rendering. */
public static final int AXISOFFSET = 0;
private boolean _forceSquare = true;
private Color _red;
private Color _redInactive;
private Color _green;
private Color _greenInactive;
private Color _yellow;
private Color _yellowInactive;
private Color _black;
// private static final RGB INACTIVE_GREEN = new RGB(201, 255, 205);
// private static final RGB INACTIVE_YELLOW = new RGB(255, 255, 200);
// private static final RGB INACTIVE_RED = new RGB(255, 201, 205);
private static final RGB INACTIVE_GREEN = new RGB(220, 255, 220);
private static final RGB INACTIVE_YELLOW = new RGB(255, 255, 220);
private static final RGB INACTIVE_RED = new RGB(255, 220, 220);
private Color[][] _inactiveColors;
private Color[][] _colors;
public RiskRenderer(Printer printer) {
super(printer);
if (printer != null) {
_yellow = printer.getSystemColor(SWT.COLOR_YELLOW);
_green = printer.getSystemColor(SWT.COLOR_GREEN);
_red = printer.getSystemColor(SWT.COLOR_RED);
_black = printer.getSystemColor(SWT.COLOR_BLACK);
_redInactive = new Color(printer, INACTIVE_RED);
_yellowInactive = new Color(printer, INACTIVE_YELLOW);
_greenInactive = new Color(printer, INACTIVE_GREEN);
}
Color[][] inactiveColors = { { _yellowInactive, _redInactive, _redInactive },
{ _greenInactive, _yellowInactive, _redInactive }, { _greenInactive, _greenInactive, _yellowInactive } };
_inactiveColors = inactiveColors;
Color[][] colors = { { _yellow, _red, _red }, { _green, _yellow, _red }, { _green, _green, _yellow } };
_colors = colors;
}
public RiskRenderer() {
super(null);
_yellow = Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW);
_green = Display.getCurrent().getSystemColor(SWT.COLOR_GREEN);
_red = Display.getCurrent().getSystemColor(SWT.COLOR_RED);
_black = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
_redInactive = new Color(Display.getCurrent(), INACTIVE_RED);
_yellowInactive = new Color(Display.getCurrent(), INACTIVE_YELLOW);
_greenInactive = new Color(Display.getCurrent(), INACTIVE_GREEN);
_black = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
Color[][] inactiveColors = { { _yellowInactive, _redInactive, _redInactive },
{ _greenInactive, _yellowInactive, _redInactive }, { _greenInactive, _greenInactive, _yellowInactive } };
_inactiveColors = inactiveColors;
Color[][] colors = { { _yellow, _red, _red }, { _green, _yellow, _red }, { _green, _green, _yellow } };
_colors = colors;
}
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
IColumn column, boolean drawFocus, boolean selected, boolean printing) {
drawBackground(gc, drawingArea, cellStyle, selected, printing);
Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
Rectangle rect = applyInsets(drect);
DummyRow.Risk risk = (Risk) column.getValue(row);
if (_forceSquare) {
int a = Math.min(rect.width, rect.height);
Rectangle nrect = new Rectangle(0, 0, a, a);
nrect.x = rect.x + (rect.width - a) / 2;
nrect.y = rect.y + (rect.height - a) / 2;
rect = nrect;
}
Color bg = gc.getBackground();
int width = rect.width;
int height = rect.height;
int sWidth = (width - AXISOFFSET) / 3;
int sHeight = (height - AXISOFFSET) / 3;
// x = prob
// y = severity
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
Color c = getColor(risk, x, y);
gc.setBackground(c);
int oX = AXISOFFSET + x * sWidth + rect.x;
int oY = rect.y + height - AXISOFFSET - (y + 1) * sHeight;
gc.fillRectangle(oX, oY, sWidth, sHeight);
gc.drawRectangle(oX, oY, sWidth, sHeight);
if (risk != null && risk.getRiskProb() - 1 == x && risk.getRiskSeverity() - 1 == y) {
gc.drawLine(oX, oY, oX + sWidth, oY + sHeight);
gc.drawLine(oX, oY + sHeight, oX + sWidth, oY);
}
}
}
// // axises
// // x
// gc.drawLine(rect.x + AXISOFFSET, rect.y + height - AXISOFFSET, rect.x + 3 * sWidth + AXISOFFSET, rect.y +
// height - AXISOFFSET);
// // y
// gc.drawLine(rect.x + AXISOFFSET, rect.y + height - AXISOFFSET, rect.x + AXISOFFSET, rect.y + height -
// AXISOFFSET - 3 * sHeight);
gc.setBackground(bg);
if (drawFocus) {
drawFocus(gc, drect);
}
drawSelection(gc, drawingArea, cellStyle, selected, printing);
}
private Color getColor(Risk risk, int prob, int sev) {
if (risk != null && risk.getRiskProb() - 1 == prob && risk.getRiskSeverity() - 1 == sev) {
return _colors[2 - prob][sev];
} else {
return _inactiveColors[2 - prob][sev];
}
}
public void dispose() {
if (_yellowInactive != null) {
_yellowInactive.dispose();
}
if (_redInactive != null) {
_redInactive.dispose();
}
if (_greenInactive != null) {
_greenInactive.dispose();
}
}
public ICellRenderer createPrintRenderer(Printer printer) {
return new RiskRenderer(printer);
}
} | 7,214 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
MultiLineListExample.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/examples/table/mllist/MultiLineListExample.java | /*
* File: MultiLineListExample.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.examples.table.mllist;
import java.util.Date;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import de.jaret.examples.table.DummyRow;
import de.jaret.util.ui.ResourceImageDescriptor;
import de.jaret.util.ui.console.ConsoleControl;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.DefaultJaretTableModel;
import de.jaret.util.ui.table.model.IJaretTableModel;
import de.jaret.util.ui.table.model.ITableViewState;
import de.jaret.util.ui.table.model.PropCol;
import de.jaret.util.ui.table.model.PropListeningTableModel;
import de.jaret.util.ui.table.renderer.DefaultBorderConfiguration;
import de.jaret.util.ui.table.renderer.DefaultCellStyle;
/**
* Simple exmaple for demonstrating the use of the jaret table.
*
* @author Peter Kliem
* @version $Id: MultiLineListExample.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class MultiLineListExample {
Shell _shell;
ConsoleControl _consoleControl;
IJaretTableModel _tableModel;
public MultiLineListExample(IJaretTableModel tableModel) {
_tableModel = tableModel;
_shell = new Shell(Display.getCurrent());
_shell.setText("jaret table multilinelist");
createControls();
_shell.open();
Display display;
display = _shell.getDisplay();
_shell.pack();
_shell.setSize(280, 400);
/*
* do the event loop until the shell is closed to block the call
*/
while (_shell != null && !_shell.isDisposed()) {
try {
if (!display.readAndDispatch())
display.sleep();
} catch (Throwable e) {
e.printStackTrace();
}
}
display.update();
}
JaretTable _jt;
/**
* Create the controls that compose the console test.
*
*/
protected void createControls() {
GridLayout gl = new GridLayout();
gl.numColumns = 1;
_shell.setLayout(gl);
GridData gd = new GridData(GridData.FILL_BOTH);
_jt = new JaretTable(_shell, SWT.V_SCROLL);
_jt.setLayoutData(gd);
if (_tableModel == null) {
DefaultJaretTableModel model = new PropListeningTableModel();
model.addRow(new DummyRow("r1", "line 1", "line 2 adds more text", true, new Date(), MultiLineListExample
.getImageRegistry().get("icon")));
model.addRow(new DummyRow("r2", "another first line", "line 2 adds more text", true, new Date(),
MultiLineListExample.getImageRegistry().get("icon")));
model.addRow(new DummyRow("r3", "and yet another one", "line 2 adds more text", true, new Date(),
MultiLineListExample.getImageRegistry().get("icon")));
model.addRow(new DummyRow("r5", "4444444444", "line 2 adds more text", true, new Date(),
MultiLineListExample.getImageRegistry().get("icon")));
model.addRow(new DummyRow("r6", "555555555", "line 2 adds more text", true, new Date(),
MultiLineListExample.getImageRegistry().get("icon")));
model.addRow(new DummyRow("r7", "6666666666", "line 2 adds more text", true, new Date(),
MultiLineListExample.getImageRegistry().get("icon")));
model.addRow(new DummyRow("r8", "7777777777", "line 2 adds more text", true, new Date(),
MultiLineListExample.getImageRegistry().get("icon")));
model.addRow(new DummyRow("r9", "88888888888", "line 2 adds more text", true, new Date(),
MultiLineListExample.getImageRegistry().get("icon")));
PropCol ct1 = new PropCol("t1", "column 1", "T1");
ct1.setEditable(false);
model.addColumn(ct1);
_tableModel = model;
}
DefaultCellStyle cs = (DefaultCellStyle) _jt.getTableViewState().getCellStyleProvider().getDefaultCellStyle()
.copy();
cs.setBorderConfiguration(new DefaultBorderConfiguration(0, 0, 0, 0));
_jt.getTableViewState().getCellStyleProvider().setColumnCellStyle(_tableModel.getColumn(0), cs);
_jt.getTableViewState().setRowHeightMode(ITableViewState.RowHeightMode.FIXED);
// has to be replaced
for (int i = 0; i < _tableModel.getRowCount(); i++) {
_jt.getTableViewState().setRowHeight(_tableModel.getRow(i), 60);
}
// _jt.getTableViewState().setColumnResizeMode(ITableViewState.ColumnResizeMode.ALL);
_jt.setHeaderHeight(0);
_jt.registerCellRenderer(_tableModel.getColumn(0), new MultilineListCellRenderer());
_jt.setTableModel(_tableModel);
_jt.getTableViewState().setColumnWidth(_tableModel.getColumn(0), 230);
}
static ImageRegistry _imageRegistry;
public static ImageRegistry getImageRegistry() {
if (_imageRegistry == null) {
_imageRegistry = new ImageRegistry();
ImageDescriptor imgDesc = new ResourceImageDescriptor("/de/jaret/examples/table/mllist/icon.gif");
_imageRegistry.put("icon", imgDesc);
imgDesc = new ResourceImageDescriptor("/de/jaret/examples/table/keyboard.png");
_imageRegistry.put("keyboard", imgDesc);
}
return _imageRegistry;
}
public static void main(String args[]) {
MultiLineListExample te = new MultiLineListExample(null);
}
}
| 6,256 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
MultilineListCellRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/examples/table/mllist/MultilineListCellRenderer.java | /*
* File: MultilineListCellRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.examples.table.mllist;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.widgets.Display;
import de.jaret.examples.table.DummyRow;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
import de.jaret.util.ui.table.renderer.CellRendererBase;
import de.jaret.util.ui.table.renderer.ICellRenderer;
import de.jaret.util.ui.table.renderer.ICellStyle;
public class MultilineListCellRenderer extends CellRendererBase implements ICellRenderer {
Font boldFont;
Font normalFont;
public MultilineListCellRenderer(Printer printer) {
super(printer);
}
public MultilineListCellRenderer() {
super(null);
boldFont = new Font(Display.getCurrent(), "Arial", 10, SWT.BOLD);
normalFont = new Font(Display.getCurrent(), "Arial", 10, SWT.NORMAL);
}
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
IColumn column, boolean drawFocus, boolean selected, boolean printing) {
drawBackground(gc, drawingArea, cellStyle, selected, printing);
Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
Rectangle rect = applyInsets(drect);
DummyRow dr = (DummyRow) row;
Image img = dr.getImg();
int x = rect.x + 4;
int y = rect.y + (rect.height - img.getBounds().height) / 2;
gc.drawImage(img, x, y);
Font save = gc.getFont();
gc.setFont(boldFont);
gc.drawString(dr.getT2(), rect.x + 70, y + 5);
gc.setFont(normalFont);
gc.drawString(dr.getT3(), rect.x + 70, y + 25);
gc.setFont(save);
if (drawFocus) {
drawFocus(gc, drawingArea);
}
drawSelection(gc, drawingArea, cellStyle, selected, printing);
}
public ICellRenderer createPrintRenderer(Printer printer) {
// TODO Auto-generated method stub
return null;
}
public void dispose() {
boldFont.dispose();
normalFont.dispose();
}
}
| 2,791 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
JaretTablePrinter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/JaretTablePrinter.java | /*
* File: JaretTablePrinter.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.printing.Printer;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
import de.jaret.util.ui.table.print.JaretTablePrintConfiguration;
import de.jaret.util.ui.table.renderer.ICellRenderer;
import de.jaret.util.ui.table.renderer.ICellStyle;
import de.jaret.util.ui.table.renderer.ITableHeaderRenderer;
/**
* <p>
* Print utility for the jaret table. The table printer depends on implemented print functionality in the configured
* renderers. It "connects" directly to the jaret table thus no headless printing is possible.
* </p>
* <p>
* The Table printer should be disposed after using!
* </p>
* TODO this is a first hack.
*
* @author Peter Kliem
* @version $Id: JaretTablePrinter.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class JaretTablePrinter {
/** borders in cm. */
protected double _borderTop = 1;
protected double _borderBottom = 1;
protected double _borderLeft = 1;
protected double _borderRight = 1;
protected Rectangle _printingRect;
protected Printer _printer;
protected double _scaleX;
protected double _scaleY;
protected ITableHeaderRenderer _headerRenderer;
protected JaretTable _table;
protected int _pageHeight;
protected int _pageWidth;
protected int _footerHeight;
protected double _scale = 1.0;
public JaretTablePrinter(Printer printer, JaretTable table) {
_table = table;
setPrinter(printer);
}
public void setPrinter(Printer printer) {
if (_printer != null) {
_printer.dispose();
}
_printer = printer;
if (printer != null) {
Point dpi = _printer.getDPI();
_scaleX = (double) dpi.x / 96.0;
_scaleY = (double) dpi.y / 96.0;
}
}
public int scaleX(int in) {
return (int) Math.round(_scaleX * (double) in * _scale);
}
public double getScaleX() {
return _scaleX;
}
public int scaleY(int in) {
return (int) Math.round(_scaleY * (double) in * _scale);
}
public Printer getPrinter() {
return _printer;
}
protected int pixelForCmX(double cm) {
Point dpi = _printer.getDPI();
double inch = cm / 2.54;
return (int) (dpi.x * inch);
}
protected int pixelForCmY(double cm) {
Point dpi = _printer.getDPI();
double inch = cm / 2.54;
return (int) (dpi.y * inch);
}
/**
* Calculate the number of pages generated when printing.
*
* @param configuration
* @return
*/
public Point calculatePageCount(JaretTablePrintConfiguration configuration) {
_scale = configuration.getScale();
_pageHeight = _printer.getClientArea().height - pixelForCmY(_borderTop + _borderBottom);
_pageWidth = _printer.getClientArea().width - pixelForCmX(_borderLeft + _borderRight);
int tHeight;
if (configuration.getRowLimit() == -1) {
tHeight = _table.getTotalHeight();
} else {
tHeight = _table.getTotalHeight(configuration.getRowLimit());
}
int tWidth;
if (configuration.getColLimit() == -1) {
tWidth = _table.getTotalWidth();
} else {
tWidth = _table.getTotalWidth(configuration.getColLimit());
}
int pagesx = (scaleX(tWidth) / _pageWidth) + 1;
int pagesy = (scaleY(tHeight) / (_pageHeight - _footerHeight)) + 1;
int headerheight = _table.getDrawHeader() ? _table.getHeaderHeight() : 0;
headerheight = configuration.getRepeatHeader() ? headerheight + headerheight * (pagesy - 1) : headerheight;
// corrected pagesy
pagesy = (scaleY(tHeight + headerheight) / (_pageHeight - _footerHeight)) + 1;
return new Point(pagesx, pagesy);
}
public void print(JaretTablePrintConfiguration configuration) {
_printingRect = new Rectangle(pixelForCmX(_borderLeft), pixelForCmY(_borderTop), _pageWidth, _pageHeight);
_headerRenderer = _table.getHeaderRenderer().getPrintRenderer(_printer);
Point pages = calculatePageCount(configuration);
int pagesx = pages.x;
int pagesy = pages.y;
_printer.startJob(configuration.getName() != null ? configuration.getName() : "jarettable");
GC gc = new GC(_printer);
Font oldfont = gc.getFont();
FontData fontdata = new FontData("Arial", (int) (8.0 * _scale), SWT.NULL);
Font printerFont = new Font(_printer, fontdata);
gc.setFont(printerFont);
for (int px = 0; px < pagesx; px++) {
int startx = (int) ((px * _pageWidth) / (_scaleX * _scale));
IColumn column = _table.getColumnForAbsX(startx);
int offx = startx - _table.getAbsBeginXForColumn(column);
int beginColIdx = _table.getColIdxForAbsX(startx);
// System.out.println("PX "+px+" startx "+startx+" offx "+offx+" beginColIdx "+beginColIdx);
int rIdx = 0;
for (int py = 0; py < pagesy; py++) {
int y = 0;
String footerText = configuration.getFooterText() != null ? configuration.getFooterText() : "";
footerText += "(" + (px + 1) + "/" + pagesx + "," + (py + 1) + "/" + pagesy + ")";
_printer.startPage();
int starty = (int) (py * ((_pageHeight - _footerHeight - (configuration.getRepeatHeader() ? scaleY(_table
.getHeaderHeight())
: 0)) / (_scaleY * _scale)));
rIdx = py == 0 ? 0 : rIdx;// _table.getRowIdxForAbsY(starty);
Rectangle clipSave = gc.getClipping();
if (starty == 0 || configuration.getRepeatHeader()) {
// draw header
// draw headers table area
int x = -offx;
int cIdx = beginColIdx;
while (scaleX(x) < _pageWidth && cIdx < _table.getColumnCount()
&& (configuration.getColLimit() == -1 || cIdx <= configuration.getColLimit())) {
IColumn col = _table.getColumn(cIdx);
int colwidth = _table.getTableViewState().getColumnWidth(col);
int xx = x > 0 ? x : 0;
int clipWidth = x > 0 ? colwidth : colwidth - offx;
if (!_headerRenderer.disableClipping()) {
gc.setClipping(scaleX(xx) + pixelForCmX(_borderLeft), pixelForCmY(_borderTop),
scaleX(clipWidth), scaleY(_table.getHeaderHeight()));
gc.setClipping(gc.getClipping().intersection(_printingRect));
}
drawHeader(gc, scaleX(x) + pixelForCmX(_borderLeft), scaleX(colwidth), col);
x += colwidth;
cIdx++;
}
y += _table.getHeaderHeight();
gc.setClipping(clipSave);
}
// normal table area
gc.setClipping(_printingRect);
while (scaleY(y) < _pageHeight && rIdx < _table.getRowCount()
&& (configuration.getRowLimit() == -1 || rIdx <= configuration.getRowLimit())) {
IRow row = _table.getRow(rIdx);
int rHeight = _table.getTableViewState().getRowHeight(row);
// do not draw a row that does not fit on th page
if (scaleY(y) + scaleY(rHeight) > _pageHeight) {
break;
}
int x = -offx;
int cIdx = beginColIdx;
while (scaleX(x) < _pageWidth && cIdx < _table.getColumnCount()
&& (configuration.getColLimit() == -1 || cIdx <= configuration.getColLimit())) {
IColumn col = _table.getColumn(cIdx);
int colwidth = _table.getTableViewState().getColumnWidth(col);
Rectangle area = new Rectangle(scaleX(x) + pixelForCmX(_borderLeft), scaleY(y)
+ pixelForCmY(_borderTop), scaleX(colwidth), scaleY(rHeight));
drawCell(gc, area, row, col);
x += colwidth;
cIdx++;
}
y += rHeight;
rIdx++;
}
gc.setClipping(clipSave);
drawFooter(gc, footerText);
_printer.endPage();
}
}
_printer.endJob();
printerFont.dispose();
gc.setFont(oldfont);
gc.dispose();
}
/**
* TODO creation and disposal of the cell renderers for printing is ... well should be changed!
*
* @param gc
* @param area
* @param row
* @param col
*/
private void drawCell(GC gc, Rectangle area, IRow row, IColumn col) {
ICellStyle bc = _table.getTableViewState().getCellStyle(row, col);
ICellRenderer cellRenderer = _table.getCellRenderer(row, col).createPrintRenderer(_printer);
if (cellRenderer != null) {
cellRenderer.draw(gc, _table, bc, area, row, col, false, false, true);
}
cellRenderer.dispose();
}
private void drawFooter(GC gc, String footer) {
Point extent = gc.textExtent(footer);
int y = _printer.getClientArea().height - _footerHeight - pixelForCmY(_borderBottom);
// gc.drawLine(0,y,_pageWidth, y);
// gc.drawLine(0,y+extent.y,_pageWidth, y+extent.y);
gc.drawString(footer, pixelForCmX(_borderLeft), y);
}
private void drawHeader(GC gc, int x, int colwidth, IColumn col) {
Rectangle area = new Rectangle(x, pixelForCmY(_borderTop), colwidth, scaleY(_table.getHeaderHeight()));
int sortingPos = _table.getTableViewState().getColumnSortingPosition(col);
boolean sortingDir = _table.getTableViewState().getColumnSortingDirection(col);
_headerRenderer.draw(gc, area, col, sortingPos, sortingDir, true);
}
public void dispose() {
if (_headerRenderer != null) {
_headerRenderer.dispose();
}
}
}
| 11,312 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
JaretTableViewer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/JaretTableViewer.java | /*
* File: JaretTableViewer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table;
import java.util.List;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Widget;
/**
* JFace Structured viewer for the jaret table (minimal implementation).
*
* @author Peter Kliem
* @version $Id: JaretTableViewer.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class JaretTableViewer extends StructuredViewer {
protected JaretTable _table;
public JaretTableViewer(JaretTable table) {
_table = table;
}
@Override
protected Widget doFindInputItem(Object element) {
// TODO Auto-generated method stub
return null;
}
@Override
protected Widget doFindItem(Object element) {
// TODO Auto-generated method stub
return null;
}
@Override
protected void doUpdateItem(Widget item, Object element, boolean fullMap) {
// TODO Auto-generated method stub
}
@Override
protected List getSelectionFromWidget() {
// TODO Auto-generated method stub
return null;
}
@Override
protected void internalRefresh(Object element) {
// TODO Auto-generated method stub
}
@Override
public void reveal(Object element) {
// TODO Auto-generated method stub
}
@Override
protected void setSelectionToWidget(List l, boolean reveal) {
// TODO Auto-generated method stub
}
@Override
public Control getControl() {
// TODO Auto-generated method stub
return null;
}
}
| 2,066 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
JaretTable.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/JaretTable.java | /*
* File: JaretTable.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
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.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.MouseTrackListener;
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.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.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Shell;
import de.jaret.util.date.JaretDate;
import de.jaret.util.misc.PropertyObservable;
import de.jaret.util.misc.PropertyObservableBase;
import de.jaret.util.ui.table.editor.BooleanCellEditor;
import de.jaret.util.ui.table.editor.DateCellEditor;
import de.jaret.util.ui.table.editor.DoubleCellEditor;
import de.jaret.util.ui.table.editor.EnumComboEditor;
import de.jaret.util.ui.table.editor.ICellEditor;
import de.jaret.util.ui.table.editor.IntegerCellEditor;
import de.jaret.util.ui.table.editor.TextCellEditor;
import de.jaret.util.ui.table.filter.DefaultAutoFilter;
import de.jaret.util.ui.table.filter.IAutoFilter;
import de.jaret.util.ui.table.filter.IRowFilter;
import de.jaret.util.ui.table.model.DefaultHierarchicalTableViewState;
import de.jaret.util.ui.table.model.DefaultTableViewState;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IHierarchicalJaretTableModel;
import de.jaret.util.ui.table.model.IHierarchicalTableViewState;
import de.jaret.util.ui.table.model.IJaretTableCell;
import de.jaret.util.ui.table.model.IJaretTableModel;
import de.jaret.util.ui.table.model.IJaretTableModelListener;
import de.jaret.util.ui.table.model.IJaretTableSelection;
import de.jaret.util.ui.table.model.IJaretTableSelectionModel;
import de.jaret.util.ui.table.model.IJaretTableSelectionModelListener;
import de.jaret.util.ui.table.model.IRow;
import de.jaret.util.ui.table.model.IRowSorter;
import de.jaret.util.ui.table.model.ITableFocusListener;
import de.jaret.util.ui.table.model.ITableNode;
import de.jaret.util.ui.table.model.ITableViewState;
import de.jaret.util.ui.table.model.ITableViewStateListener;
import de.jaret.util.ui.table.model.JaretTableCellImpl;
import de.jaret.util.ui.table.model.JaretTableSelectionModelImpl;
import de.jaret.util.ui.table.model.StdHierarchicalTableModel;
import de.jaret.util.ui.table.model.ITableViewState.RowHeightMode;
import de.jaret.util.ui.table.renderer.BooleanCellRenderer;
import de.jaret.util.ui.table.renderer.DateCellRenderer;
import de.jaret.util.ui.table.renderer.DefaultTableHeaderRenderer;
import de.jaret.util.ui.table.renderer.DoubleCellRenderer;
import de.jaret.util.ui.table.renderer.ICellRenderer;
import de.jaret.util.ui.table.renderer.ICellStyle;
import de.jaret.util.ui.table.renderer.IHierarchyRenderer;
import de.jaret.util.ui.table.renderer.ITableHeaderRenderer;
import de.jaret.util.ui.table.renderer.ImageCellRenderer;
import de.jaret.util.ui.table.renderer.TableHierarchyRenderer;
import de.jaret.util.ui.table.renderer.TextCellRenderer;
import de.jaret.util.ui.table.strategies.DefaultCCPStrategy;
import de.jaret.util.ui.table.strategies.DefaultFillDragStrategy;
import de.jaret.util.ui.table.strategies.ICCPStrategy;
import de.jaret.util.ui.table.strategies.IFillDragStrategy;
/**
* Custom drawn table widget for the SWT Toolkit. Always consider using the native table widget!
* <p>
* The JaretTable features:
* </p>
* <ul>
* <li>Flexible rendering of all elements</li>
* <li>CellEditor support</li>
* <li>Flat (table) and hierarchical (tree) support</li>
* <li>Separation between data model and viewstate</li>
* <li>row filtering and sorting without model modification</li>
* <li>simple auto filter</li>
* <li>drag fill support </li>
* <li></li>
* <li></li>
* </ul>
*
* Keyboard controls <table>
* <tr>
* <td><b>Key</b></td>
* <td><b>Function</b></td>
* </tr>
* <tr>
* <td>Shift+Click</td>
* <td>Move focus</td>
* </tr>
* <tr>
* <td>Arrows</td>
* <td>Move focus</td>
* </tr>
* <tr>
* <td>Shift-Arrow</td>
* <td>Select Current cell, shift focus and select newly focussed cell and the rectangle of cells between first and
* current cell</td>
* </tr>
* </table>
*
* @author Peter Kliem
* @version $Id: JaretTable.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class JaretTable extends Canvas implements ITableViewStateListener, IJaretTableModelListener,
IJaretTableSelectionModelListener, PropertyChangeListener, PropertyObservable {
/** true for measuring paint time. */
private static final boolean DEBUGPAINTTIME = false;
/** pixel for row resize/selection if no fixed rows are present. */
private static final int SELDELTA = 4;
/** size of the marker for fill dragging. */
private static final int FILLDRAGMARKSIZE = 4;
/** default height for the header. */
private static final int DEFAULTHEADERHEIGHT = 16;
/** default value for the minimal header height. */
private static final int DEFAULTMINHEADERHEIGHT = 10;
/** button that is the poputrigger. */
private static final int POPUPTRIGGER = 3;
/** name of the bound property. */
public static final String PROPERTYNAME_HEADERHEIGHT = "HeaderHeight";
/** name of the bound property. */
public static final String PROPERTYNAME_FIRSTROWIDX = "FirstRowIdx";
/** name of the bound property. */
public static final String PROPERTYNAME_FIRSTROWPIXELOFFSET = "FirstRowPixelOffset";
/** name of the bound property. */
public static final String PROPERTYNAME_ROWSORTER = "RowSorter";
/** name of the bound property. */
public static final String PROPERTYNAME_ROWFILTER = "RowFilter";
/** Pseudo propertyname on which property change is fired whenever the sorting changes. */
public static final String PROPERTYNAME_SORTING = "Sorting";
/** Pseudo propertyname on which property change is fired whenever the filtering changes. */
public static final String PROPERTYNAME_FILTERING = "Filtering";
/** name of the bound property. */
public static final String PROPERTYNAME_AUTOFILTERENABLE = "AutoFilterEnable";
// scroll positions of the main table area
/** Index of the first row displayed (may be only a half display). */
protected int _firstRowIdx = 0;
/** Pixel offset of the display of the first row. */
protected int _firstRowPixelOffset = 0;
/** Index of the first row displayed. */
protected int _firstColIdx = 0;
/** pixel offset of the firs displayed column. */
protected int _firstColPixelOffset = 0;
/** number of fixed columns. */
protected int _fixedColumns = 0;
/** number of fixed rows. */
protected int _fixedRows = 0;
/** cell renderer map for columns. */
protected Map<IColumn, ICellRenderer> _colCellRendererMap = new HashMap<IColumn, ICellRenderer>();
/** cell renderer map for classes. */
protected Map<Class<?>, ICellRenderer> _colClassRendererMap = new HashMap<Class<?>, ICellRenderer>();
/** cell editor map for columns. */
protected Map<IColumn, ICellEditor> _colCellEditorMap = new HashMap<IColumn, ICellEditor>();
/** cell editor map for classes. */
protected Map<Class<?>, ICellEditor> _colClassEditorMap = new HashMap<Class<?>, ICellEditor>();
/** configuration: support fill dragging. */
protected boolean _supportFillDragging = true;
/** fill drag strategy. * */
protected IFillDragStrategy _fillDragStrategy = new DefaultFillDragStrategy();
/** Strategy for handling cut copy paste. */
protected ICCPStrategy _ccpStrategy = new DefaultCCPStrategy();
/** table model. */
protected IJaretTableModel _model;
/** hierarchical table model if used. */
protected IHierarchicalJaretTableModel _hierarchicalModel;
/** table viewstate. */
protected ITableViewState _tvs = new DefaultTableViewState();
/** List of rows actually diplayed (filtered and ordered). */
protected List<IRow> _rows = new ArrayList<IRow>();
/** row filter. */
protected IRowFilter _rowFilter;
/** row sorter. */
protected IRowSorter _rowSorter;
/** List of columns actually displayed. */
protected List<IColumn> _cols = new ArrayList<IColumn>();
/** Rectangle the headers are painted in. */
protected Rectangle _headerRect;
/** height of the headers. */
protected int _headerHeight = DEFAULTHEADERHEIGHT;
/** minimal height for the header. */
protected int _minHeaderHeight = DEFAULTMINHEADERHEIGHT;
/** if true headers will be drawn. */
protected boolean _drawHeader = true;
/** rectangle the main table is drawn into (withou fixedcolRect and without fixedRowRect!). */
protected Rectangle _tableRect;
/** Renderer used to render the headers. */
protected ITableHeaderRenderer _headerRenderer = new DefaultTableHeaderRenderer();
/** Rectangle in which the fixed columns will be painted. */
protected Rectangle _fixedColRect;
/** Rectangle in which the fixed rows will be painted. */
protected Rectangle _fixedRowRect;
/** cache for the drag marker location. */
protected Rectangle _dragMarkerRect;
/** Rectangle the autofilter elements (combos) are placed. */
protected Rectangle _autoFilterRect;
/** if true autofilters are enabled and present. */
protected boolean _autoFilterEnabled = false;
/** Instance of the interbal RowFilter that makes up the autofilter. */
protected AutoFilter _autoFilter = new AutoFilter(this);
/** map containing the actual instantiated autofilters for the different columns. */
protected Map<IColumn, IAutoFilter> _autoFilterMap = new HashMap<IColumn, IAutoFilter>();
/** map containing the autofilter classes to use for dedicated content classes. */
protected Map<Class<?>, Class<? extends IAutoFilter>> _autoFilterClassMap = new HashMap<Class<?>, Class<? extends IAutoFilter>>();
/** map containing teh autofiletr classes to use for specified columns. */
protected Map<IColumn, Class<? extends IAutoFilter>> _autoFilterColumnMap = new HashMap<IColumn, Class<? extends IAutoFilter>>();
/** if true header resizing is allowed. */
private boolean _headerResizeAllowed = true;
/** if true row resizes are allowed. */
private boolean _rowResizeAllowed = true;
/** if true column resizes are allowed. */
private boolean _columnResizeAllowed = true;
/**
* If true, resizing is only allowed in header and fixed columns (for rows) and the leftmost SELDELTA pixels of
* eachrow.
*/
protected boolean _resizeRestriction = false;
/** if true fixed rows will not be affected by sorting operations. */
protected boolean _excludeFixedRowsFromSorting = true;
/** global flag for allowing sorting of the table. */
protected boolean _allowSorting = true;
// focus control
/** row of the focussed cell or null. */
protected IRow _focussedRow = null;
/** column of the focussed cell or null. */
protected IColumn _focussedColumn = null;
/** Listz of listeners interested in changes of the focussed cell. */
protected List<ITableFocusListener> _tableFocusListeners;
/** selection model used by the table. */
protected IJaretTableSelectionModel _selectionModel = new JaretTableSelectionModelImpl();
// editing
/** cell editor used to edit a cell. will be nun null when editiing. */
protected ICellEditor _editor; // if != null editing in progress
/** control of the editor. */
protected Control _editorControl = null;
/** row that is edited. */
protected IRow _editorRow;
/** context menu used on table headers. */
protected Menu _headerContextMenu;
/** context menu used for rows. */
protected Menu _rowContextMenu;
/** Delegate to handle property change listener support. */
protected PropertyChangeSupport _propertyChangeSupport;
/** row information cache. */
protected List<RowInfo> _rowInfoCache = null;
/** column information cache. */
protected List<ColInfo> _colInfoCache = new ArrayList<ColInfo>();
/**
* Simple struct for storing row information.
*
* @author Peter Kliem
* @version $Id: JaretTable.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class RowInfo {
/** beginning y coordinate. */
public int y;
/** row reference. */
public IRow row;
/** height of the row. */
public int height;
/** fixed row flag. */
public boolean fixed = false;
/**
* Construct a row info instance.
*
* @param rowIn row reference
* @param yIn begin y
* @param heightIn height of the row
* @param fixedIn true if the row is a fixed row
*/
public RowInfo(IRow rowIn, int yIn, int heightIn, boolean fixedIn) {
this.row = rowIn;
this.y = yIn;
this.height = heightIn;
this.fixed = fixedIn;
}
}
/**
* Simple struct for storing column information.
*
* @author Peter Kliem
* @version $Id: JaretTable.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class ColInfo {
/** begin x coordinate. */
public int x;
/** column reference. */
public IColumn column;
/** actual width of the column. */
public int width;
/**
* Construct a col info instance.
*
* @param columnIn col ref
* @param xIn begin x
* @param widthIn width in pixel
*/
public ColInfo(IColumn columnIn, int xIn, int widthIn) {
this.column = columnIn;
this.x = xIn;
this.width = widthIn;
}
}
/**
* Constructor for a new JaretTable widget.
*
* @param parent parent composite
* @param style style bits (use HSCROLL, VSCROLL)
*/
public JaretTable(Composite parent, int style) {
// no background painting
super(parent, style | SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED);
addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
onPaint(event);
}
});
addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent me) {
mouseDouble(me.x, me.y);
}
public void mouseDown(MouseEvent me) {
forceFocus();
mousePressed(me.x, me.y, me.button == POPUPTRIGGER, me.stateMask);
}
public void mouseUp(MouseEvent me) {
mouseReleased(me.x, me.y, me.button == POPUPTRIGGER);
}
});
addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent me) {
if ((me.stateMask & SWT.BUTTON1) != 0) {
mouseDragged(me.x, me.y, me.stateMask);
} else {
mouseMoved(me.x, me.y, me.stateMask);
}
}
});
addMouseTrackListener(new MouseTrackListener() {
public void mouseEnter(MouseEvent arg0) {
}
public void mouseExit(MouseEvent arg0) {
// on exit set standard cursor
if (Display.getCurrent().getActiveShell() != null) {
Display.getCurrent().getActiveShell().setCursor(
Display.getCurrent().getSystemCursor(SWT.CURSOR_ARROW));
}
}
public void mouseHover(MouseEvent me) {
setToolTipText(getToolTipText(me.x, me.y));
}
});
addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
onDispose(event);
}
});
// key listener for keyboard control
addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) {
handleKeyPressed(event);
}
public void keyReleased(KeyEvent arg0) {
}
});
Listener listener = new Listener() {
public void handleEvent(Event event) {
switch (event.type) {
case SWT.Resize:
updateScrollBars();
break;
default:
// do nothing
break;
}
}
};
addListener(SWT.Resize, listener);
ScrollBar verticalBar = getVerticalBar();
if (verticalBar != null) {
verticalBar.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
handleVerticalScroll(event);
}
});
}
ScrollBar horizontalBar = getHorizontalBar();
if (horizontalBar != null) {
horizontalBar.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
handleHorizontalScroll(event);
}
});
}
_tableRect = getClientArea();
_fixedColRect = getClientArea();
// updateYScrollBar();
// register default cell renderers, editors and autofilters
registerDefaultRenderers();
registerDefaultEditors();
registerDefaultAutofilters();
// register with the viewstate
_tvs.addTableViewStateListener(this);
// register with the selection model
_selectionModel.addTableSelectionModelListener(this);
setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
_propertyChangeSupport = new PropertyChangeSupport(this);
}
/**
* Dispose whatever there is to dispose (renderers and so on).
*
* @param event dispose event
*/
private void onDispose(DisposeEvent event) {
// header renderer
if (_headerRenderer != null) {
_headerRenderer.dispose();
}
// cell renderers
for (ICellRenderer renderer : _colCellRendererMap.values()) {
renderer.dispose();
}
for (ICellRenderer renderer : _colClassRendererMap.values()) {
renderer.dispose();
}
// cell editors
for (ICellEditor editor : _colCellEditorMap.values()) {
editor.dispose();
}
for (ICellEditor editor : _colClassEditorMap.values()) {
editor.dispose();
}
// autofilters
for (IAutoFilter autoFilter : _autoFilterMap.values()) {
autoFilter.dispose();
}
if (_rowSorter != null) {
_rowSorter.removePropertyChangeListener(this);
}
if (_rowFilter != null) {
_rowFilter.removePropertyChangeListener(this);
}
if (_ccpStrategy != null) {
_ccpStrategy.dispose();
}
}
/**
* Register all default renderers.
*
*/
private void registerDefaultRenderers() {
ICellRenderer cellRenderer = new TextCellRenderer();
registerCellRenderer(void.class, cellRenderer);
registerCellRenderer(String.class, cellRenderer);
registerCellRenderer(Image.class, new ImageCellRenderer());
cellRenderer = new BooleanCellRenderer();
registerCellRenderer(Boolean.class, cellRenderer);
registerCellRenderer(Boolean.TYPE, cellRenderer);
cellRenderer = new DateCellRenderer();
registerCellRenderer(Date.class, cellRenderer);
registerCellRenderer(JaretDate.class, cellRenderer);
cellRenderer = new DoubleCellRenderer();
registerCellRenderer(Double.class, cellRenderer);
registerCellRenderer(Double.TYPE, cellRenderer);
}
/**
* Register all default editors.
*
*/
private void registerDefaultEditors() {
registerCellEditor(String.class, new TextCellEditor(true));
registerCellEditor(Boolean.class, new BooleanCellEditor(true));
registerCellEditor(Date.class, new DateCellEditor());
registerCellEditor(JaretDate.class, new DateCellEditor());
registerCellEditor(Enum.class, new EnumComboEditor());
registerCellEditor(Integer.class, new IntegerCellEditor());
registerCellEditor(Integer.TYPE, new IntegerCellEditor());
registerCellEditor(Double.class, new DoubleCellEditor());
registerCellEditor(Double.TYPE, new DoubleCellEditor());
}
/**
* Regsiter the default autofilters.
*/
private void registerDefaultAutofilters() {
registerAutoFilterForClass(String.class, DefaultAutoFilter.class);
}
/**
* Register a cell renderer for rendering objects of class clazz.
*
* @param clazz class the renderer should be applied for
* @param cellRenderer renderer to use for clazz
*/
public void registerCellRenderer(Class<?> clazz, ICellRenderer cellRenderer) {
_colClassRendererMap.put(clazz, cellRenderer);
}
/**
* Register a cell renderer for a column.
*
* @param column column the renderer should be used on
* @param cellRenderer renderer to use
*/
public void registerCellRenderer(IColumn column, ICellRenderer cellRenderer) {
_colCellRendererMap.put(column, cellRenderer);
}
/**
* Retrieve the cell renderer for a cell.
*
* @param row row row of the cell
* @param column column column of the cell
* @return cell renderer
*/
protected ICellRenderer getCellRenderer(IRow row, IColumn column) {
// first check column specific renderers
ICellRenderer renderer = null;
renderer = _colCellRendererMap.get(column);
if (renderer == null) {
// try class map
Object value = column.getValue(row);
if (value != null) {
renderer = getCellRendererFromMap(value.getClass());
}
if (renderer == null) {
// nothing? -> default
renderer = _colClassRendererMap.get(void.class);
}
}
return renderer;
}
/**
* Register a cell editor for objects of class clazz.
*
* @param clazz class of objeects the editor should be used for
* @param cellEditor editor to use
*/
public void registerCellEditor(Class<?> clazz, ICellEditor cellEditor) {
_colClassEditorMap.put(clazz, cellEditor);
}
/**
* Register a cell editor for a column.
*
* @param column column the editor should be used for
* @param cellEditor editor to use
*/
public void registerCellEditor(IColumn column, ICellEditor cellEditor) {
_colCellEditorMap.put(column, cellEditor);
}
/**
* Retrieve the cell editor for a cell.
*
* @param row row of the cell
* @param column col of the cell
* @return cell editor or <code>null</code> if no editor can be found
*/
private ICellEditor getCellEditor(IRow row, IColumn column) {
// first check column specific renderers
ICellEditor editor = null;
editor = _colCellEditorMap.get(column);
if (editor == null) {
// try class map
Object value = column.getValue(row);
if (value != null) {
editor = getCellEditorFromMap(value.getClass());
} else if (column.getContentClass(row) != null) {
editor = getCellEditorFromMap(column.getContentClass(row));
} else if (column.getContentClass() != null) {
editor = getCellEditorFromMap(column.getContentClass());
}
}
return editor;
}
/**
* Retrieve a cell editor for a given class. Checks all interfaces and all superclasses.
*
* @param clazz class in queston
* @return editor or null
*/
private ICellEditor getCellEditorFromMap(Class<?> clazz) {
ICellEditor result = null;
result = _colClassEditorMap.get(clazz);
if (result != null) {
return result;
}
Class<?>[] interfaces = clazz.getInterfaces();
for (Class<?> c : interfaces) {
result = _colClassEditorMap.get(c);
if (result != null) {
return result;
}
}
Class<?> sc = clazz.getSuperclass();
while (sc != null) {
result = _colClassEditorMap.get(sc);
if (result != null) {
return result;
}
// interfaces of the superclass
Class<?>[] scinterfaces = sc.getInterfaces();
for (Class<?> c : scinterfaces) {
result = _colClassEditorMap.get(c);
if (result != null) {
return result;
}
}
sc = sc.getSuperclass();
}
return result;
}
/**
* Retrieve a cell renderer for a given class. Checks all interfaces and all superclasses.
*
* @param clazz class in queston
* @return renderer or null
*/
private ICellRenderer getCellRendererFromMap(Class<?> clazz) {
ICellRenderer result = null;
result = _colClassRendererMap.get(clazz);
if (result != null) {
return result;
}
Class<?>[] interfaces = clazz.getInterfaces();
for (Class<?> c : interfaces) {
result = _colClassRendererMap.get(c);
if (result != null) {
return result;
}
}
Class<?> sc = clazz.getSuperclass();
while (sc != null) {
result = _colClassRendererMap.get(sc);
if (result != null) {
return result;
}
// interfaces of the superclass
Class<?>[] scinterfaces = sc.getInterfaces();
for (Class<?> c : scinterfaces) {
result = _colClassRendererMap.get(c);
if (result != null) {
return result;
}
}
sc = sc.getSuperclass();
}
return result;
}
/**
* Register an autofilter implementing class to be used on columns that announce a specific content class.
*
* @param clazz content clazz thet triggers the use of the filter
* @param autoFilterClass class implementing the IAutoFilter interface that will be used
*/
public void registerAutoFilterForClass(Class<?> clazz, Class<? extends IAutoFilter> autoFilterClass) {
_autoFilterClassMap.put(clazz, autoFilterClass);
}
/**
* Regsiter an autofilter implementing class for use with a specific column.
*
* @param column column
* @param autoFilterClass class of autofilter that will be used
*/
public void registerAutoFilterForColumn(IColumn column, Class<? extends IAutoFilter> autoFilterClass) {
_autoFilterColumnMap.put(column, autoFilterClass);
}
/**
* Get the autofiletr class to be used on a column.
*
* @param column column
* @return class or <code>null</code> if none could be determined
*/
protected Class<? extends IAutoFilter> getAutoFilterClass(IColumn column) {
Class<? extends IAutoFilter> result = _autoFilterColumnMap.get(column);
if (result != null) {
return result;
}
Class<?> contentClass = column.getContentClass();
if (contentClass != null) {
result = getAutoFilterClassForClass(contentClass);
}
// nothing found so long -> use default (String) filter
if (result == null) {
result = _autoFilterClassMap.get(String.class);
}
return result;
}
/**
* Retrieve autofilter class for a given content class. Takes interfaces and superclasses into account.
*
* @param clazz content class
* @return class to be used or <code>null</code> if none could be determined
*/
private Class<? extends IAutoFilter> getAutoFilterClassForClass(Class<?> clazz) {
Class<? extends IAutoFilter> result = null;
result = _autoFilterClassMap.get(clazz);
if (result != null) {
return result;
}
Class<?>[] interfaces = clazz.getInterfaces();
for (Class<?> c : interfaces) {
result = _autoFilterClassMap.get(c);
if (result != null) {
return result;
}
}
Class<?> sc = clazz.getSuperclass();
while (sc != null) {
result = _autoFilterClassMap.get(sc);
if (result != null) {
return result;
}
// interfaces of the superclass
Class<?>[] scinterfaces = sc.getInterfaces();
for (Class<?> c : scinterfaces) {
result = _autoFilterClassMap.get(c);
if (result != null) {
return result;
}
}
sc = sc.getSuperclass();
}
return result;
}
// ////// mouse handling
/** currently dragged row (dragging height). */
protected RowInfo _heightDraggedRowInfo = null;
/** currently dragged (width) column or null. */
protected ColInfo _widthDraggedColumn = null;
/** true if the header height is beeing dragged. */
protected boolean _headerDragged = false;
/**
* Handle mouse double click.
*
* @param x x coordinate
* @param y y coordinate
*/
private void mouseDouble(int x, int y) {
if (_tableRect.contains(x, y) || (_fixedColumns > 0 && _fixedColRect.contains(x, y))
|| (_fixedRows > 0 && _fixedRowRect.contains(x, y))) {
setFocus(x, y);
startEditing(rowForY(y), colForX(x), (char) 0);
}
}
/**
* Handle mouse pressed.
*
* @param x x coordinate
* @param y y coordinate
* @param popuptrigger true if the button pressed was the popup trigger
* @param stateMask statemask from the event
*/
private void mousePressed(int x, int y, boolean popuptrigger, int stateMask) {
// check for location over drag marker and start fill drag if necessary
if (_dragMarkerRect != null && _dragMarkerRect.contains(x, y)) {
_isFillDrag = true;
_firstFillDragSelect = _selectedIdxRectangle;
return;
}
IRow row = rowByBottomBorder(y);
if (row != null
&& _rowResizeAllowed
&& (_tvs.getRowHeigthMode(row) == RowHeightMode.VARIABLE || _tvs.getRowHeigthMode(row) == RowHeightMode.OPTANDVAR)
&& (!_resizeRestriction || Math.abs(x - _tableRect.x) <= SELDELTA || (_fixedColRect != null && _fixedColRect
.contains(x, y)))) {
_heightDraggedRowInfo = getRowInfo(row);
return;
} else {
IColumn col = colByRightBorder(x);
if (col != null && _columnResizeAllowed && _tvs.columnResizingAllowed(col)
&& (!_resizeRestriction || _headerRect == null || _headerRect.contains(x, y))) {
_widthDraggedColumn = getColInfo(col);
return;
}
}
// check header drag
if (_headerResizeAllowed && Math.abs(_headerRect.y + _headerRect.height - y) <= SELDELTA) {
_headerDragged = true;
return;
}
// handle mouse press for selection
boolean doSelect = true;
// check focus set
if (_tableRect.contains(x, y) || (_fixedColumns > 0 && _fixedColRect.contains(x, y))
|| (_fixedRows > 0 && _fixedRowRect.contains(x, y))) {
setFocus(x, y);
doSelect = !handleEditorSingleClick(x, y);
}
// check hierarchy
if (_tableRect.contains(x, y) || (_fixedColumns > 0 && _fixedColRect.contains(x, y))
|| (_fixedRows > 0 && _fixedRowRect.contains(x, y))) {
IRow xrow = rowForY(y);
IColumn xcol = colForX(x);
if (xrow != null && xcol != null && isHierarchyColumn(xrow, xcol)) {
Rectangle rect = getCellBounds(xrow, xcol);
IHierarchyRenderer hrenderer = (IHierarchyRenderer) getCellRenderer(xrow, xcol);
if (hrenderer.isInActiveArea(xrow, rect, x, y)) {
toggleExpanded(xrow);
}
}
}
// check header sorting clicks
IColumn xcol = colForX(x);
if (_allowSorting && _headerRect.contains(x, y)
&& _headerRenderer.isSortingClick(getHeaderDrawingArea(xcol), xcol, x, y)) {
_tvs.setSorting(xcol);
} else if (doSelect) {
// selection can be intercepted by editor clicks
handleSelection(x, y, stateMask, false);
}
}
/**
* Toggle the expanded state of a row.
*
* @param row row to toggle
*/
private void toggleExpanded(IRow row) {
IHierarchicalTableViewState hvs = (IHierarchicalTableViewState) _tvs;
hvs.setExpanded((ITableNode) row, !hvs.isExpanded((ITableNode) row));
}
/**
* Determine whether the column is the hierrarchy column. This is accomplished by looking at the cell renderer
* class.
*
* @param row row
* @param col column
* @return true if hte adressed cell is part of the hierarchy column
*/
private boolean isHierarchyColumn(IRow row, IColumn col) {
if (row == null || col == null) {
return false;
}
return getCellRenderer(row, col) instanceof TableHierarchyRenderer;
}
/**
* Check whether a column is the hierarchy column.
*
* @param column column to check
* @return <code>true</code> if the column is the hierarchy column
*/
public boolean isHierarchyColumn(IColumn column) {
if (column == null) {
return false;
}
return isHierarchyColumn(_rows.get(0), column);
}
/**
* Retrieve the rectangle in which the header of a column is drawn.
*
* @param col column
* @return drawing rectangle for the header
*/
private Rectangle getHeaderDrawingArea(IColumn col) {
int x = getColInfo(col).x;
Rectangle r = new Rectangle(x, _tableRect.y, _tvs.getColumnWidth(col), _tableRect.height);
return r;
}
/**
* Check whether a click is a row selection.
*
* @param x x coordinate
* @param y y coordinate
* @return true for click on the left margin of the table or in the fixed column area
*/
private boolean isRowSelection(int x, int y) {
return (Math.abs(x - _tableRect.x) <= SELDELTA || (_fixedColRect != null && _fixedColRect.contains(x, y)));
}
/**
* Check whether a click is a column selection.
*
* @param x x coordinate
* @param y y coordinate
* @return true for coordinate in header or fixed rows
*/
private boolean isColumnSelection(int x, int y) {
return (_headerRect != null && _headerRect.contains(x, y))
|| (_fixedRowRect != null && _fixedRowRect.contains(x, y));
}
protected int _firstCellSelectX = -1;
protected int _firstCellSelectY = -1;
protected int _lastCellSelectX = -1;
protected int _lastCellSelectY = -1;
/**
* marker flag for drag operation: fill drag.
*/
protected boolean _isFillDrag = false;
/** first col selected in drag. */
protected int _firstColSelectIdx = -1;
/** last col selected in drag or as standard col selection. */
protected int _lastColSelectIdx = -1;
int _lastKeyColSelectIdx = -1;
int _firstKeyColSelectIdx = -1;
/** first row selected in drag. */
protected int _firstRowSelectIdx = -1;
/** last row selected in drag. */
protected int _lastRowSelectIdx = -1;
int _lastKeyRowSelectIdx = -1;
int _firstKeyRowSelectIdx = -1;
/** last cell idx selected by shift-arrow. */
protected Point _lastKeySelect = null;
/** first cell idx selected by shift-arrow. */
protected Point _firstKeySelect = null;
/** enum for the selection type (intern). */
private enum SelectType {
NONE, CELL, COLUMN, ROW
};
/** index rectangle of selected cells whenn a fill drag starts. */
Rectangle _firstFillDragSelect = null;
/** true if the fill drag is horizontal (fill along the x axis), false for vertical fill drag. */
private boolean _horizontalFillDrag;
/** type of the last selection, used for handling keyboard selection. */
protected SelectType _lastSelectType = SelectType.NONE;
/**
* Handle selection operations.
*
* @param x x
* @param y y
* @param stateMask key state mask
* @param dragging true when dragging
*/
private void handleSelection(int x, int y, int stateMask, boolean dragging) {
// a mouse select always ends a shift-arrow select
_lastKeySelect = null;
_firstKeySelect = null;
_firstKeyColSelectIdx = -1;
_lastKeyColSelectIdx = -1;
_firstKeyRowSelectIdx = -1;
_lastKeyRowSelectIdx = -1;
IRow row = rowForY(y);
int rowIdx = row != null ? _rows.indexOf(row) : -1;
IColumn col = colForX(x);
int colIdx = getColumnIdx(col);
// check fill dragging
if (dragging && _isFillDrag) {
if (_selectionModel.isCellSelectionAllowed() && _tableRect.contains(x, y)) {
if (col != null && row != null) {
if (_firstCellSelectX == -1) {
_firstCellSelectX = colIdx;
_firstCellSelectY = rowIdx;
}
if (Math.abs(_firstCellSelectX - colIdx) > Math.abs(_firstCellSelectY - rowIdx)) {
rowIdx = _firstCellSelectY;
row = rowForIdx(rowIdx);
_horizontalFillDrag = false;
} else {
colIdx = _firstCellSelectX;
col = colForIdx(colIdx);
_horizontalFillDrag = true;
}
ensureSelectionContainsRegion(_firstFillDragSelect, colIdx, rowIdx, _lastCellSelectX,
_lastCellSelectY);
// ensureSelectionContainsRegion(_firstCellSelectX, _firstCellSelectY, colIdx, rowIdx,
// _lastCellSelectX, _lastCellSelectY);
_lastCellSelectX = colIdx;
_lastCellSelectY = rowIdx;
// a newly selected cell will always be the focussed cell (causes scrolling this cell to be
// completely visible)
setFocus(row, col);
}
}
return;
}
// check row selection
if (row != null && _selectionModel.isFullRowSelectionAllowed()
&& (isRowSelection(x, y) || _selectionModel.isOnlyRowSelectionAllowed() || _firstRowSelectIdx != -1)) {
if (_firstRowSelectIdx == -1) {
_firstRowSelectIdx = rowIdx;
}
if ((stateMask & SWT.CONTROL) != 0) {
if (!_selectionModel.getSelection().getSelectedRows().contains(row)) {
_selectionModel.addSelectedRow(row);
} else {
_selectionModel.remSelectedRow(row);
}
_lastSelectType = SelectType.ROW;
} else if (dragging) {
ensureSelectionContainsRowRegion(_firstRowSelectIdx, rowIdx, _lastRowSelectIdx);
_lastRowSelectIdx = rowIdx;
_lastSelectType = SelectType.ROW;
} else {
_selectionModel.clearSelection();
_selectionModel.addSelectedRow(row);
_lastSelectType = SelectType.ROW;
}
_lastRowSelectIdx = rowIdx;
return;
}
// check column selection
if (_selectionModel.isFullColumnSelectionAllowed() && (isColumnSelection(x, y) || _firstColSelectIdx != -1)) {
if (_firstColSelectIdx == -1) {
_firstColSelectIdx = colIdx;
}
if ((stateMask & SWT.CONTROL) != 0) {
if (!_selectionModel.getSelection().getSelectedColumns().contains(col)) {
_selectionModel.addSelectedColumn(col);
} else {
_selectionModel.remSelectedColumn(col);
}
_lastSelectType = SelectType.COLUMN;
} else if (dragging) {
ensureSelectionContainsColRegion(_firstColSelectIdx, colIdx, _lastColSelectIdx);
_lastColSelectIdx = colIdx;
_lastSelectType = SelectType.COLUMN;
} else {
_selectionModel.clearSelection();
_selectionModel.addSelectedColumn(col);
_lastSelectType = SelectType.COLUMN;
}
_lastColSelectIdx = colIdx;
return;
}
// check cell selection
if (_selectionModel.isCellSelectionAllowed() && _tableRect.contains(x, y)) {
if (col != null && row != null) {
IJaretTableCell cell = new JaretTableCellImpl(row, col);
if (_firstCellSelectX == -1) {
_firstCellSelectX = colIdx;
_firstCellSelectY = rowIdx;
}
if ((stateMask & SWT.CONTROL) != 0) {
if (!_selectionModel.getSelection().getSelectedCells().contains(cell)) {
_selectionModel.addSelectedCell(cell);
} else {
_selectionModel.remSelectedCell(cell);
}
_lastSelectType = SelectType.CELL;
} else if (dragging) {
ensureSelectionContainsRegion(_firstCellSelectX, _firstCellSelectY, colIdx, rowIdx,
_lastCellSelectX, _lastCellSelectY);
_lastCellSelectX = colIdx;
_lastCellSelectY = rowIdx;
_lastSelectType = SelectType.CELL;
} else {
_selectionModel.clearSelection();
_selectionModel.addSelectedCell(cell);
_lastSelectType = SelectType.CELL;
}
// a newly selected cell will always be the focussed cell (causes scrolling this cell to be completely
// visible)
setFocus(row, col);
}
}
}
/**
* Ensures that the selection contains the rows from firstIdx to rowIdx. If the range firstIdx to lastIdx is larger
* than the region the other rows will be removed from the selection.
*
* @param firstRowSelectIdx first selected row index
* @param rowIdx current selected row index
* @param lastRowSelectIdx may be -1 for no last selection
*/
private void ensureSelectionContainsRowRegion(int firstRowSelectIdx, int rowIdx, int lastRowSelectIdx) {
int first = Math.min(firstRowSelectIdx, rowIdx);
int end = Math.max(firstRowSelectIdx, rowIdx);
for (int i = first; i <= end; i++) {
IRow row = rowForIdx(i);
if (!_selectionModel.getSelection().getSelectedRows().contains(row)) {
_selectionModel.addSelectedRow(row);
}
}
if (lastRowSelectIdx != -1) {
int f = Math.min(firstRowSelectIdx, lastRowSelectIdx);
int e = Math.max(firstRowSelectIdx, lastRowSelectIdx);
for (int i = f; i <= e; i++) {
if (i < first || i > end) {
IRow row = rowForIdx(i);
_selectionModel.remSelectedRow(row);
}
}
}
}
/**
* Ensures that the selection contains the columns from firstIdx to colIdx. If the range firstIdx to lastIdx is
* larger than the region the other columns will be removed from the selection.
*
* @param firstColIdx first selected column index
* @param colIdx current selected column index
* @param lastColSelectIdx may be -1 for no last selection
*/
private void ensureSelectionContainsColRegion(int firstColIdx, int colIdx, int lastColSelectIdx) {
int first = Math.min(firstColIdx, colIdx);
int end = Math.max(firstColIdx, colIdx);
for (int i = first; i <= end; i++) {
IColumn col = colForIdx(i);
if (!_selectionModel.getSelection().getSelectedColumns().contains(col)) {
_selectionModel.addSelectedColumn(col);
}
}
if (lastColSelectIdx != -1) {
int f = Math.min(firstColIdx, lastColSelectIdx);
int e = Math.max(firstColIdx, lastColSelectIdx);
for (int i = f; i <= e; i++) {
if (i < first || i > end) {
IColumn col = colForIdx(i);
_selectionModel.remSelectedColumn(col);
}
}
}
}
/**
* Ensures the selection contains the cells in the rectangle given by first*, *Idx. If the rectangle given by
* first*, last* is larger than the other rectangle is is ensured that the additional cells are not in the
* selection.
*
* @param firstCellSelectX begin x index of selected cell rectangle
* @param firstCellSelectY begin y index of selected cell rectangle
* @param colIdx end x index of selected cell rectangle
* @param rowIdx end y index of selected cell rectangle
* @param lastCellSelectX may be -1 for no last selection
* @param lastCellSelectY may be -1 for no last selection
*/
private void ensureSelectionContainsRegion(int firstCellSelectX, int firstCellSelectY, int colIdx, int rowIdx,
int lastCellSelectX, int lastCellSelectY) {
int firstx = Math.min(firstCellSelectX, colIdx);
int endx = Math.max(firstCellSelectX, colIdx);
int firsty = Math.min(firstCellSelectY, rowIdx);
int endy = Math.max(firstCellSelectY, rowIdx);
for (int x = firstx; x <= endx; x++) {
for (int y = firsty; y <= endy; y++) {
IJaretTableCell cell = new JaretTableCellImpl(rowForIdx(y), colForIdx(x));
if (!_selectionModel.getSelection().getSelectedCells().contains(cell)) {
_selectionModel.addSelectedCell(cell);
}
}
}
// last sel rect
if (lastCellSelectX != -1) {
int lfx = Math.min(firstCellSelectX, lastCellSelectX);
int lex = Math.max(firstCellSelectX, lastCellSelectX);
int lfy = Math.min(firstCellSelectY, lastCellSelectY);
int ley = Math.max(firstCellSelectY, lastCellSelectY);
for (int x = lfx; x <= lex; x++) {
for (int y = lfy; y <= ley; y++) {
if (!(x >= firstx && x <= endx && y >= firsty && y <= endy)) {
IJaretTableCell cell = new JaretTableCellImpl(rowForIdx(y), colForIdx(x));
_selectionModel.remSelectedCell(cell);
}
}
}
}
}
/**
* Ensures the selection contains the cells in the rectangle given by firstIdxRect, *Idx. If the rectangle given by
* first*, last* is larger than the other rectangle is is ensured that the additional cells are not in the
* selection.
*
* @param firstIdxRect rectangle containing the indizes of the originating rect
* @param colIdx new end x index for the selected rectangle
* @param rowIdx new end y index for teh selecetd rectangle
* @param lastCellSelectX may be -1 for no last selection
* @param lastCellSelectY may be -1 for no last selection
*/
private void ensureSelectionContainsRegion(Rectangle firstIdxRect, int colIdx, int rowIdx, int lastCellSelectX,
int lastCellSelectY) {
int firstx = Math.min(firstIdxRect.x, colIdx);
int endx = Math.max(firstIdxRect.x + firstIdxRect.width - 1, colIdx);
int firsty = Math.min(firstIdxRect.y, rowIdx);
int endy = Math.max(firstIdxRect.y + firstIdxRect.height - 1, rowIdx);
for (int x = firstx; x <= endx; x++) {
for (int y = firsty; y <= endy; y++) {
IJaretTableCell cell = new JaretTableCellImpl(rowForIdx(y), colForIdx(x));
if (!_selectionModel.getSelection().getSelectedCells().contains(cell)) {
_selectionModel.addSelectedCell(cell);
}
}
}
// last sel rect
if (lastCellSelectX != -1 && lastCellSelectY != -1) {
int lfx = Math.min(firstIdxRect.x, lastCellSelectX);
int lex = Math.max(firstIdxRect.x + firstIdxRect.width - 1, lastCellSelectX);
int lfy = Math.min(firstIdxRect.y, lastCellSelectY);
int ley = Math.max(firstIdxRect.y + firstIdxRect.height - 1, lastCellSelectY);
for (int x = lfx; x <= lex; x++) {
for (int y = lfy; y <= ley; y++) {
if (!(x >= firstx && x <= endx && y >= firsty && y <= endy)) {
IJaretTableCell cell = new JaretTableCellImpl(rowForIdx(y), colForIdx(x));
_selectionModel.remSelectedCell(cell);
}
}
}
}
}
/**
* Handle drag of mouse.
*
* @param x x coordinate of pointer
* @param y y coordinate of pointer
* @param stateMask keyStatemask
*/
private void mouseDragged(int x, int y, int stateMask) {
if (_isFillDrag) {
handleSelection(x, y, stateMask, true);
} else if (_heightDraggedRowInfo != null) {
int newHeight = y - _heightDraggedRowInfo.y;
if (newHeight < _tvs.getMinimalRowHeight()) {
newHeight = _tvs.getMinimalRowHeight();
}
_tvs.setRowHeight(_heightDraggedRowInfo.row, newHeight);
// setting the row heigth on an OPTVAR ror converts this to variable
if (_tvs.getRowHeigthMode(_heightDraggedRowInfo.row) == RowHeightMode.OPTANDVAR) {
_tvs.setRowHeightMode(_heightDraggedRowInfo.row, RowHeightMode.VARIABLE);
}
} else if (_widthDraggedColumn != null) {
int newWidth = x - _widthDraggedColumn.x;
if (newWidth < _tvs.getMinimalColWidth()) {
newWidth = _tvs.getMinimalColWidth();
}
if (_tvs.getColumnWidth(_widthDraggedColumn.column) != newWidth) {
_tvs.setColumnWidth(_widthDraggedColumn.column, newWidth);
}
} else if (_headerDragged) {
int newHeight = y - _headerRect.y;
if (newHeight < _minHeaderHeight) {
newHeight = _minHeaderHeight;
}
setHeaderHeight(newHeight);
} else {
handleSelection(x, y, stateMask, true);
}
}
/**
* Handle mouse move. This is mostly: modifying the appearance of the cursor.
*
* @param x x coordinate of pointer
* @param y y coordinate of pointer
* @param stateMask keyStatemask
*/
private void mouseMoved(int x, int y, int stateMask) {
Display display = Display.getCurrent();
Shell activeShell = display != null ? display.getActiveShell() : null;
// check for location over drag marker
if (_dragMarkerRect != null && _dragMarkerRect.contains(x, y)) {
if (activeShell != null) {
// MAYBE other cursor for differentiation?
activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZEALL));
}
return;
}
// check for location over lower border of row
IRow row = rowByBottomBorder(y);
if (row != null
&& _rowResizeAllowed
&& (_tvs.getRowHeigthMode(row) == RowHeightMode.VARIABLE || _tvs.getRowHeigthMode(row) == RowHeightMode.OPTANDVAR)
&& (!_resizeRestriction || Math.abs(x - _tableRect.x) <= SELDELTA || (_fixedColRect != null && _fixedColRect
.contains(x, y)))) {
if (activeShell != null) {
activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENS));
}
return;
} else {
IColumn col = colByRightBorder(x);
if (col != null && _columnResizeAllowed && _tvs.columnResizingAllowed(col)
&& (!_resizeRestriction || _headerRect == null || _headerRect.contains(x, y))) {
if (activeShell != null) {
activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZEW));
}
return;
}
}
// check header drag symboling
if (_headerRect != null && _headerResizeAllowed && Math.abs(_headerRect.y + _headerRect.height - y) <= SELDELTA) {
if (activeShell != null) {
activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENS));
}
return;
}
if (Display.getCurrent().getActiveShell() != null) {
Display.getCurrent().getActiveShell().setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_ARROW));
}
}
/**
* Handle the release of a mouse button.
*
* @param x x coordinate
* @param y y coordinate
* @param popUpTrigger true if the buttonm is the popup trigger
*/
private void mouseReleased(int x, int y, boolean popUpTrigger) {
if (_isFillDrag) {
handleFill();
}
_heightDraggedRowInfo = null;
_widthDraggedColumn = null;
_headerDragged = false;
_firstCellSelectX = -1;
_firstCellSelectY = -1;
_lastCellSelectX = -1;
_lastCellSelectY = -1;
_firstColSelectIdx = -1;
// _lastColSelectIdx = -1;
_firstRowSelectIdx = -1;
// _lastRowSelectIDx = -1;
_isFillDrag = false;
if (_headerRect.contains(x, y) && popUpTrigger) {
displayHeaderContextMenu(x, y);
} else if (popUpTrigger && isRowSelection(x, y)) {
displayRowContextMenu(x, y);
}
}
/**
* Handle the end of a fill drag.
*
*/
private void handleFill() {
if (_fillDragStrategy != null) {
if (_horizontalFillDrag) {
// horizontal base rect
for (int i = _firstFillDragSelect.x; i < _firstFillDragSelect.x + _firstFillDragSelect.width; i++) {
IJaretTableCell firstCell = getCellForIdx(i, _firstFillDragSelect.y);
List<IJaretTableCell> cells = getSelectedCellsVertical(i);
cells.remove(firstCell);
_fillDragStrategy.doFill(this, firstCell, cells);
}
} else {
// vertical base rect
for (int i = _firstFillDragSelect.y; i < _firstFillDragSelect.y + _firstFillDragSelect.height; i++) {
IJaretTableCell firstCell = getCellForIdx(_firstFillDragSelect.x, i);
List<IJaretTableCell> cells = getSelectedCellsHorizontal(i);
cells.remove(firstCell);
_fillDragStrategy.doFill(this, firstCell, cells);
}
}
}
}
/**
* Get all cells that are selected at the x idx given.
*
* @param x x idx
* @return list of selecetd cells with x idx == x
*/
private List<IJaretTableCell> getSelectedCellsVertical(int x) {
List<IJaretTableCell> cells = new ArrayList<IJaretTableCell>();
List<IJaretTableCell> s = getSelectionModel().getSelection().getSelectedCells();
for (IJaretTableCell cell : s) {
Point p = getCellDisplayIdx(cell);
if (p.x == x) {
cells.add(cell);
}
}
return cells;
}
/**
* Get all cells that are selected at the y idx given.
*
* @param y y idx
* @return list of selecetd cells at idx y == y
*/
private List<IJaretTableCell> getSelectedCellsHorizontal(int y) {
List<IJaretTableCell> cells = new ArrayList<IJaretTableCell>();
List<IJaretTableCell> s = getSelectionModel().getSelection().getSelectedCells();
for (IJaretTableCell cell : s) {
Point p = getCellDisplayIdx(cell);
if (p.y == y) {
cells.add(cell);
}
}
return cells;
}
/**
* Supply tooltip text for a position in the table.
*
* @param x x coordinate
* @param y y coordinate
* @return tooltip text or <code>null</code>
*/
private String getToolTipText(int x, int y) {
IJaretTableCell cell = getCell(x, y);
if (cell != null) {
Rectangle bounds = getCellBounds(cell);
ICellRenderer renderer = getCellRenderer(cell.getRow(), cell.getColumn());
if (renderer != null) {
String tt = renderer.getTooltip(this, bounds, cell.getRow(), cell.getColumn(), x, y);
if (tt != null) {
return tt;
}
}
}
return null;
}
// /////// end mouse handling
// // keyboard handling
/**
* Handle any key presses.
*
* @param event key event
*/
private void handleKeyPressed(KeyEvent event) {
if ((event.stateMask & SWT.SHIFT) != 0 && Character.isISOControl(event.character)) {
switch (event.keyCode) {
case SWT.ARROW_RIGHT:
selectRight();
break;
case SWT.ARROW_LEFT:
selectLeft();
break;
case SWT.ARROW_DOWN:
selectDown();
break;
case SWT.ARROW_UP:
selectUp();
break;
default:
// do nothing
break;
}
} else if ((event.stateMask & SWT.CONTROL) != 0 && Character.isISOControl(event.character)) {
// TODO keybindings hard coded is ok for now
// System.out.println("keycode "+event.keyCode);
switch (event.keyCode) {
case 'c':
copy();
break;
case 'x':
cut();
break;
case 'v':
paste();
break;
case 'a':
selectAll();
break;
default:
// do nothing
break;
}
} else {
_lastKeySelect = null;
_firstKeySelect = null;
switch (event.keyCode) {
case SWT.ARROW_RIGHT:
focusRight();
break;
case SWT.ARROW_LEFT:
focusLeft();
break;
case SWT.ARROW_DOWN:
focusDown();
break;
case SWT.ARROW_UP:
focusUp();
break;
case SWT.TAB:
focusRight();
break;
case SWT.F2:
// startEditing(_focussedRow, _focussedColumn, (char) 0);
break;
default:
if (event.character == ' ' && isHierarchyColumn(_focussedRow, _focussedColumn)) {
toggleExpanded(_focussedRow);
} else if (!Character.isISOControl(event.character)) {
// startEditing(event.character);
}
// do nothing
break;
}
}
}
/**
* Enlarge selection to the right.
*/
private void selectRight() {
IJaretTableCell cell = getFocussedCell();
if (_lastSelectType == SelectType.CELL && cell != null) {
int cx = getColumnIdx(cell.getColumn());
int cy = getRowIdx(cell.getRow());
if (_lastKeySelect == null) {
_lastKeySelect = new Point(-1, -1);
}
if (_firstKeySelect == null) {
_firstKeySelect = new Point(cx, cy);
_selectionModel.clearSelection();
}
focusRight();
cell = getFocussedCell();
cx = getColumnIdx(cell.getColumn());
cy = getRowIdx(cell.getRow());
ensureSelectionContainsRegion(_firstKeySelect.x, _firstKeySelect.y, cx, cy, _lastKeySelect.x,
_lastKeySelect.y);
_lastSelectType = SelectType.CELL;
_lastKeySelect = new Point(cx, cy);
} else if (_lastSelectType == SelectType.COLUMN && (_lastColSelectIdx != -1 || _lastKeyColSelectIdx != -1)) {
if (_firstKeyColSelectIdx == -1) {
_firstKeyColSelectIdx = _lastColSelectIdx;
}
int colIdx = _lastKeyColSelectIdx != -1 ? _lastKeyColSelectIdx + 1 : _firstKeyColSelectIdx + 1;
if (colIdx > _cols.size() - 1) {
colIdx = _cols.size() - 1;
}
ensureSelectionContainsColRegion(_firstKeyColSelectIdx, colIdx, _lastKeyColSelectIdx);
_lastKeyColSelectIdx = colIdx;
}
}
/**
* Enlarge selection to the left.
*/
private void selectLeft() {
IJaretTableCell cell = getFocussedCell();
if (_lastSelectType == SelectType.CELL && cell != null) {
if (cell != null) {
int cx = getColumnIdx(cell.getColumn());
int cy = getRowIdx(cell.getRow());
if (_lastKeySelect == null) {
_lastKeySelect = new Point(-1, -1);
}
if (_firstKeySelect == null) {
_firstKeySelect = new Point(cx, cy);
_selectionModel.clearSelection();
}
focusLeft();
cell = getFocussedCell();
cx = getColumnIdx(cell.getColumn());
cy = getRowIdx(cell.getRow());
ensureSelectionContainsRegion(_firstKeySelect.x, _firstKeySelect.y, cx, cy, _lastKeySelect.x,
_lastKeySelect.y);
_lastSelectType = SelectType.CELL;
_lastKeySelect = new Point(cx, cy);
}
} else if (_lastSelectType == SelectType.COLUMN && (_lastColSelectIdx != -1 || _lastKeyColSelectIdx != -1)) {
if (_firstKeyColSelectIdx == -1) {
_firstKeyColSelectIdx = _lastColSelectIdx;
}
int colIdx = _lastKeyColSelectIdx != -1 ? _lastKeyColSelectIdx - 1 : _firstKeyColSelectIdx - 1;
if (colIdx < 0) {
colIdx = 0;
}
ensureSelectionContainsColRegion(_firstKeyColSelectIdx, colIdx, _lastKeyColSelectIdx);
_lastKeyColSelectIdx = colIdx;
}
}
/**
* Enlarge selection downwards.
*/
private void selectDown() {
IJaretTableCell cell = getFocussedCell();
if (_lastSelectType == SelectType.CELL && cell != null) {
if (cell != null) {
int cx = getColumnIdx(cell.getColumn());
int cy = getRowIdx(cell.getRow());
if (_lastKeySelect == null) {
_lastKeySelect = new Point(-1, -1);
}
if (_firstKeySelect == null) {
_firstKeySelect = new Point(cx, cy);
_selectionModel.clearSelection();
}
focusDown();
cell = getFocussedCell();
cx = getColumnIdx(cell.getColumn());
cy = getRowIdx(cell.getRow());
ensureSelectionContainsRegion(_firstKeySelect.x, _firstKeySelect.y, cx, cy, _lastKeySelect.x,
_lastKeySelect.y);
_lastSelectType = SelectType.CELL;
_lastKeySelect = new Point(cx, cy);
}
} else if (_lastSelectType == SelectType.ROW && (_lastRowSelectIdx != -1 || _lastKeyRowSelectIdx != -1)) {
if (_firstKeyRowSelectIdx == -1) {
_firstKeyRowSelectIdx = _lastRowSelectIdx;
}
int rowIdx = _lastKeyRowSelectIdx != -1 ? _lastKeyRowSelectIdx + 1 : _firstKeyRowSelectIdx + 1;
if (rowIdx > _rows.size() - 1) {
rowIdx = _rows.size() - 1;
}
ensureSelectionContainsRowRegion(_firstKeyRowSelectIdx, rowIdx, _lastKeyRowSelectIdx);
_lastKeyRowSelectIdx = rowIdx;
}
}
/**
* Enlarge selection upwards.
*/
private void selectUp() {
IJaretTableCell cell = getFocussedCell();
if (_lastSelectType == SelectType.CELL && cell != null) {
if (cell != null) {
int cx = getColumnIdx(cell.getColumn());
int cy = getRowIdx(cell.getRow());
if (_lastKeySelect == null) {
_lastKeySelect = new Point(-1, -1);
}
if (_firstKeySelect == null) {
_firstKeySelect = new Point(cx, cy);
_selectionModel.clearSelection();
}
focusUp();
cell = getFocussedCell();
cx = getColumnIdx(cell.getColumn());
cy = getRowIdx(cell.getRow());
ensureSelectionContainsRegion(_firstKeySelect.x, _firstKeySelect.y, cx, cy, _lastKeySelect.x,
_lastKeySelect.y);
_lastSelectType = SelectType.CELL;
_lastKeySelect = new Point(cx, cy);
}
} else if (_lastSelectType == SelectType.ROW && (_lastRowSelectIdx != -1 || _lastKeyRowSelectIdx != -1)) {
if (_firstKeyRowSelectIdx == -1) {
_firstKeyRowSelectIdx = _lastRowSelectIdx;
}
int rowIdx = _lastKeyRowSelectIdx != -1 ? _lastKeyRowSelectIdx - 1 : _firstKeyRowSelectIdx - 1;
if (rowIdx < 0) {
rowIdx = 0;
}
ensureSelectionContainsRowRegion(_firstKeyRowSelectIdx, rowIdx, _lastKeyRowSelectIdx);
_lastKeyRowSelectIdx = rowIdx;
}
}
/**
* Retrieve the currently focussed cell.
*
* @return the focussed cell or <code>null</code> if no cell is focussed
*/
public IJaretTableCell getFocussedCell() {
if (_focussedColumn != null && _focussedRow != null) {
return new JaretTableCellImpl(_focussedRow, _focussedColumn);
}
return null;
}
/**
* Retrieve the indizes of the currently focussed cell (idx in the filtered, sorted or whatever table).
*
* @return Point x = column, y = row or <code>null</code> if no cell is focussed
*/
public Point getFocussedCellIdx() {
if (_focussedColumn != null && _focussedRow != null) {
return new Point(getColumnIdx(_focussedColumn), getRowIdx(_focussedRow));
}
return null;
}
/**
* Retrieve the display coordinates for a table cell.
*
* @param cell cell to get he coordinates for
* @return Point x = colIdx, y = rowIdx
*/
public Point getCellDisplayIdx(IJaretTableCell cell) {
return new Point(getColumnIdx(cell.getColumn()), getRowIdx(cell.getRow()));
}
/**
* Convenience method for setting a value at a displayed position in the table. NOTE: this method does call the the
* set method of the model directly, so be aware that the model may protest by throwing a runtime exception or just
* ignore the new value.
*
* @param colIdx column index
* @param rowIdx row index
* @param value value to set
*/
public void setValue(int colIdx, int rowIdx, Object value) {
IColumn col = getColumn(colIdx);
IRow row = getRow(rowIdx);
col.setValue(row, value);
}
/**
* {@inheritDoc} will get call to transfer focus to the table. The mthod will focus the left/uppermost cell
* displayed. If no rows and columns are present no cell will get the focus.
*/
public boolean setFocus() {
super.setFocus();
if (_focussedRow == null && _rows != null && _rows.size() > 0 && _cols.size() > 0) {
setFocus(_rows.get(_firstRowIdx), _cols.get(_firstColIdx));
}
return true;
}
/**
* Ensures there is a focussed cell and uses the cell at 0,0 if no cell is focussed.
*
*/
private void ensureFocus() {
if (_focussedRow == null) {
_focussedRow = _rows.get(0);
}
if (_focussedColumn == null) {
_focussedColumn = _cols.get(0);
}
}
/**
* Move the focus left.
*/
public void focusLeft() {
ensureFocus();
int idx = _cols.indexOf(_focussedColumn);
if (idx > 0) {
setFocus(_focussedRow, _cols.get(idx - 1));
}
}
/**
* Move the focus right.
*/
public void focusRight() {
ensureFocus();
int idx = _cols.indexOf(_focussedColumn);
if (idx < _cols.size() - 1) {
setFocus(_focussedRow, _cols.get(idx + 1));
}
}
/**
* Move the focus up.
*/
public void focusUp() {
ensureFocus();
int idx = _rows.indexOf(_focussedRow);
if (idx > 0) {
setFocus(_rows.get(idx - 1), _focussedColumn);
}
}
/**
* Move the focus down.
*/
public void focusDown() {
ensureFocus();
int idx = _rows.indexOf(_focussedRow);
if (idx < _rows.size() - 1) {
setFocus(_rows.get(idx + 1), _focussedColumn);
}
}
/**
* Set the focussed cell by coordinates.
*
* @param x x coordinate
* @param y y coordinate
*/
private void setFocus(int x, int y) {
IRow row = rowForY(y);
IColumn col = colForX(x);
if (col != null && row != null) {
setFocus(row, col);
}
}
/**
* Check whether editing of a cell is in progress.
*
* @return true when editing a cell
*/
public boolean isEditing() {
return _editor != null;
}
/**
* Handle a single mouseclick by passing it to the cell editor if present.
*
* @param x x coordinate of the click
* @param y y coordinate of the click
* @return true if the editor handled the click
*/
private boolean handleEditorSingleClick(int x, int y) {
IRow row = rowForY(y);
IColumn col = colForX(x);
if (col != null && row != null) {
ICellEditor editor = getCellEditor(row, col);
if (editor != null) {
Rectangle area = getCellBounds(row, col);
return editor.handleClick(this, row, col, area, x, y);
}
}
return false;
}
/**
* Start editing after a keystroke on a cell.
*
* @param typedKey the typed key
*/
private void startEditing(char typedKey) {
if (_focussedRow != null && _focussedColumn != null) {
startEditing(_focussedRow, _focussedColumn, typedKey);
}
}
/**
* Start editing of a specified cell if it is editable.
*
* @param row row
* @param col column
* @param typedKey key typed
*/
public void startEditing(IRow row, IColumn col, char typedKey) {
if (isEditing()) {
stopEditing(true);
}
if (!_model.isEditable(row, col)) {
return;
}
clearSelection();
if (row != null && col != null) {
_editor = getCellEditor(row, col);
if (_editor != null) {
_editorControl = _editor.getEditorControl(this, row, col, typedKey);
if (_editorControl != null) {
Rectangle bounds = getCellBounds(row, col);
// TODO borderwidth
bounds.x += 1;
bounds.width -= 1;
bounds.y += 1;
if (_editor.getPreferredHeight() == -1 || _editor.getPreferredHeight() < bounds.height) {
bounds.height -= 1;
} else {
bounds.height = _editor.getPreferredHeight();
}
_editorControl.setBounds(bounds);
_editorControl.setVisible(true);
_editorControl.forceFocus();
}
_editorRow = row;
} else {
// System.out.println("no cell editor found!");
}
}
if (_editorControl == null) {
stopEditing(true);
}
}
/**
* Clear the selection.
*/
private void clearSelection() {
_selectionModel.clearSelection();
}
/**
* Stop editing if in progress.
*
* @param storeValue if true the value of the editor is stored.
*/
public void stopEditing(boolean storeValue) {
if (isEditing()) {
_editor.stopEditing(storeValue);
if (storeValue && (_tvs.getRowHeigthMode(_editorRow) == ITableViewState.RowHeightMode.OPTIMAL)
|| _tvs.getRowHeigthMode(_editorRow) == ITableViewState.RowHeightMode.OPTANDVAR) {
optimizeHeight(_editorRow);
}
_editorRow = null;
_editor = null;
}
}
/**
* Set the focussed cell.
*
* @param row row
* @param col column
*/
private void setFocus(IRow row, IColumn col) {
if (_focussedRow != row || _focussedColumn != col) {
IRow oldRow = _focussedRow;
IColumn oldCol = _focussedColumn;
_focussedRow = row;
_focussedColumn = col;
if (isCompleteVisible(_focussedRow, _focussedColumn)) {
redraw(_focussedRow, _focussedColumn);
if (oldRow != null && oldCol != null) {
redraw(oldRow, oldCol);
}
} else {
scrollToVisible(_focussedRow, _focussedColumn); // includes redrawing
}
fireTableFocusChanged(row, col);
}
}
/**
* Calculate the preferred height of a row. Only visibl columns are taken into account.
*
* @param gc Graphics context
* @param row row to calculate the height for
* @return preferred height or -1 if no preferred height can be determined
*/
private int getPreferredRowHeight(GC gc, IRow row) {
int result = -1;
for (IColumn column : _cols) {
if (_tvs.getColumnVisible(column)) {
ICellRenderer renderer = getCellRenderer(row, column);
ICellStyle cellStyle = _tvs.getCellStyle(row, column);
int ph = renderer.getPreferredHeight(gc, cellStyle, _tvs.getColumnWidth(column), row, column);
if (ph > result) {
result = ph;
}
}
}
return result;
}
/** list of rows that will be optimized before the next drawing using the gc at hand. */
protected Collection<IRow> _rowsToOptimize = Collections.synchronizedCollection(new HashSet<IRow>());
/**
* Register a row for height optimization in the next redrwa (redraw triggered by this method).
*
* @param row row to optimize height for
*/
public void optimizeHeight(IRow row) {
_rowsToOptimize.add(row);
syncedRedraw();
}
/**
* Remove a row from the list to optimize.
*
* @param row row to remove from the list
*/
private void doNotOptimizeHeight(IRow row) {
_rowsToOptimize.remove(row);
}
/**
* Register a list of rows for heigt optimization.
*
* @param rows list of rows to optimize
*/
public void optimizeHeight(List<IRow> rows) {
_rowsToOptimize.addAll(rows);
syncedRedraw();
}
/**
* Calculates and sets the row height for all rows waiting to be optimized.
*
* @param gc GC for calculation of the heights
*/
private void doRowHeightOptimization(GC gc) {
for (IRow row : _rowsToOptimize) {
int h = getPreferredRowHeight(gc, row);
if (h != -1) {
_tvs.setRowHeight(row, h);
}
}
_rowsToOptimize.clear();
}
/**
* Scroll the addressed cell so, that is it completely visible.
*
* @param row row of the cell
* @param column column of the cell
*/
public void scrollToVisible(IRow row, IColumn column) {
// first decide: above the visible area or below?
int rIdx = _rows.indexOf(row);
int cellY = getAbsBeginYForRowIdx(rIdx) - getFixedRowsHeight();
int shownY = getAbsBeginYForRowIdx(_firstRowIdx) + _firstRowPixelOffset - getFixedRowsHeight();
if (cellY < shownY) {
if (getVerticalBar() != null) {
getVerticalBar().setSelection(cellY);
}
} else {
int cellHeight = _tvs.getRowHeight(row);
if (getVerticalBar() != null) {
getVerticalBar().setSelection(cellY + cellHeight - _tableRect.height);
}
}
// handleVerticalScroll(null);
// now left/right
int cIdx = _cols.indexOf(column);
int cellX = getAbsBeginXForColIdx(cIdx) - getFixedColumnsWidth();
int shownX = getAbsBeginXForColIdx(_firstColIdx) - getFixedColumnsWidth();
if (cellX < shownX) {
if (getHorizontalBar() != null) {
getHorizontalBar().setSelection(cellX);
}
} else {
int cellWidth = _tvs.getColumnWidth(column);
if (getHorizontalBar() != null) {
getHorizontalBar().setSelection(cellX + cellWidth - _tableRect.width);
}
}
updateScrollBars();
redraw();
}
/**
* Return true, if the adressed cell is completely (i.e. not clipped) visible.
*
* @param row row of the cell
* @param column column of the cell
* @return true if the cell is completely visible
*/
private boolean isCompleteVisible(IRow row, IColumn column) {
RowInfo rInfo = getRowInfo(row);
if (rInfo == null) {
return false;
}
ColInfo cInfo = getColInfo(column);
if (cInfo == null) {
return false;
}
Rectangle b = getCellBounds(rInfo, cInfo);
if (!(_tableRect.contains(b.x, b.y) && _tableRect.contains(b.x + b.width, b.y + b.height))) {
if (_fixedColumns == 0 && _fixedRows == 0) {
return false;
} else {
// may be in a fixed area
if (_fixedColumns > 0 && _fixedColRect.contains(b.x, b.y)
&& _fixedColRect.contains(b.x + b.width, b.y + b.height)) {
return true;
}
if (_fixedRows > 0 && _fixedRowRect.contains(b.x, b.y)
&& _fixedRowRect.contains(b.x + b.width, b.y + b.height)) {
return true;
}
return false;
}
}
return true;
}
/**
* Check whether a row is currently displayed.
*
* @param row row to check
* @return true if the row is displayed.
*/
public boolean isDisplayed(IRow row) {
RowInfo rInfo = getRowInfo(row);
return rInfo != null;
}
/**
* Check whether a column is currently displayed.
*
* @param column column to check
* @return true if the column is displayed.
*/
public boolean isDisplayed(IColumn column) {
ColInfo cInfo = getColInfo(column);
return cInfo != null;
}
/**
* Retrieve row by y coordinate of the bottom border.
*
* @param y y coordinate
* @return a row identified by the bottom delimiter or <code>null</code>
*/
private IRow rowByBottomBorder(int y) {
for (RowInfo info : getRowInfos()) {
int by = info.y + info.height;
if (Math.abs(by - y) <= SELDELTA) {
return info.row;
}
}
return null;
}
/**
* Retrieve the row info for a row.
*
* @param row row to get the info for
* @return info or <code>null</code>
*/
protected RowInfo getRowInfo(IRow row) {
for (RowInfo info : getRowInfos()) {
if (info.row.equals(row)) {
return info;
}
}
return null;
}
/**
* Retrieve a column by its right border.
*
* @param x x coordinate
* @return the column or <code>null</code>
*/
private IColumn colByRightBorder(int x) {
if (_colInfoCache != null) {
for (ColInfo info : _colInfoCache) {
int bx = info.x + info.width;
if (Math.abs(bx - x) <= SELDELTA) {
return info.column;
}
}
}
return null;
}
/**
* Retrieve cached col info for a row.
*
* @param col column to get the info for
* @return colInfo or <code>null</code>
*/
private ColInfo getColInfo(IColumn col) {
if (_colInfoCache != null) {
for (ColInfo info : _colInfoCache) {
if (info.column.equals(col)) {
return info;
}
}
}
return null;
}
/**
* Get the bounding rectangle for a cell.
*
* @param row row of the cell
* @param column column of the cell
* @return the bounding rectangle or <code>null</code> if the cell is not visible
*/
private Rectangle getCellBounds(IRow row, IColumn column) {
RowInfo rInfo = getRowInfo(row);
ColInfo cInfo = getColInfo(column);
if (rInfo == null || cInfo == null) {
return null;
}
return getCellBounds(rInfo, cInfo);
}
/**
* Get the bounding rectangle for a cell.
*
* @param rInfo row info for the row
* @param cInfo column info for the row
* @return the bounding rectangle
*/
private Rectangle getCellBounds(RowInfo rInfo, ColInfo cInfo) {
return new Rectangle(cInfo.x, rInfo.y, cInfo.width, rInfo.height);
}
/**
* Retrieve the bounds for a cell.
*
* @param cell cell
* @return cell bounds or null if the cell is not displayed
*/
private Rectangle getCellBounds(IJaretTableCell cell) {
return getCellBounds(cell.getRow(), cell.getColumn());
}
/**
* Get the bounding rect for a row.
*
* @param row row
* @return bounding rect or <code>null</code> if the row is not visible
*/
private Rectangle getRowBounds(IRow row) {
RowInfo rInfo = getRowInfo(row);
return rInfo == null ? null : getRowBounds(rInfo);
}
/**
* Get bounding rect for a row by the rowinfo.
*
* @param info row info
* @return bounding rect
*/
private Rectangle getRowBounds(RowInfo info) {
int bx = _fixedColumns == 0 ? _tableRect.x : _fixedColRect.x;
int width = _fixedColumns == 0 ? _tableRect.width : _fixedColRect.width + _tableRect.width;
return new Rectangle(bx, info.y, width, info.height);
}
/**
* Get the bounding rect for a column.
*
* @param column column
* @return bounding rect or <code>null</code> if the column is not visible
*/
public Rectangle getColumnBounds(IColumn column) {
ColInfo cInfo = getColInfo(column);
return cInfo != null ? getColumnBounds(cInfo) : null;
}
/**
* Get the bounds for a column.
*
* @param info column info
* @return bounding rectangle
*/
private Rectangle getColumnBounds(ColInfo info) {
int by = _fixedRows == 0 ? _tableRect.y : _fixedRowRect.y;
int height = _fixedRows == 0 ? _tableRect.height : _fixedRowRect.height + _tableRect.height;
return new Rectangle(info.x, by, info.width, height);
}
/**
* Redraw a cell. Method can be called from any thread.
*
* @param row row of the cell
* @param column column of the cell
*/
private void redraw(IRow row, IColumn column) {
Rectangle r = getCellBounds(row, column);
if (r != null) {
syncedRedraw(r.x, r.y, r.width, r.height);
}
}
/**
* Redraw a row. Method can be called from any thread.
*
* @param row row to be painted
*/
private void redraw(IRow row) {
Rectangle r = getRowBounds(row);
if (r != null) {
syncedRedraw(r.x, r.y, r.width, r.height);
}
}
/**
* Redraw a column. Method can be called from any thread.
*
* @param column column to be repainted
*/
private void redraw(IColumn column) {
Rectangle r = getColumnBounds(column);
if (r != null) {
syncedRedraw(r.x, r.y, r.width, r.height);
}
}
/**
* Redraw a region. This method can be called from any thread.
*
* @param x x coordinate
* @param y y coordinate
* @param width width of the region
* @param height height of the region
*/
private void syncedRedraw(final int x, final int y, final int width, final int height) {
Runnable r = new Runnable() {
public void run() {
if (!isDisposed()) {
redraw(x, y, width, height, true);
}
}
};
Display.getCurrent().syncExec(r);
}
/**
* Redraw complete area. Safe to call from any thread.
*
*/
private void syncedRedraw() {
Runnable r = new Runnable() {
public void run() {
if (!isDisposed()) {
redraw();
}
}
};
Display.getCurrent().syncExec(r);
}
// / end redra methods
/**
* Update the scrollbars.
*/
protected void updateScrollBars() {
updateYScrollBar();
updateXScrollBar();
}
/**
* Update the horiontal scrollbar.
*/
private void updateXScrollBar() {
if (Display.getCurrent() != null) {
Display.getCurrent().syncExec(new Runnable() {
public void run() {
ScrollBar scroll = getHorizontalBar();
// scroll may be null
if (scroll != null) {
_oldHorizontalScroll = -1; // make sure no optimization will be applied
scroll.setMinimum(0);
scroll.setMaximum(getTotalWidth() - getFixedColumnsWidth());
scroll.setThumb(getWidth() - getFixedColumnsWidth());
scroll.setIncrement(50); // increment for arrows
scroll.setPageIncrement(getWidth()); // page increment areas
}
}
});
}
}
/** last horizontal scroll value for scroll optimization. */
private int _oldHorizontalScroll = -1;
/** last vertical scroll value for scroll optimization. */
private int _oldVerticalScroll = -1;
/** if true use optimized scrolling. */
private boolean _optimizeScrolling = true;
/**
* Handle a change of the horizontal scrollbar.
*
* @param event SelectionEvent
*/
private void handleHorizontalScroll(SelectionEvent event) {
int value = getHorizontalBar().getSelection() + getFixedColumnsWidth();
int colIdx = getColIdxForAbsX(value);
int offset = value - getAbsBeginXForColIdx(colIdx);
int diff = _oldHorizontalScroll - value;
if (Math.abs(diff) > _tableRect.width / 2 || _oldHorizontalScroll == -1 || !_optimizeScrolling) {
_firstColIdx = colIdx;
_firstColPixelOffset = offset;
redraw();
} else {
if (diff > 0) {
scroll(_tableRect.x + diff, 0, _tableRect.x, 0, _tableRect.width - diff, getHeight(), false);
} else {
diff = -diff;
scroll(_tableRect.x, 0, _tableRect.x + diff, 0, _tableRect.width - diff, getHeight(), false);
}
_firstColIdx = colIdx;
_firstColPixelOffset = offset;
}
_oldHorizontalScroll = value;
}
/**
* Update the vertical scrollbar if present.
*/
public void updateYScrollBar() {
if (Display.getCurrent() != null) {
Display.getCurrent().syncExec(new Runnable() {
public void run() {
ScrollBar scroll = getVerticalBar();
// scroll may be null
if (scroll != null) {
_oldVerticalScroll = -1; // guarantee a clean repaint
scroll.setMinimum(0);
scroll.setMaximum(getTotalHeight() - getFixedRowsHeight());
int height = getHeight();
if (_tableRect != null) {
height = _tableRect.height;
}
scroll.setThumb(height); // - getFixedRowsHeight() - getHeaderHeight());
scroll.setIncrement(50); // increment for arrows
scroll.setPageIncrement(getHeight()); // page increment areas
scroll.setSelection(getAbsBeginYForRowIdx(_firstRowIdx) + _firstRowPixelOffset
+ getFixedRowsHeight());
}
}
});
}
}
/**
* Handle a selection on the vertical scroll bar (a vertical scroll).
*
* @param event selection
*/
private void handleVerticalScroll(SelectionEvent event) {
int value = getVerticalBar().getSelection() + getFixedRowsHeight();
int rowidx = getRowIdxForAbsY(value);
int offset = value - getAbsBeginYForRowIdx(rowidx);
int oldFirstIdx = _firstRowIdx;
int oldPixelOffset = _firstRowPixelOffset;
int diff = _oldVerticalScroll - value;
if (Math.abs(diff) > _tableRect.height / 2 || _oldVerticalScroll == -1 || !_optimizeScrolling) {
update();
_firstRowIdx = rowidx;
_firstRowPixelOffset = offset;
_rowInfoCache = null; // kill the cache
redraw();
} else {
Rectangle completeArea = new Rectangle(_fixedColRect.x, _tableRect.y, _fixedColRect.width
+ _tableRect.width, _tableRect.height);
if (diff > 0) {
scroll(0, completeArea.y + diff, 0, completeArea.y, getWidth(), completeArea.height - diff, false);
} else {
diff = -diff;
scroll(0, completeArea.y, 0, completeArea.y + diff, getWidth(), completeArea.height - diff, false);
}
_firstRowIdx = rowidx;
_firstRowPixelOffset = offset;
_rowInfoCache = null; // kill the cache
}
_oldVerticalScroll = value;
firePropertyChange(PROPERTYNAME_FIRSTROWIDX, oldFirstIdx, _firstRowIdx);
firePropertyChange(PROPERTYNAME_FIRSTROWPIXELOFFSET, oldPixelOffset, _firstRowPixelOffset);
}
/**
* Get the absolute begin x for a column.
*
* @param colIdx index of the column (in the displayed columns)
* @return the absolute x coordinate
*/
public int getAbsBeginXForColIdx(int colIdx) {
int x = 0;
for (int idx = 0; idx < colIdx; idx++) {
IColumn col = _cols.get(idx);
int colWidth = _tvs.getColumnWidth(col);
x += colWidth;
}
return x;
}
/**
* Get the absolute begin x for a column.
*
* @param column the column
* @return the absolute x coordinate
*/
public int getAbsBeginXForColumn(IColumn column) {
return getAbsBeginXForColIdx(_cols.indexOf(column));
}
/**
* Retrieve the beginning x coordinate for a column.
*
* @param column column
* @return beginning x coordinate for drawing that column
*/
private int xForCol(IColumn column) {
int x = getAbsBeginXForColIdx(_cols.indexOf(column));
int begin = getAbsBeginXForColIdx(_firstColIdx) + _firstColPixelOffset;
return x - begin + _fixedColRect.width;
}
/**
* Return the (internal) index of the column corresponding to the given x coordinate value (absolute value taking
* all visible columns into account).
*
* @param absX absolute x coordinate
* @return the column index in the internal list of columns (or -1 if none could be determined)
*/
public int getColIdxForAbsX(int absX) {
int idx = 0;
int x = 0;
while (x <= absX && idx < _cols.size()) {
IColumn col = _cols.get(idx);
int colWidth = _tvs.getColumnWidth(col);
x += colWidth;
idx++;
}
return idx < _cols.size() ? idx - 1 : -1;
}
/**
* Return the column for an absolute x coordinate.
*
* @param absX absolute x coordinate
* @return the column for the coordinate
*/
public IColumn getColumnForAbsX(int absX) {
return _cols.get(getColIdxForAbsX(absX));
}
/**
* Return the absolute y coordinate for the given row (given by index).
*
* @param rowidx index of the row
* @return absolute y coordinate (of all rows) for the row
*/
private int getAbsBeginYForRowIdx(int rowidx) {
int y = 0;
for (int idx = 0; idx < rowidx; idx++) {
IRow row = _rows.get(idx);
int rowHeight = _tvs.getRowHeight(row);
y += rowHeight;
}
return y;
}
/**
* Get row index for an absolute y coordinate (thought on the full height table with all rows).
*
* @TODO optimize
* @param absY absolute y position (thought on the full table height)
* @return index of the corresponding row
*/
public int getRowIdxForAbsY(int absY) {
int idx = 0;
int y = 0;
while (y <= absY) {
IRow row = _rows.get(idx);
int rowHeight = _tvs.getRowHeight(row);
y += rowHeight;
idx++;
}
return idx - 1;
}
/**
* Retrie internal index of gicen row.
*
* @param row row
* @return internal index or -1 if the row is not in the internal list
*/
private int getRowIdx(IRow row) {
return row != null ? _rows.indexOf(row) : -1;
}
/**
* Retrieve the row corresponding to a specified y coordinate.
*
* @param y y
* @return row for that y ycoordinate or <code>null</code> if no row could be determined.
*/
public IRow rowForY(int y) {
if ((y < _tableRect.y || y > _tableRect.y + _tableRect.height) && _fixedRows == 0) {
return null;
}
for (RowInfo rInfo : getRowInfos()) {
if (y >= rInfo.y && y < rInfo.y + rInfo.height) {
return rInfo.row;
}
}
return null;
}
/**
* Retrive the list of currently availbale RowInfo etries.
*
* @return list of rowinfos
*/
private List<RowInfo> getRowInfos() {
if (_rowInfoCache == null) {
fillRowInfoCache();
}
return _rowInfoCache;
}
/**
* Fill the cache of row infos for the current viewconfiguration.
*/
private void fillRowInfoCache() {
if (_rowInfoCache != null) {
return;
}
_rowInfoCache = new ArrayList<RowInfo>();
// fixed row area
int y = 0;
if (_fixedRows > 0) {
y = _fixedRowRect.y;
for (int rIdx = 0; rIdx < _fixedRows; rIdx++) {
IRow row = _rows.get(rIdx);
int rHeight = _tvs.getRowHeight(row);
_rowInfoCache.add(new RowInfo(row, y, rHeight, true));
y += rHeight;
}
}
// normal table area
int rIdx = _firstRowIdx;
y = _tableRect.y - _firstRowPixelOffset;
while (y < getHeight() && rIdx < _rows.size()) {
IRow row = _rows.get(rIdx);
int rHeight = _tvs.getRowHeight(row);
_rowInfoCache.add(new RowInfo(row, y, rHeight, false));
y += rHeight;
rIdx++;
}
}
/**
* Retrieve a row from the internal list of rows.
*
* @param idx index in the internal list
* @return the row for idx
*/
private IRow rowForIdx(int idx) {
return _rows.get(idx);
}
/**
* Retrieve the column corresponding to a x coordinate.
*
* @param x x
* @return the corresponding column or <code>null</code> if none could be determined
*/
public IColumn colForX(int x) {
if ((x < _tableRect.x || x > _tableRect.x + _tableRect.width) && _fixedColumns == 0) {
return null;
}
for (ColInfo cInfo : _colInfoCache) {
if (x >= cInfo.x && x < cInfo.x + cInfo.width) {
return cInfo.column;
}
}
return null;
}
/**
* Get the column for a given index.
*
* @param idx index
* @return tghe column
*/
private IColumn colForIdx(int idx) {
return _cols.get(idx);
}
/**
* Get the index of a given column.
*
* @param column column
* @return the index of the column or -1 if no index could be given
*/
private int getColumnIdx(IColumn column) {
return column != null ? _cols.indexOf(column) : -1;
}
/**
* Retrieve TableXCell for given pixel coordinates.
*
* @param x pixel coordinate x
* @param y pixel coordinate y
* @return table cel if found or <code>null</code> if no cell can be found
*/
public IJaretTableCell getCell(int x, int y) {
if (_tableRect.contains(x, y)) {
IRow row = rowForY(y);
IColumn col = colForX(x);
if (row == null || col == null) {
return null;
}
return new JaretTableCellImpl(row, col);
}
return null;
}
/**
* Retrieve a table cell for given index coordinates.
*
* @param colIdx column index (X)
* @param rowIdx row index (Y)
* @return table cell
*/
public IJaretTableCell getCellForIdx(int colIdx, int rowIdx) {
return new JaretTableCellImpl(rowForIdx(rowIdx), colForIdx(colIdx));
}
/**
* Set a table model to be displayed by the jaret table.
*
* @param model the table model to be displayed.
*/
public void setTableModel(IJaretTableModel model) {
if (_model != null) {
_model.removeJaretTableModelListener(this);
}
_model = model;
_model.addJaretTableModelListener(this);
_hierarchicalModel = null;
// update the sorted columnlist
List<IColumn> cList = new ArrayList<IColumn>();
for (int i = 0; i < model.getColumnCount(); i++) {
cList.add(model.getColumn(i));
}
_tvs.setSortedColumns(cList);
updateColumnList();
registerRowsForOptimization();
updateRowList();
updateYScrollBar();
updateXScrollBar();
redraw();
}
/**
* Set a hierarchical table model. This will internally create a StdHierrahicalTableModel that is a normal
* TbaleModel incluuding only the expanded rows.
*
* @param hmodel hierarchical model to display
*/
public void setTableModel(IHierarchicalJaretTableModel hmodel) {
if (_model != null) {
_model.removeJaretTableModelListener(this);
}
if (_tvs != null) {
_tvs.removeTableViewStateListener(this);
}
_tvs = new DefaultHierarchicalTableViewState();
_tvs.addTableViewStateListener(this);
_model = new StdHierarchicalTableModel(hmodel, (IHierarchicalTableViewState) _tvs);
_model.addJaretTableModelListener(this);
_hierarchicalModel = hmodel;
updateColumnList();
registerRowsForOptimization();
updateRowList();
updateColumnList();
updateYScrollBar();
updateXScrollBar();
redraw();
}
/**
* Retrieve a hierarchical model if set.
*
* @return hierarchical model or <code>null</code>
*/
public IHierarchicalJaretTableModel getHierarchicalModel() {
return _hierarchicalModel;
}
/**
* Retrieve the displayed table model.
*
* @return the table model
*/
public IJaretTableModel getTableModel() {
return _model;
}
/**
* Add a column to the underlying table model. Model has to be set for that operation or an IllegalStateException
* will be thrown.
*
* @param column column to be added
*/
public void addColumn(IColumn column) {
if (_model != null) {
_model.addColumn(column);
} else {
throw new IllegalStateException("model has to be set for the operation.");
}
}
/**
* Registers all rows in the model for optimization that have a mode indicating optimal height.
*
*/
private void registerRowsForOptimization() {
if (_model != null) {
for (int i = 0; i < _model.getRowCount(); i++) {
IRow row = _model.getRow(i);
if (_tvs.getRowHeigthMode(row) == ITableViewState.RowHeightMode.OPTANDVAR
|| _tvs.getRowHeigthMode(row) == ITableViewState.RowHeightMode.OPTIMAL) {
optimizeHeight(row);
}
}
}
}
/**
* Update the internal rowlist according to filter and sorter.
*
*/
private void updateRowList() {
_rows = new ArrayList<IRow>();
if (_model != null) {
for (int i = 0; i < _model.getRowCount(); i++) {
IRow row = _model.getRow(i);
if (i < _fixedRows) {
// fixed rows are exluded from filtering
_rows.add(row);
} else if (_rowFilter == null || (_rowFilter != null && _rowFilter.isInResult(row))) {
if (!_autoFilterEnabled || _autoFilter.isInResult(row)) {
if (!_rows.contains(row)) {
_rows.add(row);
}
}
}
}
}
// sort either by column sort order or by a set row sorter
RowComparator comparator = new RowComparator();
IRowSorter rs = null;
if (comparator.canSort()) {
rs = comparator;
} else {
rs = _rowSorter;
}
if (rs != null) {
List<IRow> fixedRows = new ArrayList<IRow>();
// the exclusion of the fixed rows may be solved more elegant ...
if (_excludeFixedRowsFromSorting) {
for (int i = 0; i < _fixedRows; i++) {
fixedRows.add(_rows.remove(0));
}
}
Collections.sort(_rows, rs);
if (_excludeFixedRowsFromSorting) {
for (int i = fixedRows.size() - 1; i >= 0; i--) {
_rows.add(0, fixedRows.get(i));
}
}
}
// to be sure no one misses this
updateYScrollBar();
}
/**
* Get the index of the given row in the internal, fileterd list of rows.
*
* @param row row to retrieve the index for
* @return index of the row or -1 if the row is not in filtered list of rows
*/
public int getInternalRowIndex(IRow row) {
return _rows.indexOf(row);
}
/**
* Comparator based on the sorting settings of the columns.
*
* @author Peter Kliem
* @version $Id: JaretTable.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class RowComparator extends PropertyObservableBase implements IRowSorter {
/** arary of Row comparators (IColumns are Comparators for rows!). */
private List<Comparator<IRow>> _comparators = new ArrayList<Comparator<IRow>>();
/**
* Construct it. Initializes itself with the columns.
*/
public RowComparator() {
IColumn[] arr = new IColumn[_cols.size()];
int max = 0;
for (IColumn col : _cols) {
int sortP = _tvs.getColumnSortingPosition(col);
if (sortP > 0) {
arr[sortP] = col;
if (sortP > max) {
max = sortP;
}
}
}
for (int i = 1; i <= max; i++) {
_comparators.add(arr[i]);
}
}
/**
* Check whether the comparator is able to sort.
*
* @return true if comparators are present
*/
public boolean canSort() {
return _comparators.size() > 0;
}
/**
* {@inheritDoc}
*/
public int compare(IRow r1, IRow r2) {
for (Comparator<IRow> comp : _comparators) {
int res = comp.compare(r1, r2);
res = _tvs.getColumnSortingDirection((IColumn) comp) ? res : -res;
if (res != 0) {
return res;
}
}
return 0;
}
}
/**
* Update the internal column list. Should be called whenever a column changes visibility or the column order has
* been changed.
*
*/
public void updateColumnList() {
_cols = new ArrayList<IColumn>();
// these are columns to take into account
for (int i = 0; i < _model.getColumnCount(); i++) {
if (i < _tvs.getSortedColumns().size()) {
IColumn col = _tvs.getSortedColumns().get(i);
if (_tvs.getColumnVisible(col)) {
_cols.add(col);
}
}
}
// if not all columns have been in the sorted columns - add the other columns
for (int i = 0; i < _model.getColumnCount(); i++) {
IColumn col = _model.getColumn(i);
if (!_cols.contains(col) && _tvs.getColumnVisible(col)) {
_cols.add(col);
}
}
}
/**
* Handling of the paint event -> do the painting.
*
* @param event PaintEvent
*/
private void onPaint(PaintEvent event) {
if (event.width == 0 || event.height == 0) {
return;
}
// System.out.println("Paint event "+event);
long time = System.currentTimeMillis();
// kill the cache
_rowInfoCache = null;
GC gc = event.gc; // gc for painting
// do rowheight optimizations for registered rows
doRowHeightOptimization(gc);
// do the actual painting
paint(gc, getWidth(), getHeight());
if (DEBUGPAINTTIME) {
System.out.println("time " + (System.currentTimeMillis() - time) + " ms");
}
}
/**
* Calculate the layout of the table area rectangles.
*
* @param width width of the table
* @param height height of the table
*/
private void preparePaint(int width, int height) {
if (_drawHeader) {
_headerRect = new Rectangle(0, 0, width, _headerHeight);
} else {
_headerRect = new Rectangle(0, 0, 0, 0);
}
if (_autoFilterEnabled) {
// preferred height of the autofilters
int autoFilterHeight = getPreferredAutoFilterHeight();
_autoFilterRect = new Rectangle(0, _headerRect.y + _headerRect.height, _headerRect.width, autoFilterHeight);
_tableRect = new Rectangle(0, _autoFilterRect.y + _autoFilterRect.height, width, height
- _autoFilterRect.height);
} else {
_tableRect = new Rectangle(0, _headerRect.y + _headerRect.height, width, height - _headerRect.height);
}
// do we have fixed cols? correct other rects and calc fixed col rect
if (_fixedColumns > 0) {
int fWidth = getFixedColumnsWidth();
_headerRect.x = _headerRect.x + fWidth;
_headerRect.width = _headerRect.width - fWidth;
if (_autoFilterEnabled) {
_autoFilterRect.x = _headerRect.x;
_autoFilterRect.width = _headerRect.width;
}
_tableRect.x = _headerRect.x;
_tableRect.width = _headerRect.width;
_fixedColRect = new Rectangle(0, _tableRect.y, fWidth, _tableRect.height);
} else {
_fixedColRect = new Rectangle(_tableRect.x, _tableRect.y, 0, _tableRect.height);
}
// do we have fixed rows? correct other rects nd setup the fixed row rect
if (_fixedRows > 0) {
int fHeight = getFixedRowsHeight();
if (_autoFilterEnabled) {
_fixedRowRect = new Rectangle(0, _autoFilterRect.y + _autoFilterRect.height, width,
getFixedRowsHeight());
} else {
_fixedRowRect = new Rectangle(0, _headerRect.y + _headerRect.height, width, getFixedRowsHeight());
}
_tableRect.y = _tableRect.y + fHeight;
_tableRect.height = _tableRect.height - fHeight;
if (_fixedColumns > 0) {
_fixedColRect.y = _tableRect.y;
_fixedColRect.height = _tableRect.height;
}
} else {
// ensure fixed Row rect is available
_fixedRowRect = new Rectangle(_tableRect.x, _tableRect.y, _tableRect.width, 0);
}
}
/**
* Retrieve the maximum preferred height of the autofilter controls.
*
* @return preferred height for the autofilters
*/
private int getPreferredAutoFilterHeight() {
int result = 0;
for (IAutoFilter af : _autoFilterMap.values()) {
int height = af.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
if (height > result) {
result = height;
}
}
return result;
}
/**
* The main paint method.
*
* @param gc GC
* @param width width of the control
* @param height height of the control
*/
public void paint(GC gc, int width, int height) {
preparePaint(width, height);
// clear bg
Color bg = gc.getBackground();
gc.setBackground(getBackground());
gc.fillRectangle(gc.getClipping());
gc.setBackground(bg);
drawHeader(gc, width, height);
drawTableArea(gc, width, height);
// set the bounds for the output filters
setUpAutoFilter(gc);
// additional rendering
if (_isFillDrag) {
drawFillDragBorder(gc);
}
}
/**
* Setup the autofilter components.
*
* @param gc GC
*/
private void setUpAutoFilter(GC gc) {
if (_autoFilterEnabled) {
for (IColumn column : _cols) {
IAutoFilter af = _autoFilterMap.get(column);
ColInfo cInfo = getColInfo(column);
if (af != null && cInfo == null) {
af.getControl().setVisible(false);
} else {
if (af != null) {
af.getControl().setVisible(true);
af.getControl().setBounds(cInfo.x, _autoFilterRect.y, cInfo.width, _autoFilterRect.height);
}
}
}
} else {
for (IColumn column : _cols) {
IAutoFilter af = _autoFilterMap.get(column);
if (af != null) {
af.getControl().setVisible(false);
}
}
}
}
/**
* Draw the table header.
*
* @param gc gc
* @param width width of the table
* @param height height of the table
*/
private void drawHeader(GC gc, int width, int height) {
if (_headerRenderer != null && _drawHeader) {
// draw headers for fixed columns
for (int cIdx = 0; cIdx < _fixedColumns; cIdx++) {
int x = getAbsBeginXForColIdx(cIdx);
IColumn col = _cols.get(cIdx);
int colwidth = _tvs.getColumnWidth(col);
// fixed cols may render wherever they want if they disable clipping
if (!_headerRenderer.disableClipping()) {
gc.setClipping(x, _headerRect.y, colwidth, _headerRect.height);
}
// column may indicate that no header should be painted
if (col.displayHeader()) {
drawHeader(gc, x, colwidth, col);
}
}
// draw headers table area
int x = -_firstColPixelOffset;
x += _tableRect.x;
int cIdx = _firstColIdx;
while (x < getWidth() && cIdx < _cols.size()) {
IColumn col = _cols.get(cIdx);
int colwidth = _tvs.getColumnWidth(col);
int xx = x > _headerRect.x ? x : _headerRect.x;
int clipWidth = x > _headerRect.x ? colwidth : colwidth - _firstColPixelOffset;
if (!_headerRenderer.disableClipping()) {
gc.setClipping(xx, _headerRect.y, clipWidth, _headerRect.height);
} else if (_fixedColumns > 0) {
// if fixed columns are present the header renderer of ordinary columns may not interfere with the
// fixed region
gc.setClipping(xx, _headerRect.y, _tableRect.width - xx, _headerRect.height);
}
// column may indicate that no header should be painted
if (col.displayHeader()) {
drawHeader(gc, x, colwidth, col);
}
x += colwidth;
cIdx++;
}
}
}
/**
* Render the header for one column.
*
* @param gc gc
* @param x starting x
* @param colwidth width
* @param col column
*/
private void drawHeader(GC gc, int x, int colwidth, IColumn col) {
Rectangle area = new Rectangle(x, _headerRect.y, colwidth, _headerRect.height);
int sortingPos = _tvs.getColumnSortingPosition(col);
boolean sortingDir = _tvs.getColumnSortingDirection(col);
_headerRenderer.draw(gc, area, col, sortingPos, sortingDir, false);
}
/**
* Convenience method to check whether a certain cell is selected.
*
* @param row row of the cell
* @param column column of the cell
* @return true if the cell is selected (by itself, a row of a column selection)
*/
public boolean isSelected(IRow row, IColumn column) {
if (_selectionModel.getSelection().getSelectedRows().contains(row)) {
return true;
}
if (_selectionModel.getSelection().getSelectedColumns().contains(column)) {
return true;
}
IJaretTableCell cell = new JaretTableCellImpl(row, column);
if (_selectionModel.getSelection().getSelectedCells().contains(cell)) {
return true;
}
return false;
}
/**
* Draw the main table area including fixed rows and columns.
*
* @param gc gc
* @param width width of the area
* @param height height of the area
*/
private void drawTableArea(GC gc, int width, int height) {
_colInfoCache.clear();
boolean colCacheFilled = false;
Rectangle clipSave = gc.getClipping();
// iterate over all rows in the row info cache
for (RowInfo rowInfo : getRowInfos()) {
int y = rowInfo.y;
IRow row = rowInfo.row;
int rHeight = _tvs.getRowHeight(row);
int yclip = y;
if (rowInfo.fixed && yclip < _fixedRowRect.y) {
yclip = _fixedRowRect.y;
} else if (!rowInfo.fixed && yclip < _tableRect.y) {
yclip = _tableRect.y;
}
int x = 0;
// fixed columns
if (_fixedColumns > 0) {
x = _fixedColRect.x;
for (int cIdx = 0; cIdx < _fixedColumns; cIdx++) {
IColumn col = _cols.get(cIdx);
int colwidth = _tvs.getColumnWidth(col);
if (!colCacheFilled) {
_colInfoCache.add(new ColInfo(col, x, colwidth));
}
// clipping is extended by 1 for border drawing
gc.setClipping(x, yclip, colwidth + 1, rHeight + 1);
Rectangle area = new Rectangle(x, y, colwidth, rHeight);
drawCell(gc, area, row, col);
x += colwidth;
}
}
// columns in normal table area
x = _tableRect.x - _firstColPixelOffset;
int cIdx = _firstColIdx;
while (x < getWidth() && cIdx < _cols.size()) {
IColumn col = _cols.get(cIdx);
int colwidth = _tvs.getColumnWidth(col);
if (!colCacheFilled) {
_colInfoCache.add(new ColInfo(col, x, colwidth));
}
int xx = x > _tableRect.x ? x : _tableRect.x;
int clipWidth = x > _tableRect.x ? colwidth : colwidth - _firstColPixelOffset;
// clipping is extended by 1 for border drawing
gc.setClipping(xx, yclip, clipWidth + 1, rHeight + 1);
Rectangle area = new Rectangle(x, y, colwidth, rHeight);
drawCell(gc, area, row, col);
x += colwidth;
cIdx++;
}
colCacheFilled = true;
}
// TODO this is a workaround for the autofilter to be rendered correctly if the
// filter result is no rows
if (!colCacheFilled) {
// fixed cols
int x = 0;
if (_fixedColumns > 0) {
for (int i = 0; i < _fixedColumns; i++) {
IColumn col = _cols.get(i);
int colwidth = _tvs.getColumnWidth(col);
_colInfoCache.add(new ColInfo(col, x, colwidth));
x += colwidth;
}
}
x = -_firstColPixelOffset;
x += _tableRect.x;
int cIdx = _firstColIdx;
while (x < getWidth() && cIdx < _cols.size()) {
IColumn col = _cols.get(cIdx);
int colwidth = _tvs.getColumnWidth(col);
_colInfoCache.add(new ColInfo(col, x, colwidth));
x += colwidth;
cIdx++;
}
}
// draw extra lines to separate fixed areas
if (_fixedColRect != null && _fixedColumns > 0) {
int maxY = _fixedColRect.y + _fixedColRect.height - 1;
if (_rows != null && _rows.size() > 0) {
IRow lastRow = _rows.get(_rows.size() - 1);
Rectangle bounds = getRowBounds(lastRow);
if (bounds != null) {
maxY = bounds.y + bounds.height;
}
}
gc.setClipping(new Rectangle(0, 0, width, height));
int fx = _fixedColRect.x + _fixedColRect.width - 1;
gc.drawLine(fx, _fixedRowRect.y, fx, maxY);
gc.setClipping(clipSave);
}
if (_fixedRowRect != null && _fixedRows > 0) {
int maxX = _fixedRowRect.x + _fixedRowRect.width - 1;
if (_cols != null && _cols.size() > 0) {
IColumn lastCol = _cols.get(_cols.size() - 1);
int mx = xForCol(lastCol) + _tvs.getColumnWidth(lastCol);
maxX = mx;
}
gc.setClipping(new Rectangle(0, 0, width, height));
int fy = _fixedRowRect.y + _fixedRowRect.height - 1;
gc.drawLine(_fixedRowRect.x, fy, maxX, fy);
gc.setClipping(clipSave);
}
}
/**
* Draw a single cell. Drawing is accomplished by the associated cell renderer. However the mark for fill dragging
* is drawn by this method.
*
* @param gc gc
* @param area drawing area the cell takes up
* @param row row of the cell
* @param col olumn of the cell
*/
private void drawCell(GC gc, Rectangle area, IRow row, IColumn col) {
ICellStyle bc = _tvs.getCellStyle(row, col);
ICellRenderer cellRenderer = getCellRenderer(row, col);
boolean hasFocus = false;
if (_focussedRow == row && _focussedColumn == col) { // == is appropriate: these are really the same objects!
hasFocus = true;
}
boolean isSelected = isSelected(row, col);
cellRenderer.draw(gc, this, bc, area, row, col, hasFocus, isSelected, false);
if (_supportFillDragging && isSelected && isDragMarkerCell(row, col)) {
drawFillDragMark(gc, area);
}
}
/** if a rectangular area is selected, this holds the rectangle ofth eindizes. */
private Rectangle _selectedIdxRectangle = null;
/**
* Retrieve the index rectangle of selected cells.
*
* @return rectangel made from the indizes of the selected cells if a rectangular area is selected (all cells)
*/
private Rectangle getSelectedRectangle() {
IJaretTableSelection selection = getSelectionModel().getSelection();
if (!selection.isEmpty() && _selectedIdxRectangle == null) {
Set<IJaretTableCell> cells = selection.getAllSelectedCells(getTableModel());
int minx = -1;
int maxx = -1;
int miny = -1;
int maxy = -1;
// line is the outer map
Map<Integer, Map<Integer, IJaretTableCell>> cellMap = new HashMap<Integer, Map<Integer, IJaretTableCell>>();
for (IJaretTableCell cell : cells) {
Point p = getCellDisplayIdx(cell);
Map<Integer, IJaretTableCell> lineMap = cellMap.get(p.y);
if (lineMap == null) {
lineMap = new HashMap<Integer, IJaretTableCell>();
cellMap.put(p.y, lineMap);
}
if (miny == -1 || p.y < miny) {
miny = p.y;
}
if (maxy == -1 || p.y > maxy) {
maxy = p.y;
}
lineMap.put(p.x, cell);
if (minx == -1 || p.x < minx) {
minx = p.x;
}
if (maxx == -1 || p.x > maxx) {
maxx = p.x;
}
}
// check if all cells are selected
boolean everythingSelected = true;
for (int y = miny; y <= maxy && everythingSelected; y++) {
Map<Integer, IJaretTableCell> lineMap = cellMap.get(y);
if (lineMap != null) {
for (int x = minx; x <= maxx; x++) {
IJaretTableCell cell = lineMap.get(x);
if (cell == null) {
everythingSelected = false;
break;
}
}
} else {
everythingSelected = false;
break;
}
}
if (everythingSelected) {
_selectedIdxRectangle = new Rectangle(minx, miny, maxx - minx + 1, maxy - miny + 1);
} else {
_selectedIdxRectangle = null;
}
}
return _selectedIdxRectangle;
}
/**
* Check whether a cell is the cell that should currently be marked with the drag fill marker.
*
* @param row row of the cell
* @param col column of the cell
* @return true if it is the cell carrying the drag mark
*/
private boolean isDragMarkerCell(IRow row, IColumn col) {
Rectangle selIdxRect = getSelectedRectangle();
if (selIdxRect != null) {
if (selIdxRect.width == 1 || selIdxRect.height == 1) {
int x = getColumnIdx(col);
int y = getRowIdx(row);
if (x == selIdxRect.x + selIdxRect.width - 1 && y == selIdxRect.y + selIdxRect.height - 1) {
return true;
}
}
}
return false;
}
/**
* Draws the fill drag mark.
*
* @param gc GC
* @param area drawing area of the cell carrying the marker
*/
private void drawFillDragMark(GC gc, Rectangle area) {
Color bg = gc.getBackground();
gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
_dragMarkerRect = new Rectangle(area.x + area.width - FILLDRAGMARKSIZE,
area.y + area.height - FILLDRAGMARKSIZE, FILLDRAGMARKSIZE, FILLDRAGMARKSIZE);
gc.fillRectangle(_dragMarkerRect);
gc.setBackground(bg);
}
/**
* Draws a thicker border around the fill drag area.
*
* @param gc GC
*/
private void drawFillDragBorder(GC gc) {
// TODO
// if (_firstCellSelectX != -1) {
// IRow row = rowForIdx(_firstCellSelectX);
// IColumn column = colForIdx(_firstCellSelectY);
// Rectangle firstCellBounds = getCellBounds(row, column);
// if (firstCellBounds == null) {
// firstCellBounds = new Rectangle(-1, -1, -1, -1);
// if (getRowBounds(row) != null) {
// firstCellBounds = getRowBounds(row);
// } else if (getColumnBounds(column)!=null) {
// firstCellBounds = getColumnBounds(column);
// } else
// }
// }
}
/**
* Set the header drawing height.
*
* @param newHeight height in pixel.
*/
public void setHeaderHeight(int newHeight) {
if (newHeight != _headerHeight) {
int oldVal = _headerHeight;
_headerHeight = newHeight;
redraw();
firePropertyChange(PROPERTYNAME_HEADERHEIGHT, oldVal, _headerHeight);
}
}
/**
* Retrieve the header height.
*
* @return header height (pixel)
*/
public int getHeaderHeight() {
return _headerHeight;
}
/**
* Total height of all possibly displayed rows (filter applied!).
*
* @return sum of all rowheigths
*/
public int getTotalHeight() {
if (_rows != null) {
int h = 0;
for (IRow row : _rows) {
h += _tvs.getRowHeight(row);
}
return h;
} else {
return 0;
}
}
/**
* Total height of the first n rows.
*
* @param numRows number of rows to sum up the heights of
* @return sum of the first first n rowheights
*/
public int getTotalHeight(int numRows) {
if (_rows != null) {
int h = 0;
for (int i = 0; i < numRows; i++) {
IRow row = _rows.get(i);
h += _tvs.getRowHeight(row);
}
return h;
} else {
return 0;
}
}
/**
* Retrieve total width of all possibly displayed columns.
*
* @return sum of colwidhts
*/
public int getTotalWidth() {
if (_cols != null) {
int width = 0;
for (IColumn col : _cols) {
width += _tvs.getColumnWidth(col);
}
return width;
} else {
return 0;
}
}
/**
* Retrieve total width of the first n columns.
*
* @param n number of colums to take into account
* @return sum of the first n column withs
*/
public int getTotalWidth(int n) {
if (_cols != null) {
int width = 0;
for (int i = 0; i < n; i++) {
IColumn col = _cols.get(i);
width += _tvs.getColumnWidth(col);
}
return width;
} else {
return 0;
}
}
/**
* Calculate the width of all fixed columns.
*
* @return the sum of the individual widths of the fixed columns
*/
private int getFixedColumnsWidth() {
int w = 0;
for (int i = 0; i < _fixedColumns; i++) {
w += _tvs.getColumnWidth(_cols.get(i));
}
return w;
}
/**
* Calculate the height of all fixed rows.
*
* @return sum of the individual heights of the fixed rows
*/
private int getFixedRowsHeight() {
int h = 0;
for (int i = 0; i < _fixedRows; i++) {
h += _tvs.getRowHeight(_rows.get(i));
}
return h;
}
/**
* Retrieve the width of the control.
*
* @return width in pixel
*/
public int getWidth() {
return getClientArea().width;
}
/**
* Retrieve the height of the control.
*
* @return height in pixel
*/
public int getHeight() {
return getClientArea().height;
}
/**
* Retrieve the table viewstate.
*
* @return the tvs.
*/
public ITableViewState getTableViewState() {
return _tvs;
}
/**
* Set a TableViewState.
*
* @param tvs The tvs to set.
*/
public void setTableViewState(ITableViewState tvs) {
if (_tvs != null) {
_tvs.removeTableViewStateListener(this);
}
_tvs = tvs;
_tvs.addTableViewStateListener(this);
}
// ///////// TableViewStateListener
/**
* {@inheritDoc}
*/
public void rowHeightChanged(IRow row, int newHeight) {
Rectangle r = getRowBounds(row);
if (r != null) {
int height = getHeight() - r.y;
redraw(r.x, r.y, r.width, height, true);
_rowInfoCache = null;
}
updateYScrollBar();
}
/**
* {@inheritDoc}
*/
public void rowHeightModeChanged(IRow row, RowHeightMode newHeightMode) {
if (isDisplayed(row)) {
if (newHeightMode == RowHeightMode.OPTANDVAR || newHeightMode == RowHeightMode.OPTIMAL) {
optimizeHeight(row);
}
redraw();
}
// tweak: if the default height mode qualifies the row for height optimization it will be optimized since it is
// registered
// so it has to be removed if the mode changes before drawing
if (newHeightMode != RowHeightMode.OPTANDVAR && newHeightMode != RowHeightMode.OPTIMAL) {
doNotOptimizeHeight(row);
}
}
/**
* {@inheritDoc}
*/
public void columnWidthChanged(IColumn column, int newWidth) {
registerRowsForOptimization(); // row heights may change for opt/optvar
Rectangle r = getColumnBounds(column);
if (_headerRect != null) {
int y = _drawHeader ? _headerRect.y : r.y;
int width = getWidth() - r.x;
int height = _drawHeader ? _headerRect.height + r.height : r.height;
if (_autoFilterEnabled) {
height += _autoFilterRect.height;
}
redraw(r.x, y, width, height, true);
}
updateXScrollBar();
}
/**
* {@inheritDoc}
*/
public void columnWidthsChanged() {
registerRowsForOptimization(); // row heights may change for opt/optvar
redraw();
updateXScrollBar();
}
// private boolean isColumnResizePossible(IColumn column, int oldWidth, int newWidth) {
// if (_tvs.getColumnResizeMode() == TableViewState.ColumnResizeMode.NONE) {
// return true;
// }
// int delta = newWidth - oldWidth;
// if (_tvs.getColumnResizeMode() == TableViewState.ColumnResizeMode.SUBSEQUENT) {
// int idx = _cols.indexOf(column);
// if (idx > _cols.size()-1) {
// return false;
// }
// IColumn subsequent = _cols.get(idx+1);
// if (_tvs.getColumnWidth(subsequent) - delta > _tvs.getMinimalColWidth()) {
// return true;
// }
// return false;
// }
// return false;
// }
/**
* {@inheritDoc}
*/
public void columnVisibilityChanged(IColumn column, boolean visible) {
updateColumnList();
updateXScrollBar();
redraw();
}
/**
* {@inheritDoc}
*/
public void sortingChanged() {
updateRowList();
redraw();
// fire the general sorting change
firePropertyChange(PROPERTYNAME_SORTING, null, "x");
}
/**
* {@inheritDoc}
*/
public void columnOrderChanged() {
updateColumnList();
redraw();
}
/**
* {@inheritDoc}
*/
public void cellStyleChanged(IRow row, IColumn column, ICellStyle style) {
if (column == null) {
redraw(row);
} else if (row == null) {
redraw(column);
} else {
redraw(row, column);
}
}
// //// End tableviewstatelistener
/**
* Set the enabled state for the autofilter.
*
* @param enable true for enabling the autofilter
*/
public void setAutoFilterEnable(boolean enable) {
if (_autoFilterEnabled != enable) {
_autoFilterEnabled = enable;
if (enable) {
updateAutoFilter();
}
redraw();
updateYScrollBar();
preparePaint(getWidth(), getHeight());
firePropertyChange(PROPERTYNAME_AUTOFILTERENABLE, !enable, enable);
}
}
/**
* Retrieve the autofilter state.
*
* @return true for anabled autofilter
*/
public boolean getAutoFilterEnable() {
return _autoFilterEnabled;
}
/**
* Create and/or update autofilters.
*
*/
private void updateAutoFilter() {
if (_autoFilterEnabled) {
// check combining autofilter
if (_autoFilter == null) {
_autoFilter = new AutoFilter(this);
}
// create autofilter instances and controls if necessary
for (IColumn column : _cols) {
if (_autoFilterMap.get(column) == null) {
IAutoFilter af = createAutoFilter(column);
if (af != null) {
af.addPropertyChangeListener(_autoFilter);
_autoFilterMap.put(column, af);
}
}
}
// update the filters and register them with the combining internal autofilter row filter
for (IColumn column : _cols) {
IAutoFilter af = _autoFilterMap.get(column);
if (af != null) { // might be null in case of errors
af.update();
}
}
}
}
/**
* Instantiate an autofilter instance for the given column.
*
* @param column column
* @return instantiated autofilter or <code>null</code> if any error occurs during instantiation
*/
private IAutoFilter createAutoFilter(IColumn column) {
Class<? extends IAutoFilter> clazz = getAutoFilterClass(column);
if (clazz == null) {
return null;
}
IAutoFilter result = null;
try {
Constructor<? extends IAutoFilter> constructor = clazz.getConstructor();
result = constructor.newInstance();
} catch (Exception e) {
e.printStackTrace(); // TODO
return null;
}
result.setTable(this);
result.setColumn(column);
return result;
}
/**
* Retrieve the state of header drawing.
*
* @return true when headers are drawn.
*/
public boolean getDrawHeader() {
return _drawHeader;
}
/**
* If set to true, the header row will be drawn.
*
* @param drawHeader true: draw the header
*/
public void setDrawHeader(boolean drawHeader) {
if (_drawHeader != drawHeader) {
_drawHeader = drawHeader;
redraw();
}
}
/**
* @return Returns the headerRenderer.
*/
public ITableHeaderRenderer getHeaderRenderer() {
return _headerRenderer;
}
/**
* Set a header renderer.
*
* @param headerRenderer The headerRenderer to set.
*/
public void setHeaderRenderer(ITableHeaderRenderer headerRenderer) {
_headerRenderer = headerRenderer;
redraw();
}
/**
* @return Returns the columnResizeAllowed.
*/
public boolean isColumnResizeAllowed() {
return _columnResizeAllowed;
}
/**
* Set whether column resizing is allowed.
*
* @param columnResizeAllowed true for allowing col resizing.
*/
public void setColumnResizeAllowed(boolean columnResizeAllowed) {
_columnResizeAllowed = columnResizeAllowed;
}
/**
* @return Returns the headerResizeAllowed.
*/
public boolean isHeaderResizeAllowed() {
return _headerResizeAllowed;
}
/**
* @param headerResizeAllowed The headerResizeAllowed to set.
*/
public void setHeaderResizeAllowed(boolean headerResizeAllowed) {
_headerResizeAllowed = headerResizeAllowed;
}
/**
* @return Returns the rowResizeAllowed.
*/
public boolean isRowResizeAllowed() {
return _rowResizeAllowed;
}
/**
* @param rowResizeAllowed The rowResizeAllowed to set.
*/
public void setRowResizeAllowed(boolean rowResizeAllowed) {
_rowResizeAllowed = rowResizeAllowed;
}
/**
* Set the first row displayed.
*
* @param idx index of the first row to be displayed.
* @param pixeloffset the pixeloffset of the first row
*/
public void setFirstRow(int idx, int pixeloffset) {
if (_firstRowIdx != idx || _firstRowPixelOffset != pixeloffset) {
int oldFirstIdx = _firstRowIdx;
int oldPixelOffset = _firstRowPixelOffset;
_firstRowIdx = idx;
_firstRowPixelOffset = pixeloffset;
_rowInfoCache = null; // kill the cache
updateYScrollBar();
redraw();
firePropertyChange(PROPERTYNAME_FIRSTROWIDX, oldFirstIdx, idx);
firePropertyChange(PROPERTYNAME_FIRSTROWPIXELOFFSET, oldPixelOffset, pixeloffset);
}
}
/**
* Internal row filter pooling the results of the autofilters.
*
* @author Peter Kliem
* @version $Id: JaretTable.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
private class AutoFilter extends PropertyObservableBase implements IRowFilter, PropertyChangeListener {
/** the table instance of the filter. */
private JaretTable _table;
public AutoFilter(JaretTable table) {
_table = table;
}
/**
* {@inheritDoc}
*/
public boolean isInResult(IRow row) {
boolean result = true;
for (IColumn column : _cols) {
IAutoFilter af = _autoFilterMap.get(column);
if (af != null) {
result = result && af.isInResult(row);
}
if (!result) {
break;
}
}
return result;
}
/**
* {@inheritDoc} Whenever a filter signals change update everything.
*/
public void propertyChange(PropertyChangeEvent evt) {
updateRowList();
setFirstRow(_fixedRows, 0);
redraw();
// genarl filtering change signalling
_table.firePropertyChange(PROPERTYNAME_FILTERING, null, "x");
}
}
/**
* If a header context is present, display it at x,y.
*
* @param x x coordinate
* @param y y coordinate
*/
public void displayHeaderContextMenu(int x, int y) {
if (_headerContextMenu != null) {
dispContextMenu(_headerContextMenu, x, y);
}
}
/**
* If a row context is present, display it at x,y.
*
* @param x x coordinate
* @param y y coordinate
*/
public void displayRowContextMenu(int x, int y) {
if (_rowContextMenu != null) {
dispContextMenu(_rowContextMenu, x, y);
}
}
// todo move to utils
private void dispContextMenu(Menu contextMenu, int x, int y) {
Shell shell = Display.getCurrent().getActiveShell();
Point coords = Display.getCurrent().map(this, shell, x, y);
contextMenu.setLocation(coords.x + shell.getLocation().x, coords.y + shell.getLocation().y);
contextMenu.setVisible(true);
}
/**
* Set a context menu to be displayed on the header area.
*
* @param headerCtxMenu menu to display on the header or <code>null</code> to disable
*/
public void setHeaderContextMenu(Menu headerCtxMenu) {
_headerContextMenu = headerCtxMenu;
}
/**
* Retrieve a context menu that has been set on the header.
*
* @return context menu or <code>null</code>
*/
public Menu getHeaderContextMenu() {
return _headerContextMenu;
}
/**
* Set a context menu to be displayed on rows.
*
* @param rowCtxMenu context menu or <code>null</code> to disable
*/
public void setRowContextMenu(Menu rowCtxMenu) {
_rowContextMenu = rowCtxMenu;
}
/**
* Retrieve a context menu that has been set for the rows.
*
* @return context menu or <code>null</code>
*/
public Menu getRowContextMenu() {
return _rowContextMenu;
}
/**
* @return Returns the fixedColumns.
*/
public int getFixedColumns() {
return _fixedColumns;
}
/**
* Set the numerb of fixed columns. Fixed columns are excluded from vertial scrolling. Row resizing can be
* restricted to the area of the fixed columns.
*
* @param fixedColumns The fixedColumns to set.
*/
public void setFixedColumns(int fixedColumns) {
if (_fixedColumns != fixedColumns) {
_fixedColumns = fixedColumns;
_firstColIdx = fixedColumns;
_firstColPixelOffset = 0;
redraw();
}
}
/**
* @return Returns the fixedRows.
*/
public int getFixedRows() {
return _fixedRows;
}
/**
* Set the number of rows to be fixed (excluded from scrolling and autofiltering; optionally from sorting).
*
* @param fixedRows The fixedRows to set.
*/
public void setFixedRows(int fixedRows) {
if (_fixedRows != fixedRows) {
_fixedRows = fixedRows;
_firstRowIdx = fixedRows;
_firstRowPixelOffset = 0;
_rowInfoCache = null;
redraw();
}
}
// /////////// table model listener
/**
* {@inheritDoc}
*/
public void rowChanged(IRow row) {
if (_tvs.getRowHeigthMode(row) == ITableViewState.RowHeightMode.OPTIMAL
|| _tvs.getRowHeigthMode(row) == ITableViewState.RowHeightMode.OPTANDVAR) {
optimizeHeight(row);
}
redraw(row);
}
/**
* {@inheritDoc}
*/
public void rowRemoved(IRow row) {
// MAYBE could be further optimized
updateRowList();
if (isDisplayed(row)) {
syncedRedraw();
}
updateYScrollBar();
}
/**
* {@inheritDoc}
*/
public void rowAdded(int idx, IRow row) {
updateRowList();
syncedRedraw();
updateYScrollBar();
}
/**
* {@inheritDoc}
*/
public void columnAdded(int idx, IColumn column) {
_tvs.getSortedColumns().add(column);
updateColumnList();
syncedRedraw();
updateXScrollBar();
}
/**
* {@inheritDoc}
*/
public void columnRemoved(IColumn column) {
// MAYBE optimize
_tvs.getSortedColumns().remove(column);
updateColumnList();
if (isDisplayed(column)) {
syncedRedraw();
}
updateXScrollBar();
}
/**
* {@inheritDoc}
*/
public void columnChanged(IColumn column) {
redraw(column);
}
/**
* {@inheritDoc}
*/
public void cellChanged(IRow row, IColumn column) {
redraw(row, column);
}
/**
* {@inheritDoc}
*/
public void tableDataChanged() {
// TODO optimze row heights
updateRowList();
syncedRedraw();
}
// end table model listener
/**
* Retrieve the flag controlling whether fixed rows are excluded from sorting.
*
* @return if true fixed rows will not be affected by sorting operations
*/
public boolean getExcludeFixedRowsFromSorting() {
return _excludeFixedRowsFromSorting;
}
/**
* If set to true, fixed rows are exluded from sorting.
*
* @param excludeFixedRowsFromSorting true for exclude fixed rows from sorting.
*/
public void setExcludeFixedRowsFromSorting(boolean excludeFixedRowsFromSorting) {
_excludeFixedRowsFromSorting = excludeFixedRowsFromSorting;
}
/**
* Get the state of the resize restriction flag. If true, resizing is only allowed in header and fixed columns (for
* rows) and the leftmost SELDELTA pixels of eachrow.
*
* @return Returns the resizeRestriction.
*/
public boolean getResizeRestriction() {
return _resizeRestriction;
}
/**
* If set to true resizing of columns will only be allowed in the header area. Row resizing will be allowed on fixed
* columns and on the first SEL_DELTA pixels of the leftmost column when restricted.
*
* @param resizeRestriction The resizeRestriction to set.
*/
public void setResizeRestriction(boolean resizeRestriction) {
_resizeRestriction = resizeRestriction;
}
// //////// selection listener
/**
* {@inheritDoc}
*/
public void rowSelectionAdded(IRow row) {
_selectedIdxRectangle = null;
redraw(row);
}
/**
* {@inheritDoc}
*/
public void rowSelectionRemoved(IRow row) {
_selectedIdxRectangle = null;
redraw(row);
}
/**
* {@inheritDoc}
*/
public void cellSelectionAdded(IJaretTableCell cell) {
_selectedIdxRectangle = null;
redraw(cell.getRow(), cell.getColumn());
}
/**
* {@inheritDoc}
*/
public void cellSelectionRemoved(IJaretTableCell cell) {
_selectedIdxRectangle = null;
redraw(cell.getRow(), cell.getColumn());
}
/**
* {@inheritDoc}
*/
public void columnSelectionAdded(IColumn column) {
_selectedIdxRectangle = null;
redraw(column);
}
/**
* {@inheritDoc}
*/
public void columnSelectionRemoved(IColumn column) {
_selectedIdxRectangle = null;
redraw(column);
}
// end selection listener
/**
* Retrieve the selectionmodel used by the table.
*
* @return the selection model
*/
public IJaretTableSelectionModel getSelectionModel() {
return _selectionModel;
}
/**
* Set the selection model to be used by the table.
*
* @param jts the selection model to be used (usually the default implementation)
*/
public void setSelectionModel(IJaretTableSelectionModel jts) {
if (_selectionModel != null) {
_selectionModel.removeTableSelectionModelListener(this);
}
_selectionModel = jts;
_selectionModel.addTableSelectionModelListener(this);
}
/**
* Current number of displayed columns.
*
* @return number of displayed columns
*/
public int getColumnCount() {
return _cols.size();
}
/**
* Retrieve column by the display idx.
*
* @param idx display idx
* @return column
*/
public IColumn getColumn(int idx) {
return _cols.get(idx);
}
/**
* Convenience method to retrieve a column by it's id from the model.
*
* @param id id of the column
* @return column or <code>null</code>
*/
public IColumn getColumn(String id) {
for (int i = 0; i < _model.getColumnCount(); i++) {
if (_model.getColumn(i).getId().equals(id)) {
return _model.getColumn(i);
}
}
return null;
}
/**
* Get the number of displayed rows (after filtering!).
*
* @return number of displayed rows
*/
public int getRowCount() {
return _rows.size();
}
/**
* Get a row by the display idx.
*
* @param idx index in the list of displayed rows.
* @return row
*/
public IRow getRow(int idx) {
return _rows.get(idx);
}
/**
* @return Returns the rowFilter.
*/
public IRowFilter getRowFilter() {
return _rowFilter;
}
/**
* Set a row filter on the table.
*
* @param rowFilter The rowFilter to set.
*/
public void setRowFilter(IRowFilter rowFilter) {
IRowFilter oldVal = _rowFilter;
if (_rowFilter != null) {
_rowFilter.removePropertyChangeListener(this);
}
_rowFilter = rowFilter;
if (_rowFilter != null) {
_rowFilter.addPropertyChangeListener(this);
}
updateRowList();
updateAutoFilter(); // update autofilter (just in case it is enabled)
redraw();
firePropertyChange(PROPERTYNAME_ROWFILTER, oldVal, _rowFilter);
// general change of filtering
firePropertyChange(PROPERTYNAME_FILTERING, null, "x");
}
/**
* @return Returns the rowSorter.
*/
public IRowSorter getRowSorter() {
return _rowSorter;
}
/**
* Set a row sorter. A row sorter will be overruled by sorting setup on columns.
*
* @param rowSorter The rowSorter to set.
*/
public void setRowSorter(IRowSorter rowSorter) {
IRowSorter oldValue = _rowSorter;
if (_rowSorter != null) {
_rowSorter.removePropertyChangeListener(this);
}
_rowSorter = rowSorter;
if (_rowSorter != null) {
_rowSorter.addPropertyChangeListener(this);
}
updateRowList();
redraw();
// fire the change for the sorter object
firePropertyChange(PROPERTYNAME_ROWSORTER, oldValue, _rowSorter);
// fire the general sorting change
firePropertyChange(PROPERTYNAME_SORTING, null, "x");
}
/**
* Add a listener to listen for focus changes in the table (focussed cell).
*
* @param tfl listener
*/
public synchronized void addTableFocusListener(ITableFocusListener tfl) {
if (_tableFocusListeners == null) {
_tableFocusListeners = new Vector<ITableFocusListener>();
}
_tableFocusListeners.add(tfl);
}
/**
* Remove a registered listener.
*
* @param tfl listener
*/
public synchronized void remTableFocusListener(ITableFocusListener tfl) {
if (_tableFocusListeners != null) {
_tableFocusListeners.remove(tfl);
}
}
/**
* Inform focus listeners about a change of the focussed cell.
*
* @param row row of the focussed cell
* @param column column of the focussed cell
*/
private void fireTableFocusChanged(IRow row, IColumn column) {
if (_tableFocusListeners != null) {
for (ITableFocusListener listener : _tableFocusListeners) {
listener.tableFocusChanged(this, row, column);
}
}
}
// ************ property change listener
/**
* {@inheritDoc} The table eitselflistens for prop changes of the rowSorter and the rowFilter.
*/
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getSource().equals(_rowSorter)) {
updateRowList();
updateAutoFilter(); // update autofilter (just in case it is enabled)
redraw();
firePropertyChange(PROPERTYNAME_SORTING, null, "x");
} else if (evt.getSource().equals(_rowFilter)) {
updateRowList();
updateAutoFilter(); // update autofilter (just in case it is enabled)
redraw();
firePropertyChange(PROPERTYNAME_FILTERING, null, "x");
}
}
// ************ property change listener
/**
* Retrieve the used startegy when performing a fill drag.
*
* @return the fillDragStrategy
*/
public IFillDragStrategy getFillDragStrategy() {
return _fillDragStrategy;
}
/**
* Set the strategy used when perfoming a fill drag.
*
* @param fillDragStrategy the fillDragStrategy to set. Must be non null.
*/
public void setFillDragStrategy(IFillDragStrategy fillDragStrategy) {
if (fillDragStrategy == null) {
throw new IllegalArgumentException("FillDragStrategy must not be NULL");
}
_fillDragStrategy = fillDragStrategy;
}
/**
* Retrieve whether fill dragging is activated.
*
* @return the supportFillDragging
*/
public boolean isSupportFillDragging() {
return _supportFillDragging;
}
/**
* Set fill drag activation.
*
* @param supportFillDragging the supportFillDragging to set
*/
public void setSupportFillDragging(boolean supportFillDragging) {
_supportFillDragging = supportFillDragging;
_dragMarkerRect = null;
redraw();
}
/**
* @return the iccpStrategy
*/
public ICCPStrategy getCcpStrategy() {
return _ccpStrategy;
}
/**
* Set the strategy to perform cut, copy, paste operations. Setting the strategy to <code>null</code> causes
* deactivation of ccp.
*
* @param ccpStrategy the iccpStrategy to set or <code>null</code> to deactivat ccp
*/
public void setCcpStrategy(ICCPStrategy ccpStrategy) {
_ccpStrategy = ccpStrategy;
}
/**
* Do a cut operation. Implementation is supplied by the CCPStrategy.
*
*/
public void cut() {
if (_ccpStrategy != null) {
_ccpStrategy.cut(this);
}
}
/**
* Do a copy operation. Implementation is supplied by the CCPStrategy.
*
*/
public void copy() {
if (_ccpStrategy != null) {
_ccpStrategy.copy(this);
}
}
/**
* Do a paste operation. Implementation is supplied by the CCPStrategy.
*
*/
public void paste() {
if (_ccpStrategy != null) {
_ccpStrategy.paste(this);
}
}
/**
* Select all cells by selectiong all displayed (not filtered) columns.
*
*/
public void selectAll() {
getSelectionModel().clearSelection();
for (IColumn col : _cols) {
getSelectionModel().addSelectedColumn(col);
}
}
/**
* Retrieve whether scroll opotimizations are active.
*
* @return true if scrolling is done optimized
*/
public boolean getOptimizeScrolling() {
return _optimizeScrolling;
}
/**
* Set whether to use optimized scrolling by copying content. Defaults to false (since it causes trouble when
* running on Linux or OSX).
*
* @param optimizeScrolling true for optimizing
*/
public void setOptimizeScrolling(boolean optimizeScrolling) {
_optimizeScrolling = optimizeScrolling;
}
/**
* Retrieve the height used to render the autofilters.
*
* @return height of the autofilter rectangle
*/
public int getAutoFilterHeight() {
return _autoFilterEnabled ? _autoFilterRect.height : 0;
}
/**
* {@inheritDoc}
*/
public void addPropertyChangeListener(PropertyChangeListener listener) {
_propertyChangeSupport.addPropertyChangeListener(listener);
}
/**
* {@inheritDoc}
*/
public void removePropertyChangeListener(PropertyChangeListener listener) {
_propertyChangeSupport.removePropertyChangeListener(listener);
}
/**
* {@inheritDoc}
*/
public void firePropertyChange(String propName, Object oldVal, Object newVal) {
if (_propertyChangeSupport != null) {
_propertyChangeSupport.firePropertyChange(propName, oldVal, newVal);
}
}
/**
* Retrieve the pixel offset the first row is scrolled.
*
* @return pixel ofset of the first row
*/
public int getFirstRowPixelOffset() {
return _firstRowPixelOffset;
}
/**
* Retrive the index of the first row displayed in the scrolled area of the table.
*
* @return index of the first row displayed
*/
public int getFirstRowIdx() {
return _firstRowIdx;
}
/**
* Check whether sorting the table is allowed.
*
* @return true if sorting is allowed
*/
public boolean getAllowSorting() {
return _allowSorting;
}
/**
* Set the global allowance for sorting. This defaults to true.
*
* @param allowSorting true to allow sorting
*/
public void setAllowSorting(boolean allowSorting) {
_allowSorting = allowSorting;
}
/**
* Get access to the internal row list. This is for special purposes (like synchronizing models) only. Use with
* care!
*
* @return the internal list of rows
*/
public List<IRow> getInternalRowList() {
return _rows;
}
}
| 165,508 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
TableHierarchyRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/TableHierarchyRenderer.java | /*
* File: TableHierarchyRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import java.util.List;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.SWT;
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.printing.Printer;
import org.eclipse.swt.widgets.Display;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IHierarchicalTableViewState;
import de.jaret.util.ui.table.model.IRow;
import de.jaret.util.ui.table.model.ITableNode;
import de.jaret.util.ui.table.model.StdHierarchicalTableModel;
/**
* A renderer for rendering the hierarchy (as a tree) of a hierarchical tree model.
*
* @author Peter Kliem
* @version $Id: TableHierarchyRenderer.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class TableHierarchyRenderer extends CellRendererBase implements IHierarchyRenderer {
/** size of the plus/minus signs. */
protected int SIZE = 12;
protected int SIGNINSETS = 3;
protected boolean _drawTree = true;
protected int _levelWidth = 30;
protected boolean _drawIcons = false;
protected boolean _drawLabels = false;
protected ILabelProvider _labelProvider = null;
/** type of nodemarks to draw: 0 none, 1 +/-, 2 triangles. */
protected int _nodeMarkType = 2;
/**
* Create the renderer for a printer device.
* @param printer printer device
*/
public TableHierarchyRenderer(Printer printer) {
super(printer);
SIZE = scaleX(SIZE);
SIGNINSETS = scaleX(SIGNINSETS);
}
/**
* Create the renderer for use with the display.
*/
public TableHierarchyRenderer() {
super(null);
}
/**
* {@inheritDoc}
*/
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
IColumn column, boolean drawFocus, boolean selected, boolean printing) {
int offx;
offx = scaleX(_levelWidth);
ITableNode node = (ITableNode) row;
int level = node.getLevel();
boolean leaf = node.getChildren().size() == 0;
boolean expanded = ((IHierarchicalTableViewState) jaretTable.getTableViewState()).isExpanded(node);
int x = drawingArea.x + offx * level + SIZE / 2;
int y = drawingArea.y + (drawingArea.height - SIZE) / 2;
if (leaf && !_drawIcons) {
drawLeaf(gc, SIZE, x, y);
} else if (expanded && !leaf) {
if (_nodeMarkType == 1) {
drawMinus(gc, SIZE, x, y);
} else if (_nodeMarkType == 2) {
drawTriangleDown(gc, SIZE, x, y);
}
} else if (!leaf) {
if (_nodeMarkType == 1) {
drawPlus(gc, SIZE, x, y);
} else if (_nodeMarkType == 2) {
drawTriangleRight(gc, SIZE, x, y);
}
}
if (_nodeMarkType != 0) {
x += SIZE + 4;
}
// default for drawing selection
Rectangle labelrect = drawingArea;
if (_labelProvider != null && (_drawIcons || _drawLabels)) {
int labelx = x;
labelrect = new Rectangle(x, y, 0, 0);
if (_drawIcons) {
Image img = _labelProvider.getImage(row);
if (img != null) {
if (!printing) {
gc.drawImage(img, x, y);
labelx += img.getBounds().width;
labelrect.width += img.getBounds().width;
labelrect.height = img.getBounds().height;
} else {
gc.drawImage(img, 0, 0, img.getBounds().width, img.getBounds().height, x, y, scaleX(img
.getBounds().width), scaleY(img.getBounds().height));
labelx += scaleX(img.getBounds().width);
labelrect.width += scaleX(img.getBounds().width);
labelrect.height = scaleY(img.getBounds().height);
}
}
}
if (_drawLabels) {
String label = _labelProvider.getText(row);
if (label != null) {
gc.drawString(label, labelx, y);
Point extent = gc.stringExtent(label);
labelrect.width += extent.x;
labelrect.height = Math.max(labelrect.height, extent.y);
}
}
}
// draw tree connections
if (_drawTree) {
// TimeBarNode node = (TimeBarNode) row;
if (printing) {
gc.setLineWidth(3);
}
gc.setLineStyle(SWT.LINE_DOT);
int midy = drawingArea.y + ((drawingArea.height - SIZE) / 2) + SIZE / 2;
int icoy = drawingArea.y + ((drawingArea.height - SIZE) / 2) + SIZE;
int icox = drawingArea.x + offx * (level) + SIZE - SIZE / 2;
int midx = drawingArea.x + +offx * (level) + SIZE;
int beginx = drawingArea.x + offx * (level - 1) + SIZE;
int endx = drawingArea.x + offx * (level + 1) + SIZE;
// connection
gc.drawLine(beginx, midy, icox, midy);
// uplink
gc.drawLine(beginx, drawingArea.y, beginx, midy);
// downlink
if ((!leaf && expanded)) {
gc.drawLine(midx, icoy, midx, drawingArea.y + drawingArea.height);
}
boolean hasMoreSiblings = true;
if (jaretTable.getTableModel() instanceof StdHierarchicalTableModel) {
StdHierarchicalTableModel model = (StdHierarchicalTableModel) jaretTable.getTableModel();
hasMoreSiblings = model.moreSiblings(node, node.getLevel());
}
// // downlink on begin
// // if has more siblings
// if (hasMoreSiblings) {
// // gc.drawLine(beginx, icoy, beginx,
// drawingArea.y+drawingArea.height);
// }
// level lines
if (jaretTable.getTableModel() instanceof StdHierarchicalTableModel) {
StdHierarchicalTableModel model = (StdHierarchicalTableModel) jaretTable.getTableModel();
for (int i = 0; i < level; i++) {
if (model.moreSiblings(node, i)) {
x = drawingArea.x + offx * i + SIZE;
gc.drawLine(x, drawingArea.y, x, drawingArea.y + drawingArea.height);
}
}
}
gc.setLineStyle(SWT.LINE_SOLID);
gc.setLineWidth(1);
}
if (drawFocus) {
drawFocus(gc, labelrect);
}
drawSelection(gc, labelrect, cellStyle, selected, printing);
}
protected void drawPlus(GC gc, int size, int x, int y) {
gc.drawLine(x + SIGNINSETS, y + size / 2, x + size - SIGNINSETS, y + size / 2);
gc.drawLine(x + size / 2, y + SIGNINSETS, x + size / 2, y + size - SIGNINSETS);
gc.drawRectangle(x, y, size, size);
}
protected void drawMinus(GC gc, int size, int x, int y) {
gc.drawLine(x + SIGNINSETS, y + size / 2, x + size - SIGNINSETS, y + size / 2);
gc.drawRectangle(x, y, size, size);
}
protected void drawTriangleDown(GC gc, int size, int x, int y) {
Color bg = gc.getBackground();
gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
int[] pArray = new int[] { x, y, x + size, y, x + size / 2, y + size - 3 };
gc.fillPolygon(pArray);
gc.setBackground(bg);
}
protected void drawTriangleRight(GC gc, int size, int x, int y) {
Color bg = gc.getBackground();
gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
int[] pArray = new int[] { x, y, x + size - 3, y + size / 2, x, y + size };
gc.fillPolygon(pArray);
gc.setBackground(bg);
}
protected void drawLeaf(GC gc, int size, int x, int y) {
Color bg = gc.getBackground();
gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
gc.fillOval(x + size / 2, y + size / 2, size / 2, size / 2);
gc.setBackground(bg);
}
/**
* {@inheritDoc}
*/
public boolean contains(Rectangle drawingArea, int x, int y) {
return true;
}
/**
* {@inheritDoc}
*/
public int getPreferredWidth() {
return scaleX(SIZE + 4);
}
/**
* {@inheritDoc}
*/
public void dispose() {
if (_labelProvider != null) {
_labelProvider.dispose();
}
}
/**
* @return Returns the labelProvider.
*/
public ILabelProvider getLabelProvider() {
return _labelProvider;
}
/**
* @param labelProvider The labelProvider to set.
*/
public void setLabelProvider(ILabelProvider labelProvider) {
_labelProvider = labelProvider;
}
/**
* @return Returns the levelWidth.
*/
public int getLevelWidth() {
return _levelWidth;
}
/**
* @param levelWidth The levelWidth to set.
*/
public void setLevelWidth(int levelWidth) {
_levelWidth = levelWidth;
}
/**
* @return Returns the drawIcons.
*/
public boolean getDrawIcons() {
return _drawIcons;
}
/**
* @param drawIcons The drawIcons to set.
*/
public void setDrawIcons(boolean drawIcons) {
this._drawIcons = drawIcons;
}
/**
* @return Returns the drawLabels.
*/
public boolean getDrawLabels() {
return _drawLabels;
}
/**
* @param drawLabels The drawLabels to set.
*/
public void setDrawLabels(boolean drawLabels) {
this._drawLabels = drawLabels;
}
/**
* {@inheritDoc}
*/
public ICellRenderer createPrintRenderer(Printer printer) {
TableHierarchyRenderer r = new TableHierarchyRenderer(printer);
r.setDrawIcons(_drawIcons);
r.setDrawLabels(_drawLabels);
r.setLevelWidth(_levelWidth);
r.setLabelProvider(_labelProvider);
return r;
}
/**
* {@inheritDoc}
*/
public int getPreferredWidth(List<IRow> rows, IColumn column) {
return -1;
}
/**
* {@inheritDoc}
*/
public int getPreferredHeight(IRow row, IColumn column) {
return -1;
}
/**
* {@inheritDoc}
*/
public boolean isInActiveArea(IRow row, Rectangle drawingArea, int xx, int yy) {
int offx = scaleX(_levelWidth);
ITableNode node = (ITableNode) row;
int level = node.getLevel();
boolean leaf = node.getChildren().size() == 0;
// leaves can not be toggled
if (leaf) {
return false;
}
int x = drawingArea.x + offx * level + SIZE / 2;
int y = drawingArea.y + (drawingArea.height - SIZE) / 2;
return x <= xx && xx <= x + SIZE && y <= yy && yy <= y + SIZE;
}
}
| 11,969 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultBorderConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/DefaultBorderConfiguration.java | /*
* File: DefaultBorderConfiguration.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import java.util.StringTokenizer;
/**
* Default implementation of a BorderConfiguration.
*
* @author Peter Kliem
* @version $Id: DefaultBorderConfiguration.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class DefaultBorderConfiguration implements IBorderConfiguration {
/** left border. */
protected int _borderLeft;
/** right border. */
protected int _borderRight;
/** top border. */
protected int _borderTop;
/** bottom border. */
protected int _borderBottom;
/**
* Construct a border configuration.
*
* @param left left border
* @param right right border
* @param top top border
* @param bottom bottom border
*/
public DefaultBorderConfiguration(int left, int right, int top, int bottom) {
_borderBottom = bottom;
_borderLeft = left;
_borderRight = right;
_borderTop = top;
}
/**
* Construct a borderconfiguration form a comma separated string holding the values (no error hndling).
*
* @param str csv string
*/
public DefaultBorderConfiguration(String str) {
StringTokenizer tokenizer = new StringTokenizer(str, ",");
_borderLeft = Integer.parseInt(tokenizer.nextToken());
_borderRight = Integer.parseInt(tokenizer.nextToken());
_borderTop = Integer.parseInt(tokenizer.nextToken());
_borderBottom = Integer.parseInt(tokenizer.nextToken());
}
/**
* {@inheritDoc}
*/
public DefaultBorderConfiguration copy() {
DefaultBorderConfiguration bc = new DefaultBorderConfiguration(_borderLeft, _borderRight, _borderTop,
_borderBottom);
return bc;
}
/**
* {@inheritDoc} Produces a string that can be passed to the constructor as a csv string.
*/
public String toString() {
return _borderLeft + "," + _borderRight + "," + _borderTop + "," + _borderBottom;
}
/**
* @return Returns the borderBottom.
*/
public int getBorderBottom() {
return _borderBottom;
}
/**
* @param borderBottom The borderBottom to set.
*/
public void setBorderBottom(int borderBottom) {
_borderBottom = borderBottom;
}
/**
* @return Returns the borderLeft.
*/
public int getBorderLeft() {
return _borderLeft;
}
/**
* @param borderLeft The borderLeft to set.
*/
public void setBorderLeft(int borderLeft) {
_borderLeft = borderLeft;
}
/**
* @return Returns the borderRight.
*/
public int getBorderRight() {
return _borderRight;
}
/**
* @param borderRight The borderRight to set.
*/
public void setBorderRight(int borderRight) {
_borderRight = borderRight;
}
/**
* @return Returns the borderTop.
*/
public int getBorderTop() {
return _borderTop;
}
/**
* @param borderTop The borderTop to set.
*/
public void setBorderTop(int borderTop) {
_borderTop = borderTop;
}
}
| 3,660 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
CellRendererBase.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/CellRendererBase.java | /*
* File: CellRendererBase.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.widgets.Display;
import de.jaret.util.swt.ColorManager;
import de.jaret.util.swt.FontManager;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Base implementation for cell renderers that support both screen and printer rendering. This base implementation
* contains some useful methods so that it is highly recommended to base all renderer implementations on this base.
*
* @author Peter Kliem
* @version $Id: CellRendererBase.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public abstract class CellRendererBase extends RendererBase implements ICellRenderer {
/** selection color for overlay (non printing only). */
protected static final Color SELECTIONCOLOR = Display.getCurrent().getSystemColor(SWT.COLOR_GRAY);
/** alpha value used when drawing default selection. */
private static final int SELECTIONALPHA = 150;
/** insets used when drawing the focus. */
protected static final int FOCUSINSETS = 2;
/** default background color. */
protected static final RGB WHITERGB = new RGB(255, 255, 255);
/** default foreground color. */
protected static final RGB BLACKRGB = new RGB(0, 0, 0);
/** cell inset used by the convenience methods. */
protected int _inset = 2;
/**
* May be constructed without printer (supplying null).
*
* @param printer or <code>null</code>
*/
public CellRendererBase(Printer printer) {
super(printer);
}
/**
* {@inheritDoc} Default implementation: no prferred width.
*/
public int getPreferredWidth(List<IRow> rows, IColumn column) {
return -1;
}
/**
* {@inheritDoc} Default implementation returning: no information.
*/
public int getPreferredHeight(GC gc, ICellStyle cellStyle, int width, IRow row, IColumn column) {
return -1;
}
/**
* {@inheritDoc} Default: no tooltip.
*/
public String getTooltip(JaretTable jaretTable, Rectangle drawingArea, IRow row, IColumn column, int x, int y) {
return null;
}
/**
* Target inner width (width - borders - insets).
*
* @param width width
* @param cellStyle cell style
* @return target inner width
*/
protected int getInnerWidth(int width, ICellStyle cellStyle) {
int sum = _inset * 2 + cellStyle.getBorderConfiguration().getBorderLeft()
+ cellStyle.getBorderConfiguration().getBorderRight() - 1;
return width - sum;
}
/**
* Calculate the sum of all vertical spaces that could be spplied.
*
* @param cellStyle cell style
* @return sum of all vertical spaces
*/
protected int getVerticalSpacesSum(ICellStyle cellStyle) {
return _inset * 2 + cellStyle.getBorderConfiguration().getBorderTop()
+ cellStyle.getBorderConfiguration().getBorderBottom() - 1;
}
/**
* Draw focus marking. Should be called with the corrected drawing area.
*
* @param gc GC
* @param drawingArea corrected drawing area
*/
protected void drawFocus(GC gc, Rectangle drawingArea) {
Color bg = gc.getBackground();
Color fg = gc.getForeground();
gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
gc.drawFocus(drawingArea.x + FOCUSINSETS, drawingArea.y + FOCUSINSETS, drawingArea.width - 2 * FOCUSINSETS,
drawingArea.height - 2 * FOCUSINSETS - 1);
// gc.drawRectangle(drawingArea.x + 2, drawingArea.y + 2, drawingArea.width - 4, drawingArea.height - 3);
gc.setForeground(fg);
gc.setBackground(bg);
}
/**
* Calculate the resulting rectangle after applying the insets.
*
* @param rect cell drawing area
* @return corrected rectangle
*/
protected Rectangle applyInsets(Rectangle rect) {
int d = _inset;
return new Rectangle(rect.x + d, rect.y + d, rect.width - 2 * d, rect.height - 2 * d);
}
/**
* Draw the border for the cell according to the cell style.
*
* @param gc GC
* @param cellStyle th style
* @param drawingArea the drawing area of the cell
* @param printing true marks operation for a printer
* @return the corrected drawing area (the thickness of the border has been substracted)
*/
protected Rectangle drawBorder(GC gc, ICellStyle cellStyle, Rectangle drawingArea, boolean printing) {
IBorderConfiguration borderConfiguration = cellStyle.getBorderConfiguration();
int x = drawingArea.x;
int y = drawingArea.y;
int width = drawingArea.width;
int height = drawingArea.height;
Color fg = gc.getForeground();
gc.setForeground(getBorderColor(cellStyle, printing));
int lineWidth = gc.getLineWidth();
if (borderConfiguration.getBorderLeft() > 0) {
int lw = scaleX(borderConfiguration.getBorderLeft());
gc.setLineWidth(lw);
gc.drawLine(drawingArea.x, drawingArea.y, drawingArea.x, drawingArea.y + drawingArea.height);
x += lw;
width -= lw;
}
if (borderConfiguration.getBorderRight() > 0) {
int lw = scaleX(borderConfiguration.getBorderRight());
gc.setLineWidth(lw);
gc.drawLine(drawingArea.x + drawingArea.width, drawingArea.y, drawingArea.x + drawingArea.width,
drawingArea.y + drawingArea.height);
width -= lw;
}
if (borderConfiguration.getBorderTop() > 0) {
int lw = scaleY(borderConfiguration.getBorderTop());
gc.setLineWidth(lw);
gc.drawLine(drawingArea.x, drawingArea.y, drawingArea.x + drawingArea.width - 1, drawingArea.y);
y += lw;
height -= lw;
}
if (borderConfiguration.getBorderBottom() > 0) {
int lw = scaleY(borderConfiguration.getBorderBottom());
gc.setLineWidth(lw);
gc.drawLine(drawingArea.x, drawingArea.y + drawingArea.height, drawingArea.x + drawingArea.width,
drawingArea.y + drawingArea.height);
height -= lw;
}
gc.setLineWidth(lineWidth);
gc.setForeground(fg);
return new Rectangle(x, y, width, height);
}
/**
* Draw the cell background.
*
* @param gc GC
* @param area cell drawing area
* @param style cell style
* @param selected true for selected
* @param printing true if printing
*/
protected void drawBackground(GC gc, Rectangle area, ICellStyle style, boolean selected, boolean printing) {
Color c = gc.getBackground();
Color bg;
bg = getBackgroundColor(style, printing);
gc.setBackground(bg);
gc.fillRectangle(area);
gc.setBackground(c);
}
/**
* Draws a cell selection by overlaying alpha blended area using SELECTIONCOLOR.
*
* @param gc GC
* @param area area of the cell
* @param style cellstyle
* @param selected true if selecetd
* @param printing true if printing - no selection will be drawn when printing
*/
protected void drawSelection(GC gc, Rectangle area, ICellStyle style, boolean selected, boolean printing) {
Color c = gc.getBackground();
Color bg;
if (selected && !printing) {
bg = SELECTIONCOLOR;
gc.setBackground(bg);
int alpha = gc.getAlpha();
gc.setAlpha(SELECTIONALPHA);
gc.fillRectangle(area);
gc.setAlpha(alpha);
gc.setBackground(c);
}
}
/**
* Draw a marker in upper left corner for indicating a cell comment.
*
* @param gc GC
* @param area drawing area
* @param color color of the marker
* @param size size of the marker
*/
protected void drawCommentMarker(GC gc, Rectangle area, Color color, int size) {
Color bg = gc.getBackground();
gc.setBackground(color);
gc.fillRectangle(area.x + area.width - size, area.y, size, size);
gc.setBackground(bg);
}
/**
* Check whether a position is in the area of the commetn marker.
*
* @param area drawing area of the cell
* @param size size of the marker
* @param x x coordinate to check
* @param y y coordinate to check
* @return true if the position is in the area of the marker
*/
protected boolean isInCommentMarkerArea(Rectangle area, int size, int x, int y) {
Rectangle r = new Rectangle(area.x + area.width - size, area.y, size, size);
return r.contains(x, y);
}
/**
* Get the background color according to a cell style.
*
* @param style cell style
* @param printing true for printing
* @return the color
*/
protected Color getBackgroundColor(ICellStyle style, boolean printing) {
Device device = printing ? _printer : Display.getCurrent();
ColorManager cm = ColorManager.getColorManager(device);
Color bg = cm.getColor(style.getBackgroundColor() != null ? style.getBackgroundColor() : WHITERGB);
return bg;
}
/**
* Get the foreground color according to the cell style.
*
* @param style cell style
* @param printing true for printing
* @return the foreground color
*/
protected Color getForegroundColor(ICellStyle style, boolean printing) {
Device device = printing ? _printer : Display.getCurrent();
ColorManager cm = ColorManager.getColorManager(device);
Color bg = cm.getColor(style.getForegroundColor() != null ? style.getForegroundColor() : BLACKRGB);
return bg;
}
/**
* Get the border color according to the cell style.
*
* @param style cell style
* @param printing true for printing
* @return the border color
*/
protected Color getBorderColor(ICellStyle style, boolean printing) {
Device device = printing ? _printer : Display.getCurrent();
ColorManager cm = ColorManager.getColorManager(device);
Color bg = cm.getColor(style.getBorderColor() != null ? style.getBorderColor() : new RGB(0, 0, 0));
return bg;
}
/**
* Retrieve the font accrding to the cell style.
*
* @param style cell style
* @param printing true for printing
* @param defaultFont a default font used if no font can be retrieved
* @return font according to style or default font
*/
protected Font getFont(ICellStyle style, boolean printing, Font defaultFont) {
Device device = printing ? _printer : Display.getCurrent();
FontManager fm = FontManager.getFontManager(device);
Font f = style.getFont() != null ? fm.getFont(style.getFont()) : defaultFont;
return f;
}
}
| 11,998 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultTableHeaderRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/DefaultTableHeaderRenderer.java | /*
* File: DefaultTableHeaderRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.SWT;
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.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.widgets.Display;
import de.jaret.util.swt.SwtGraphicsHelper;
import de.jaret.util.ui.table.model.IColumn;
/**
* Default header renderer for the jaret table. The header renderer will render a simple header view. The renderer
* supports rotating the header text from 0 to 90 degrees anti-clock wise. If a rotation is set, the header is drawn
* using a white background. Several properties allow changing the drawing (always consider writing a specialized
* renderer!).
*
* @author Peter Kliem
* @version $Id: DefaultTableHeaderRenderer.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class DefaultTableHeaderRenderer extends RendererBase implements ITableHeaderRenderer {
/** Alignment enumeration. */
public enum Alignment {
LEFT, CENTER, RIGHT
};
/** default background rgb for non rotated drawing. */
private static RGB DEFAULTBACKGROUND = new RGB(220, 220, 220);
/** Alignment: default left. */
protected Alignment _alignment = Alignment.LEFT;
/** true if the header box should be drawn. */
protected boolean _drawBox = true;
/** background rgb value. */
protected RGB _backgroundRGB = DEFAULTBACKGROUND;
/** allocated background color. */
protected Color _bgColor;
/** FOntadat of the font to use. */
protected FontData _fontData;
/** font when aquired. */
protected Font _font;
/** rotation of the header text. */
protected int _rotation = 0;
/** Transformations for rotated text. */
protected Transform _transform;
/** inverse transformation to reset gc. */
protected Transform _transformInv;
protected ImageRegistry _imageRegistry;
/** key for uowards arrow. */
protected static final String UP = "up";
/** key for downwards arrow. */
protected static final String DOWN = "down";
/** width reserved for the sorting area. */
protected static final int SORTINGAREAINDICATORWIDTH = 16;
/** preferred height to use when more space is available. */
private static final int PREFHEIGHT = 20;
/**
* Construct a header renderer for printing.
*
* @param printer printer device
*/
public DefaultTableHeaderRenderer(Printer printer) {
super(printer);
}
/**
* Construct header renderer for a display.
*/
public DefaultTableHeaderRenderer() {
super(null);
}
/**
* Set the rotation of the header text. Please note that you have to call <code>redraw()</code> on the table
* yourself if you change the rotation while the table is showing.
*
* @param rotation rotation in degrees anti clockwise between 0 and 90 degrees.
*/
public void setRotation(int rotation) {
if (rotation < 0 || rotation > 90) {
throw new IllegalArgumentException("Rotation range 0..90");
}
if (_rotation != rotation) {
disposeTransformations();
_rotation = rotation;
_transform = new Transform(Display.getCurrent());
_transformInv = new Transform(Display.getCurrent());
_transform.rotate(-rotation);
_transformInv.rotate(-rotation);
_transformInv.invert();
}
}
/**
* {@inheritDoc}
*/
public void draw(GC gc, Rectangle drawingArea, IColumn column, int sortingOrder, boolean sortDir, boolean printing) {
Color bg = gc.getBackground();
Font font = gc.getFont();
String label = column.getHeaderLabel();
if (_fontData != null && _font == null) {
_font = new Font(gc.getDevice(), _fontData);
}
if (_font != null) {
gc.setFont(_font);
}
if (_rotation == 0) {
// classic rendering
// allocate color when not allocated
if (_bgColor == null) {
_bgColor = new Color(gc.getDevice(), _backgroundRGB);
}
gc.setBackground(_bgColor);
// if the available space is too big, restrict to pref height
if (drawingArea.height > PREFHEIGHT) {
drawingArea.y += drawingArea.height - PREFHEIGHT;
drawingArea.height = PREFHEIGHT;
}
gc.fillRectangle(drawingArea);
if (sortingOrder > 0) {
Image img = getImageRegistry().get(sortDir ? DOWN : UP);
gc.drawImage(img, drawingArea.x + 2, drawingArea.y + drawingArea.height - img.getBounds().height - 1);
}
// box or line
if (_drawBox) {
gc.drawRectangle(drawingArea.x, drawingArea.y, drawingArea.width - 1, drawingArea.height - 1);
} else {
gc.drawLine(drawingArea.x, drawingArea.y + drawingArea.height - 1, drawingArea.width - 1, drawingArea.y
+ drawingArea.height - 1);
}
// label
int offx = column.supportsSorting() ? SORTINGAREAINDICATORWIDTH : 2;
if (_alignment.equals(Alignment.LEFT)) {
gc.drawString(label, drawingArea.x + offx, drawingArea.y + scaleY(2));
} else if (_alignment.equals(Alignment.CENTER)) {
Rectangle rect = new Rectangle(drawingArea.x + offx, drawingArea.y + scaleY(2), drawingArea.width
- offx, drawingArea.height - 2 * scaleY(2));
SwtGraphicsHelper.drawStringCentered(gc, label, rect);
} else if (_alignment.equals(Alignment.RIGHT)) {
SwtGraphicsHelper.drawStringRightAlignedVTop(gc, label, drawingArea.x + drawingArea.width,
drawingArea.y + scaleY(2));
}
} else {
// rotated drawing
gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
Point extent = gc.stringExtent(label);
float[] cords = {(float) (drawingArea.x + ((drawingArea.width - extent.x / 2) / 2)),
(float) (drawingArea.y + drawingArea.height - 9)};
_transformInv.transform(cords);
gc.setTransform(_transform);
gc.drawString(label, (int) cords[0], (int) cords[1]);
gc.setTransform(null);
}
gc.setFont(font);
gc.setBackground(bg);
}
/**
* {@inheritDoc}
*/
public boolean disableClipping() {
// disable clipping when rotated
return _rotation != 0;
}
/**
* {@inheritDoc}
*/
public void dispose() {
disposeTransformations();
if (_imageRegistry != null) {
_imageRegistry.dispose();
}
if (_bgColor != null) {
_bgColor.dispose();
}
if (_font != null) {
_font.dispose();
}
}
private ImageRegistry getImageRegistry() {
if (_imageRegistry == null) {
_imageRegistry = new ImageRegistry();
ImageDescriptor imgDesc = new LocalResourceImageDescriptor(
"/de/jaret/util/ui/table/resource/smallarrow_down.gif");
_imageRegistry.put(DOWN, imgDesc.createImage());
imgDesc = new LocalResourceImageDescriptor("/de/jaret/util/ui/table/resource/smallarrow_up.gif");
_imageRegistry.put(UP, imgDesc.createImage());
}
return _imageRegistry;
}
public class LocalResourceImageDescriptor extends ImageDescriptor {
String rscString;
/**
*
*/
public LocalResourceImageDescriptor(String rscString) {
this.rscString = rscString;
}
/**
* {@inheritDoc}
*/
public ImageData getImageData() {
Image img = new Image(Display.getCurrent(), this.getClass().getResourceAsStream(rscString));
return img.getImageData();
}
}
/**
* Dispose the transformations.
*
*/
private void disposeTransformations() {
if (_transform != null) {
_transform.dispose();
}
if (_transformInv != null) {
_transformInv.dispose();
}
}
/**
* {@inheritDoc}
*/
public boolean isSortingClick(Rectangle drawingArea, IColumn column, int x, int y) {
return x - drawingArea.x < SORTINGAREAINDICATORWIDTH;
}
/**
* {@inheritDoc}
*/
public ITableHeaderRenderer getPrintRenderer(Printer printer) {
return new DefaultTableHeaderRenderer(printer);
}
/**
* Retrieve the alignment for the header label (only when not rotated).
*
* @return the alignment
*/
public Alignment getAlignment() {
return _alignment;
}
/**
* Set the alignment for the header label (not used when rotated).
*
* @param alignment alignment to be used
*/
public void setAlignment(Alignment alignment) {
_alignment = alignment;
}
/**
* Retrieve whether the header is drawn boxed.
*
* @return true if a box is drawn around the header
*/
public boolean getDrawBox() {
return _drawBox;
}
/**
* Set whether the header should be drawn boxed.
*
* @param drawBox true for boxed drawing
*/
public void setDrawBox(boolean drawBox) {
_drawBox = drawBox;
}
/**
* Get the background RGB value of the header (non rotated only).
*
* @return the RGB value for the background
*/
public RGB getBackgroundRGB() {
return _backgroundRGB;
}
/**
* Set the background rgb value. The color will be aquired when used. Will only be used when non rotated.
*
* @param backgroundRGB the RGB value
*/
public void setBackgroundRGB(RGB backgroundRGB) {
if (_bgColor != null) {
_bgColor.dispose();
_bgColor = null;
}
_backgroundRGB = backgroundRGB;
}
/**
* Get the fontdata for the font used to render the header label.
*
* @return the fontdata
*/
public FontData getFontData() {
return _fontData;
}
/**
* Set the fontdata for the font to render the header. The font will be aquired when used.
*
* @param fontData fontdat ato use
*/
public void setFontData(FontData fontData) {
if (_font != null) {
_font.dispose();
_font = null;
}
_fontData = fontData;
}
}
| 11,850 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
BarCellRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/BarCellRenderer.java | /*
* File: BarCellRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.widgets.Display;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* CellRenderer rendering bar according to the cell value that is expected to be of type Integer. Min and max can be
* configured.
*
* @author Peter Kliem
* @version $Id: BarCellRenderer.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class BarCellRenderer extends CellRendererBase implements ICellRenderer {
/** min value. */
protected int _min = 0;
/** max value. */
protected int _max = 100;
/** color for rendering. */
protected Color _barColor;
/**
* Constructor for BarCellRenderer.
*
* @param printer Printer or <code>null</code>
*/
public BarCellRenderer(Printer printer) {
super(printer);
if (printer != null) {
_barColor = printer.getSystemColor(SWT.COLOR_DARK_RED);
}
}
/**
* Default constructor.
*
*/
public BarCellRenderer() {
super(null);
_barColor = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED);
}
/**
* @return Returns the max.
*/
public int getMax() {
return _max;
}
/**
* @param max The max to set.
*/
public void setMax(int max) {
this._max = max;
}
/**
* @return Returns the min.
*/
public int getMin() {
return _min;
}
/**
* @param min The min to set.
*/
public void setMin(int min) {
this._min = min;
}
/**
* {@inheritDoc}
*/
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
IColumn column, boolean drawFocus, boolean selected, boolean printing) {
drawBackground(gc, drawingArea, cellStyle, selected, printing);
Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
Rectangle rect = applyInsets(drect);
Object value = column.getValue(row);
if (value instanceof Integer) {
int val = ((Integer) value).intValue();
double pixPer = (double) rect.width / (double) (_max - _min);
int correctedValue = val - _min;
int drawingWidth = (int) (correctedValue * pixPer);
Color bg = gc.getBackground();
gc.setBackground(_barColor);
gc.fillRectangle(rect.x, rect.y, drawingWidth, rect.height);
gc.setBackground(bg);
} else {
// indicate error with red fill
Color bg = gc.getBackground();
gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
gc.fillRectangle(rect);
gc.setBackground(bg);
}
if (drawFocus) {
drawFocus(gc, drawingArea);
}
drawSelection(gc, drawingArea, cellStyle, selected, printing);
}
/**
* {@inheritDoc}
*/
public void dispose() {
}
/**
* {@inheritDoc}
*/
public ICellRenderer createPrintRenderer(Printer printer) {
return new BarCellRenderer(printer);
}
}
| 3,948 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
LabelProviderRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/LabelProviderRenderer.java | /*
* File: LabelProviderRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.printing.Printer;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Cell renderer rendering an object using an ILabelProvider (uses text only).
*
* @author kliem
* @version $Id: LabelProviderRenderer.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class LabelProviderRenderer extends TextCellRenderer {
/** Label provider tat will be used. */
protected ILabelProvider _labelProvider;
/**
* Construct a label provider renderer for a printer.
*
* @param printer printer device
*/
public LabelProviderRenderer(Printer printer) {
super(printer);
}
/**
* Construct a label provider renderer.
*/
public LabelProviderRenderer() {
this(null);
}
/**
* {@inheritDoc} Use the label provider to convert value to String.
*/
protected String convertValue(IRow row, IColumn column) {
if (_labelProvider == null) {
// error: handle gracefully
return "no label provider set";
}
Object value = column.getValue(row);
return _labelProvider.getText(value);
}
/**
* Retrieve the label provider used.
*
* @return the label provider
*/
public ILabelProvider getLabelProvider() {
return _labelProvider;
}
/**
* Set the label provider to be used by the renderer.
*
* @param labelProvider label provider to be used
*/
public void setLabelProvider(ILabelProvider labelProvider) {
_labelProvider = labelProvider;
}
/**
* {@inheritDoc}
*/
public ICellRenderer createPrintRenderer(Printer printer) {
LabelProviderRenderer lpr = new LabelProviderRenderer(printer);
lpr.setLabelProvider(getLabelProvider());
return lpr;
}
}
| 2,468 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultCellStyleProvider.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/DefaultCellStyleProvider.java | /*
* File: DefaultCellStyleProvider.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IJaretTableCell;
import de.jaret.util.ui.table.model.IRow;
import de.jaret.util.ui.table.model.ITableViewState;
import de.jaret.util.ui.table.model.JaretTableCellImpl;
import de.jaret.util.ui.table.model.ITableViewState.HAlignment;
import de.jaret.util.ui.table.model.ITableViewState.VAlignment;
/**
* A Default implementation of a CellStyleProvider. It will register itself with every cell style as a property change
* listener.
*
* @author Peter Kliem
* @version $Id: DefaultCellStyleProvider.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class DefaultCellStyleProvider implements ICellStyleProvider, PropertyChangeListener {
/** map storing the row cell styles. */
protected Map<IRow, ICellStyle> _rowMap = new HashMap<IRow, ICellStyle>();
/** map storing the column cell styles. */
protected Map<IColumn, ICellStyle> _columnMap = new HashMap<IColumn, ICellStyle>();
/** map combintaion storing the style of a cell . */
protected Map<IRow, Map<IColumn, ICellStyle>> _cellMap = new HashMap<IRow, Map<IColumn, ICellStyle>>();
/** the listener list. */
protected List<ICellStyleListener> _listeners;
/** the default cell style. */
protected ICellStyle _defaultCellStyle;
/** the default cell style aligned right. */
protected ICellStyle _defaultCellStyleAlignRight;
/** style stategy. */
protected IStyleStrategy _styleStrategy;
/**
* Constructor.
*/
public DefaultCellStyleProvider() {
IBorderConfiguration borderConf = new DefaultBorderConfiguration(1, 1, 1, 1);
_defaultCellStyle = new DefaultCellStyle(null, null, borderConf, null);
_defaultCellStyle.addPropertyChangeListener(this);
_defaultCellStyleAlignRight = new DefaultCellStyle(null, null, borderConf, null);
_defaultCellStyleAlignRight.setHorizontalAlignment(ITableViewState.HAlignment.RIGHT);
_defaultCellStyleAlignRight.addPropertyChangeListener(this);
}
/**
* {@inheritDoc} TODO include a strategy for priority row/column.
*/
public ICellStyle getCellStyle(IRow row, IColumn column) {
ICellStyle style = null;
style = getCellSpecificStyle(row, column, false);
if (style == null) {
style = _rowMap.get(row);
}
if (style == null) {
style = _columnMap.get(column);
}
if (style == null) {
Class<?> clazz = column.getContentClass(row);
if (clazz != null
&& (clazz.equals(Double.class) || clazz.equals(Integer.class) || clazz.equals(Float.class)
|| clazz.equals(Double.TYPE) || clazz.equals(Integer.TYPE) || clazz.equals(Float.TYPE))) {
style = _defaultCellStyleAlignRight;
} else {
style = _defaultCellStyle;
}
}
if (_styleStrategy != null) {
style = _styleStrategy.getCellStyle(row, column, style, _defaultCellStyle);
}
return style;
}
/**
* {@inheritDoc}
*/
public void setRowCellStyle(IRow row, ICellStyle style) {
ICellStyle old = _rowMap.get(row);
if (old != null) {
old.removePropertyChangeListener(this);
}
_rowMap.put(row, style);
if (style != null) {
style.addPropertyChangeListener(this);
}
fireCellStyleChanged(row, null, style);
}
/**
* {@inheritDoc}
*/
public ICellStyle getRowCellStyle(IRow row, boolean create) {
ICellStyle style = null;
style = _rowMap.get(row);
if (style != null) {
return style;
}
if (style == null && !create) {
return _defaultCellStyle;
} else {
style = _defaultCellStyle.copy();
setRowCellStyle(row, style);
return style;
}
}
/**
* {@inheritDoc}
*/
public void setColumnCellStyle(IColumn column, ICellStyle style) {
ICellStyle old = _columnMap.get(column);
if (old != null) {
old.removePropertyChangeListener(this);
}
_columnMap.put(column, style);
if (style != null) {
style.addPropertyChangeListener(this);
}
fireCellStyleChanged(null, column, style);
}
/**
* {@inheritDoc}
*/
public ICellStyle getColumnCellStyle(IColumn column, boolean create) {
ICellStyle style = null;
style = _columnMap.get(column);
if (style != null) {
return style;
}
if (style == null && !create) {
return _defaultCellStyle;
} else {
// System.out.println("creating");
style = _defaultCellStyle.copy();
setColumnCellStyle(column, style);
return style;
}
}
/**
* {@inheritDoc}
*/
public ICellStyle getCellSpecificStyle(IRow row, IColumn column, boolean create) {
ICellStyle style = null;
Map<IColumn, ICellStyle> cMap = _cellMap.get(row);
if (cMap != null) {
style = cMap.get(column);
}
if (style == null && create) {
style = _defaultCellStyle.copy();
setCellStyle(row, column, style);
}
return style;
}
/**
* {@inheritDoc}
*/
public void setCellStyle(IRow row, IColumn column, ICellStyle style) {
ICellStyle oldStyle = getCellSpecificStyle(row, column, false);
if (oldStyle != null) {
oldStyle.removePropertyChangeListener(this);
}
Map<IColumn, ICellStyle> cMap = _cellMap.get(row);
if (cMap == null) {
cMap = new HashMap<IColumn, ICellStyle>();
_cellMap.put(row, cMap);
}
cMap.put(column, style);
style.addPropertyChangeListener(this);
}
/**
* {@inheritDoc}
*/
public ICellStyle getDefaultCellStyle() {
return _defaultCellStyle;
}
/**
* {@inheritDoc}
*/
public void setDefaultCellStyle(ICellStyle cellStyle) {
_defaultCellStyle.removePropertyChangeListener(this);
_defaultCellStyle = cellStyle;
cellStyle.addPropertyChangeListener(this);
}
/**
* {@inheritDoc}
*/
public synchronized void addCellStyleListener(ICellStyleListener csl) {
if (_listeners == null) {
_listeners = new ArrayList<ICellStyleListener>();
}
_listeners.add(csl);
}
/**
* {@inheritDoc}
*/
public void remCellStyleListener(ICellStyleListener csl) {
if (_listeners != null) {
_listeners.remove(csl);
}
}
/**
* Inform listeners about a cell style change.
*
* @param row row affected
* @param column olumn affected
* @param cellStyle new style
*/
protected void fireCellStyleChanged(IRow row, IColumn column, ICellStyle cellStyle) {
if (_listeners != null) {
for (ICellStyleListener listener : _listeners) {
listener.cellStyleChanged(row, column, cellStyle);
}
}
}
/**
* Retrieve all cells that have a certain style. TODO check performance
*
* @param style the style to search
* @return list of cels the style applies to
*/
protected List<IJaretTableCell> getStyleLocations(ICellStyle style) {
List<IJaretTableCell> result = new ArrayList<IJaretTableCell>();
if (_columnMap.containsValue(style)) {
for (IColumn col : _columnMap.keySet()) {
if (_columnMap.get(col) == style) {
result.add(new JaretTableCellImpl(null, col));
}
}
}
if (_rowMap.containsValue(style)) {
for (IRow row : _rowMap.keySet()) {
if (_rowMap.get(row) == style) {
result.add(new JaretTableCellImpl(row, null));
}
}
}
for (IRow row : _cellMap.keySet()) {
Map<IColumn, ICellStyle> cmap = _cellMap.get(row);
if (cmap != null) {
for (IColumn col : cmap.keySet()) {
ICellStyle cs = cmap.get(col);
if (style == cs) {
result.add(new JaretTableCellImpl(row, col));
}
}
}
}
return result;
}
/**
* {@inheritDoc} Listens to all styles and fires style changed for every location a style is used in.
*/
public void propertyChange(PropertyChangeEvent event) {
ICellStyle style = (ICellStyle) event.getSource();
List<IJaretTableCell> locs = getStyleLocations(style);
for (IJaretTableCell loc : locs) {
fireCellStyleChanged(loc.getRow(), loc.getColumn(), (ICellStyle) style);
}
}
/**
* {@inheritDoc}
*/
public IStyleStrategy getStyleStrategy() {
return _styleStrategy;
}
/**
* {@inheritDoc}
*/
public void setStyleStrategy(IStyleStrategy startegy) {
_styleStrategy = startegy;
}
// ////////// convenience methods
/**
* {@inheritDoc}
*/
public void setBackground(IRow row, RGB background) {
ICellStyle style = getRowCellStyle(row, true);
style.setBackgroundColor(background);
setRowCellStyle(row, style);
}
/**
* {@inheritDoc}
*/
public void setBackground(IColumn column, RGB background) {
ICellStyle style = getColumnCellStyle(column, true);
style.setBackgroundColor(background);
setColumnCellStyle(column, style);
}
/**
* {@inheritDoc}
*/
public void setBackground(IRow row, IColumn column, RGB background) {
ICellStyle style = getCellSpecificStyle(row, column, true);
style.setBackgroundColor(background);
setCellStyle(row, column, style);
}
/**
* {@inheritDoc}
*/
public void setForeground(IRow row, RGB foreground) {
ICellStyle style = getRowCellStyle(row, true);
style.setForegroundColor(foreground);
setRowCellStyle(row, style);
}
/**
* {@inheritDoc}
*/
public void setForeground(IColumn column, RGB foreground) {
ICellStyle style = getColumnCellStyle(column, true);
style.setForegroundColor(foreground);
setColumnCellStyle(column, style);
}
/**
* {@inheritDoc}
*/
public void setForeground(IRow row, IColumn column, RGB foreground) {
ICellStyle style = getCellSpecificStyle(row, column, true);
style.setForegroundColor(foreground);
setCellStyle(row, column, style);
}
/**
* {@inheritDoc}
*/
public void setHorizontalAlignment(IRow row, HAlignment alignment) {
ICellStyle style = getRowCellStyle(row, true);
style.setHorizontalAlignment(alignment);
setRowCellStyle(row, style);
}
/**
* {@inheritDoc}
*/
public void setHorizontalAlignment(IColumn column, HAlignment alignment) {
ICellStyle style = getColumnCellStyle(column, true);
style.setHorizontalAlignment(alignment);
setColumnCellStyle(column, style);
}
/**
* {@inheritDoc}
*/
public void setHorizontalAlignment(IRow row, IColumn column, HAlignment alignment) {
ICellStyle style = getCellSpecificStyle(row, column, true);
style.setHorizontalAlignment(alignment);
setCellStyle(row, column, style);
}
/**
* {@inheritDoc}
*/
public void setVerticalAlignment(IRow row, VAlignment alignment) {
ICellStyle style = getRowCellStyle(row, true);
style.setVerticalAlignment(alignment);
setRowCellStyle(row, style);
}
/**
* {@inheritDoc}
*/
public void setVerticalAlignment(IColumn column, VAlignment alignment) {
ICellStyle style = getColumnCellStyle(column, true);
style.setVerticalAlignment(alignment);
setColumnCellStyle(column, style);
}
/**
* {@inheritDoc}
*/
public void setVerticalAlignment(IRow row, IColumn column, VAlignment alignment) {
ICellStyle style = getCellSpecificStyle(row, column, true);
style.setVerticalAlignment(alignment);
setCellStyle(row, column, style);
}
/**
* {@inheritDoc}
*/
public void setFont(IRow row, FontData fontdata) {
ICellStyle style = getRowCellStyle(row, true);
style.setFont(fontdata);
setRowCellStyle(row, style);
}
/**
* {@inheritDoc}
*/
public void setFont(IColumn column, FontData fontdata) {
ICellStyle style = getColumnCellStyle(column, true);
style.setFont(fontdata);
setColumnCellStyle(column, style);
}
/**
* {@inheritDoc}
*/
public void setFont(IRow row, IColumn column, FontData fontdata) {
ICellStyle style = getCellSpecificStyle(row, column, true);
style.setFont(fontdata);
setCellStyle(row, column, style);
}
}
| 14,360 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ObjectImageRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/ObjectImageRenderer.java | /*
* File: ObjectImageRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.widgets.Display;
import de.jaret.util.ui.ResourceImageDescriptor;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* CellRenderer rendering object instances (i.e. enums) to images.
*
* @author Peter Kliem
* @version $Id: ObjectImageRenderer.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class ObjectImageRenderer extends CellRendererBase implements ICellRenderer {
protected Map<Object, String> _keyMap = new HashMap<Object, String>();
private ImageRegistry _imageRegistry;
public ObjectImageRenderer(Printer printer) {
super(printer);
}
public ObjectImageRenderer() {
super(null);
}
/**
* Add a mapping between an object instance and an image descriptor.
*
* @param o object instance
* @param key string key (has to be non null an unique for this renderer) to identfy the object
* @param imageDescriptor image descriptor for the image
*/
public void addObjectImageDescriptorMapping(Object o, String key, ImageDescriptor imageDescriptor) {
getImageRegistry().put(key, imageDescriptor);
_keyMap.put(o, key);
}
/**
* Add a mapping between object instance and an image ressource.
*
* @param o object instance
* @param key string key (has to be non null an unique for this renderer) to identfy the object
* @param ressourceName ressource path
*/
public void addObjectRessourceNameMapping(Object o, String key, String ressourceName) {
ImageDescriptor imgDesc = new ResourceImageDescriptor(ressourceName, this.getClass());
addObjectImageDescriptorMapping(o, key, imgDesc);
}
/**
* {@inheritDoc}
*/
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
IColumn column, boolean drawFocus, boolean selected, boolean printing) {
drawBackground(gc, drawingArea, cellStyle, selected, printing);
Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
Rectangle rect = applyInsets(drect);
Object value = column.getValue(row);
String key = _keyMap.get(value);
if (key != null) {
Image img = null;
img = getImageRegistry().get(key);
int x = rect.x + (rect.width - scaleX(img.getBounds().width)) / 2;
int y = rect.y + (rect.height - scaleY(img.getBounds().height)) / 2;
gc.drawImage(img, 0, 0, img.getBounds().width, img.getBounds().height, x, y, scaleX(img.getBounds().width),
scaleY(img.getBounds().height));
} else {
// indicate error with red fill
Color bg = gc.getBackground();
gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_MAGENTA));
gc.fillRectangle(rect);
gc.setBackground(bg);
}
if (drawFocus) {
drawFocus(gc, drect);
}
drawSelection(gc, drawingArea, cellStyle, selected, printing);
}
/**
* {@inheritDoc}
*
* @TODO
*/
public int getPreferredWidth(List<IRow> rows, IColumn column) {
return -1;// return getImageRegistry().get(CHECKED).getBounds().width;
}
/**
* {@inheritDoc} TODO
*/
public int getPreferredHeight(GC gc, ICellStyle cellStyle, int width, IRow row, IColumn column) {
return -1;// getImageRegistry().get(CHECKED).getBounds().height;
}
/**
* Retrieve the image registry instance.
*
* @return ImageRegistry
*/
private synchronized ImageRegistry getImageRegistry() {
if (_imageRegistry == null) {
_imageRegistry = new ImageRegistry();
}
return _imageRegistry;
}
/**
* {@inheritDoc} Disposes the image registry and clears the map with object instances to help garbage collecting.
*/
public void dispose() {
if (_imageRegistry != null) {
_imageRegistry.dispose();
}
_keyMap.clear();
}
/**
* {@inheritDoc}
*/
public ICellRenderer createPrintRenderer(Printer printer) {
ObjectImageRenderer renderer = new ObjectImageRenderer(printer);
for (Object o : _keyMap.keySet()) {
String key = _keyMap.get(o);
ImageDescriptor imageDesc = getImageRegistry().getDescriptor(key);
renderer.addObjectImageDescriptorMapping(o, key, imageDesc);
}
return renderer;
}
}
| 5,598 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ClassImageRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/ClassImageRenderer.java | /*
* File: ClassImageRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.widgets.Display;
import de.jaret.util.ui.ResourceImageDescriptor;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* CellRenderer rendering images corresponding to the class of the value.
*
* @author Peter Kliem
* @version $Id: ClassImageRenderer.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class ClassImageRenderer extends CellRendererBase implements ICellRenderer {
protected Map<Class, String> _keyMap = new HashMap<Class, String>();
private ImageRegistry _imageRegistry;
public ClassImageRenderer(Printer printer) {
super(printer);
}
public ClassImageRenderer() {
super(null);
}
/**
* Add a mapping between a class and an image descriptor.
*
* @param clazz the class
* @param key string key (has to be non null an unique for this renderer) to identfy the object
* @param imageDescriptor image descriptor for the image
*/
public void addClassImageDescriptorMapping(Class<?> clazz, String key, ImageDescriptor imageDescriptor) {
getImageRegistry().put(key, imageDescriptor);
_keyMap.put(clazz, key);
}
/**
* Add a mapping between a class and an image ressource.
*
* @param clazz class
* @param key string key (has to be non null an unique for this renderer) to identfy the object
* @param ressourceName ressource path
*/
public void addClassRessourceNameMapping(Class<?> clazz, String key, String ressourceName) {
ImageDescriptor imgDesc = new ResourceImageDescriptor(ressourceName, this.getClass());
addClassImageDescriptorMapping(clazz, key, imgDesc);
}
/**
* Retrieve the key for a class, checking all super classes and interfaces.
*
* @param clazz class to check
* @return key or null
*/
protected String getKeyForClass(Class<?> clazz) {
String result = _keyMap.get(clazz);
if (result != null) {
return result;
}
Class<?>[] interfaces = clazz.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
result = _keyMap.get(interfaces[i]);
if (result != null) {
return result;
}
}
Class<?> sc = clazz.getSuperclass();
if (sc != null) {
result = getKeyForClass(sc);
}
return result;
}
/**
* {@inheritDoc}
*/
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
IColumn column, boolean drawFocus, boolean selected, boolean printing) {
drawBackground(gc, drawingArea, cellStyle, selected, printing);
Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
Rectangle rect = applyInsets(drect);
Object value = column.getValue(row);
String key = getKeyForClass(value.getClass());
if (key != null) {
Image img = null;
img = getImageRegistry().get(key);
int x = rect.x + (rect.width - scaleX(img.getBounds().width)) / 2;
int y = rect.y + (rect.height - scaleY(img.getBounds().height)) / 2;
gc.drawImage(img, 0, 0, img.getBounds().width, img.getBounds().height, x, y, scaleX(img.getBounds().width),
scaleY(img.getBounds().height));
} else {
// indicate error with red fill
Color bg = gc.getBackground();
gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_MAGENTA));
gc.fillRectangle(rect);
gc.setBackground(bg);
}
if (drawFocus) {
drawFocus(gc, drect);
}
drawSelection(gc, drawingArea, cellStyle, selected, printing);
}
/**
* {@inheritDoc}
*
* @TODO
*/
public int getPreferredWidth(List<IRow> rows, IColumn column) {
return -1;// return getImageRegistry().get(CHECKED).getBounds().width;
}
/**
* {@inheritDoc} TODO
*/
public int getPreferredHeight(GC gc, ICellStyle cellStyle, int width, IRow row, IColumn column) {
return -1;// getImageRegistry().get(CHECKED).getBounds().height;
}
/**
* Retrieve the image registry instance.
*
* @return ImageRegistry
*/
private synchronized ImageRegistry getImageRegistry() {
if (_imageRegistry == null) {
_imageRegistry = new ImageRegistry();
}
return _imageRegistry;
}
/**
* {@inheritDoc} Disposes the image registry and clears the key map to help garbage collecting.
*/
public void dispose() {
if (_imageRegistry != null) {
_imageRegistry.dispose();
}
_keyMap.clear();
}
/**
* {@inheritDoc}
*/
public ICellRenderer createPrintRenderer(Printer printer) {
ClassImageRenderer renderer = new ClassImageRenderer(printer);
for (Class<?> clazz : _keyMap.keySet()) {
String key = _keyMap.get(clazz);
ImageDescriptor imageDesc = getImageRegistry().getDescriptor(key);
renderer.addClassImageDescriptorMapping(clazz, key, imageDesc);
}
return renderer;
}
}
| 6,354 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ICellRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/ICellRenderer.java | /*
* File: ICellRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import java.util.List;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.printing.Printer;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Interface for a cell renderer for a jaret table.
*
* @author Peter Kliem
* @version $Id: ICellRenderer.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public interface ICellRenderer {
/**
* Draw a single cell. The draw method should be null safe (handling null as the cell value).
*
* @param gc GC to paint on
* @param jaretTable table the rendering is for
* @param cellStyle style of the cell
* @param drawingArea rectangle to draw within
* @param row row of the cell to paint
* @param column column of the cell to paint
* @param drawFocus true if a focus mark should be drawn
* @param selected true if the cell is currently selected
* @param printing true if the render operation is for a printer
*/
void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row, IColumn column,
boolean drawFocus, boolean selected, boolean printing);
/**
* Calculate the preferred width for the column.
*
* @param rows the rows currently displayed by the table
* @param column the column for which the preferred width is to be calculated
* @return the preferred width or -1 for no special preferred width.
*/
int getPreferredWidth(List<IRow> rows, IColumn column);
/**
* Calculate the preferred height of a specific cell.
*
* @param gc GC that will used
* @param cellStyle cell style of the cell
* @param width width of the column (thus of the cell)
* @param row row
* @param column column
* @return the preferred height or -1 for no special preferred height
*/
int getPreferredHeight(GC gc, ICellStyle cellStyle, int width, IRow row, IColumn column);
/**
* Provide a tooltip text for display.
*
* @param jaretTable table that is asking
* @param drawingArea area of the cell rendering
* @param row row
* @param column column
* @param x mouse x coordinate (absolute within drawing area)
* @param y mouse y coordinate (abs within drawing area)
* @return tootip text or <code>null</code> if no tooltip is to be shown
*/
String getTooltip(JaretTable jaretTable, Rectangle drawingArea, IRow row, IColumn column, int x, int y);
/**
* Create a renderer connfigured for printing.
*
* @param printer printer to use
* @return a configured renderer for printing
*/
ICellRenderer createPrintRenderer(Printer printer);
/**
* If there are resources to free - this is the place.
*
*/
void dispose();
}
| 3,436 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ImageCellRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/ImageCellRenderer.java | /*
* File: ImageCellRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.widgets.Display;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* CellRenderer rendering an image.
*
* @author Peter Kliem
* @version $Id: ImageCellRenderer.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class ImageCellRenderer extends CellRendererBase implements ICellRenderer {
/**
* Construct an image cell renderer for use with a printer.
*
* @param printer printer
*/
public ImageCellRenderer(Printer printer) {
super(printer);
}
/**
* Construct an image cell renderer for display use.
*
*/
public ImageCellRenderer() {
super(null);
}
/**
* {@inheritDoc}
*/
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
IColumn column, boolean drawFocus, boolean selected, boolean printing) {
drawBackground(gc, drawingArea, cellStyle, selected, printing);
Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
Rectangle rect = applyInsets(drect);
Object value = column.getValue(row);
if (value != null) {
if (value instanceof Image) {
Image img = (Image) value;
int x = rect.x + (rect.width - img.getBounds().width) / 2;
int y = rect.y + (rect.height - img.getBounds().height) / 2;
gc.drawImage(img, x, y);
} else {
// indicate error with red fill
Color bg = gc.getBackground();
gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
gc.fillRectangle(rect);
gc.setBackground(bg);
}
}
if (drawFocus) {
drawFocus(gc, drawingArea);
}
drawSelection(gc, drawingArea, cellStyle, selected, printing);
}
// public int getPreferredWidth(List<IRow> rows, IColumn column) {
// int max = 0;
// for (IRow row : rows) {
// Image img = (Image)column.getValue(row);
// if (img.getBounds().width > max) {
// max = img.getBounds().width;
// }
// }
// return max;
// }
// public int getPreferredHeight(IRow row, IColumn column) {
// Image img = (Image)column.getValue(row);
// return img.getBounds().height;
// }
//
/**
* {@inheritDoc}
*/
public void dispose() {
// nothing to dispose
}
/**
* {@inheritDoc}
*/
public ICellRenderer createPrintRenderer(Printer printer) {
return new ImageCellRenderer(printer);
}
}
| 3,490 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ICellStyle.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/ICellStyle.java | /*
* File: ICellStyle.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import de.jaret.util.misc.PropertyObservable;
import de.jaret.util.ui.table.model.ITableViewState;
/**
* Interface describing the style of a cell.
*
* @author Peter Kliem
* @version $Id: ICellStyle.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public interface ICellStyle extends PropertyObservable {
/** property name. */
String HORIZONTAL_ALIGNMENT = "HorizontalAlignment";
/** property name. */
String VERTICAL_ALIGNMENT = "VerticalAlignment";
/** property name. */
String BACKGROUNDCOLOR = "BackgroundColor";
/** property name. */
String FOREGROUNDCOLOR = "ForegroundColor";
/** property name. */
String FONT = "Font";
/** property name. */
String BORDERCONFIGURATION = "BorderConfiguration";
/** property name. */
String BORDERCOLOR = "BorderColor";
/**
* Retrieve the border configuration.
*
* @return the border configuration
*/
IBorderConfiguration getBorderConfiguration();
/**
* Set the border configuration.
*
* @param borderConfiguration the onfiguration to use
*/
void setBorderConfiguration(IBorderConfiguration borderConfiguration);
/**
* Retrieve the border color.
*
* @return border color
*/
RGB getBorderColor();
/**
* Set the border color.
*
* @param bordercolor border color
*/
void setBorderColor(RGB bordercolor);
/**
* Retrieve the foreground color.
*
* @return the foreground color
*/
RGB getForegroundColor();
/**
* Set the foreground color.
*
* @param foreground the fore ground colro to use
*/
void setForegroundColor(RGB foreground);
/**
* Retrieve the background color.
*
* @return the background color
*/
RGB getBackgroundColor();
/**
* Set the background color.
*
* @param background the color to use
*/
void setBackgroundColor(RGB background);
/**
* Retrieve the font.
*
* @return the font data for the font to use
*/
FontData getFont();
/**
* Set the font.
*
* @param fontdata font data of the font
*/
void setFont(FontData fontdata);
/**
* Retrieve the horizontal alignment.
*
* @return the horizontal alignment
*/
ITableViewState.HAlignment getHorizontalAlignment();
/**
* Set the horizontal alignment.
*
* @param alignment the horizontal alignment
*/
void setHorizontalAlignment(ITableViewState.HAlignment alignment);
/**
* Retrieve the vertical alignment.
*
* @return the vertical alignment
*/
ITableViewState.VAlignment getVerticalAlignment();
/**
* Set the vertical alignemnt.
*
* @param alignment the vertical alignment
*/
void setVerticalAlignment(ITableViewState.VAlignment alignment);
boolean getMultiLine();
void setMultiLine(boolean multiLine);
/**
* Copy the cell style.
*
* @return a copy of the cell style
*/
ICellStyle copy();
}
| 3,794 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IHierarchyRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/IHierarchyRenderer.java | /*
* File: IHierarchyRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import org.eclipse.swt.graphics.Rectangle;
import de.jaret.util.ui.table.model.IRow;
/**
* Interface specifying extensions to the ICellRenderer interface necessary for hierarchy handling.
*
* @author Peter Kliem
* @version $Id: IHierarchyRenderer.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public interface IHierarchyRenderer extends ICellRenderer {
/**
* Should return true if a click on the coordinates x,y should toggle expanded state.
*
* @param row row
* @param drawingarea drawing area of the hierarchy section of the row
* @param x x coordinate to check
* @param y y coordinate to check
* @return true if the click is in the acive area
*/
boolean isInActiveArea(IRow row, Rectangle drawingarea, int x, int y);
}
| 1,273 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DoubleCellRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/DoubleCellRenderer.java | /*
* File: DoubleCellRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.eclipse.swt.printing.Printer;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* CellRenderer for double values.
*
* @author Peter Kliem
* @version $Id: DoubleCellRenderer.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class DoubleCellRenderer extends TextCellRenderer {
/** default fraction digits. */
protected static final int DEFAULT_FRACTION_DIGITS = 2;
/** number format for text converson. */
protected NumberFormat _numberFormat = DecimalFormat.getIntegerInstance();
/**
* Construct a double cell renderer for printing.
*
* @param printer printer device
*/
public DoubleCellRenderer(Printer printer) {
super(printer);
_numberFormat.setMaximumFractionDigits(DEFAULT_FRACTION_DIGITS);
_numberFormat.setMinimumFractionDigits(DEFAULT_FRACTION_DIGITS);
}
/**
* Construct a double cell renderer for use with a display.
*/
public DoubleCellRenderer() {
this(null);
}
/**
* Retrieve the used number format.
*
* @return number format
*/
public NumberFormat getNumberFormat() {
return _numberFormat;
}
/**
* Set number format used for text conversion.
*
* @param numberFormat number format
*/
public void setNumberFormat(NumberFormat numberFormat) {
_numberFormat = numberFormat;
}
/**
* {@inheritDoc}
*/
protected String convertValue(IRow row, IColumn column) {
Double value = (Double) column.getValue(row);
return value != null ? _numberFormat.format(value.doubleValue()) : null;
}
/**
* {@inheritDoc}
*/
public ICellRenderer createPrintRenderer(Printer printer) {
DoubleCellRenderer dcr = new DoubleCellRenderer(printer);
dcr.setNumberFormat(getNumberFormat());
return dcr;
}
}
| 2,532 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
RendererBase.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/RendererBase.java | /*
* File: RendererBase.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.printing.Printer;
/**
* Base implementation for renderers that support both screen and printer rendering. It's main purpose is scaling
* beetween screen and printer coordinates (based on 96dpi for the screen).
*
* @author Peter Kliem
* @version $Id: RendererBase.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public abstract class RendererBase {
/** printer if used. */
protected Printer _printer;
/** constant for scaling: screen resolution x. */
protected static final double SCREEN_DPI_X = 96.0;
/** constant for scaling: screen resolution y. */
protected static final double SCREEN_DPI_Y = 96.0;
/** x scaling for transformation beetwenn screen and printer. */
protected double _scaleX = 1.0;
/** y scaling for transformation beetwenn screen and printer. */
protected double _scaleY = 1.0;
/** for saving gc attribute. */
private Color _bgColor;
/** for saving gc attribute. */
private Color _fgColor;
/** for saving gc attribute. */
private int _lineWidth;
/** for saving gc attribute. */
private Font _font;
/**
* May be constructed without printer (supplying null).
*
* @param printer or <code>null</code>
*/
public RendererBase(Printer printer) {
_printer = printer;
if (_printer != null) {
Point dpi = _printer.getDPI();
_scaleX = (double) dpi.x / SCREEN_DPI_X;
_scaleY = (double) dpi.y / SCREEN_DPI_Y;
}
}
/**
* Scale an x coordinate/size from screen to printer.
*
* @param in corodinate/size to scale
* @return scaled value
*/
public int scaleX(int in) {
return (int) Math.round(_scaleX * (double) in);
}
/**
* Retrieve the x scale factor.
*
* @return x scale factor
*/
public double getScaleX() {
return _scaleX;
}
/**
* Scale an y coordinate/size from screen to printer.
*
* @param in corodinate/size to scale
* @return scaled value
*/
public int scaleY(int in) {
return (int) Math.round(_scaleY * (double) in);
}
/**
* Retrieve the y scale factor.
*
* @return y scale factor
*/
public double getScaleY() {
return _scaleY;
}
/**
* Retrieve the printer device.
*
* @return printer device if set <code>null</code> otherwise
*/
public Printer getPrinter() {
return _printer;
}
/**
* Helper method saving several GC attributes to loal variables. The values can be restored with
* <code>restoreGCAttributes</code>.
*
* @param gc GC to save attributes for
*/
protected void saveGCAttributes(GC gc) {
_bgColor = gc.getBackground();
_fgColor = gc.getForeground();
_font = gc.getFont();
_lineWidth = gc.getLineWidth();
}
/**
* Helper method to restore attribute values saved with <code>saveGCAttributes</code>.
*
* @param gc GC to restore attributes for
*/
protected void restoreGCAttributes(GC gc) {
if (_bgColor == null) {
throw new RuntimeException("no attributes saved");
}
gc.setBackground(_bgColor);
gc.setForeground(_fgColor);
gc.setFont(_font);
gc.setLineWidth(_lineWidth);
}
}
| 4,122 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
SmileyCellRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/SmileyCellRenderer.java | /*
* File: SmileyCellRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import javax.swing.BoundedRangeModel;
import javax.swing.DefaultBoundedRangeModel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Path;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.widgets.Display;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Fun renderer rendering an integer as a smiley.
*
* @TODO Printing
*
* @author Peter Kliem
* @version $Id: SmileyCellRenderer.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class SmileyCellRenderer extends CellRendererBase implements ICellRenderer {
private BoundedRangeModel _brModel = new DefaultBoundedRangeModel(50, 0, 0, 100);
private boolean _eyeBrows = true;
private boolean _colorChange = true;
/** if true, rendering will be alwa limited to a maximal square, forcing the smiley to be a circle. */
private boolean _forceCircle = true;
private Color _neutral;
private Color _positive;
private Color _negative;
private Color _currentColor;
private Color _black;
private double _currentValue;
public SmileyCellRenderer(Printer printer) {
super(printer);
if (printer != null) {
_neutral = printer.getSystemColor(SWT.COLOR_YELLOW);
_positive = printer.getSystemColor(SWT.COLOR_GREEN);
_negative = printer.getSystemColor(SWT.COLOR_RED);
_black = printer.getSystemColor(SWT.COLOR_BLACK);
}
}
public SmileyCellRenderer() {
super(null);
_neutral = Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW);
_positive = Display.getCurrent().getSystemColor(SWT.COLOR_GREEN);
_negative = Display.getCurrent().getSystemColor(SWT.COLOR_RED);
_black = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
}
/**
* {@inheritDoc}
*/
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
IColumn column, boolean drawFocus, boolean selected, boolean printing) {
drawBackground(gc, drawingArea, cellStyle, selected, printing);
Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
Rectangle rect = applyInsets(drect);
Object value = column.getValue(row);
if (value != null) {
saveGCAttributes(gc);
int val = ((Integer) value).intValue();
_brModel.setValue(val);
calcSmileFactor();
if (_forceCircle) {
int a = Math.min(rect.width, rect.height);
Rectangle nrect = new Rectangle(0, 0, a, a);
nrect.x = rect.x + (rect.width - a) / 2;
nrect.y = rect.y + (rect.height - a) / 2;
rect = nrect;
}
int width = rect.width;
int height = rect.height;
int offx = rect.x;
int offy = rect.y;
float foffx = (float) offx;
float foffy = (float) offy;
int lineWidth = height / 40;
if (!_colorChange) {
gc.setBackground(_neutral);
} else {
if (_currentValue >= 0) { // positive
gc.setBackground(calcColor(_positive, printing));
} else { // negative
gc.setBackground(calcColor(_negative, printing));
}
}
Device device = printing ? _printer : Display.getCurrent();
Path p = new Path(device);
p.addArc(foffx + 0 + lineWidth / 2, foffy + 0 + lineWidth / 2, width - 1 - lineWidth, height - 1
- lineWidth, 0, 360);
gc.fillPath(p);
gc.setForeground(_black);
gc.setLineWidth(lineWidth);
gc.drawPath(p);
p.dispose();
// eyes
int y = height / 3;
int x1 = width / 3;
int x2 = width - width / 3;
int r = width / 30;
// eyes have a minimal size
if (r == 0) {
r = 1;
}
gc.setBackground(_black);
gc.fillOval(offx + x1 - r, offy + y - r, 2 * r, 2 * r);
gc.fillOval(offx + x2 - r, offy + y - r, 2 * r, 2 * r);
// eye brows
if (_eyeBrows) {
gc.setLineWidth(lineWidth / 2);
int ebWidth = width / 10;
int yDist = height / 13;
int yOff = (int) (_currentValue * (double) height / 30);
int xShift = (int) (_currentValue * (double) width / 90);
p = new Path(device);
p.moveTo(foffx + x1 - ebWidth / 2 + xShift, foffy + y - yDist + yOff);
p.lineTo(foffx + x1 + ebWidth / 2 - xShift, foffy + y - yDist - yOff);
gc.drawPath(p);
p.dispose();
p = new Path(device);
p.moveTo(foffx + x2 - ebWidth / 2 + xShift, foffy + y - yDist - yOff);
p.lineTo(foffx + x2 + ebWidth / 2 - xShift, foffy + y - yDist + yOff);
gc.drawPath(p);
p.dispose();
}
// mouth
gc.setLineWidth(lineWidth);
x1 = (int) (width / 4.5);
x2 = width - x1;
y = height - height / 3;
int midX = width / 2;
int offset = (int) (_currentValue * (double) height / 3);
p = new Path(Display.getCurrent());
p.moveTo(foffx + x1, foffy + y);
p.quadTo(foffx + midX, foffy + y + offset, foffx + x2, foffy + y);
gc.drawPath(p);
p.dispose();
restoreGCAttributes(gc);
}
if (drawFocus) {
drawFocus(gc, drect);
}
drawSelection(gc, drawingArea, cellStyle, selected, printing);
}
/**
* Scales the BoundedRangeModel to [-1, 1]
*/
private void calcSmileFactor() {
int range = _brModel.getMaximum() - _brModel.getMinimum();
int mid = _brModel.getMinimum() + range / 2;
int value = _brModel.getValue();
_currentValue = (double) (value - mid) / (double) (range / 2);
// due to rounding errors the smileFactor may be over 1
if (_currentValue > 1) {
_currentValue = 1;
} else if (_currentValue < -1) {
_currentValue = -1;
}
}
/**
* Calculates the color beetween _neutral and the specified color
*
* @param destColor
* @return the mixed color
*/
private Color calcColor(Color destColor, boolean printing) {
int rDiff = destColor.getRed() - _neutral.getRed();
int gDiff = destColor.getGreen() - _neutral.getGreen();
int bDiff = destColor.getBlue() - _neutral.getBlue();
double factor = Math.abs(_currentValue);
int r = (int) ((double) rDiff * factor);
int g = (int) ((double) gDiff * factor);
int b = (int) ((double) bDiff * factor);
if (_currentColor != null) {
_currentColor.dispose();
}
if (!printing) {
_currentColor = new Color(Display.getCurrent(), _neutral.getRed() + r, _neutral.getGreen() + g, _neutral
.getBlue()
- b);
} else {
_currentColor = new Color(_printer, _neutral.getRed() + r, _neutral.getGreen() + g, _neutral.getBlue() - b);
}
return _currentColor;
}
/**
* {@inheritDoc}
*/
public void dispose() {
if (_currentColor != null) {
_currentColor.dispose();
}
}
/**
* {@inheritDoc}
*/
public ICellRenderer createPrintRenderer(Printer printer) {
// return new SmileyCellRenderer(printer);
// TODO there is a printing problem with using path on a printer, so use a text cell renderer instead
return new TextCellRenderer(printer);
}
}
| 8,813 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultCellStyle.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/DefaultCellStyle.java | /*
* File: DefaultCellStyle.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import de.jaret.util.misc.PropertyObservableBase;
import de.jaret.util.ui.table.model.ITableViewState;
import de.jaret.util.ui.table.model.ITableViewState.HAlignment;
import de.jaret.util.ui.table.model.ITableViewState.VAlignment;
/**
* Default implementation of ICellStyle.
*
* @author Peter Kliem
* @version $Id: DefaultCellStyle.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class DefaultCellStyle extends PropertyObservableBase implements ICellStyle {
/** the border configuraion. */
protected IBorderConfiguration _borderConfiguration;
/** foreground color as RGB (no color ressource here). */
protected RGB _foregroundColor;
/** background color as RGB (no color ressource here). */
protected RGB _backgroundColor;
/** border color as RGB (no color ressource here). */
protected RGB _borderColor;
/** the font data to use (no font ressource here). */
protected FontData _font;
/** horizontal alignement. */
protected ITableViewState.HAlignment _hAlignment = ITableViewState.HAlignment.LEFT;
/** vertical alignment. */
protected ITableViewState.VAlignment _vAlignment = ITableViewState.VAlignment.TOP;
/** should allow multinline.*/
protected boolean _multiLine = true;
/**
* Construct a new default cell style.
*
* @param foregroundColor forgeround
* @param backgroundColor background
* @param borderConfiguration border config
* @param font fontdata
*/
public DefaultCellStyle(RGB foregroundColor, RGB backgroundColor, IBorderConfiguration borderConfiguration,
FontData font) {
_foregroundColor = foregroundColor;
_backgroundColor = backgroundColor;
_borderConfiguration = borderConfiguration;
_font = font;
}
/**
* {@inheritDoc}
*/
public DefaultCellStyle copy() {
DefaultCellStyle cs = new DefaultCellStyle(_foregroundColor, _backgroundColor, _borderConfiguration.copy(),
_font);
cs.setHorizontalAlignment(_hAlignment);
cs.setVerticalAlignment(_vAlignment);
return cs;
}
/**
* @return Returns the backgroundColor.
*/
public RGB getBackgroundColor() {
return _backgroundColor;
}
/**
* @param backgroundColor The backgroundColor to set.
*/
public void setBackgroundColor(RGB backgroundColor) {
if (isRealModification(_backgroundColor, backgroundColor)) {
RGB oldVal = _backgroundColor;
_backgroundColor = backgroundColor;
firePropertyChange(BACKGROUNDCOLOR, oldVal, backgroundColor);
}
}
/**
* @return Returns the borderColor.
*/
public RGB getBorderColor() {
return _borderColor;
}
/**
* {@inheritDoc}
*/
public void setBorderColor(RGB borderColor) {
if (isRealModification(_borderColor, borderColor)) {
RGB oldVal = _borderColor;
_borderColor = borderColor;
firePropertyChange(BORDERCOLOR, oldVal, borderColor);
}
}
/**
* @return Returns the borderConfiguration.
*/
public IBorderConfiguration getBorderConfiguration() {
return _borderConfiguration;
}
/**
* {@inheritDoc}
*/
public void setBorderConfiguration(IBorderConfiguration borderConfiguration) {
if (isRealModification(_borderConfiguration, borderConfiguration)) {
IBorderConfiguration oldVal = _borderConfiguration;
_borderConfiguration = borderConfiguration;
firePropertyChange(BORDERCONFIGURATION, oldVal, borderConfiguration);
}
}
/**
* @return Returns the font.
*/
public FontData getFont() {
return _font;
}
/**
* @param font The font to set.
*/
public void setFont(FontData font) {
if (isRealModification(_font, font)) {
FontData oldVal = _font;
_font = font;
firePropertyChange(FONT, oldVal, font);
}
}
/**
* @return Returns the foregroundColor.
*/
public RGB getForegroundColor() {
return _foregroundColor;
}
/**
* @param foregroundColor The foregroundColor to set.
*/
public void setForegroundColor(RGB foregroundColor) {
if (isRealModification(_foregroundColor, foregroundColor)) {
RGB oldVal = _foregroundColor;
_foregroundColor = foregroundColor;
firePropertyChange(FOREGROUNDCOLOR, oldVal, foregroundColor);
}
}
/**
* {@inheritDoc}
*/
public HAlignment getHorizontalAlignment() {
return _hAlignment;
}
/**
* {@inheritDoc}
*/
public void setHorizontalAlignment(HAlignment alignment) {
if (!_hAlignment.equals(alignment)) {
HAlignment oldVal = _hAlignment;
_hAlignment = alignment;
firePropertyChange(HORIZONTAL_ALIGNMENT, oldVal, alignment);
}
}
/**
* {@inheritDoc}
*/
public VAlignment getVerticalAlignment() {
return _vAlignment;
}
/**
* {@inheritDoc}
*/
public void setVerticalAlignment(VAlignment alignment) {
if (!_vAlignment.equals(alignment)) {
VAlignment oldVal = _vAlignment;
_vAlignment = alignment;
firePropertyChange(VERTICAL_ALIGNMENT, oldVal, alignment);
}
}
/**
* @return Returns the multiLine.
*/
public boolean getMultiLine() {
return _multiLine;
}
/**
* @param multiLine The multiLine to set.
*/
public void setMultiLine(boolean multiLine) {
_multiLine = multiLine;
}
}
| 6,466 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IBorderConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/IBorderConfiguration.java | /*
* File: IBorderConfiguration.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
/**
* Interface describing a border to be rendered around a cell.
*
* @author Peter Kliem
* @version $Id: IBorderConfiguration.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public interface IBorderConfiguration {
/**
* Get left border width.
*
* @return border width in pixels
*/
int getBorderLeft();
/**
* Get right border width.
*
* @return border width in pixels
*/
int getBorderRight();
/**
* Get top border width.
*
* @return border width in pixels
*/
int getBorderTop();
/**
* Get bottom border width.
*
* @return border width in pixels
*/
int getBorderBottom();
/**
* Produce a copy of this border configuration.
*
* @return copy of the configuration
*/
IBorderConfiguration copy();
}
| 1,363 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
BooleanCellRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/BooleanCellRenderer.java | /*
* File: BooleanCellRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import java.util.List;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.widgets.Display;
import de.jaret.util.ui.ResourceImageDescriptor;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* CellRenderer rendering a Boolean to a checkbox image (default) or any other two images.
*
* @author Peter Kliem
* @version $Id: BooleanCellRenderer.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class BooleanCellRenderer extends CellRendererBase implements ICellRenderer {
/** rsc name for the checked state. */
protected String _checkedRscName = "/de/jaret/util/ui/table/resource/checked.gif";
/** default rsc name for the unchecked state. */
protected String _uncheckedRscName = "/de/jaret/util/ui/table/resource/unchecked.gif";
/** key for checked image in registry. */
protected static final String CHECKED = "checked";
/** key for unchecked image in registry. */
protected static final String UNCHECKED = "unchecked";
/** image registry for holding the images. */
private ImageRegistry _imageRegistry;
/**
* Construct a boolean cell renderer for a printer device using default resources.
*
* @param printer printer device
*/
public BooleanCellRenderer(Printer printer) {
super(printer);
}
/**
* Construct a boolean cell renderer for the display using default resources.
*/
public BooleanCellRenderer() {
super(null);
}
/**
* Construct a boolean cell renderer for a printer device providing resource names.
*
* @param printer printer device
* @param checkedRscName resource path for the checked image
* @param uncheckedRscName resource path for the unchecked image
*/
public BooleanCellRenderer(Printer printer, String checkedRscName, String uncheckedRscName) {
super(printer);
_checkedRscName = checkedRscName;
_uncheckedRscName = uncheckedRscName;
}
/**
* Construct a boolean cell renderer for the display providing resource names.
*
* @param checkedRscName resource path for the checked image
* @param uncheckedRscName resource path for the unchecked image
*/
public BooleanCellRenderer(String checkedRscName, String uncheckedRscName) {
super(null);
_checkedRscName = checkedRscName;
_uncheckedRscName = uncheckedRscName;
}
/**
* {@inheritDoc}
*/
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
IColumn column, boolean drawFocus, boolean selected, boolean printing) {
drawBackground(gc, drawingArea, cellStyle, selected, printing);
Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
Rectangle rect = applyInsets(drect);
Object value = column.getValue(row);
if (value instanceof Boolean) {
Image img = null;
if (((Boolean) value).booleanValue()) {
img = getImageRegistry().get(CHECKED);
} else {
img = getImageRegistry().get(UNCHECKED);
}
int x = rect.x + (rect.width - scaleX(img.getBounds().width)) / 2;
int y = rect.y + (rect.height - scaleY(img.getBounds().height)) / 2;
gc.drawImage(img, 0, 0, img.getBounds().width, img.getBounds().height, x, y, scaleX(img.getBounds().width),
scaleY(img.getBounds().height));
} else {
// indicate error with red fill
Color bg = gc.getBackground();
gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_MAGENTA));
gc.fillRectangle(rect);
gc.setBackground(bg);
}
if (drawFocus) {
drawFocus(gc, drect);
}
drawSelection(gc, drawingArea, cellStyle, selected, printing);
}
/**
* {@inheritDoc}
*/
public int getPreferredWidth(List<IRow> rows, IColumn column) {
return getImageRegistry().get(CHECKED).getBounds().width;
}
/**
* {@inheritDoc}
*/
public int getPreferredHeight(GC gc, ICellStyle cellStyle, int width, IRow row, IColumn column) {
return getImageRegistry().get(CHECKED).getBounds().height;
}
/**
* Retrieve the image registry used by the renderer (lazy initializing).
*
* @return initialized image regsitry containing the resources
*/
private ImageRegistry getImageRegistry() {
if (_imageRegistry == null) {
_imageRegistry = new ImageRegistry();
ImageDescriptor imgDesc = new ResourceImageDescriptor(_checkedRscName, this.getClass());
_imageRegistry.put(CHECKED, imgDesc.createImage());
imgDesc = new ResourceImageDescriptor(_uncheckedRscName, this.getClass());
_imageRegistry.put(UNCHECKED, imgDesc.createImage());
}
return _imageRegistry;
}
/**
* {@inheritDoc}
*/
public void dispose() {
if (_imageRegistry != null) {
_imageRegistry.dispose();
}
}
/**
* {@inheritDoc}
*/
public ICellRenderer createPrintRenderer(Printer printer) {
return new BooleanCellRenderer(printer, _checkedRscName, _uncheckedRscName);
}
}
| 6,291 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ITableHeaderRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/ITableHeaderRenderer.java | /*
* File: ITableHeaderRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.printing.Printer;
import de.jaret.util.ui.table.model.IColumn;
/**
* Interface describing a header renderer for the jaret table.
*
* @author Peter Kliem
* @version $Id: ITableHeaderRenderer.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public interface ITableHeaderRenderer {
/**
* Draw a table header.
*
* @param gc GC to be used
* @param rectangle rectangle to draw within
* @param column the column for which the header is painted.
* @param sortingPosition if the column is part of the sorting set this indicates the sorting order position. A
* value of 0 means no sorting.
* @param sortDir if sorting this indicates the sorting direction. <code>true</code> means ascending.
* @param printing true if the draw operation is for a printer
*/
void draw(GC gc, Rectangle rectangle, IColumn column, int sortingPosition, boolean sortDir, boolean printing);
/**
* If this method returns <code>true</code> the gc for drawing will not be limited by a clipping rect. This is
* useful for slanted header texts but should be used with the appropriate care.
*
* @return true if the rendering should not be clipped.
*/
boolean disableClipping();
/**
* Check whether a click hits the area reserved for sorting indication.
*
* @param drawingArea drawing aea of the header
* @param column column
* @param x x coordinat of the click
* @param y y coordinate of the click
* @return true if the click is in the area that should be active for sorting
*/
boolean isSortingClick(Rectangle drawingArea, IColumn column, int x, int y);
/**
* Create a table header renderer for printing.
*
* @param printer the printer that will be used
* @return a configured header renderer for printing.
*/
ITableHeaderRenderer getPrintRenderer(Printer printer);
/**
* Dispose any resources allocated.
*
*/
void dispose();
}
| 2,635 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DateCellRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/DateCellRenderer.java | /*
* File: DateCellRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import java.text.DateFormat;
import java.util.Date;
import org.eclipse.swt.printing.Printer;
import de.jaret.util.date.JaretDate;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Cell renderer for a date. Can also render a JaretDate.
*
* @author Peter Kliem
* @version $Id: DateCellRenderer.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class DateCellRenderer extends TextCellRenderer {
/** dateformat used to format the date to text. */
protected DateFormat _dateformat = DateFormat.getDateInstance(DateFormat.MEDIUM);
/**
* Construct a date cell renderer for a printer.
*
* @param printer priner device
*/
public DateCellRenderer(Printer printer) {
super(printer);
}
/**
* Construct a date cell renderer.
*/
public DateCellRenderer() {
super();
}
/**
* {@inheritDoc}
*/
protected String convertValue(IRow row, IColumn column) {
Object value = column.getValue(row);
if (value instanceof Date) {
Date date = (Date) value;
return _dateformat.format(date);
} else if (value instanceof JaretDate) {
Date date = ((JaretDate) value).getDate();
return _dateformat.format(date);
}
return "";
}
/**
* Retrive the used date format.
*
* @return Returns the dateformat.
*/
public DateFormat getDateformat() {
return _dateformat;
}
/**
* Set the dateformat used for text transformation.
*
* @param dateformat The dateformat to set.
*/
public void setDateformat(DateFormat dateformat) {
_dateformat = dateformat;
}
/**
* {@inheritDoc}
*/
public ICellRenderer createPrintRenderer(Printer printer) {
DateCellRenderer renderer = new DateCellRenderer(printer);
renderer.setDateformat(getDateformat());
return renderer;
}
}
| 2,538 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IStyleStrategy.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/IStyleStrategy.java | /*
* File: IStyleStrategy.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Interface for a strategy that can be added to a cell style provider to determine styles on the fly based on the
* content of the element (such as coloring the background of even rows).
*
* @author kliem
* @version $Id: IStyleStrategy.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public interface IStyleStrategy {
/**
* This method is called before a cell style is delivered to the jaret table (by getCellStyle(row, col) in the cell
* style provider). It gets the cell style regulary determined by the provider and the default cell style. It can
* then replace that style according to the strategy. The strategy should not alter the incoming style since this
* alters all cells using that style.
*
* @param row row
* @param column column
* @param incomingStyle the determined cell style
* @param defaultCellStyle the defalt cell style used by the provider
* @return cellstyle to be used by the table
*/
ICellStyle getCellStyle(IRow row, IColumn column, ICellStyle incomingStyle, ICellStyle defaultCellStyle);
}
| 1,669 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ICellStyleProvider.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/ICellStyleProvider.java | /*
* File: ICellStyleProvider.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
import de.jaret.util.ui.table.model.ITableViewState;
/**
* Interface for a cell style supplier. The cell style provider is responsible for storing the individual cell styles.
* It is possible to define a single style for a row, a column or a specific cell. A default cell style is used whenever
* no specific cell style has been set.
* <p>
* The interface operates on cell styles. In some cases this is quite inconvenient so som econvience methods have been
* added to support direct setting of the properties.
* </p>
*
* @author Peter Kliem
* @version $Id: ICellStyleProvider.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public interface ICellStyleProvider {
/**
* Set a style strategy to be involved when delivering styles.
*
* @param startegy strategy to use
*/
void setStyleStrategy(IStyleStrategy startegy);
/**
* Retrieve a style strategy if set.
*
* @return the strategy or <code>null</code>
*/
IStyleStrategy getStyleStrategy();
/**
* Retrieve the cell style for a cell. This method should not create CellStyle objects.
*
* @param row row of the cell
* @param column col of the cell
* @return cell style for the specified cell
*/
ICellStyle getCellStyle(IRow row, IColumn column);
/**
* Get the cell style defined for a single cell. Should create a new CellStyle object if create is true.
*
* @param row row of the cell
* @param column column of the cell
* @param create true will signal to create a new style object if necessary
* @return cell style for the cell
*/
ICellStyle getCellSpecificStyle(IRow row, IColumn column, boolean create);
/**
* Retrieve the cell style for a column.
*
* @param column column
* @param create if true and no style has been set for the column, create a copy of the default cell style
* @return the cellstyle for the colun which might be the default cell style if create is set to false
*/
ICellStyle getColumnCellStyle(IColumn column, boolean create);
/**
* Set the cell style for a column.
*
* @param column column
* @param style style
*/
void setColumnCellStyle(IColumn column, ICellStyle style);
/**
* Retrieve the cell style for a row.
*
* @param row row
* @param create if true and no style has been set for the row, create a copy of the default cell style
* @return the cellstyle for the row which might be the default cell style if create is set to false
*/
ICellStyle getRowCellStyle(IRow row, boolean create);
/**
* Set the cell style for a row.
*
* @param row row
* @param style cell style
*/
void setRowCellStyle(IRow row, ICellStyle style);
/**
* Set the cell style to use for a specific cell.
*
* @param row row of the cell
* @param column column of the cell
* @param style style to use
*/
void setCellStyle(IRow row, IColumn column, ICellStyle style);
/**
* Retrieve the default cell style used for cells where no style has been set. If the returned cell style is
* modified, this applies for all default styled cells.
*
* @return the default cell style.
*/
ICellStyle getDefaultCellStyle();
/**
* Set the default cell style that is used whenever no specific style has been set for a cell, column or row.
*
* @param cellStyle cell style to use as the default cell style
*/
void setDefaultCellStyle(ICellStyle cellStyle);
/**
* Add a listener to listen on cell style changes.
*
* @param csl listener
*/
void addCellStyleListener(ICellStyleListener csl);
/**
* Remove a cell sytle listener.
*
* @param csl listener to remove
*/
void remCellStyleListener(ICellStyleListener csl);
/**
* Convenience method for setting the background of a row. This method will manipulate or create a style.
*
* @param row row
* @param background background color
*/
void setBackground(IRow row, RGB background);
/**
* Convenience method for setting the background of a column. This method will manipulate or create a style.
*
* @param column column
* @param background background color
*/
void setBackground(IColumn column, RGB background);
/**
* Convenience method for setting the background of a cell. This method will manipulate or create a style.
*
* @param row row of th cell
* @param column column of the cell
* @param background background color
*/
void setBackground(IRow row, IColumn column, RGB background);
/**
* Convenience method for setting the foreground of a row. This method will manipulate or create a style.
*
* @param row row
* @param foreground background color
*/
void setForeground(IRow row, RGB foreground);
/**
* Convenience method for setting the foreground of a column. This method will manipulate or create a style.
*
* @param column column
* @param foreground foreground color
*/
void setForeground(IColumn column, RGB foreground);
/**
* Convenience method for setting the foreground of a cell. This method will manipulate or create a style.
*
* @param row row of th cell
* @param column column of the cell
* @param foreground foreground color
*/
void setForeground(IRow row, IColumn column, RGB foreground);
/**
* Convenience method for setting the horizontal alignment. The method will create a cell style for the element or
* manipulate the already set style.
*
* @param row row
* @param hAlignment horizontal alignment
*/
void setHorizontalAlignment(IRow row, ITableViewState.HAlignment hAlignment);
/**
* Convenience method for setting the horizontal alignment. The method will create a cell style for the element or
* manipulate the already set style.
*
* @param column column
* @param hAlignment horizontal alignment
*/
void setHorizontalAlignment(IColumn column, ITableViewState.HAlignment hAlignment);
/**
* Convenience method for setting the horizontal alignment. The method will create a cell style for the element or
* manipulate the already set style.
*
* @param row row of th cell
* @param column column of the cell
* @param hAlignment horizontal alignment
*/
void setHorizontalAlignment(IRow row, IColumn column, ITableViewState.HAlignment hAlignment);
/**
* Convenience method for setting the vertical alignment. The method will create a cell style for the element or
* manipulate the already set style.
*
* @param row row
* @param vAlignment vertical alignment
*/
void setVerticalAlignment(IRow row, ITableViewState.VAlignment vAlignment);
/**
* Convenience method for setting the vertical alignment. The method will create a cell style for the element or
* manipulate the already set style.
*
* @param column column
* @param vAlignment vertical alignment
*/
void setVerticalAlignment(IColumn column, ITableViewState.VAlignment vAlignment);
/**
* Convenience method for setting the vertical alignment. The method will create a cell style for the element or
* manipulate the already set style.
*
* @param row row of th cell
* @param column column of the cell
* @param vAlignment vertical alignment
*/
void setVerticalAlignment(IRow row, IColumn column, ITableViewState.VAlignment vAlignment);
/**
* Convenience method for setting the font. The method will create a cell style for the element or manipulate the
* already set style.
*
* @param row row
* @param fontdata font data for the font to use
*/
void setFont(IRow row, FontData fontdata);
/**
* Convenience method for setting the font. The method will create a cell style for the element or manipulate the
* already set style.
*
* @param column column
* @param fontdata font data for the font to use
*/
void setFont(IColumn column, FontData fontdata);
/**
* Convenience method for setting the font. The method will create a cell style for the element or manipulate the
* already set style.
*
* @param row row of th cell
* @param column column of the cell
* @param fontdata font data for the font to use
*/
void setFont(IRow row, IColumn column, FontData fontdata);
}
| 9,569 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ICellStyleListener.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/ICellStyleListener.java | /*
* File: ICellStyleListener.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Interface for a listener listening on style changes.
*
* @author Peter Kliem
* @version $Id: ICellStyleListener.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public interface ICellStyleListener {
/**
* Will be called whenever a style changed.
*
* @param row row
* @param column column
* @param style changed style
*/
void cellStyleChanged(IRow row, IColumn column, ICellStyle style);
}
| 1,016 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
TextCellRenderer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/renderer/TextCellRenderer.java | /*
* File: TextCellRenderer.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.renderer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.TextLayout;
import org.eclipse.swt.graphics.TextStyle;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.widgets.Display;
import de.jaret.util.swt.TextRenderer;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
import de.jaret.util.ui.table.model.ITableViewState;
/**
* TextCellRenderer for the jaret table. Features an integrated comment marker (tooltip), Override getComment() to use
* this. This CellRenderer may be used as the basis for a lot of toText-CellRenderers (see the DateCellRenderer)
*
* @author Peter Kliem
* @version $Id: TextCellRenderer.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class TextCellRenderer extends CellRendererBase implements ICellRenderer {
/** size of the comment arker. */
private static final int COMMENTMARKER_SIZE = 5;
/** color of the comment marker. */
protected Color _commentColor;
/**
* Create a text cell renderer for printing.
*
* @param printer printer device
*/
public TextCellRenderer(Printer printer) {
super(printer);
}
/**
* Create a text cell renderer for display.
*/
public TextCellRenderer() {
super(null);
_commentColor = Display.getCurrent().getSystemColor(SWT.COLOR_RED);
}
/**
* {@inheritDoc}
*/
public String getTooltip(JaretTable jaretTable, Rectangle drawingArea, IRow row, IColumn column, int x, int y) {
if (getComment(row, column) != null && isInCommentMarkerArea(drawingArea, COMMENTMARKER_SIZE, x, y)) {
return getComment(row, column);
}
return null;
}
/**
* Convert the value specified by row, column to a string. This method is ideally suited to be overidden by
* extensions of the textcellrenderer.
*
* @param row row of the cell
* @param column column of the cell
* @return String for the value
*/
protected String convertValue(IRow row, IColumn column) {
Object value = column.getValue(row);
return value != null ? value.toString() : null;
}
/**
* Override for using content marker and tooltip.
*
* @param row row of the cell
* @param column column of the cell
* @return comment as String or <code>null</code>
*/
protected String getComment(IRow row, IColumn column) {
return null;
}
/**
* {@inheritDoc}
*/
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
IColumn column, boolean drawFocus, boolean selected, boolean printing) {
drawBackground(gc, drawingArea, cellStyle, selected, printing);
Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
Rectangle rect = applyInsets(drect);
// convert the value to a string
String s = convertValue(row, column);
Color fg = gc.getForeground();
Color bg = gc.getBackground();
Font font = gc.getFont();
// draw comment marker if comment is present and not printing
if (!printing && getComment(row, column) != null) {
drawCommentMarker(gc, drawingArea, _commentColor, COMMENTMARKER_SIZE);
}
if (drawFocus) {
drawFocus(gc, drect);
}
drawSelection(gc, drawingArea, cellStyle, selected, printing);
gc.setForeground(fg);
gc.setBackground(bg);
gc.setFont(font);
if (s != null) {
if (selected && !printing) {
gc.setBackground(SELECTIONCOLOR);
} else {
gc.setBackground(getBackgroundColor(cellStyle, printing));
}
gc.setForeground(getForegroundColor(cellStyle, printing));
gc.setFont(getFont(cellStyle, printing, gc.getFont()));
drawCellString(gc, rect, s, cellStyle);
if (s.indexOf("we") != -1) {
TextLayout textLayout = new TextLayout(gc.getDevice());
textLayout.setText(s);
textLayout.setFont(gc.getFont());
textLayout.setWidth(rect.width);
Color color = new Color(gc.getDevice(), 150, 100, 100);
Font font2 = new Font(gc.getDevice(), gc.getFont().getFontData()[0].getName(), gc.getFont()
.getFontData()[0].getHeight(), SWT.ITALIC);
TextStyle style = new TextStyle(font2, color, null);
for (int i = 1; i < s.length(); i++) {
int j = indexOf(s, "we", i, false);
if (j != -1) {
textLayout.setStyle(style, j, j + 3);
} else {
break;
}
}
gc.fillRectangle(rect);
textLayout.draw(gc, rect.x, rect.y);
gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
}
}
}
public int indexOf(String srcStr, String str, int index, boolean isCaseSensitive) {
if (index == 0) {
return -1;
}
if (index == 1) {
if (isCaseSensitive) {
return srcStr.indexOf(str);
} else {
return srcStr.toUpperCase().indexOf(str.toUpperCase());
}
}
if (isCaseSensitive) {
return srcStr.indexOf(str, indexOf(srcStr, str, index - 1, isCaseSensitive) + str.length());
} else {
return srcStr.toUpperCase().indexOf(str.toUpperCase(),
indexOf(srcStr, str, index - 1, isCaseSensitive) + str.length());
}
}
/**
* Draw the string.
*
* @param gc gc
* @param rect drawing area
* @param s String to drw
* @param cellStyle the cell style
*/
private void drawCellString(GC gc, Rectangle rect, String s, ICellStyle cellStyle) {
if (cellStyle.getMultiLine()) {
drawCellStringMulti(gc, rect, s, cellStyle);
} else {
drawCellStringSingle(gc, rect, s);
}
}
/**
* Draw single line String.
*
* @param gc gc
* @param rect drawing area
* @param s String to draw
*/
private void drawCellStringSingle(GC gc, Rectangle rect, String s) {
gc.drawString(s, rect.x, rect.y + 10, true);
}
/**
* Draw a String in the drawing area, splitting it into multiple lines.
*
* @param gc gc
* @param rect drawing area
* @param s String to draw
* @param cellStyle cell style determing alignment
*/
private void drawCellStringMulti(GC gc, Rectangle rect, String s, ICellStyle cellStyle) {
int halign = TextRenderer.LEFT;
if (cellStyle.getHorizontalAlignment() == ITableViewState.HAlignment.RIGHT) {
halign = TextRenderer.RIGHT;
} else if (cellStyle.getHorizontalAlignment() == ITableViewState.HAlignment.CENTER) {
halign = TextRenderer.CENTER;
}
int valign = TextRenderer.TOP;
if (cellStyle.getVerticalAlignment() == ITableViewState.VAlignment.BOTTOM) {
valign = TextRenderer.BOTTOM;
} else if (cellStyle.getVerticalAlignment() == ITableViewState.VAlignment.CENTER) {
valign = TextRenderer.CENTER;
}
TextRenderer.renderText(gc, rect, true, false, s, halign, valign);
}
/**
* {@inheritDoc}
*/
public int getPreferredHeight(GC gc, ICellStyle cellStyle, int width, IRow row, IColumn column) {
Object value = convertValue(row, column);
Font font = gc.getFont();
int height = -1;
if (value != null) {
String s = value.toString();
gc.setFont(getFont(cellStyle, false, gc.getFont()));
height = TextRenderer.getHeight(gc, getInnerWidth(width, cellStyle), true, s);
}
gc.setFont(font);
return height + getVerticalSpacesSum(cellStyle);
}
/**
* {@inheritDoc}
*/
public void dispose() {
// nothing to dispose
}
/**
* {@inheritDoc}
*/
public ICellRenderer createPrintRenderer(Printer printer) {
return new TextCellRenderer(printer);
}
}
| 9,014 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
JaretTablePrintDialog.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/print/JaretTablePrintDialog.java | /*
* File: JaretTablePrintDialog.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.print;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.printing.PrintDialog;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.printing.PrinterData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell;
import de.jaret.util.ui.table.JaretTablePrinter;
/**
* Simple print dialog for a jaret table.
*
* @author Peter Kliem
* @version $Id: JaretTablePrintDialog.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class JaretTablePrintDialog extends Dialog {
protected static PrinterData _printerData;
protected int _pIdx = -1;
protected String[] _printers;
protected PrinterData[] _pdatas;
protected CCombo _printerCombo;
protected JaretTablePrintConfiguration _configuration;
protected Button _repeatHeader;
protected Label _pagesLabel;
protected JaretTablePrinter _tablePrinter;
public JaretTablePrintDialog(Shell parentShell, String printerName, JaretTablePrinter tablePrinter,
JaretTablePrintConfiguration printConfiguration) {
super(parentShell);
_tablePrinter = tablePrinter;
_configuration = printConfiguration;
if (_configuration == null) {
_configuration = new JaretTablePrintConfiguration("table", false, 1.0);
}
if (printerName == null && _printerData != null) {
printerName = _printerData.name;
}
_pdatas = Printer.getPrinterList();
_printers = new String[_pdatas.length];
int stdIdx = -1;
for (int i = 0; i < _pdatas.length; i++) {
PrinterData pd = _pdatas[i];
_printers[i] = pd.name;
if (printerName != null && pd.name.equals(printerName)) {
_pIdx = i;
}
if (pd.name.equals(Printer.getDefaultPrinterData().name)) {
stdIdx = i;
}
}
if (_pIdx == -1) {
_printerData = Printer.getDefaultPrinterData();
_pIdx = stdIdx;
} else {
_printerData = _pdatas[_pIdx];
}
}
public void setRowLimit(int limit) {
_configuration.setRowLimit(limit);
}
public void setColLimit(int limit) {
_configuration.setColLimit(limit);
}
public JaretTablePrintConfiguration getConfiguration() {
return _configuration;
}
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("Print");
}
@Override
protected Control createDialogArea(Composite parent) {
Composite dialogArea = new Composite(parent, SWT.NULL);
// dialogArea.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW));
GridData gd1 = new GridData(GridData.FILL_BOTH);
dialogArea.setLayoutData(gd1);
GridLayout gl = new GridLayout();
gl.numColumns = 1;
dialogArea.setLayout(gl);
createPrinterSelection(dialogArea);
Composite parameterArea = new Composite(dialogArea, SWT.NULL);
GridData gd = new GridData(GridData.FILL_BOTH);
parameterArea.setLayoutData(gd);
createParameterArea(parameterArea);
return dialogArea;
}
@Override
protected void okPressed() {
_printerData = _pdatas[_printerCombo.getSelectionIndex()];
super.okPressed();
}
private void createPrinterSelection(Composite parent) {
Composite area = new Composite(parent, SWT.NULL);
area.setLayout(new RowLayout());
// area.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
_printerCombo = new CCombo(area, SWT.BORDER | SWT.READ_ONLY);
_printerCombo.setItems(_printers);
_printerCombo.select(_pIdx);
Button select = new Button(area, SWT.PUSH);
select.setText("Configure");
select.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
PrintDialog pd = new PrintDialog(Display.getCurrent().getActiveShell());
PrinterData pdata = pd.open();
if (pdata != null) {
_printerData = pdata;
select(_printerData);
}
}
private void select(PrinterData printerData) {
for (int i = 0; i < _pdatas.length; i++) {
PrinterData pd = _pdatas[i];
if (pd.name.equals(printerData.name)) {
_printerCombo.select(i);
break;
}
}
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
protected void createParameterArea(Composite parent) {
GridLayout gl = new GridLayout();
gl.numColumns = 2;
parent.setLayout(gl);
_repeatHeader = new Button(parent, SWT.CHECK);
_repeatHeader.setSelection(_configuration.getRepeatHeader());
_repeatHeader.setText("Repeat header");
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
_repeatHeader.setLayoutData(gd);
final Label scaleText = new Label(parent, SWT.RIGHT);
scaleText.setText(getScaleText());
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
scaleText.setLayoutData(gd);
final Scale scale = new Scale(parent, SWT.HORIZONTAL);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
scale.setLayoutData(gd);
scale.setMaximum(1000);
scale.setMinimum(10);
scale.setSelection((int) (_configuration.getScale() * 100));
scale.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent ev) {
int val = scale.getSelection();
double s = (double) val / 100.0;
_configuration.setScale(s);
scaleText.setText(getScaleText());
updateConf();
}
public void widgetDefaultSelected(SelectionEvent arg0) {
}
});
_pagesLabel = new Label(parent, SWT.RIGHT);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
_pagesLabel.setLayoutData(gd);
_printerData = _pdatas[_printerCombo.getSelectionIndex()];
Printer printer = new Printer(_printerData);
_tablePrinter.setPrinter(printer);
Point pages = _tablePrinter.calculatePageCount(_configuration);
printer.dispose();
_pagesLabel.setText(getPagesText(pages));
}
private String getScaleText() {
int pc = (int) (_configuration.getScale() * 100);
return Integer.toString(pc) + "%";
}
private String getPagesText(Point pages) {
return "X: " + pages.x + " Y: " + pages.y + " (" + pages.x * pages.y + " pages)";
}
private void updateConf() {
_configuration.setRepeatHeader(_repeatHeader.getSelection());
Printer printer = new Printer(_printerData);
_tablePrinter.setPrinter(printer);
Point pages = _tablePrinter.calculatePageCount(_configuration);
printer.dispose();
_pagesLabel.setText(getPagesText(pages));
}
public PrinterData getPrinterData() {
return _printerData;
}
}
| 8,622 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
JaretTablePrintConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/print/JaretTablePrintConfiguration.java | /*
* File: JaretTablePrintConfiguration.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.print;
/**
* Simple structure to control the printing using the JaretTablePrinter.
*
* @author Peter Kliem
* @version $Id: JaretTablePrintConfiguration.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class JaretTablePrintConfiguration {
protected boolean _repeatHeader;
protected double _scale;
protected String _name;
protected String _footerText;
protected int _rowLimit = -1;
protected int _colLimit = -1;
public JaretTablePrintConfiguration(String name, boolean repeatHeader, double scale) {
_name = name;
_repeatHeader = repeatHeader;
_scale = scale;
}
public JaretTablePrintConfiguration() {
this("Table", false, 1.0);
}
/**
* @return Returns the name.
*/
public String getName() {
return _name;
}
/**
* @param name The name to set.
*/
public void setName(String name) {
_name = name;
}
/**
* @return Returns the repeatHeader.
*/
public boolean getRepeatHeader() {
return _repeatHeader;
}
/**
* @param repeatHeader The repeatHeader to set.
*/
public void setRepeatHeader(boolean repeatHeader) {
_repeatHeader = repeatHeader;
}
/**
* @return Returns the scale.
*/
public double getScale() {
return _scale;
}
/**
* @param scale The scale to set.
*/
public void setScale(double scale) {
_scale = scale;
}
/**
* @return Returns the footerText.
*/
public String getFooterText() {
return _footerText;
}
/**
* @param footerText The footerText to set.
*/
public void setFooterText(String footerText) {
_footerText = footerText;
}
/**
* @return Returns the colLimit.
*/
public int getColLimit() {
return _colLimit;
}
/**
* @param colLimit The colLimit to set.
*/
public void setColLimit(int colLimit) {
_colLimit = colLimit;
}
/**
* @return Returns the rowLimit.
*/
public int getRowLimit() {
return _rowLimit;
}
/**
* @param rowLimit The rowLimit to set.
*/
public void setRowLimit(int rowLimit) {
_rowLimit = rowLimit;
}
}
| 2,861 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
BooleanCellEditor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/editor/BooleanCellEditor.java | /*
* File: BooleanCellEditor.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.editor;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* BooleanCellEditor is not a real editor. It toggles on double click, optional on click and on a typed SPACE.
*
* @author Peter Kliem
* @version $Id: BooleanCellEditor.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class BooleanCellEditor extends CellEditorBase implements ICellEditor {
/** single clickk attribute: if true react on single clicks. */
protected boolean _singleClick = false;
/**
* Default constructor.
*
*/
public BooleanCellEditor() {
}
/**
* Constructor including the singelClick property.
*
* @param singleClick if true the editor will react on single clicks in the cell
*/
public BooleanCellEditor(boolean singleClick) {
_singleClick = singleClick;
}
/**
* {@inheritDoc}
*/
public Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey) {
if (typedKey == ' ') {
toggle(row, column);
} else if (typedKey == 0) {
toggle(row, column);
}
return null;
}
/**
* {@inheritDoc}
*/
public void stopEditing(boolean storeInput) {
// nothing to do
}
/** selection area width and height. */
private static final int SELECTION_DELTA = 16;
/**
* {@inheritDoc}
*/
public boolean handleClick(JaretTable table, IRow row, IColumn column, Rectangle drawingArea, int x, int y) {
if (_singleClick) {
Rectangle rect = new Rectangle(drawingArea.x + (drawingArea.width - SELECTION_DELTA) / 2, drawingArea.y
+ (drawingArea.height - SELECTION_DELTA) / 2, SELECTION_DELTA, SELECTION_DELTA);
if (rect.contains(x, y)) {
toggle(row, column);
return true;
}
}
return false;
}
/**
* Toggle the boolean value.
*
* @param row row of the cell
* @param column column of the cell
*/
private void toggle(IRow row, IColumn column) {
Object value = column.getValue(row);
if (value instanceof Boolean) {
column.setValue(row, ((Boolean) value).booleanValue() ? Boolean.FALSE : Boolean.TRUE);
}
}
/**
* {@inheritDoc}
*/
public void dispose() {
super.dispose();
}
}
| 3,098 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
CellEditorBase.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/editor/CellEditorBase.java | /*
* File: CellEditorBase.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.editor;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Abstract base implementation for ICellEditors for the jaret table.
*
* @author Peter Kliem
* @version $Id: CellEditorBase.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public abstract class CellEditorBase implements ICellEditor {
/** member storing the last requested row. */
protected IRow _row;
/** member storing the last requested column. */
protected IColumn _column;
/** member storing the requesting table. */
protected JaretTable _table;
/**
* {@inheritDoc} Base implementation storing the table and row/col information.
*/
public Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey) {
_table = table;
_row = row;
_column = column;
return null;
}
/**
* {@inheritDoc}
*/
public void dispose() {
// help the garbage collector
_table = null;
_column = null;
_row = null;
}
/**
* {@inheritDoc} default will always return -1.
*/
public int getPreferredHeight() {
return -1;
}
/**
* {@inheritDoc}
*/
public boolean handleClick(JaretTable table, IRow row, IColumn column, Rectangle drawingArea, int x, int y) {
// no action on single click
return false;
}
}
| 2,050 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
EnumComboEditor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/editor/EnumComboEditor.java | /*
* File: EnumComboEditor.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.editor;
import org.eclipse.swt.SWT;
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.graphics.Point;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Control;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Editor for a field with an enum as type. Naturally uses a combobox.
*
* @author Peter Kliem
* @version $Id: EnumComboEditor.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class EnumComboEditor extends CellEditorBase implements ICellEditor, FocusListener {
/** combobox widget. */
protected Combo _combo;
/** old value. */
protected Object _oldVal;
/** list of selectable items in the combobox. */
protected Object[] _items;
/**
* {@inheritDoc}
*/
public Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey) {
super.getEditorControl(table, row, column, typedKey);
_items = new Object[] {};
if (_combo == null) {
_combo = new Combo(table, SWT.BORDER | SWT.READ_ONLY);
_combo.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.TAB) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusRight();
} else if (event.keyCode == SWT.CR) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusDown();
} else if (event.keyCode == SWT.ESC) {
event.doit = false;
stopEditing(false);
_column.setValue(_row, _oldVal);
_table.forceFocus();
}
}
public void keyReleased(KeyEvent arg0) {
}
});
_combo.addFocusListener(this);
}
Class<?> clazz = column.getContentClass(row);
if (clazz != null && Enum.class.isAssignableFrom(clazz)) {
_items = clazz.getEnumConstants();
} else {
_items = new Object[] {};
}
Object value = column.getValue(row);
_oldVal = value;
int selIdx = -1;
String[] stringItems = new String[_items.length];
for (int i = 0; i < _items.length; i++) {
stringItems[i] = _items[i].toString();
if (value != null && value.equals(_items[i])) {
selIdx = i;
}
}
_combo.setItems(stringItems);
if (selIdx != -1) {
_combo.select(selIdx);
}
return _combo;
}
/**
* {@inheritDoc}
*/
public void stopEditing(boolean storeInput) {
if (storeInput) {
int selIdx = _combo.getSelectionIndex();
Object selection = null;
if (selIdx != -1) {
selection = _items[selIdx];
}
_column.setValue(_row, selection);
}
_combo.setVisible(false);
}
/**
* {@inheritDoc}
*/
public void dispose() {
super.dispose();
if (_combo != null && !_combo.isDisposed()) {
_combo.dispose();
}
}
/**
* {@inheritDoc} Do nothing on gaining focus.
*/
public void focusGained(FocusEvent arg0) {
}
/**
* {@inheritDoc} Stop editing and store the value.
*/
public void focusLost(FocusEvent arg0) {
stopEditing(true);
}
/**
* {@inheritDoc}
*/
public int getPreferredHeight() {
if (_combo != null) {
Point size = _combo.computeSize(SWT.DEFAULT, SWT.DEFAULT);
return size.y;
}
return -1;
}
}
| 4,699 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ICellEditor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/editor/ICellEditor.java | /*
* File: ICellEditor.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.editor;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Interface for a cell editor to be used in the jaret table.
*
* @author Peter Kliem
* @version $Id: ICellEditor.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public interface ICellEditor {
/**
* Provide the Control for editing the value at row/column. <b>Important:</b> make shure _not_ to create a new
* control with every call!
* <p>
* This method may return <code>null</code> indicating that the editor will not supply a control.
* </p>
*
* @param table the table requesting the editor
* @param row row
* @param column column
* @param typedKey the character typed when invoking the editor (may be 0 if the editor was invoked without typing
* any key)
* @return configured Control (parent has to be the table)
*/
Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey);
/**
* End editing.
*
* @param storeInput if true the editor shall save the current input.
*/
void stopEditing(boolean storeInput);
/**
* Handle a click on the cell. This could handle the whole edit for single click editors. The return value controls
* whether the click will be used for regular selection after handling.
*
* @param table the jaret table calling
* @param row row
* @param column column
* @param drawingArea the rectangle of the cell
* @param x clicked coordinate x
* @param y clicked coordinate y
* @return true if the click has been handled
*/
boolean handleClick(JaretTable table, IRow row, IColumn column, Rectangle drawingArea, int x, int y);
/**
* Dispose whatever resouces have been allocated.
*
*/
void dispose();
/**
* If the renderer *wishes* to be sized not the height of the cell, this method may be used to announce the
* preferred height of the control. A value of -1 signals no preference.
*
* @return preferred height or -1 for no preference.
*/
int getPreferredHeight();
}
| 2,787 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IntegerCellEditor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/editor/IntegerCellEditor.java | /*
* File: IntegerCellEditor.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.editor;
import org.eclipse.swt.SWT;
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.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Spinner;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Cell Editor for editing integer values using a spinner widget. Well it seems that the Spinner does not support
* negative values ...
*
* Key bindings: CR, TAB: accept input and leave, ESC leave and reset to value when starting editing
* </p>
*
* @author Peter Kliem
* @version $Id: IntegerCellEditor.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class IntegerCellEditor extends CellEditorBase implements ICellEditor, FocusListener {
/** spinner widgrt. */
protected Spinner _spinner;
/** old value. */
private int _oldVal;
/** min value that can be selected. */
private int _min = Integer.MIN_VALUE;
/** max value that can be selected. */
private int _max = Integer.MAX_VALUE;
/**
* Construct an integer cell renderer with given min and max values.
*
* @param min minimal value
* @param max maximum value
*/
public IntegerCellEditor(int min, int max) {
_min = min;
_max = max;
}
/**
* Default construcor.
*
*/
public IntegerCellEditor() {
}
protected int convertValue(IRow row, IColumn column) {
Object value = column.getValue(row);
return value != null ? (Integer) value : 0;
}
protected void storeValue(IRow row, IColumn column) {
Integer value = _spinner.getSelection();
_column.setValue(_row, value);
}
/**
* Create the control.
*
* @param table parent table
*/
private void createControl(JaretTable table) {
if (_spinner == null) {
_table = table;
_spinner = new Spinner(table, SWT.BORDER);
_spinner.setMaximum(_max);
_spinner.setMinimum(_min);
_spinner.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
e.doit = false;
}
});
_spinner.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.TAB) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusRight();
} else if (event.keyCode == SWT.CR) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusDown();
} else if (event.keyCode == SWT.ESC) {
event.doit = false;
stopEditing(false);
_column.setValue(_row, _oldVal);
_table.forceFocus();
}
}
public void keyReleased(KeyEvent arg0) {
}
});
_spinner.addFocusListener(this);
}
}
/**
* {@inheritDoc}
*/
public Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey) {
super.getEditorControl(table, row, column, typedKey);
createControl(table);
_oldVal = (Integer) column.getValue(row);
if (false && typedKey != 0) {
// _spinner.setsetText("" + typedKey);
// _text.setSelection(1);
} else {
int value = convertValue(row, column);
_spinner.setSelection(value);
}
return _spinner;
}
/**
* {@inheritDoc}
*/
public int getPreferredHeight() {
if (_spinner == null) {
return -1;
}
Point size = _spinner.computeSize(SWT.DEFAULT, SWT.DEFAULT);
return size.y;
}
/**
* {@inheritDoc} Do nothing on gaining focus.
*/
public void focusGained(FocusEvent arg0) {
}
/**
* {@inheritDoc} Stop and strore when focus leaves.
*/
public void focusLost(FocusEvent arg0) {
_table.stopEditing(true);
}
/**
* {@inheritDoc}
*/
public void dispose() {
super.dispose();
if (_spinner != null && !_spinner.isDisposed()) {
_spinner.removeFocusListener(this);
_spinner.dispose();
}
}
/**
* {@inheritDoc}
*/
public void stopEditing(boolean storeInput) {
if (storeInput) {
storeValue(_row, _column);
}
_spinner.setVisible(false);
}
}
| 5,662 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DoubleCellEditor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/editor/DoubleCellEditor.java | /*
* File: DoubleCellEditor.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.editor;
import java.text.ParseException;
import org.eclipse.swt.SWT;
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.graphics.Point;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
import de.jaret.util.ui.DoubleField;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Cell Editor for editing double values.
* <p>
* Key bindings: CR, TAB: accept input and leave, ESC leave and reset to value when starting editing. Cursor up/down
* will roll the value.
* </p>
*
* @author Peter Kliem
* @version $Id: DoubleCellEditor.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class DoubleCellEditor extends CellEditorBase implements ICellEditor, FocusListener {
/** text control wrapped by the doublefield. */
protected Text _text;
/** old value for restauration. */
protected double _oldVal;
/** doublefield managing the input. */
protected DoubleField _doubleField;
/**
* Default constructor.
*/
public DoubleCellEditor() {
}
/**
* Convert the value retrieved from the model.
*
* @param row row of the cell
* @param column column of the cell
* @return double value (defaulting to 0.0)
*/
protected double convertValue(IRow row, IColumn column) {
Object value = column.getValue(row);
return value != null ? (Double) value : 0.0;
}
/**
* Store the value in the model. If any error occurs, it will be silently ignored!
*
* @param row row
* @param column column
*/
protected void storeValue(IRow row, IColumn column) {
double value;
try {
value = _doubleField.getValue();
_column.setValue(_row, value);
} catch (ParseException e) {
// ignore
}
}
/**
* Create and setup the control.
*
* @param table parent for the control
*/
private void createControl(JaretTable table) {
if (_text == null) {
_table = table;
_text = new Text(table, SWT.BORDER | SWT.RIGHT);
_doubleField = new DoubleField();
_doubleField.setText(_text);
_text.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.TAB) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusRight();
} else if (event.keyCode == SWT.CR) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusDown();
} else if (event.keyCode == SWT.ESC) {
event.doit = false;
stopEditing(false);
_column.setValue(_row, _oldVal);
_table.forceFocus();
}
}
public void keyReleased(KeyEvent arg0) {
}
});
_text.addFocusListener(this);
}
}
/**
* {@inheritDoc}
*/
public Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey) {
super.getEditorControl(table, row, column, typedKey);
createControl(table);
_oldVal = convertValue(row, column);
if (typedKey != 0) {
_text.setText("" + typedKey);
_text.setSelection(1);
} else {
double value = convertValue(row, column);
_doubleField.setValue(value);
_text.selectAll();
}
return _text;
}
/**
* {@inheritDoc}
*/
public int getPreferredHeight() {
if (_text == null) {
return -1;
}
Point size = _text.computeSize(SWT.DEFAULT, SWT.DEFAULT);
return size.y;
}
/**
* {@inheritDoc} do nothing.
*/
public void focusGained(FocusEvent arg0) {
}
/**
* {@inheritDoc} On losing focus store the value.
*/
public void focusLost(FocusEvent arg0) {
_table.stopEditing(true);
}
/**
* {@inheritDoc}
*/
public void dispose() {
super.dispose();
if (_text != null && !_text.isDisposed()) {
_doubleField.setText(null);
_text.removeFocusListener(this);
_text.dispose();
}
}
/**
* {@inheritDoc}
*/
public void stopEditing(boolean storeInput) {
if (storeInput) {
storeValue(_row, _column);
}
_text.setVisible(false);
}
}
| 5,567 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ObjectComboEditor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/editor/ObjectComboEditor.java | /*
* File: ObjectComboEditor.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.editor;
import java.util.List;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.SWT;
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.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Control;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Editor using a ComboBox for selecting one of several objects supplied to the editor at creation time. A label
* provider is used for toString conversion.
*
* @author Peter Kliem
* @version $Id: ObjectComboEditor.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class ObjectComboEditor extends CellEditorBase implements ICellEditor, FocusListener {
/** combox widget. */
protected Combo _combo;
/** old value. */
protected Object _oldVal;
/** list of items displayed. */
protected String[] _stringItems;
/** label provider used. */
protected ILabelProvider _labelProvider;
/** if true allow null as a possible selection. */
protected boolean _allowNull = true;
/** the text displayed for <code>null</code>. */
protected String _nullText = "";
/** object list for selection. */
protected List<? extends Object> _itemList;
/**
* Construct a new ObjectComboEditor with a list of selectabel Objects and an ILabelprovider.
*
* @param list list of Objects that may be selected.
* @param labelProvider label provider to be used or <code>null</code>. In the latter case a simple toString
* label provider will be used.
* @param allowNull if true null will always be a possible value in the comboBox
* @param nullText string to be displyed for the null value if allowed
*/
public ObjectComboEditor(List<? extends Object> list, ILabelProvider labelProvider, boolean allowNull,
String nullText) {
_labelProvider = labelProvider;
if (_labelProvider == null) {
_labelProvider = new ToStringLabelProvider();
}
_allowNull = allowNull;
_nullText = nullText;
_itemList = list;
if (_itemList != null) {
initItems();
}
}
protected void initItems() {
_stringItems = _allowNull ? new String[_itemList.size() + 1] : new String[_itemList.size()];
int i = 0;
if (_allowNull) {
_stringItems[0] = _nullText;
i = 1;
}
for (Object o : _itemList) {
_stringItems[i++] = _labelProvider.getText(o);
}
}
/**
* {@inheritDoc}
*/
public Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey) {
super.getEditorControl(table, row, column, typedKey);
if (_combo == null) {
_combo = new Combo(table, SWT.BORDER | SWT.READ_ONLY);
_combo.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.TAB) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusRight();
} else if (event.keyCode == SWT.CR) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusDown();
} else if (event.keyCode == SWT.ESC) {
event.doit = false;
stopEditing(false);
_column.setValue(_row, _oldVal);
_table.forceFocus();
}
}
public void keyReleased(KeyEvent arg0) {
}
});
_combo.addFocusListener(this);
_combo.setItems(_stringItems);
}
Object value = column.getValue(row);
_oldVal = value;
int selIdx = -1;
if (_allowNull && value == null) {
selIdx = 0;
} else {
selIdx = _itemList.indexOf(value);
selIdx = _allowNull ? selIdx + 1 : selIdx;
}
if (selIdx != -1) {
_combo.select(selIdx);
}
return _combo;
}
/**
* {@inheritDoc}
*/
public void stopEditing(boolean storeInput) {
if (storeInput) {
int selIdx = _combo.getSelectionIndex();
Object selection = null;
if (selIdx != -1) {
if (_allowNull && selIdx == 0) {
selection = null;
} else {
selIdx = _allowNull ? selIdx - 1 : selIdx;
selection = _itemList.get(selIdx);
}
}
_column.setValue(_row, selection);
}
_combo.setVisible(false);
}
/**
* {@inheritDoc}
*/
public void dispose() {
super.dispose();
if (_combo != null && !_combo.isDisposed()) {
_combo.dispose();
}
}
/**
* {@inheritDoc} Nothing to do on gaining focus.
*/
public void focusGained(FocusEvent arg0) {
}
/**
* {@inheritDoc} Store and end editing when focus is taken away.
*/
public void focusLost(FocusEvent arg0) {
stopEditing(true);
}
/**
* {@inheritDoc}
*/
public int getPreferredHeight() {
if (_combo != null) {
Point size = _combo.computeSize(SWT.DEFAULT, SWT.DEFAULT);
return size.y;
}
return -1;
}
/**
* Simple Labelprovider just using the toString method of any supplied object.
*
* @author Peter Kliem
* @version $Id: ObjectComboEditor.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class ToStringLabelProvider implements ILabelProvider {
/**
* {@inheritDoc}
*/
public Image getImage(Object element) {
return null;
}
/**
* {@inheritDoc}
*/
public String getText(Object element) {
return element.toString();
}
/**
* {@inheritDoc}
*/
public void addListener(ILabelProviderListener listener) {
}
/**
* {@inheritDoc}
*/
public void dispose() {
}
/**
* {@inheritDoc}
*/
public boolean isLabelProperty(Object element, String property) {
return false;
}
/**
* {@inheritDoc}
*/
public void removeListener(ILabelProviderListener listener) {
}
}
}
| 7,657 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DateCellEditor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/editor/DateCellEditor.java | /*
* File: DateCellEditor.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.editor;
import java.util.Calendar;
import java.util.Date;
import org.eclipse.swt.SWT;
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.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import de.jaret.util.date.JaretDate;
import de.jaret.util.ui.datechooser.DateChooser;
import de.jaret.util.ui.datechooser.IDateChooserListener;
import de.jaret.util.ui.datechooser.IFieldIdentifier;
import de.jaret.util.ui.datechooser.SimpleFieldIdentifier;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Cell editor for editing dates using the jaret datechooser. Supports java.util.date and JaretDate. The fieldidentifier
* used for the datechooser (see Javadoc there) is not locale dependant (Day/Month/year) have to be changed when used in
* another country (or removed!).
* <p>
* Key bindings: TAB and CR will leave the datechooser (positive). ESC will leave the chooser resetting the date to the
* value present when editing started.
* </p>
*
* @author Peter Kliem
* @version $Id: DateCellEditor.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class DateCellEditor extends CellEditorBase implements ICellEditor, IDateChooserListener, FocusListener {
/** chooser component. */
protected DateChooser _chooser;
/** old java.util.Date val if present. */
protected Date _oldVal;
/** old JaretDate value if present. */
protected JaretDate _oldJaretDateVal;
/** true if jaretdate is used. */
private boolean _jaretDate;
/**
* Create the chooser control.
*
* @param table parent table.
*/
private void createControl(JaretTable table) {
_table = table;
if (_chooser == null) {
_chooser = new DateChooser(table, SWT.NULL);
// TODO locale dependent
IFieldIdentifier fi = new SimpleFieldIdentifier(".", new int[] {Calendar.DAY_OF_MONTH, Calendar.MONTH,
Calendar.YEAR});
_chooser.setFieldIdentifier(fi);
_chooser.setSelectAllOnFocusGained(false);
_chooser.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
_chooser.addFocusListener(this);
_chooser.addDateChooserListener(this);
_chooser.getTextField().addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.TAB) {
_chooser.validateInput();
stopEditing(true);
event.doit = false; // do not further process
_table.forceFocus();
_table.focusRight();
} else if (event.keyCode == SWT.CR) {
_chooser.validateInput();
stopEditing(true);
event.doit = false; // do not further process
_table.forceFocus();
_table.focusDown();
} else if (event.keyCode == SWT.ESC) {
stopEditing(false);
restoreOldVal();
event.doit = false; // do not further process
_table.forceFocus();
}
}
public void keyReleased(KeyEvent e) {
}
});
// add a traverse listener so the TAB-key won't traverse the focus out of the table
_chooser.getTextField().addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
e.doit = false;
}
});
}
}
/**
* {@inheritDoc}
*/
public Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey) {
super.getEditorControl(table, row, column, typedKey);
createControl(table);
if (column.getValue(row) instanceof Date) {
_oldVal = (Date) column.getValue(row);
_jaretDate = false;
} else if (column.getValue(row) instanceof JaretDate) {
_oldVal = ((JaretDate) column.getValue(row)).getDate();
_oldJaretDateVal = (JaretDate) column.getValue(row);
_jaretDate = true;
}
if (typedKey != 0) {
_chooser.setText("" + typedKey);
_chooser.setSelection(1);
} else {
_chooser.setDate(_oldVal);
}
_row = row;
_column = column;
return _chooser;
}
/**
* Restore date from the the beginning of the edit action.
*
*/
private void restoreOldVal() {
if (!_jaretDate) {
_column.setValue(_row, _oldVal);
} else {
_column.setValue(_row, _oldJaretDateVal);
}
}
/**
* {@inheritDoc}
*/
public void stopEditing(boolean storeInput) {
if (storeInput) {
storeValue();
}
_chooser.setDropped(false);
_chooser.setVisible(false);
}
/**
* Store the value in the model.
*
*/
private void storeValue() {
if (!_jaretDate) {
_column.setValue(_row, _chooser.getDate());
} else {
_column.setValue(_row, new JaretDate(_chooser.getDate()));
}
}
/**
* {@inheritDoc}
*/
public void dispose() {
if (_chooser != null && !_chooser.isDisposed()) {
_chooser.removeFocusListener(this);
_chooser.dispose();
}
// help the garbage collector
_table = null;
_column = null;
_row = null;
}
/**
* {@inheritDoc} If the users choses a date, stop editing an store the chosen date.
*/
public void dateChosen(Date date) {
// if a date has been chosen in the datechooser stop editing immediately
stopEditing(true);
_table.forceFocus();
}
/**
* {@inheritDoc} No Action on intermediate changes in the chooser.
*/
public void dateIntermediateChange(Date date) {
}
/**
* {@inheritDoc} When the chooser tells us the user canceled the editing, restore the old date.
*/
public void choosingCanceled() {
_chooser.setDate(_oldVal);
}
/**
* {@inheritDoc} nothing to do.
*/
public void inputInvalid() {
}
/**
* {@inheritDoc} Do nothing on focus gained.
*/
public void focusGained(FocusEvent e) {
}
/**
* {@inheritDoc} When loosing focus, stop the editing and store the value.
*/
public void focusLost(FocusEvent e) {
_table.stopEditing(true);
}
}
| 7,648 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
TextCellEditor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/editor/TextCellEditor.java | /*
* File: TextCellEditor.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.editor;
import org.eclipse.swt.SWT;
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.graphics.Point;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Cell Editor for editing strings. Supports single and multiple line edits. For multiple line usage there are several
* options:
* <ul>
* <li>resize: when true the input will be growing with the input text up to maxRows rows</li>
* <li>maxRows: max height of input filed when resizing</li>
* </ul>
* <p>
* Key bindings: CR, TAB: accept input and leave, ALT+CR insert CR, ESC leave and reset to value when starting editing
* </p>
*
* @author Peter Kliem
* @version $Id: TextCellEditor.java,v 1.1 2012-05-07 01:34:38 jason Exp $
*/
public class TextCellEditor extends CellEditorBase implements ICellEditor, FocusListener {
protected boolean _multi = true;
/** control used for editing. */
protected Text _text;
private String _oldVal;
private int _maxrows = 6;
public TextCellEditor(boolean multi) {
_multi = multi;
}
protected String convertValue(IRow row, IColumn column) {
Object value = column.getValue(row);
return value != null ? value.toString() : null;
}
protected void storeValue(IRow row, IColumn column) {
String value = _text.getText();
_column.setValue(_row, value);
}
/**
* Create the control to be used when editing.
*
* @param table table is the parent control
*/
private void createControl(JaretTable table) {
if (_text == null) {
_table = table;
if (!_multi) {
_text = new Text(table, SWT.BORDER);
} else {
_text = new Text(table, SWT.BORDER | SWT.MULTI | SWT.WRAP);
}
_text.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) {
if ((event.stateMask & SWT.ALT) != 0 && event.keyCode == SWT.CR) {
event.doit = false;
_text.insert("\n");
} else if (event.keyCode == SWT.TAB) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusRight();
} else if (event.keyCode == SWT.CR) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusDown();
} else if (event.keyCode == SWT.ESC) {
event.doit = false;
stopEditing(false);
_column.setValue(_row, _oldVal);
_table.forceFocus();
} else {
if (_multi) {
// System.out.println("lines "+_text.getLineCount());
// System.out.println("lineheight "+_text.getLineHeight());
// int lheight = _text.getLineHeight();
// int lcount = _text.getLineCount();
// TODO
if (true || _text.getLineCount() * _text.getLineHeight() < _text.getSize().y) {
Point newSize = new Point(_text.getSize().x, getPreferredHeight());
_text.setSize(newSize);
}
}
}
}
public void keyReleased(KeyEvent arg0) {
}
});
_text.addFocusListener(this);
}
}
/**
* {@inheritDoc}
*/
public Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey) {
super.getEditorControl(table, row, column, typedKey);
createControl(table);
_oldVal = (String) column.getValue(row);
if (typedKey != 0) {
_text.setText("" + typedKey);
_text.setSelection(1);
} else {
String value = convertValue(row, column);
_text.setText(value != null ? value : "");
_text.selectAll();
}
return _text;
}
/**
* {@inheritDoc}
*/
public int getPreferredHeight() {
if (_text == null) {
return -1;
}
int lheight = _text.getLineHeight();
int lcount = _text.getLineCount();
if (lcount > _maxrows + 1) {
lcount = _maxrows;
}
return (lcount + 1) * lheight;
}
public void focusGained(FocusEvent arg0) {
}
public void focusLost(FocusEvent arg0) {
_table.stopEditing(true);
}
public void dispose() {
super.dispose();
if (_text != null && !_text.isDisposed()) {
_text.removeFocusListener(this);
_text.dispose();
}
}
/**
* {@inheritDoc}
*/
public void stopEditing(boolean storeInput) {
if (storeInput) {
storeValue(_row, _column);
}
_text.setVisible(false);
}
/**
* @return the maxrows
*/
public int getMaxrows() {
return _maxrows;
}
/**
* @param maxrows the maxrows to set
*/
public void setMaxrows(int maxrows) {
_maxrows = maxrows;
}
}
| 6,339 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IAutoFilter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/filter/IAutoFilter.java | /*
* File: IAutoFilter.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.filter;
import org.eclipse.swt.widgets.Control;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
/**
* Interface describing an autofilter to be used within a jaret table. An autofilter will be instantiated for every
* column it is used on. So it is absolutely necessary that an autofilter can be instantiated by a default constructor.
*
* @author kliem
* @version $Id: IAutoFilter.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public interface IAutoFilter extends IRowFilter {
/**
* Tell the autofilter which table he serves. This will be called after instantiating the autofilter.
*
* @param table table the autofilter is used with
*/
void setTable(JaretTable table);
/**
* Tell the autofilter on which column it works. This method will be called once after the filter has been
* instantiated.
*
* @param column column for the autofilter
*/
void setColumn(IColumn column);
/**
* Get the control representing the autofilter (most probably a combo box).
*
* @return configured control representing the filter
*/
Control getControl();
/**
* Update/create the control and internal state.
*/
void update();
/**
* Remove any selection (usually revert to a setting that filters nothing).
*/
void reset();
/**
* Dispose all resources.
*/
void dispose();
}
| 1,964 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultAutoFilter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/filter/DefaultAutoFilter.java | /*
* File: DefaultAutoFilter.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.filter;
import java.util.Set;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Control;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* Default implementation of the IAutofilter interface rendering a combobox with a simple selection mechanism.
*
* @author kliem
* @version $Id: DefaultAutoFilter.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class DefaultAutoFilter extends AbstractAutoFilter implements IAutoFilter, SelectionListener {
/** maximal length of an object list in a autofilter combox (-1 for unlimited). */
private static final int MAX_AUTOFILTERLENGTH = -1;
/** text: to be externalized. */
protected static final String TEXT_FILTER_ALL = "(all)";
/** text: to be externalized. */
protected static final String TEXT_FILTER_EMPTY = "(empty)";
/** text: to be externalized. */
protected static final String TEXT_FILTER_NONEMPTY = "(non-empty)";
/** control used for the filter -> coombobox. */
protected CCombo _combo;
/**
* {@inheritDoc}
*/
public void dispose() {
if (_combo != null) {
_combo.dispose();
}
}
/**
* {@inheritDoc}
*/
public Control getControl() {
return _combo;
}
/**
* {@inheritDoc}
*/
public boolean isInResult(IRow row) {
String filter = _combo.getText();
Object value = _column.getValue(row);
String valString = value != null ? value.toString() : "";
if (!filter.equals(TEXT_FILTER_ALL)) {
if (filter.equals(TEXT_FILTER_EMPTY) && valString.trim().length() > 0) {
return false;
}
if (filter.equals(TEXT_FILTER_NONEMPTY) && valString.trim().length() == 0) {
return false;
}
if (!filter.equals(TEXT_FILTER_ALL) && !filter.equals(TEXT_FILTER_EMPTY)
&& !filter.equals(TEXT_FILTER_NONEMPTY)) {
if (!filter.equals(valString)) {
return false;
}
}
}
return true;
}
/**
* {@inheritDoc}
*/
public void update() {
if (_combo == null) {
_combo = new CCombo(_table, SWT.BORDER | SWT.READ_ONLY);
_combo.addSelectionListener(this);
}
IColumn col = _column;
Set<String> colFilterStrings = getColFilterStrings(col, MAX_AUTOFILTERLENGTH);
String[] items = new String[colFilterStrings.size() + 3];
int idx = 0;
items[idx++] = TEXT_FILTER_ALL;
items[idx++] = TEXT_FILTER_EMPTY;
items[idx++] = TEXT_FILTER_NONEMPTY;
for (String s : colFilterStrings) {
items[idx++] = s;
}
_combo.setItems(items);
_combo.select(0);
}
/**
* {@inheritDoc}
*/
public void reset() {
_combo.select(0);
firePropertyChange("FILTER", null, "x");
}
/**
* {@inheritDoc}
*/
public void widgetDefaultSelected(SelectionEvent e) {
}
/**
* {@inheritDoc} Inform everyone the filter changed.
*/
public void widgetSelected(SelectionEvent e) {
firePropertyChange("FILTER", null, "x");
}
}
| 3,980 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IRowFilter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/filter/IRowFilter.java | /*
* File: IRowFilter.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.filter;
import de.jaret.util.misc.PropertyObservable;
import de.jaret.util.ui.table.model.IRow;
/**
* A simple row filter for the jaret table. This is a PropertyObservable to allow the table to refresh on prop changes.
*
* @author Peter Kliem
* @version $Id: IRowFilter.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public interface IRowFilter extends PropertyObservable {
/**
* Check whether the row is in the resulting list of rows.
*
* @param row row to check.
* @return true if the rw is in the result.
*/
boolean isInResult(IRow row);
}
| 1,055 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AbstractAutoFilter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/filter/AbstractAutoFilter.java | /*
* File: AbstractAutoFilter.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.filter;
import java.util.HashSet;
import java.util.Set;
import de.jaret.util.misc.PropertyObservableBase;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IRow;
/**
* An abstract base that can be used when implementing autofilters.
*
* @author kliem
* @version $Id: AbstractAutoFilter.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public abstract class AbstractAutoFilter extends PropertyObservableBase implements IAutoFilter {
/** table of the autofilter. */
protected JaretTable _table;
/** column of the autofilter. */
protected IColumn _column;
/**
* {@inheritDoc}
*/
public void setColumn(IColumn column) {
_column = column;
}
/**
* {@inheritDoc}
*/
public void setTable(JaretTable table) {
_table = table;
}
/**
* Get all possible filter strings for the autofilter comboboxes.
*
* @param col the column to look at
* @param maxLength the maxmium length of the individual strings. If a string is larger than that it wil be
* truncated, -1 for no truncation
* @return set of strings, shortened if necessary
*/
protected Set<String> getColFilterStrings(IColumn col, int maxLength) {
Set<String> result = new HashSet<String>();
for (int i = 0; i < _table.getRowCount(); i++) {
IRow row = _table.getRow(i);
Object val = col.getValue(row);
if (val != null) {
String valStr = val.toString();
if (maxLength != -1 && valStr.length() > maxLength) {
// TODO mark for proper use in filters
valStr = valStr.substring(0, maxLength - 1);
}
result.add(valStr);
}
}
return result;
}
}
| 2,393 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AbstractSelectionProvider.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/util/AbstractSelectionProvider.java | /*
* File: AbstractSelectionProvider.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.util;
import java.util.List;
import java.util.Vector;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IJaretTableCell;
import de.jaret.util.ui.table.model.IJaretTableSelectionModelListener;
import de.jaret.util.ui.table.model.IRow;
/**
* Abstract base for an ISelectionProvider based on a jaret Table.
*
* @author Peter Kliem
* @version $Id: AbstractSelectionProvider.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public abstract class AbstractSelectionProvider implements ISelectionProvider, IJaretTableSelectionModelListener {
/** jaret table the selection provider listens to. */
protected JaretTable _table;
/** list of ISelection listeners. * */
protected List<ISelectionChangedListener> _selectionChangeListeners;
/**
* Contruct an abstract selection provider.
*
* @param table JaretTable to listen to
*/
public AbstractSelectionProvider(JaretTable table) {
_table = table;
_table.getSelectionModel().addTableSelectionModelListener(this);
}
// ///////////// ISelectionProvider
/**
* {@inheritDoc}
*/
public synchronized void addSelectionChangedListener(ISelectionChangedListener listener) {
if (_selectionChangeListeners == null) {
_selectionChangeListeners = new Vector<ISelectionChangedListener>();
}
_selectionChangeListeners.add(listener);
}
/**
* {@inheritDoc}
*/
public void removeSelectionChangedListener(ISelectionChangedListener listener) {
if (_selectionChangeListeners != null) {
_selectionChangeListeners.remove(listener);
}
}
/**
* {@inheritDoc}
*/
public void setSelection(ISelection selection) {
setISelection(selection);
}
/**
* {@inheritDoc}
* Retrieve an IStructuredSelection of the current selection (will contain rows, columns and cells).
*/
public ISelection getSelection() {
return getISelection();
}
/**
* Override this method to return an ISelectiobn appropriate for the intended use.
*
* @return ISelection
*/
protected abstract ISelection getISelection();
/**
* Override this method to set a selection on the table based on an ISelection.
*
* @param selection ISelection to be set.
*/
protected abstract void setISelection(ISelection selection);
/**
* Inform listeners about a change of selection.
*/
private void fireSelectionChanged() {
SelectionChangedEvent event = new SelectionChangedEvent(this, getSelection());
if (_selectionChangeListeners != null) {
for (ISelectionChangedListener listener : _selectionChangeListeners) {
listener.selectionChanged(event);
}
}
}
// ////////// IjaretTableModeSelectionListener
/**
* {@inheritDoc}
*/
public void rowSelectionAdded(IRow row) {
fireSelectionChanged();
}
/**
* {@inheritDoc}
*/
public void rowSelectionRemoved(IRow row) {
fireSelectionChanged();
}
/**
* {@inheritDoc}
*/
public void cellSelectionAdded(IJaretTableCell cell) {
fireSelectionChanged();
}
/**
* {@inheritDoc}
*/
public void cellSelectionRemoved(IJaretTableCell cell) {
fireSelectionChanged();
}
/**
* {@inheritDoc}
*/
public void columnSelectionAdded(IColumn column) {
fireSelectionChanged();
}
/**
* {@inheritDoc}
*/
public void columnSelectionRemoved(IColumn column) {
fireSelectionChanged();
}
// //// end ISelectionProvider
}
| 4,582 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultSelectionProvider.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/util/DefaultSelectionProvider.java | /*
* File: DefaultSelectionProvider.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.util;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.IJaretTableCell;
import de.jaret.util.ui.table.model.IJaretTableSelection;
import de.jaret.util.ui.table.model.IRow;
/**
* Default implementation of a SelectionProvider based on the jarettable. This will simply put rows, columns and cells in
* a structured selection.
*
* @author Peter Kliem
* @version $Id: DefaultSelectionProvider.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class DefaultSelectionProvider extends AbstractSelectionProvider {
/**
* Create a default selection provider.
*
* @param table JaretTable providing the selection
*/
public DefaultSelectionProvider(JaretTable table) {
super(table);
}
/**
* {@inheritDoc}. Returns a structured selection containig rows and columns and cells that have been selected.
*/
@SuppressWarnings("unchecked")
protected ISelection getISelection() {
IJaretTableSelection selection = _table.getSelectionModel().getSelection();
if (selection != null && !selection.isEmpty()) {
List list = new ArrayList();
for (IRow row : selection.getSelectedRows()) {
list.add(row);
}
for (IColumn col : selection.getSelectedColumns()) {
list.add(col);
}
for (IJaretTableCell cell : selection.getSelectedCells()) {
list.add(cell);
}
StructuredSelection sselection = new StructuredSelection(list);
return sselection;
}
return new StructuredSelection();
}
/**
* {@inheritDoc}
*/
protected void setISelection(ISelection selection) {
// TODO Auto-generated method stub
}
}
| 2,515 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
JaretTableActionFactory.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/util/action/JaretTableActionFactory.java | /*
* File: JaretTableActionFactory.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.util.action;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jface.action.Action;
import de.jaret.util.ui.table.JaretTable;
/**
* Utility ActionFactory for the jaret table, producing actions for some common tasks to accomodate on a jaret table.
*
* @author Peter Kliem
* @version $Id: JaretTableActionFactory.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class JaretTableActionFactory {
/**
* Constant denoting the configure columns action.
*/
public static final String ACTION_CONFIGURECOLUMNS = "jarettable.configurecolumns";
public static final String ACTION_OPTROWHEIGHT = "jarettable.optimizerowheigth";
public static final String ACTION_OPTALLROWHEIGHTS = "jarettable.optimizeallrowheights";
protected Map<String, Action> _actionMap;
public Action createStdAction(JaretTable table, String name) {
if (_actionMap == null) {
_actionMap = new HashMap<String, Action>();
}
Action result = _actionMap.get(name);
if (result != null) {
return result;
}
if (name.equals(ACTION_CONFIGURECOLUMNS)) {
result = new ConfigureColumnsAction(table);
} else if (name.equals(ACTION_OPTROWHEIGHT)) {
result = new OptimizeRowHeightAction(table);
} else if (name.equals(ACTION_OPTALLROWHEIGHTS)) {
result = new OptimizeAllRowHeightsAction(table);
} else if (name.equals("s")) {
result = null;
}
if (result != null) {
_actionMap.put(name, result);
}
return result;
}
}
| 2,133 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
OptimizeAllRowHeightsAction.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/util/action/OptimizeAllRowHeightsAction.java | /*
* File: OptimizeAllRowHeightsAction.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.util.action;
import org.eclipse.jface.action.Action;
import de.jaret.util.ui.table.JaretTable;
/**
* Action that registers all rows of the model for optimization of the row height.
*
* @author Peter Kliem
* @version $Id: OptimizeAllRowHeightsAction.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class OptimizeAllRowHeightsAction extends Action {
/** tbale the action has been constructed for. */
protected JaretTable _table;
/**
* Construct the action.
*
* @param table table to operate on
*/
public OptimizeAllRowHeightsAction(JaretTable table) {
_table = table;
}
/**
* {@inheritDoc} call optimize height for all rows of the table.
*/
public void run() {
for (int i = 0; i < _table.getTableModel().getRowCount(); i++) {
_table.optimizeHeight(_table.getTableModel().getRow(i));
}
}
/**
* {@inheritDoc}
*/
public String getText() {
return "Optimal row heights for all rows";
}
}
| 1,536 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ConfigureColumnsAction.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/util/action/ConfigureColumnsAction.java | /*
* File: ConfigureColumnsAction.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.util.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IColumn;
import de.jaret.util.ui.table.model.ITableViewState;
/**
* Action for configuring column display. Showing a dialog to reorder and change the visibility of rows. The action can
* be parametrized to disallow manipulating the positions and visibility of fixed columns. The table will be
* manipoulated instantly. Values will be saved to allow cancelling the configuration.
*
* @author Peter Kliem
* @version $Id: ConfigureColumnsAction.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class ConfigureColumnsAction extends Action {
/** table the action is operating on. */
protected JaretTable _table;
/** the table viewstate. */
protected ITableViewState _tvs;
/** checkbox table viewer used to display the columns. */
protected CheckboxTableViewer _chkBoxViewer;
/** saved order for doing a proper cancel operation. */
protected List<IColumn> _saveOrder;
/** saved visibility for the columns for proper cancel action. */
protected Map<IColumn, Boolean> _saveVisibility;
/** if true fixed columns can be shifted or changed in visibility. */
protected boolean _allowFixedColumns;
/**
* Construct the action.
*
* @param table table to operate on
* @param allowFixedColumns if true fixed columns can be changed in visibility and position (moving them out of the
* fixed position)
*/
public ConfigureColumnsAction(JaretTable table, boolean allowFixedColumns) {
setTable(table);
_allowFixedColumns = allowFixedColumns;
}
/**
* Construct the action (allowFixedColumns defaults to true).
*
* @param table table to operate on
*/
public ConfigureColumnsAction(JaretTable table) {
this(table, true);
}
/**
* Set the table to operate on.
*
* @param table table
*/
public void setTable(JaretTable table) {
_table = table;
_tvs = _table.getTableViewState();
}
/**
* {@inheritDoc}
*/
public void run() {
save();
Dialog confColsDialog = new Dialog(Display.getCurrent().getActiveShell()) {
@Override
protected Control createDialogArea(Composite parent) {
return createColumnControlPanel(parent);
}
};
int result = confColsDialog.open();
if (result == Dialog.CANCEL) {
restore();
}
}
/**
* Save the current properties of the viewstate.
*/
private void save() {
_saveOrder = new ArrayList<IColumn>();
_saveOrder.addAll(_tvs.getSortedColumns());
_saveVisibility = new HashMap<IColumn, Boolean>();
for (int i = 0; i < _table.getTableModel().getColumnCount(); i++) {
IColumn col = _table.getTableModel().getColumn(i);
_saveVisibility.put(col, _tvs.getColumnVisible(col));
}
}
/**
* Restore viewstate to previously saved state.
*/
private void restore() {
_tvs.setSortedColumns(_saveOrder);
for (int i = 0; i < _table.getTableModel().getColumnCount(); i++) {
IColumn col = _table.getTableModel().getColumn(i);
boolean visible = _saveVisibility.get(col);
_tvs.setColumnVisible(col, visible);
}
}
/**
* {@inheritDoc}
*/
public String getText() {
return "Configure columns";
}
/**
* Create the dialog area. TODO can be done much nicer ... but works for the first draft
*
* @param parent parent composite
* @return initialized control
*/
private Control createColumnControlPanel(Composite parent) {
Composite panel = new Composite(parent, SWT.NULL);
panel.setLayout(new RowLayout());
Label l = new Label(panel, SWT.NULL);
l.setText("Configure the columns");
Table table = new Table(parent, SWT.CHECK | SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL);
_chkBoxViewer = new CheckboxTableViewer(table);
_chkBoxViewer.setContentProvider(new ColTableContentProvider());
_chkBoxViewer.setLabelProvider(new ColTableLabelProvider());
TableColumn column = new TableColumn(_chkBoxViewer.getTable(), SWT.LEFT);
column.setText("Column");
column.setWidth(100);
_chkBoxViewer.getTable().setHeaderVisible(true);
_chkBoxViewer.setInput("x");
final int firstColIdx = _allowFixedColumns ? 0 : _table.getFixedColumns();
for (int i = 0; i < _table.getTableModel().getColumnCount(); i++) {
IColumn col = _table.getTableModel().getColumn(i);
_chkBoxViewer.setChecked(col, _tvs.getColumnVisible(col));
}
table.getColumn(0).pack();
table.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
if (event.detail == SWT.CHECK) {
TableItem item = (TableItem) event.item;
IColumn col = (IColumn) item.getData();
int idx = _tvs.getSortedColumns().indexOf(col);
if (_allowFixedColumns || idx >= _table.getFixedColumns()) {
_tvs.setColumnVisible(col, item.getChecked());
} else {
_chkBoxViewer.setChecked(col, _tvs.getColumnVisible(col));
}
}
}
});
Button upButton = new Button(panel, SWT.PUSH);
upButton.setText("up");
upButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent arg0) {
if (_chkBoxViewer.getTable().getSelectionCount() > 0) {
TableItem item = _chkBoxViewer.getTable().getItem(_chkBoxViewer.getTable().getSelectionIndex());
IColumn col = (IColumn) item.getData();
int idx = _tvs.getSortedColumns().indexOf(col);
if (idx > firstColIdx) {
_tvs.getSortedColumns().remove(col);
_tvs.getSortedColumns().add(idx - 1, col);
_table.updateColumnList();
_table.redraw();
_chkBoxViewer.refresh();
}
}
}
public void widgetDefaultSelected(SelectionEvent arg0) {
}
});
Button downButton = new Button(panel, SWT.PUSH);
downButton.setText("down");
downButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent arg0) {
if (_chkBoxViewer.getTable().getSelectionCount() > 0) {
TableItem item = _chkBoxViewer.getTable().getItem(_chkBoxViewer.getTable().getSelectionIndex());
IColumn col = (IColumn) item.getData();
int idx = _tvs.getSortedColumns().indexOf(col);
if (idx < _tvs.getSortedColumns().size() - 1) {
_tvs.getSortedColumns().remove(col);
_tvs.getSortedColumns().add(idx + 1, col);
_table.updateColumnList();
_table.redraw();
_chkBoxViewer.refresh();
}
}
}
public void widgetDefaultSelected(SelectionEvent arg0) {
}
});
return panel;
}
/**
* Content provider for the table viewer.
*
* @author kliem
* @version $Id: ConfigureColumnsAction.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class ColTableContentProvider implements IStructuredContentProvider {
/**
* {@inheritDoc}
*/
public Object[] getElements(Object element) {
Object[] kids = null;
java.util.List l = _table.getTableViewState().getSortedColumns();
kids = l.toArray();
return kids;
}
/**
* {@inheritDoc}
*/
public void dispose() {
}
/**
* {@inheritDoc}
*/
public void inputChanged(Viewer viewer, Object oldObject, Object newObject) {
}
}
/**
* Labelprovider for the table viewer.
*
* @author kliem
* @version $Id: ConfigureColumnsAction.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class ColTableLabelProvider implements ITableLabelProvider {
/**
* {@inheritDoc}
*/
public String getColumnText(Object obj, int i) {
String result;
IColumn column = (IColumn) obj;
int idx = _tvs.getSortedColumns().indexOf(column);
switch (i) {
case 0:
result = column.getHeaderLabel();
if (!_allowFixedColumns && idx < _table.getFixedColumns()) {
result+="(fixed)";
}
break;
default:
result = "error - unknow column";
break;
}
return result;
}
/**
* {@inheritDoc}
*/
public void addListener(ILabelProviderListener ilabelproviderlistener) {
}
/**
* {@inheritDoc}
*/
public void dispose() {
}
/**
* {@inheritDoc}
*/
public boolean isLabelProperty(Object obj, String s) {
return false;
}
/**
* {@inheritDoc}
*/
public void removeListener(ILabelProviderListener ilabelproviderlistener) {
}
/**
* {@inheritDoc}
*/
public Image getColumnImage(Object arg0, int arg1) {
return null;
}
}
}
| 11,775 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
OptimizeRowHeightAction.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/util/action/OptimizeRowHeightAction.java | /*
* File: OptimizeRowHeightAction.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.util.action;
import org.eclipse.jface.action.Action;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IJaretTableSelection;
import de.jaret.util.ui.table.model.IRow;
/**
* Action that registers all selected rows for optimization of their respective heights.
*
* @author Peter Kliem
* @version $Id: OptimizeRowHeightAction.java,v 1.1 2012-05-07 01:34:39 jason Exp $
*/
public class OptimizeRowHeightAction extends Action {
protected JaretTable _table;
public OptimizeRowHeightAction(JaretTable table) {
_table = table;
}
@Override
public void run() {
IJaretTableSelection selection = _table.getSelectionModel().getSelection();
if (!selection.isEmpty() && selection.getSelectedRows().size() > 0) {
for (IRow row : selection.getSelectedRows()) {
_table.optimizeHeight(row);
}
}
}
@Override
public String getText() {
return "Optimal row height";
}
}
| 1,503 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultCCPStrategy.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/strategies/DefaultCCPStrategy.java | /*
* File: DefaultCCPStrategy.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.strategies;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IJaretTableCell;
import de.jaret.util.ui.table.model.IJaretTableSelection;
/**
* Default implementation for cut, copy, paste. See the the description of the methods for details. The implementation
* is not yet perfect. It uses "brutal" String conversions. May be it would best to introduce converter services in the
* table model (optional) or use methods in renderers or editors for conversion.
*
* @author Peter Kliem
* @version $Id: DefaultCCPStrategy.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class DefaultCCPStrategy implements ICCPStrategy {
/** Delimiter used when copying. */
private static final String COPY_DELIMITER = "\t";
/** Delimiters for separating fields in paste operations. */
private static final String PASTE_DELIMITERS = "\t;";
/** Clipboard instance. */
private Clipboard _clipboard;
/** If set to true header labels will always included in copies. */
private boolean _includeHeadersInCopy = false;
/**
* Aquire clipboard.
*
* @return Clipboard instance
*/
private synchronized Clipboard getClipboard() {
if (_clipboard == null) {
_clipboard = new Clipboard(Display.getCurrent());
}
return _clipboard;
}
/**
* {@inheritDoc}
*/
public void dispose() {
if (_clipboard != null) {
_clipboard.dispose();
}
}
/**
* Do the copy operation using the constant COPY_DELIMITER. Empty lines will be omitted, missing cels will be empty.
*
* @param table jaret table the operation is invoked on
*/
public void copy(JaretTable table) {
cutOrCopy(table, false);
}
/**
* Do the cut operation. Basicly a a copy and a empty operation.
*
* @param table jaret table the operation is invoked on
*/
public void cut(JaretTable table) {
cutOrCopy(table, true);
}
/**
* Do the actual copy or cut operation.
*
* @param table table
* @param cut if set to true cells we be emptied
*/
protected void cutOrCopy(JaretTable table, boolean cut) {
IJaretTableSelection selection = table.getSelectionModel().getSelection();
Clipboard cb = getClipboard();
if (!selection.isEmpty()) {
Set<IJaretTableCell> cells = selection.getAllSelectedCells(table.getTableModel());
int minx = -1;
int maxx = -1;
int miny = -1;
int maxy = -1;
// line is the outer map
Map<Integer, Map<Integer, IJaretTableCell>> cellMap = new HashMap<Integer, Map<Integer, IJaretTableCell>>();
for (IJaretTableCell cell : cells) {
Point p = table.getCellDisplayIdx(cell);
Map<Integer, IJaretTableCell> lineMap = cellMap.get(p.y);
if (lineMap == null) {
lineMap = new HashMap<Integer, IJaretTableCell>();
cellMap.put(p.y, lineMap);
}
if (miny == -1 || p.y < miny) {
miny = p.y;
}
if (maxy == -1 || p.y > maxy) {
maxy = p.y;
}
lineMap.put(p.x, cell);
if (minx == -1 || p.x < minx) {
minx = p.x;
}
if (maxx == -1 || p.x > maxx) {
maxx = p.x;
}
}
StringBuilder buf = new StringBuilder();
if (_includeHeadersInCopy) {
for (int x = minx; x <= maxx; x++) {
String headerLabel = table.getColumn(x).getHeaderLabel();
buf.append(headerLabel);
buf.append(COPY_DELIMITER);
}
buf.append("\n");
}
for (int y = miny; y <= maxy; y++) {
Map<Integer, IJaretTableCell> lineMap = cellMap.get(y);
// empty lines are ommitted
if (lineMap != null) {
for (int x = minx; x <= maxx; x++) {
IJaretTableCell cell = lineMap.get(x);
String value = null;
if (cell != null) {
Object val = cell.getColumn().getValue(cell.getRow());
value = val != null ? val.toString() : null;
if (cut) {
emptyCell(cell);
}
}
if (value != null) {
buf.append(value);
}
buf.append(COPY_DELIMITER);
}
buf.append("\n");
}
}
TextTransfer textTransfer = TextTransfer.getInstance();
cb.setContents(new Object[] {buf.toString()}, new Transfer[] {textTransfer});
}
}
/**
* Empty the given cell. First try null, if an exception is thrown by the modell try the empty string.
*
* @param cell cell to be emptied
*/
protected void emptyCell(IJaretTableCell cell) {
try {
cell.getColumn().setValue(cell.getRow(), null);
} catch (Exception e) {
try {
cell.getColumn().setValue(cell.getRow(), "");
} catch (Exception ex) {
// ignore
}
}
}
/**
* Paste pastes textual context starting at the focussed cell (does not use the selection by now). Uses TAB and
* semicolon as delimiters (Excel uses TAB, semicolon for pasting csv).
*
* @param table the jaret table
*/
public void paste(JaretTable table) {
Clipboard cb = getClipboard();
TextTransfer textTransfer = TextTransfer.getInstance();
Object content = cb.getContents(textTransfer);
if (content != null) {
if (content instanceof String) {
String string = (String) content;
List<String> lines = new ArrayList<String>();
StringTokenizer tokenizer = new StringTokenizer(string, "\n");
while (tokenizer.hasMoreTokens()) {
lines.add(tokenizer.nextToken());
}
Point focus = table.getFocussedCellIdx();
if (focus == null) {
table.setFocus();
focus = table.getFocussedCellIdx();
}
int lineOff = 0;
for (String line : lines) {
tokenizer = new StringTokenizer(line, PASTE_DELIMITERS, true);
int colOff = 0;
String last = null;
while (tokenizer.hasMoreTokens()) {
String value = tokenizer.nextToken();
boolean ignore = false;
if (PASTE_DELIMITERS.indexOf(value) != -1) {
// delimiter
if (last != null && last.equals(value)) {
value = "";
} else {
ignore = true;
}
}
if (!ignore) {
try {
table.setValue(focus.x + colOff, focus.y + lineOff, value);
} catch (Exception e) {
// silently ignore -- this can happen
}
colOff++;
}
last = value;
}
lineOff++;
}
}
}
}
/**
* Retrieve the state of header include in the copied content.
*
* @return the includeHeadersInCopy
*/
public boolean getIncludeHeadersInCopy() {
return _includeHeadersInCopy;
}
/**
* Set includeHeaders: if set to true in copy and cut context the headline (=col headers) labels will be included.
*
* @param includeHeadersInCopy the includeHeadersInCopy to set
*/
public void setIncludeHeadersInCopy(boolean includeHeadersInCopy) {
_includeHeadersInCopy = includeHeadersInCopy;
}
}
| 9,537 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ICCPStrategy.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/strategies/ICCPStrategy.java | /*
* File: ICCPStrategy.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.strategies;
import de.jaret.util.ui.table.JaretTable;
/**
* Interface describing the strategies used for Cut, Copy and Paste.
*
* @author Peter Kliem
* @version $Id: ICCPStrategy.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface ICCPStrategy {
/**
* Do the cut operation.
*
* @param table table the operation should be performed on
*/
void cut(JaretTable table);
/**
* Do the copy operation.
*
* @param table table the operation should be performed on
*/
void copy(JaretTable table);
/**
* Do the paste operation.
*
* @param table table the operation should be performed on
*/
void paste(JaretTable table);
/**
* If there is something to dispose ... most probably the clipboard instance.
*
*/
void dispose();
}
| 1,337 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultFillDragStrategy.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/strategies/DefaultFillDragStrategy.java | /*
* File: DefaultFillDragStrategy.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.strategies;
import java.util.List;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IJaretTableCell;
/**
* Defaut implementation of a fill drag strategy: simply copy the content.
*
* @author Peter Kliem
* @version $Id: DefaultFillDragStrategy.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class DefaultFillDragStrategy implements IFillDragStrategy {
/**
* {@inheritDoc}
*/
public void doFill(JaretTable table, IJaretTableCell firstCell, List<IJaretTableCell> cells) {
Object value = firstCell.getColumn().getValue(firstCell.getRow());
for (IJaretTableCell cell : cells) {
// check whether destination cell is editable
if (table.getTableModel().isEditable(cell.getRow(), cell.getColumn())) {
try {
cell.getColumn().setValue(cell.getRow(), value);
} catch (Exception e) {
// whatever happens -- ignore it
}
}
}
}
}
| 1,527 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IFillDragStrategy.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/strategies/IFillDragStrategy.java | /*
* File: IFillDragStrategy.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.strategies;
import java.util.List;
import de.jaret.util.ui.table.JaretTable;
import de.jaret.util.ui.table.model.IJaretTableCell;
/**
* Interface describing a stragey used when cells should be filled after a fill drag.
*
* @author Peter Kliem
* @version $Id: IFillDragStrategy.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface IFillDragStrategy {
/**
* Do a fill operation fro the first cell to the other cells.
*
* @param table table requesting the operation
* @param firstCell originating cell
* @param cells cells to be filled
*/
void doFill(JaretTable table, IJaretTableCell firstCell, List<IJaretTableCell> cells);
}
| 1,164 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AbstractColumn.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/AbstractColumn.java | /*
* File: AbstractColumn.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import java.util.List;
import java.util.Vector;
/**
* Abstract base implemenation of an IColumn.
*
* @author Peter Kliem
* @version $Id: AbstractColumn.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public abstract class AbstractColumn implements IColumn {
/** column listeners. */
protected List<IColumnListener> _listeners;
/**
* Inform listeners about a value change.
*
* @param row row
* @param column column
* @param oldValue old value
* @param newValue new value
*/
protected void fireValueChanged(IRow row, IColumn column, Object oldValue, Object newValue) {
if (_listeners != null) {
for (IColumnListener listener : _listeners) {
listener.valueChanged(row, column, oldValue, newValue);
}
}
}
/**
* {@inheritDoc}
*/
public synchronized void addColumnListener(IColumnListener cl) {
if (_listeners == null) {
_listeners = new Vector<IColumnListener>();
}
_listeners.add(cl);
}
/**
* {@inheritDoc}
*/
public void remColumnListener(IColumnListener cl) {
if (_listeners != null) {
_listeners.remove(cl);
}
}
/**
* Default implementation: no difference to getContentClass(). {@inheritDoc}
*/
public Class<?> getContentClass(IRow row) {
return getContentClass();
}
/**
* Header display always defaults to true. {@inheritDoc}
*/
public boolean displayHeader() {
return true;
}
/**
* Deafult: cols are aditable.
*
* @return true
*/
public boolean isEditable() {
return true;
}
/**
* Default: delegate to <code>isEditable</code>. {@inheritDoc}
*/
public boolean isEditable(IRow row) {
return isEditable();
}
}
| 2,416 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
JaretTableSelectionImpl.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/JaretTableSelectionImpl.java | /*
* File: JaretTableSelectionImpl.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Implementation of the JaretTableSelection.
*
* @author Peter Kliem
* @version $Id: JaretTableSelectionImpl.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class JaretTableSelectionImpl implements IJaretTableSelection {
/** selected rows. */
protected List<IRow> _rows = new ArrayList<IRow>();
/** selected columns. */
protected List<IColumn> _columns = new ArrayList<IColumn>();
/** selected cells. */
protected List<IJaretTableCell> _cells = new ArrayList<IJaretTableCell>();
/**
* {@inheritDoc}
*/
public void clear() {
_rows.clear();
_columns.clear();
_cells.clear();
}
/**
* {@inheritDoc}
*/
public List<IRow> getSelectedRows() {
return _rows;
}
/**
* {@inheritDoc}
*/
public List<IColumn> getSelectedColumns() {
return _columns;
}
/**
* {@inheritDoc}
*/
public List<IJaretTableCell> getSelectedCells() {
return _cells;
}
/**
* {@inheritDoc}
*/
public void addRow(IRow row) {
_rows.add(row);
}
/**
* {@inheritDoc}
*/
public void remRow(IRow row) {
_rows.remove(row);
}
/**
* {@inheritDoc}
*/
public void addColumn(IColumn column) {
_columns.add(column);
}
/**
* {@inheritDoc}
*/
public void remColumn(IColumn column) {
_columns.remove(column);
}
/**
* {@inheritDoc}
*/
public void addCell(IJaretTableCell cell) {
_cells.add(cell);
}
/**
* {@inheritDoc}
*/
public void remCell(IJaretTableCell cell) {
_cells.remove(cell);
}
/**
* {@inheritDoc}
*/
public boolean isEmpty() {
return _rows.size() == 0 && _columns.size() == 0 && _cells.size() == 0;
}
/**
* {@inheritDoc}
*/
public Set<IJaretTableCell> getAllSelectedCells(IJaretTableModel model) {
Set<IJaretTableCell> set = new HashSet<IJaretTableCell>();
for (IRow row : _rows) {
for (int i = 0; i < model.getColumnCount(); i++) {
JaretTableCellImpl cell = new JaretTableCellImpl(row, model.getColumn(i));
set.add(cell);
}
}
for (IColumn col : _columns) {
for (int i = 0; i < model.getRowCount(); i++) {
JaretTableCellImpl cell = new JaretTableCellImpl(model.getRow(i), col);
set.add(cell);
}
}
set.addAll(_cells);
return set;
}
}
| 3,269 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IJaretTableSelection.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/IJaretTableSelection.java | /*
* File: IJaretTableSelection.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import java.util.List;
import java.util.Set;
/**
* Interface describing the selection in a jaret table. The selection is composed of full selected rows and columns and
* of a list of selected cells. If the selection contains full selected rows or columns, the cells of the rows/columns
* are not included in the list of single cells.
*
* @author Peter Kliem
* @version $Id: IJaretTableSelection.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface IJaretTableSelection {
/**
* Retrieve selected rows.
*
* @return selected rows.
*/
List<IRow> getSelectedRows();
/**
* Retrieve selected Columns.
*
* @return selecetd columns
*/
List<IColumn> getSelectedColumns();
/**
* Retrieve cells that have been selected seperately.
*
* @return List of JaretTableCells selected seperately
*/
List<IJaretTableCell> getSelectedCells();
/**
* Retrieve a set of all selected cells (union of all cells in selected rows and columns plus. the cells selected
* seperately)
*
* @param model is needed to determine all cells.
* @return Set of all selected cells.
*/
Set<IJaretTableCell> getAllSelectedCells(IJaretTableModel model);
/**
* Add a row to the selection.
*
* @param row the row to add
*/
void addRow(IRow row);
/**
* Remove row from selection.
*
* @param row row to remove
*/
void remRow(IRow row);
/**
* Add a acolumn to the selection.
*
* @param column column to add
*/
void addColumn(IColumn column);
/**
* Remove column from the selection.
*
* @param column col to remove
*/
void remColumn(IColumn column);
/**
* Add a cell to the selection.
*
* @param cell cell to add
*/
void addCell(IJaretTableCell cell);
/**
* Remove a cell from the selection.
*
* @param cell cell to remove
*/
void remCell(IJaretTableCell cell);
/**
* Check if something is selected.
*
* @return true if the selection is empty
*/
boolean isEmpty();
/**
* Clear the selection.
*
*/
void clear();
}
| 2,812 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IHierarchicalTableViewStateListener.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/IHierarchicalTableViewStateListener.java | /*
* File: IHierarchicalTableViewStateListener.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
/**
* Listener interface for listening on expanded/folded events.
*
* @author Peter Kliem
* @version $Id: IHierarchicalTableViewStateListener.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface IHierarchicalTableViewStateListener {
/**
* Node has been expanded.
*
* @param node node that has been expanded.
*/
void nodeExpanded(ITableNode node);
/**
* Node has been folded/collapsed.
*
* @param node node that had been folded
*/
void nodeFolded(ITableNode node);
}
| 1,050 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AbstractRowFilter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/AbstractRowFilter.java | /*
* File: AbstractRowFilter.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import de.jaret.util.misc.PropertyObservableBase;
import de.jaret.util.ui.table.filter.IRowFilter;
/**
* Abstract base implementation of a RowFilter to allow easy anonymous inner classes to be constructed.
*
* @author Peter Kliem
* @version $Id: AbstractRowFilter.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public abstract class AbstractRowFilter extends PropertyObservableBase implements IRowFilter {
}
| 895 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ITableViewState.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/ITableViewState.java | /*
* File: ITableViewState.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import java.util.List;
import de.jaret.util.ui.table.renderer.ICellStyle;
import de.jaret.util.ui.table.renderer.ICellStyleProvider;
/**
* View state of a jaret table. The viewstate controls the rendering of the model (i.e. row heights).
*
* @author Peter Kliem
* @version $Id: ITableViewState.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface ITableViewState {
/**
* Enumeration for the row height mode of a table row.
* <ul>
* <li>FIXED: fixed height</li>
* <li>OPTIMAL: height will be optimal with information from the renderers. Manual resize of the row will not be
* possible.</li>
* <li>OPTANDVAR: like OPTIMAL. When the height of the row is changed manually the row height mode is changed to
* VARIABLE</li>
* <li>VARIABLE: height variable by dragging</li>
* </ul>
*/
static enum RowHeightMode {
FIXED, OPTIMAL, OPTANDVAR, VARIABLE
};
/**
* Enumeration for the possible resize behaviours:
* <ul>
* <li>NONE: resize will only have an effect on the resized column</li>
* <li>SUBSEQUENT: resize will take/give the space from the next visible column (unless minwidth is reached)</li>
* <li>ALLSUBSEQUENT: resize will take/give the space from all following visible columns (unless minwidth of those
* is reached)</li>
* <li>ALL: width is interpreted as a weight; all columns will be resized</li>
* </ul>
* Recommended mode is NONE since the other modes result in heavy redraw activity.
*/
static enum ColumnResizeMode {
NONE, SUBSEQUENT, ALLSUBSEQUENT, ALL
};
static enum HAlignment {
LEFT, RIGHT, CENTER
};
static enum VAlignment {
TOP, BOTTOM, CENTER
};
/**
* Retrieve the current height of a row.
*
* @param row row to query the height for.
* @return height in pixel.
*/
int getRowHeight(IRow row);
/**
* Set the height of a row.
*
* @param row row
* @param height height
*/
void setRowHeight(IRow row, int height);
/**
* Set the row height for ALL rows.
*
* @param height height
*/
void setRowHeight(int height);
/**
* Get the configured minimal row heigth.
*
* @return minimal row height
*/
int getMinimalRowHeight();
/**
* Set the minimal row height.
*
* @param minimalRowHeight value to set
*/
void setMinimalRowHeight(int minimalRowHeight);
/**
* Retrieve the row heigth mode for a specific row.
*
* @param row row to get the heigth mode for
* @return the row height mode
*/
RowHeightMode getRowHeigthMode(IRow row);
/**
* Set the row height mode for a specific row.
*
* @param row row to set the height mode for
* @param mode mode to set.
*/
void setRowHeightMode(IRow row, RowHeightMode mode);
/**
* Set the row heigth mode for all rows and the mode to use as the default for new rows.
*
* @param mode mode to be used.
*/
void setRowHeightMode(RowHeightMode mode);
/**
* Retrieve the default row heigth mode.
*
* @return the default row height mode.
*/
RowHeightMode getRowHeightMode();
/**
* retrive the width of a column.
*
* @param column column
* @return the width in pixel
*/
int getColumnWidth(IColumn column);
/**
* Set the width of a column.
*
* @param column column
* @param width width in pixel
*/
void setColumnWidth(IColumn column, int width);
/**
* Retrieve the minimum column width.
*
* @return the minimum width a col can be shrinked to
*/
int getMinimalColWidth();
/**
* Set the minimum col width.
*
* @param minimalColumnWidth width a column can be minimal sized to
*/
void setMinimalColWidth(int minimalColumnWidth);
/**
* Check whether a column is visible.
*
* @param column column
* @return true if the col is visible
*/
boolean getColumnVisible(IColumn column);
/**
* Set the visibility of a column.
*
* @param column column
* @param visible true for visible
*/
void setColumnVisible(IColumn column, boolean visible);
/**
* Set the visibility of a column.
*
* @param columnID id of the column
* @param visible true for visible
*/
void setColumnVisible(String columnID, boolean visible);
/**
* Check whether resizing of a column is allowed.
*
* @param column column
* @return true if resizing is allowed
*/
boolean columnResizingAllowed(IColumn column);
/**
* Set whether resizing a column is allowed.
*
* @param column column
* @param resizingAllowed true for allow resizing
*/
void setColumnResizingAllowed(IColumn column, boolean resizingAllowed);
/**
* Retrieve the mode used when resizing a column.
*
* @return the current column resizing mode
*/
ColumnResizeMode getColumnResizeMode();
/**
* Set the mode to use when the size of a column changes.
*
* @param resizeMode the resize mode.
*/
void setColumnResizeMode(ColumnResizeMode resizeMode);
/**
* Retrieve the list of columns in their display order.
*
* @return List of columnsin their display order
*/
List<IColumn> getSortedColumns();
/**
* Set the order of the columns.
*
* @param columns ordered list of columns
*/
void setSortedColumns(List<IColumn> columns);
/**
* Retrieve the position in the sorting order set.
*
* @param column column
* @return position
*/
int getColumnSortingPosition(IColumn column);
/**
* Retrieve the sorting direction for a column.
*
* @param column column to check the sorting direction
* @return true for ascending, false for descending
*/
boolean getColumnSortingDirection(IColumn column);
/**
* Handle the slection of a column for sorting (handle a click).
*
* @param column column to add to the sorting (or to reverse its sorting direction)
*/
void setSorting(IColumn column);
/**
* Retrieve the cell style provider of the viewstate.
*
* @return the cell style provider
*/
ICellStyleProvider getCellStyleProvider();
/**
* Retrieve the cell style for a specified cell.
*
* @param row row of the cell
* @param column column of the cell
* @return the cellstyle for the cell
*/
ICellStyle getCellStyle(IRow row, IColumn column);
/**
* Add a listener to be informed about changes on the viewstate.
*
* @param tvsl listener to add
*/
void addTableViewStateListener(ITableViewStateListener tvsl);
/**
* Remove a listener from the viewstate.
*
* @param tvsl listener to be removed
*/
void removeTableViewStateListener(ITableViewStateListener tvsl);
}
| 7,845 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
HierarchyColumn.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/HierarchyColumn.java | /*
* File: HierarchyColumn.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
/**
* Dummy column for placement of the hierarchy.
*
* @author Peter Kliem
* @version $Id: HierarchyColumn.java,v 1.1 2012-05-07 01:34:36 jason Exp $
*/
public class HierarchyColumn extends AbstractColumn {
/**
* {@inheritDoc}
*/
public String getId() {
return "hierarchycolumnID";
}
/**
* {@inheritDoc}
*/
public String getHeaderLabel() {
return "hierarchy";
}
/**
* {@inheritDoc}
*/
@Override
public boolean displayHeader() {
return false;
}
/**
* {@inheritDoc}
*/
public Object getValue(IRow row) {
return "hierarchy column";
}
/**
* {@inheritDoc}
*/
public void setValue(IRow row, Object value) {
}
/**
* {@inheritDoc}
*/
public boolean supportsSorting() {
return false;
}
/**
* {@inheritDoc}
*/
public Class<?> getContentClass() {
return String.class;
}
/**
* {@inheritDoc}
*/
public int compare(IRow o1, IRow o2) {
return 0;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isEditable() {
return false;
}
}
| 1,737 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IJaretTableCell.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/IJaretTableCell.java | /*
* File: IJaretTableCell.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
/**
* Interface describing the location (in the data model) of a single cell.
*
* @author Peter Kliem
* @version $Id: IJaretTableCell.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface IJaretTableCell {
/**
* Retrieve the row.
*
* @return the row of the cell
*/
IRow getRow();
/**
* Retrieve the column.
*
* @return the column of the cell
*/
IColumn getColumn();
}
| 929 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
JaretTableSelectionModelImpl.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/JaretTableSelectionModelImpl.java | /*
* File: JaretTableSelectionModelImpl.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
/**
* Implementation of the JaretTableSelectionModel.
*
* @author Peter Kliem
* @version $Id: JaretTableSelectionModelImpl.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class JaretTableSelectionModelImpl implements IJaretTableSelectionModel {
/** listeners to inform. */
protected List<IJaretTableSelectionModelListener> _listeners;
/** true for allowance of full row selection. */
protected boolean _fullRowSelectionAllowed = true;
/** true for allowance of full column selection. */
protected boolean _fullColumnSelectionAllowed = true;
/** true for allowance of single cell selection. */
protected boolean _cellSelectioAllowed = true;
/** true if multiple selection of more than one elemnt is allowed. */
protected boolean _multipleSelectionAllowed = true;
/** true if only row selections are allowed. */
protected boolean _onlyRowSelectionAllowed = false;
/** the selection data store. */
protected IJaretTableSelection _selection = new JaretTableSelectionImpl();
/**
* {@inheritDoc}
*/
public void clearSelection() {
List<IRow> l = new ArrayList<IRow>();
l.addAll(_selection.getSelectedRows());
for (IRow row : l) {
remSelectedRow(row);
}
List<IColumn> c = new ArrayList<IColumn>();
c.addAll(_selection.getSelectedColumns());
for (IColumn col : c) {
remSelectedColumn(col);
}
List<IJaretTableCell> t = new ArrayList<IJaretTableCell>();
t.addAll(_selection.getSelectedCells());
for (IJaretTableCell cell : t) {
remSelectedCell(cell);
}
}
/**
* {@inheritDoc}
*/
public boolean isFullRowSelectionAllowed() {
return _fullRowSelectionAllowed;
}
/**
* {@inheritDoc}
*/
public void setFullRowSelectionAllowed(boolean allowed) {
_fullRowSelectionAllowed = allowed;
}
/**
* {@inheritDoc}
*/
public boolean isFullColumnSelectionAllowed() {
return _fullColumnSelectionAllowed;
}
/**
* {@inheritDoc}
*/
public void setFullColumnSelectionAllowed(boolean allowed) {
_fullColumnSelectionAllowed = allowed;
}
/**
* {@inheritDoc}
*/
public boolean isCellSelectionAllowed() {
return _cellSelectioAllowed;
}
/**
* {@inheritDoc}
*/
public void setCellSelectionAllowed(boolean allowed) {
_cellSelectioAllowed = allowed;
}
/**
* {@inheritDoc}
*/
public boolean isMultipleSelectionAllowed() {
return _multipleSelectionAllowed;
}
/**
* {@inheritDoc}
*/
public void setMultipleSelectionAllowed(boolean allowed) {
_multipleSelectionAllowed = allowed;
}
/**
* {@inheritDoc}
*/
public void addSelectedRow(IRow row) {
if (!_selection.getSelectedRows().contains(row)) {
_selection.addRow(row);
fireRowSelectionAdded(row);
}
}
/**
* {@inheritDoc}
*/
public void remSelectedRow(IRow row) {
if (_selection.getSelectedRows().contains(row)) {
_selection.remRow(row);
fireRowSelectionRemoved(row);
}
}
/**
* {@inheritDoc}
*/
public void addSelectedColumn(IColumn column) {
if (!_selection.getSelectedColumns().contains(column)) {
_selection.addColumn(column);
fireColumnSelectionAdded(column);
}
}
/**
* {@inheritDoc}
*/
public void remSelectedColumn(IColumn column) {
if (_selection.getSelectedColumns().contains(column)) {
_selection.remColumn(column);
fireColumnSelectionRemoved(column);
}
}
/**
* {@inheritDoc}
*/
public void addSelectedCell(IJaretTableCell cell) {
if (!_selection.getSelectedCells().contains(cell)) {
_selection.addCell(cell);
fireCellSelectionAdded(cell);
}
}
/**
* {@inheritDoc}
*/
public void remSelectedCell(IJaretTableCell cell) {
if (_selection.getSelectedCells().contains(cell)) {
_selection.remCell(cell);
fireCellSelectionRemoved(cell);
}
}
/**
* {@inheritDoc}
*/
public IJaretTableSelection getSelection() {
return _selection;
}
private void fireRowSelectionAdded(IRow row) {
if (_listeners != null) {
for (IJaretTableSelectionModelListener listener : _listeners) {
listener.rowSelectionAdded(row);
}
}
}
private void fireRowSelectionRemoved(IRow row) {
if (_listeners != null) {
for (IJaretTableSelectionModelListener listener : _listeners) {
listener.rowSelectionRemoved(row);
}
}
}
private void fireColumnSelectionAdded(IColumn column) {
if (_listeners != null) {
for (IJaretTableSelectionModelListener listener : _listeners) {
listener.columnSelectionAdded(column);
}
}
}
private void fireColumnSelectionRemoved(IColumn column) {
if (_listeners != null) {
for (IJaretTableSelectionModelListener listener : _listeners) {
listener.columnSelectionRemoved(column);
}
}
}
private void fireCellSelectionAdded(IJaretTableCell cell) {
if (_listeners != null) {
for (IJaretTableSelectionModelListener listener : _listeners) {
listener.cellSelectionAdded(cell);
}
}
}
private void fireCellSelectionRemoved(IJaretTableCell cell) {
if (_listeners != null) {
for (IJaretTableSelectionModelListener listener : _listeners) {
listener.cellSelectionRemoved(cell);
}
}
}
/**
* {@inheritDoc}
*/
public synchronized void addTableSelectionModelListener(IJaretTableSelectionModelListener jtsm) {
if (_listeners == null) {
_listeners = new Vector<IJaretTableSelectionModelListener>();
}
_listeners.add(jtsm);
}
/**
* {@inheritDoc}
*/
public void removeTableSelectionModelListener(IJaretTableSelectionModelListener jtsm) {
if (_listeners != null) {
_listeners.remove(jtsm);
}
}
/**
* {@inheritDoc}
*/
public boolean isOnlyRowSelectionAllowed() {
return _onlyRowSelectionAllowed;
}
/**
* {@inheritDoc}
*/
public void setOnlyRowSelectionAllowed(boolean allowed) {
_onlyRowSelectionAllowed = allowed;
}
}
| 7,557 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IHierarchicalJaretTableModel.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/IHierarchicalJaretTableModel.java | /*
* File: IHierarchicalJaretTableModel.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
/**
* Hierarchical model for the jaret table.
*
* @author Peter Kliem
* @version $Id: IHierarchicalJaretTableModel.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface IHierarchicalJaretTableModel {
/**
* Retrieve the root node.
*
* @return the root node
*/
ITableNode getRootNode();
}
| 824 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IJaretTableModel.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/IJaretTableModel.java | /*
* File: IJaretTableModel.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
/**
* Interface for the table model used by the jaret table. The model should always provide all data. Sorting and
* filtering is done by the jaret table displaying the data.
*
* @author Peter Kliem
* @version $Id: IJaretTableModel.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface IJaretTableModel {
/**
* Return the number of rows in the model.
*
* @return number of rows
*/
int getRowCount();
/**
* Retrieve a specific row.
*
* @param idx index of the row
* @return the row
*/
IRow getRow(int idx);
/**
* Retrieve the number of columns.
*
* @return the number of columns.
*/
int getColumnCount();
/**
* Retrieve a column specified by it's index.
*
* @param idx index of the column to retrieve
* @return column at index idx
*/
IColumn getColumn(int idx);
/**
* Retrieve a column specified by it's id.
*
* @param id id of the column to retrieve
* @return column for the given id or <code>null</code> if the column coud not be found
*/
IColumn getColumn(String id);
/**
* Check whether a cell is editable.
*
* @param row row of the cell
* @param column column of the cell
* @return true for an editable cell
*/
boolean isEditable(IRow row, IColumn column);
/**
* Set the value of a particular cell.
*
* @param row row of the cell
* @param column column of the cell
* @param value the value to be stored
*/
void setValue(IRow row, IColumn column, Object value);
/**
* Add a column.
*
* @param column column to add
*/
void addColumn(IColumn column);
/**
* Add a listener listening for changes on the model.
*
* @param jtml listener to add
*/
void addJaretTableModelListener(IJaretTableModelListener jtml);
/**
* Remove a listener on the model.
*
* @param jtml listener to remove
*/
void removeJaretTableModelListener(IJaretTableModelListener jtml);
}
| 2,662 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
PropCol.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/PropCol.java | /*
* File: PropCol.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
/**
* Column implementation for the jaret table using reflection (getPropName, setPropName) to retrieve the column value.
* Does not support listening for property changes on the underlying POJO (But will fire a valueChanged if the model is
* changed by setValue). Supports property paths and an optional accessor (IPropColAccessor).
*
* @todo error handling is NOT implemented correct
*
* @author Peter Kliem
* @version $Id: PropCol.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class PropCol extends AbstractColumn implements IColumn {
/** id string. */
protected String _id;
/** header label string. */
protected String _headerLabel;
/** name of the mapped property (or path separeted by dots). */
protected String _prop;
/** array of property names parsed from the property. */
protected String[] _propPath;
/** true if the col should be able to sort the table. */
protected boolean _supportSorting = true;
/** true if the column is editable. */
protected boolean _editable = true;
/** content class if specified directly. */
protected Class<?> _contentClass;
/** optional accessor. */
protected IPropColAccessor _accessor = null;
/**
* Construct the column.
*
* @param id id of the column
* @param label header label
* @param prop property name (usually starting with a capital letter or path)
* @param contentClass class of the objects held by the column
* @param accessor optinal accessor to be invoked on the property to retrive/set the value
*/
public PropCol(String id, String label, String prop, Class<?> contentClass, IPropColAccessor accessor) {
super();
_headerLabel = label;
_id = id;
_prop = prop;
initPropPath();
_contentClass = contentClass;
_accessor = accessor;
}
/**
* Construct the column.
*
* @param id id of the column
* @param label header label
* @param prop property name (usually starting with a capital letter or path)
* @param contentClass class of the objects held by the column
*/
public PropCol(String id, String label, String prop, Class<?> contentClass) {
this(id, label, prop, contentClass, null);
}
/**
* Construct the column.
*
* @param id id of the column
* @param label header label
* @param prop property name (usually starting with a capital letter or path)
*/
public PropCol(String id, String label, String prop) {
this(id, label, prop, null);
}
/**
* Parse _prop as dot separted string to the array of property names forming an access path to the property.
*/
private void initPropPath() {
StringTokenizer tokenizer = new StringTokenizer(_prop, ".");
List<String> l = new ArrayList<String>();
while (tokenizer.hasMoreTokens()) {
l.add(tokenizer.nextToken());
}
_propPath = l.toArray(new String[0]);
}
/**
* {@inheritDoc}
*/
public String getId() {
return _id;
}
/**
* {@inheritDoc}
*/
public String getHeaderLabel() {
return _headerLabel;
}
/**
* {@inheritDoc}
*/
public Object getValue(IRow row) {
if (row != null) {
try {
Object base = row;
for (int i = 0; i < _propPath.length; i++) {
String propName = _propPath[i];
Method getter = base.getClass().getMethod("get" + propName, new Class[] {});
base = getter.invoke(base, new Object[] {});
}
if (_accessor == null) {
return base;
} else {
return _accessor.getValue(base);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
/**
* {@inheritDoc}
*/
public Class<?> getContentClass(IRow row) {
if (row != null) {
try {
Object base = row;
for (int i = 0; i < _propPath.length; i++) {
String propName = _propPath[i];
Method getter = base.getClass().getMethod("get" + propName, new Class[] {});
if (i == _propPath.length - 1) {
return getter.getReturnType();
} else {
base = getter.invoke(base, new Object[] {});
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
/**
* Check whether there is a real modification between two (possible null) objects.
*
* @param o1 object1
* @param o2 object 2
* @return true if a real modification has been detected
*/
protected boolean isRealModification(Object o1, Object o2) {
if (o1 == null && o2 == null) {
return false;
}
if (o1 != null && o2 == null) {
return true;
}
if (o2 != null && o1 == null) {
return true;
}
return !o1.equals(o2);
}
/**
* {@inheritDoc}
*/
public void setValue(IRow row, Object value) {
Object oldValue = getValue(row);
if (isRealModification(oldValue, value)) {
try {
Object base = row;
for (int i = 0; i < _propPath.length - 1; i++) {
String propName = _propPath[i];
Method getter = base.getClass().getMethod("get" + propName, new Class[] {});
base = getter.invoke(base, new Object[] {});
}
if (_accessor == null) {
Class<?> clazz;
if (value == null) {
clazz = getContentClass(row);
} else {
clazz = value.getClass();
if (clazz.equals(Boolean.class)) {
clazz = Boolean.TYPE;
} else if (clazz.equals(Integer.class)) {
clazz = Integer.TYPE;
} else if (clazz.equals(Double.class)) {
clazz = Double.TYPE;
}
}
Method setter = base.getClass().getMethod("set" + _propPath[_propPath.length - 1],
new Class[] {clazz});
setter.invoke(base, new Object[] {value});
} else {
_accessor.setValue(base, value);
}
fireValueChanged(row, this, oldValue, value);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Could not set value " + e.getLocalizedMessage());
}
}
}
/**
* {@inheritDoc} Sorting default behaviour: compare <code>toString()</code>.
*/
@SuppressWarnings("unchecked")
public int compare(IRow r1, IRow r2) {
Object val1 = getValue(r1);
Object val2 = getValue(r2);
if (val1 == null && val2 == null) {
return 0;
}
if (val1 == null) {
return -1;
}
if (val2 == null) {
return 1;
}
// check for comparable types
if (val1.getClass().equals(val2.getClass())) {
if (val1 instanceof Comparable) {
return ((Comparable) val1).compareTo(val2);
}
}
return val1.toString().compareTo(val2.toString());
}
/**
* {@inheritDoc}
*/
public boolean supportsSorting() {
return _supportSorting;
}
/**
* Set whether the column should support sorting.
*
* @param supportSorting true if sorting should be supported
*/
public void setSupportSorting(boolean supportSorting) {
_supportSorting = supportSorting;
}
/**
* {@inheritDoc}
*/
public Class<?> getContentClass() {
return _contentClass;
}
/**
* {@inheritDoc}
*/
public boolean isEditable() {
return _editable;
}
/**
* Set whether the column should be editable.
*
* @param editable true for allow edit
*/
public void setEditable(boolean editable) {
_editable = editable;
}
}
| 9,391 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IRowSorter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/IRowSorter.java | /*
* File: IRowSorter.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import java.util.Comparator;
import de.jaret.util.misc.PropertyObservable;
/**
* A comparator for IRow to be set on the table. It is a PropertyObeservable to allow the table to react on changes with
* a refresh.
*
* @author Peter Kliem
* @version $Id: IRowSorter.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface IRowSorter extends Comparator<IRow>, PropertyObservable {
}
| 869 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IColumnListener.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/IColumnListener.java | /*
* File: IColumnListener.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
/**
* Interface for listening on value changes on a specific cell in a column.
*
* @author Peter Kliem
* @version $Id: IColumnListener.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface IColumnListener {
/**
* Called when a value in a column changed.
*
* @param row the row
* @param column the column
* @param oldValue the old value
* @param newValue the new value
*/
void valueChanged(IRow row, IColumn column, Object oldValue, Object newValue);
}
| 994 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ITableViewStateListener.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/ITableViewStateListener.java | /*
* File: ITableViewStateListener.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import de.jaret.util.ui.table.model.ITableViewState.RowHeightMode;
import de.jaret.util.ui.table.renderer.ICellStyle;
/**
* Interface for listening to changes on the viewstate.
*
* @author Peter Kliem
* @version $Id: ITableViewStateListener.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface ITableViewStateListener {
/**
* Height of row changed.
*
* @param row row
* @param newHeight new height
*/
void rowHeightChanged(IRow row, int newHeight);
/**
* Row height mode changed.
*
* @param row row
* @param newHeightMode new height mode
*/
void rowHeightModeChanged(IRow row, RowHeightMode newHeightMode);
/**
* Column width changed.
*
* @param column column
* @param newWidth new width
*/
void columnWidthChanged(IColumn column, int newWidth);
/**
* Called when more than one column width has changed.
*
*/
void columnWidthsChanged();
/**
* Called when the visibility of a column changed.
*
* @param column column
* @param visible true column is now visible false otherwise
*/
void columnVisibilityChanged(IColumn column, boolean visible);
/**
* Called when the sorting order for rows indicated on columns changed.
*/
void sortingChanged();
/**
* Called whenever a cellstyle has been changed.
*
* @param row row
* @param column column
* @param cellStyle new or changed cell style
*/
void cellStyleChanged(IRow row, IColumn column, ICellStyle cellStyle);
/**
* Called when the ordering of the columns changed.
*
*/
void columnOrderChanged();
}
| 2,254 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IJaretTableSelectionModel.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/IJaretTableSelectionModel.java | /*
* File: IJaretTableSelectionModel.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
/**
* Selection model for the jaret table. The selection models controls the slection istelf and the possible selection
* modes.
*
* @author Peter Kliem
* @version $Id: IJaretTableSelectionModel.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface IJaretTableSelectionModel {
/**
* Clear the selection.
*/
void clearSelection();
/**
* Check whether full row selection is allowed.
*
* @return true if full row selection is allowed.
*/
boolean isFullRowSelectionAllowed();
/**
* Set the allowance for full row selection.
*
* @param allowed true for allowed
*/
void setFullRowSelectionAllowed(boolean allowed);
/**
* Check whether full column selection is allowed.
*
* @return true if full column selection is allowed.
*/
boolean isFullColumnSelectionAllowed();
/**
* Set the allowance for full column selection.
*
* @param allowed true for allowed
*/
void setFullColumnSelectionAllowed(boolean allowed);
/**
*
* @return true if selection of single cells is allowed
*/
boolean isCellSelectionAllowed();
/**
* Set allowance for single cell selections.
*
* @param allowed true for allowed
*/
void setCellSelectionAllowed(boolean allowed);
/**
* Retrieve allowance for multiple elements selectable.
*
* @return true if multiple elemets should be selectable
*/
boolean isMultipleSelectionAllowed();
/**
* Set the allowance for multiple selection.
*
* @param allowed true for allowed
*/
void setMultipleSelectionAllowed(boolean allowed);
/**
* Check whether only row selection is allowed.
*
* @return true if only rows should be selectable
*/
boolean isOnlyRowSelectionAllowed();
/**
* If set to true only row selection is allowed.
*
* @param allowed true for only row selection
*/
void setOnlyRowSelectionAllowed(boolean allowed);
/**
* Add a row to the selection.
*
* @param row element to be added to the selection
*/
void addSelectedRow(IRow row);
/**
* Remove a row from the selection.
*
* @param row element to be removed from the selection
*/
void remSelectedRow(IRow row);
/**
* Add a column to the selection.
*
* @param column element to be added to the selection
*/
void addSelectedColumn(IColumn column);
/**
* Remove a column from the selection.
*
* @param column element to be removed from the selection
*/
void remSelectedColumn(IColumn column);
/**
* Add a cell to the selection.
*
* @param cell element to be added to the selection
*/
void addSelectedCell(IJaretTableCell cell);
/**
* Remove a cell from the selection.
*
* @param cell element to be removed from the selection
*/
void remSelectedCell(IJaretTableCell cell);
/**
* retrieve the selected elements in the tabel selection structure.
*
* @return selected elements
*/
IJaretTableSelection getSelection();
/**
* Add a listener to listen to changes of the selection.
*
* @param jtsm listener
*/
void addTableSelectionModelListener(IJaretTableSelectionModelListener jtsm);
/**
* Remove a listener.
*
* @param jtsm listener to be removed
*/
void removeTableSelectionModelListener(IJaretTableSelectionModelListener jtsm);
}
| 4,212 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AbstractRowSorter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/AbstractRowSorter.java | /*
* File: AbstractRowSorter.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import de.jaret.util.misc.PropertyObservableBase;
/**
* Abstract RowSorter base for easy creating of anonymous inner classes.
*
* @author Peter Kliem
* @version $Id: AbstractRowSorter.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public abstract class AbstractRowSorter extends PropertyObservableBase implements IRowSorter {
}
| 814 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IRow.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/IRow.java | /*
* File: IRow.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
/**
* Row interface for rows used with jaret table models. The unique id is <b>only</b> used for persisting view state
* information (a feature most users do appreciate).
*
* @author Peter Kliem
* @version $Id: IRow.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface IRow {
/**
* Used for storing the row height (identification purposes).
*
* @return a unique id
*/
String getId();
}
| 902 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultHierarchicalTableModel.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/DefaultHierarchicalTableModel.java | /*
* File: DefaultHierarchicalTableModel.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
/**
* Default implementation of a hierarchical jaret table model.
*
* @author Peter Kliem
* @version $Id: DefaultHierarchicalTableModel.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class DefaultHierarchicalTableModel implements IHierarchicalJaretTableModel {
/** the root node. */
protected ITableNode _root;
/**
* Construct the model.
*
* @param root the root node
*/
public DefaultHierarchicalTableModel(ITableNode root) {
_root = root;
}
/**
* {@inheritDoc}
*/
public ITableNode getRootNode() {
return _root;
}
}
| 1,119 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IColumn.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/IColumn.java | /*
* File: IColumn.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import java.util.Comparator;
/**
* Interface for a column used in a jaret table model. The unique id is <b>only</b> used for storing view state
* information.
*
* @author Peter Kliem
* @version $Id: IColumn.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface IColumn extends Comparator<IRow> {
/**
* Id is used for storing the column width. It has to be unique among all columns if the use of the view state
* persisting support will be used.
*
* @return unique id.
*/
String getId();
/**
* Return a textual label to be displayed as the column header label.
*
* @return header label
*/
String getHeaderLabel();
/**
* Should return true for a header to be painted. Note that this ia a small violation of the separation between
* viewstate and data. However this can be tolerated.
*
* @return true when a header should be painted
*/
boolean displayHeader();
/**
* Retrieve the value of the column for the given row.
*
* @param row the row
* @return the column value for the given row.
*/
Object getValue(IRow row);
/**
* Set the value of the coloumn for a given row.
*
* @param row the row
* @param value value to set
*/
void setValue(IRow row, Object value);
/**
* Check whether the column supports sorting.
*
* @return true when sorting is supported.
*/
boolean supportsSorting();
/**
* To allow null values as column value and to support cell editing and displaying a column may support this method
* for supplying the information.
*
* @return the contained class or null if the information is not available.
*/
Class<?> getContentClass();
/**
* To specify a content class per row this method may be implemented to reflect the appropriate class.
*
* @param row row of which to get the content class
* @return contained class or null if the information is not available.
*/
Class<?> getContentClass(IRow row);
/**
* Check whether the column can be edited.
*
* @return true if the values of the columns can be changed
*/
boolean isEditable();
/**
* Check whether a a specific cell of the column can be edited.
*
* @param row row specifying the cell in the column
* @return true if the ell can be changed
*/
boolean isEditable(IRow row);
/**
* Add a listener to listen on changes on the column.
*
* @param cl listener to add
*/
void addColumnListener(IColumnListener cl);
/**
* Remove a column listener.
*
* @param cl listener to remove
*/
void remColumnListener(IColumnListener cl);
}
| 3,358 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
StdHierarchicalTableModel.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/StdHierarchicalTableModel.java | /*
* File: StdHierarchicalTableModel.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import de.jaret.util.misc.PropertyObservable;
/**
* Implementation of a "normal" jaret table model based on a hierarchical jaret table model. The StdHierarchicalmodel
* will listen on propchanges if the nodes are PropertyObservables.
*
* @author Peter Kliem
* @version $Id: StdHierarchicalTableModel.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class StdHierarchicalTableModel extends AbstractJaretTableModel implements IHierarchicalTableViewStateListener,
ITableNodeListener, PropertyChangeListener {
/**
* Current row list = list of visible nodes.
*/
protected List<ITableNode> _rows;
/** the hierarchical model this "normal" model maps. */
protected IHierarchicalJaretTableModel _hModel;
/** the hierarchical viewstate responsible for node visibility. */
protected IHierarchicalTableViewState _hvs;
/** the list of columns. */
protected List<IColumn> _cols = new ArrayList<IColumn>();
/**
* Construct a new stdhierarchical table model for a viewstate and a hierarchical model.
*
* @param hModel hierarchical table model
* @param hvs hierarchical viewstate
*/
public StdHierarchicalTableModel(IHierarchicalJaretTableModel hModel, IHierarchicalTableViewState hvs) {
_hModel = hModel;
_hvs = hvs;
_hvs.addHierarchicalViewstateListener(this);
updateRowList();
}
/**
* Register as propchange listener if node is observable.
*
* @param node node
*/
private void registerPropChange(ITableNode node) {
// listen for propertychanges if we are dealing with a propertyobservable
if (node instanceof PropertyObservable) {
((PropertyObservable) node).addPropertyChangeListener(this);
}
}
/**
* Deregister as propchange listener if node is observable.
*
* @param node node
*/
private void deRegisterPropChange(ITableNode node) {
if (node instanceof PropertyObservable) {
((PropertyObservable) node).removePropertyChangeListener(this);
}
}
/**
* Update the internal rowlist by traversing the hierarchy.
*/
private void updateRowList() {
_rows = new ArrayList<ITableNode>();
updateRowList(_rows, 0, _hModel.getRootNode(), true);
}
/**
* Recursive creation of the list of rows.
*
* @param rows list to be filled
* @param level current level
* @param node current node
* @param visible true if visible
*/
private void updateRowList(List<ITableNode> rows, int level, ITableNode node, boolean visible) {
if (visible) {
rows.add(node);
registerPropChange(node);
}
node.addTableNodeListener(this);
// set the level of the node
node.setLevel(level);
for (ITableNode n : node.getChildren()) {
updateRowList(rows, level + 1, n, _hvs.isExpanded(node) && visible);
}
}
/**
* Check whether more siblings exist for a given node on a given level.
* @param node node
* @param level level
* @return true if more siblings exist (even with other parent)
*/
public boolean moreSiblings(ITableNode node, int level) {
int idx = _rows.indexOf(node);
if (idx == -1) {
throw new RuntimeException();
}
if (node.getLevel() == level) {
return getNextSibling(node) != null;
} else {
ITableNode n = node;
for (int l = node.getLevel(); l > level + 1; l--) {
n = getParent(n);
}
return getNextSibling(n) != null;
}
}
/**
* Return the next sibling of a node.
*
* @param node node to get the next sibling for
* @return the sibling or <code>null</code> if there is none
*/
public ITableNode getNextSibling(ITableNode node) {
ITableNode parent = getParent(node);
if (parent == null) {
return null;
}
int idx = parent.getChildren().indexOf(node);
if (parent.getChildren().size() > idx + 1) {
return parent.getChildren().get(idx + 1);
} else {
return null;
}
}
/**
* Retrieve the parent of a particular node.
*
* @param node node
* @return parent of the node or <code>null</code> if it is the root node or is not in the list of nodes (not
* visible)
*/
private ITableNode getParent(ITableNode node) {
int idx = _rows.indexOf(node);
if (idx == -1) {
return null;
}
for (int i = idx - 1; i >= 0; i--) {
ITableNode n = _rows.get(i);
if (n.getChildren().contains(node)) {
return n;
}
}
return null;
}
/**
* Check whether a node is visible.
*
* @param node node to check
* @return true if the node is visible
*/
public boolean isVisible(ITableNode node) {
return getIdxForNode(node) != -1;
}
/**
* Get the index of a node in the list of visible nodes.
*
* @param node node to check
* @return index or -1 if not found
*/
private int getIdxForNode(ITableNode node) {
return _rows.indexOf(node);
}
/**
* {@inheritDoc}
*/
public IRow getRow(int rowIdx) {
return _rows.get(rowIdx);
}
/**
* {@inheritDoc}
*/
public int getRowCount() {
return _rows.size();
}
/**
* {@inheritDoc}
*/
public void nodeAdded(ITableNode parent, ITableNode newChild) {
newChild.addTableNodeListener(this);
if (_hvs.isExpanded(parent)) {
// search the position of the new child and add the row
Map<ITableNode, Integer> map = new HashMap<ITableNode, Integer>();
posForNode(parent, map);
int pos = map.get(newChild);
_rows.add(pos, newChild);
fireRowAdded(pos, newChild);
// if the new child has children and is expanded, add all of its children
List<ITableNode> toAdd = new ArrayList<ITableNode>();
enumerateChildren(newChild, toAdd);
pos++;
for (ITableNode tableNode : toAdd) {
_rows.add(pos, tableNode);
fireRowAdded(pos, tableNode);
pos++;
}
}
}
/**
* Fill a list with all children of the given node that are visible.
*
* @param node starting ndoe
* @param children list to fill
*/
private void enumerateChildren(ITableNode node, List<ITableNode> children) {
if (node.getChildren() != null && _hvs.isExpanded(node)) {
for (ITableNode tableNode : node.getChildren()) {
children.add(tableNode);
enumerateChildren(tableNode, children);
}
}
}
/**
* Fill a map with the index positions for the underlying nodes.
*
* @param node starting node
* @param map map to fill with the indizes
* @return "inserted" count for recursive call
*/
private int posForNode(ITableNode node, Map<ITableNode, Integer> map) {
int idx = getIdxForNode(node);
int count = node.getChildren().size();
int inserted = 0;
for (int i = 0; i < count; i++) {
ITableNode n = node.getChildren().get(i);
map.put(n, idx + 1 + inserted);
inserted++;
if (_hvs.isExpanded(n) && n.getChildren().size() > 0) {
inserted += posForNode(n, map);
}
}
return inserted;
}
/**
* {@inheritDoc}
*/
public void nodeRemoved(ITableNode parent, ITableNode removedChild) {
removedChild.removeTableNodeListener(this);
if (_hvs.isExpanded(parent)) {
// remove the row of the child
_rows.remove(removedChild);
fireRowRemoved(removedChild);
// remove the rows of all visible children
List<ITableNode> toRemove = new ArrayList<ITableNode>();
enumerateChildren(removedChild, toRemove);
for (ITableNode tableNode : toRemove) {
_rows.remove(tableNode);
fireRowRemoved(tableNode);
}
}
}
/**
* {@inheritDoc }Handle expansion of a node. This means adding all rows that become visible when expanding.
*/
public void nodeExpanded(ITableNode node) {
nodeExpanded2(node);
}
/**
* Handle expansion of a node by traversing all children of the node to check whether they are visible.
*
* @param node node expanded
* @return count of nodes that became visible ()= number of insertedlines)
*/
private int nodeExpanded2(ITableNode node) {
int idx = getIdxForNode(node);
int count = node.getChildren().size();
int inserted = 0;
for (int i = 0; i < count; i++) {
ITableNode n = node.getChildren().get(i);
int newIdx = idx + 1 + inserted;
_rows.add(newIdx, n);
inserted++;
fireRowAdded(newIdx, n);
registerPropChange(n);
if (_hvs.isExpanded(n) && n.getChildren().size() > 0) {
inserted += nodeExpanded2(n);
}
}
return inserted;
}
/**
* {@inheritDoc} Handle folding of a node. This means removing all rows that "disappear" with folding.
*/
public void nodeFolded(ITableNode node) {
int count = node.getChildren().size();
for (int i = 0; i < count; i++) {
ITableNode n = node.getChildren().get(i);
if (_hvs.isExpanded(n) && n.getChildren().size() > 0) {
nodeFolded(n);
}
int idx2 = getIdxForNode(n);
// maybe the node is already hidden ...
if (idx2 != -1) {
_rows.remove(idx2);
}
fireRowRemoved(n);
deRegisterPropChange(n);
}
}
/**
* {@inheritDoc}
*/
public int getColumnCount() {
return _cols.size();
}
/**
* {@inheritDoc}
*/
public IColumn getColumn(int idx) {
return _cols.get(idx);
}
/**
* Add a column to the list of columns.
*
* @param column column to add
*/
public void addColumn(IColumn column) {
_cols.add(column);
fireColumnAdded(_cols.size() - 1, column);
}
/**
* {@inheritDoc}
*/
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getSource() instanceof IRow) {
fireRowChanged((IRow) evt.getSource());
}
}
}
| 11,846 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ITableNode.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/ITableNode.java | /*
* File: ITableNode.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import java.util.List;
/**
* Interface describing a table row in a hierarchy of rows.
*
* @author Peter Kliem
* @version $Id: ITableNode.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface ITableNode extends IRow {
/**
* Retriev all children of the node.
*
* @return chrildren of the node
*/
List<ITableNode> getChildren();
/**
* Retrieve the level in the tree.
*
* @return level in the tree.
*/
int getLevel();
/**
* Tell the node it's level.
*
* @TODO remove
* @param level level of the node
*/
void setLevel(int level);
/**
* Add a node as a child.
*
* @param node child to be added.
*/
void addNode(ITableNode node);
/**
* Remove a child node.
*
* @param node node to remove.
*/
void remNode(ITableNode node);
/**
* Add a listener to listen for node changes.
*
* @param tnl listener to add
*/
void addTableNodeListener(ITableNodeListener tnl);
/**
* Remove a listener registered for node changes.
*
* @param tnl listener to remove
*/
void removeTableNodeListener(ITableNodeListener tnl);
}
| 1,748 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AbstractTableNode.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/AbstractTableNode.java | /*
* File: AbstractTableNode.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import de.jaret.util.misc.PropertyObservableBase;
/**
* Abstract base implementation of an ITableNode.
*
* @author Peter Kliem
* @version $Id: AbstractTableNode.java,v 1.1 2012-05-07 01:34:36 jason Exp $
*/
public abstract class AbstractTableNode extends PropertyObservableBase implements ITableNode {
/** listeners. */
protected List<ITableNodeListener> _listeners;
/** list of the chikdren of the node. */
protected List<ITableNode> _children = new ArrayList<ITableNode>();
/** level in the hierarchy. */
protected int _level;
// TODO remove
/**
* {@inheritDoc}
*/
public List<ITableNode> getChildren() {
return _children;
}
/**
* {@inheritDoc}
*/
public int getLevel() {
return _level;
}
/**
* {@inheritDoc}
*/
public void setLevel(int level) {
_level = level;
if (_children != null) {
for (ITableNode node : _children) {
node.setLevel(level+1);
}
}
}
/**
* Add a node.
*
* @param node node to add
*/
public void addNode(ITableNode node) {
node.setLevel(_level + 1);
_children.add(node);
fireNodeAdded(node);
}
/**
* Remove a node.
*
* @param node node to remove
*/
public void remNode(ITableNode node) {
if (_children.contains(node)) {
_children.remove(node);
fireNodeRemoved(node);
}
}
/**
* {@inheritDoc}
*/
public synchronized void addTableNodeListener(ITableNodeListener tnl) {
if (_listeners == null) {
_listeners = new Vector<ITableNodeListener>();
}
_listeners.add(tnl);
}
/**
* {@inheritDoc}
*/
public void removeTableNodeListener(ITableNodeListener tnl) {
if (_listeners != null) {
_listeners.remove(tnl);
}
}
/**
* Inform listeners about a newly added node.
*
* @param node the added node
*/
protected void fireNodeAdded(ITableNode node) {
if (_listeners != null) {
for (ITableNodeListener listener : _listeners) {
listener.nodeAdded(this, node);
}
}
}
/**
* Inform listeners about the removal of a node.
*
* @param node removed node
*/
protected void fireNodeRemoved(ITableNode node) {
if (_listeners != null) {
for (ITableNodeListener listener : _listeners) {
listener.nodeRemoved(this, node);
}
}
}
}
| 3,266 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AbstractJaretTableModel.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/AbstractJaretTableModel.java | /*
* File: AbstractJaretTableModel.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import java.util.List;
import java.util.Vector;
/**
* Abstract base implementation of a JaretTableModel.
*
* @author Peter Kliem
* @version $Id: AbstractJaretTableModel.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public abstract class AbstractJaretTableModel implements IJaretTableModel {
/** registered listeners. */
protected List<IJaretTableModelListener> _listeners;
/**
* {@inheritDoc} Simple default implementation.
*/
public IColumn getColumn(String id) {
for (int i = 0; i < getColumnCount(); i++) {
if (getColumn(i).getId() != null && getColumn(i).getId().equals(id)) {
return getColumn(i);
}
}
return null;
}
/**
* {@inheritDoc}
*/
public void setValue(IRow row, IColumn column, Object value) {
column.setValue(row, value);
}
/**
* {@inheritDoc} Delegates to the column.
*/
public boolean isEditable(IRow row, IColumn column) {
return column.isEditable(row);
}
/**
* {@inheritDoc}
*/
public synchronized void addJaretTableModelListener(IJaretTableModelListener jtml) {
if (_listeners == null) {
_listeners = new Vector<IJaretTableModelListener>();
}
_listeners.add(jtml);
}
/**
* {@inheritDoc}
*/
public synchronized void removeJaretTableModelListener(IJaretTableModelListener jtml) {
if (_listeners != null) {
_listeners.remove(jtml);
}
}
/**
* Inform listeners about an added row.
*
* @param idx index of the row
* @param row the row
*/
protected void fireRowAdded(int idx, IRow row) {
if (_listeners != null) {
for (int i = 0; i < _listeners.size(); i++) {
IJaretTableModelListener listener = _listeners.get(i);
listener.rowAdded(idx, row);
}
}
}
/**
* Inform listeners about a removed row.
*
* @param row the removed row
*/
protected void fireRowRemoved(IRow row) {
if (_listeners != null) {
for (int i = 0; i < _listeners.size(); i++) {
IJaretTableModelListener listener = _listeners.get(i);
listener.rowRemoved(row);
}
}
}
/**
* Inform listeners abou a changed row.
*
* @param row the changed row
*/
protected void fireRowChanged(IRow row) {
if (_listeners != null) {
for (int i = 0; i < _listeners.size(); i++) {
IJaretTableModelListener listener = _listeners.get(i);
listener.rowChanged(row);
}
}
}
/**
* Inform listeners about an added column.
*
* @param idx index
* @param column column
*/
protected void fireColumnAdded(int idx, IColumn column) {
if (_listeners != null) {
for (IJaretTableModelListener listener : _listeners) {
listener.columnAdded(idx, column);
}
}
}
/**
* Inform listeners about a removed column.
*
* @param column the now missing column
*/
protected void fireColumnRemoved(IColumn column) {
if (_listeners != null) {
for (IJaretTableModelListener listener : _listeners) {
listener.columnRemoved(column);
}
}
}
/**
* Inform listeners about a changed column.
*
* @param column changed col
*/
protected void fireColumnChanged(IColumn column) {
if (_listeners != null) {
for (IJaretTableModelListener listener : _listeners) {
listener.columnChanged(column);
}
}
}
/**
* Inform listeners about a changed cell.
*
* @param row row of the cell
* @param column olumn of the cell
*/
protected void fireCellChanged(IRow row, IColumn column) {
if (_listeners != null) {
for (IJaretTableModelListener listener : _listeners) {
listener.cellChanged(row, column);
}
}
}
/**
* Inform listeners about a general change of the model data.
*
*/
protected void fireTableDataChanged() {
if (_listeners != null) {
for (IJaretTableModelListener listener : _listeners) {
listener.tableDataChanged();
}
}
}
}
| 5,120 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultHierarchicalTableViewState.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/DefaultHierarchicalTableViewState.java | /*
* File: DefaultHierarchicalTableViewState.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
/**
* Default implementation of a hierarchical view state.
*
* @author Peter Kliem
* @version $Id: DefaultHierarchicalTableViewState.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class DefaultHierarchicalTableViewState extends DefaultTableViewState implements IHierarchicalTableViewState {
/** listener list. */
protected List<IHierarchicalTableViewStateListener> _listeners;
/** map holding the node expanded states. */
protected Map<ITableNode, Boolean> _expandedStatesMap = new HashMap<ITableNode, Boolean>();
/**
* {@inheritDoc}
*/
public boolean isExpanded(ITableNode node) {
Boolean state = _expandedStatesMap.get(node);
return !(state == null || !state.booleanValue());
}
/**
* {@inheritDoc}
*/
public void setExpanded(ITableNode node, boolean expanded) {
boolean state = isExpanded(node);
if (state != expanded) {
_expandedStatesMap.put(node, expanded);
if (expanded) {
fireNodeExpanded(node);
} else {
fireNodeFolded(node);
}
}
}
/**
* {@inheritDoc}
*/
public void setExpandedRecursive(ITableNode node, boolean expanded) {
if (node.getChildren().size() > 0) {
setExpanded(node, expanded);
for (ITableNode child : node.getChildren()) {
setExpandedRecursive(child, expanded);
}
}
}
/**
* {@inheritDoc}
*/
public synchronized void addHierarchicalViewstateListener(IHierarchicalTableViewStateListener htvsListener) {
if (_listeners == null) {
_listeners = new Vector<IHierarchicalTableViewStateListener>();
}
_listeners.add(htvsListener);
}
/**
* {@inheritDoc}
*/
public void remHierarchicalViewStateListener(IHierarchicalTableViewStateListener htvsListener) {
if (_listeners != null) {
_listeners.remove(htvsListener);
}
}
/**
* Inform listeners about a node expansion.
*
* @param node expanded node
*/
protected void fireNodeExpanded(ITableNode node) {
if (_listeners != null) {
for (IHierarchicalTableViewStateListener listener : _listeners) {
listener.nodeExpanded(node);
}
}
}
/**
* Infor listeners about a folded node.
*
* @param node node that has been folded
*/
protected void fireNodeFolded(ITableNode node) {
if (_listeners != null) {
for (IHierarchicalTableViewStateListener listener : _listeners) {
listener.nodeFolded(node);
}
}
}
}
| 3,407 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IJaretTableModelListener.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/IJaretTableModelListener.java | /*
* File: IJaretTableModelListener.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
/**
* Listener for listening to table model changes on a jaret table model.
*
* @author Peter Kliem
* @version $Id: IJaretTableModelListener.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface IJaretTableModelListener {
/**
* Called if there has been a change in the row data.
*
* @param row row that changed.
*/
void rowChanged(IRow row);
/**
* Called when a row has been removed from the model.
*
* @param row removed row.
*/
void rowRemoved(IRow row);
/**
* Called when a row has been added to the model.
*
* @param idx index of the added row.
* @param row row that has been added.
*/
void rowAdded(int idx, IRow row);
/**
* Called when a column has been added to the table model.
*
* @param idx index of the new column.
* @param column the new column.
*/
void columnAdded(int idx, IColumn column);
/**
* Called when a column has been removed from the model.
*
* @param column the removed row.
*/
void columnRemoved(IColumn column);
/**
* Called when a column changed.
*
* @param column changed column.
*/
void columnChanged(IColumn column);
/**
* The value of the specified cell changed.
*
* @param row of the cell
* @param column of the cell
*/
void cellChanged(IRow row, IColumn column);
/**
* All table data has been invalidated.
*
*/
void tableDataChanged();
}
| 2,077 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultTableViewState.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/DefaultTableViewState.java | /*
* File: DefaultTableViewState.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import de.jaret.util.ui.table.renderer.DefaultCellStyleProvider;
import de.jaret.util.ui.table.renderer.ICellStyle;
import de.jaret.util.ui.table.renderer.ICellStyleListener;
import de.jaret.util.ui.table.renderer.ICellStyleProvider;
/**
* Default implementation of a TableViewState for the jaret table.
*
* @author Peter Kliem
* @version $Id: DefaultTableViewState.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class DefaultTableViewState implements ITableViewState, ICellStyleListener {
/** map of row configurations. */
protected Map<IRow, RowConfiguration> _rowConfiguations = new HashMap<IRow, RowConfiguration>();
/** map of column configurations. */
protected Map<IColumn, ColumnConfiguration> _colConfigurations = new HashMap<IColumn, ColumnConfiguration>();
/** listener list for the tableviewstate listeners. */
protected List<ITableViewStateListener> _listeners;
protected int _minimalRowHeight = 10;
protected int _maximalRowHeight = -1; // undefined
protected int _defaultRowHeight = 22;
protected int _minimalColumnWidth = 10;
protected int _maximalColumnWidth = -1; // undefined
protected int _defaultColumnWidth = 100;
/** the sorted list (for display) of columns. */
protected List<IColumn> _sortedColumns;
/** the cell style provider used. */
protected ICellStyleProvider _cellStyleProvider;
/** The colummn resize mode used by the table. */
protected ColumnResizeMode _columnResizeMode;
/** Default row height mode for new rows. */
protected RowHeightMode _defaultRowHeightMode = RowHeightMode.OPTANDVAR;
/**
* Constructor.
*
*/
public DefaultTableViewState() {
_cellStyleProvider = new DefaultCellStyleProvider();
_cellStyleProvider.addCellStyleListener(this);
}
/**
* {@inheritDoc}
*/
public int getRowHeight(IRow row) {
RowConfiguration configuration = getRowConfiguration(row);
return configuration.rowHeight;
}
/**
* {@inheritDoc}
*/
public void setRowHeight(IRow row, int height) {
RowConfiguration configuration = getRowConfiguration(row);
if (configuration.rowHeight != height) {
configuration.rowHeight = height;
fireRowHeightChanged(row, height);
}
}
/**
* {@inheritDoc}
*/
public void setRowHeight(int height) {
_defaultRowHeight = height;
// set for all rows known
for (RowConfiguration rconfig : _rowConfiguations.values()) {
rconfig.rowHeight = height;
}
// TODO may be optimized
for (IRow row : _rowConfiguations.keySet()) {
fireRowHeightChanged(row, height);
}
}
/**
* {@inheritDoc}
*/
public RowHeightMode getRowHeigthMode(IRow row) {
RowConfiguration configuration = getRowConfiguration(row);
return configuration.heightMode;
}
/**
* {@inheritDoc}
*/
public void setRowHeightMode(IRow row, RowHeightMode mode) {
RowConfiguration configuration = getRowConfiguration(row);
if (configuration.heightMode != mode) {
configuration.heightMode = mode;
fireRowHeightModeChanged(row, mode);
}
}
/**
* {@inheritDoc}
*/
public void setRowHeightMode(RowHeightMode mode) {
_defaultRowHeightMode = mode;
// set for all rows known
for (RowConfiguration rconfig : _rowConfiguations.values()) {
rconfig.heightMode = mode;
}
for (IRow row : _rowConfiguations.keySet()) {
fireRowHeightModeChanged(row, mode);
}
}
/**
* {@inheritDoc}
*/
public RowHeightMode getRowHeightMode() {
return _defaultRowHeightMode;
}
private RowConfiguration getRowConfiguration(IRow row) {
RowConfiguration configuration = _rowConfiguations.get(row);
if (configuration == null) {
configuration = getDefaultRowConfiguration();
_rowConfiguations.put(row, configuration);
}
return configuration;
}
private RowConfiguration getDefaultRowConfiguration() {
RowConfiguration configuration = new RowConfiguration();
configuration.rowHeight = _defaultRowHeight;
configuration.heightMode = _defaultRowHeightMode;
return configuration;
}
private ColumnConfiguration getColumnConfiguration(IColumn col) {
ColumnConfiguration configuration = _colConfigurations.get(col);
if (configuration == null) {
configuration = getDefaultColumnConfiguration(col.getId());
_colConfigurations.put(col, configuration);
}
return configuration;
}
private ColumnConfiguration getColumnConfiguration(String columnId) {
for (ColumnConfiguration colConf : _colConfigurations.values()) {
if (colConf.id.equals(columnId)) {
return colConf;
}
}
return getDefaultColumnConfiguration(columnId);
}
private ColumnConfiguration getDefaultColumnConfiguration(String colId) {
ColumnConfiguration configuration = new ColumnConfiguration();
configuration.id = colId;
configuration.resizable = true;
configuration.columnWidth = _defaultColumnWidth;
return configuration;
}
/**
* {@inheritDoc}
*/
public int getColumnWidth(IColumn column) {
ColumnConfiguration configuration = getColumnConfiguration(column);
return (int) Math.round(configuration.columnWidth);
}
/**
* {@inheritDoc}
*/
public void setColumnWidth(IColumn column, int width) {
ColumnConfiguration configuration = getColumnConfiguration(column);
if (configuration.columnWidth != width) {
int oldVal = (int) Math.round(configuration.columnWidth);
if (_columnResizeMode == ColumnResizeMode.SUBSEQUENT) {
IColumn sCol = getSubsequentColumn(column);
if (sCol == null) {
// no subsequent col -> do it
configuration.columnWidth = width;
fireColumnWidthChanged(column, width);
} else {
int max = getColumnWidth(sCol) - _minimalColumnWidth;
int delta = width - oldVal;
delta = delta > max ? max : delta;
configuration.columnWidth += delta;
ColumnConfiguration sConfiguration = getColumnConfiguration(sCol);
sConfiguration.columnWidth -= delta;
fireColumnWidthsChanged();
}
} else if (_columnResizeMode == ColumnResizeMode.ALLSUBSEQUENT || _columnResizeMode == ColumnResizeMode.ALL) {
List<IColumn> sCols = null;
if (_columnResizeMode == ColumnResizeMode.ALLSUBSEQUENT) {
sCols = getSubsequentColumns(column);
} else {
sCols = getAllVisibleCols(column);
}
if (sCols.size() == 0) {
// no subsequent cols -> do it
configuration.columnWidth = width;
fireColumnWidthChanged(column, width);
} else {
int max = 0;
for (IColumn c : sCols) {
max += getColumnWidth(c) - _minimalColumnWidth;
}
int delta = width - oldVal;
delta = delta > max ? max : delta;
configuration.columnWidth += delta;
double distDelta = (double) delta / (double) sCols.size();
for (IColumn c : sCols) {
ColumnConfiguration sConfiguration = getColumnConfiguration(c);
sConfiguration.columnWidth -= distDelta;
}
fireColumnWidthsChanged();
}
} else { // mode NONE
configuration.columnWidth = width;
fireColumnWidthChanged(column, width);
}
}
}
/**
* Creates a list of al visible cols without the given column.
*
* @param without the column to omit
* @return list of visible columns without a given one
*/
private List<IColumn> getAllVisibleCols(IColumn without) {
List<IColumn> result = new ArrayList<IColumn>();
int idx = _sortedColumns.indexOf(without);
for (int i = 0; i < _sortedColumns.size(); i++) {
if (idx != i && getColumnVisible(_sortedColumns.get(i))) {
result.add(_sortedColumns.get(i));
}
}
return result;
}
/**
* Retrieve the next column after the given one.
*
* @param column reference column
* @return next column in the sorted columns or <code>null</code> if the given column is the last
*/
private IColumn getSubsequentColumn(IColumn column) {
List<IColumn> l = getSubsequentColumns(column);
if (l.size() > 0) {
return l.get(0);
}
return null;
}
/**
* Retrieve the list of columns behind the given column.
*
* @param column reference column
* @return list of columns behind the given column in the sorted columns
*/
private List<IColumn> getSubsequentColumns(IColumn column) {
List<IColumn> result = new ArrayList<IColumn>();
int idx = _sortedColumns.indexOf(column);
if (idx == -1) {
return result;
}
for (int i = idx + 1; i < _sortedColumns.size(); i++) {
if (getColumnVisible(_sortedColumns.get(i))) {
result.add(_sortedColumns.get(i));
}
}
return result;
}
/**
* {@inheritDoc}
*/
public boolean getColumnVisible(IColumn column) {
ColumnConfiguration configuration = getColumnConfiguration(column);
return configuration.visible;
}
/**
* {@inheritDoc}
*/
public void setColumnVisible(IColumn column, boolean visible) {
ColumnConfiguration configuration = getColumnConfiguration(column);
if (configuration.visible != visible) {
configuration.visible = visible;
fireColumnVisibilityChanged(column, visible);
}
}
/**
* {@inheritDoc}
*/
public void setColumnVisible(String columnId, boolean visible) {
ColumnConfiguration configuration = getColumnConfiguration(columnId);
if (configuration.visible != visible) {
configuration.visible = visible;
// TODO fireColumnVisibilityChanged(column, visible);
}
}
/**
* {@inheritDoc}
*/
public List<IColumn> getSortedColumns() {
if (_sortedColumns == null) {
_sortedColumns = new ArrayList<IColumn>();
}
return _sortedColumns;
}
/**
* {@inheritDoc}
*/
public void setSortedColumns(List<IColumn> sortedColumns) {
_sortedColumns = sortedColumns;
fireColumnOrderChanged();
}
/**
* {@inheritDoc}
*/
public int getColumnSortingPosition(IColumn column) {
ColumnConfiguration configuration = getColumnConfiguration(column);
return configuration.sortingPosition;
}
/**
* {@inheritDoc}
*/
public boolean getColumnSortingDirection(IColumn column) {
ColumnConfiguration configuration = getColumnConfiguration(column);
return configuration.sortingDirection;
}
/**
* {@inheritDoc}
*/
public void setSorting(IColumn column) {
ColumnConfiguration conf = getColumnConfiguration(column);
if (conf.sortingPosition == 0) {
addShiftSorting();
conf.sortingPosition = 1;
} else {
if (conf.sortingDirection) {
conf.sortingDirection = false;
} else {
conf.sortingDirection = true;
remSorting(conf.sortingPosition);
conf.sortingPosition = 0;
}
}
fireSortingChanged();
}
private void addShiftSorting() {
for (ColumnConfiguration cconf : _colConfigurations.values()) {
if (cconf.sortingPosition > 0) {
cconf.sortingPosition++;
}
}
}
private void remSorting(int pos) {
for (ColumnConfiguration cconf : _colConfigurations.values()) {
if (cconf.sortingPosition > pos) {
cconf.sortingPosition--;
}
}
}
/**
* Simple helper class holding the configuration for a row.
*
* @author Peter Kliem
* @version $Id: DefaultTableViewState.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class RowConfiguration {
/** rowheightmode. */
public RowHeightMode heightMode;
/** actual row height. */
public int rowHeight;
}
/**
* Simple helper class holding the onfiguration information for a column.
*
* @author Peter Kliem
* @version $Id: DefaultTableViewState.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class ColumnConfiguration {
/** width of the column. */
public double columnWidth;
/** resize allowance. */
public boolean resizable = true;
/** true when visible. */
public boolean visible = true;
/** id of the column. */
public String id;
/** position in sorting. */
public int sortingPosition;
/** sorting direction if sorting. */
public boolean sortingDirection = true; // ascending as default
}
/**
* {@inheritDoc}
*/
public synchronized void addTableViewStateListener(ITableViewStateListener tvsl) {
if (_listeners == null) {
_listeners = new Vector<ITableViewStateListener>();
}
_listeners.add(tvsl);
}
/**
* {@inheritDoc}
*/
public void removeTableViewStateListener(ITableViewStateListener tvsl) {
if (_listeners != null) {
_listeners.remove(tvsl);
}
}
/**
* Inform listeners about a change in the height of a row.
*
* @param row row
* @param newHeight new row height
*/
protected void fireRowHeightChanged(IRow row, int newHeight) {
if (_listeners != null) {
for (ITableViewStateListener listener : _listeners) {
listener.rowHeightChanged(row, newHeight);
}
}
}
protected void fireRowHeightModeChanged(IRow row, RowHeightMode newMode) {
if (_listeners != null) {
for (ITableViewStateListener listener : _listeners) {
listener.rowHeightModeChanged(row, newMode);
}
}
}
protected void fireColumnWidthChanged(IColumn column, int newWidth) {
if (_listeners != null) {
for (ITableViewStateListener listener : _listeners) {
listener.columnWidthChanged(column, newWidth);
}
}
}
protected void fireColumnWidthsChanged() {
if (_listeners != null) {
for (ITableViewStateListener listener : _listeners) {
listener.columnWidthsChanged();
}
}
}
protected void fireColumnVisibilityChanged(IColumn column, boolean visible) {
if (_listeners != null) {
for (ITableViewStateListener listener : _listeners) {
listener.columnVisibilityChanged(column, visible);
}
}
}
protected void fireSortingChanged() {
if (_listeners != null) {
for (ITableViewStateListener listener : _listeners) {
listener.sortingChanged();
}
}
}
protected void fireColumnOrderChanged() {
if (_listeners != null) {
for (ITableViewStateListener listener : _listeners) {
listener.columnOrderChanged();
}
}
}
protected void fireCellStyleChanged(IRow row, IColumn column, ICellStyle cellStyle) {
if (_listeners != null) {
for (ITableViewStateListener listener : _listeners) {
listener.cellStyleChanged(row, column, cellStyle);
}
}
}
/**
* {@inheritDoc}
*/
public int getMinimalRowHeight() {
return _minimalRowHeight;
}
/**
* {@inheritDoc}
*/
public void setMinimalRowHeight(int minimalRowHeight) {
_minimalRowHeight = minimalRowHeight;
}
/**
* {@inheritDoc}
*/
public int getMinimalColWidth() {
return _minimalColumnWidth;
}
/**
* {@inheritDoc}
*/
public void setMinimalColWidth(int minimalColumnWidth) {
_minimalColumnWidth = minimalColumnWidth;
}
/**
* {@inheritDoc}
*/
public ICellStyleProvider getCellStyleProvider() {
return _cellStyleProvider;
}
/**
* {@inheritDoc}
*/
public void setCellStyleProvider(ICellStyleProvider cellStyleProvider) {
if (_cellStyleProvider != null) {
_cellStyleProvider.remCellStyleListener(this);
}
_cellStyleProvider = cellStyleProvider;
_cellStyleProvider.addCellStyleListener(this);
}
/**
* {@inheritDoc}
*/
public ICellStyle getCellStyle(IRow row, IColumn column) {
return _cellStyleProvider.getCellStyle(row, column);
}
/**
* {@inheritDoc} inform listeners abou the received cell style change.
*/
public void cellStyleChanged(IRow row, IColumn column, ICellStyle style) {
fireCellStyleChanged(row, column, style);
}
/**
* {@inheritDoc}
*/
public boolean columnResizingAllowed(IColumn column) {
ColumnConfiguration conf = getColumnConfiguration(column);
return conf.resizable;
}
/**
* {@inheritDoc}
*/
public void setColumnResizingAllowed(IColumn column, boolean resizingAllowed) {
ColumnConfiguration conf = getColumnConfiguration(column);
conf.resizable = resizingAllowed;
}
/**
* @return Returns the columnResizeMode.
*/
public ColumnResizeMode getColumnResizeMode() {
return _columnResizeMode;
}
/**
* @param columnResizeMode The columnResizeMode to set.
*/
public void setColumnResizeMode(ColumnResizeMode columnResizeMode) {
_columnResizeMode = columnResizeMode;
}
}
| 19,943 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IJaretTableSelectionModelListener.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/IJaretTableSelectionModelListener.java | /*
* File: IJaretTableSelectionModelListener.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
/**
* Listener for listening on selection changes on a jaret table selection.
*
* @author Peter Kliem
* @version $Id: IJaretTableSelectionModelListener.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public interface IJaretTableSelectionModelListener {
/**
* Called whenever a row has been added to a selection.
*
* @param row row added.
*/
void rowSelectionAdded(IRow row);
/**
* Called whenever a row has been removed from the selection.
*
* @param row row removed.
*/
void rowSelectionRemoved(IRow row);
/**
* Called whenever a cell has been added to a selection.
*
* @param cell cell added
*/
void cellSelectionAdded(IJaretTableCell cell);
/**
* Called whenever a cell has been removed from the selection.
*
* @param cell cell removed
*/
void cellSelectionRemoved(IJaretTableCell cell);
/**
* Called whenever a column has been added to a selection.
*
* @param column column added
*/
void columnSelectionAdded(IColumn column);
/**
* Called whenever a column has been removed from the selection.
*
* @param column column removed
*/
void columnSelectionRemoved(IColumn column);
}
| 1,799 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IndexColumn.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/IndexColumn.java | /*
* File: IndexColumn.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import de.jaret.util.ui.table.JaretTable;
/**
* A simple column displaying the row index.
*
* @author Peter Kliem
* @version $Id: IndexColumn.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class IndexColumn extends AbstractColumn implements IColumn {
/** id of the index col. */
public static final String ID = "indexColumnId";
/** table the column is for. */
protected JaretTable _table;
/** haeder label for the column. */
protected String _headerLabel;
/**
* Construct an index column.
*
* @param table table the indexcolumn is used for
* @param headerLabel hedare label to use
*/
public IndexColumn(JaretTable table, String headerLabel) {
_table = table;
_headerLabel = headerLabel;
}
/**
* {@inheritDoc}
*/
public String getId() {
return ID;
}
/**
* {@inheritDoc}
*/
public String getHeaderLabel() {
return _headerLabel;
}
/**
* {@inheritDoc}
*/
public Object getValue(IRow row) {
return new Integer(_table.getInternalRowIndex(row));
}
/**
* {@inheritDoc}
*/
public void setValue(IRow row, Object value) {
}
/**
* {@inheritDoc}
*/
public int compare(IRow r1, IRow r2) {
return ((Integer) getValue(r1)).compareTo((Integer) getValue(r2));
}
/**
* {@inheritDoc}
*/
public boolean supportsSorting() {
return true;
}
/**
* {@inheritDoc}
*/
public Class<?> getContentClass() {
return Integer.class;
}
/**
* {@inheritDoc} Never editable.
*/
public boolean isEditable() {
return false;
}
/**
* {@inheritDoc} Never editable.
*/
public boolean isEditable(IRow row) {
return false;
}
}
| 2,404 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
PropListeningTableModel.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/PropListeningTableModel.java | /*
* File: PropListeningTableModel.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import de.jaret.util.misc.PropertyObservable;
/**
* Extension of the DefaultJaretTableModel registering itself as a property change listener on each row.
*
* @author Peter Kliem
* @version $Id: PropListeningTableModel.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class PropListeningTableModel extends DefaultJaretTableModel implements PropertyChangeListener {
/**
* {@inheritDoc}
*/
public void addRow(IRow row) {
super.addRow(row);
if (row instanceof PropertyObservable) {
((PropertyObservable) row).addPropertyChangeListener(this);
}
}
/**
* {@inheritDoc}
*/
public void remRow(IRow row) {
super.remRow(row);
if (row instanceof PropertyObservable) {
((PropertyObservable) row).removePropertyChangeListener(this);
}
}
/**
* {@inheritDoc} Evry change will trigger row changed.
*/
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getSource() instanceof IRow) {
fireRowChanged((IRow) evt.getSource());
}
}
}
| 1,707 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
JaretTableCellImpl.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/base_plugins/de.jaret.util.ui.table/src/de/jaret/util/ui/table/model/JaretTableCellImpl.java | /*
* File: JaretTableCellImpl.java
* Copyright (c) 2004-2007 Peter Kliem ([email protected])
* A commercial license is available, see http://www.jaret.de.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
package de.jaret.util.ui.table.model;
/**
* Implementation of the IJaretTableCell.
*
* @author Peter Kliem
* @version $Id: JaretTableCellImpl.java,v 1.1 2012-05-07 01:34:37 jason Exp $
*/
public class JaretTableCellImpl implements IJaretTableCell {
/** the row. */
protected IRow _row;
/** the column. */
protected IColumn _column;
/**
* Construct a table cell instance.
*
* @param row the row
* @param column the column
*/
public JaretTableCellImpl(IRow row, IColumn column) {
_column = column;
_row = row;
}
/**
* @return Returns the column.
*/
public IColumn getColumn() {
return _column;
}
/**
* @return Returns the row.
*/
public IRow getRow() {
return _row;
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (o == null || !(o instanceof IJaretTableCell)) {
return false;
}
IJaretTableCell cell = (IJaretTableCell) o;
return _row.equals(cell.getRow()) && _column.equals(cell.getColumn());
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return _row.hashCode() * _column.hashCode();
}
}
| 1,759 | 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.