Search in sources :

Example 11 with MindMapPanelConfig

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;
}
Also used : KeyShortcut(com.igormaznitsa.mindmap.swing.panel.utils.KeyShortcut) RenderQuality(com.igormaznitsa.mindmap.swing.panel.utils.RenderQuality) MindMapPanelConfig(com.igormaznitsa.mindmap.swing.panel.MindMapPanelConfig)

Example 12 with MindMapPanelConfig

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);
            }
        }
    }
}
Also used : HasOptions(com.igormaznitsa.mindmap.plugins.api.HasOptions) RenderedImage(java.awt.image.RenderedImage) MindMapPanelConfig(com.igormaznitsa.mindmap.swing.panel.MindMapPanelConfig)

Example 13 with MindMapPanelConfig

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);
            }
        }
    }
}
Also used : MindMap(com.igormaznitsa.mindmap.model.MindMap) MMGraphics(com.igormaznitsa.mindmap.swing.panel.ui.gfx.MMGraphics) MindMapPanelConfig(com.igormaznitsa.mindmap.swing.panel.MindMapPanelConfig) BufferedImage(java.awt.image.BufferedImage) HasOptions(com.igormaznitsa.mindmap.plugins.api.HasOptions)

Aggregations

MindMapPanelConfig (com.igormaznitsa.mindmap.swing.panel.MindMapPanelConfig)13 PropertiesPreferences (com.igormaznitsa.mindmap.swing.panel.utils.PropertiesPreferences)6 File (java.io.File)3 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 HasOptions (com.igormaznitsa.mindmap.plugins.api.HasOptions)2 MindMap (com.igormaznitsa.mindmap.model.MindMap)1 AbstractExporter (com.igormaznitsa.mindmap.plugins.api.AbstractExporter)1 AbstractImporter (com.igormaznitsa.mindmap.plugins.api.AbstractImporter)1 MindMapConfigListener (com.igormaznitsa.mindmap.swing.panel.MindMapConfigListener)1 MindMapPanel (com.igormaznitsa.mindmap.swing.panel.MindMapPanel)1 MMGraphics (com.igormaznitsa.mindmap.swing.panel.ui.gfx.MMGraphics)1 KeyShortcut (com.igormaznitsa.mindmap.swing.panel.utils.KeyShortcut)1 RenderQuality (com.igormaznitsa.mindmap.swing.panel.utils.RenderQuality)1 Point (java.awt.Point)1 BufferedImage (java.awt.image.BufferedImage)1 RenderedImage (java.awt.image.RenderedImage)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Properties (java.util.Properties)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1