use of org.freeplane.features.nodestyle.NodeStyleController in project freeplane by freeplane.
the class NodeViewLayoutAdapter method calculateContentSize.
protected Dimension calculateContentSize(final NodeView view) {
final JComponent content = view.getContent();
final ModeController modeController = view.getMap().getModeController();
final NodeStyleController nsc = NodeStyleController.getController(modeController);
Dimension contentSize;
if (content instanceof ZoomableLabel) {
int maxNodeWidth = nsc.getMaxWidth(view.getModel());
contentSize = ((ZoomableLabel) content).getPreferredSize(maxNodeWidth);
} else {
contentSize = content.getPreferredSize();
}
int minNodeWidth = nsc.getMinWidth(view.getModel());
int contentWidth = Math.max(view.getZoomed(minNodeWidth), contentSize.width);
int contentHeight = contentSize.height;
final Dimension contentProfSize = new Dimension(contentWidth, contentHeight);
return contentProfSize;
}
use of org.freeplane.features.nodestyle.NodeStyleController in project freeplane by freeplane.
the class StyleEditorPanel method setStyle.
public void setStyle(final NodeModel node) {
if (internalChange) {
return;
}
internalChange = true;
try {
final LogicalStyleController logicalStyleController = LogicalStyleController.getController();
if (addStyleBox) {
final boolean isStyleSet = LogicalStyleModel.getStyle(node) != null;
mSetStyle.setValue(isStyleSet);
setStyleList(mMapStyleButton, logicalStyleController.getMapStyleNames(node, "\n"));
}
setStyleList(mNodeStyleButton, logicalStyleController.getNodeStyleNames(node, "\n"));
final NodeStyleController styleController = NodeStyleController.getController();
{
final Color nodeColor = NodeStyleModel.getColor(node);
final Color viewNodeColor = styleController.getColor(node);
mSetNodeColor.setValue(nodeColor != null);
mNodeColor.setColorValue(viewNodeColor);
}
{
final Color color = NodeStyleModel.getBackgroundColor(node);
final Color viewColor = styleController.getBackgroundColor(node);
mSetNodeBackgroundColor.setValue(color != null);
mNodeBackgroundColor.setColorValue(viewColor != null ? viewColor : Controller.getCurrentController().getMapViewManager().getBackgroundColor(node));
}
{
final String shape = NodeStyleModel.getShape(node);
final String viewShape = styleController.getShape(node);
mSetNodeShape.setValue(shape != null);
mNodeShape.setValue(viewShape);
}
final NodeSizeModel nodeSizeModel = NodeSizeModel.getModel(node);
{
final int width = nodeSizeModel != null ? nodeSizeModel.getMaxNodeWidth() : NodeSizeModel.NOT_SET;
final int viewWidth = styleController.getMaxWidth(node);
mSetMaxNodeWidth.setValue(width != NodeSizeModel.NOT_SET);
mMaxNodeWidth.setValue(Integer.toString(viewWidth));
}
{
final int width = nodeSizeModel != null ? nodeSizeModel.getMinNodeWidth() : NodeSizeModel.NOT_SET;
final int viewWidth = styleController.getMinWidth(node);
mSetMinNodeWidth.setValue(width != NodeSizeModel.NOT_SET);
mMinNodeWidth.setValue(Integer.toString(viewWidth));
}
final EdgeController edgeController = EdgeController.getController();
final EdgeModel edgeModel = EdgeModel.getModel(node);
{
final Color edgeColor = edgeModel != null ? edgeModel.getColor() : null;
final Color viewColor = edgeController.getColor(node);
mSetEdgeColor.setValue(edgeColor != null);
mEdgeColor.setColorValue(viewColor);
}
{
final EdgeStyle style = edgeModel != null ? edgeModel.getStyle() : null;
final EdgeStyle viewStyle = edgeController.getStyle(node);
mSetEdgeStyle.setValue(style != null);
mEdgeStyle.setValue(viewStyle.toString());
}
{
final int width = edgeModel != null ? edgeModel.getWidth() : EdgeModel.DEFAULT_WIDTH;
final int viewWidth = edgeController.getWidth(node);
mSetEdgeWidth.setValue(width != EdgeModel.DEFAULT_WIDTH);
mEdgeWidth.setValue(Integer.toString(viewWidth));
}
{
final CloudController cloudController = CloudController.getController();
final CloudModel cloudModel = CloudModel.getModel(node);
final Color viewCloudColor = cloudController.getColor(node);
mSetCloud.setValue(cloudModel != null);
mCloudColor.setColorValue(viewCloudColor);
final CloudModel.Shape viewCloudShape = cloudController.getShape(node);
mCloudShape.setValue(viewCloudShape != null ? viewCloudShape.toString() : CloudModel.Shape.ARC.toString());
}
{
final String fontFamilyName = NodeStyleModel.getFontFamilyName(node);
final String viewFontFamilyName = styleController.getFontFamilyName(node);
mSetNodeFontName.setValue(fontFamilyName != null);
mNodeFontName.setValue(viewFontFamilyName);
}
{
final Integer fontSize = NodeStyleModel.getFontSize(node);
final Integer viewfontSize = styleController.getFontSize(node);
mSetNodeFontSize.setValue(fontSize != null);
mNodeFontSize.setValue(viewfontSize.toString());
}
{
final Boolean bold = NodeStyleModel.isBold(node);
final Boolean viewbold = styleController.isBold(node);
mSetNodeFontBold.setValue(bold != null);
mNodeFontBold.setValue(viewbold);
}
{
final Boolean italic = NodeStyleModel.isItalic(node);
final Boolean viewitalic = styleController.isItalic(node);
mSetNodeFontItalic.setValue(italic != null);
mNodeFontItalic.setValue(viewitalic);
}
{
final Boolean hyperlink = NodeLinks.formatNodeAsHyperlink(node);
final Boolean viewhyperlink = LinkController.getController().formatNodeAsHyperlink(node);
mSetNodeFontHyperlink.setValue(hyperlink != null);
mNodeFontHyperlink.setValue(viewhyperlink);
}
{
final Boolean nodeNumbering = NodeStyleModel.getNodeNumbering(node);
final Boolean viewNodeNumbering = styleController.getNodeNumbering(node);
mSetNodeNumbering.setValue(nodeNumbering != null);
mNodeNumbering.setValue(viewNodeNumbering);
}
{
String nodeFormat = NodeStyleModel.getNodeFormat(node);
String viewNodeFormat = TextController.getController().getNodeFormat(node);
mSetNodeFormat.setValue(nodeFormat != null);
if (viewNodeFormat == null && node.getUserObject() instanceof IFormattedObject)
viewNodeFormat = ((IFormattedObject) node.getUserObject()).getPattern();
mNodeFormat.setValue(viewNodeFormat);
}
if (mAutomaticLayoutComboBox != null) {
final ModeController modeController = Controller.getCurrentModeController();
AutomaticLayoutController al = modeController.getExtension(AutomaticLayoutController.class);
IExtension extension = al.getExtension(node);
if (extension == null)
mAutomaticLayoutComboBox.setSelectedItem(AUTOMATIC_LAYOUT_DISABLED);
else
mAutomaticLayoutComboBox.setSelectedIndex(((AutomaticLayout) extension).ordinal());
}
if (mAutomaticEdgeColorCheckBox != null) {
final ModeController modeController = Controller.getCurrentModeController();
AutomaticEdgeColorHook al = (AutomaticEdgeColorHook) modeController.getExtension(AutomaticEdgeColorHook.class);
mAutomaticEdgeColorCheckBox.setSelected(al.isActive(node));
}
} finally {
internalChange = false;
}
}
use of org.freeplane.features.nodestyle.NodeStyleController in project freeplane by freeplane.
the class EditNodeTextField method show.
/* (non-Javadoc)
* @see org.freeplane.view.swing.map.INodeTextField#show()
*/
@SuppressWarnings("serial")
@Override
public void show(final RootPaneContainer frame) {
final ModeController modeController = Controller.getCurrentModeController();
final IMapViewManager viewController = modeController.getController().getMapViewManager();
final MTextController textController = (MTextController) TextController.getController(modeController);
nodeView = (NodeView) SwingUtilities.getAncestorOfClass(NodeView.class, parent);
font = parent.getFont();
zoom = viewController.getZoom();
if (zoom != 1F) {
final float fontSize = (int) (Math.rint(font.getSize() * zoom));
font = font.deriveFont(fontSize);
}
final HTMLEditorKit kit = new ScaledEditorKit() {
@Override
public void write(Writer out, Document doc, int pos, int len) throws IOException, BadLocationException {
if (doc instanceof HTMLDocument) {
HTMLWriter w = new SHTMLWriter(out, (HTMLDocument) doc, pos, len);
w.write();
} else {
super.write(out, doc, pos, len);
}
}
};
textfield.setEditorKit(kit);
final InputMap inputMap = textfield.getInputMap();
final ActionMap actionMap = textfield.getActionMap();
actionMap.put(DefaultEditorKit.pasteAction, pasteAction);
inputMap.put((KeyStroke) boldAction.getValue(Action.ACCELERATOR_KEY), "boldAction");
actionMap.put("boldAction", boldAction);
inputMap.put((KeyStroke) italicAction.getValue(Action.ACCELERATOR_KEY), "italicAction");
actionMap.put("italicAction", italicAction);
inputMap.put((KeyStroke) underlineAction.getValue(Action.ACCELERATOR_KEY), "underlineAction");
actionMap.put("underlineAction", underlineAction);
inputMap.put((KeyStroke) redAction.getValue(Action.ACCELERATOR_KEY), "redAction");
actionMap.put("redAction", redAction);
inputMap.put((KeyStroke) greenAction.getValue(Action.ACCELERATOR_KEY), "greenAction");
actionMap.put("greenAction", greenAction);
inputMap.put((KeyStroke) blueAction.getValue(Action.ACCELERATOR_KEY), "blueAction");
actionMap.put("blueAction", blueAction);
inputMap.put((KeyStroke) blackAction.getValue(Action.ACCELERATOR_KEY), "blackAction");
actionMap.put("blackAction", blackAction);
inputMap.put((KeyStroke) defaultColorAction.getValue(Action.ACCELERATOR_KEY), "defaultColorAction");
actionMap.put("defaultColorAction", defaultColorAction);
inputMap.put((KeyStroke) removeFormattingAction.getValue(Action.ACCELERATOR_KEY), "removeFormattingAction");
actionMap.put("removeFormattingAction", removeFormattingAction);
final Color nodeTextColor = parent.getForeground();
textfield.setCaretColor(nodeTextColor);
final StringBuilder ruleBuilder = new StringBuilder(100);
ruleBuilder.append("body {");
ruleBuilder.append("font-family: ").append(font.getFamily()).append(";");
final int fontSize = Math.round(font.getSize() / UITools.FONT_SCALE_FACTOR);
ruleBuilder.append("font-size: ").append(fontSize).append("pt;");
if (font.isItalic()) {
ruleBuilder.append("font-style: italic; ");
}
if (font.isBold()) {
ruleBuilder.append("font-weight: bold; ");
}
ruleBuilder.append("color: ").append(ColorUtils.colorToString(nodeTextColor)).append(";");
final Color bgColor = getBackground();
ruleBuilder.append("background-color: ").append(ColorUtils.colorToString(bgColor)).append(";");
ruleBuilder.append("}\n");
final HTMLDocument document = (HTMLDocument) textfield.getDocument();
final StyleSheet styleSheet = document.getStyleSheet();
styleSheet.addRule(ruleBuilder.toString());
textfield.setText(text);
final MapView mapView = (MapView) viewController.getMapViewComponent();
if (!mapView.isValid())
mapView.validate();
final NodeStyleController nsc = NodeStyleController.getController(modeController);
maxWidth = nsc.getMaxWidth(node);
final Icon icon = parent.getIcon();
if (icon != null) {
maxWidth -= icon.getIconWidth();
maxWidth -= parent.getIconTextGap();
}
maxWidth = mapView.getZoomed(maxWidth);
extraWidth = ResourceController.getResourceController().getIntProperty("editor_extra_width", 80);
extraWidth = mapView.getZoomed(extraWidth);
final TextFieldListener textFieldListener = new TextFieldListener();
this.textFieldListener = textFieldListener;
textfield.addFocusListener(textFieldListener);
textfield.addKeyListener(textFieldListener);
textfield.addMouseListener(textFieldListener);
mapViewChangeListener = new MapViewChangeListener();
Controller.getCurrentController().getMapViewManager().addMapViewChangeListener(mapViewChangeListener);
SpellCheckerController.getController().enableAutoSpell(textfield, true);
mapView.scrollNodeToVisible(nodeView);
assert (parent.isValid());
final int nodeWidth = parent.getWidth();
final int nodeHeight = parent.getHeight();
final Dimension textFieldSize;
textfield.setBorder(new MatteBorder(2, 2, 2, 2, nodeView.getSelectedColor()));
textFieldSize = textfield.getPreferredSize();
textFieldSize.width += 1;
if (textFieldSize.width < extraWidth)
textFieldSize.width = extraWidth;
if (textFieldSize.width < 10)
textFieldSize.width = 10;
if (textFieldSize.width > maxWidth) {
textFieldSize.width = maxWidth;
setLineWrap();
textFieldSize.height = textfield.getPreferredSize().height;
}
final Rectangle textR = ((ZoomableLabelUI) parent.getUI()).getTextR(parent);
textFieldSize.width = Math.max(textFieldSize.width, textR.width);
textFieldSize.height = Math.max(textFieldSize.height, textR.height);
textfield.setSize(textFieldSize.width, textFieldSize.height);
horizontalSpace = Math.max(nodeWidth - textFieldSize.width, textR.x);
verticalSpace = Math.max(nodeHeight - textFieldSize.height, textR.y);
final Dimension newParentSize = new Dimension(horizontalSpace + textFieldSize.width, verticalSpace + textFieldSize.height);
parent.setPreferredSize(newParentSize);
final Point location = new Point(textR.x - 2, textR.y);
if (!layoutMapOnTextChange)
UITools.convertPointToAncestor(parent, location, mapView);
textfield.setBounds(location.x, location.y, textFieldSize.width, textFieldSize.height);
parent.setText("");
if (nodeView.isRoot() && parent instanceof MainView)
parent.setHorizontalAlignment(JLabel.LEFT);
if (layoutMapOnTextChange)
parent.add(textfield, 0);
else
mapView.add(textfield, 0);
final EventBuffer eventQueue = MTextController.getController().getEventQueue();
KeyEvent firstEvent = eventQueue.getFirstEvent();
redispatchKeyEvents(textfield, firstEvent);
if (firstEvent == null) {
MouseEvent currentEvent = eventQueue.getMouseEvent();
int pos = document.getLength();
if (currentEvent != null) {
MouseEvent mouseEvent = (MouseEvent) currentEvent;
if (mouseEvent.getComponent().equals(parent)) {
final Point point = mouseEvent.getPoint();
point.x -= textR.x;
point.y -= textR.y;
pos = textfield.viewToModel(point);
}
}
textfield.setCaretPosition(pos);
}
document.addDocumentListener(documentListener);
if (textController.isMinimized(node)) {
layout();
}
textfield.repaint();
textfield.requestFocusInWindow();
}
Aggregations