use of com.igormaznitsa.mindmap.swing.panel.MindMapPanelConfig in project netbeans-mmd-plugin by raydac.
the class MindMapSettingsPanel method makeConfig.
public MindMapPanelConfig makeConfig() {
final MindMapPanelConfig result = new MindMapPanelConfig(this.etalon, false);
result.setPaperColor(this.colorButtonBackgroundColor.getValue());
result.setGridColor(this.colorButtonGridColor.getValue());
result.setCollapsatorBackgroundColor(this.colorButtonCollapsatorFill.getValue());
result.setCollapsatorBorderColor(this.colorButtonCollapsatorBorder.getValue());
result.setConnectorColor(this.colorButtonConnectorColor.getValue());
result.setJumpLinkColor(this.colorButtonJumpLink.getValue());
result.setSelectLineColor(this.colorButtonSelectFrameColor.getValue());
result.setRootBackgroundColor(this.colorButtonRootFill.getValue());
result.setRootTextColor(this.colorButtonRootText.getValue());
result.setFirstLevelBackgroundColor(this.colorButton1stLevelFill.getValue());
result.setFirstLevelTextColor(this.colorButton1stLevelText.getValue());
result.setOtherLevelBackgroundColor(this.colorButton2ndLevelFill.getValue());
result.setOtherLevelTextColor(this.colorButton2ndLevelText.getValue());
result.setGridStep(getInt(this.spinnerGridStep));
result.setConnectorWidth(getFloat(this.spinnerConnectorWidth));
result.setCollapsatorSize(getInt(this.spinnerCollapsatorSize));
result.setCollapsatorBorderWidth(getFloat(this.spinnerCollapsatorWidth));
result.setJumpLinkWidth(getFloat(this.spinnerJumpLinkWidth));
result.setSelectLineWidth(getFloat(this.spinnerSelectionFrameWidth));
result.setSelectLineGap(getInt(this.spinnerSelectionFrameGap));
result.setElementBorderWidth(getFloat(this.spinnerBorderWidth));
result.setShowGrid(this.checkBoxShowGrid.isSelected());
result.setDropShadow(this.checkBoxDropShadow.isSelected());
result.setFirstLevelHorizontalInset(this.slider1stLevelHorzGap.getValue());
result.setFirstLevelVerticalInset(this.slider1stLevelVertGap.getValue());
result.setOtherLevelHorizontalInset(this.slider2ndLevelHorzGap.getValue());
result.setOtherLevelVerticalInset(this.slider2ndLevelVertGap.getValue());
result.setRenderQuality(GetUtils.ensureNonNull((RenderQuality) comboBoxRenderQuality.getSelectedItem(), RenderQuality.DEFAULT));
result.setFont(this.theFont);
final int scaleModifier = (this.checkBoxScalingModifierALT.isSelected() ? KeyEvent.ALT_MASK : 0) | (this.checkBoxScalingModifierCTRL.isSelected() ? KeyEvent.CTRL_MASK : 0) | (this.checkBoxScalingModifierSHFT.isSelected() ? KeyEvent.SHIFT_MASK : 0) | (this.checkBoxScalingModifierMETA.isSelected() ? KeyEvent.META_MASK : 0);
result.setScaleModifiers(scaleModifier);
for (final Map.Entry<String, KeyShortcut> e : this.mapKeyShortCuts.entrySet()) {
result.setKeyShortCut(e.getValue());
}
return result;
}
use of com.igormaznitsa.mindmap.swing.panel.MindMapPanelConfig in project netbeans-mmd-plugin by raydac.
the class PNGImageExporter method doExport.
@Override
public void doExport(@Nonnull final MindMapPanel panel, @Nullable final JComponent options, @Nullable final OutputStream out) throws IOException {
if (options instanceof HasOptions) {
final HasOptions opts = (HasOptions) options;
this.flagExpandAllNodes = Boolean.parseBoolean(opts.getOption(Options.KEY_EXPAND_ALL));
this.flagDrawBackground = Boolean.parseBoolean(opts.getOption(Options.KEY_DRAW_BACK));
} else {
for (final Component compo : Assertions.assertNotNull(options).getComponents()) {
if (compo instanceof JCheckBox) {
final JCheckBox cb = (JCheckBox) compo;
if ("unfold".equalsIgnoreCase(cb.getActionCommand())) {
this.flagExpandAllNodes = cb.isSelected();
} else if ("back".equalsIgnoreCase(cb.getActionCommand())) {
this.flagDrawBackground = cb.isSelected();
}
}
}
}
final MindMapPanelConfig newConfig = new MindMapPanelConfig(panel.getConfiguration(), false);
newConfig.setDrawBackground(this.flagDrawBackground);
newConfig.setScale(1.0f);
final RenderedImage image = MindMapPanel.renderMindMapAsImage(panel.getModel(), newConfig, flagExpandAllNodes, RenderQuality.QUALITY);
if (image == null) {
if (out == null) {
LOGGER.error("Can't render map as image");
panel.getController().getDialogProvider(panel).msgError(null, Texts.getString("PNGImageExporter.msgErrorDuringRendering"));
return;
} else {
throw new IOException("Can't render image");
}
}
final ByteArrayOutputStream buff = new ByteArrayOutputStream(128000);
// NOI18N
ImageIO.write(image, "png", buff);
final byte[] imageData = buff.toByteArray();
File fileToSaveMap = null;
OutputStream theOut = out;
if (theOut == null) {
fileToSaveMap = MindMapUtils.selectFileToSaveForFileFilter(panel, Texts.getString("PNGImageExporter.saveDialogTitle"), ".png", Texts.getString("PNGImageExporter.filterDescription"), Texts.getString("PNGImageExporter.approveButtonText"));
// NOI18N
fileToSaveMap = MindMapUtils.checkFileAndExtension(panel, fileToSaveMap, ".png");
theOut = fileToSaveMap == null ? null : new BufferedOutputStream(new FileOutputStream(fileToSaveMap, false));
}
if (theOut != null) {
try {
IOUtils.write(imageData, theOut);
} finally {
if (fileToSaveMap != null) {
IOUtils.closeQuietly(theOut);
}
}
}
}
use of com.igormaznitsa.mindmap.swing.panel.MindMapPanelConfig in project netbeans-mmd-plugin by raydac.
the class SVGImageExporter method doExport.
@Override
public void doExport(@Nonnull final MindMapPanel panel, @Nullable final JComponent options, @Nullable final OutputStream out) throws IOException {
if (options instanceof HasOptions) {
final HasOptions opts = (HasOptions) options;
this.flagExpandAllNodes = Boolean.parseBoolean(opts.getOption(Options.KEY_EXPAND_ALL));
this.flagDrawBackground = Boolean.parseBoolean(opts.getOption(Options.KEY_DRAW_BACK));
} else {
for (final Component compo : Assertions.assertNotNull(options).getComponents()) {
if (compo instanceof JCheckBox) {
final JCheckBox cb = (JCheckBox) compo;
if ("unfold".equalsIgnoreCase(cb.getActionCommand())) {
this.flagExpandAllNodes = cb.isSelected();
} else if ("back".equalsIgnoreCase(cb.getActionCommand())) {
this.flagDrawBackground = cb.isSelected();
}
}
}
}
final MindMap workMap = new MindMap(panel.getModel(), null);
workMap.resetPayload();
if (this.flagExpandAllNodes) {
MindMapUtils.removeCollapseAttr(workMap);
}
final MindMapPanelConfig newConfig = new MindMapPanelConfig(panel.getConfiguration(), false);
newConfig.setDrawBackground(this.flagDrawBackground);
newConfig.setScale(1.0f);
final Dimension2D blockSize = calculateSizeOfMapInPixels(workMap, null, newConfig, flagExpandAllNodes, RenderQuality.DEFAULT);
if (blockSize == null) {
return;
}
final StringBuilder buffer = new StringBuilder(16384);
buffer.append(String.format(SVG_HEADER, 100, 100, dbl2str(blockSize.getWidth()), dbl2str(blockSize.getHeight()))).append(NEXT_LINE);
final BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);
final Graphics2D g = image.createGraphics();
final MMGraphics gfx = new SVGMMGraphics(buffer, g);
gfx.setClip(0, 0, (int) Math.round(blockSize.getWidth()), (int) Math.round(blockSize.getHeight()));
try {
layoutFullDiagramWithCenteringToPaper(gfx, workMap, newConfig, blockSize);
drawOnGraphicsForConfiguration(gfx, newConfig, workMap, false, null);
} finally {
gfx.dispose();
}
buffer.append("</svg>");
final String text = buffer.toString();
File fileToSaveMap = null;
OutputStream theOut = out;
if (theOut == null) {
fileToSaveMap = MindMapUtils.selectFileToSaveForFileFilter(panel, Texts.getString("SvgExporter.saveDialogTitle"), ".svg", Texts.getString("SvgExporter.filterDescription"), Texts.getString("SvgExporter.approveButtonText"));
// NOI18N
fileToSaveMap = MindMapUtils.checkFileAndExtension(panel, fileToSaveMap, ".svg");
theOut = fileToSaveMap == null ? null : new BufferedOutputStream(new FileOutputStream(fileToSaveMap, false));
}
if (theOut != null) {
try {
IOUtils.write(text, theOut, "UTF-8");
} finally {
if (fileToSaveMap != null) {
IOUtils.closeQuietly(theOut);
}
}
}
}
Aggregations