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;
}
}
}
}
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);
}
});
}
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());
}
}
Aggregations