Search in sources :

Example 61 with ActionEvent

use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.

the class SwipeBackSupport method bind.

/**
 * Binds support for swiping to the given forms
 *
 * @param currentForm the current form
 * @param destination the destination form which can be created lazily
 */
protected void bind(final Form currentForm, final LazyValue<Form> destination) {
    pointerDragged = new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            if (sideSwipePotential) {
                final int x = evt.getX();
                final int y = evt.getY();
                if (Math.abs(y - initialDragY) > x - initialDragX) {
                    sideSwipePotential = false;
                    return;
                }
                evt.consume();
                if (dragActivated) {
                    currentX = x;
                    Display.getInstance().getCurrent().repaint();
                } else {
                    if (x - initialDragX > Display.getInstance().convertToPixels(currentForm.getUIManager().getThemeConstant("backGestureThresholdInt", 5), true)) {
                        dragActivated = true;
                        destinationForm = destination.get();
                        startBackTransition(currentForm, destinationForm);
                    }
                }
            }
        }
    };
    pointerReleased = new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            if (dragActivated) {
                int destNumberX = Display.getInstance().getDisplayWidth();
                int incrementsX = Display.getInstance().convertToPixels(3, true);
                if (currentX < destNumberX / 2) {
                    destinationForm = currentForm;
                    destNumberX = 0;
                    incrementsX *= -1;
                }
                final int destNumber = destNumberX;
                final int increments = incrementsX;
                Display.getInstance().getCurrent().registerAnimated(new Animation() {

                    public boolean animate() {
                        currentX += increments;
                        if (currentX > 0 && currentX >= destNumber || currentX < 0 && currentX <= destNumber) {
                            currentX = destNumber;
                            Transition t = destinationForm.getTransitionInAnimator();
                            destinationForm.setTransitionInAnimator(CommonTransitions.createEmpty());
                            destinationForm.show();
                            destinationForm.setTransitionInAnimator(t);
                            destinationForm = null;
                            dragActivated = false;
                            return false;
                        }
                        return true;
                    }

                    public void paint(Graphics g) {
                    }
                });
            }
        }
    };
    pointerPressed = new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            sideSwipePotential = false;
            int displayWidth = Display.getInstance().getDisplayWidth();
            sideSwipePotential = !transitionRunning && evt.getX() < displayWidth / currentForm.getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
            initialDragX = evt.getX();
            initialDragY = evt.getY();
        /*if (sideSwipePotential) {
                    Component c = Display.getInstance().getCurrent().getComponentAt(initialDragX, initialDragY);
                    if (c != null && c.shouldBlockSideSwipe()) {
                        sideSwipePotential = false;
                    }
                }*/
        }
    };
    currentForm.addPointerDraggedListener(pointerDragged);
    currentForm.addPointerReleasedListener(pointerReleased);
    currentForm.addPointerPressedListener(pointerPressed);
}
Also used : Graphics(com.codename1.ui.Graphics) ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) Transition(com.codename1.ui.animations.Transition) Animation(com.codename1.ui.animations.Animation)

Example 62 with ActionEvent

use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.

the class L10nEditor method initTable.

