diff --git a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/AsmCodeGenerator.java b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/AsmCodeGenerator.java index 22ab2a7f8bd6..b33256d242d8 100644 --- a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/AsmCodeGenerator.java +++ b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/AsmCodeGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -852,20 +852,20 @@ public class AsmCodeGenerator { else { generator.push((String) null); } - pushBorderProperties(container, generator, borderTitle, componentLocal); - - Type borderFactoryType = ourBorderFactoryType; - StringDescriptor borderFactoryValue = (StringDescriptor)container.getDelegeeClientProperties().get(ourBorderFactoryClientProperty); - if (borderFactoryValue == null && borderTitle != null && Boolean.valueOf(System.getProperty("idea.is.internal")).booleanValue()) { - borderFactoryValue = StringDescriptor.create("com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"); - container.getDelegeeClientProperties().put(ourBorderFactoryClientProperty, borderFactoryValue); + if (borderTitle != null) { + pushBorderProperties(container, generator, borderTitle, componentLocal); + Type borderFactoryType = ourBorderFactoryType; + StringDescriptor borderFactoryValue = (StringDescriptor)container.getDelegeeClientProperties().get(ourBorderFactoryClientProperty); + if (borderFactoryValue == null && Boolean.valueOf(System.getProperty("idea.is.internal")).booleanValue()) { + borderFactoryValue = StringDescriptor.create("com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"); + container.getDelegeeClientProperties().put(ourBorderFactoryClientProperty, borderFactoryValue); + } + if (borderFactoryValue != null && borderFactoryValue.getValue().length() != 0) { + borderFactoryType = typeFromClassName(borderFactoryValue.getValue()); + } + generator.invokeStatic(borderFactoryType, ourCreateTitledBorderMethod); } - if (borderFactoryValue != null && borderFactoryValue.getValue().length() != 0) { - borderFactoryType = typeFromClassName(borderFactoryValue.getValue()); - } - - generator.invokeStatic(borderFactoryType, ourCreateTitledBorderMethod); // set border generator.invokeVirtual(Type.getType(JComponent.class), diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/make/FormSourceCodeGenerator.java b/plugins/ui-designer/src/com/intellij/uiDesigner/make/FormSourceCodeGenerator.java index 21e72aa42078..4d01bae51fbc 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/make/FormSourceCodeGenerator.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/make/FormSourceCodeGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -776,8 +776,9 @@ public final class FormSourceCodeGenerator { if (!borderNone || borderTitle != null) { startMethodCall(variable, "setBorder"); - - startStaticMethodCall(BorderFactory.class, "createTitledBorder"); + if (borderTitle != null) { + startStaticMethodCall(BorderFactory.class, "createTitledBorder"); + } if (!borderNone) { startStaticMethodCall(BorderFactory.class, borderFactoryMethodName); @@ -801,26 +802,26 @@ public final class FormSourceCodeGenerator { push((String) null); } - push(borderTitle); - - if (isCustomBorder(container)) { - push(container.getBorderTitleJustification(), ourTitleJustificationMap); - push(container.getBorderTitlePosition(), ourTitlePositionMap); - if (container.getBorderTitleFont() != null || container.getBorderTitleColor() != null) { - if (container.getBorderTitleFont() == null) { - push((String) null); - } - else { - pushFont(variable, container.getBorderTitleFont(), "getFont"); - } - if (container.getBorderTitleColor() != null) { - pushColor(container.getBorderTitleColor()); + if (borderTitle != null) { + push(borderTitle); + if (isCustomBorder(container)) { + push(container.getBorderTitleJustification(), ourTitleJustificationMap); + push(container.getBorderTitlePosition(), ourTitlePositionMap); + if (container.getBorderTitleFont() != null || container.getBorderTitleColor() != null) { + if (container.getBorderTitleFont() == null) { + push((String)null); + } + else { + pushFont(variable, container.getBorderTitleFont(), "getFont"); + } + if (container.getBorderTitleColor() != null) { + pushColor(container.getBorderTitleColor()); + } } } + endMethod(); // createTitledBorder } - endMethod(); // createTitledBorder - endMethod(); // setBorder } } diff --git a/plugins/ui-designer/testData/TestBorderWithoutTitle.form b/plugins/ui-designer/testData/TestBorderWithoutTitle.form new file mode 100644 index 000000000000..f71d55c920dd --- /dev/null +++ b/plugins/ui-designer/testData/TestBorderWithoutTitle.form @@ -0,0 +1,12 @@ + +
diff --git a/plugins/ui-designer/testData/TestNoneBorderWithTitle.form b/plugins/ui-designer/testData/TestNoneBorderWithTitle.form new file mode 100644 index 000000000000..8f13946f8870 --- /dev/null +++ b/plugins/ui-designer/testData/TestNoneBorderWithTitle.form @@ -0,0 +1,12 @@ + + diff --git a/plugins/ui-designer/testData/sourceCodeGenerator/borders/BindingTest.java b/plugins/ui-designer/testData/sourceCodeGenerator/borders/BindingTest.java new file mode 100644 index 000000000000..181687d6ad16 --- /dev/null +++ b/plugins/ui-designer/testData/sourceCodeGenerator/borders/BindingTest.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2009 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import javax.swing.*; + +public class BindingTest { + public JComponent myRootComponent; + public static JComponent myStaticField; + public final JComponent myFinalField = null; + public int myIntField; + public String myStringField; + + public BindingTest() { + } +} diff --git a/plugins/ui-designer/testData/sourceCodeGenerator/borders/BindingTest.java.after b/plugins/ui-designer/testData/sourceCodeGenerator/borders/BindingTest.java.after new file mode 100644 index 000000000000..6f38fcff4ac4 --- /dev/null +++ b/plugins/ui-designer/testData/sourceCodeGenerator/borders/BindingTest.java.after @@ -0,0 +1,67 @@ +/* + * Copyright 2000-2009 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import javax.swing.*; + +public class BindingTest { + public JComponent myRootComponent; + public static JComponent myStaticField; + public final JComponent myFinalField = null; + public int myIntField; + public String myStringField; + + public BindingTest() { + } + + { +// GUI initializer generated by IntelliJ IDEA GUI Designer +// >>> IMPORTANT!! <<< +// DO NOT EDIT OR ADD ANY CODE HERE! + $$$setupUI$$$(); + } + + /** + * Method generated by IntelliJ IDEA GUI Designer + * >>> IMPORTANT!! <<< + * DO NOT edit this method OR call it in your code! + * + * @noinspection ALL + */ + private void $$$setupUI$$$() { + myRootComponent = new JPanel(); + myRootComponent.setLayout(new com.intellij.uiDesigner.core.GridLayoutManager(4, 1, new java.awt.Insets(0, 0, 0, 0), -1, -1)); + final JPanel panel1 = new JPanel(); + panel1.setLayout(new com.intellij.uiDesigner.core.GridLayoutManager(1, 1, new java.awt.Insets(0, 0, 0, 0), -1, -1)); + myRootComponent.add(panel1, new com.intellij.uiDesigner.core.GridConstraints(0, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_BOTH, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + panel1.setBorder(javax.swing.BorderFactory.createEmptyBorder()); + final com.intellij.uiDesigner.core.Spacer spacer1 = new com.intellij.uiDesigner.core.Spacer(); + myRootComponent.add(spacer1, new com.intellij.uiDesigner.core.GridConstraints(3, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_VERTICAL, 1, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + final JPanel panel2 = new JPanel(); + panel2.setLayout(new com.intellij.uiDesigner.core.GridLayoutManager(1, 1, new java.awt.Insets(0, 0, 0, 0), -1, -1)); + myRootComponent.add(panel2, new com.intellij.uiDesigner.core.GridConstraints(1, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_BOTH, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + panel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEmptyBorder(), "BorderTitle")); + final JPanel panel3 = new JPanel(); + panel3.setLayout(new com.intellij.uiDesigner.core.GridLayoutManager(1, 1, new java.awt.Insets(0, 0, 0, 0), -1, -1)); + myRootComponent.add(panel3, new com.intellij.uiDesigner.core.GridConstraints(2, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_BOTH, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + panel3.setBorder(javax.swing.BorderFactory.createTitledBorder("BorderTitle")); + } + + /** + * @noinspection ALL + */ + public JComponent $$$getRootComponent$$$() { + return myRootComponent; + } +} diff --git a/plugins/ui-designer/testData/sourceCodeGenerator/borders/Test.form b/plugins/ui-designer/testData/sourceCodeGenerator/borders/Test.form new file mode 100644 index 000000000000..f6fdd483e56a --- /dev/null +++ b/plugins/ui-designer/testData/sourceCodeGenerator/borders/Test.form @@ -0,0 +1,45 @@ + + diff --git a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java index a45dfeb88204..093547bfb5cb 100644 --- a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java +++ b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,8 @@ import junit.framework.TestCase; import org.jetbrains.asm4.ClassWriter; import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; import javax.swing.border.EtchedBorder; import javax.swing.border.TitledBorder; import java.awt.*; @@ -331,6 +333,19 @@ public class AsmCodeGeneratorTest extends TestCase { assertEquals("BorderTitle", border.getTitle()); assertTrue(border.getBorder().toString(), border.getBorder() instanceof EtchedBorder); } + + public void testBorderWithoutTitle() throws Exception { + JPanel panel = (JPanel) getInstrumentedRootComponent("TestBorderWithoutTitle.form", "BindingTest"); + Border border = panel.getBorder(); + assertTrue(border.toString(), border instanceof EmptyBorder); + } + + public void testNoneBorderWithTitle() throws Exception { + JPanel panel = (JPanel) getInstrumentedRootComponent("TestNoneBorderWithTitle.form", "BindingTest"); + assertTrue(panel.getBorder() instanceof TitledBorder); + TitledBorder border = (TitledBorder) panel.getBorder(); + assertEquals("BorderTitle", border.getTitle()); + } public void testMnemonic() throws Exception { JPanel panel = (JPanel) getInstrumentedRootComponent("TestMnemonics.form", "BindingTest"); diff --git a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/make/FormSourceCodeGeneratorTest.java b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/make/FormSourceCodeGeneratorTest.java index 0d212f65565e..f9bb8e0265bc 100644 --- a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/make/FormSourceCodeGeneratorTest.java +++ b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/make/FormSourceCodeGeneratorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,8 @@ package com.intellij.uiDesigner.make; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PluginPathManager; import com.intellij.openapi.command.CommandProcessor; -import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -58,6 +56,10 @@ public class FormSourceCodeGeneratorTest extends PsiTestCase { public void testSimple() throws IOException { doTest(); } + + public void testBorders() throws IOException { + doTest(); + } public void testCustomCreateComponent() throws IOException { doTest();