Search in sources :

Example 1 with AbstractElement

use of com.igormaznitsa.mindmap.swing.panel.ui.AbstractElement in project netbeans-mmd-plugin by raydac.

the class MMDGraphEditor method topicToCentre.

public boolean topicToCentre(@Nullable Topic topic) {
    boolean result = false;
    assertSwingDispatchThread();
    if (topic != null) {
        // to make it sure that topic is from the same model
        topic = this.mindMapPanel.getModel().findForPositionPath(topic.getPositionPath());
        if (topic != null) {
            AbstractElement element = (AbstractElement) topic.getPayload();
            if (element == null && this.mindMapPanel.updateElementsAndSizeForCurrentGraphics(true, true)) {
                element = (AbstractElement) topic.getPayload();
                this.mainScrollPane.getViewport().doLayout();
            }
            if (element != null) {
                final Rectangle2D bounds = element.getBounds();
                final Dimension viewPortSize = mainScrollPane.getViewport().getExtentSize();
                final int x = Math.max(0, (int) Math.round(bounds.getX() - (viewPortSize.getWidth() - bounds.getWidth()) / 2));
                final int y = Math.max(0, (int) Math.round(bounds.getY() - (viewPortSize.getHeight() - bounds.getHeight()) / 2));
                this.mainScrollPane.getViewport().setViewPosition(new Point(x, y));
                result = true;
            }
        }
    }
    return result;
}
Also used : AbstractElement(com.igormaznitsa.mindmap.swing.panel.ui.AbstractElement) Rectangle2D(java.awt.geom.Rectangle2D) MMDPrint(com.igormaznitsa.mindmap.print.MMDPrint)

Example 2 with AbstractElement

use of com.igormaznitsa.mindmap.swing.panel.ui.AbstractElement in project netbeans-mmd-plugin by raydac.

the class Utils method renderWithTransparency.

@Nonnull
public static Image renderWithTransparency(final float opacity, @Nonnull final AbstractElement element, @Nonnull final MindMapPanelConfig config, @Nonnull final RenderQuality quality) {
    final AbstractElement cloned = element.makeCopy();
    final Rectangle2D bounds = cloned.getBounds();
    final float increase = config.safeScaleFloatValue(config.getElementBorderWidth() + config.getShadowOffset(), 0.0f);
    final int imageWidth = (int) Math.round(bounds.getWidth() + increase);
    final int imageHeight = (int) Math.round(bounds.getHeight() + increase);
    bounds.setRect(0.0d, 0.0d, bounds.getWidth(), bounds.getHeight());
    final BufferedImage result = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB);
    for (int y = 0; y < imageHeight; y++) {
        for (int x = 0; x < imageWidth; x++) {
            result.setRGB(x, y, 0);
        }
    }
    final Graphics2D g = result.createGraphics();
    final MMGraphics gfx = new MMGraphics2DWrapper(g);
    try {
        quality.prepare(g);
        cloned.doPaint(gfx, config, false);
    } finally {
        gfx.dispose();
    }
    int alpha;
    if (opacity <= 0.0f) {
        alpha = 0x00;
    } else if (opacity >= 1.0f) {
        alpha = 0xFF;
    } else {
        alpha = Math.round(0xFF * opacity);
    }
    alpha <<= 24;
    for (int y = 0; y < imageHeight; y++) {
        for (int x = 0; x < imageWidth; x++) {
            final int curAlpha = result.getRGB(x, y) >>> 24;
            if (curAlpha == 0xFF) {
                result.setRGB(x, y, (result.getRGB(x, y) & 0xFFFFFF) | alpha);
            } else if (curAlpha != 0x00) {
                final int calculated = Math.round(curAlpha * opacity) << 24;
                result.setRGB(x, y, (result.getRGB(x, y) & 0xFFFFFF) | calculated);
            }
        }
    }
    return result;
}
Also used : AbstractElement(com.igormaznitsa.mindmap.swing.panel.ui.AbstractElement) MMGraphics2DWrapper(com.igormaznitsa.mindmap.swing.panel.ui.gfx.MMGraphics2DWrapper) Rectangle2D(java.awt.geom.Rectangle2D) MMGraphics(com.igormaznitsa.mindmap.swing.panel.ui.gfx.MMGraphics) BufferedImage(java.awt.image.BufferedImage) Nonnull(javax.annotation.Nonnull)

Example 3 with AbstractElement

use of com.igormaznitsa.mindmap.swing.panel.ui.AbstractElement in project netbeans-mmd-plugin by raydac.

the class MMDEditor method drop.

