Search in sources :

Example 26 with Node

use of com.codename1.rad.nodes.Node in project CodenameOne by codenameone.

the class Node method getLocalToParentTransform.

/**
 * Gets the transform to use to transform the Node into its parent node's space.
 * @return
 */
public Transform getLocalToParentTransform() {
    Transform t = Transform.makeIdentity();
    Point3D rotationAxis = this.rotationAxis.get();
    if (rotationAxis == null) {
        rotationAxis = new Point3D(0, 0, 1);
    }
    Bounds localBounds = boundsInLocal.get();
    // Do translation
    translate(t, layoutX.get() + translateX.get(), layoutY.get() + translateY.get(), layoutZ.get() + translateZ.get());
    // Do scale
    // Do rotation
    translate(t, localBounds.getWidth() / 2, localBounds.getHeight() / 2, localBounds.getDepth() / 2);
    scale(t, scaleX.get(), scaleY.get(), scaleZ.get());
    rotate(t, rotate.get() * Math.PI / 180.0, rotationAxis.getX(), rotationAxis.getY(), rotationAxis.getZ());
    translate(t, -localBounds.getWidth() / 2, -localBounds.getHeight() / 2, -localBounds.getDepth() / 2);
    translate(t, 0, 0, localCanvasZ.get());
    return t;
}
Also used : Transform(com.codename1.ui.Transform)

Example 27 with Node

use of com.codename1.rad.nodes.Node in project CodenameOne by codenameone.

the class JavaSEPort method createSkinsMenu.

