use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class GridInsertLocation method isInsertInsideComponent.
private boolean isInsertInsideComponent(final int size) {
int endColumn = getInsertCell();
if (isInsertAfter())
endColumn++;
int row = getOppositeCell();
for (int r = row; r < row + size; r++) {
for (int col = 0; col < endColumn; col++) {
RadComponent component;
if (isColumnInsert()) {
component = RadAbstractGridLayoutManager.getComponentAtGrid(getContainer(), r, col);
} else {
component = RadAbstractGridLayoutManager.getComponentAtGrid(getContainer(), col, r);
}
if (component != null) {
GridConstraints constraints = component.getConstraints();
final boolean isRow = !isColumnInsert();
if (constraints.getCell(isRow) + constraints.getSpan(isRow) > endColumn && constraints.getSpan(isRow) > 1) {
return true;
}
}
}
}
return false;
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class GridInsertLocation method placeFeedback.
@Override
public void placeFeedback(FeedbackLayer feedbackLayer, ComponentDragObject dragObject) {
final int insertCol = getColumn();
final int insertRow = getRow();
Rectangle feedbackRect = getGridFeedbackRect(dragObject, isColumnInsert(), isRowInsert(), false);
if (feedbackRect == null) {
feedbackLayer.removeFeedback();
return;
}
Rectangle cellRect = getGridFeedbackCellRect(dragObject, isColumnInsert(), isRowInsert(), false);
assert cellRect != null;
final RadAbstractGridLayoutManager layoutManager = getContainer().getGridLayoutManager();
int[] vGridLines = layoutManager.getVerticalGridLines(getContainer());
int[] hGridLines = layoutManager.getHorizontalGridLines(getContainer());
FeedbackPainter painter = (myMode == GridInsertMode.ColumnBefore || myMode == GridInsertMode.ColumnAfter) ? VertInsertFeedbackPainter.INSTANCE : HorzInsertFeedbackPainter.INSTANCE;
Rectangle rc;
Rectangle rcFeedback = null;
if (dragObject.getComponentCount() == 1) {
int lastColIndex = insertCol + dragObject.getColSpan(0);
if (lastColIndex > vGridLines.length - 1) {
lastColIndex = insertCol + 1;
}
int lastRowIndex = insertRow + dragObject.getRowSpan(0);
if (lastRowIndex > hGridLines.length - 1) {
lastRowIndex = insertRow + 1;
}
int cellWidth = vGridLines[lastColIndex] - vGridLines[insertCol];
int cellHeight = hGridLines[lastRowIndex] - hGridLines[insertRow];
RadComponent component = layoutManager.getComponentAtGrid(getContainer(), insertRow, insertCol);
if (component != null && mySpanInsertMode) {
Rectangle bounds = component.getBounds();
bounds.translate(-vGridLines[insertCol], -hGridLines[insertRow]);
int spaceToRight = vGridLines[lastColIndex] - vGridLines[insertCol] - (bounds.x + bounds.width);
int spaceBelow = hGridLines[lastRowIndex] - hGridLines[insertRow] - (bounds.y + bounds.height);
if (myMode == GridInsertMode.RowBefore && bounds.y > INSERT_RECT_MIN_SIZE) {
rcFeedback = new Rectangle(0, 0, cellWidth, bounds.y);
} else if (myMode == GridInsertMode.RowAfter && spaceBelow > INSERT_RECT_MIN_SIZE) {
rcFeedback = new Rectangle(0, bounds.y + bounds.height, cellWidth, spaceBelow);
} else if (myMode == GridInsertMode.ColumnBefore && bounds.x > INSERT_RECT_MIN_SIZE) {
rcFeedback = new Rectangle(0, 0, bounds.x, cellHeight);
} else if (myMode == GridInsertMode.ColumnAfter && spaceToRight > INSERT_RECT_MIN_SIZE) {
rcFeedback = new Rectangle(bounds.x + bounds.width, 0, spaceToRight, cellHeight);
}
if (rcFeedback != null) {
boolean spanInsertMode = false;
if (isRowInsert()) {
int columns = layoutManager.getGridColumnCount(getContainer());
for (int i = 0; i < columns; i++) {
if (i != insertCol && RadAbstractGridLayoutManager.getComponentAtGrid(getContainer(), insertRow, i) != null) {
spanInsertMode = true;
break;
}
}
} else {
int rows = layoutManager.getGridRowCount(getContainer());
for (int i = 0; i < rows; i++) {
if (i != insertRow && RadAbstractGridLayoutManager.getComponentAtGrid(getContainer(), i, insertCol) != null) {
spanInsertMode = true;
break;
}
}
}
if (!spanInsertMode) {
rcFeedback = null;
}
}
if (rcFeedback != null) {
rcFeedback.translate(vGridLines[insertCol], hGridLines[insertRow]);
}
}
if (rcFeedback == null) {
if (insertCol == layoutManager.getGridColumnCount(getContainer()) - 1 && myMode == GridInsertMode.ColumnAfter) {
final Dimension initialSize = dragObject.getInitialSize(getContainer());
int feedbackX = vGridLines[vGridLines.length - 1] + layoutManager.getGapCellSize(myContainer, false);
int remainingSize = getContainer().getDelegee().getWidth() - feedbackX;
if (!dragObject.isHGrow() && remainingSize > initialSize.width) {
if (dragObject.isVGrow() || initialSize.height > cellHeight) {
rcFeedback = new Rectangle(feedbackX, hGridLines[insertRow], initialSize.width, cellHeight);
} else {
rcFeedback = new Rectangle(feedbackX, hGridLines[insertRow] + (cellHeight - initialSize.height) / 2, initialSize.width, initialSize.height);
}
} else if (remainingSize >= 4) {
rcFeedback = new Rectangle(feedbackX, hGridLines[insertRow], remainingSize, cellHeight);
}
} else if (insertRow == layoutManager.getGridRowCount(getContainer()) - 1 && myMode == GridInsertMode.RowAfter) {
final Dimension initialSize = dragObject.getInitialSize(getContainer());
int feedbackY = hGridLines[hGridLines.length - 1] + layoutManager.getGapCellSize(myContainer, true);
int remainingSize = getContainer().getDelegee().getHeight() - feedbackY;
if (!dragObject.isVGrow() && remainingSize > initialSize.height) {
rcFeedback = new Rectangle(vGridLines[insertCol], feedbackY, cellWidth, initialSize.height);
} else if (remainingSize >= 4) {
rcFeedback = new Rectangle(vGridLines[insertCol], feedbackY, cellWidth, remainingSize);
}
}
}
}
if (rcFeedback != null) {
feedbackLayer.putFeedback(getContainer().getDelegee(), rcFeedback, getInsertFeedbackTooltip());
return;
}
rc = getInsertFeedbackPosition(myMode, getContainer(), cellRect, feedbackRect);
feedbackLayer.putFeedback(getContainer().getDelegee(), rc, painter, getInsertFeedbackTooltip());
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class GridInsertProcessor method getDropTargetContainer.
public static RadContainer getDropTargetContainer(final RadRootContainer rootContainer, final Point aPoint) {
int EPSILON = 4;
RadContainer container = FormEditingUtil.getRadContainerAt(rootContainer, aPoint.x, aPoint.y, EPSILON);
// to facilitate initial component adding, increase stickiness if there is one container at top level
if (container instanceof RadRootContainer && rootContainer.getComponentCount() == 1) {
final RadComponent singleComponent = rootContainer.getComponents()[0];
if (singleComponent instanceof RadContainer) {
Rectangle rc = singleComponent.getDelegee().getBounds();
rc.grow(EPSILON * 2, EPSILON * 2);
if (rc.contains(aPoint)) {
container = (RadContainer) singleComponent;
EPSILON *= 2;
}
}
}
return container;
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class FormInspectionUtil method getText.
@Nullable
public static String getText(@NotNull final Module module, final IComponent component) {
IProperty textProperty = findProperty(component, SwingProperties.TEXT);
if (textProperty != null) {
Object propValue = textProperty.getPropertyValue(component);
String value = null;
if (propValue instanceof StringDescriptor) {
StringDescriptor descriptor = (StringDescriptor) propValue;
if (component instanceof RadComponent) {
value = StringDescriptorManager.getInstance(module).resolve((RadComponent) component, descriptor);
} else {
value = StringDescriptorManager.getInstance(module).resolve(descriptor, null);
}
} else if (propValue instanceof String) {
value = (String) propValue;
}
if (value != null) {
return value;
}
}
return null;
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class FormSpellCheckingInspection method checkStringDescriptor.
@Override
protected void checkStringDescriptor(Module module, final IComponent component, final IProperty prop, final StringDescriptor descriptor, final FormErrorCollector collector) {
final String value = descriptor.getResolvedValue();
if (value == null) {
return;
}
final SpellCheckerManager manager = SpellCheckerManager.getInstance(module.getProject());
PlainTextSplitter.getInstance().split(value, TextRange.allOf(value), textRange -> {
final String word = textRange.substring(value);
if (manager.hasProblem(word)) {
final List<String> suggestions = manager.getSuggestions(word);
if (!suggestions.isEmpty() && prop instanceof IntroStringProperty) {
EditorQuickFixProvider changeToProvider = new EditorQuickFixProvider() {
@Override
public QuickFix createQuickFix(final GuiEditor editor, final RadComponent component1) {
return new PopupQuickFix<String>(editor, "Change to...", component1) {
@Override
public void run() {
ListPopup popup = JBPopupFactory.getInstance().createListPopup(getPopupStep());
popup.showUnderneathOf(component1.getDelegee());
}
@Override
public ListPopupStep<String> getPopupStep() {
return new BaseListPopupStep<String>("Select Replacement", suggestions) {
@Override
public PopupStep onChosen(String selectedValue, boolean finalChoice) {
FormInspectionUtil.updateStringPropertyValue(editor, component1, (IntroStringProperty) prop, descriptor, selectedValue);
return FINAL_CHOICE;
}
};
}
};
}
};
EditorQuickFixProvider acceptProvider = new EditorQuickFixProvider() {
@Override
public QuickFix createQuickFix(final GuiEditor editor, RadComponent component1) {
return new QuickFix(editor, "Save '" + word + "' to dictionary", component1) {
@Override
public void run() {
manager.acceptWordAsCorrect(word, editor.getProject());
}
};
}
};
collector.addError(getID(), component, prop, "Typo in word '" + word + "'", changeToProvider, acceptProvider);
} else {
collector.addError(getID(), component, prop, "Typo in word '" + word + "'");
}
}
});
}
Aggregations