private void initTable() {
    bundleTable.setModel(new AbstractTableModel() {

        public int getRowCount() {
            return keys.size();
        }

        public int getColumnCount() {
            return 1 + localeList.size();
        }

        public boolean isCellEditable(int row, int col) {
            boolean b = col != 0;
            if (b) {
                String s = (String) getValueAt(row, col);
                return s == null || !s.contains("\n");
            }
            return b;
        }

        public String getColumnName(int columnIndex) {
            if (columnIndex == 0) {
                return "Key";
            }
            return (String) localeList.get(columnIndex - 1);
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
            if (columnIndex == 0) {
                return keys.get(rowIndex);
            }
            Hashtable h = res.getL10N(localeName, (String) localeList.get(columnIndex - 1));
            return h.get(keys.get(rowIndex));
        }

        public void setValueAt(Object val, int rowIndex, int columnIndex) {
            res.setModified();
            if (columnIndex == 0) {
                if (!keys.contains(val)) {
                // ...
                }
                return;
            }
            // Hashtable h = (Hashtable)bundle.get(localeList.get(columnIndex - 1));
            // h.put(keys.get(rowIndex), val);
            String currentKey = (String) keys.get(rowIndex);
            res.setLocaleProperty(localeName, (String) localeList.get(columnIndex - 1), currentKey, val);
            if (currentKey.equals("@im")) {
                StringTokenizer tok = new StringTokenizer((String) val, "|");
                boolean modified = false;
                while (tok.hasMoreTokens()) {
                    String currentIm = tok.nextToken();
                    if ("ABC".equals(currentIm) || "123".equals(currentIm) || "Abc".equals(currentIm) || "abc".equals(currentIm)) {
                        continue;
                    }
                    String prop = "@im-" + currentIm;
                    if (!keys.contains(prop)) {
                        keys.add(prop);
                        for (Object locale : localeList) {
                            res.setLocaleProperty(localeName, (String) locale, prop, "");
                        }
                        modified = true;
                    }
                }
                if (modified) {
                    fireTableDataChanged();
                }
                return;
            }
            if (currentKey.equals("@vkb")) {
                boolean modified = false;
                StringTokenizer tok = new StringTokenizer((String) val, "|");
                while (tok.hasMoreTokens()) {
                    String currentIm = tok.nextToken();
                    if ("ABC".equals(currentIm) || "123".equals(currentIm) || ".,123".equals(currentIm) || ".,?".equals(currentIm)) {
                        continue;
                    }
                    String prop = "@vkb-" + currentIm;
                    if (!keys.contains(prop)) {
                        keys.add(prop);
                        for (Object locale : localeList) {
                            res.setLocaleProperty(localeName, (String) locale, prop, "");
                        }
                        modified = true;
                    }
                }
                if (modified) {
                    fireTableDataChanged();
                }
            }
        }
    });
    bundleTable.setDefaultRenderer(Object.class, new SwingRenderer() {

        private JCheckBox chk = new JCheckBox();

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            if (column > 0) {
                // constant value
                String key = (String) keys.get(row);
                if (key.startsWith("@")) {
                    if (key.equalsIgnoreCase("@rtl")) {
                        chk.setSelected(value != null && "true".equalsIgnoreCase(value.toString()));
                        updateComponentSelectedState(chk, isSelected, table, row, column, hasFocus);
                        return chk;
                    }
                    if (key.startsWith("@vkb") || key.startsWith("@im")) {
                        JButton b = new JButton("...");
                        updateComponentSelectedState(b, isSelected, table, row, column, hasFocus);
                        return b;
                    }
                }
            }
            return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        }
    });
    bundleTable.setDefaultEditor(Object.class, new DefaultCellEditor(new JTextField()) {

        private Object currentValue;

        String editedKey;

        private DefaultCellEditor standardEditor = new DefaultCellEditor(new JTextField());

        private DefaultCellEditor buttonEditor = new DefaultCellEditor(new JTextField()) {

            private JButton button = new JButton("...");

            {
                button.setBorderPainted(false);
                button.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        if (editedKey.equals("@vkb") || editedKey.equals("@im")) {
                            currentValue = editInputModeOrder((String) currentValue, editedKey.equals("@vkb"));
                            fireEditingStoppedExt();
                            return;
                        }
                        /*if(editedKey.startsWith("@vkb")) {
                                VKBEditor v = new VKBEditor(button, editedKey.substring(5), (String)currentValue);
                                currentValue = v.getValue();
                                fireEditingStoppedExt();
                                return;
                            }*/
                        if (editedKey.startsWith("@im")) {
                            currentValue = editTextFieldInputMode((String) currentValue);
                            fireEditingStoppedExt();
                            return;
                        }
                    }
                });
            }

            public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
                editedKey = (String) keys.get(row);
                return button;
            }
        };

        private DefaultCellEditor checkBoxEditor = new DefaultCellEditor(new JCheckBox()) {

            public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
                return super.getTableCellEditorComponent(table, new Boolean("true".equalsIgnoreCase((String) value)), isSelected, row, column);
            }

            public Object getCellEditorValue() {
                Boolean b = (Boolean) super.getCellEditorValue();
                if (b.booleanValue()) {
                    return "true";
                }
                return "false";
            }
        };

        private TableCellEditor current = standardEditor;

        {
            buttonEditor.setClickCountToStart(1);
            checkBoxEditor.setClickCountToStart(1);
        }

        private void updateEditor(int row) {
            // constant value
            final String key = (String) keys.get(row);
            if (key.startsWith("@")) {
                if (key.equalsIgnoreCase("@rtl")) {
                    current = checkBoxEditor;
                    return;
                }
                if (key.startsWith("@vkb") || key.startsWith("@im")) {
                    current = buttonEditor;
                    return;
                }
            }
            current = standardEditor;
        }

        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
            updateEditor(row);
            currentValue = value;
            return current.getTableCellEditorComponent(table, value, isSelected, row, column);
        }

        public void fireEditingStoppedExt() {
            fireEditingStopped();
        }

        public Object getCellEditorValue() {
            if (current == buttonEditor) {
                return currentValue;
            }
            return current.getCellEditorValue();
        }

        public boolean stopCellEditing() {
            return current.stopCellEditing();
        }

        public void cancelCellEditing() {
            current.cancelCellEditing();
        }

        public void addCellEditorListener(CellEditorListener l) {
            current.addCellEditorListener(l);
            super.addCellEditorListener(l);
        }

        public void removeCellEditorListener(CellEditorListener l) {
            current.removeCellEditorListener(l);
            super.removeCellEditorListener(l);
        }

        public boolean isCellEditable(EventObject anEvent) {
            return current.isCellEditable(anEvent);
        }

        public boolean shouldSelectCell(EventObject anEvent) {
            return current.shouldSelectCell(anEvent);
        }
    });
    locales.setModel(new DefaultComboBoxModel(localeList.toArray()));
    removeLocale.setEnabled(localeList.size() > 1);
}
Also used : Hashtable(java.util.Hashtable) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) CellEditorListener(javax.swing.event.CellEditorListener) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) JTextField(javax.swing.JTextField) SwingRenderer(com.codename1.ui.resource.util.SwingRenderer) EventObject(java.util.EventObject) DefaultCellEditor(javax.swing.DefaultCellEditor) JCheckBox(javax.swing.JCheckBox) StringTokenizer(java.util.StringTokenizer) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) AbstractTableModel(javax.swing.table.AbstractTableModel) EventObject(java.util.EventObject) TableCellEditor(javax.swing.table.TableCellEditor) Component(java.awt.Component) UIBuilderOverride(com.codename1.ui.util.UIBuilderOverride)

