use of com.codename1.ui.Component in project CodenameOne by codenameone.
the class MigLayout method checkCache.
/**
* Check if something has changed and if so recreate it to the cached
* objects.
*
* @param parent The parent that is the target for this layout manager.
*/
private void checkCache(Container parent) {
if (parent == null) {
return;
}
if (dirty) {
grid = null;
}
cleanConstraintMaps(parent);
// Check if the grid is valid
int mc = PlatformDefaults.getModCount();
if (lastModCount != mc) {
grid = null;
lastModCount = mc;
}
// if (!parent.isValid()) {
if (!lastWasInvalid) {
lastWasInvalid = true;
int hash = 0;
// Added in 3.7.3 to resolve a timing regression introduced in 3.7.1
boolean resetLastInvalidOnParent = false;
for (ComponentWrapper wrapper : ccMap.keySet()) {
Object component = wrapper.getComponent();
if (component instanceof TextArea) {
resetLastInvalidOnParent = true;
}
hash ^= wrapper.getLayoutHashCode();
hash += 285134905;
}
if (resetLastInvalidOnParent) {
resetLastInvalidOnParent(parent);
}
if (hash != lastHash) {
grid = null;
lastHash = hash;
}
Dimension ps = new Dimension(parent.getWidth(), parent.getHeight());
if (lastInvalidSize == null || !lastInvalidSize.equals(ps)) {
grid = null;
lastInvalidSize = ps;
}
}
/*} else {
lastWasInvalid = false;
}*/
ContainerWrapper par = checkParent(parent);
setDebug(par, getDebugMillis() > 0);
if (grid == null) {
grid = new Grid(par, lc, rowSpecs, colSpecs, ccMap, callbackList);
}
dirty = false;
}
use of com.codename1.ui.Component in project CodenameOne by codenameone.
the class MigLayout method layoutContainer.
public void layoutContainer(final Container parent) {
checkCache(parent);
Style i = parent.getStyle();
int[] b = new int[] { i.getMarginLeftNoRTL(), i.getMarginTop(), parent.getWidth() - i.getHorizontalMargins(), parent.getHeight() - i.getVerticalMargins() };
if (grid.layout(b, lc.getAlignX(), lc.getAlignY(), getDebug())) {
grid = null;
checkCache(parent);
grid.layout(b, lc.getAlignX(), lc.getAlignY(), getDebug());
}
/*long newSize = grid.getHeight()[1] + (((long) grid.getWidth()[1]) << 32);
if (lastSize != newSize) {
lastSize = newSize;
final ContainerWrapper containerWrapper = checkParent(parent);
Window win = ((Window) SwingUtilities.getAncestorOfClass(Window.class, (Component)containerWrapper.getComponent()));
if (win != null) {
if (win.isVisible()) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
adjustWindowSize(containerWrapper);
}
});
} else {
adjustWindowSize(containerWrapper);
}
}
}*/
lastInvalidSize = null;
}
use of com.codename1.ui.Component in project CodenameOne by codenameone.
the class MigLayout method cleanConstraintMaps.
/**
* Checks so all components in ccMap actually exist in the parent's
* collection. Removes any references that don't.
*
* @param parent The parent to compare ccMap against. Never null.
*/
private void cleanConstraintMaps(Container parent) {
HashSet<Component> parentCompSet = new HashSet<Component>();
for (int iter = 0; iter < parent.getComponentCount(); iter++) {
parentCompSet.add(parent.getComponentAt(iter));
}
Iterator<Map.Entry<ComponentWrapper, CC>> it = ccMap.entrySet().iterator();
while (it.hasNext()) {
Component c = (Component) it.next().getKey().getComponent();
if (parentCompSet.contains(c) == false) {
it.remove();
scrConstrMap.remove(c);
}
}
}
use of com.codename1.ui.Component in project CodenameOne by codenameone.
the class MigLayout method setConstraintMap.
/**
* Sets the constraints map.
*
* @param map The map. Will be copied.
*/
public void setConstraintMap(Map<Component, Object> map) {
scrConstrMap.clear();
ccMap.clear();
for (Component e : map.keySet()) {
setComponentConstraintsImpl(e, map.get(e), true);
}
}
use of com.codename1.ui.Component in project CodenameOne by codenameone.
the class DefaultListCellRenderer method getCellRendererComponent.
/**
* {@inheritDoc}
*/
public Component getCellRendererComponent(Component list, Object model, T value, int index, boolean isSelected) {
if (!alwaysRenderSelection && !Display.getInstance().shouldRenderSelection(list)) {
isSelected = false;
}
setFocus(isSelected);
if (showNumbers) {
String text = "" + value;
Map<String, String> t = UIManager.getInstance().getBundle();
if (t != null && value != null) {
Object o = t.get(value.toString());
if (o != null) {
text = (String) o;
}
}
if (isRTL()) {
setText(text + " ." + (index + 1));
} else {
setText("" + (index + 1) + ". " + text);
}
} else {
if (value != null) {
String v = value.toString();
setText(v);
if (isRightAlignNumbers()) {
char c = v.charAt(0);
Style s = getStyle();
if (c >= '0' && c <= '9') {
s.setAlignment(RIGHT);
} else {
s.setAlignment(LEFT);
}
}
} else {
setText("null");
}
}
if (value instanceof Command) {
setIcon(((Command) value).getIcon());
setEnabled(((Command) value).isEnabled());
}
return this;
}
Aggregations