private JMenu createSkinsMenu(final JFrame frm, final JMenu menu) throws MalformedURLException {
    JMenu m;
    if (menu == null) {
        m = new JMenu("Skins");
        m.setDoubleBuffered(true);
    } else {
        m = menu;
        m.removeAll();
    }
    final JMenu skinMenu = m;
    Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
    String skinNames = pref.get("skins", DEFAULT_SKINS);
    if (skinNames != null) {
        if (skinNames.length() < DEFAULT_SKINS.length()) {
            skinNames = DEFAULT_SKINS;
        }
        ButtonGroup skinGroup = new ButtonGroup();
        StringTokenizer tkn = new StringTokenizer(skinNames, ";");
        while (tkn.hasMoreTokens()) {
            final String current = tkn.nextToken();
            String name = current;
            if (current.contains(":")) {
                try {
                    URL u = new URL(current);
                    File f = new File(u.getFile());
                    if (!f.exists()) {
                        continue;
                    }
                    name = f.getName();
                } catch (Exception e) {
                    continue;
                }
            } else {
                // remove the old builtin skins from the menu
                if (current.startsWith("/") && !current.equals(DEFAULT_SKIN)) {
                    continue;
                }
            }
            String d = System.getProperty("dskin");
            JRadioButtonMenuItem i = new JRadioButtonMenuItem(name, name.equals(pref.get("skin", d)));
            i.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent ae) {
                    if (netMonitor != null) {
                        netMonitor.dispose();
                        netMonitor = null;
                    }
                    if (perfMonitor != null) {
                        perfMonitor.dispose();
                        perfMonitor = null;
                    }
                    Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
                    pref.putBoolean("desktopSkin", false);
                    String mainClass = System.getProperty("MainClass");
                    if (mainClass != null) {
                        pref.put("skin", current);
                        frm.dispose();
                        System.setProperty("reload.simulator", "true");
                    } else {
                        loadSkinFile(current, frm);
                        refreshSkin(frm);
                    }
                }
            });
            skinGroup.add(i);
            skinMenu.add(i);
        }
    }
    JMenuItem dSkin = new JMenuItem("Desktop.skin");
    dSkin.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            if (netMonitor != null) {
                netMonitor.dispose();
                netMonitor = null;
            }
            if (perfMonitor != null) {
                perfMonitor.dispose();
                perfMonitor = null;
            }
            Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
            pref.putBoolean("desktopSkin", true);
            pref.putBoolean("uwpDesktopSkin", false);
            String mainClass = System.getProperty("MainClass");
            if (mainClass != null) {
                deinitializeSync();
                frm.dispose();
                System.setProperty("reload.simulator", "true");
            }
        }
    });
    JMenuItem uwpSkin = new JMenuItem("UWP Desktop.skin");
    uwpSkin.setToolTipText("Windows 10 Desktop Skin");
    uwpSkin.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            if (netMonitor != null) {
                netMonitor.dispose();
                netMonitor = null;
            }
            if (perfMonitor != null) {
                perfMonitor.dispose();
                perfMonitor = null;
            }
            Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
            pref.putBoolean("desktopSkin", true);
            pref.putBoolean("uwpDesktopSkin", true);
            String mainClass = System.getProperty("MainClass");
            if (mainClass != null) {
                deinitializeSync();
                frm.dispose();
                System.setProperty("reload.simulator", "true");
            }
        }
    });
    skinMenu.addSeparator();
    skinMenu.add(dSkin);
    skinMenu.add(uwpSkin);
    skinMenu.addSeparator();
    JMenuItem more = new JMenuItem("More...");
    skinMenu.add(more);
    more.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final JDialog pleaseWait = new JDialog(frm, false);
            pleaseWait.setLocationRelativeTo(frm);
            pleaseWait.setTitle("Message");
            pleaseWait.setLayout(new BorderLayout());
            pleaseWait.add(new JLabel("  Please Wait...  "), BorderLayout.CENTER);
            pleaseWait.pack();
            pleaseWait.setVisible(true);
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    final JDialog d = new JDialog(frm, true);
                    d.setLocationRelativeTo(frm);
                    d.setTitle("Skins");
                    d.getContentPane().setLayout(new BorderLayout());
                    String userDir = System.getProperty("user.home");
                    final File skinDir = new File(userDir + "/.codenameone/");
                    if (!skinDir.exists()) {
                        skinDir.mkdir();
                    }
                    Vector data = new Vector();
                    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                    final Document[] doc = new Document[1];
                    try {
                        DocumentBuilder db = dbf.newDocumentBuilder();
                        Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
                        InputStream is = openSkinsURL();
                        doc[0] = db.parse(is);
                        NodeList skins = doc[0].getElementsByTagName("Skin");
                        for (int i = 0; i < skins.getLength(); i++) {
                            Node skin = skins.item(i);
                            NamedNodeMap attr = skin.getAttributes();
                            String url = attr.getNamedItem("url").getNodeValue();
                            int ver = 0;
                            Node n = attr.getNamedItem("version");
                            if (n != null) {
                                ver = Integer.parseInt(n.getNodeValue());
                            }
                            boolean exists = new File(skinDir.getAbsolutePath() + url).exists();
                            if (!(exists) || Integer.parseInt(pref.get(url, "0")) < ver) {
                                Vector row = new Vector();
                                row.add(new Boolean(false));
                                row.add(new ImageIcon(new URL(defaultCodenameOneComProtocol + "://www.codenameone.com/OTA" + attr.getNamedItem("icon").getNodeValue())));
                                row.add(attr.getNamedItem("name").getNodeValue());
                                if (exists) {
                                    row.add("Update");
                                } else {
                                    row.add("New");
                                }
                                data.add(row);
                            }
                        }
                    } catch (Exception ex) {
                        Logger.getLogger(JavaSEPort.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    if (data.size() == 0) {
                        pleaseWait.setVisible(false);
                        JOptionPane.showMessageDialog(frm, "No New Skins to Install");
                        return;
                    }
                    Vector cols = new Vector();
                    cols.add("Install");
                    cols.add("Icon");
                    cols.add("Name");
                    cols.add("");
                    final DefaultTableModel tableModel = new DefaultTableModel(data, cols) {

                        @Override
                        public boolean isCellEditable(int row, int column) {
                            return column == 0;
                        }
                    };
                    JTable skinsTable = new JTable(tableModel) {

                        @Override
                        public Class<?> getColumnClass(int column) {
                            if (column == 0) {
                                return Boolean.class;
                            }
                            if (column == 1) {
                                return Icon.class;
                            }
                            return super.getColumnClass(column);
                        }
                    };
                    skinsTable.setRowHeight(112);
                    skinsTable.getTableHeader().setReorderingAllowed(false);
                    final JTextField filter = new JTextField();
                    final TableRowSorter<DefaultTableModel> sorter = new TableRowSorter<DefaultTableModel>(((DefaultTableModel) skinsTable.getModel()));
                    filter.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {

                        private void updateFilter() {
                            try {
                                RowFilter rf = RowFilter.regexFilter("(?i)" + filter.getText(), 2);
                                sorter.setRowFilter(rf);
                            } catch (java.util.regex.PatternSyntaxException e) {
                                return;
                            }
                        }

                        @Override
                        public void insertUpdate(javax.swing.event.DocumentEvent e) {
                            updateFilter();
                        }

                        @Override
                        public void removeUpdate(DocumentEvent e) {
                            updateFilter();
                        }

                        @Override
                        public void changedUpdate(DocumentEvent e) {
                            updateFilter();
                        }
                    });
                    skinsTable.setRowSorter(sorter);
                    d.getContentPane().add(filter, BorderLayout.NORTH);
                    d.getContentPane().add(new JScrollPane(skinsTable), BorderLayout.CENTER);
                    JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
                    JButton download = new JButton("Download");
                    download.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            final Vector toDowload = new Vector();
                            NodeList skins = doc[0].getElementsByTagName("Skin");
                            for (int i = 0; i < tableModel.getRowCount(); i++) {
                                if (((Boolean) tableModel.getValueAt(i, 0)).booleanValue()) {
                                    Node skin;
                                    for (int j = 0; j < skins.getLength(); j++) {
                                        skin = skins.item(j);
                                        NamedNodeMap attr = skin.getAttributes();
                                        if (attr.getNamedItem("name").getNodeValue().equals(tableModel.getValueAt(i, 2))) {
                                            String url = attr.getNamedItem("url").getNodeValue();
                                            String[] data = new String[2];
                                            data[0] = defaultCodenameOneComProtocol + "://www.codenameone.com/OTA" + url;
                                            data[1] = attr.getNamedItem("version").getNodeValue();
                                            toDowload.add(data);
                                            break;
                                        }
                                    }
                                }
                            }
                            if (toDowload.size() > 0) {
                                final JDialog downloadMessage = new JDialog(d, true);
                                downloadMessage.setTitle("Downloading");
                                downloadMessage.setLayout(new FlowLayout());
                                downloadMessage.setLocationRelativeTo(d);
                                final JLabel details = new JLabel("<br><br>Details");
                                downloadMessage.add(details);
                                final JLabel progress = new JLabel("Progress<br><br>");
                                downloadMessage.add(progress);
                                new Thread() {

                                    @Override
                                    public void run() {
                                        for (Iterator it = toDowload.iterator(); it.hasNext(); ) {
                                            String[] data = (String[]) it.next();
                                            String url = data[0];
                                            details.setText(url.substring(url.lastIndexOf("/")));
                                            details.repaint();
                                            progress.setText("");
                                            progress.repaint();
                                            try {
                                                File skin = downloadSkin(skinDir, url, data[1], progress);
                                                if (skin.exists()) {
                                                    addSkinName(skin.toURI().toString());
                                                }
                                            } catch (Exception e) {
                                            }
                                        }
                                        downloadMessage.setVisible(false);
                                        d.setVisible(false);
                                        try {
                                            createSkinsMenu(frm, skinMenu);
                                        } catch (MalformedURLException ex) {
                                            Logger.getLogger(JavaSEPort.class.getName()).log(Level.SEVERE, null, ex);
                                        }
                                    }
                                }.start();
                                downloadMessage.pack();
                                downloadMessage.setSize(200, 70);
                                downloadMessage.setVisible(true);
                            } else {
                                JOptionPane.showMessageDialog(d, "Choose a Skin to Download");
                            }
                        }
                    });
                    p.add(download);
                    d.getContentPane().add(p, BorderLayout.SOUTH);
                    d.pack();
                    pleaseWait.dispose();
                    d.setVisible(true);
                }
            });
        }
    });
    skinMenu.addSeparator();
    JMenuItem addSkin = new JMenuItem("Add New...");
    skinMenu.add(addSkin);
    addSkin.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            FileDialog picker = new FileDialog(frm, "Add Skin");
            picker.setMode(FileDialog.LOAD);
            picker.setFilenameFilter(new FilenameFilter() {

                public boolean accept(File file, String string) {
                    return string.endsWith(".skin");
                }
            });
            picker.setModal(true);
            picker.setVisible(true);
            String file = picker.getFile();
            if (file != null) {
                if (netMonitor != null) {
                    netMonitor.dispose();
                    netMonitor = null;
                }
                if (perfMonitor != null) {
                    perfMonitor.dispose();
                    perfMonitor = null;
                }
                String mainClass = System.getProperty("MainClass");
                if (mainClass != null) {
                    Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
                    pref.put("skin", picker.getDirectory() + File.separator + file);
                    deinitializeSync();
                    frm.dispose();
                    System.setProperty("reload.simulator", "true");
                } else {
                    loadSkinFile(picker.getDirectory() + File.separator + file, frm);
                    refreshSkin(frm);
                }
            }
        }
    });
    skinMenu.addSeparator();
    JMenuItem reset = new JMenuItem("Reset Skins");
    skinMenu.add(reset);
    reset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            if (JOptionPane.showConfirmDialog(frm, "Are you sure you want to reset skins to default?", "Clean Storage", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
                Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
                pref.put("skins", DEFAULT_SKINS);
                String userDir = System.getProperty("user.home");
                final File skinDir = new File(userDir + "/.codenameone/");
                if (skinDir.exists()) {
                    File[] childs = skinDir.listFiles();
                    for (int i = 0; i < childs.length; i++) {
                        File child = childs[i];
                        if (child.getName().endsWith(".skin")) {
                            child.delete();
                        }
                    }
                }
                if (netMonitor != null) {
                    netMonitor.dispose();
                    netMonitor = null;
                }
                if (perfMonitor != null) {
                    perfMonitor.dispose();
                    perfMonitor = null;
                }
                String mainClass = System.getProperty("MainClass");
                if (mainClass != null) {
                    pref.put("skin", DEFAULT_SKIN);
                    deinitializeSync();
                    frm.dispose();
                    System.setProperty("reload.simulator", "true");
                } else {
                    loadSkinFile(DEFAULT_SKIN, frm);
                    refreshSkin(frm);
                }
            }
        }
    });
    return skinMenu;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Node(org.w3c.dom.Node) AttributedString(java.text.AttributedString) Document(org.w3c.dom.Document) Vector(java.util.Vector) NodeList(org.w3c.dom.NodeList) java.util(java.util) DefaultTableModel(javax.swing.table.DefaultTableModel) FilenameFilter(java.io.FilenameFilter) PathIterator(java.awt.geom.PathIterator) Preferences(java.util.prefs.Preferences) java.awt.event(java.awt.event) javax.swing.event(javax.swing.event) TableRowSorter(javax.swing.table.TableRowSorter) NamedNodeMap(org.w3c.dom.NamedNodeMap) BufferedInputStream(com.codename1.io.BufferedInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) AudioInputStream(javax.sound.sampled.AudioInputStream) ZipInputStream(java.util.zip.ZipInputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) ParseException(java.text.ParseException) EOFException(java.io.EOFException) FontFormatException(java.awt.FontFormatException) LineUnavailableException(javax.sound.sampled.LineUnavailableException) Point(java.awt.Point) StringTokenizer(java.util.StringTokenizer) DocumentBuilder(javax.xml.parsers.DocumentBuilder) FileDialog(java.awt.FileDialog)

