Java Code Examples for com.codename1.ui.events.ActionEvent#getSource()

The following examples show how to use com.codename1.ui.events.ActionEvent#getSource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LikeButton.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void actionPerformed(ActionEvent evt) {
    if(!FaceBookAccess.getInstance().isAuthenticated()) {
        FaceBookAccess.setClientId(appId);
        FaceBookAccess.setRedirectURI(redirectURI);
        FaceBookAccess.setClientSecret(clientSecret);
        if(permissions != null) {
            FaceBookAccess.setPermissions(permissions);            
        }
        FaceBookAccess.getInstance().showAuthentication(this);
        return;
    }
    if(evt.getSource() instanceof Exception) {
        return;
    }
    try {
        FaceBookAccess.getInstance().postLike(getPostId());
    } catch (IOException ex) {
        Log.e(ex);
    }
}
 
Example 2
Source File: Tree.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent evt) {
    if(current != null) {
        leafListener.fireActionEvent(new ActionEvent(current,ActionEvent.Type.Other));
        return;
    }
    Component c = (Component)evt.getSource();
    Container lead = c.getParent().getLeadParent();
    if(lead != null) {
        c = lead;
    }
    Object e = c.getClientProperty(KEY_EXPANDED);
    if(e != null && e.equals("true")) {
        collapseNode(c);
    } else {
        expandNode(isInitialized(), c);
    }
}
 
Example 3
Source File: FacebookShare.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void actionPerformed(ActionEvent evt) {
    if (!FaceBookAccess.getInstance().isAuthenticated()) {
        FaceBookAccess.getInstance().showAuthentication(this);
        return;
    }
    if (evt.getSource() instanceof Exception) {
        return;
    }
    if (evt.getSource() instanceof String) {
        token = (String) evt.getSource();
    }

    super.actionPerformed(evt);
}
 
Example 4
Source File: Capture.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent evt) {
    if(evt == null) {
        url = null;
    } else {
        url = (String)evt.getSource();
    }
    completed = true;
    synchronized(this) {
        this.notify();
    }
}
 
Example 5
Source File: ComponentSelector.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a ComponentInspector with the source component of the provided event.
 * @param e The event whose source component is added to the set.
 * @return A ComponentSelector with a single component - the source of the event.
 */
public static ComponentSelector $(ActionEvent e) {
    Object src = e.getSource();
    if (src == null) {
        return new ComponentSelector();
    } else if (src instanceof Component) {
        return new ComponentSelector((Component)src);
    }
    return new ComponentSelector();
}
 
Example 6
Source File: TextSelection.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == selectAll) {
        selectAll();
    } else {
        copy();
    }
}
 
Example 7
Source File: SwitchList.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt) {
    if (evt.getSource() instanceof Switch && contains((Switch)evt.getSource())) {
        Switch src = (Switch)evt.getSource();
        int index = SwitchList.this.getComponentIndex(src.getParent());
        if (src.isOn()) {
            getMultiListModel().addSelectedIndices(index);
        } else {
            getMultiListModel().removeSelectedIndices(index);
        }
    }
}
 
Example 8
Source File: RadioButtonList.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt) {
    if (evt.getSource() instanceof RadioButton && contains((Component)evt.getSource())) {
        RadioButton src = (RadioButton)evt.getSource();
        int index = RadioButtonList.this.getComponentIndex(src);
        if (src.isSelected()) {
            getModel().setSelectedIndex(index);
        }
    }
}
 
Example 9
Source File: CheckBoxList.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt) {
    if (evt.getSource() instanceof CheckBox && contains((Component)evt.getSource())) {
        CheckBox src = (CheckBox)evt.getSource();
        int index = CheckBoxList.this.getComponentIndex(src);
        if (src.isSelected()) {
            getMultiListModel().addSelectedIndices(index);
        } else {
            getMultiListModel().removeSelectedIndices(index);
        }
    }
}
 
Example 10
Source File: ButtonList.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt) {
    if (evt.getSource() instanceof Component && contains((Component)evt.getSource())) {
        ActionEvent nevt = new ActionEvent(this, evt.getEventType(), evt.getActualComponent(), evt.getX(), evt.getY());
        actionListeners.fireActionEvent(nevt);
    }
}
 
Example 11
Source File: Table.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public void actionPerformed(ActionEvent evt) {
    Component c = (Component)evt.getSource();
    int row = getCellRow(c);
    int column = getCellColumn(c);
    if(c instanceof TextArea) {
        TextArea t = (TextArea)c;
        editingColumn = column;
        editingRow = row;
        if(isAbstractTableModel()) {
            Class type = ((AbstractTableModel)model).getCellType(row, column);
            if(type == Integer.class) {
                model.setValueAt(row, column, t.getAsInt(0));
                return;
            }
            if(type == Long.class) {
                model.setValueAt(row, column, t.getAsLong(0));
                return;
            }
            if(type == Short.class) {
                model.setValueAt(row, column, (short)t.getAsInt(0));
                return;
            }
            if(type == Byte.class) {
                model.setValueAt(row, column, (byte)t.getAsInt(0));
                return;
            }
            if(type == Float.class) {
                model.setValueAt(row, column, (float)t.getAsDouble(0));
                return;
            }
            if(type == Double.class) {
                model.setValueAt(row, column, t.getAsDouble(0));
                return;
            }
            if(type == Character.class) {
                if(t.getText().length() > 0) {
                    model.setValueAt(row, column, t.getText().charAt(0));
                }
                return;
            }
        }
        model.setValueAt(row, column, t.getText());
    } else {
        if(c instanceof Picker) {
            switch(((Picker)c).getType()) {
                case Display.PICKER_TYPE_DATE:
                    model.setValueAt(row, column, ((Picker)c).getDate());              
                    break;
                    
                case Display.PICKER_TYPE_STRINGS:
                    model.setValueAt(row, column, ((Picker)c).getSelectedString());
                    break;
            }
        } else {
            if(c instanceof CheckBox) {
                model.setValueAt(row, column, ((CheckBox)c).isSelected());
            }
        }
    }
}
 
Example 12
Source File: Label.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt) {
    if (isInitialized() && evt.getSource() == getIcon()) {
        repaint();
    }
}