IDEA-35738 Cannot drag around label with empty text

This commit is contained in:
Alexander Lobas
2012-01-24 18:28:23 +04:00
parent f8e5d17e6d
commit 7a5d4d2a5f
2 changed files with 139 additions and 115 deletions
@@ -68,7 +68,7 @@ public final class FormEditingUtil {
private FormEditingUtil() {
}
public static boolean canDeleteSelection(final GuiEditor editor){
public static boolean canDeleteSelection(final GuiEditor editor) {
final ArrayList<RadComponent> selection = getSelectedComponents(editor);
if (selection.isEmpty()) return false;
final RadRootContainer rootContainer = editor.getRootContainer();
@@ -83,7 +83,7 @@ public final class FormEditingUtil {
*
* @param editor the editor in which the selection is deleted.
*/
public static void deleteSelection(final GuiEditor editor){
public static void deleteSelection(final GuiEditor editor) {
final List<RadComponent> selection = getSelectedComponents(editor);
deleteComponents(selection, true);
editor.refreshAndSave(true);
@@ -93,7 +93,7 @@ public final class FormEditingUtil {
if (selection.size() == 0) {
return;
}
final RadRootContainer rootContainer = (RadRootContainer) getRoot(selection.iterator().next());
final RadRootContainer rootContainer = (RadRootContainer)getRoot(selection.iterator().next());
final Set<String> deletedComponentIds = new HashSet<String>();
for (final RadComponent component : selection) {
boolean wasSelected = component.isSelected();
@@ -126,7 +126,7 @@ public final class FormEditingUtil {
parent.getComponent(index).setSelected(true);
}
else if (index > 0 && parent.getComponentCount() == index) {
parent.getComponent(index-1).setSelected(true);
parent.getComponent(index - 1).setSelected(true);
}
else {
parent.setSelected(true);
@@ -178,7 +178,7 @@ public final class FormEditingUtil {
private static void deleteEmptyGridCells(final RadContainer parent, final GridConstraints delConstraints, final boolean isRow) {
final RadAbstractGridLayoutManager layoutManager = parent.getGridLayoutManager();
for(int cell=delConstraints.getCell(isRow) + delConstraints.getSpan(isRow)-1; cell>= delConstraints.getCell(isRow); cell--) {
for (int cell = delConstraints.getCell(isRow) + delConstraints.getSpan(isRow) - 1; cell >= delConstraints.getCell(isRow); cell--) {
if (cell < parent.getGridCellCount(isRow) && GridChangeUtil.canDeleteCell(parent, cell, isRow) == GridChangeUtil.CellStatus.Empty &&
!layoutManager.isGapCell(parent, isRow, cell)) {
layoutManager.deleteGridCells(parent, cell, isRow);
@@ -186,7 +186,7 @@ public final class FormEditingUtil {
}
}
private static final int EMPTY_COMPONENT_SIZE = 5;
public static final int EMPTY_COMPONENT_SIZE = 5;
private static Component getDeepestEmptyComponentAt(JComponent parent, Point location) {
int size = parent.getComponentCount();
@@ -228,7 +228,7 @@ public final class FormEditingUtil {
* @param x in editor pane coordinates
* @param y in editor pane coordinates
*/
public static RadComponent getRadComponentAt(final RadRootContainer rootContainer, final int x, final int y){
public static RadComponent getRadComponentAt(final RadRootContainer rootContainer, final int x, final int y) {
Point location = new Point(x, y);
SwingUtilities.convertPointToScreen(location, rootContainer.getDelegee());
Component c = getDeepestEmptyComponentAt(rootContainer.getDelegee(), location);
@@ -240,7 +240,7 @@ public final class FormEditingUtil {
RadComponent result = null;
while (c != null) {
if (c instanceof JComponent){
if (c instanceof JComponent) {
final RadComponent component = (RadComponent)((JComponent)c).getClientProperty(RadComponent.CLIENT_PROP_RAD_COMPONENT);
if (component != null) {
@@ -263,16 +263,16 @@ public final class FormEditingUtil {
/**
* @return component which has dragger. There is only one component with the dargger
* at a time.
* at a time.
*/
@Nullable
public static RadComponent getDraggerHost(@NotNull final GuiEditor editor){
public static RadComponent getDraggerHost(@NotNull final GuiEditor editor) {
final Ref<RadComponent> result = new Ref<RadComponent>();
iterate(
editor.getRootContainer(),
new ComponentVisitor<RadComponent>() {
public boolean visit(final RadComponent component) {
if(component.hasDragger()){
if (component.hasDragger()) {
result.set(component);
return false;
}
@@ -314,18 +314,18 @@ public final class FormEditingUtil {
/**
* @return currently selected components. Method returns the minimal amount of
* selected component which contains all selected components. It means that if the
* selected container contains some selected children then only this container
* will be added to the returned array.
* selected component which contains all selected components. It means that if the
* selected container contains some selected children then only this container
* will be added to the returned array.
*/
@NotNull
public static ArrayList<RadComponent> getSelectedComponents(@NotNull final GuiEditor editor){
public static ArrayList<RadComponent> getSelectedComponents(@NotNull final GuiEditor editor) {
final ArrayList<RadComponent> result = new ArrayList<RadComponent>();
calcSelectedComponentsImpl(result, editor.getRootContainer());
return result;
}
private static void calcSelectedComponentsImpl(final ArrayList<RadComponent> result, final RadContainer container){
private static void calcSelectedComponentsImpl(final ArrayList<RadComponent> result, final RadContainer container) {
if (container.isSelected()) {
if (container.getParent() != null) { // ignore RadRootContainer
result.add(container);
@@ -350,7 +350,7 @@ public final class FormEditingUtil {
* @return all selected component inside the <code>editor</code>
*/
@NotNull
public static ArrayList<RadComponent> getAllSelectedComponents(@NotNull final GuiEditor editor){
public static ArrayList<RadComponent> getAllSelectedComponents(@NotNull final GuiEditor editor) {
final ArrayList<RadComponent> result = new ArrayList<RadComponent>();
iterate(
editor.getRootContainer(),
@@ -373,8 +373,7 @@ public final class FormEditingUtil {
return getExceptionMessage(cause);
}
}
else
if (ex instanceof InvocationTargetException) {
else if (ex instanceof InvocationTargetException) {
final Throwable target = ((InvocationTargetException)ex).getTargetException();
if (target != null && target != ex) {
return getExceptionMessage(target);
@@ -382,10 +381,13 @@ public final class FormEditingUtil {
}
String message = ex.getMessage();
if (ex instanceof ClassNotFoundException) {
message = message != null? UIDesignerBundle.message("error.class.not.found.N", message) : UIDesignerBundle.message("error.class.not.found");
message =
message != null ? UIDesignerBundle.message("error.class.not.found.N", message) : UIDesignerBundle.message("error.class.not.found");
}
else if (ex instanceof NoClassDefFoundError) {
message = message != null? UIDesignerBundle.message("error.required.class.not.found.N", message) : UIDesignerBundle.message("error.required.class.not.found");
message = message != null
? UIDesignerBundle.message("error.required.class.not.found.N", message)
: UIDesignerBundle.message("error.required.class.not.found");
}
return message;
}
@@ -394,14 +396,16 @@ public final class FormEditingUtil {
return findComponentWithBinding(component, binding, null);
}
public static IComponent findComponentWithBinding(IComponent component, final String binding, @Nullable final IComponent exceptComponent) {
public static IComponent findComponentWithBinding(IComponent component,
final String binding,
@Nullable final IComponent exceptComponent) {
// Check that binding is unique
final Ref<IComponent> boundComponent = new Ref<IComponent>();
iterate(
component,
new ComponentVisitor() {
public boolean visit(final IComponent component) {
if(component != exceptComponent && binding.equals(component.getBinding())) {
if (component != exceptComponent && binding.equals(component.getBinding())) {
boundComponent.set(component);
return false;
}
@@ -419,10 +423,10 @@ public final class FormEditingUtil {
RadComponent component = getRadComponentAt(rootContainer, x, y);
if (isNullOrRoot(component) && epsilon > 0) {
// try to find component near specified location
component = getRadComponentAt(rootContainer, x-epsilon, y-epsilon);
if (isNullOrRoot(component)) component = getRadComponentAt(rootContainer, x-epsilon, y+epsilon);
if (isNullOrRoot(component)) component = getRadComponentAt(rootContainer, x+epsilon, y-epsilon);
if (isNullOrRoot(component)) component = getRadComponentAt(rootContainer, x+epsilon, y+epsilon);
component = getRadComponentAt(rootContainer, x - epsilon, y - epsilon);
if (isNullOrRoot(component)) component = getRadComponentAt(rootContainer, x - epsilon, y + epsilon);
if (isNullOrRoot(component)) component = getRadComponentAt(rootContainer, x + epsilon, y - epsilon);
if (isNullOrRoot(component)) component = getRadComponentAt(rootContainer, x + epsilon, y + epsilon);
}
if (component != null) {
@@ -447,9 +451,9 @@ public final class FormEditingUtil {
}
public static IRootContainer getRoot(IComponent component) {
while(component != null) {
while (component != null) {
if (component.getParentContainer() instanceof IRootContainer) {
return (IRootContainer) component.getParentContainer();
return (IRootContainer)component.getParentContainer();
}
component = component.getParentContainer();
}
@@ -459,7 +463,7 @@ public final class FormEditingUtil {
/**
* Iterates component and its children (if any)
*/
public static void iterate(final IComponent component, final ComponentVisitor visitor){
public static void iterate(final IComponent component, final ComponentVisitor visitor) {
iterateImpl(component, visitor);
}
@@ -507,9 +511,9 @@ public final class FormEditingUtil {
public static Locale[] collectUsedLocales(final Module module, final IRootContainer rootContainer) {
final Set<Locale> locales = new HashSet<Locale>();
final PropertiesReferenceManager propManager = PropertiesReferenceManager.getInstance(module.getProject());
for(String bundleName: collectUsedBundleNames(rootContainer)) {
for (String bundleName : collectUsedBundleNames(rootContainer)) {
List<PropertiesFile> propFiles = propManager.findPropertiesFiles(module, bundleName.replace('/', '.'));
for(PropertiesFile propFile: propFiles) {
for (PropertiesFile propFile : propFiles) {
locales.add(propFile.getLocale());
}
}
@@ -528,9 +532,9 @@ public final class FormEditingUtil {
public void run() {
if (!GridChangeUtil.canDeleteCells(container, cells, isRow)) {
Set<RadComponent> componentsInColumn = new HashSet<RadComponent>();
for(RadComponent component: container.getComponents()) {
for (RadComponent component : container.getComponents()) {
GridConstraints c = component.getConstraints();
for(int cell: cells) {
for (int cell : cells) {
if (c.contains(isRow, cell)) {
componentsInColumn.add(component);
break;
@@ -545,7 +549,7 @@ public final class FormEditingUtil {
final int rc = Messages.showYesNoDialog(editor, message,
isRow ? UIDesignerBundle.message("delete.row.title")
: UIDesignerBundle.message("delete.column.title"), Messages.getQuestionIcon());
: UIDesignerBundle.message("delete.column.title"), Messages.getQuestionIcon());
if (rc != DialogWrapper.OK_EXIT_CODE) {
return;
}
@@ -554,7 +558,7 @@ public final class FormEditingUtil {
}
}
for(int cell: cells) {
for (int cell : cells) {
container.getGridLayoutManager().deleteGridCells(container, cell, isRow);
}
editor.refreshAndSave(true);
@@ -566,8 +570,8 @@ public final class FormEditingUtil {
}
/**
* @param rootContainer
* @return id
* @param rootContainer
*/
public static String generateId(final RadRootContainer rootContainer) {
while (true) {
@@ -582,9 +586,9 @@ public final class FormEditingUtil {
* @return {@link com.intellij.uiDesigner.designSurface.GuiEditor} from the context. Can be <code>null</code>.
*/
@Nullable
public static GuiEditor getEditorFromContext(@NotNull final DataContext context){
public static GuiEditor getEditorFromContext(@NotNull final DataContext context) {
final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
if(editor instanceof UIFormEditor){
if (editor instanceof UIFormEditor) {
return ((UIFormEditor)editor).getEditor();
}
else {
@@ -592,7 +596,8 @@ public final class FormEditingUtil {
}
}
@Nullable public static GuiEditor getActiveEditor(final DataContext context){
@Nullable
public static GuiEditor getActiveEditor(final DataContext context) {
Project project = PlatformDataKeys.PROJECT.getData(context);
if (project == null) {
return null;
@@ -605,11 +610,10 @@ public final class FormEditingUtil {
}
/**
*
* @param componentToAssignBinding
* @param binding
* @param component topmost container where to find duplicate binding. In most cases
* it should be {@link com.intellij.uiDesigner.designSurface.GuiEditor#getRootContainer()}
* @param component topmost container where to find duplicate binding. In most cases
* it should be {@link com.intellij.uiDesigner.designSurface.GuiEditor#getRootContainer()}
*/
public static boolean isBindingUnique(
final IComponent componentToAssignBinding,
@@ -633,7 +637,7 @@ public final class FormEditingUtil {
@Nullable
public static RadContainer getSelectionParent(final List<RadComponent> selection) {
RadContainer parent = null;
for(RadComponent c: selection) {
for (RadComponent c : selection) {
if (parent == null) {
parent = c.getParent();
}
@@ -651,17 +655,17 @@ public final class FormEditingUtil {
int maxRow = 0;
int maxCol = 0;
for(RadComponent c: selection) {
for (RadComponent c : selection) {
minRow = Math.min(minRow, c.getConstraints().getRow());
minCol = Math.min(minCol, c.getConstraints().getColumn());
maxRow = Math.max(maxRow, c.getConstraints().getRow() + c.getConstraints().getRowSpan());
maxCol = Math.max(maxCol, c.getConstraints().getColumn() + c.getConstraints().getColSpan());
}
return new Rectangle(minCol, minRow, maxCol-minCol, maxRow-minRow);
return new Rectangle(minCol, minRow, maxCol - minCol, maxRow - minRow);
}
public static boolean isComponentSwitchedInView(@NotNull RadComponent component) {
while(component.getParent() != null) {
while (component.getParent() != null) {
if (!component.getParent().getLayoutManager().isSwitchedToChild(component.getParent(), component)) {
return false;
}
@@ -680,7 +684,7 @@ public final class FormEditingUtil {
public static boolean selectComponent(final GuiEditor editor, @NotNull final RadComponent component) {
boolean hasTab = false;
RadComponent parent = component;
while(parent.getParent() != null) {
while (parent.getParent() != null) {
if (parent.getParent().getLayoutManager().switchContainerToChild(parent.getParent(), parent)) {
hasTab = true;
}
@@ -724,8 +728,8 @@ public final class FormEditingUtil {
}
builder.beginUpdateSelection();
try {
clearSelection((RadContainer) getRoot(component));
for(RadComponent aComponent: components) {
clearSelection((RadContainer)getRoot(component));
for (RadComponent aComponent : components) {
selectComponent(editor, aComponent);
}
}
@@ -736,12 +740,12 @@ public final class FormEditingUtil {
}
public static boolean isDropOnChild(final DraggedComponentList draggedComponentList,
final ComponentDropLocation location) {
final ComponentDropLocation location) {
if (location.getContainer() == null) {
return false;
}
for(RadComponent component: draggedComponentList.getComponents()) {
for (RadComponent component : draggedComponentList.getComponents()) {
if (isChild(location.getContainer(), component)) {
return true;
}
@@ -750,7 +754,7 @@ public final class FormEditingUtil {
}
private static boolean isChild(RadContainer maybeChild, RadComponent maybeParent) {
while(maybeChild != null) {
while (maybeChild != null) {
if (maybeParent == maybeChild) {
return true;
}
@@ -779,30 +783,31 @@ public final class FormEditingUtil {
public static int adjustForGap(final RadContainer container, final int cellIndex, final boolean isRow, final int delta) {
if (container.getGridLayoutManager().isGapCell(container, isRow, cellIndex)) {
return cellIndex+delta;
return cellIndex + delta;
}
return cellIndex;
}
public static int prevRow(final RadContainer container, final int row) {
return adjustForGap(container, row-1, true, -1);
return adjustForGap(container, row - 1, true, -1);
}
public static int nextRow(final RadContainer container, final int row) {
return adjustForGap(container, row+1, true, 1);
return adjustForGap(container, row + 1, true, 1);
}
public static int prevCol(final RadContainer container, final int col) {
return adjustForGap(container, col-1, false, -1);
return adjustForGap(container, col - 1, false, -1);
}
public static int nextCol(final RadContainer container, final int col) {
return adjustForGap(container, col+1, false, 1);
return adjustForGap(container, col + 1, false, 1);
}
@Nullable public static IButtonGroup findGroupForComponent(final IRootContainer radRootContainer, @NotNull final IComponent component) {
for(IButtonGroup group: radRootContainer.getButtonGroups()) {
for(String id: group.getComponentIds()) {
@Nullable
public static IButtonGroup findGroupForComponent(final IRootContainer radRootContainer, @NotNull final IComponent component) {
for (IButtonGroup group : radRootContainer.getButtonGroups()) {
for (String id : group.getComponentIds()) {
if (component.getId().equals(id)) {
return group;
}
@@ -812,7 +817,7 @@ public final class FormEditingUtil {
}
public static void remapToActionTargets(final List<RadComponent> selection) {
for(int i=0; i<selection.size(); i++) {
for (int i = 0; i < selection.size(); i++) {
final RadComponent c = selection.get(i);
if (c.getParent() != null) {
selection.set(i, c.getParent().getActionTargetComponent(c));
@@ -868,7 +873,7 @@ public final class FormEditingUtil {
});
}
public static void clearSelection(@NotNull final RadContainer container){
public static void clearSelection(@NotNull final RadContainer container) {
container.setSelected(false);
for (int i = 0; i < container.getComponentCount(); i++) {
@@ -887,6 +892,7 @@ public final class FormEditingUtil {
* <code>container</code>. The method goes recursively through the hierarchy
* of components. Note, that if <code>container</code> itself has <code>id</code>
* then the method immediately retuns it.
*
* @return the found component.
*/
@Nullable
@@ -899,9 +905,9 @@ public final class FormEditingUtil {
}
final IContainer uiContainer = (IContainer)component;
for (int i=0; i < uiContainer.getComponentCount(); i++){
for (int i = 0; i < uiContainer.getComponentCount(); i++) {
final IComponent found = findComponent(uiContainer.getComponent(i), id);
if (found != null){
if (found != null) {
return found;
}
}
@@ -914,7 +920,7 @@ public final class FormEditingUtil {
.findClass(classToBindName.replace('$', '.'), module.getModuleWithDependenciesScope());
}
public interface ComponentVisitor <Type extends IComponent>{
public interface ComponentVisitor<Type extends IComponent> {
/**
* @return true if iteration should continue
*/
@@ -75,7 +75,7 @@ public final class Painter {
private Painter() {
}
public static void paintComponentDecoration(final GuiEditor editor, final RadComponent component, final Graphics g){
public static void paintComponentDecoration(final GuiEditor editor, final RadComponent component, final Graphics g) {
// Collect selected components and paint decoration for non selected components
final ArrayList<RadComponent> selection = new ArrayList<RadComponent>();
final Rectangle layeredPaneRect = editor.getLayeredPane().getVisibleRect();
@@ -83,24 +83,24 @@ public final class Painter {
component,
new FormEditingUtil.ComponentVisitor<RadComponent>() {
public boolean visit(final RadComponent component) {
if(!component.getDelegee().isShowing()){ // Skip invisible components
if (!component.getDelegee().isShowing()) { // Skip invisible components
return true;
}
final Shape oldClip = g.getClip();
final RadContainer parent = component.getParent();
if(parent != null){
if (parent != null) {
final Point p = SwingUtilities.convertPoint(component.getDelegee(), 0, 0, editor.getLayeredPane());
final Rectangle visibleRect = layeredPaneRect.intersection(new Rectangle(p.x, p.y, parent.getWidth(), parent.getHeight()));
g.setClip(visibleRect);
}
if(component.isSelected()){ // we will paint selection later
if (component.isSelected()) { // we will paint selection later
selection.add(component);
}
else{
else {
paintComponentBoundsImpl(editor, component, g);
}
paintGridOutline(editor, component, g);
if(parent != null){
if (parent != null) {
g.setClip(oldClip);
}
return true;
@@ -109,17 +109,17 @@ public final class Painter {
);
// Let's paint decoration for selected components
for(int i = selection.size() - 1; i >= 0; i--){
for (int i = selection.size() - 1; i >= 0; i--) {
final Shape oldClip = g.getClip();
final RadComponent c = selection.get(i);
final RadContainer parent = c.getParent();
if(parent != null){
if (parent != null) {
final Point p = SwingUtilities.convertPoint(c.getDelegee(), 0, 0, editor.getLayeredPane());
final Rectangle visibleRect = layeredPaneRect.intersection(new Rectangle(p.x, p.y, parent.getWidth(), parent.getHeight()));
g.setClip(visibleRect);
}
paintComponentBoundsImpl(editor, c, g);
if(parent != null){
if (parent != null) {
g.setClip(oldClip);
}
}
@@ -131,15 +131,15 @@ public final class Painter {
* Method does nothing if the <code>component</code> is not an instance
* of <code>RadContainer</code>.
*/
private static void paintComponentBoundsImpl(final GuiEditor editor, @NotNull final RadComponent component, final Graphics g){
if (!(component instanceof RadContainer) && !(component instanceof RadNestedForm) && !component.isDragBorder()){
private static void paintComponentBoundsImpl(final GuiEditor editor, @NotNull final RadComponent component, final Graphics g) {
if (!(component instanceof RadContainer) && !(component instanceof RadNestedForm) && !component.isDragBorder()) {
return;
}
boolean highlightBoundaries = (getDesignTimeInsets(component) > 2);
if (component instanceof RadContainer && !component.isDragBorder()) {
RadContainer container = (RadContainer) component;
RadContainer container = (RadContainer)component;
if (!highlightBoundaries && (container.getBorderTitle() != null || container.getBorderType() != BorderType.NONE)) {
return;
}
@@ -151,9 +151,9 @@ public final class Painter {
editor.getRootContainer().getDelegee()
);
g.translate(point.x, point.y);
try{
try {
if (component.isDragBorder()) {
Graphics2D g2d = (Graphics2D) g;
Graphics2D g2d = (Graphics2D)g;
g2d.setColor(LightColors.YELLOW);
g2d.setStroke(new BasicStroke(2.0f));
g2d.translate(1, 1);
@@ -171,13 +171,14 @@ public final class Painter {
if (component.isDragBorder()) {
g.translate(-1, -1);
}
}finally{
}
finally {
g.translate(-point.x, -point.y);
}
}
private static int getDesignTimeInsets(RadComponent component) {
while(component != null) {
while (component != null) {
Integer designTimeInsets = (Integer)component.getDelegee().getClientProperty(GridLayoutManager.DESIGN_TIME_INSETS);
if (designTimeInsets != null) {
return designTimeInsets.intValue();
@@ -190,15 +191,15 @@ public final class Painter {
/**
* This method paints grid bounds for "grid" containers
*/
public static void paintGridOutline(final GuiEditor editor, @NotNull final RadComponent component, final Graphics g){
public static void paintGridOutline(final GuiEditor editor, @NotNull final RadComponent component, final Graphics g) {
if (!editor.isShowGrid()) {
return;
}
if (!(component instanceof RadContainer)){
if (!(component instanceof RadContainer)) {
return;
}
final RadContainer container = (RadContainer)component;
if(!container.getLayoutManager().isGrid()){
if (!container.getLayoutManager().isGrid()) {
return;
}
@@ -218,13 +219,14 @@ public final class Painter {
editor.getRootContainer().getDelegee()
);
g.translate(point.x, point.y);
try{
try {
// Paint grid
if (container.getWidth() > 0 && container.getHeight() > 0) {
Image gridImage = CachedGridImage.getGridImage(container);
g.drawImage(gridImage, 0, 0, null);
}
}finally{
}
finally {
g.translate(-point.x, -point.y);
}
}
@@ -233,7 +235,7 @@ public final class Painter {
* Paints selection for the specified <code>component</code>.
*/
public static void paintSelectionDecoration(@NotNull RadComponent component, Graphics g,
boolean focused){
boolean focused) {
if (component.isSelected()) {
if (focused) {
g.setColor(Color.BLUE);
@@ -246,6 +248,22 @@ public final class Painter {
g.fillRect(point.x - R, point.y - R, 2 * R + 1, 2 * R + 1);
}
}
else if (component.getWidth() < FormEditingUtil.EMPTY_COMPONENT_SIZE || component.getHeight() < FormEditingUtil.EMPTY_COMPONENT_SIZE) {
Graphics2D g2d = (Graphics2D)g;
Composite oldComposite = g2d.getComposite();
Stroke oldStroke = g2d.getStroke();
Color oldColor = g2d.getColor();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f));
g2d.setStroke(new BasicStroke(0.7f));
g2d.setColor(Color.black);
g2d.drawRect(0, 0, Math.max(component.getWidth(), FormEditingUtil.EMPTY_COMPONENT_SIZE),
Math.max(component.getHeight(), FormEditingUtil.EMPTY_COMPONENT_SIZE));
g2d.setComposite(oldComposite);
g2d.setStroke(oldStroke);
g2d.setColor(oldColor);
}
}
/**
@@ -264,36 +282,36 @@ public final class Painter {
}
*/
final int width=component.getWidth();
final int height=component.getHeight();
final int width = component.getWidth();
final int height = component.getHeight();
final Point[] points = getPoints(width, height);
if (isInside(x, y, points[SE])) {
return EAST_MASK | SOUTH_MASK;
}
else if (isInside(x,y,points[NW])) {
else if (isInside(x, y, points[NW])) {
return WEST_MASK | NORTH_MASK;
}
else if(isInside(x,y,points[N])){
else if (isInside(x, y, points[N])) {
return NORTH_MASK;
}
else if(isInside(x,y,points[NE])){
else if (isInside(x, y, points[NE])) {
return EAST_MASK | NORTH_MASK;
}
else if (isInside(x, y, points[W])){
else if (isInside(x, y, points[W])) {
return WEST_MASK;
}
else if (isInside(x, y, points[E])){
else if (isInside(x, y, points[E])) {
return EAST_MASK;
}
else if (isInside(x, y, points[SW])){
else if (isInside(x, y, points[SW])) {
return WEST_MASK | SOUTH_MASK;
}
else if (isInside(x, y, points[S])){
else if (isInside(x, y, points[S])) {
return SOUTH_MASK;
}
else{
else {
return 0;
}
}
@@ -303,7 +321,7 @@ public final class Painter {
}
@JdkConstants.CursorType
public static int getResizeCursor(final int resizeMask){
public static int getResizeCursor(final int resizeMask) {
if (resizeMask == (WEST_MASK | NORTH_MASK)) {
return Cursor.NW_RESIZE_CURSOR;
}
@@ -354,13 +372,13 @@ public final class Painter {
Rectangle[] allBounds = new Rectangle[components.size()];
int lastTop = -1;
int minLeft = Integer.MAX_VALUE;
for(int i=0; i<components.size(); i++) {
for (int i = 0; i < components.size(); i++) {
final Rectangle rc = SwingUtilities.convertRectangle(
components.get(i).getParent().getDelegee(),
components.get(i).getBounds(),
rootContainer.getDelegee()
);
allBounds [i] = rc;
allBounds[i] = rc;
minLeft = Math.min(minLeft, rc.x);
if (i == 0) {
@@ -371,7 +389,7 @@ public final class Painter {
}
}
Graphics2D g2d = (Graphics2D) g;
Graphics2D g2d = (Graphics2D)g;
Stroke oldStroke = g2d.getStroke();
g2d.setStroke(new BasicStroke(2.0f));
g2d.setColor(new Color(104, 107, 130));
@@ -379,42 +397,42 @@ public final class Painter {
// all items in group have same Y
int left = Integer.MAX_VALUE;
int right = Integer.MIN_VALUE;
for(Rectangle rc: allBounds) {
for (Rectangle rc : allBounds) {
final int midX = (int)rc.getCenterX();
left = Math.min(left, midX);
right = Math.max(right, midX);
g2d.drawLine(midX, lastTop-8, midX, lastTop);
g2d.drawLine(midX, lastTop - 8, midX, lastTop);
}
g2d.drawLine(left, lastTop-8, right, lastTop-8);
g2d.drawLine(left, lastTop - 8, right, lastTop - 8);
}
else {
int top = Integer.MAX_VALUE;
int bottom = Integer.MIN_VALUE;
for(Rectangle rc: allBounds) {
for (Rectangle rc : allBounds) {
final int midY = (int)rc.getCenterY();
top = Math.min(top, midY);
bottom = Math.max(bottom, midY);
g2d.drawLine(minLeft-8, midY, rc.x, midY);
g2d.drawLine(minLeft - 8, midY, rc.x, midY);
}
g2d.drawLine(minLeft-8, top, minLeft-8, bottom);
g2d.drawLine(minLeft - 8, top, minLeft - 8, bottom);
}
g2d.setStroke(oldStroke);
}
public static void paintComponentTag(final RadComponent component, final Graphics g) {
if (component instanceof RadContainer) return;
for(IProperty prop: component.getModifiedProperties()) {
for (IProperty prop : component.getModifiedProperties()) {
if (prop.getName().equals(SwingProperties.TEXT)) {
final Object desc = prop.getPropertyValue(component);
if (!(desc instanceof StringDescriptor) || ((StringDescriptor) desc).getValue() == null ||
((StringDescriptor) desc).getValue().length() > 0) {
if (!(desc instanceof StringDescriptor) || ((StringDescriptor)desc).getValue() == null ||
((StringDescriptor)desc).getValue().length() > 0) {
return;
}
}
else if (prop.getName().equals(SwingProperties.MODEL)) {
// don't paint tags on non-empty lists
final Object value = prop.getPropertyValue(component);
if (value instanceof String[] && ((String[]) value).length > 0) {
if (value instanceof String[] && ((String[])value).length > 0) {
return;
}
}
@@ -429,15 +447,15 @@ public final class Painter {
String className = component.getComponentClassName();
int pos = className.lastIndexOf('.');
if (pos >= 0) {
tagBuilder.append(className.substring(pos+1));
tagBuilder.append(className.substring(pos + 1));
}
else {
tagBuilder.append(className);
}
final Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(tagBuilder.toString(), g);
Graphics2D g2d = (Graphics2D) g;
Graphics2D g2d = (Graphics2D)g;
g2d.setColor(Color.BLUE);
g2d.fillRect(0, 0, (int) stringBounds.getWidth(), (int) stringBounds.getHeight());
g2d.fillRect(0, 0, (int)stringBounds.getWidth(), (int)stringBounds.getHeight());
g2d.setColor(Color.WHITE);
g.drawString(tagBuilder.toString(), 0, g.getFontMetrics().getAscent());
}