Example 63 with ActionEvent

use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.

the class LiveDemo method start.

public void start() {
    Form previewForm = new Form("Preview Theme");
    Toolbar tb = new Toolbar();
    previewForm.setToolbar(tb);
    tb.setTitle("Preview Theme");
    tb.addMaterialCommandToSideMenu("Side Command", FontImage.MATERIAL_HELP, new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            ToastBar.showErrorMessage("Unmapped....");
        }
    });
    tb.addMaterialCommandToOverflowMenu("Overflow Command", FontImage.MATERIAL_HELP, new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            ToastBar.showErrorMessage("Unmapped....");
        }
    });
    tb.addMaterialCommandToRightBar("", FontImage.MATERIAL_HELP, new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            ToastBar.showErrorMessage("Unmapped....");
        }
    });
    previewForm.setLayout(new BorderLayout());
    Container first = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    first.addComponent(new Label("This is a Label"));
    first.addComponent(new Button("This is a Button"));
    MultiButton mb = new MultiButton("This is a MultiButton");
    mb.setTextLine2("Second line of text");
    FontImage.setMaterialIcon(mb, FontImage.MATERIAL_HELP);
    first.addComponent(mb);
    TextField txt = new TextField();
    txt.setHint("This is a TextField");
    first.addComponent(txt);
    first.addComponent(new CheckBox("This is a CheckBox"));
    RadioButton rb1 = new RadioButton("This is a Radio Button 1");
    rb1.setGroup("group");
    first.addComponent(rb1);
    RadioButton rb2 = new RadioButton("This is a Radio Button 2");
    rb2.setGroup("group");
    first.addComponent(rb2);
    final Slider s = new Slider();
    s.setText("50%");
    s.setProgress(50);
    s.setEditable(true);
    s.setRenderPercentageOnTop(true);
    first.addComponent(s);
    Button b1 = new Button("Show a Dialog");
    b1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            Dialog.show("Dialog Title", "Dialog Body", "Ok", "Cancel");
        }
    });
    first.addComponent(b1);
    previewForm.add(BorderLayout.CENTER, first);
    previewForm.show();
}
Also used : Slider(com.codename1.ui.Slider) Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent) BoxLayout(com.codename1.ui.layouts.BoxLayout) Label(com.codename1.ui.Label) RadioButton(com.codename1.ui.RadioButton) Container(com.codename1.ui.Container) ActionListener(com.codename1.ui.events.ActionListener) BorderLayout(com.codename1.ui.layouts.BorderLayout) RadioButton(com.codename1.ui.RadioButton) Button(com.codename1.ui.Button) MultiButton(com.codename1.components.MultiButton) CheckBox(com.codename1.ui.CheckBox) TextField(com.codename1.ui.TextField) MultiButton(com.codename1.components.MultiButton) Toolbar(com.codename1.ui.Toolbar)