@Override
public void drop(@Nonnull final DropTargetDropEvent dtde) {
    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
    File detectedFile;
    String detectedLink;
    String detectedNote;
    URI decodedLink;
    try {
        detectedFile = extractDropFile(dtde);
        detectedLink = DnDUtils.extractDropLink(dtde);
        detectedNote = DnDUtils.extractDropNote(dtde);
        decodedLink = null;
        if (detectedLink != null) {
            try {
                decodedLink = new URI(detectedLink);
            } catch (final URISyntaxException ex) {
                decodedLink = null;
            }
        }
        dtde.dropComplete(true);
    } catch (final Exception ex) {
        // NOI18N
        LOGGER.error("Error during DnD processing", ex);
        dtde.dropComplete(false);
        return;
    }
    final AbstractElement element = this.mindMapPanel.findTopicUnderPoint(dtde.getLocation());
    if (detectedFile != null) {
        decodedLink = DnDUtils.extractUrlLinkFromFile(detectedFile);
        if (decodedLink != null) {
            addURItoElement(decodedLink, element);
        } else {
            addFileToElement(detectedFile, element);
        }
        dtde.dropComplete(true);
    } else if (decodedLink != null) {
        addURItoElement(decodedLink, element);
        dtde.dropComplete(true);
    } else if (detectedNote != null) {
        addNoteToElement(detectedNote, element);
        dtde.dropComplete(true);
    } else {
        dtde.dropComplete(false);
    }
}
Also used : AbstractElement(com.igormaznitsa.mindmap.swing.panel.ui.AbstractElement) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 4 with AbstractElement

use of com.igormaznitsa.mindmap.swing.panel.ui.AbstractElement in project netbeans-mmd-plugin by raydac.

the class MindMapDocumentEditor method drop.

@SuppressWarnings("unchecked")
@Override
public void drop(final DropTargetDropEvent dtde) {
    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
    File dropFile = null;
    String extractedLink;
    String extractedText = null;
    URI decodedLink = null;
    try {
        dropFile = extractDropFile(dtde);
        extractedLink = DnDUtils.extractDropLink(dtde);
        extractedText = DnDUtils.extractDropNote(dtde);
        decodedLink = null;
        if (extractedLink != null) {
            try {
                decodedLink = new URI(extractedLink);
            } catch (final URISyntaxException ex) {
                decodedLink = null;
            }
        }
        dtde.dropComplete(true);
    } catch (Exception ex) {
        LOGGER.error("Can't complete DnD operation for error", ex);
        dtde.dropComplete(false);
    }
    final AbstractElement element = this.mindMapPanel.findTopicUnderPoint(dtde.getLocation());
    if (dropFile != null) {
        decodedLink = DnDUtils.extractUrlLinkFromFile(dropFile);
        if (decodedLink == null) {
            addFileToElement(dropFile, element);
        } else {
            addURItoElement(decodedLink, element);
        }
    } else if (decodedLink != null) {
        addURItoElement(decodedLink, element);
    } else if (extractedText != null) {
        addNoteToElement(extractedText, element);
    }
}
Also used : AbstractElement(com.igormaznitsa.mindmap.swing.panel.ui.AbstractElement) URISyntaxException(java.net.URISyntaxException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 5 with AbstractElement

use of com.igormaznitsa.mindmap.swing.panel.ui.AbstractElement in project netbeans-mmd-plugin by raydac.

the class MMDEditor method topicToCentre.

public boolean topicToCentre(@Nullable final Topic topic) {
    boolean result = false;
    assertSwingDispatchThread();
    if (topic != null) {
        AbstractElement element = (AbstractElement) topic.getPayload();
        if (element == null && this.mindMapPanel.updateElementsAndSizeForCurrentGraphics(true, true)) {
            element = (AbstractElement) topic.getPayload();
            this.scrollPane.getViewport().doLayout();
        }
        if (element != null) {
            final Rectangle2D bounds = element.getBounds();
            final Dimension viewPortSize = this.scrollPane.getViewport().getExtentSize();
            final int x = Math.max(0, (int) Math.round(bounds.getX() - (viewPortSize.getWidth() - bounds.getWidth()) / 2));
            final int y = Math.max(0, (int) Math.round(bounds.getY() - (viewPortSize.getHeight() - bounds.getHeight()) / 2));
            this.scrollPane.getViewport().setViewPosition(new Point(x, y));
            result = true;
        }
    }
    return result;
}
Also used : AbstractElement(com.igormaznitsa.mindmap.swing.panel.ui.AbstractElement) Rectangle2D(java.awt.geom.Rectangle2D)

Aggregations

AbstractElement (com.igormaznitsa.mindmap.swing.panel.ui.AbstractElement)8 Rectangle2D (java.awt.geom.Rectangle2D)4 File (java.io.File)4 URISyntaxException (java.net.URISyntaxException)4 IOException (java.io.IOException)3 URI (java.net.URI)3 Nonnull (javax.annotation.Nonnull)2 MindMap (com.igormaznitsa.mindmap.model.MindMap)1 MindMapController (com.igormaznitsa.mindmap.model.MindMapController)1 Topic (com.igormaznitsa.mindmap.model.Topic)1 HasOptions (com.igormaznitsa.mindmap.plugins.api.HasOptions)1 MMDPrint (com.igormaznitsa.mindmap.print.MMDPrint)1 DialogProvider (com.igormaznitsa.mindmap.swing.panel.DialogProvider)1 MindMapPanel (com.igormaznitsa.mindmap.swing.panel.MindMapPanel)1 MindMapPanelController (com.igormaznitsa.mindmap.swing.panel.MindMapPanelController)1 ElementPart (com.igormaznitsa.mindmap.swing.panel.ui.ElementPart)1 MMGraphics (com.igormaznitsa.mindmap.swing.panel.ui.gfx.MMGraphics)1 MMGraphics2DWrapper (com.igormaznitsa.mindmap.swing.panel.ui.gfx.MMGraphics2DWrapper)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Component (java.awt.Component)1