|
From: <caw...@us...> - 2006-12-15 15:22:23
|
Revision: 1695
http://svn.sourceforge.net/rubyeclipse/?rev=1695&view=rev
Author: cawilliams
Date: 2006-12-15 07:22:22 -0800 (Fri, 15 Dec 2006)
Log Message:
-----------
move things around so most suff is internal (and looks like the JDT's package structure)
Added Paths:
-----------
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/util/
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/util/LayoutUtil.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/util/TestUnitStatus.java
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/util/LayoutUtil.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/util/LayoutUtil.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/util/LayoutUtil.java 2006-12-15 15:22:22 UTC (rev 1695)
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.testunit.util;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.rubypeople.rdt.internal.testunit.wizards.MethodStubsSelectionButtonGroup;
+import org.rubypeople.rdt.internal.ui.util.PixelConverter;
+
+
+public class LayoutUtil {
+
+ /*
+ * Calculates the number of columns needed by field editors
+ */
+ public static int getNumberOfColumns(MethodStubsSelectionButtonGroup[] editors) {
+ int columnCount= 0;
+ for (int i= 0; i < editors.length; i++) {
+ columnCount= Math.max(editors[i].getNumberOfControls(), columnCount);
+ }
+ return columnCount;
+ }
+
+ /*
+ * Creates a composite and fills in the given editors.
+ * @param labelOnTop Defines if the label of all fields should be on top of the fields
+ */
+ public static void doDefaultLayout(Composite parent, MethodStubsSelectionButtonGroup[] editors, boolean labelOnTop) {
+ doDefaultLayout(parent, editors, labelOnTop, 0, 0, 0, 0);
+ }
+
+ /*
+ * Creates a composite and fills in the given editors.
+ * @param labelOnTop Defines if the label of all fields should be on top of the fields
+ * @param minWidth The minimal width of the composite
+ * @param minHeight The minimal height of the composite
+ */
+ public static void doDefaultLayout(Composite parent, MethodStubsSelectionButtonGroup[] editors, boolean labelOnTop, int minWidth, int minHeight) {
+ doDefaultLayout(parent, editors, labelOnTop, minWidth, minHeight, 0, 0);
+ }
+
+ public static void doDefaultLayout(Composite parent, MethodStubsSelectionButtonGroup[] editors, boolean labelOnTop, int minWidth, int minHeight, int marginWidth, int marginHeight) {
+ int nCulumns= getNumberOfColumns(editors);
+ Control[][] controls= new Control[editors.length][];
+ for (int i= 0; i < editors.length; i++) {
+ controls[i]= editors[i].doFillIntoGrid(parent, nCulumns);
+ }
+ if (labelOnTop) {
+ nCulumns--;
+ modifyLabelSpans(controls, nCulumns);
+ }
+ GridLayout layout= new GridLayout();
+ if (marginWidth != SWT.DEFAULT) {
+ layout.marginWidth= marginWidth;
+ }
+ if (marginHeight != SWT.DEFAULT) {
+ layout.marginHeight= marginHeight;
+ }
+// layout.minimumWidth= minWidth;
+// layout.minimumHeight= minHeight;
+ layout.numColumns= nCulumns;
+ parent.setLayout(layout);
+ }
+
+ private static void modifyLabelSpans(Control[][] controls, int nCulumns) {
+ for (int i= 0; i < controls.length; i++) {
+ setHorizontalSpan(controls[i][0], nCulumns);
+ }
+ }
+
+ /*
+ * Sets the span of a control. Assumes that MGridData is used.
+ */
+ public static void setHorizontalSpan(Control control, int span) {
+ Object ld= control.getLayoutData();
+ if (ld instanceof GridData) {
+ ((GridData)ld).horizontalSpan= span;
+ } else if (span != 1) {
+ GridData gd= new GridData();
+ gd.horizontalSpan= span;
+ control.setLayoutData(gd);
+ }
+ }
+
+ /*
+ * Sets the width hint of a control. Assumes that MGridData is used.
+ */
+ public static void setWidthHint(Control control, int widthHint) {
+ Object ld= control.getLayoutData();
+ if (ld instanceof GridData) {
+ ((GridData)ld).widthHint= widthHint;
+ }
+ }
+
+ /*
+ * Sets the horizontal indent of a control. Assumes that MGridData is used.
+ */
+ public static void setHorizontalIndent(Control control, int horizontalIndent) {
+ Object ld= control.getLayoutData();
+ if (ld instanceof GridData) {
+ ((GridData)ld).horizontalIndent= horizontalIndent;
+ }
+ }
+
+ /*
+ * Creates a spacer control with the given span.
+ * The composite is assumed to have <code>MGridLayout</code> as
+ * layout.
+ * @param parent The parent composite
+ */
+ public static Control createEmptySpace(Composite parent, int span) {
+ Label label= new Label(parent, SWT.LEFT);
+ GridData gd= new GridData();
+ gd.horizontalAlignment= GridData.BEGINNING;
+ gd.grabExcessHorizontalSpace= false;
+ gd.horizontalSpan= span;
+ gd.horizontalIndent= 0;
+ gd.widthHint= 0;
+ gd.heightHint= 0;
+ label.setLayoutData(gd);
+ return label;
+ }
+
+
+ /**
+ * Returns a width hint for a button control.
+ * @param button the button for which to set the dimension hint
+ * @return the width hint
+ */
+ public static int getButtonWidthHint(Button button) {
+ button.setFont(JFaceResources.getDialogFont());
+ PixelConverter converter= new PixelConverter(button);
+ int widthHint= converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
+ return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
+ }
+
+ /**
+ * Sets width and height hint for the button control.
+ * <b>Note:</b> This is a NOP if the button's layout data is not
+ * an instance of <code>GridData</code>.
+ *
+ * @param button the button for which to set the dimension hint
+ */
+ public static void setButtonDimensionHint(Button button) {
+ Assert.isNotNull(button);
+ Object gd= button.getLayoutData();
+ if (gd instanceof GridData) {
+ ((GridData)gd).widthHint= getButtonWidthHint(button);
+ ((GridData)gd).horizontalAlignment = GridData.FILL;
+ }
+ }
+
+}
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/util/TestUnitStatus.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/util/TestUnitStatus.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/util/TestUnitStatus.java 2006-12-15 15:22:22 UTC (rev 1695)
@@ -0,0 +1,182 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.rubypeople.rdt.internal.testunit.util;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
+import org.rubypeople.rdt.internal.testunit.ui.TestunitPlugin;
+
+/**
+ * An implemention of IStatus.
+ * TO DO: Why is it duplicated, it should leverage the Status base class???
+ */
+public class TestUnitStatus implements IStatus {
+ private String fStatusMessage;
+ private int fSeverity;
+
+ /**
+ * Creates a status set to OK (no message)
+ */
+ public TestUnitStatus() {
+ this(OK, null);
+ }
+
+ /**
+ * Creates a status .
+ * @param severity The status severity: ERROR, WARNING, INFO and OK.
+ * @param message The message of the status. Applies only for ERROR,
+ * WARNING and INFO.
+ */
+ public TestUnitStatus(int severity, String message) {
+ fStatusMessage= message;
+ fSeverity= severity;
+ }
+
+ public static IStatus createError(String message) {
+ return new TestUnitStatus(IStatus.ERROR, message);
+ }
+
+ public static IStatus createWarning(String message) {
+ return new TestUnitStatus(IStatus.WARNING, message);
+ }
+
+ public static IStatus createInfo(String message) {
+ return new TestUnitStatus(IStatus.INFO, message);
+ }
+
+ /**
+ * Returns if the status' severity is OK.
+ */
+ public boolean isOK() {
+ return fSeverity == IStatus.OK;
+ }
+
+ /**
+ * Returns if the status' severity is WARNING.
+ */
+ public boolean isWarning() {
+ return fSeverity == IStatus.WARNING;
+ }
+
+ /**
+ * Returns if the status' severity is INFO.
+ */
+ public boolean isInfo() {
+ return fSeverity == IStatus.INFO;
+ }
+
+ /**
+ * Returns if the status' severity is ERROR.
+ */
+ public boolean isError() {
+ return fSeverity == IStatus.ERROR;
+ }
+
+ /**
+ * @see IStatus#getMessage()
+ */
+ public String getMessage() {
+ return fStatusMessage;
+ }
+
+ /**
+ * Sets the status to ERROR.
+ * @param errorMessage the error message (can be empty, but not null)
+ */
+ public void setError(String errorMessage) {
+ Assert.isNotNull(errorMessage);
+ fStatusMessage= errorMessage;
+ fSeverity= IStatus.ERROR;
+ }
+
+ /**
+ * Sets the status to WARNING.
+ * @param warningMessage the warning message (can be empty, but not null)
+ */
+ public void setWarning(String warningMessage) {
+ Assert.isNotNull(warningMessage);
+ fStatusMessage= warningMessage;
+ fSeverity= IStatus.WARNING;
+ }
+
+ /**
+ * Sets the status to INFO.
+ * @param infoMessage the info message (can be empty, but not null)
+ */
+ public void setInfo(String infoMessage) {
+ Assert.isNotNull(infoMessage);
+ fStatusMessage= infoMessage;
+ fSeverity= IStatus.INFO;
+ }
+
+ /**
+ * Sets the status to OK.
+ */
+ public void setOK() {
+ fStatusMessage= null;
+ fSeverity= IStatus.OK;
+ }
+
+ /*
+ * @see IStatus#matches(int)
+ */
+ public boolean matches(int severityMask) {
+ return (fSeverity & severityMask) != 0;
+ }
+
+ /**
+ * Returns always <code>false</code>.
+ * @see IStatus#isMultiStatus()
+ */
+ public boolean isMultiStatus() {
+ return false;
+ }
+
+ /*
+ * @see IStatus#getSeverity()
+ */
+ public int getSeverity() {
+ return fSeverity;
+ }
+
+ /*
+ * @see IStatus#getPlugin()
+ */
+ public String getPlugin() {
+ return TestunitPlugin.PLUGIN_ID;
+ }
+
+ /**
+ * Returns always <code>null</code>.
+ * @see IStatus#getException()
+ */
+ public Throwable getException() {
+ return null;
+ }
+
+ /**
+ * Returns always the error severity.
+ * @see IStatus#getCode()
+ */
+ public int getCode() {
+ return fSeverity;
+ }
+
+ /**
+ * Returns always <code>null</code>.
+ * @see IStatus#getChildren()
+ */
+ public IStatus[] getChildren() {
+ return new IStatus[0];
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|