Search in sources :

Example 1 with SerialCheker

use of com.ramussoft.pb.frames.components.SerialCheker in project ramus by Vitaliy-Yakovchuk.

the class MainFrame method setEngine.

public void setEngine(final GUIFramework framework) {
    this.framework = framework;
    if (Metadata.DEMO) {
        Thread thread = new Thread(new Runnable() {

            @Override
            public void run() {
                String serial = Options.getString("SERIAL");
                if ((serial == null) || (!new SerialCheker().check(serial))) {
                    framework.getEngine().addElementListener(null, new DemoChecker(framework));
                    Metadata.DEMO_REGISTERED = false;
                } else
                    Metadata.DEMO_REGISTERED = true;
            }
        });
        thread.setPriority(Thread.MIN_PRIORITY);
        thread.start();
    }
    if (Metadata.LOCAL_VERSION_DISABLE) {
        if (framework.getEngine().getDeligate() != null) {
            ext(framework);
        }
    }
}
Also used : DemoChecker(com.ramussoft.pb.idef.elements.DemoChecker) SerialCheker(com.ramussoft.pb.frames.components.SerialCheker)

Example 2 with SerialCheker

use of com.ramussoft.pb.frames.components.SerialCheker in project ramus by Vitaliy-Yakovchuk.

the class IDEF0ViewPlugin method getActionDescriptors.

