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