Package com.lightcrafts.templates

Examples of com.lightcrafts.templates.TemplateKey


    /**
     * Report the currently active Template namespace.  This is used to
     * initialize the save-Template dialog.
     */
    public String getNamespace() {
        TemplateKey key = tree.getSelectedTemplateKey();
        return (key != null) ? key.getNamespace() : null;
    }
View Full Code Here


//            }
//        );
        addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent event) {
                    TemplateKey key = tree.getSelectedTemplateKey();
                    if (key != null) {
                        try {
                            tree.clearSelection();
                            TemplateDatabase.removeTemplateDocument(key);
                        }
View Full Code Here

                    if (event.isPopupTrigger()) {
                        Point p = event.getPoint();
                        TreePath path = getClosestPathForLocation(p.x, p.y);
                        if (path != null) {
                            Object last = path.getLastPathComponent();
                            TemplateKey key = null;
                            if (last instanceof TemplateTreeNode) {
                                TemplateTreeNode node = (TemplateTreeNode) last;
                                key = node.key;
                            }
                            popup.show(p, key);
View Full Code Here

    private List<TemplateKey> getSelectedTemplateKeys() {
        Object[] rows = list.getSelectedValues();
        List<TemplateKey> keys = new ArrayList<TemplateKey>();
        for (Object row : rows) {
            TemplateKey key = (TemplateKey) row;
            keys.add(key);
        }
        return keys;
    }
View Full Code Here

            showError(
                LOCALE.get("TemplateImportError", file.getName()), e
            );
            return;
        }
        TemplateKey key = TemplateKey.importKey(file);
        try {
            TemplateDatabase.addTemplateDocument(doc, key, false);
        }
        catch (TemplateDatabase.TemplateException e) {
            showError(LOCALE.get("TemplateStoreError",  key.toString()), e);
            return;
        }
        updateFromTemplates();
    }
View Full Code Here

        String defaultName = null;
        do {
            String name = LOCALE.get(
                "TemplateDefaultNamePattern", Integer.toString(n++)
            );
            TemplateKey key = new TemplateKey(nsDefault, name);
            try {
                TemplateDatabase.getTemplateDocument(key);
            }
            catch (TemplateDatabase.TemplateException e) {
                // No Template with this name has been defined.
                defaultName = name;
            }
        } while (defaultName == null);

        namespaceField.addItem(nsDefault);
        namespaceField.setSelectedItem(nsDefault);
        namespaceField.setEditable(true);
        nameField.setPreferredSize(
            new Dimension(160, namespaceField.getPreferredSize().height)
        );
        nameField.getEditor().selectAll();
       
        nameField.addItem(defaultName);
        nameField.setSelectedItem(defaultName);
        nameField.setEditable(true);
        nameField.setPreferredSize(
            new Dimension(160, nameField.getPreferredSize().height)
        );
        nameField.getEditor().selectAll();

        Box messageBox = Box.createVerticalBox();
        messageBox.add(textGrid);
        messageBox.add(defaultBox);
        messageBox.add(Box.createVerticalStrut(8));
        if (selector != null) {
            messageBox.add(selector);
        }
        // We use our own OK button, instead of the one generated by
        // JOptionPane, so we can set it to be the default button for the
        // dialog.
        JButton okButton = new JButton(LOCALE.get("TemplateSaveOption"));
        JButton cancelButton = new JButton(LOCALE.get("TemplateCancelOption"));
        JOptionPane pane = new JOptionPane(
            messageBox,
            JOptionPane.QUESTION_MESSAGE,
            JOptionPane.OK_CANCEL_OPTION,
            null,
            new Object[] { okButton, cancelButton },
            null
        );
        // Set a minimum width for the dialog.
        Dimension size = pane.getPreferredSize();
        size = new Dimension(Math.max(size.width, 400), size.height);
        pane.setPreferredSize(size);

        // Use a custom dialog instead of the JOptionPane showXxxDialog()
        // methods so that we can set the initial focus on the combo box
        // instead of the OK button.
        final JDialog dialog = new JDialog(parent);
        dialog.setTitle(LOCALE.get("TemplateSaveDialogTitle"));
        dialog.setContentPane(pane);
        dialog.getRootPane().setDefaultButton(okButton);

        // This causes the dialog to go away when the user presses "ESCAPE".
        pane.registerKeyboardAction(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    dialog.setVisible(false);
                }
            },
            KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW
        );
        // This causes the dialog to go away when the user clicks "OK".
        okButton.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {

                    // In case this happens while the combo box editor is
                    // active, commit the current text to the combo box model:
                    ComboBoxEditor editor = nameField.getEditor();
                    JTextField text = (JTextField) editor.getEditorComponent();
                    String name = text.getText();
                    nameField.setSelectedItem(name);

                    isOkSelected = true;
                    dialog.setVisible(false);
                }
            }
        );
        // This causes the dialog to go away when the user clicks "Cancel".
        cancelButton.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent event) {
                    dialog.setVisible(false);
                }
            }
        );
        dialog.setModal(true);
        dialog.setResizable(true);
        dialog.pack();
        dialog.setLocationRelativeTo(parent);

        dialog.setVisible(true);

        isDefaultSelected = defaultCheck.isSelected();

        if (! isOkSelected) {
            // The dialog was disposed, or the user clicked Cancel.
            return null;
        }
        if (nameField.getEditor().getEditorComponent().isFocusOwner()) {
            KeyboardFocusManager focus =
                KeyboardFocusManager.getCurrentKeyboardFocusManager();
            focus.upFocusCycle();
        }
        return new TemplateKey(getNamespaceText(), getNameText());
    }
