use of com.codename1.db.Row in project CodenameOne by codenameone.
the class DefaultLookAndFeel method drawTextArea.
/**
* {@inheritDoc}
*/
public void drawTextArea(Graphics g, TextArea ta) {
setFG(g, ta);
int line = ta.getLines();
int oX = g.getClipX();
int oY = g.getClipY();
int oWidth = g.getClipWidth();
int oHeight = g.getClipHeight();
Font f = ta.getStyle().getFont();
int fontHeight = f.getHeight();
int align = reverseAlignForBidi(ta);
int leftPadding = ta.getStyle().getPaddingLeft(ta.isRTL());
int rightPadding = ta.getStyle().getPaddingRight(ta.isRTL());
int topPadding = ta.getStyle().getPaddingTop();
boolean shouldBreak = false;
for (int i = 0; i < line; i++) {
int x = ta.getX() + leftPadding;
int y = ta.getY() + topPadding + (ta.getRowsGap() + fontHeight) * i;
if (Rectangle.intersects(x, y, ta.getWidth(), fontHeight, oX, oY, oWidth, oHeight)) {
String rowText = (String) ta.getTextAt(i);
// display ******** if it is a password field
String displayText = "";
if ((ta.getConstraint() & TextArea.PASSWORD) != 0) {
int rlen = rowText.length();
for (int j = 0; j < rlen; j++) {
displayText += passwordChar;
}
} else {
displayText = rowText;
}
switch(align) {
case Component.RIGHT:
x = ta.getX() + ta.getWidth() - rightPadding - f.stringWidth(displayText);
break;
case Component.CENTER:
x += (ta.getWidth() - leftPadding - rightPadding - f.stringWidth(displayText)) / 2;
break;
}
int nextY = ta.getY() + topPadding + (ta.getRowsGap() + fontHeight) * (i + 2);
// add "..." at the last row
if (ta.isEndsWith3Points() && ta.getGrowLimit() == (i + 1) && ta.getGrowLimit() != line) {
if (displayText.length() > 3) {
displayText = displayText.substring(0, displayText.length() - 3);
}
g.drawString(displayText + "...", x, y, ta.getStyle().getTextDecoration());
return;
} else {
g.drawString(displayText, x, y, ta.getStyle().getTextDecoration());
}
shouldBreak = true;
} else {
if (shouldBreak) {
break;
}
}
}
}
use of com.codename1.db.Row in project CodenameOne by codenameone.
the class TableLayout method getRowHeightPixels.
private int getRowHeightPixels(int row, int percentageOf, int available) {
int current = 0;
for (int iter = 0; iter < columns; iter++) {
Constraint c = tablePositions[row * columns + iter];
if (c == null || c == H_SPAN_CONSTRAINT || c == V_SPAN_CONSTRAINT || c == VH_SPAN_CONSTRAINT || c.spanVertical > 1) {
continue;
}
// height in percentage of the parent container
if (c.height > 0) {
current = Math.max(current, c.height * percentageOf / 100);
} else {
Style s = c.parent.getStyle();
current = Math.max(current, c.parent.getPreferredH() + s.getMarginTop() + s.getMarginBottom());
}
if (available > -1) {
current = Math.min(available, current);
}
}
return current;
}
use of com.codename1.db.Row in project CodenameOne by codenameone.
the class TableLayout method layoutContainer.
/**
* {@inheritDoc}
*/
public void layoutContainer(Container parent) {
try {
verticalSpanningExists = false;
horizontalSpanningExists = false;
// column and row size in pixels
Style s = parent.getStyle();
int top = s.getPaddingTop();
int left = s.getPaddingLeft(parent.isRTL());
int bottom = s.getPaddingBottom();
int right = s.getPaddingRight(parent.isRTL());
boolean rtl = parent.isRTL();
columnSizes = new int[columns];
if (modifableColumnSize == null || columns != modifableColumnSize.length) {
modifableColumnSize = new boolean[columns];
}
columnPositions = new int[columns];
int[] rowSizes = new int[rows];
rowPositions = new int[rows];
int pWidth = parent.getLayoutWidth() - parent.getSideGap() - left - right;
int pHeight = parent.getLayoutHeight() - parent.getBottomGap() - top - bottom;
int currentX = left;
int availableReminder = pWidth;
int cslen = columnSizes.length;
for (int iter = 0; iter < cslen; iter++) {
columnSizes[iter] = getColumnWidthPixels(iter, pWidth, availableReminder);
availableReminder -= columnSizes[iter];
}
// so they are distributed sensibly if no room is available
if (!parent.isScrollableX()) {
int totalWidth = 0;
int totalModifyablePixels = 0;
// check how many columns we can modify (the user hasn't requested a specific size for those)
for (int iter = 0; iter < modifableColumnSize.length; iter++) {
if (modifableColumnSize[iter]) {
totalModifyablePixels += columnSizes[iter];
}
totalWidth += columnSizes[iter];
}
if (pWidth < totalWidth) {
int totalPixelsToRemove = totalWidth - pWidth;
int totalPixelsNecessary = totalModifyablePixels - totalPixelsToRemove;
// Go over the modifyable columns and remove the right pixels according to the ratio
for (int iter = 0; iter < modifableColumnSize.length; iter++) {
if (modifableColumnSize[iter]) {
columnSizes[iter] = (int) (((float) columnSizes[iter]) / ((float) totalModifyablePixels) * totalPixelsNecessary);
}
}
}
}
for (int iter = 0; iter < columnSizes.length; iter++) {
if (rtl) {
currentX += columnSizes[iter];
columnPositions[iter] = pWidth - currentX;
} else {
columnPositions[iter] = currentX;
currentX += columnSizes[iter];
}
}
int currentY = top;
int rlen = rowSizes.length;
for (int iter = 0; iter < rlen; iter++) {
if (parent.isScrollableY()) {
rowSizes[iter] = getRowHeightPixels(iter, pHeight, -1);
} else {
rowSizes[iter] = getRowHeightPixels(iter, pHeight, pHeight - currentY + top);
}
rowPositions[iter] = currentY;
currentY += rowSizes[iter];
}
int clen = columnSizes.length;
for (int r = 0; r < rlen; r++) {
for (int c = 0; c < clen; c++) {
Constraint con = tablePositions[r * columns + c];
int conX, conY, conW, conH;
if (con != null && con != H_SPAN_CONSTRAINT && con != V_SPAN_CONSTRAINT && con != VH_SPAN_CONSTRAINT) {
Style componentStyle = con.parent.getStyle();
int leftMargin = componentStyle.getMarginLeft(parent.isRTL());
int topMargin = componentStyle.getMarginTop();
// conX = left + leftMargin + columnPositions[c]; // bugfix table with padding not drawn correctly
// conY = top + topMargin + rowPositions[r]; // bugfix table with padding not drawn correctly
conX = leftMargin + columnPositions[c];
conY = topMargin + rowPositions[r];
if (con.spanHorizontal > 1) {
horizontalSpanningExists = true;
int w = columnSizes[c];
for (int sh = 1; sh < con.spanHorizontal; sh++) {
w += columnSizes[Math.min(c + sh, columnSizes.length - 1)];
}
// for RTL we need to move the component to the side so spanning will work
if (rtl) {
conX = left + leftMargin + columnPositions[c + con.spanHorizontal - 1];
}
conW = w - leftMargin - componentStyle.getMarginLeft(parent.isRTL());
} else {
conW = columnSizes[c] - leftMargin - componentStyle.getMarginRight(parent.isRTL());
}
if (con.spanVertical > 1) {
verticalSpanningExists = true;
int h = rowSizes[r];
for (int sv = 1; sv < con.spanVertical; sv++) {
h += rowSizes[Math.min(r + sv, rowSizes.length - 1)];
}
conH = h - topMargin - componentStyle.getMarginBottom();
} else {
conH = rowSizes[r] - topMargin - componentStyle.getMarginBottom();
}
placeComponent(rtl, con, conX, conY, conW, conH);
}
}
}
} catch (ArrayIndexOutOfBoundsException err) {
Log.e(err);
}
}
use of com.codename1.db.Row in project CodenameOne by codenameone.
the class Table method createCellImpl.
private Component createCellImpl(Object value, final int row, final int column, boolean editable) {
Component c = createCell(value, row, column, editable);
c.putClientProperty("row", new Integer(row));
c.putClientProperty("column", new Integer(column));
// we do this here to allow subclasses to return a text area or its subclass
if (c instanceof TextArea) {
((TextArea) c).addActionListener(listener);
}
Style s = c.getSelectedStyle();
// s.setMargin(0, 0, 0, 0);
s.setMargin(verticalBorderSpacing, verticalBorderSpacing, horizontalBorderSpacing, horizontalBorderSpacing);
if ((drawBorder) && (innerBorder != INNER_BORDERS_NONE)) {
s.setBorder(null);
s = c.getUnselectedStyle();
s.setBorder(null);
} else {
s = c.getUnselectedStyle();
}
// s.setBgTransparency(0);
// s.setMargin(0, 0, 0, 0);
s.setMargin(verticalBorderSpacing, verticalBorderSpacing, horizontalBorderSpacing, horizontalBorderSpacing);
return c;
}
use of com.codename1.db.Row in project CodenameOne by codenameone.
the class PerformanceMonitor method refreshFrameActionPerformed.
// GEN-LAST:event_runGCActionPerformed
private void refreshFrameActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_refreshFrameActionPerformed
componentHierarchy.setModel(new ComponentTreeModel(Display.getInstance().getCurrent()));
componentHierarchy.setCellRenderer(new DefaultTreeCellRenderer() {
@Override
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
String s = value.toString();
if (value instanceof Component) {
s = ((Component) value).getUIID() + ": " + s;
}
// To change body of generated methods, choose Tools | Templates.
return super.getTreeCellRendererComponent(tree, s, sel, expanded, leaf, row, hasFocus);
}
});
Display.getInstance().callSerially(new Runnable() {
public void run() {
trackDrawing = true;
Display.getInstance().getCurrent().repaint();
Display.getInstance().callSerially(new Runnable() {
public void run() {
// data collected
trackDrawing = false;
renderedItems.setModel(createTableModel());
}
});
}
});
}
Aggregations