Search in sources :

Example 21 with Row

use of com.codename1.db.Row in project CodenameOne by codenameone.

the class Table method createCell.

/**
 * Creates a cell based on the given value
 *
 * @param value the new value object
 * @param row row number, -1 for the header rows
 * @param column column number
 * @param editable true if the cell is editable
 * @return cell component instance
 */
protected Component createCell(Object value, int row, final int column, boolean editable) {
    if (row == -1) {
        Button header = new Button((String) value, getUIID() + "Header");
        header.getAllStyles().setAlignment(titleAlignment);
        header.setTextPosition(LEFT);
        if (isSortSupported()) {
            header.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent evt) {
                    Comparator cmp = createColumnSortComparator(column);
                    if (cmp == null) {
                        return;
                    }
                    if (column == sortedColumn) {
                        ascending = !ascending;
                    } else {
                        sortedColumn = column;
                        ascending = false;
                    }
                    setModel(new SortableTableModel(sortedColumn, ascending, model, cmp));
                }
            });
            if (sortedColumn == column) {
                if (ascending) {
                    FontImage.setMaterialIcon(header, FontImage.MATERIAL_ARROW_DROP_UP);
                } else {
                    FontImage.setMaterialIcon(header, FontImage.MATERIAL_ARROW_DROP_DOWN);
                }
            }
        }
        return header;
    }
    if (editable) {
        TextField cell = new TextField("" + value, -1);
        cell.setLeftAndRightEditingTrigger(false);
        cell.setUIID(getUIID() + "Cell");
        return cell;
    }
    Label cell = new Label("" + value);
    cell.setUIID(getUIID() + "Cell");
    cell.getUnselectedStyle().setAlignment(cellAlignment);
    cell.getSelectedStyle().setAlignment(cellAlignment);
    cell.setFocusable(true);
    return cell;
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) Button(com.codename1.ui.Button) ActionEvent(com.codename1.ui.events.ActionEvent) Label(com.codename1.ui.Label) TextField(com.codename1.ui.TextField) Comparator(java.util.Comparator)

Example 22 with Row

use of com.codename1.db.Row in project CodenameOne by codenameone.

the class CN1ImageLuminanceSource method getRow.

// Instead of multiplying by 306, 601, 117, we multiply by 256, 512, 256, so that
// the multiplies can be implemented as shifts.
// 
// Really, it's:
// 
// return ((((pixel >> 16) & 0xFF) << 8) +
// (((pixel >>  8) & 0xFF) << 9) +
// (( pixel        & 0xFF) << 8)) >> 10;
// 
// That is, we're replacing the coefficients in the original with powers of two,
// which can be implemented as shifts, even though changing the coefficients slightly
// alters the conversion. The difference is not significant for our purposes.
public byte[] getRow(int y, byte[] row) {
    if (y < 0 || y >= getHeight()) {
        throw new IllegalArgumentException("Requested row is outside the image: " + y);
    }
    int width = getWidth();
    if (row == null || row.length < width) {
        row = new byte[width];
    }
    /*
         * if (rgbData == null || rgbData.length < width) { rgbData = new
         * int[width]; }
         */
    // image.getRGB(rgbData, 0, width, 0, y, width, 1);
    // For LWUIT Image get the row as sub image without alpha processing,
    // as we don't need alpha channel anyway
    Image rowImg = image.subImage(0, y, width, 1, false);
    rgbData = rowImg.getRGB();
    for (int x = 0; x < width; x++) {
        row[x] = toLuminance(rgbData[x]);
    }
    return row;
}
Also used : Image(com.codename1.ui.Image)

Aggregations

Component (com.codename1.ui.Component)8 Style (com.codename1.ui.plaf.Style)5 ArrayList (java.util.ArrayList)4 Point (java.awt.Point)3 EventObject (java.util.EventObject)3 Hashtable (java.util.Hashtable)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)2 TableLayout (com.codename1.ui.table.TableLayout)2 EmbeddedContainer (com.codename1.ui.util.EmbeddedContainer)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 List (java.util.List)2 StringTokenizer (java.util.StringTokenizer)2 JButton (javax.swing.JButton)2 JList (javax.swing.JList)2 Cursor (com.codename1.db.Cursor)1 Row (com.codename1.db.Row)1 BufferedInputStream (com.codename1.io.BufferedInputStream)1 Button (com.codename1.ui.Button)1 Container (com.codename1.ui.Container)1