Search in sources :

Example 1 with ElementListener

use of com.ramussoft.common.event.ElementListener in project ramus by Vitaliy-Yakovchuk.

the class RowSet method elementCreated.

protected void elementCreated(ElementEvent event) {
    synchronized (this) {
        Element element = event.getNewElement();
        createNativeRow(element);
    }
    for (ElementListener l : getElementListeners()) {
        l.elementCreated(event);
    }
}
Also used : Element(com.ramussoft.common.Element) ElementListener(com.ramussoft.common.event.ElementListener)

Example 2 with ElementListener

use of com.ramussoft.common.event.ElementListener in project ramus by Vitaliy-Yakovchuk.

the class IDEF0ViewPlugin method createRegisterAction.

private ActionDescriptor createRegisterAction() {
    ActionDescriptor register = new ActionDescriptor();
    register.setMenu("Help");
    register.setAction(new AbstractAction() {

        {
            putValue(ACTION_COMMAND_KEY, "RegisterApplication");
        }

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            JPanel panel = new JPanel(new BorderLayout());
            double[][] size = { { 5, TableLayout.FILL, TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM, TableLayout.FILL, TableLayout.MINIMUM, TableLayout.FILL, 5 }, { 5, TableLayout.MINIMUM, 5, TableLayout.MINIMUM, 5, TableLayout.MINIMUM, 5, TableLayout.MINIMUM, 5 } };
            JPanel center = new JPanel(new TableLayout(size));
            final JTextField regName = new JTextField();
            center.add(new JLabel(ResourceLoader.getString("RegName")), "1,1,9,1");
            center.add(regName, "1,3,9,3");
            center.add(new JLabel(ResourceLoader.getString("SerialNumber")), "1,5,9,5");
            final JTextField[] fields = new JTextField[5];
            for (int i = 0; i < 5; i++) {
                try {
                    fields[i] = new JFormattedTextField(new MaskFormatter("AAAAA"));
                } catch (ParseException e1) {
                }
                fields[i].setPreferredSize(new Dimension(60, fields[i].getPreferredSize().height));
                center.add(fields[i], (i * 2 + 1) + ", 7");
                center.add(new JLabel("-"), (i * 2 + 2) + ", 7");
                final Action oldPaste = fields[i].getActionMap().get("paste");
                AbstractAction paste = new AbstractAction() {

                    @Override
                    public void actionPerformed(java.awt.event.ActionEvent e) {
                        String text = getClipboard();
                        if (text != null) {
                            String trim = text.trim();
                            if (trim.length() == 29) {
                                String[] strings = trim.split("-");
                                boolean ok = true;
                                for (String s : strings) {
                                    if (s.length() != 5)
                                        ok = false;
                                    for (char c : s.toCharArray()) {
                                        if (!Character.isLetterOrDigit(c))
                                            ok = false;
                                    }
                                }
                                if (ok) {
                                    for (int i = 0; i < 5; i++) {
                                        fields[i].setText(strings[i].toUpperCase());
                                    }
                                    return;
                                }
                            }
                        }
                        oldPaste.actionPerformed(e);
                    }
                };
                fields[i].getActionMap().put("paste-from-clipboard", paste);
                fields[i].getActionMap().put("paste", paste);
            }
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    fields[0].requestFocus();
                }
            });
            panel.add(center, BorderLayout.SOUTH);
            BaseDialog dialog = new BaseDialog(framework.getMainFrame(), true) {

                private int count = 0;

                @Override
                protected void onOk() {
                    final StringBuffer sb = new StringBuffer();
                    for (JTextField field : fields) {
                        sb.append(field.getText().trim());
                        sb.append("-");
                    }
                    String serial = sb.toString().substring(0, sb.length() - 1);
                    if (new SerialCheker().check(serial)) {
                        Metadata.DEMO_REGISTERED = true;
                        com.ramussoft.gui.common.prefrence.Options.setString("REGISTERED_VERSION", Boolean.toString(true));
                        Options.setString("SERIAL", serial);
                        for (ElementListener el : framework.getEngine().getElementListeners(null)) {
                            if (el instanceof DemoChecker) {
                                DemoChecker dc = (DemoChecker) el;
                                framework.getEngine().removeElementListener(null, el);
                                dc.getFramework().propertyChanged("EnableSaveActions");
                                String uc = " " + GlobalResourcesManager.getString("UnregisteredCopy");
                                String title = framework.getMainFrame().getTitle().replace(uc, "");
                                framework.getMainFrame().setTitle(title);
                            }
                        }
                        com.ramussoft.gui.common.prefrence.Options.setString("REG_NAME", regName.getText());
                        Metadata.REGISTERED_FOR = regName.getText();
                        super.onOk();
                        SwingUtilities.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                JOptionPane.showMessageDialog(framework.getMainFrame(), MessageFormat.format(ResourceLoader.getString("SerialIsRight"), Metadata.getApplicationName()));
                            }
                        });
                    } else {
                        try {
                            getOKButton().setEnabled(false);
                            Thread.sleep(3000 * count);
                            count++;
                            SwingUtilities.invokeLater(new Runnable() {

                                @Override
                                public void run() {
                                    JOptionPane.showMessageDialog(framework.getMainFrame(), ResourceLoader.getString("SerialIsWrong"));
                                }
                            });
                            getOKButton().setEnabled(true);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            };
            dialog.setTitle(ResourceLoader.getString("RegisterApplication"));
            dialog.setMainPane(panel);
            dialog.pack();
            dialog.setLocationRelativeTo(null);
            dialog.setResizable(false);
            dialog.setVisible(true);
        }
    });
    return register;
}
Also used : JPanel(javax.swing.JPanel) AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) DemoChecker(com.ramussoft.pb.idef.elements.DemoChecker) MaskFormatter(javax.swing.text.MaskFormatter) JTextField(javax.swing.JTextField) BorderLayout(java.awt.BorderLayout) ElementListener(com.ramussoft.common.event.ElementListener) AbstractAction(javax.swing.AbstractAction) TableLayout(info.clearthought.layout.TableLayout) SerialCheker(com.ramussoft.pb.frames.components.SerialCheker) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) ParseException(java.text.ParseException)

Aggregations

ElementListener (com.ramussoft.common.event.ElementListener)2 Element (com.ramussoft.common.Element)1 SerialCheker (com.ramussoft.pb.frames.components.SerialCheker)1 DemoChecker (com.ramussoft.pb.idef.elements.DemoChecker)1 TableLayout (info.clearthought.layout.TableLayout)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 ParseException (java.text.ParseException)1 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1 JFormattedTextField (javax.swing.JFormattedTextField)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JTextField (javax.swing.JTextField)1 MaskFormatter (javax.swing.text.MaskFormatter)1