use of com.codename1.ui.plaf.UIManager in project CodenameOne by codenameone.
the class Container method insertComponentAtImpl.
void insertComponentAtImpl(int index, final Component cmp) {
if (index == Integer.MAX_VALUE) {
index = components.size();
}
if (cmp.getParent() != null) {
throw new IllegalArgumentException("Component is already contained in Container: " + cmp.getParent());
}
if (cmp instanceof Form) {
cmp.setVisible(true);
cmp.setPreferredSize(null);
}
UIManager manager = getUIManager();
boolean refreshLaf = manager != cmp.getUIManager();
cmp.setParent(this);
if (refreshLaf) {
Display.getInstance().callSerially(new Runnable() {
public void run() {
cmp.refreshTheme(false);
}
});
}
components.add(index, cmp);
setShouldCalcPreferredSize(true);
if (isInitialized()) {
cmp.initComponentImpl();
}
}
use of com.codename1.ui.plaf.UIManager in project CodenameOne by codenameone.
the class Container method initLaf.
/**
* {@inheritDoc}
*/
protected void initLaf(UIManager uim) {
if (uim == getUIManager() && isInitialized()) {
return;
}
super.initLaf(uim);
LookAndFeel laf = uim.getLookAndFeel();
setSmoothScrolling(laf.isDefaultSmoothScrolling());
if (components != null) {
int count = getComponentCount();
for (int i = 0; i < count; i++) {
Component c = getComponentAt(i);
c.initLaf(uim);
}
}
}
use of com.codename1.ui.plaf.UIManager in project CodenameOne by codenameone.
the class MenuBar method initMenuBar.
/**
* Initialize the MenuBar
*
* @param parent the associated Form
*/
protected void initMenuBar(Form parent) {
this.parent = parent;
selectMenuItem = createMenuSelectCommand();
cancelMenuItem = createMenuCancelCommand();
UIManager manager = parent.getUIManager();
LookAndFeel lf = manager.getLookAndFeel();
// don't minimize the app if it's a Dialog
minimizeOnBack = manager.isThemeConstant("minimizeOnBackBool", true) && !(parent instanceof Dialog);
hideEmptyCommands = manager.isThemeConstant("hideEmptyCommandsBool", false);
menuStyle = manager.getComponentStyle("Menu");
setUIID("SoftButton");
menuCommand = new Command(manager.localize("menu", "Menu"), lf.getMenuIcons()[2]);
// use the slide transition by default
if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
transitionIn = lf.getDefaultMenuTransitionIn();
transitionOut = lf.getDefaultMenuTransitionOut();
} else {
transitionIn = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 300, true);
transitionOut = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, false, 300, true);
}
menuCellRenderer = lf.getMenuRenderer();
int softkeyCount = Display.getInstance().getImplementation().getSoftkeyCount();
thirdSoftButton = Display.getInstance().isThirdSoftButton();
int commandBehavior = getCommandBehavior();
if (softkeyCount > 1 && commandBehavior < Display.COMMAND_BEHAVIOR_BUTTON_BAR) {
if (thirdSoftButton) {
setLayout(new GridLayout(1, 3));
soft = new Button[] { createSoftButton("SoftButtonCenter"), createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
main = soft[0];
left = soft[1];
right = soft[2];
if (parent.isRTL()) {
right.setUIID("SoftButtonLeft");
left.setUIID("SoftButtonRight");
addComponent(right);
addComponent(main);
addComponent(left);
} else {
addComponent(left);
addComponent(main);
addComponent(right);
}
if (isReverseSoftButtons()) {
Button b = soft[1];
soft[1] = soft[2];
soft[2] = b;
}
} else {
setLayout(new GridLayout(1, 2));
soft = new Button[] { createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
main = soft[0];
left = soft[0];
right = soft[1];
if (parent.isRTL()) {
right.setUIID("SoftButtonLeft");
left.setUIID("SoftButtonRight");
addComponent(right);
addComponent(left);
} else {
addComponent(left);
addComponent(right);
}
if (isReverseSoftButtons()) {
Button b = soft[0];
soft[0] = soft[1];
soft[1] = b;
}
}
// It doesn't make sense for softbuttons to have ... at the end
for (int iter = 0; iter < soft.length; iter++) {
soft[iter].setEndsWith3Points(false);
}
} else {
// special case for touch screens we still want the 3 softbutton areas...
if (thirdSoftButton) {
setLayout(new GridLayout(1, 3));
soft = new Button[] { createSoftButton("SoftButtonCenter"), createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
main = soft[0];
left = soft[1];
right = soft[2];
addComponent(left);
addComponent(main);
addComponent(right);
if (isReverseSoftButtons()) {
Button b = soft[1];
soft[1] = soft[2];
soft[2] = b;
}
} else {
soft = new Button[] { createSoftButton("SoftButtonCenter") };
}
}
softCommand = new Command[soft.length];
}
use of com.codename1.ui.plaf.UIManager in project CodenameOne by codenameone.
the class MenuBar method createCommandComponent.
/**
* Creates the component containing the commands within the given vector
* used for showing the menu dialog, this method calls the createCommandList
* method by default however it allows more elaborate menu creation.
*
* @param commands list of command objects
* @return Component that will result in the parent menu dialog recieving a command event
*/
protected Component createCommandComponent(Vector commands) {
UIManager manager = parent.getUIManager();
// Create a touch based menu interface
if (manager.getLookAndFeel().isTouchMenus()) {
Container menu = new Container();
menu.setScrollableY(true);
for (int iter = 0; iter < commands.size(); iter++) {
Command c = (Command) commands.elementAt(iter);
menu.addComponent(createTouchCommandButton(c));
}
if (!manager.isThemeConstant("touchCommandFlowBool", false)) {
int cols = calculateTouchCommandGridColumns(menu);
if (cols > getCommandCount()) {
cols = getCommandCount();
}
int rows = Math.max(1, getCommandCount() / cols + (getCommandCount() % cols != 0 ? 1 : 0));
if (rows > 1) {
// try to prevent too many columns concentraiting within a single row
int remainingColumns = (rows * cols) % getCommandCount();
int newCols = cols;
int newRows = rows;
while (remainingColumns != 0 && remainingColumns > 1 && newCols >= 2) {
newCols--;
newRows = Math.max(1, getCommandCount() / newCols + (getCommandCount() % newCols != 0 ? 1 : 0));
if (newRows != rows) {
break;
}
remainingColumns = (newRows * newCols) % getCommandCount();
}
if (newRows == rows) {
cols = newCols;
rows = newRows;
}
}
GridLayout g = new GridLayout(rows, cols);
g.setFillLastRow(manager.isThemeConstant("touchCommandFillBool", true));
menu.setLayout(g);
} else {
((FlowLayout) menu.getLayout()).setFillRows(true);
}
menu.setPreferredW(Display.getInstance().getDisplayWidth());
return menu;
}
return createCommandList(commands);
}
use of com.codename1.ui.plaf.UIManager in project CodenameOne by codenameone.
the class MenuBar method showMenuDialog.
/*private void fixCommandAlignment() {
if (left != null) {
if (parent.isRTL()) {
left.setAlignment(Label.RIGHT);
right.setAlignment(Label.LEFT);
} else {
left.setAlignment(Label.LEFT);
right.setAlignment(Label.RIGHT);
}
if(main != null && main != left && main != right) {
main.setAlignment(CENTER);
}
}
}*/
/**
* A menu is implemented as a dialog, this method allows you to override dialog
* display in order to customize the dialog menu in various ways
*
* @param menu a dialog containing menu options that can be customized
* @return the command selected by the user in the dialog (not menu) Select
* or Cancel
*/
protected Command showMenuDialog(Dialog menu) {
UIManager manager = parent.getUIManager();
boolean pref = manager.isThemeConstant("menuPrefSizeBool", false);
int height;
int marginLeft;
int marginRight = 0;
if (pref) {
Container dialogContentPane = menu.getDialogComponent();
marginLeft = parent.getWidth() - (dialogContentPane.getPreferredW() + menu.getStyle().getHorizontalPadding());
marginLeft = Math.max(0, marginLeft);
if (parent.getSoftButtonCount() > 1) {
height = parent.getHeight() - parent.getSoftButton(0).getParent().getPreferredH() - dialogContentPane.getPreferredH();
} else {
height = parent.getHeight() - dialogContentPane.getPreferredH();
}
height = Math.max(0, height);
} else {
float menuWidthPercent = 1 - Float.parseFloat(manager.getThemeConstant("menuWidthPercent", "75")) / 100;
float menuHeightPercent = 1 - Float.parseFloat(manager.getThemeConstant("menuHeightPercent", "50")) / 100;
height = (int) (parent.getHeight() * menuHeightPercent);
marginLeft = (int) (parent.getWidth() * menuWidthPercent);
}
if (isReverseSoftButtons()) {
marginRight = marginLeft;
marginLeft = 0;
}
if (getCommandBehavior() == Display.COMMAND_BEHAVIOR_ICS) {
menu.setTransitionOutAnimator(transitionIn);
menu.setTransitionInAnimator(transitionOut);
int th = getTitleAreaContainer().getHeight();
return menu.show(th, height - th, marginLeft, marginRight, true);
} else {
if (manager.getLookAndFeel().isTouchMenus() && manager.isThemeConstant("PackTouchMenuBool", true)) {
return menu.showPacked(BorderLayout.SOUTH, true);
} else {
return menu.show(height, 0, marginLeft, marginRight, true);
}
}
}
Aggregations