use of com.igormaznitsa.mindmap.model.Topic in project netbeans-mmd-plugin by raydac.
the class MindMapTreeCellRenderer method getTreeCellRendererComponent.
@Override
public Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean sel, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
final DefaultTreeCellRenderer result = (DefaultTreeCellRenderer) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (value instanceof Topic) {
result.setIcon(getIconForTopic((Topic) value));
result.setText(extractTextFromTopic((Topic) value));
}
return result;
}
use of com.igormaznitsa.mindmap.model.Topic in project netbeans-mmd-plugin by raydac.
the class ExplorerTree method addChildTo.
private void addChildTo(@Nonnull final NodeFileOrFolder folder, @Nullable final String extension) {
String fileName = JOptionPane.showInputDialog(Main.getApplicationFrame(), extension == null ? "Folder name" : "File name", extension == null ? "New folder" : "New " + extension.toUpperCase(Locale.ENGLISH) + " file", JOptionPane.QUESTION_MESSAGE);
if (fileName != null) {
fileName = fileName.trim();
if (NodeProjectGroup.FILE_NAME.matcher(fileName).matches()) {
if (extension != null) {
final String providedExtension = FilenameUtils.getExtension(fileName);
if (!extension.equalsIgnoreCase(providedExtension)) {
fileName += '.' + extension;
}
}
final File file = new File(folder.makeFileForNode(), fileName);
if (file.exists()) {
DialogProviderManager.getInstance().getDialogProvider().msgError(null, "File '" + fileName + "' already exists!");
return;
}
boolean ok = false;
if (extension == null) {
if (!file.mkdirs()) {
// NOI18N
LOGGER.error("Can't create folder");
DialogProviderManager.getInstance().getDialogProvider().msgError(null, "Can't create folder '" + fileName + "'!");
} else {
ok = true;
}
} else {
switch(extension) {
case "mmd":
{
// NOI18N
final MindMap model = new MindMap(null, true);
// NOI18N
model.setAttribute("showJumps", "true");
final Topic root = model.getRoot();
if (root != null) {
// NOI18N
root.setText("Root");
}
try {
// NOI18N
FileUtils.write(file, model.write(new StringWriter()).toString(), "UTF-8");
ok = true;
} catch (IOException ex) {
// NOI18N
LOGGER.error("Can't create MMD file", ex);
DialogProviderManager.getInstance().getDialogProvider().msgError(null, "Can't create mind map '" + fileName + "'!");
}
}
break;
case "puml":
{
// NOI18N
final String nextLine = GetUtils.ensureNonNull(System.getProperty("line.separator"), "\n");
final String text = "@startuml" + nextLine + nextLine + "@enduml";
try {
// NOI18N
FileUtils.write(file, text, "UTF-8");
ok = true;
} catch (IOException ex) {
// NOI18N
LOGGER.error("Can't create PUML file", ex);
DialogProviderManager.getInstance().getDialogProvider().msgError(null, "Can't create puml file '" + fileName + "'!");
}
}
break;
case "txt":
{
// NOI18N
try {
// NOI18N
FileUtils.write(file, "", "UTF-8");
ok = true;
} catch (IOException ex) {
// NOI18N
LOGGER.error("Can't create TXT file", ex);
DialogProviderManager.getInstance().getDialogProvider().msgError(null, "Can't create txt file '" + fileName + "'!");
}
}
break;
default:
// NOI18N
throw new Error("Unexpected extension : " + extension);
}
}
if (ok) {
getCurrentGroup().addChild(folder, file);
context.openFileAsTab(file);
context.focusInTree(file);
}
} else {
DialogProviderManager.getInstance().getDialogProvider().msgError(null, "Illegal file name!");
}
}
}
use of com.igormaznitsa.mindmap.model.Topic in project netbeans-mmd-plugin by raydac.
the class AbstractCollapsableElement method alignElementAndChildren.
@Override
public void alignElementAndChildren(@Nonnull final MindMapPanelConfig cfg, final boolean leftSide, final double leftX, final double topY) {
super.alignElementAndChildren(cfg, leftSide, leftX, topY);
final double horzInset = cfg.getOtherLevelHorizontalInset() * cfg.getScale();
double childrenX;
final double COLLAPSATORSIZE = cfg.getCollapsatorSize() * cfg.getScale();
final double COLLAPSATORDISTANCE = cfg.getCollapsatorSize() * 0.1d * cfg.getScale();
final double collapsatorX;
if (leftSide) {
childrenX = leftX + this.blockSize.getWidth() - this.bounds.getWidth();
this.moveTo(childrenX, topY + (this.blockSize.getHeight() - this.bounds.getHeight()) / 2);
childrenX -= horzInset;
collapsatorX = -COLLAPSATORSIZE - COLLAPSATORDISTANCE;
} else {
childrenX = leftX;
this.moveTo(childrenX, topY + (this.blockSize.getHeight() - this.bounds.getHeight()) / 2);
childrenX += this.bounds.getWidth() + horzInset;
collapsatorX = this.bounds.getWidth() + COLLAPSATORDISTANCE;
}
this.collapsatorZone.setRect(collapsatorX, (this.bounds.getHeight() - COLLAPSATORSIZE) / 2, COLLAPSATORSIZE, COLLAPSATORSIZE);
if (!this.isCollapsed()) {
final double vertInset = cfg.getOtherLevelVerticalInset() * cfg.getScale();
final Dimension2D childBlockSize = calcBlockSize(cfg, null, true);
double currentY = topY + (this.blockSize.getHeight() - childBlockSize.getHeight()) / 2.0d;
boolean notFirstChild = false;
for (final Topic t : this.model.getChildren()) {
if (notFirstChild) {
currentY += vertInset;
} else {
notFirstChild = true;
}
final AbstractElement w = (AbstractElement) assertNotNull(t.getPayload());
w.alignElementAndChildren(cfg, leftSide, leftSide ? childrenX - w.getBlockSize().getWidth() : childrenX, currentY);
currentY += w.getBlockSize().getHeight();
}
}
}
use of com.igormaznitsa.mindmap.model.Topic in project netbeans-mmd-plugin by raydac.
the class AbstractCollapsableElement method doPaintConnectors.
@Override
public void doPaintConnectors(@Nonnull final MMGraphics g, final boolean leftDirection, @Nonnull final MindMapPanelConfig cfg) {
final Rectangle2D source = new Rectangle2D.Double(this.bounds.getX() + this.collapsatorZone.getX(), this.bounds.getY() + this.collapsatorZone.getY(), this.collapsatorZone.getWidth(), this.collapsatorZone.getHeight());
final boolean lefDir = isLeftDirection();
for (final Topic t : this.model.getChildren()) {
this.drawConnector(g, source, (assertNotNull((AbstractElement) t.getPayload())).getBounds(), lefDir, cfg);
}
}
use of com.igormaznitsa.mindmap.model.Topic in project netbeans-mmd-plugin by raydac.
the class AbstractCollapsableElement method calcBlockSize.
@Override
@Nonnull
public Dimension2D calcBlockSize(@Nonnull final MindMapPanelConfig cfg, @Nullable final Dimension2D size, final boolean childrenOnly) {
final Dimension2D result = size == null ? new Dimension() : size;
final double scaledVInset = cfg.getScale() * cfg.getOtherLevelVerticalInset();
final double scaledHInset = cfg.getScale() * cfg.getOtherLevelHorizontalInset();
double width = childrenOnly ? 0.0d : this.bounds.getWidth();
double height = childrenOnly ? 0.0d : this.bounds.getHeight();
if (this.hasChildren()) {
if (!this.isCollapsed()) {
width += childrenOnly ? 0.0d : scaledHInset;
final double baseWidth = childrenOnly ? 0.0d : width;
double childrenHeight = 0.0d;
boolean notFirstChiild = false;
for (final Topic t : this.model.getChildren()) {
if (notFirstChiild) {
childrenHeight += scaledVInset;
} else {
notFirstChiild = true;
}
((AbstractElement) assertNotNull(t.getPayload())).calcBlockSize(cfg, result, false);
width = Math.max(baseWidth + result.getWidth(), width);
childrenHeight += result.getHeight();
}
height = Math.max(height, childrenHeight);
} else if (!childrenOnly) {
width += cfg.getCollapsatorSize() * cfg.getScale();
}
}
result.setSize(width, height);
return result;
}
Aggregations