use of org.freeplane.features.text.TextController in project freeplane by freeplane.
the class MTextController method editDetails.
public void editDetails(final NodeModel nodeModel, InputEvent e, final boolean editLong) {
final Controller controller = Controller.getCurrentController();
stopEditing();
Controller.getCurrentModeController().setBlocked(true);
String text = DetailTextModel.getDetailTextText(nodeModel);
final boolean isNewNode = text == null;
if (isNewNode) {
final MTextController textController = MTextController.getController();
textController.setDetails(nodeModel, "<html>");
text = "";
}
final EditNodeBase.IEditControl editControl = new EditNodeBase.IEditControl() {
@Override
public void cancel() {
if (isNewNode) {
final String detailText = DetailTextModel.getDetailTextText(nodeModel);
final MModeController modeController = (MModeController) Controller.getCurrentModeController();
if (detailText != null)
modeController.undo();
modeController.resetRedo();
}
stop();
}
@Override
public void ok(final String newText) {
if (HtmlUtils.isEmpty(newText))
if (isNewNode) {
final MModeController modeController = (MModeController) Controller.getCurrentModeController();
modeController.undo();
modeController.resetRedo();
} else {
keepNodePosition();
setDetailsHtmlText(nodeModel, null);
}
else {
keepNodePosition();
setDetailsHtmlText(nodeModel, newText);
}
stop();
}
private void keepNodePosition() {
Controller.getCurrentController().getSelection().keepNodePosition(nodeModel, 0, 0);
}
@Override
public void split(final String newText, final int position) {
}
private void stop() {
Controller.getCurrentModeController().setBlocked(false);
mCurrentEditor = null;
}
@Override
public boolean canSplit() {
return false;
}
@Override
public EditedComponent getEditType() {
return EditedComponent.DETAIL;
}
};
mCurrentEditor = createEditor(nodeModel, editControl, text, false, editLong, true);
final RootPaneContainer frame = (RootPaneContainer) SwingUtilities.getWindowAncestor(controller.getMapViewManager().getMapViewComponent());
mCurrentEditor.show(frame);
}
use of org.freeplane.features.text.TextController in project freeplane by freeplane.
the class SplitToWordsAction method actionPerformed.
@Override
protected void actionPerformed(ActionEvent e, NodeModel node) {
final ModeController modeController = Controller.getCurrentModeController();
MTextController textController = (MTextController) modeController.getExtension(TextController.class);
final MMapController mapController = (MMapController) modeController.getMapController();
String details;
try {
details = textController.getTransformedObject(node).toString();
} catch (TransformationException e1) {
return;
}
String plainText = HtmlUtils.htmlToPlain(details).trim();
int nodeCountInLine;
boolean newNode;
if (leaveOriginalNodeEmpty) {
nodeCountInLine = 0;
newNode = true;
textController.setNodeText(node, "");
} else {
nodeCountInLine = -1;
newNode = false;
}
NodeModel currentNode = node;
final Matcher matcher = compiledWordPattern.matcher(plainText);
while (matcher.find()) {
String word = matcher.group();
final String currentText;
if (newNode) {
if (nodeCountInLine == nodeNumberInLine) {
nodeCountInLine = 0;
currentNode = node;
}
currentNode = mapController.addNewNode(currentNode, currentNode.getChildCount(), currentNode.isLeft());
nodeCountInLine++;
currentText = "";
} else if (nodeCountInLine == -1) {
nodeCountInLine = 0;
currentNode = node;
currentText = "";
} else
currentText = currentNode.getText() + ' ';
boolean auxiliaryWord = auxiliaryWords.contains(word.toLowerCase());
if (!auxiliaryWord) {
textController.setNodeText(currentNode, currentText + capitalize(word));
newNode = true;
} else {
textController.setNodeText(currentNode, currentText + word);
newNode = false;
}
}
if (saveOriginalTextAsDetails) {
textController.setDetails(currentNode, HtmlUtils.isHtmlNode(details) ? details : HtmlUtils.plainToHTML(details));
textController.setIsMinimized(currentNode, true);
}
}
use of org.freeplane.features.text.TextController in project freeplane by freeplane.
the class NodeView method numberingChanged.
// updates children, starting from firstChangedIndex, if necessary.
private void numberingChanged(int firstChangedIndex) {
final TextController textController = TextController.getController(getMap().getModeController());
if (firstChangedIndex > 0 || textController.getNodeNumbering(getModel())) {
final Component[] components = getComponents();
for (int i = firstChangedIndex; i < components.length; i++) {
if (components[i] instanceof NodeView) {
final NodeView view = (NodeView) components[i];
final MainView childMainView = view.getMainView();
if (childMainView != null) {
childMainView.updateText(view.getModel());
view.numberingChanged(0);
}
}
}
}
}
use of org.freeplane.features.text.TextController in project freeplane by freeplane.
the class NoteViewMouseListener method mouseClicked.
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
TextController controller = TextController.getController();
if (controller.canEdit()) {
NodeModel node = new NodeSelector().getRelatedNodeView(e).getModel();
((MNoteController) NoteController.getController()).editNoteInDialog(node);
}
} else
super.mouseClicked(e);
}
use of org.freeplane.features.text.TextController in project freeplane by freeplane.
the class MainView method updateText.
public void updateText(NodeModel nodeModel) {
final NodeView nodeView = getNodeView();
if (nodeView == null)
return;
final ModeController modeController = nodeView.getMap().getModeController();
final TextController textController = TextController.getController(modeController);
isShortened = textController.isMinimized(nodeModel);
final Object userObject = nodeModel.getUserObject();
String text;
try {
final Object transformedContent = textController.getTransformedObject(nodeModel);
if (nodeView.isSelected()) {
nodeView.getMap().getModeController().getController().getViewController().addObjectTypeInfo(transformedContent);
}
Icon icon = textController.getIcon(transformedContent, nodeModel, userObject);
putClientProperty(TEXT_RENDERING_ICON, icon);
text = transformedContent.toString();
textModified = transformedContent instanceof HighlightedTransformedObject ? TextModificationState.HIGHLIGHT : TextModificationState.NONE;
} catch (Throwable e) {
LogUtils.warn(e.getMessage(), e);
text = TextUtils.format("MainView.errorUpdateText", String.valueOf(userObject), e.getLocalizedMessage());
textModified = TextModificationState.FAILURE;
}
if (isShortened) {
text = textController.getShortText(text);
}
text = convertTextToHtmlLink(text, nodeModel);
updateText(text);
}
Aggregations