@SuppressWarnings("unused")
@Override
public ActionDescriptor[] getActionDescriptors() {
    ActionDescriptor openStreans = new ActionDescriptor();
    openStreans.setActionLevel(ActionLevel.GLOBAL);
    openStreans.setMenu("Tools");
    openStreans.setAction(new AbstractAction() {

        {
            putValue(ACTION_COMMAND_KEY, "streams");
        }

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            framework.propertyChanged(OPEN_STREAMS);
        }
    });
    ActionDescriptor runWebServer = new ActionDescriptor();
    runWebServer.setActionLevel(ActionLevel.GLOBAL);
    runWebServer.setMenu("Tools");
    runWebServer.setAction(new AbstractAction() {

        {
            putValue(ACTION_COMMAND_KEY, MainFrame.OPEN_WEB_SERVER);
        }

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            if (server == null) {
                server = new HTTPServer("0", NDataPluginFactory.getDataPlugin(null, engine, rules), framework) {

                    @Override
                    protected void serverStarted() {
                        AbstractAttributePlugin.openUrl("http://127.0.0.1:" + getServer().getLocalPort(), framework);
                    }
                };
            } else {
                AbstractAttributePlugin.openUrl("http://127.0.0.1:" + server.getServer().getLocalPort(), framework);
            }
        }
    });
    ActionDescriptor idef0Separator = new ActionDescriptor();
    idef0Separator.setMenu("IDEF0");
    ActionDescriptor loadModelsFromFile = new ActionDescriptor();
    loadModelsFromFile.setActionLevel(ActionLevel.GLOBAL);
    loadModelsFromFile.setMenu("IDEF0");
    loadModelsFromFile.setAction(new AbstractAction() {

        {
            putValue(ACTION_COMMAND_KEY, "loadModelsFromFile");
        }

        @Override
        public void actionPerformed(java.awt.event.ActionEvent event) {
            DataPlugin plugin = NDataPluginFactory.getDataPlugin(null, engine, rules);
            try {
                final JFileChooser chooser = frame.getChooser();
                if (chooser.showOpenDialog(framework.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
                    plugin.loadFromParalel(chooser.getSelectedFile(), framework);
                }
            } catch (final IOException e) {
                JOptionPane.showMessageDialog(framework.getMainFrame(), e.getLocalizedMessage());
            }
        }
    });
    ActionDescriptor toolsSeparator = new ActionDescriptor();
    toolsSeparator.setMenu("Tools");
    if ((Metadata.DEMO) && (!new SerialCheker().check(Options.getString("SERIAL")))) {
        Metadata.DEMO_REGISTERED = false;
        if (Metadata.DEMO) {
            framework.addActionListener("MainFrameShown", new ActionListener() {

                @Override
                public void onAction(ActionEvent event) {
                    String title = framework.getMainFrame().getTitle();
                    if (!Metadata.DEMO_REGISTERED)
                        title += " " + GlobalResourcesManager.getString("UnregisteredCopy");
                    else
                        title += " " + MessageFormat.format(GlobalResourcesManager.getString("RegisteredName"), Metadata.REGISTERED_FOR);
                    framework.getMainFrame().setTitle(title);
                }
            });
        }
        return new ActionDescriptor[] { runWebServer, openStreans, findAction(CURSOR_TOOL), findAction(FUNCTION_TOOL), findAction(ARROW_TOOL), findAction(TILDA_TOOL), findAction(TEXT_TOOL), findAction(EXTERNAL_REFERENCE_TOOL), findAction(DFDS_ROLE_TOOL), findAction(DATA_STORE_TOOL), findAction(IDEF0_NET), findAction(GO_TO_PARENT), findAction(GO_TO_CHILD), idef0Separator, findAction(CENTER_ALL_SECTORS), idef0Separator, loadModelsFromFile, toolsSeparator, findAction(ADD_MODEL_TO_TEMPLATE, "Tools"), findAction(USER_TEMPLATES, "Tools"), idef0Separator, findAction(MODEL_PROPETIES), findAction(DIAGRAM_PROPETIES), idef0Separator, findAction(EXPORT_TO_IMAGES), createExportToIDL(), createImportFromIDL(), createRegisterAction(), toolsSeparator, findAction(CREATE_LEVEL) };
    } else {
        if (Metadata.DEMO) {
            framework.addActionListener("MainFrameShown", new ActionListener() {

                @Override
                public void onAction(ActionEvent event) {
                    String title = framework.getMainFrame().getTitle();
                    if (!Metadata.DEMO_REGISTERED)
                        title += " " + GlobalResourcesManager.getString("UnregisteredCopy");
                    else
                        title += " " + MessageFormat.format(GlobalResourcesManager.getString("RegisteredName"), Metadata.REGISTERED_FOR);
                    framework.getMainFrame().setTitle(title);
                }
            });
        }
        ActionDescriptor editSeparator = new ActionDescriptor();
        editSeparator.setMenu("Edit");
        ActionDescriptor cut = new ActionDescriptor();
        cut.setMenu("Edit");
        cut.setAction(frame.findAction(MainFrame.CUT));
        ActionDescriptor copy = new ActionDescriptor();
        copy.setMenu("Edit");
        copy.setAction(frame.findAction(MainFrame.COPY));
        ActionDescriptor paste = new ActionDescriptor();
        paste.setMenu("Edit");
        paste.setAction(frame.findAction(MainFrame.PASTE));
        return new ActionDescriptor[] { runWebServer, openStreans, findAction(CURSOR_TOOL), findAction(FUNCTION_TOOL), findAction(ARROW_TOOL), findAction(TILDA_TOOL), findAction(TEXT_TOOL), findAction(EXTERNAL_REFERENCE_TOOL), findAction(DFDS_ROLE_TOOL), findAction(DATA_STORE_TOOL), findAction(IDEF0_NET), findAction(GO_TO_PARENT), findAction(GO_TO_CHILD), idef0Separator, findAction(CENTER_ALL_SECTORS), idef0Separator, loadModelsFromFile, toolsSeparator, findAction(ADD_MODEL_TO_TEMPLATE, "Tools"), findAction(USER_TEMPLATES, "Tools"), idef0Separator, findAction(MODEL_PROPETIES), findAction(DIAGRAM_PROPETIES), idef0Separator, findAction(EXPORT_TO_IMAGES), createExportToIDL(), createImportFromIDL(), editSeparator, cut, copy, paste };
    }
}
Also used : SerialCheker(com.ramussoft.pb.frames.components.SerialCheker) ActionEvent(com.ramussoft.gui.common.event.ActionEvent) IOException(java.io.IOException) HTTPServer(com.ramussoft.pb.print.web.HTTPServer) JFileChooser(javax.swing.JFileChooser) ActionListener(com.ramussoft.gui.common.event.ActionListener) DataPlugin(com.ramussoft.pb.DataPlugin) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) AbstractAction(javax.swing.AbstractAction)

Example 3 with SerialCheker

use of com.ramussoft.pb.frames.components.SerialCheker 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

SerialCheker (com.ramussoft.pb.frames.components.SerialCheker)3 DemoChecker (com.ramussoft.pb.idef.elements.DemoChecker)2 AbstractAction (javax.swing.AbstractAction)2 ElementListener (com.ramussoft.common.event.ElementListener)1 ActionEvent (com.ramussoft.gui.common.event.ActionEvent)1 ActionListener (com.ramussoft.gui.common.event.ActionListener)1 DataPlugin (com.ramussoft.pb.DataPlugin)1 NDataPlugin (com.ramussoft.pb.data.negine.NDataPlugin)1 HTTPServer (com.ramussoft.pb.print.web.HTTPServer)1 TableLayout (info.clearthought.layout.TableLayout)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 Action (javax.swing.Action)1 JFileChooser (javax.swing.JFileChooser)1 JFormattedTextField (javax.swing.JFormattedTextField)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JTextField (javax.swing.JTextField)1