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