Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MigLayout debugMode

Change-Id: I7a125547d483d9947572e2bae58317ec74ada2d6
  • Loading branch information...
commit ff8d5dc7b950aee9d98816fd0a8d7261d278c6d6 1 parent 8e5d132
@kennardconsulting kennardconsulting authored
View
9 modules/miglayout/src/main/java/org/metawidget/swing/layout/MigLayout.java
@@ -62,6 +62,8 @@
private final boolean mSupportMnemonics;
+ private final boolean mDebugMode;
+
//
// Constructor
//
@@ -75,6 +77,7 @@ public MigLayout( MigLayoutConfig config ) {
mNumberOfColumns = config.getNumberOfColumns();
mSupportMnemonics = config.isSupportMnemonics();
+ mDebugMode = config.isDebugMode();
}
//
@@ -98,8 +101,10 @@ public void startContainerLayout( JComponent container, SwingMetawidget metawidg
LC layoutConstraints = new LC().insets( "0" );
// Debug Info (draws the red and blue lines)
- //
- // layoutConstraints.debug( 500 );
+
+ if ( mDebugMode ) {
+ layoutConstraints.debug( 500 );
+ }
// Create the Layout
//
View
25 modules/miglayout/src/main/java/org/metawidget/swing/layout/MigLayoutConfig.java
@@ -35,6 +35,8 @@
private boolean mSupportMnemonics = true;
+ private boolean mDebugMode;
+
//
// Public methods
//
@@ -65,6 +67,19 @@ public MigLayoutConfig setSupportMnemonics( boolean supportMnemonics ) {
return this;
}
+ /**
+ * @param debugMode
+ * true to enable MigLayout debug mode
+ * @return this, as part of a fluent interface
+ */
+
+ public MigLayoutConfig setDebugMode( boolean debugMode ) {
+
+ mDebugMode = debugMode;
+
+ return this;
+ }
+
@Override
public boolean equals( Object that ) {
@@ -84,6 +99,10 @@ public boolean equals( Object that ) {
return false;
}
+ if ( mDebugMode != ( (MigLayoutConfig) that ).mDebugMode ) {
+ return false;
+ }
+
return true;
}
@@ -93,6 +112,7 @@ public int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + mNumberOfColumns;
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode( mSupportMnemonics );
+ hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode( mDebugMode );
return hashCode;
}
@@ -110,4 +130,9 @@ protected boolean isSupportMnemonics() {
return mSupportMnemonics;
}
+
+ protected boolean isDebugMode(){
+
+ return mDebugMode;
+ }
}
View
11 modules/miglayout/src/main/java/org/metawidget/swt/layout/MigLayout.java
@@ -50,7 +50,9 @@
// Private members
//
- private final int mNumberOfColumns;
+ private final int mNumberOfColumns;
+
+ private final boolean mDebugMode;
//
// Constructor
@@ -64,6 +66,7 @@ public MigLayout() {
public MigLayout( MigLayoutConfig config ) {
mNumberOfColumns = config.getNumberOfColumns();
+ mDebugMode = config.isDebugMode();
}
//
@@ -87,8 +90,10 @@ public void startContainerLayout( Composite container, SwtMetawidget metawidget
LC layoutConstraints = new LC().insets( "0" );
// Debug Info (draws the red and blue lines)
- //
- // layoutConstraints.debug( 500 );
+
+ if ( mDebugMode ) {
+ layoutConstraints.debug( 500 );
+ }
// Create the Layout
//
View
34 modules/miglayout/src/main/java/org/metawidget/swt/layout/MigLayoutConfig.java
@@ -31,7 +31,9 @@
// Private members
//
- private int mNumberOfColumns = 1;
+ private int mNumberOfColumns = 1;
+
+ private boolean mDebugMode = false;
//
// Public methods
@@ -52,6 +54,19 @@ public MigLayoutConfig setNumberOfColumns( int numberOfColumns ) {
return this;
}
+ /**
+ * @param debugMode
+ * true to enable MigLayout debug mode
+ * @return this, as part of a fluent interface
+ */
+
+ public MigLayoutConfig setDebugMode( boolean debugMode ) {
+
+ mDebugMode = debugMode;
+
+ return this;
+ }
+
@Override
public boolean equals( Object that ) {
@@ -59,7 +74,7 @@ public boolean equals( Object that ) {
return true;
}
- if ( !ObjectUtils.nullSafeClassEquals( this, that )) {
+ if ( !ObjectUtils.nullSafeClassEquals( this, that ) ) {
return false;
}
@@ -67,13 +82,21 @@ public boolean equals( Object that ) {
return false;
}
+ if ( mDebugMode != ( (MigLayoutConfig) that ).mDebugMode ) {
+ return false;
+ }
+
return true;
}
@Override
public int hashCode() {
- return mNumberOfColumns;
+ int hashCode = 1;
+ hashCode = 31 * hashCode + mNumberOfColumns;
+ hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode( mDebugMode );
+
+ return hashCode;
}
//
@@ -84,4 +107,9 @@ protected int getNumberOfColumns() {
return mNumberOfColumns;
}
+
+ protected boolean isDebugMode() {
+
+ return mDebugMode;
+ }
}
View
13 modules/miglayout/src/test/java/org/metawidget/swing/layout/MigLayoutTest.java
@@ -291,6 +291,19 @@ public void testMnemonics() {
assertEquals( -1, label.getDisplayedMnemonicIndex() );
}
+ public void testDebugMode() {
+
+ SwingMetawidget metawidget = new SwingMetawidget();
+ metawidget.setMetawidgetLayout( new org.metawidget.swing.layout.MigLayout() );
+ metawidget.setToInspect( new Foo() );
+
+ assertEquals( 0, ( (LC) ( (net.miginfocom.swing.MigLayout) metawidget.getLayout() ).getLayoutConstraints() ).getDebugMillis() );
+
+ metawidget.setMetawidgetLayout( new org.metawidget.swing.layout.MigLayout( new MigLayoutConfig().setDebugMode( true ) ));
+
+ assertEquals( 500, ( (LC) ( (net.miginfocom.swing.MigLayout) metawidget.getLayout() ).getLayoutConstraints() ).getDebugMillis() );
+ }
+
public void testConfig() {
MetawidgetTestUtils.testEqualsAndHashcode( MigLayoutConfig.class, new MigLayoutConfig() {
View
13 modules/miglayout/src/test/java/org/metawidget/swt/layout/MigLayoutTest.java
@@ -282,6 +282,19 @@ public void testOddColumns()
assertTrue( GROW_ALL == ( (CC) facet.getLayoutData() ).getHorizontal().getGrow() );
}
+ public void testDebugMode() {
+
+ SwtMetawidget metawidget = new SwtMetawidget( new Shell( TEST_DISPLAY, SWT.NONE ), SWT.NONE );
+ metawidget.setMetawidgetLayout( new org.metawidget.swt.layout.MigLayout() );
+ metawidget.setToInspect( new Foo() );
+
+ assertEquals( 0, ( (LC) ( (net.miginfocom.swt.MigLayout) metawidget.getLayout() ).getLayoutConstraints() ).getDebugMillis() );
+
+ metawidget.setMetawidgetLayout( new org.metawidget.swt.layout.MigLayout( new MigLayoutConfig().setDebugMode( true ) ));
+
+ assertEquals( 500, ( (LC) ( (net.miginfocom.swt.MigLayout) metawidget.getLayout() ).getLayoutConstraints() ).getDebugMillis() );
+ }
+
public void testConfig() {
MetawidgetTestUtils.testEqualsAndHashcode( MigLayoutConfig.class, new MigLayoutConfig() {
Please sign in to comment.
Something went wrong with that request. Please try again.