use of com.scriptographer.adm.layout.TableLayout in project scriptographer by scriptographer.
the class AdmComponentProxy method createItem.
protected Item createItem(Dialog dialog) {
// Item:
item = null;
ComponentType type = component.getType();
switch(type) {
case NUMBER:
{
Boolean steppers = component.getSteppers();
if (steppers != null && steppers) {
item = new SpinEdit(dialog) {
protected void onChange() {
AdmComponentProxy.this.onChange(true);
}
};
} else {
TextEditItem textItem = new TextEdit(dialog) {
protected void onChange() {
AdmComponentProxy.this.onChange(true);
}
};
textItem.setAllowMath(true);
textItem.setAllowUnits(true);
item = textItem;
}
}
break;
case STRING:
{
Boolean multiline = component.getMultiline();
TextOption[] options = multiline != null && multiline ? new TextOption[] { TextOption.MULTILINE } : null;
item = new TextEdit(dialog, options) {
protected void onChange() {
AdmComponentProxy.this.onChange(true);
}
};
}
break;
case TEXT:
{
item = new TextPane(dialog);
// Space a bit more to the top, to compensate the descender space.
item.setMargin(new Border(1, 0, 0, 0));
}
break;
case RULER:
{
// If the ruler has a label, add it to the left of it, using an
// ItemGroup and a TableLayout. The ItemGroup needs to be created
// before the frame, otherwise layouting issues arise...
// Ideally this should be resolved, but as ADM is on its way out,
// just work around it for now.
ItemGroup group;
String label = component.getLabel();
if (label != null && !label.equals("")) {
group = new ItemGroup(dialog);
TextPane labelItem = new TextPane(dialog);
labelItem.setText(label);
// Use 3 rows, so the center one with the ruler gets centered,
// then span the label across all three.
double[][] sizes = { new double[] { TableLayout.PREFERRED, TableLayout.FILL }, new double[] { TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL } };
group.setLayout(new TableLayout(sizes));
group.add(labelItem, "0, 0, 0, 2");
group.setMarginTop(2);
} else {
group = null;
}
Frame frame = new Frame(dialog);
frame.setStyle(FrameStyle.SUNKEN);
// Margin needs to be set before changing size...
// TODO: Fix this in UI package?
int top = label != null ? 2 : 4, bottom = 4;
frame.setMargin(top, 0, bottom, 0);
// Margin is included inside size, not added. This is different
// to how things works with CSS...
// TODO: Fix this in UI package?
frame.setHeight(2 + top + bottom);
// Now finish setting up the layout group and label
if (group != null) {
group.add(frame, "1, 1, full, center");
item = group;
} else {
item = frame;
}
}
break;
case SLIDER:
{
item = new Slider(dialog) {
protected void onChange() {
AdmComponentProxy.this.onChange(true);
}
};
}
break;
case BOOLEAN:
{
item = new CheckBox(dialog) {
protected void onClick() {
AdmComponentProxy.this.onChange(true);
}
};
}
break;
case LIST:
{
item = new PopupList(dialog, true) {
protected void onChange() {
selectedIndex = this.getSelectedEntry().getIndex();
AdmComponentProxy.this.onChange(true);
}
};
}
break;
case BUTTON:
{
item = new Button(dialog) {
protected void onClick() {
AdmComponentProxy.this.onClick();
}
};
}
break;
case COLOR:
{
item = new ColorButton(dialog) {
protected void onClick() {
AdmComponentProxy.this.onChange(true);
}
};
}
break;
case FONT:
{
item = new FontPopupList(dialog, new FontPopupListOption[] { FontPopupListOption.EDITABLE, FontPopupListOption.VERTICAL }) {
protected void onChange() {
AdmComponentProxy.this.onChange(true);
}
};
}
break;
case MENU_ENTRY:
case MENU_SEPARATOR:
{
PopupMenu menu = dialog.getPopupMenu();
if (menu != null) {
entry = new ListEntry(menu) {
protected void onSelect() {
AdmComponentProxy.this.onSelect();
}
};
if (type == ComponentType.MENU_SEPARATOR)
entry.setSeparator(true);
}
}
break;
}
initialize();
return item;
}
use of com.scriptographer.adm.layout.TableLayout in project scriptographer by scriptographer.
the class AdmPaletteProxy method createLayout.
protected static TableLayout createLayout(Dialog dialog, Component[] components, boolean hasLogo, int extraRows, int gap) {
// First collect all content in a LinkedHashMap, then create the layout
// at the end, and add the items to it. This allows flexibility
// regarding amount of rows, as needed by the ruler element that uses
// two rows when it has a title.
LinkedHashMap<String, com.scriptographer.adm.Component> content = new LinkedHashMap<String, com.scriptographer.adm.Component>();
int column = hasLogo ? 1 : 0, row = 0;
for (int i = 0; i < components.length; i++) {
Component item = components[i];
if (item != null) {
AdmComponentProxy proxy = new AdmComponentProxy(item);
row = proxy.addToContent(dialog, content, column, row);
}
}
if (hasLogo) {
ImagePane logo = new ImagePane(dialog);
logo.setImage(AdmUiFactory.getImage("logo.png"));
logo.setMargin(-4, 4, -4, -4);
// Logo uses all rows of components + filler row
content.put("0, 0, 0, " + row + ", left, top", logo);
row++;
}
double[] rows = new double[row + extraRows];
for (int i = 0; i < rows.length; i++) rows[i] = TableLayout.PREFERRED;
// Define the filler row, 2nd last
if (hasLogo)
rows[rows.length - extraRows - 1] = TableLayout.FILL;
else if (rows.length > 0)
rows[rows.length - 1] = TableLayout.FILL;
double[][] sizes = { hasLogo ? new double[] { TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL } : new double[] { TableLayout.PREFERRED, TableLayout.FILL }, rows };
TableLayout layout = new TableLayout(sizes, 0, gap);
dialog.setLayout(layout);
dialog.setContent(content);
return layout;
}
use of com.scriptographer.adm.layout.TableLayout in project scriptographer by scriptographer.
the class Component method setContent.
public void setContent(Map<String, ? extends Component> elements) {
// in the map:
if (this.getLayout() == null) {
boolean borderLayout = true;
for (String key : elements.keySet()) borderLayout = borderLayoutPattern.matcher(key).matches();
if (borderLayout) {
this.setLayout(new BorderLayout());
} else {
// TODO: Figure out amount of rows and columns by analyzing the keys.
// for now we don't do that...
this.setLayout(new TableLayout("preferred", "preferred"));
}
}
Content content = getContent();
content.removeAll();
content.addAll(elements);
}
use of com.scriptographer.adm.layout.TableLayout in project scriptographer by scriptographer.
the class LayoutConverter method convert.
public LayoutManager convert(ArgumentReader reader, Object from) {
if (reader.isArray()) {
String str = reader.readString();
if (str != null) {
// See if it's an available alignment for FlowLayout
if (HorizontalLayout.getAlignment(str) != null) {
// FlowLayout
return new HorizontalLayout(str, reader.readInteger(0), reader.readInteger(0));
} else {
// TableLayout
return new TableLayout(str, reader.readString(""), reader.readInteger(0), reader.readInteger(0));
}
} else {
reader.revert();
// Try if there's an array now:
Object[] array = reader.readObject(Object[].class);
if (array != null) {
// TableLayout
return new TableLayout(array, reader.readObject(Object[].class), reader.readInteger(0), reader.readInteger(0));
} else {
reader.revert();
// BorderLayout
return new BorderLayout(reader.readInteger(0), reader.readInteger(0));
}
}
} else if (reader.isMap()) {
if (reader.has("columns")) {
// TableLayout
String str = reader.readString("columns");
if (str != null) {
return new TableLayout(str, reader.readString("rows", ""), reader.readInteger("", 0), reader.readInteger(0));
} else {
Object[] array = reader.readObject("columns", Object[].class);
if (array != null) {
return new TableLayout(array, reader.readObject("rows", Object[].class), reader.readInteger("hgap", 0), reader.readInteger("vgap", 0));
} else {
throw new RuntimeException("Unsupported format for TableLayout");
}
}
} else if (reader.has("alignment")) {
// FlowLayout
String alignment = reader.readString("alignment");
if (HorizontalLayout.getAlignment(alignment) != null) {
return new HorizontalLayout(alignment, reader.readInteger("hgap", 0), reader.readInteger("vgap", 0));
} else {
throw new RuntimeException("Unsupported alignment for FlowLayout: " + alignment);
}
} else {
return new BorderLayout(reader.readInteger("hgap", 0), reader.readInteger("vgap", 0));
}
}
return null;
}
Aggregations