Example 28 with Node

use of com.codename1.rad.nodes.Node in project CodeRAD by shannah.

the class ActionNode method findAttribute.

@Override
public Attribute findAttribute(Class type) {
    Attribute att = super.findAttribute(type);
    if (att != null) {
        return att;
    }
    Node parent = getParent();
    if (parent instanceof ActionNode) {
        return parent.findAttribute(type);
    }
    return null;
}
Also used : ActionStyleAttribute(com.codename1.rad.attributes.ActionStyleAttribute)

Example 29 with Node

use of com.codename1.rad.nodes.Node in project CodeRAD by shannah.

the class FieldNode method getPropertySelector.

/**
 * Gets a property selector for this field node.  If the field contained
 * a PropertyNode or a Tags node, then it will construct a selector from those.
 *
 * Otherwise it will check for a {@link ProeprtySelectorAttribute}, and return
 * a selector constructed form that, with the provided entity root.
 * @param context
 * @return A property selector, or null if no property or tag is set, and no property selector is set.
 */
public PropertySelector getPropertySelector(Entity context) {
    if (context == null) {
        return null;
    }
    Property prop = getProperty(context.getEntity().getEntityType());
    if (prop != null) {
        return new PropertySelector(context, prop);
    }
    Tags tags = getTags();
    if (tags != null) {
        return new PropertySelector(context, tags.toArray());
    }
    PropertySelectorAttribute selectorProvider = (PropertySelectorAttribute) findAttribute(PropertySelectorAttribute.class);
    if (selectorProvider != null) {
        return selectorProvider.getValue(context);
    }
    return null;
}
Also used : PropertySelector(com.codename1.rad.models.PropertySelector) PropertySelectorAttribute(com.codename1.rad.attributes.PropertySelectorAttribute) Property(com.codename1.rad.models.Property) Tags(com.codename1.rad.models.Tags)

