}
if (component instanceof RadContainer) {
+ component.refresh();
+
final RadContainer container = (RadContainer)component;
for (int i = container.getComponentCount() - 1; i >= 0; i--) {
refreshImpl(container.getComponent(i));
private void fireHierarchyChanged() {
final HierarchyChangeListener[] listeners = myListenerList.getListeners(HierarchyChangeListener.class);
- for(final HierarchyChangeListener listener : listeners) {
+ for (final HierarchyChangeListener listener : listeners) {
listener.hierarchyChanged();
}
}
/**
* @return the component which represents layer with active decorators
- * such as grid edit controls, inplace editors, etc.
+ * such as grid edit controls, inplace editors, etc.
*/
public InplaceEditingLayer getInplaceEditingLayer() {
return myInplaceEditingLayer;
public boolean visit(final IComponent component) {
final RadComponent radComponent = (RadComponent)component;
boolean componentModified = false;
- for(IProperty prop: component.getModifiedProperties()) {
+ for (IProperty prop : component.getModifiedProperties()) {
if (prop instanceof IntroStringProperty) {
- IntroStringProperty strProp = (IntroStringProperty) prop;
+ IntroStringProperty strProp = (IntroStringProperty)prop;
componentModified = strProp.refreshValue(radComponent) || componentModified;
}
}
}
if (component.getParentContainer() instanceof RadTabbedPane) {
- componentModified = ((RadTabbedPane) component.getParentContainer()).refreshChildTitle(radComponent) || componentModified;
+ componentModified = ((RadTabbedPane)component.getParentContainer()).refreshChildTitle(radComponent) || componentModified;
}
if (componentModified) {
anythingModified.set(Boolean.TRUE);
}
public void setDesignTimeInsets(final int insets) {
- Integer oldInsets = (Integer) myRootContainer.getDelegee().getClientProperty(GridLayoutManager.DESIGN_TIME_INSETS);
+ Integer oldInsets = (Integer)myRootContainer.getDelegee().getClientProperty(GridLayoutManager.DESIGN_TIME_INSETS);
if (oldInsets == null || oldInsets.intValue() != insets) {
myRootContainer.getDelegee().putClientProperty(GridLayoutManager.DESIGN_TIME_INSETS, insets);
revalidateRecursive(myRootContainer.getDelegee());
}
private static void revalidateRecursive(final JComponent component) {
- for(Component child: component.getComponents()) {
+ for (Component child : component.getComponents()) {
if (child instanceof JComponent) {
revalidateRecursive((JComponent)child);
}
/**
* Creates and sets new <code>RadRootContainer</code>
+ *
* @param keepSelection if true, the GUI designer tries to preserve the selection state after reload.
*/
public void readFromFile(final boolean keepSelection) {
}
showInvalidCard(original);
}
- catch(final LinkageError exc) {
+ catch (final LinkageError exc) {
showInvalidCard(exc);
}
}
FormEditingUtil.iterate(getRootContainer(), new FormEditingUtil.ComponentVisitor() {
public boolean visit(final IComponent component) {
if (component instanceof RadTabbedPane) {
- RadTabbedPane tabbedPane = (RadTabbedPane) component;
+ RadTabbedPane tabbedPane = (RadTabbedPane)component;
RadComponent c = tabbedPane.getSelectedTab();
if (c != null) {
result.put(tabbedPane.getId(), c.getId());
FormEditingUtil.iterate(getRootContainer(), new FormEditingUtil.ComponentVisitor() {
public boolean visit(final IComponent component) {
if (component instanceof RadTabbedPane) {
- RadTabbedPane tabbedPane = (RadTabbedPane) component;
+ RadTabbedPane tabbedPane = (RadTabbedPane)component;
String selectedTabId = tabbedPaneSelectedTabs.get(tabbedPane.getId());
if (selectedTabId != null) {
- for(RadComponent c: tabbedPane.getComponents()) {
+ for (RadComponent c : tabbedPane.getComponents()) {
if (c.getId().equals(selectedTabId)) {
tabbedPane.selectTab(c);
break;
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
if (orientation == SwingConstants.HORIZONTAL) {
- return visibleRect.width-10;
+ return visibleRect.width - 10;
}
- return visibleRect.height-10;
+ return visibleRect.height - 10;
}
public boolean getScrollableTracksViewportWidth() {
}
private class MyPaletteKeyListener extends KeyAdapter {
- @Override public void keyPressed(KeyEvent e) {
+ @Override
+ public void keyPressed(KeyEvent e) {
PaletteManager paletteManager = PaletteManager.getInstance(getProject());
if (e.getKeyCode() == KeyEvent.VK_SHIFT && paletteManager.getActiveItem(ComponentItem.class) != null && isActiveEditor()) {
setDesignTimeInsets(12);
}
}
- @Override public void keyReleased(KeyEvent e) {
+ @Override
+ public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
setDesignTimeInsets(2);
}
/**
* Whether the component selected or not. Value is java.lang.Boolean
*/
- @NonNls public static final String PROP_SELECTED="selected";
+ @NonNls public static final String PROP_SELECTED = "selected";
/**
* Change notification for this property is fired when the constraints of a component
* class of delegee and specified ID.
*
* @param aClass class of the compoent's delegee
- * @param id id of the compoent inside the form. <code>id</code>
- * should be a unique atring inside the form.
+ * @param id id of the compoent inside the form. <code>id</code>
+ * should be a unique atring inside the form.
*/
public RadComponent(final Module module, @NotNull final Class aClass, @NotNull final String id) {
myModule = module;
return myLoadingProperties;
}
- @NotNull public final Project getProject() {
+ @NotNull
+ public final Project getProject() {
return myModule.getProject();
}
* @return the component's id. It is unique within the form.
*/
@NotNull
- public final String getId(){
+ public final String getId() {
return myId;
}
- public final String getBinding(){
+ public final String getBinding() {
return myBinding;
}
- public final void setBinding(final String binding){
+ public final void setBinding(final String binding) {
//TODO[anton,vova]: check that binding is a valid java identifier!!!
myBinding = binding;
}
/**
* @return Swing delegee component. The <code>RadComponent</code> has the same
- * delegee during all its life.
+ * delegee during all its life.
*/
@NotNull
- public final JComponent getDelegee(){
+ public final JComponent getDelegee() {
return myDelegee;
}
*
* @param x x in delegee coordinate system
* @param y y in delegee coordinate system
- *
* @return inplace property for the <code>RadComponent</code> if any.
- * The method returns <code>null</code> if the component doesn't have
- * any inplace property. Please not the method can return different
- * instances of the property for each invokation.
+ * The method returns <code>null</code> if the component doesn't have
+ * any inplace property. Please not the method can return different
+ * instances of the property for each invokation.
*/
@Nullable
- public Property getInplaceProperty(final int x, final int y){
+ public Property getInplaceProperty(final int x, final int y) {
return getDefaultInplaceProperty();
}
*
* @param x x in delegee coordinate system
* @param y y in delegee coordinate system
- *
* @return area where editor component is located. This is the hint to the
- * designer. Designer can use or not this rectangle.
+ * designer. Designer can use or not this rectangle.
*/
@Nullable
- public Rectangle getInplaceEditorBounds(@NotNull final Property property, final int x, final int y){
+ public Rectangle getInplaceEditorBounds(@NotNull final Property property, final int x, final int y) {
return null;
}
@NotNull
- public final Class getComponentClass(){
+ public final Class getComponentClass() {
return myClass;
}
return myClass.getName();
}
- public final Object getCustomLayoutConstraints(){
+ public final Object getCustomLayoutConstraints() {
return myCustomLayoutConstraints;
}
- public final void setCustomLayoutConstraints(final Object customConstraints){
+ public final void setCustomLayoutConstraints(final Object customConstraints) {
myCustomLayoutConstraints = customConstraints;
}
}
}
- public final boolean hasDragger(){
+ public final boolean hasDragger() {
return myHasDragger;
}
- public final void setDragger(final boolean hasDragger){
+ public final void setDragger(final boolean hasDragger) {
myHasDragger = hasDragger;
}
myDefaultBinding = defaultBinding;
}
- public final void addPropertyChangeListener(final PropertyChangeListener l){
+ public final void addPropertyChangeListener(final PropertyChangeListener l) {
final PropertyChangeListener[] propertyChangeListeners = myChangeSupport.getPropertyChangeListeners();
- for(PropertyChangeListener listener: propertyChangeListeners) {
+ for (PropertyChangeListener listener : propertyChangeListeners) {
assert listener != l;
}
myChangeSupport.addPropertyChangeListener(l);
}
- public final void removePropertyChangeListener(final PropertyChangeListener l){
+ public final void removePropertyChangeListener(final PropertyChangeListener l) {
myChangeSupport.removePropertyChangeListener(l);
}
@NotNull final String propertyName,
final Object oldValue,
final Object newValue
- ){
+ ) {
myChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
}
* @return component's constarints.
*/
@NotNull
- public final GridConstraints getConstraints(){
+ public final GridConstraints getConstraints() {
return myConstraints;
}
- public final RadContainer getParent(){
+ public final RadContainer getParent() {
return myParent;
}
- public final void setParent(final RadContainer parent){
+ public final void setParent(final RadContainer parent) {
myParent = parent;
}
- public boolean isSelected(){
+ public boolean isSelected() {
return mySelected;
}
- public void setSelected(final boolean selected){
+ public void setSelected(final boolean selected) {
if (mySelected != selected) {
mySelected = selected;
firePropertyChanged(PROP_SELECTED, !mySelected, mySelected);
/**
* @see JComponent#getClientProperty(Object)
*/
- public final Object getClientProperty(@NotNull final Object key){
+ public final Object getClientProperty(@NotNull final Object key) {
return myDelegee.getClientProperty(key);
}
/**
* @see JComponent#putClientProperty(Object, Object)
*/
- public final void putClientProperty(@NotNull final Object key, final Object value){
+ public final void putClientProperty(@NotNull final Object key, final Object value) {
myDelegee.putClientProperty(key, value);
}
return myDelegee.getY();
}
- public final void setLocation(final Point location){
+ public final void setLocation(final Point location) {
myDelegee.setLocation(location);
}
- public final void shift(final int dx, final int dy){
+ public final void shift(final int dx, final int dy) {
myDelegee.setLocation(myDelegee.getX() + dx, myDelegee.getY() + dy);
}
- public final int getWidth(){
+ public final int getWidth() {
return myDelegee.getWidth();
}
- public final int getHeight(){
+ public final int getHeight() {
return myDelegee.getHeight();
}
myDelegee.setBounds(bounds);
}
- public final Dimension getMinimumSize(){
+ public final Dimension getMinimumSize() {
return Util.getMinimumSize(myDelegee, myConstraints, false);
}
- public final Dimension getPreferredSize(){
+ public final Dimension getPreferredSize() {
return Util.getPreferredSize(myDelegee, myConstraints, false);
}
+ public void refresh() {
+ }
+
public final void revalidate() {
RadContainer theContainer = null;
- for (RadContainer container = this instanceof RadContainer ? (RadContainer)this : getParent(); container != null; container = container.getParent()) {
+ for (RadContainer container = this instanceof RadContainer ? (RadContainer)this : getParent();
+ container != null;
+ container = container.getParent()) {
final RadContainer parent = container.getParent();
if (parent != null && parent.isXY()) {
final Dimension size = container.getSize();
return this;
}
- public void processMouseEvent(final MouseEvent event) {}
+ public void processMouseEvent(final MouseEvent event) {
+ }
@Nullable
public EventProcessor getEventProcessor(final MouseEvent event) {
/**
* Serializes component's ID
*/
- protected final void writeId(final XmlWriter writer){
+ protected final void writeId(final XmlWriter writer) {
writer.addAttribute("id", getId());
}
/**
* Serializes component's class
*/
- protected final void writeClass(final XmlWriter writer){
+ protected final void writeClass(final XmlWriter writer) {
writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_CLASS, getComponentClass().getName());
}
}
}
- protected final void writeBinding(final XmlWriter writer){
+ protected final void writeBinding(final XmlWriter writer) {
// Binding
- if (getBinding() != null){
+ if (getBinding() != null) {
writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_BINDING, getBinding());
}
if (isCustomCreate()) {
}
}
- protected void writeConstraints(final XmlWriter writer){
+ protected void writeConstraints(final XmlWriter writer) {
writer.startElement("constraints");
try {
if (getParent() != null) {
getParent().getLayoutManager().writeChildConstraints(writer, this);
}
- } finally {
+ }
+ finally {
writer.endElement(); // constraints
}
}
- protected final void writeProperties(final XmlWriter writer){
+ protected final void writeProperties(final XmlWriter writer) {
writer.startElement(UIFormXmlConstants.ELEMENT_PROPERTIES);
- try{
+ try {
final IntrospectedProperty[] introspectedProperties =
getPalette().getIntrospectedProperties(this);
- for(final IntrospectedProperty property : introspectedProperties) {
+ for (final IntrospectedProperty property : introspectedProperties) {
if (isMarkedAsModified(property)) {
final Object value = property.getValue(this);
if (value != null) {
}
}
}
- }finally{
+ }
+ finally {
writer.endElement(); // properties
}
writeClientProperties(writer);
boolean haveClientProperties = false;
try {
ClientPropertiesProperty cpp = ClientPropertiesProperty.getInstance(getProject());
- for(Property prop: cpp.getChildren(this)) {
- ClientPropertyProperty clientProp = (ClientPropertyProperty) prop;
+ for (Property prop : cpp.getChildren(this)) {
+ ClientPropertyProperty clientProp = (ClientPropertyProperty)prop;
final Object value = getDelegee().getClientProperty(clientProp.getName());
if (value != null) {
if (!haveClientProperties) {
public IProperty[] getModifiedProperties() {
IntrospectedProperty[] props = getPalette().getIntrospectedProperties(this);
ArrayList<IProperty> result = new ArrayList<IProperty>();
- for(IntrospectedProperty prop: props) {
+ for (IntrospectedProperty prop : props) {
if (isMarkedAsModified(prop)) {
result.add(prop);
}
result = container;
}
else if (component instanceof Box.Filler) {
- Box.Filler filler = (Box.Filler) component;
+ Box.Filler filler = (Box.Filler)component;
if (filler.getMaximumSize().height == Short.MAX_VALUE) {
result = new RadVSpacer(null, id);
result.getConstraints().setVSizePolicy(GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW);
final IntrospectedProperty[] properties = context.getPalette().getIntrospectedProperties(component.getClass(),
result.getDelegee().getClass());
- for(IntrospectedProperty prop: properties) {
+ for (IntrospectedProperty prop : properties) {
if (component instanceof AbstractButton) {
- AbstractButton btn = (AbstractButton) component;
+ AbstractButton btn = (AbstractButton)component;
if (prop.getName().equals(SwingProperties.LABEL) && btn.getLabel().equals(btn.getText())) {
continue;
}
}
}
prop.importSnapshotValue(context, component, result);
-
}
if (component instanceof AbstractButton) {
- AbstractButton btn = (AbstractButton) component;
+ AbstractButton btn = (AbstractButton)component;
if (btn.getModel() instanceof DefaultButtonModel) {
- DefaultButtonModel model = (DefaultButtonModel) btn.getModel();
+ DefaultButtonModel model = (DefaultButtonModel)btn.getModel();
if (model.getGroup() != null) {
context.registerButtonGroup(model.getGroup());
}
if (component.getComponentCount() == 0) {
return false;
}
-
+
JComponent instance;
try {
instance = component.getClass().newInstance();
}
- catch(Exception ex) {
+ catch (Exception ex) {
return false;
}
return instance.getComponentCount() == component.getComponentCount();
public String getComponentTitle() {
Palette palette = Palette.getInstance(getModule().getProject());
IntrospectedProperty[] props = palette.getIntrospectedProperties(this);
- for(IntrospectedProperty prop: props) {
+ for (IntrospectedProperty prop : props) {
if (prop.getName().equals(SwingProperties.TEXT) && prop instanceof IntroStringProperty) {
- StringDescriptor value = (StringDescriptor) prop.getValue(this);
+ StringDescriptor value = (StringDescriptor)prop.getValue(this);
if (value != null) {
return "\"" + value.getResolvedValue() + "\"";
}
}
if (getParent() instanceof RadTabbedPane) {
- RadTabbedPane parentTabbedPane = (RadTabbedPane) getParent();
+ RadTabbedPane parentTabbedPane = (RadTabbedPane)getParent();
final StringDescriptor descriptor = parentTabbedPane.getChildTitle(this);
if (descriptor != null) {
if (descriptor.getResolvedValue() == null) {
protected RadLayoutManager myLayoutManager;
private LayoutManager myDelegeeLayout;
- public RadContainer(final Module module, final String id){
+ public RadContainer(final Module module, final String id) {
this(module, JPanel.class, id);
}
- public RadContainer(final Module module, final Class aClass, final String id){
+ public RadContainer(final Module module, final Class aClass, final String id) {
super(module, aClass, id);
myComponents = new ArrayList<RadComponent>();
setPalette(palette);
}
- @Nullable protected RadLayoutManager createInitialLayoutManager() {
+ @Nullable
+ protected RadLayoutManager createInitialLayoutManager() {
String defaultLayoutManager = UIFormXmlConstants.LAYOUT_INTELLIJ;
if (getModule() != null) {
final GuiDesignerConfiguration configuration = GuiDesignerConfiguration.getInstance(getModule().getProject());
// 1. We have to check whether user clicked inside border (if any) or not.
// In this case we have return inplace editor for border text
final Insets insets = getDelegee().getInsets(); // border insets
- if(
- x < insets.left || x > getWidth() - insets.right ||
- y < 0 || y > insets.top
- ){
+ if (
+ x < insets.left || x > getWidth() - insets.right ||
+ y < 0 || y > insets.top
+ ) {
return super.getInplaceProperty(x, y);
}
return new MyBorderTitleProperty();
}
- @Override @Nullable
+ @Override
+ @Nullable
public Property getDefaultInplaceProperty() {
return new MyBorderTitleProperty();
}
- @Override @Nullable
+ @Override
+ @Nullable
public Rectangle getDefaultInplaceEditorBounds() {
return getBorderInPlaceEditorBounds(new MyBorderTitleProperty());
}
public Rectangle getInplaceEditorBounds(final Property property, final int x, final int y) {
- if(property instanceof MyBorderTitleProperty){ // If this is our property
+ if (property instanceof MyBorderTitleProperty) { // If this is our property
return getBorderInPlaceEditorBounds(property);
}
return super.getInplaceEditorBounds(property, x, y);
);
}
- public final LayoutManager getLayout(){
+ public final LayoutManager getLayout() {
if (myDelegeeLayout != null) {
return myDelegeeLayout;
}
getDelegee().setLayout(layout);
if (layout instanceof AbstractLayout) {
- AbstractLayout aLayout = (AbstractLayout) layout;
- for (int i=0; i < getComponentCount(); i++) {
+ AbstractLayout aLayout = (AbstractLayout)layout;
+ for (int i = 0; i < getComponentCount(); i++) {
final RadComponent c = getComponent(i);
aLayout.addLayoutComponent(c.getDelegee(), c.getConstraints());
}
}
}
- public final boolean isXY(){
+ public final boolean isXY() {
return getLayout() instanceof XYLayoutManager;
}
/**
* @param component component to be added.
- *
- * @exception java.lang.IllegalArgumentException if <code>component</code> is <code>null</code>
- * @exception java.lang.IllegalArgumentException if <code>component</code> already exist in the
- * container
+ * @throws java.lang.IllegalArgumentException
+ * if <code>component</code> is <code>null</code>
+ * @throws java.lang.IllegalArgumentException
+ * if <code>component</code> already exist in the
+ * container
*/
public final void addComponent(@NotNull final RadComponent component, int index) {
if (myComponents.contains(component)) {
final RadComponent[] oldChildren = myComponents.toArray(new RadComponent[myComponents.size()]);
// Remove from old parent
- final RadContainer oldParent=component.getParent();
- if(oldParent!=null) {
+ final RadContainer oldParent = component.getParent();
+ if (oldParent != null) {
oldParent.removeComponent(component);
}
* of invalid Swing hierarchy.
*
* @param component component to be removed.
- *
- * @exception java.lang.IllegalArgumentException if <code>component</code>
- * is <code>null</code>
- * @exception java.lang.IllegalArgumentException if <code>component</code>
- * doesn't exist in the container
+ * @throws java.lang.IllegalArgumentException
+ * if <code>component</code>
+ * is <code>null</code>
+ * @throws java.lang.IllegalArgumentException
+ * if <code>component</code>
+ * doesn't exist in the container
*/
- public final void removeComponent(@NotNull final RadComponent component){
- if(!myComponents.contains(component)){
+ public final void removeComponent(@NotNull final RadComponent component) {
+ if (!myComponents.contains(component)) {
//noinspection HardCodedStringLiteral
throw new IllegalArgumentException("component is not added: " + component);
}
}
public RadComponent findComponentInRect(final int startRow, final int startCol, final int rowSpan, final int colSpan) {
- for(int r=startRow; r < startRow + rowSpan; r++) {
- for(int c=startCol; c < startCol + colSpan; c++) {
+ for (int r = startRow; r < startRow + rowSpan; r++) {
+ for (int c = startCol; c < startCol + colSpan; c++) {
final RadComponent result = getComponentAtGrid(r, c);
if (result != null) {
return result;
/**
* @return border's type.
- *
* @see com.intellij.uiDesigner.shared.BorderType
*/
@NotNull
- public final BorderType getBorderType(){
+ public final BorderType getBorderType() {
return myBorderType;
}
/**
+ * @throws java.lang.IllegalArgumentException
+ * if <code>type</code>
+ * is <code>null</code>
* @see com.intellij.uiDesigner.shared.BorderType
- *
- * @exception java.lang.IllegalArgumentException if <code>type</code>
- * is <code>null</code>
*/
- public final void setBorderType(@NotNull final BorderType type){
- if(myBorderType==type){
+ public final void setBorderType(@NotNull final BorderType type) {
+ if (myBorderType == type) {
return;
}
- myBorderType=type;
+ myBorderType = type;
updateBorder();
}
/**
* @return border's title. If the container doesn't have any title then the
- * method returns <code>null</code>.
+ * method returns <code>null</code>.
*/
@Nullable
- public final StringDescriptor getBorderTitle(){
+ public final StringDescriptor getBorderTitle() {
return myBorderTitle;
}
/**
* @param title new border's title. <code>null</code> means that
- * the containr doesn't have have titled border.
+ * the containr doesn't have have titled border.
*/
- public final void setBorderTitle(final StringDescriptor title){
- if(Comparing.equal(title,myBorderTitle)){
+ public final void setBorderTitle(final StringDescriptor title) {
+ if (Comparing.equal(title, myBorderTitle)) {
return;
}
myBorderTitle = title;
public RadLayoutManager getLayoutManager() {
RadContainer parent = this;
- while(parent != null) {
+ while (parent != null) {
if (parent.myLayoutManager != null) {
return parent.myLayoutManager;
}
return myLayoutManager.areChildrenExclusive();
}
+ @Override
+ public void refresh() {
+ for (int i = 0; i < getComponentCount(); i++) {
+ getComponent(i).refresh();
+ }
+ myLayoutManager.refresh(this);
+ }
+
/**
* Serializes container's border
*/
- protected final void writeBorder(final XmlWriter writer){
+ protected final void writeBorder(final XmlWriter writer) {
writer.startElement(UIFormXmlConstants.ELEMENT_BORDER);
- try{
+ try {
writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_TYPE, getBorderType().getId());
if (getBorderTitle() != null) {
final StringDescriptor descriptor = getBorderTitle();
writer.writeColorDescriptor(myBorderColor);
writer.endElement();
}
- }finally{
+ }
+ finally {
writer.endElement(); // border
}
}
/**
* Serializes container's children
*/
- protected final void writeChildren(final XmlWriter writer){
+ protected final void writeChildren(final XmlWriter writer) {
// Children
writer.startElement("children");
- try{
+ try {
writeChildrenImpl(writer);
- }finally{
+ }
+ finally {
writer.endElement(); // children
}
}
- protected final void writeChildrenImpl(final XmlWriter writer){
- for (int i=0; i < getComponentCount(); i++) {
+ protected final void writeChildrenImpl(final XmlWriter writer) {
+ for (int i = 0; i < getComponentCount(); i++) {
getComponent(i).write(writer);
}
}
else {
writer.startElement("grid");
}
- try{
+ try {
writeId(writer);
writeClassIfDifferent(writer, JPanel.class.getName());
writeBinding(writer);
// Children
writeChildren(writer);
- }finally{
+ }
+ finally {
writer.endElement(); // xy/grid
}
}
protected void importSnapshotComponent(final SnapshotContext context, final JComponent component) {
getLayoutManager().createSnapshotLayout(context, component, this, component.getLayout());
importSnapshotBorder(component);
- for(Component child: component.getComponents()) {
+ for (Component child : component.getComponents()) {
if (child instanceof JComponent) {
- RadComponent childComponent = createSnapshotComponent(context, (JComponent) child);
+ RadComponent childComponent = createSnapshotComponent(context, (JComponent)child);
if (childComponent != null) {
- getLayoutManager().addSnapshotComponent(component, (JComponent) child, this, childComponent);
+ getLayoutManager().addSnapshotComponent(component, (JComponent)child, this, childComponent);
}
}
}
Border border = component.getBorder();
if (border != null) {
if (border instanceof TitledBorder) {
- TitledBorder titledBorder = (TitledBorder) border;
+ TitledBorder titledBorder = (TitledBorder)border;
setBorderTitle(StringDescriptor.create(titledBorder.getTitle()));
setBorderTitleJustification(titledBorder.getTitleJustification());
setBorderTitlePosition(titledBorder.getTitlePosition());
setBorderType(BorderType.ETCHED);
}
else if (border instanceof BevelBorder) {
- BevelBorder bevelBorder = (BevelBorder) border;
+ BevelBorder bevelBorder = (BevelBorder)border;
setBorderType(bevelBorder.getBevelType() == BevelBorder.RAISED ? BorderType.BEVEL_RAISED : BorderType.BEVEL_LOWERED);
}
else if (border instanceof EmptyBorder) {
- EmptyBorder emptyBorder = (EmptyBorder) border;
+ EmptyBorder emptyBorder = (EmptyBorder)border;
setBorderType(BorderType.EMPTY);
setBorderSize(emptyBorder.getBorderInsets());
}
else if (border instanceof LineBorder) {
- LineBorder lineBorder = (LineBorder) border;
+ LineBorder lineBorder = (LineBorder)border;
setBorderType(BorderType.LINE);
setBorderColor(new ColorDescriptor(lineBorder.getLineColor()));
}
if (!(myLayoutManager instanceof RadAbstractGridLayoutManager)) {
throw new RuntimeException("Not a grid container");
}
- return (RadAbstractGridLayoutManager) myLayoutManager;
+ return (RadAbstractGridLayoutManager)myLayoutManager;
}
@Nullable
public RadComponent findComponentWithConstraints(final Object constraints) {
- for(RadComponent component: getComponents()) {
+ for (RadComponent component : getComponents()) {
if (constraints.equals(component.getCustomLayoutConstraints())) {
return component;
}
myEditor = new StringEditor(getModule().getProject());
}
- public Dimension getPreferredSize(){
+ public Dimension getPreferredSize() {
return myEditor.getPreferredSize();
}
private final int[] mySnapshotXMax = new int[512];
private final int[] mySnapshotYMax = new int[512];
- @Override public String getName() {
+ @Override
+ public String getName() {
return UIFormXmlConstants.LAYOUT_GRIDBAG;
}
if (container.getLayoutManager().isGrid()) {
// preprocess: store weights in GridBagConstraints
RadAbstractGridLayoutManager grid = container.getGridLayoutManager();
- for(RadComponent c: container.getComponents()) {
+ for (RadComponent c : container.getComponents()) {
GridBagConstraints gbc = GridBagConverter.getGridBagConstraints(c);
if (grid.canCellGrow(container, false, c.getConstraints().getColumn())) {
gbc.weightx = 1.0;
public void writeChildConstraints(final XmlWriter writer, final RadComponent child) {
writeGridConstraints(writer, child);
if (child.getCustomLayoutConstraints() instanceof GridBagConstraints) {
- GridBagConstraints gbc = (GridBagConstraints) child.getCustomLayoutConstraints();
+ GridBagConstraints gbc = (GridBagConstraints)child.getCustomLayoutConstraints();
writer.startElement(UIFormXmlConstants.ELEMENT_GRIDBAG);
try {
if (!gbc.insets.equals(new Insets(0, 0, 0, 0))) {
container.getDelegee().add(component.getDelegee(), gbc, index);
}
+ @Override
+ public void refresh(RadContainer container) {
+ checkEmptyCells(container);
+ }
+
+ private static final int MINIMUM_GRID_SIZE = 15;
+
+ private static void checkEmptyCells(RadContainer container) {
+ JComponent jComponent = container.getDelegee();
+ GridBagLayout layout = (GridBagLayout)jComponent.getLayout();
+ Dimension oldSize = jComponent.getSize();
+
+ // clear cells
+ layout.columnWidths = null;
+ layout.rowHeights = null;
+
+ // calculate layout fields
+ jComponent.setSize(500, 400);
+ jComponent.doLayout();
+ jComponent.setSize(oldSize);
+
+ int[][] dimensions = layout.getLayoutDimensions();
+
+ // check empty columns
+ int[] columnWidths = dimensions[0];
+ boolean doLayoutColumns = false;
+
+ for (int i = 0; i < columnWidths.length; i++) {
+ if (columnWidths[i] == 0) {
+ columnWidths[i] = MINIMUM_GRID_SIZE;
+ doLayoutColumns = true;
+ }
+ }
+
+ // check empty rows
+ int[] rowHeights = dimensions[1];
+ boolean doLayoutRows = false;
+
+ for (int i = 0; i < rowHeights.length; i++) {
+ if (rowHeights[i] == 0) {
+ rowHeights[i] = MINIMUM_GRID_SIZE;
+ doLayoutRows = true;
+ }
+ }
+
+ // apply changes
+ if (doLayoutColumns) {
+ layout.columnWidths = columnWidths;
+ }
+ if (doLayoutRows) {
+ layout.rowHeights = rowHeights;
+ }
+ if (doLayoutColumns || doLayoutRows) {
+ jComponent.doLayout();
+ }
+ }
+
@Override
public Property[] getContainerProperties(final Project project) {
return Property.EMPTY_ARRAY;
@Override
public Property[] getComponentProperties(final Project project, final RadComponent component) {
- return new Property[] {
+ return new Property[]{
new HorzAlignProperty(),
new VertAlignProperty(),
new ComponentInsetsProperty(),
new IPadProperty(false)
};
}
-
+
private static GridBagLayout getGridBag(RadContainer container) {
- return (GridBagLayout) container.getLayout();
+ return (GridBagLayout)container.getLayout();
}
@Override
public int getGridRowCount(RadContainer container) {
int[][] layoutDimensions = getGridBag(container).getLayoutDimensions();
- return layoutDimensions [1].length;
+ return layoutDimensions[1].length;
}
@Override
public int getGridColumnCount(RadContainer container) {
int[][] layoutDimensions = getGridBag(container).getLayoutDimensions();
- return layoutDimensions [0].length;
+ return layoutDimensions[0].length;
}
@Override
@Override
public int[] getGridCellSizes(RadContainer container, boolean isRow) {
int[][] layoutDimensions = getGridBag(container).getLayoutDimensions();
- return layoutDimensions [isRow ? 1 : 0];
+ return layoutDimensions[isRow ? 1 : 0];
}
private static int[] getGridLines(final RadContainer container, final int rowColIndex, final int delta) {
final GridBagLayout gridBag = getGridBag(container);
Point layoutOrigin = gridBag.getLayoutOrigin();
int[][] layoutDimensions = gridBag.getLayoutDimensions();
- int[] result = new int [layoutDimensions [rowColIndex].length+delta];
+ int[] result = new int[layoutDimensions[rowColIndex].length + delta];
if (result.length > 0) {
- result [0] = (rowColIndex == 0) ? layoutOrigin.x : layoutOrigin.y;
- for(int i=1; i<result.length; i++) {
- result [i] = result [i-1]+layoutDimensions [rowColIndex] [i-1];
+ result[0] = (rowColIndex == 0) ? layoutOrigin.x : layoutOrigin.y;
+ for (int i = 1; i < result.length; i++) {
+ result[i] = result[i - 1] + layoutDimensions[rowColIndex][i - 1];
}
}
return result;
}
- @NotNull @Override
+ @NotNull
+ @Override
public ComponentDropLocation getDropLocation(@NotNull RadContainer container, @Nullable final Point location) {
if (getGridRowCount(container) == 0 && getGridColumnCount(container) == 0) {
return new FirstComponentInsertLocation(container, container.getBounds(), 0, 0);
@Override
protected void updateConstraints(final RadComponent component) {
- GridBagLayout layout = (GridBagLayout) component.getParent().getLayout();
+ GridBagLayout layout = (GridBagLayout)component.getParent().getLayout();
GridBagConstraints gbc = GridBagConverter.getGridBagConstraints(component);
layout.setConstraints(component.getDelegee(), gbc);
super.updateConstraints(component);
GridBagLayout gridBag = getGridBag(container);
double[][] weights = gridBag.getLayoutWeights();
if (weights != null) {
- double[] cellWeights = weights [isRow ? 1 : 0];
- return i >= 0 && i < cellWeights.length && cellWeights [i] >= 0.1;
+ double[] cellWeights = weights[isRow ? 1 : 0];
+ return i >= 0 && i < cellWeights.length && cellWeights[i] >= 0.1;
}
return false;
}
}
public static Dimension getGridBagSize(final JComponent parent) {
- GridBagLayout gridBag = (GridBagLayout) parent.getLayout();
+ GridBagLayout gridBag = (GridBagLayout)parent.getLayout();
gridBag.layoutContainer(parent);
int[][] layoutDimensions = gridBag.getLayoutDimensions();
int colCount = layoutDimensions[0].length;
// account for invisible components
- for(Component component: parent.getComponents()) {
+ for (Component component : parent.getComponents()) {
final GridBagConstraints constraints = gridBag.getConstraints(component);
colCount = Math.max(colCount, constraints.gridx + constraints.gridwidth);
rowCount = Math.max(rowCount, constraints.gridy + constraints.gridheight);
// logic copied from GridBagLayout.java
- GridBagLayout gridBag = (GridBagLayout) parent.getLayout();
+ GridBagLayout gridBag = (GridBagLayout)parent.getLayout();
final GridBagConstraints constraints = gridBag.getConstraints(child);
int curX = constraints.gridx;
/* If x or y is negative, then use relative positioning: */
if (curX < 0 && curY < 0) {
- if(myLastSnapshotRow >= 0)
+ if (myLastSnapshotRow >= 0) {
curY = myLastSnapshotRow;
- else if(myLastSnapshotCol >= 0)
+ }
+ else if (myLastSnapshotCol >= 0) {
curX = myLastSnapshotCol;
- else
+ }
+ else {
curY = 0;
+ }
}
if (curX < 0) {
if (curHeight <= 0) {
curHeight += gridBagSize.height - curY;
- if (curHeight < 1)
+ if (curHeight < 1) {
curHeight = 1;
+ }
}
px = 0;
- for (int i = curY; i < (curY + curHeight); i++)
+ for (int i = curY; i < (curY + curHeight); i++) {
px = Math.max(px, mySnapshotXMax[i]);
+ }
curX = px - curX - 1;
- if(curX < 0)
+ if (curX < 0) {
curX = 0;
+ }
}
else if (curY < 0) {
if (curWidth <= 0) {
curWidth += gridBagSize.width - curX;
- if (curWidth < 1)
+ if (curWidth < 1) {
curWidth = 1;
+ }
}
py = 0;
- for (int i = curX; i < (curX + curWidth); i++)
+ for (int i = curX; i < (curX + curWidth); i++) {
py = Math.max(py, mySnapshotYMax[i]);
+ }
curY = py - curY - 1;
- if(curY < 0)
+ if (curY < 0) {
curY = 0;
+ }
}
if (curWidth <= 0) {
curWidth += gridBagSize.width - curX;
- if (curWidth < 1)
+ if (curWidth < 1) {
curWidth = 1;
+ }
}
if (curHeight <= 0) {
curHeight += gridBagSize.height - curY;
- if (curHeight < 1)
+ if (curHeight < 1) {
curHeight = 1;
+ }
}
/* Adjust xMax and yMax */
for (int i = curX; i < (curX + curWidth); i++) {
- mySnapshotYMax[i] = curY + curHeight;
+ mySnapshotYMax[i] = curY + curHeight;
}
for (int i = curY; i < (curY + curHeight); i++) {
- mySnapshotXMax[i] = curX + curWidth;
+ mySnapshotXMax[i] = curX + curWidth;
}
/* Make negative sizes start a new row/column */
- if (constraints.gridheight == 0 && constraints.gridwidth == 0)
+ if (constraints.gridheight == 0 && constraints.gridwidth == 0) {
myLastSnapshotRow = myLastSnapshotCol = -1;
- if (constraints.gridheight == 0 && myLastSnapshotRow < 0)
+ }
+ if (constraints.gridheight == 0 && myLastSnapshotRow < 0) {
myLastSnapshotCol = curX + curWidth;
- else if (constraints.gridwidth == 0 && myLastSnapshotCol < 0)
+ }
+ else if (constraints.gridwidth == 0 && myLastSnapshotCol < 0) {
myLastSnapshotRow = curY + curHeight;
+ }
component.getConstraints().setColumn(curX);
component.getConstraints().setRow(curY);
if (constraints.weightx >= 1.0) {
component.getConstraints().setHSizePolicy(GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW);
}
- else {
+ else {
component.getConstraints().setHSizePolicy(0);
}
if (constraints.weighty >= 1.0) {
}
private static int convertAnchor(final GridBagConstraints gbc) {
- switch(gbc.anchor) {
- case GridBagConstraints.NORTHWEST: return GridConstraints.ANCHOR_NORTHWEST;
- case GridBagConstraints.NORTH: return GridConstraints.ANCHOR_NORTH;
- case GridBagConstraints.NORTHEAST: return GridConstraints.ANCHOR_NORTHEAST;
- case GridBagConstraints.EAST: return GridConstraints.ANCHOR_EAST;
- case GridBagConstraints.SOUTHEAST: return GridConstraints.ANCHOR_SOUTHEAST;
- case GridBagConstraints.SOUTH: return GridConstraints.ANCHOR_SOUTH;
- case GridBagConstraints.SOUTHWEST: return GridConstraints.ANCHOR_SOUTHWEST;
- default: return GridConstraints.ANCHOR_WEST;
+ switch (gbc.anchor) {
+ case GridBagConstraints.NORTHWEST:
+ return GridConstraints.ANCHOR_NORTHWEST;
+ case GridBagConstraints.NORTH:
+ return GridConstraints.ANCHOR_NORTH;
+ case GridBagConstraints.NORTHEAST:
+ return GridConstraints.ANCHOR_NORTHEAST;
+ case GridBagConstraints.EAST:
+ return GridConstraints.ANCHOR_EAST;
+ case GridBagConstraints.SOUTHEAST:
+ return GridConstraints.ANCHOR_SOUTHEAST;
+ case GridBagConstraints.SOUTH:
+ return GridConstraints.ANCHOR_SOUTH;
+ case GridBagConstraints.SOUTHWEST:
+ return GridConstraints.ANCHOR_SOUTHWEST;
+ default:
+ return GridConstraints.ANCHOR_WEST;
}
}
private static int convertFill(final GridBagConstraints gbc) {
- switch(gbc.fill) {
- case GridBagConstraints.HORIZONTAL: return GridConstraints.FILL_HORIZONTAL;
- case GridBagConstraints.VERTICAL: return GridConstraints.FILL_VERTICAL;
- case GridBagConstraints.BOTH: return GridConstraints.FILL_BOTH;
- default: return GridConstraints.FILL_NONE;
+ switch (gbc.fill) {
+ case GridBagConstraints.HORIZONTAL:
+ return GridConstraints.FILL_HORIZONTAL;
+ case GridBagConstraints.VERTICAL:
+ return GridConstraints.FILL_VERTICAL;
+ case GridBagConstraints.BOTH:
+ return GridConstraints.FILL_BOTH;
+ default:
+ return GridConstraints.FILL_NONE;
}
}
final GridBagConstraints cellConstraints = (GridBagConstraints)component.getCustomLayoutConstraints();
cellConstraints.insets = value;
- GridBagLayout layout = (GridBagLayout) component.getParent().getLayout();
+ GridBagLayout layout = (GridBagLayout)component.getParent().getLayout();
GridBagConstraints gbc = (GridBagConstraints)layout.getConstraints(component.getDelegee()).clone();
gbc.insets = value;
layout.setConstraints(component.getDelegee(), gbc);
public Double getValue(final RadComponent component) {
if (component.getCustomLayoutConstraints() instanceof GridBagConstraints) {
- GridBagConstraints gbc = (GridBagConstraints) component.getCustomLayoutConstraints();
+ GridBagConstraints gbc = (GridBagConstraints)component.getCustomLayoutConstraints();
return myIsWeightX ? gbc.weightx : gbc.weighty;
}
return 0.0;
protected void setValueImpl(final RadComponent component, final Double value) throws Exception {
if (component.getCustomLayoutConstraints() instanceof GridBagConstraints) {
- GridBagConstraints gbc = (GridBagConstraints) component.getCustomLayoutConstraints();
+ GridBagConstraints gbc = (GridBagConstraints)component.getCustomLayoutConstraints();
if (myIsWeightX) {
gbc.weightx = value.doubleValue();
}
else {
gbc.weighty = value.doubleValue();
}
- ((GridBagLayout) component.getParent().getLayout()).setConstraints(component.getDelegee(), gbc);
+ ((GridBagLayout)component.getParent().getLayout()).setConstraints(component.getDelegee(), gbc);
}
}
public Integer getValue(final RadComponent component) {
if (component.getCustomLayoutConstraints() instanceof GridBagConstraints) {
- GridBagConstraints gbc = (GridBagConstraints) component.getCustomLayoutConstraints();
+ GridBagConstraints gbc = (GridBagConstraints)component.getCustomLayoutConstraints();
return myIsIpadX ? gbc.ipadx : gbc.ipady;
}
return 0;
protected void setValueImpl(final RadComponent component, final Integer value) throws Exception {
if (component.getCustomLayoutConstraints() instanceof GridBagConstraints) {
- GridBagConstraints gbc = (GridBagConstraints) component.getCustomLayoutConstraints();
+ GridBagConstraints gbc = (GridBagConstraints)component.getCustomLayoutConstraints();
if (myIsIpadX) {
gbc.ipadx = value.intValue();
}
else {
gbc.ipady = value.intValue();
}
- ((GridBagLayout) component.getParent().getLayout()).setConstraints(component.getDelegee(), gbc);
+ ((GridBagLayout)component.getParent().getLayout()).setConstraints(component.getDelegee(), gbc);
}
}
}
*
* @return the layout manager name.
*/
- @Nullable public abstract String getName();
+ @Nullable
+ public abstract String getName();
- @Nullable public LayoutManager createLayout() {
+ @Nullable
+ public LayoutManager createLayout() {
return null;
}
public void changeContainerLayout(RadContainer container) throws IncorrectOperationException {
- ensureChildrenVisible(container);
+ ensureChildrenVisible(container);
container.setLayoutManager(this);
}
public void writeLayout(final XmlWriter writer, final RadContainer radContainer) {
}
- @NotNull public ComponentDropLocation getDropLocation(RadContainer container, @Nullable final Point location) {
+ public void refresh(RadContainer container) {
+ }
+
+ @NotNull
+ public ComponentDropLocation getDropLocation(RadContainer container, @Nullable final Point location) {
return NoDropLocation.INSTANCE;
}
protected static void ensureChildrenVisible(final RadContainer container) {
if (container.getLayoutManager().areChildrenExclusive()) {
// ensure that components which were hidden by previous layout are visible (IDEADEV-16077)
- for(RadComponent child: container.getComponents()) {
+ for (RadComponent child : container.getComponents()) {
final IProperty property = FormInspectionUtil.findProperty(child, SwingProperties.VISIBLE);
if (property == null || property.getPropertyValue(child) == Boolean.TRUE) {
child.getDelegee().setVisible(true);