View Full Code Here

                    );
                    if (option == 0) {
                        try {
                            InputStream in = new FileInputStream(file);
                            XmlDocument template = new XmlDocument(in);
                            TemplateKey key = TemplateKey.importKey(file);
                            TemplateDatabase.addTemplateDocument(
                                template, key, true
                            );
                            TemplateList.showDialog(frame);
                        }
                        catch (Throwable t) {
                            showError(
                                LOCALE.get(
                                    "TemplateImportError", file.getName()
                                ),
                                t, frame
                            );
                        }
                        return null;
                    }
                    else if (option == 2) {
                        return null;
                    }
                    // option == 1, let the initialization continue...
                }
                // LightweightDocument couldn't figure out the original image
                // path, so let Document throw its MissingImageFileException:
                doc = new Document(xml, null, info, cancel);
            }
            else {
                // Check for a missing image file:
                boolean hunted = false;
                if (! imageFile.exists()) {
                    // Isolate the image file name, admitting both unix and
                    // windows path syntax:
                    String imageFileName =
                        imageFile.getAbsolutePath().replaceAll(
                            ".*[/\\\\]", ""
                        );
                    // Try the DocumentDatabase:
                    File[] files =
                        DocumentDatabase.findImageFiles(imageFileName);

                    // Maybe check the Document file's directory directly,
                    // since DocumentDatabase is sometimes disabled:
                    if (files.length == 0) {
                        File docDir = file.getParentFile();
                        File altImageFile = new File(docDir, imageFileName);
                        if (altImageFile.isFile()) {
                            files = new File[1];
                            files[0] = altImageFile;
                        }
                    }
                    imageFile = DocumentImageSelector.chooseImageFile(
                        file, imageFile, files, LastOpenPath, frame
                    );
                    if (imageFile == null) {
                        // User cancelled.
                        return null;
                    }
                    hunted = true;
                }
                ImageInfo imageFileInfo = ImageInfo.getInstanceFor(imageFile);
                ImageMetadata meta = imageFileInfo.getMetadata();

                // Read the saved document:
                doc = new Document(xml, meta, info, cancel);
                if (hunted) {
                    doc.markDirty();
                }
            }
            DocumentDatabase.addDocumentFile(file);
        }
        else {
            // Maybe it's an image:
            ImageInfo info = ImageInfo.getInstanceFor(file);
            ImageMetadata meta = info.getMetadata();
            ImageType type = info.getImageType();

            // Maybe set up a template with default tools:
            XmlDocument xml = null;

            // First look for default settings in the user-defined templates:
            TemplateKey template = TemplateDatabase.getDefaultTemplate(meta);
            if (template != null) {
                try {
                    xml = TemplateDatabase.getTemplateDocument(template);
                }
                catch (TemplateDatabase.TemplateException e) {
View Full Code Here

            // Maybe set up a template with default tools:
            XmlDocument xml = null;

            // First look for default settings in the user-defined templates:
            TemplateKey template = TemplateDatabase.getDefaultTemplate(meta);
            if (template != null) {
                try {
                    xml = TemplateDatabase.getTemplateDocument(template);
                }
                catch (TemplateDatabase.TemplateException e) {
View Full Code Here

        if (doc == null) {
            return null;
        }
        // Loop until a unique name is selected or the dialog is cancelled:
        boolean done = false;
        TemplateKey key;
        do {
            XmlDocument xml = new XmlDocument("Template")// See Document()
            XmlNode root = xml.getRoot();
            doc.saveTemplate(root);

            SaveTemplateDialog dialog = new SaveTemplateDialog();
            ImageMetadata meta = doc.getMetadata();
            key = dialog.showDialog(meta, xml, namespace, frame);
            if (key == null) {
                // Dialog was disposed, or the user cancelled.
                return null;
            }
            // First check if a template with this name already exists:
            XmlDocument conflict = null;
            try {
                conflict = TemplateDatabase.getTemplateDocument(key);
            }
            catch (TemplateDatabase.TemplateException e) {
                // Interpret as no preexisting template with this name.
            }
            if (conflict != null) {
                int replace = Env.getAlertDialog().showAlert(
                    frame,
                    LOCALE.get("TemplateClobberQuestionMajor", key.toString()),
                    LOCALE.get("TemplateClobberQuestionMinor"),
                    AlertDialog.WARNING_ALERT,
                    LOCALE.get("TemplateClobberReplaceOption"),
                    LOCALE.get("TemplateClobberCancelOption")
                );
View Full Code Here

        updateTitle();
    }

    public void addTemplate() {
        String namespace = templates.getNamespace();
        TemplateKey key = Application.saveTemplate(ComboFrame.this, namespace);
        if (key != null) {
            namespace = key.getNamespace();
            templates.setNamespace(namespace);
        }
    }
View Full Code Here

TOP

Related Classes of com.lightcrafts.templates.TemplateKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.