use of org.freeplane.features.text.mindmapmode.MTextController in project freeplane by freeplane.
the class MClipboardController method getFlavorHandler.
private IDataFlavorHandler getFlavorHandler(final Transferable t) {
if (t.isDataFlavorSupported(MindMapNodesSelection.mindMapNodesFlavor)) {
try {
final String textFromClipboard = t.getTransferData(MindMapNodesSelection.mindMapNodesFlavor).toString();
return new MindMapNodesFlavorHandler(textFromClipboard);
} catch (final UnsupportedFlavorException e) {
} catch (final IOException e) {
}
}
final ResourceController resourceController = ResourceController.getResourceController();
DataFlavor supportedHtmlFlavor = getSupportedHtmlFlavor(t);
if (supportedHtmlFlavor != null) {
try {
final String textFromClipboard = t.getTransferData(supportedHtmlFlavor).toString();
if (textFromClipboard.charAt(0) != 65533) {
if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
final MTextController textController = (MTextController) TextController.getController();
final boolean richText = textController.useRichTextInEditor(RESOURCES_REMIND_USE_RICH_TEXT_IN_NEW_NODES);
if (richText) {
final boolean structuredHtmlImport = resourceController.getBooleanProperty("structured_html_import");
final IDataFlavorHandler htmlFlavorHandler;
if (structuredHtmlImport) {
htmlFlavorHandler = new StructuredHtmlFlavorHandler(textFromClipboard);
} else {
htmlFlavorHandler = new DirectHtmlFlavorHandler(textFromClipboard);
}
return htmlFlavorHandler;
}
}
}
} catch (final UnsupportedFlavorException e) {
} catch (final IOException e) {
}
}
if (t.isDataFlavorSupported(MindMapNodesSelection.fileListFlavor)) {
try {
final List<File> fileList = castToFileList(t.getTransferData(MindMapNodesSelection.fileListFlavor));
if (!shouldIgnoreFileListFlavor(fileList))
return new FileListFlavorHandler(fileList);
} catch (final UnsupportedFlavorException e) {
} catch (final IOException e) {
}
}
if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
final String plainTextFromClipboard = t.getTransferData(DataFlavor.stringFlavor).toString();
return new StringFlavorHandler(plainTextFromClipboard);
} catch (final UnsupportedFlavorException e) {
} catch (final IOException e) {
}
}
if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
try {
Image image = (Image) t.getTransferData(DataFlavor.imageFlavor);
return new ImageFlavorHandler(image);
} catch (final UnsupportedFlavorException e) {
} catch (final IOException e) {
}
}
return null;
}
use of org.freeplane.features.text.mindmapmode.MTextController in project freeplane by freeplane.
the class TimeManagement method createDateFormatChooser.
private JComboBox createDateFormatChooser() {
class DateFormatComboBoxElement {
private final PatternFormat dateFormat;
DateFormatComboBoxElement(PatternFormat dateFormat) {
this.dateFormat = dateFormat;
}
PatternFormat getDateFormat() {
return dateFormat;
}
public String toString() {
return dateFormat.formatObject(getCalendarDate()).toString();
}
}
final String dateFormatPattern = ResourceController.getResourceController().getProperty("date_format");
final Vector<DateFormatComboBoxElement> values = new Vector<DateFormatComboBoxElement>();
final List<PatternFormat> datePatterns = FormatController.getController().getDateFormats();
int selectedIndex = 0;
for (int i = 0; i < datePatterns.size(); ++i) {
final PatternFormat patternFormat = datePatterns.get(i);
values.add(new DateFormatComboBoxElement(patternFormat));
if (patternFormat.getPattern().equals(dateFormatPattern)) {
selectedIndex = i;
}
}
if (!datePatterns.isEmpty()) {
dateFormat = datePatterns.get(selectedIndex);
}
final JComboBox dateFormatChooser = new JComboBoxWithBorder(values);
dateFormatChooser.setFocusable(false);
if (!datePatterns.isEmpty()) {
dateFormatChooser.setSelectedIndex(selectedIndex);
}
dateFormatChooser.addItemListener(new ItemListener() {
public void itemStateChanged(final ItemEvent e) {
dateFormat = ((DateFormatComboBoxElement) e.getItem()).getDateFormat();
final Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (focusOwner instanceof JTable) {
JTable table = (JTable) focusOwner;
final int[] selectedRows = table.getSelectedRows();
final int[] selectedColumns = table.getSelectedColumns();
for (int r : selectedRows) for (int c : selectedColumns) {
Object date = table.getValueAt(r, c);
if (date instanceof FormattedDate) {
final FormattedDate fd = (FormattedDate) date;
if (!fd.getDateFormat().equals(dateFormat)) {
table.setValueAt(new FormattedDate(fd, dateFormat.getPattern()), r, c);
}
}
}
} else {
ModeController mController = Controller.getCurrentModeController();
for (final NodeModel node : mController.getMapController().getSelectedNodes()) {
final MTextController textController = (MTextController) TextController.getController();
Object date = node.getUserObject();
if (date instanceof FormattedDate) {
final FormattedDate fd = (FormattedDate) date;
if (!fd.getDateFormat().equals(dateFormat)) {
textController.setNodeObject(node, new FormattedDate(fd, dateFormat.getPattern()));
}
}
}
}
}
});
dateFormatChooser.setAlignmentX(Component.LEFT_ALIGNMENT);
return dateFormatChooser;
}
use of org.freeplane.features.text.mindmapmode.MTextController in project freeplane by freeplane.
the class TimeManagement method insertTime.
void insertTime(final Dialog dialog, final JButton appendButton) {
FormattedDate date = getCalendarDate();
final String dateAsString = dateFormat.formatObject(date).toString();
final Window parentWindow;
if (dialog != null) {
parentWindow = (Window) dialog.getParent();
} else {
parentWindow = SwingUtilities.getWindowAncestor(appendButton);
}
final Component mostRecentFocusOwner = parentWindow.getMostRecentFocusOwner();
if (mostRecentFocusOwner instanceof JTextComponent && !(mostRecentFocusOwner.getClass().getName().contains("JSpinField"))) {
final JTextComponent textComponent = (JTextComponent) mostRecentFocusOwner;
textComponent.replaceSelection(dateAsString);
return;
}
if (mostRecentFocusOwner instanceof JTable) {
JTable table = (JTable) mostRecentFocusOwner;
final int[] selectedRows = table.getSelectedRows();
final int[] selectedColumns = table.getSelectedColumns();
for (int r : selectedRows) for (int c : selectedColumns) table.setValueAt(date, r, c);
} else {
ModeController mController = Controller.getCurrentModeController();
for (final NodeModel node : mController.getMapController().getSelectedNodes()) {
final MTextController textController = (MTextController) TextController.getController();
textController.setNodeObject(node, date);
}
}
}
use of org.freeplane.features.text.mindmapmode.MTextController in project freeplane by freeplane.
the class FormulaTextTransformer method createEditor.
public EditNodeBase createEditor(final NodeModel node, final EditNodeBase.IEditControl editControl, String text, final boolean editLong) {
MTextController textController = MTextController.getController();
if (textController.isTextFormattingDisabled(node))
return null;
final KeyEvent firstKeyEvent = textController.getEventQueue().getFirstEvent();
if (firstKeyEvent != null) {
if (firstKeyEvent.getKeyChar() == '=') {
text = "=";
} else {
return null;
}
}
if (text.startsWith("=")) {
JEditorPane textEditor = new JEditorPane();
textEditor.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
final JRestrictedSizeScrollPane scrollPane = new JRestrictedSizeScrollPane(textEditor);
scrollPane.setMinimumSize(new Dimension(0, 60));
final EditNodeDialog editNodeDialog = new FormulaEditor(node, text, firstKeyEvent, editControl, false, textEditor);
editNodeDialog.setTitle(TextUtils.getText("formula_editor"));
textEditor.setContentType("text/groovy");
final String fontName = ResourceController.getResourceController().getProperty(FormulaEditor.GROOVY_EDITOR_FONT);
final int fontSize = ResourceController.getResourceController().getIntProperty(FormulaEditor.GROOVY_EDITOR_FONT_SIZE);
textEditor.setFont(new Font(fontName, Font.PLAIN, fontSize));
return editNodeDialog;
}
return null;
}
use of org.freeplane.features.text.mindmapmode.MTextController in project freeplane by freeplane.
the class MMapController method addFreeNode.
public NodeModel addFreeNode(final Point pt, final boolean newNodeIsLeft) {
final ModeController modeController = Controller.getCurrentModeController();
final TextController textController = TextController.getController();
if (textController instanceof MTextController) {
((MTextController) textController).stopEditing();
modeController.forceNewTransaction();
}
final NodeModel target = getRootNode();
final NodeModel targetNode = target;
final boolean parentFolded = isFolded(targetNode);
if (parentFolded) {
unfold(targetNode);
}
if (!isWriteable(target)) {
UITools.errorMessage(TextUtils.getText("node_is_write_protected"));
return null;
}
final NodeModel newNode = newNode("", target.getMap());
LogicalStyleModel.createExtension(newNode).setStyle(MapStyleModel.FLOATING_STYLE);
newNode.addExtension(modeController.getExtension(FreeNode.class));
if (!addNewNode(newNode, target, target.getChildCount(), newNodeIsLeft))
return null;
final Quantity<LengthUnits> x = LengthUnits.pixelsInPt(pt.x);
final Quantity<LengthUnits> y = LengthUnits.pixelsInPt(pt.y);
((MLocationController) MLocationController.getController(modeController)).moveNodePosition(newNode, x, y);
final Component component = Controller.getCurrentController().getMapViewManager().getComponent(newNode);
if (component == null)
return newNode;
component.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent e) {
}
public void focusGained(FocusEvent e) {
e.getComponent().removeFocusListener(this);
((MTextController) textController).edit(newNode, targetNode, true, false, false);
}
});
select(newNode);
return newNode;
}
Aggregations