use of com.igormaznitsa.mindmap.swing.panel.DialogProvider in project netbeans-mmd-plugin by raydac.
the class Main method makeConversion.
private static void makeConversion(@Nonnull final File from, @Nonnull final AbstractImporter fromFormat, @Nonnull final File to, @Nonnull final AbstractExporter toFormat, @Nonnull final MindMapPanelConfig config, @Nonnull final Properties options) throws Exception {
final AtomicReference<Exception> error = new AtomicReference<>();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
try {
final DialogProvider dialog = new DialogProvider() {
@Override
public void msgError(@Nullable final Component parentComponent, @Nonnull final String text) {
LOGGER.error(text);
}
@Override
public void msgInfo(@Nullable final Component parentComponent, @Nonnull final String text) {
LOGGER.info(text);
}
@Override
public void msgWarn(@Nullable final Component parentComponent, @Nonnull final String text) {
LOGGER.warn(text);
}
@Override
public boolean msgConfirmOkCancel(@Nullable final Component parentComponent, @Nonnull final String title, @Nonnull final String question) {
// NOI18N
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean msgOkCancel(@Nullable final Component parentComponent, @Nonnull final String title, @Nonnull final JComponent component) {
// NOI18N
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean msgConfirmYesNo(@Nullable final Component parentComponent, @Nonnull final String title, @Nonnull final String question) {
// NOI18N
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Boolean msgConfirmYesNoCancel(@Nullable final Component parentComponent, @Nonnull final String title, @Nonnull final String question) {
// NOI18N
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public File msgSaveFileDialog(@Nullable final Component parentComponent, @Nonnull final String id, @Nonnull final String title, @Nullable final File defaultFolder, final boolean filesOnly, @Nonnull final FileFilter fileFilter, @Nonnull final String approveButtonText) {
return to;
}
@Override
public File msgOpenFileDialog(@Nullable final Component parentComponent, @Nonnull final String id, @Nonnull final String title, @Nullable final File defaultFolder, final boolean filesOnly, @Nonnull final FileFilter fileFilter, @Nonnull final String approveButtonText) {
return from;
}
};
final MindMapPanel panel = new MindMapPanel(new MindMapPanelController() {
@Override
public boolean isUnfoldCollapsedTopicDropTarget(@Nonnull final MindMapPanel source) {
return false;
}
@Override
public boolean isCopyColorInfoFromParentToNewChildAllowed(@Nonnull final MindMapPanel source) {
return false;
}
@Override
public boolean isTrimTopicTextBeforeSet(@Nonnull final MindMapPanel source) {
return false;
}
@Override
public boolean isSelectionAllowed(@Nonnull final MindMapPanel source) {
return false;
}
@Override
public boolean isElementDragAllowed(@Nonnull final MindMapPanel source) {
return false;
}
@Override
public boolean isMouseMoveProcessingAllowed(@Nonnull final MindMapPanel source) {
return false;
}
@Override
public boolean isMouseWheelProcessingAllowed(@Nonnull final MindMapPanel source) {
return false;
}
@Override
public boolean isMouseClickProcessingAllowed(@Nonnull final MindMapPanel source) {
return false;
}
@Override
@Nonnull
public MindMapPanelConfig provideConfigForMindMapPanel(@Nonnull final MindMapPanel source) {
return config;
}
@Override
@Nullable
public JPopupMenu makePopUpForMindMapPanel(@Nonnull final MindMapPanel source, @Nonnull final Point point, @Nullable final AbstractElement elementUnderMouse, @Nullable final ElementPart elementPartUnderMouse) {
return null;
}
@Override
@Nonnull
public DialogProvider getDialogProvider(@Nonnull final MindMapPanel source) {
return dialog;
}
@Override
public boolean processDropTopicToAnotherTopic(@Nonnull final MindMapPanel source, @Nonnull final Point dropPoint, @Nonnull final Topic draggedTopic, @Nonnull final Topic destinationTopic) {
return false;
}
});
MindMap map = new MindMap(new MindMapController() {
private static final long serialVersionUID = -5276000656494506314L;
@Override
public boolean canBeDeletedSilently(@Nonnull final MindMap map, @Nonnull final Topic topic) {
return true;
}
}, false);
panel.setModel(map);
map = fromFormat.doImport(panel, dialog, null, new Topic[0]);
if (map != null) {
panel.setModel(map);
} else {
dialog.msgError(MAIN_FRAME, "Can't import map");
}
final JComponent optionsComponent = toFormat.makeOptions();
if (!options.isEmpty()) {
if (optionsComponent instanceof HasOptions) {
final HasOptions optionable = (HasOptions) optionsComponent;
for (final String k : options.stringPropertyNames()) {
if (optionable.doesSupportKey(k)) {
optionable.setOption(k, options.getProperty(k));
} else {
// NOI18N
throw new IllegalArgumentException("Exporter " + toFormat.getMnemonic() + " doesn't support option '" + k + "\', it provides options " + Arrays.toString(optionable.getOptionKeys()));
}
}
} else {
// NOI18N
throw new IllegalArgumentException("Exporter " + toFormat.getMnemonic() + " doesn't support options");
}
}
final FileOutputStream result = new FileOutputStream(to, false);
try {
toFormat.doExport(panel, optionsComponent, result);
result.flush();
} finally {
IOUtils.closeQuietly(result);
}
} catch (Exception ex) {
error.set(ex);
}
}
});
if (error.get() != null) {
throw error.get();
}
}
Aggregations