not sure about vsync, only happens on one computer so I'll check more.
But in regards to tables, trying to start fresh using this as an example:
http://hg.l33tlabs.org/twlexamples/file ... alog1.javaI'm trying to add it to a DialogLayout, but comes out funny if I set nothing or try setSize, setMinSize, @override layout, etc, etc... just looks odd:
http://i.imgur.com/pxnUP.pngIt seems that Table has different behavior than other widgets in regards to sizing?
Code:
public class DialogAdvancedSettingsTest extends DialogLayout {
private ScrollPane scrollPane;
public DialogAdvancedSettingsTest() {
setTheme("AdvancedSettings");
final ListModel<String> cbm = new SimpleChangableListModel<String>("Hallo", "Welt", "Test");
final ComboBoxValue cbv = new ComboBoxValue(0, cbm);
TableModel m = new AbstractTableModel() {
public int getNumRows() {
return 20;
}
public int getNumColumns() {
return 3;
}
public String getColumnHeaderText(int column) {
return "Column " + column;
}
public Object getCell(int row, int column) {
if (row == 7 && column == 1) {
// This cell will contain a ComboBoxValue - via registerCellRenderer
// below this will cause a comobox to appear
return cbv;
}
if (row == 6 && column == 1) {
return "Selected: " + cbv.getValue();
}
return "Row " + row + (((row * getNumColumns() + column) % 17 == 0) ? "\n" : "") + " Column " + column;
}
@Override
public Object getTooltipContent(int row, int column) {
return "X:" + (column + 1) + " Y:" + (row + 1);
}
};
Table t = new Table(m);
// register the ComboBoxValue class (see below) and it's cell widget creator
// this will change the behavior of cells when they contain a data valzue of
// the type "ComboBoxValue"
t.registerCellRenderer(ComboBoxValue.class, new ComboBoxCellWidgetCreator());
t.setTheme("table");
t.setVaribleRowHeight(true);
t.setDefaultSelectionManager();
add(t);
}
public void centerScrollPane() {
scrollPane.updateScrollbarSizes();
scrollPane.setScrollPositionX(scrollPane.getMaxScrollPosX() / 2);
scrollPane.setScrollPositionY(scrollPane.getMaxScrollPosY() / 2);
}
/**
* This is a very simple model class which will store the currently selected entry of the combobox and the model for
* the combobox.
*
* It is also the "key" type which will cause the cell to become a ComboBox
*/
public static class ComboBoxValue extends SimpleIntegerModel {
private final ListModel<String> model;
public ComboBoxValue(int value, ListModel<String> model) {
super(0, model.getNumEntries() - 1, value);
this.model = model;
}
public ListModel<String> getModel() {
return model;
}
}
/**
* A CellWidgetCreator instance is used to create and position the ComboBox widget inside the table cell. This class
* is also responsible to connect all listeners so that updates to/from the combobox can happen.
*
* Only a single ComboBoxCellWidgetCreator will be created per table. But it can manage several widgets/cells.
*
* As this is a simple example only the listener ComboBox -> ComboBoxValue is implemeted.
*/
private static class ComboBoxCellWidgetCreator implements CellWidgetCreator {
private int comboBoxHeight;
private ComboBoxValue data;
public void applyTheme(ThemeInfo themeInfo) {
comboBoxHeight = themeInfo.getParameter("comboBoxHeight", 0);
}
public String getTheme() {
return "ComboBoxCellRenderer";
}
/**
* Update or create the ComboBox widget.
*
* @param existingWidget
* null on first call per cell or the previous widget when an update has been send to that cell.
* @return the widget to use for this cell
*/
public Widget updateWidget(Widget existingWidget) {
MyComboBox cb = (MyComboBox) existingWidget;
if (cb == null) {
cb = new MyComboBox();
}
// in this example there should be no update to cells
// but the code pattern here can also be used when updates are
// generated. Care should be taken that the above type cast
// does not fail.
cb.setData(data);
return cb;
}
public void positionWidget(Widget widget, int x, int y, int w, int h) {
// this method will size and position the ComboBox
// If the widget should be centered (like a check box) then this
// would be done here
widget.setPosition(x, y);
widget.setSize(w, h);
}
public void setCellData(int row, int column, Object data) {
// we have to remember the cell data for the next call of updateWidget
this.data = (ComboBoxValue) data;
}
public Widget getCellRenderWidget(int x, int y, int width, int height, boolean isSelected) {
// this cell does not render anything itself
return null;
}
public int getColumnSpan() {
// no column spanning
return 1;
}
public int getPreferredHeight() {
// we have to inform the table about the required cell height before
// we can create the widget - so we need to get the required height
// from the theme - see applyTheme/getTheme
return comboBoxHeight;
}
/**
* We need a subclass of ComboBox to contain ("be" in this example) the listeners.
*/
private static class MyComboBox extends ComboBox<String> implements Runnable {
ComboBoxValue data;
public MyComboBox() {
setTheme("combobox"); // keep default theme name
addCallback(this);
}
void setData(ComboBoxValue data) {
this.data = null;
setModel(data.getModel());
setSelected(data.getValue());
this.data = data;
}
public void run() {
if (data != null) {
data.setValue(getSelected());
}
}
}
}
@Override
public void saveSettings() {
}
}