Example 30 with Node

use of com.codename1.rad.nodes.Node in project CodeRAD by shannah.

the class Controller method getViewNode.

/**
 * Gets the {@link ViewNode} that should be used as the view model for views of this controller. Subclasses should override {@link #createViewNode() }
 * to define the view node for the controller.  This method will defer to that for the initial view node creation, and then just return
 * that view node on subsequeuent calls.
 *
 * NOTE: This will automatically set the parent node of the view node to the view node of the parent controller.
 * @return
 */
public ViewNode getViewNode() {
    startControllerInternal();
    if (node == null) {
        node = createViewNode();
        ViewNode parentNode = null;
        if (parent != null) {
            parentNode = parent.getViewNode();
        }
        node.setParent(parentNode);
    }
    return node;
}
Also used : ViewNode(com.codename1.rad.nodes.ViewNode)

Aggregations

BorderLayout (com.codename1.ui.layouts.BorderLayout)11 ViewNode (com.codename1.rad.nodes.ViewNode)10 ActionNode (com.codename1.rad.nodes.ActionNode)8 Container (com.codename1.ui.Container)7 ListNode (com.codename1.rad.nodes.ListNode)6 PropertySelectorAttribute (com.codename1.rad.attributes.PropertySelectorAttribute)5 Node (com.codename1.rad.nodes.Node)5 BoxLayout (com.codename1.ui.layouts.BoxLayout)5 MultiButtonEntityView (com.codename1.rad.ui.entityviews.MultiButtonEntityView)4 Label (com.codename1.ui.Label)4 GridLayout (com.codename1.ui.layouts.GridLayout)4 Log (com.codename1.io.Log)3 NodeDecoratorAttribute (com.codename1.rad.attributes.NodeDecoratorAttribute)3 ViewPropertyParameterAttribute (com.codename1.rad.attributes.ViewPropertyParameterAttribute)3 Entity (com.codename1.rad.models.Entity)3 EntityList (com.codename1.rad.models.EntityList)3 EntityTypeBuilder.entityTypeBuilder (com.codename1.rad.models.EntityTypeBuilder.entityTypeBuilder)3 Thing (com.codename1.rad.schemas.Thing)3 WrapperEntityView (com.codename1.rad.ui.entityviews.WrapperEntityView)3 Button (com.codename1.ui.Button)3