Search in sources :

Example 1 with LayoutBuilder

use of org.gephi.layout.spi.LayoutBuilder in project gephi by gephi.

the class LayoutModelImpl method readXML.

public void readXML(XMLStreamReader reader) throws XMLStreamException {
    boolean end = false;
    LayoutPropertyKey key = null;
    String valueClassStr = null;
    String selectedLayoutBuilderClass = null;
    while (reader.hasNext() && !end) {
        Integer eventType = reader.next();
        if (eventType.equals(XMLEvent.START_ELEMENT)) {
            String name = reader.getLocalName();
            if ("property".equalsIgnoreCase(name)) {
                key = new LayoutPropertyKey(reader.getAttributeValue(null, "property"), reader.getAttributeValue(null, "layout"));
                valueClassStr = reader.getAttributeValue(null, "class");
            } else if ("selectedlayoutbuilder".equalsIgnoreCase(name)) {
                selectedLayoutBuilderClass = reader.getAttributeValue(null, "class");
            }
        } else if (eventType.equals(XMLEvent.CHARACTERS)) {
            if (key != null && !reader.isWhiteSpace()) {
                Object value = parse(valueClassStr, reader.getText());
                if (value != null) {
                    savedProperties.put(key, value);
                }
            }
        } else if (eventType.equals(XMLStreamReader.END_ELEMENT)) {
            key = null;
            if ("layoutmodel".equalsIgnoreCase(reader.getLocalName())) {
                end = true;
            }
        }
    }
    //Try to retrieve selected layout and make it the currently selected layout (after reading saved properties)
    if (selectedLayoutBuilderClass != null) {
        for (LayoutBuilder builder : Lookup.getDefault().lookupAll(LayoutBuilder.class)) {
            if (builder.getClass().getName().equals(selectedLayoutBuilderClass)) {
                setSelectedLayout(builder.buildLayout());
                break;
            }
        }
    }
}
Also used : LayoutBuilder(org.gephi.layout.spi.LayoutBuilder)

Example 2 with LayoutBuilder

use of org.gephi.layout.spi.LayoutBuilder in project gephi by gephi.

the class LayoutPanel method initEvents.

private void initEvents() {
    layoutCombobox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (layoutCombobox.getSelectedItem().equals(NO_SELECTION) && model.getSelectedLayout() != null) {
                setSelectedLayout(null);
            } else if (layoutCombobox.getSelectedItem() instanceof LayoutBuilderWrapper) {
                LayoutBuilder builder = ((LayoutBuilderWrapper) layoutCombobox.getSelectedItem()).getLayoutBuilder();
                if (model.getSelectedLayout() == null || model.getSelectedBuilder() != builder) {
                    setSelectedLayout(builder);
                }
            }
        }
    });
    infoLabel.addMouseListener(new MouseAdapter() {

        RichTooltip richTooltip;

        @Override
        public void mouseEntered(MouseEvent e) {
            if (infoLabel.isEnabled() && model != null && model.getSelectedLayout() != null) {
                richTooltip = buildTooltip(model.getSelectedBuilder());
                richTooltip.showTooltip(infoLabel, e.getLocationOnScreen());
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
            if (richTooltip != null) {
                richTooltip.hideTooltip();
                richTooltip = null;
            }
        }
    });
    presetsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JPopupMenu menu = new JPopupMenu();
            List<Preset> presets = layoutPresetPersistence.getPresets(model.getSelectedLayout());
            if (presets != null && !presets.isEmpty()) {
                for (final Preset p : presets) {
                    JMenuItem item = new JMenuItem(p.toString());
                    item.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            layoutPresetPersistence.loadPreset(p, model.getSelectedLayout());
                            refreshProperties();
                            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.status.loadPreset", model.getSelectedBuilder().getName(), p.toString()));
                        }
                    });
                    menu.add(item);
                }
            } else {
                menu.add("<html><i>" + NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.nopreset") + "</i></html>");
            }
            JMenuItem saveItem = new JMenuItem(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset"));
            saveItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    String lastPresetName = NbPreferences.forModule(LayoutPanel.class).get("LayoutPanel.lastPresetName", "");
                    NotifyDescriptor.InputLine question = new NotifyDescriptor.InputLine(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset.input"), NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset.input.name"));
                    question.setInputText(lastPresetName);
                    if (DialogDisplayer.getDefault().notify(question) == NotifyDescriptor.OK_OPTION) {
                        String input = question.getInputText();
                        if (input != null && !input.isEmpty()) {
                            layoutPresetPersistence.savePreset(input, model.getSelectedLayout());
                            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.status.savePreset", model.getSelectedBuilder().getName(), input));
                            NbPreferences.forModule(LayoutPanel.class).put("LayoutPanel.lastPresetName", input);
                        }
                    }
                }
            });
            menu.add(new JSeparator());
            menu.add(saveItem);
            menu.show(layoutToolbar, 0, -menu.getPreferredSize().height);
        }
    });
}
Also used : LayoutBuilder(org.gephi.layout.spi.LayoutBuilder) ItemEvent(java.awt.event.ItemEvent) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) Preset(org.gephi.desktop.layout.LayoutPresetPersistence.Preset) MouseAdapter(java.awt.event.MouseAdapter) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator) NotifyDescriptor(org.openide.NotifyDescriptor) RichTooltip(org.gephi.ui.components.richtooltip.RichTooltip) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener) ArrayList(java.util.ArrayList) List(java.util.List) JMenuItem(javax.swing.JMenuItem)

Example 3 with LayoutBuilder

use of org.gephi.layout.spi.LayoutBuilder in project gephi by gephi.

the class LayoutPanel method refreshChooser.

private void refreshChooser() {
    DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
    comboBoxModel.addElement(NO_SELECTION);
    comboBoxModel.setSelectedItem(NO_SELECTION);
    if (model != null) {
        List<LayoutBuilder> builders = new ArrayList<>(Lookup.getDefault().lookupAll(LayoutBuilder.class));
        Collections.sort(builders, new Comparator() {

            @Override
            public int compare(Object o1, Object o2) {
                return ((LayoutBuilder) o1).getName().compareTo(((LayoutBuilder) o2).getName());
            }
        });
        for (LayoutBuilder builder : builders) {
            LayoutBuilderWrapper item = new LayoutBuilderWrapper(builder);
            comboBoxModel.addElement(item);
            if (model.getSelectedLayout() != null && builder == model.getSelectedBuilder()) {
                comboBoxModel.setSelectedItem(item);
            }
        }
    }
    layoutCombobox.setModel(comboBoxModel);
    if (model != null) {
        layoutCombobox.setEnabled(!model.isRunning());
    }
}
Also used : LayoutBuilder(org.gephi.layout.spi.LayoutBuilder) ArrayList(java.util.ArrayList) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Comparator(java.util.Comparator)

Aggregations

LayoutBuilder (org.gephi.layout.spi.LayoutBuilder)3 ArrayList (java.util.ArrayList)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 Comparator (java.util.Comparator)1 List (java.util.List)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 JSeparator (javax.swing.JSeparator)1 Preset (org.gephi.desktop.layout.LayoutPresetPersistence.Preset)1 RichTooltip (org.gephi.ui.components.richtooltip.RichTooltip)1 NotifyDescriptor (org.openide.NotifyDescriptor)1