Example 64 with ActionEvent

use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.

the class TimelineEditor method playActionPerformed.

private void playActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_playActionPerformed
    final Timeline t = (Timeline) renderer.getImage();
    t.setPause(false);
    play.setEnabled(false);
    pause.setEnabled(true);
    refreshTimeline = new javax.swing.Timer(500, new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (t.isPause()) {
                pause.setEnabled(false);
                play.setEnabled(true);
                refreshTimeline.stop();
                refreshTimeline = null;
                return;
            }
            refreshingTimelineLock = true;
            timeline.setValue(t.getTime());
            refreshingTimelineLock = false;
        }
    });
    refreshTimeline.setRepeats(true);
    refreshTimeline.start();
}
Also used : Timeline(com.codename1.ui.animations.Timeline) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent)

Example 65 with ActionEvent

use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.

the class PulsateEditor method pulsateWizard.

public void pulsateWizard(EditableResources res, JComponent parent) {
    File[] f = ResourceEditorView.showOpenFileChooser("Image", ".png", ".jpg", ".jpeg", ".gif");
    if (f != null && f.length > 0) {
        try {
            timelineName.setText(f[0].getName());
            sourceImage = ImageIO.read(f[0]);
            updateTimeline();
            timer = new javax.swing.Timer(130, new java.awt.event.ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    if (previewLabel.animate()) {
                        previewLabel.repaint();
                        preview.repaint();
                    }
                }
            });
            timer.setRepeats(true);
            timer.setCoalesce(true);
            timer.start();
            int val = JOptionPane.showConfirmDialog(parent, this, "Edit Effect", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
            timer.stop();
            if (val == JOptionPane.OK_OPTION) {
                store(res, currentImage, timelineName.getText() + ": TL ");
                for (EncodedImage img : internalImages) {
                    store(res, img, timelineName.getText() + ": Fr ");
                }
            }
        } catch (IOException ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(parent, "Error in reading image file", "File Read Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) IOException(java.io.IOException) File(java.io.File) EncodedImage(com.codename1.ui.EncodedImage)

Aggregations

ActionEvent (com.codename1.ui.events.ActionEvent)98 ActionListener (com.codename1.ui.events.ActionListener)55 IOException (java.io.IOException)30 BorderLayout (com.codename1.ui.layouts.BorderLayout)28 Form (com.codename1.ui.Form)18 Hashtable (java.util.Hashtable)14 Vector (java.util.Vector)11 NetworkEvent (com.codename1.io.NetworkEvent)10 Container (com.codename1.ui.Container)9 ActionEvent (java.awt.event.ActionEvent)9 Command (com.codename1.ui.Command)8 ActionListener (java.awt.event.ActionListener)8 Button (com.codename1.ui.Button)7 Style (com.codename1.ui.plaf.Style)7 Rectangle (com.codename1.ui.geom.Rectangle)6 File (java.io.File)6 ConnectionNotFoundException (javax.microedition.io.ConnectionNotFoundException)6 MediaException (javax.microedition.media.MediaException)6 RecordStoreException (javax.microedition.rms.RecordStoreException)6 BufferedOutputStream (com.codename1.io.BufferedOutputStream)5