diff options
| author | Paul Buetow <paul@buetow.org> | 2009-02-18 23:01:21 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2009-02-18 23:01:21 +0000 |
| commit | 89c679eb813611a2ede208b4c8e27c7f596b3be7 (patch) | |
| tree | f44c19435286e78b9e8002990e1b55183a4fbc49 /sources/client/helper | |
| parent | 177f346a9bbe455dc12fd26dfa2c586585c28c1e (diff) | |
added copyright to header
Diffstat (limited to 'sources/client/helper')
| -rw-r--r-- | sources/client/helper/DateSpinner.java | 88 | ||||
| -rw-r--r-- | sources/client/helper/GUIHelper.java | 342 |
2 files changed, 219 insertions, 211 deletions
diff --git a/sources/client/helper/DateSpinner.java b/sources/client/helper/DateSpinner.java index e374107..3683bc2 100644 --- a/sources/client/helper/DateSpinner.java +++ b/sources/client/helper/DateSpinner.java @@ -1,3 +1,7 @@ +/* NetCalendar 2006, 2009 (c) Dipl.-Inform. (FH) Paul C. Buetow + * http://netcalendar.buetow.org - netcalendar@dev.buetow.org + */ + package client.helper; @@ -12,46 +16,46 @@ import javax.swing.*; * @author buetow */ public class DateSpinner extends JComponent { - private final static long serialVersionUID = 1L; - private Date date; - private SpinnerDateModel spinnerDateModel; - - /** - * Creates a date spinner to set/edit a given date. This constructor uses the - * current date! - */ - public DateSpinner() { - this.date = new Date(); - initComponents(); - } - - /** - * Creates a date spinner to set/edit a given date. - * @param date The date to be used for the date spinner! - */ - public DateSpinner(Date date) { - this.date = date; - initComponents(); - } - - /** - * Initializes all the date spinner GUI components. - */ - private void initComponents() { - setLayout(new FlowLayout(FlowLayout.LEFT, 4, 4)); - - spinnerDateModel = new SpinnerDateModel(date, null, null, Calendar.MONTH); - JSpinner jSpinner = new JSpinner(spinnerDateModel); - new JSpinner.DateEditor(jSpinner, "MM/yy"); - - add(jSpinner); - } - - /** - * Returns the date which is represented by this spinner. - * @return Returns the date which is represented by this spinner. - */ - public Date getDate() { - return spinnerDateModel.getDate(); - } + private final static long serialVersionUID = 1L; + private Date date; + private SpinnerDateModel spinnerDateModel; + + /** + * Creates a date spinner to set/edit a given date. This constructor uses the + * current date! + */ + public DateSpinner() { + this.date = new Date(); + initComponents(); + } + + /** + * Creates a date spinner to set/edit a given date. + * @param date The date to be used for the date spinner! + */ + public DateSpinner(Date date) { + this.date = date; + initComponents(); + } + + /** + * Initializes all the date spinner GUI components. + */ + private void initComponents() { + setLayout(new FlowLayout(FlowLayout.LEFT, 4, 4)); + + spinnerDateModel = new SpinnerDateModel(date, null, null, Calendar.MONTH); + JSpinner jSpinner = new JSpinner(spinnerDateModel); + new JSpinner.DateEditor(jSpinner, "MM/yy"); + + add(jSpinner); + } + + /** + * Returns the date which is represented by this spinner. + * @return Returns the date which is represented by this spinner. + */ + public Date getDate() { + return spinnerDateModel.getDate(); + } } diff --git a/sources/client/helper/GUIHelper.java b/sources/client/helper/GUIHelper.java index 5da3bbf..a2de13a 100644 --- a/sources/client/helper/GUIHelper.java +++ b/sources/client/helper/GUIHelper.java @@ -1,3 +1,7 @@ +/* NetCalendar 2006, 2009 (c) Dipl.-Inform. (FH) Paul C. Buetow + * http://netcalendar.buetow.org - netcalendar@dev.buetow.org + */ + package client.helper; import javax.swing.*; @@ -12,178 +16,178 @@ import shared.*; * @author buetow */ public class GUIHelper { - /** - * Aligns the first <code>iRows</code> * <code>iCols</code> - * components of the parent in a grid. Each component is as big as the maximum - * preferred width and height of the components. - * The parent is made just big enough to fit them all. - * @param containerParent Specifies the container to be used - * @param iRows Specifies the number of rows to use. - * @param iCols Specifies the number of columns to use. - * @param iInitialX Specifies the x location to start the grid at. - * @param iInitialY Specifies the y location to start the grid at. - * @param iXPad Specifies the x padding between the cells. - * @param iYPad Specifies the y padding between the cells - */ - public static void makeGrid(Container containerParent, - int iRows, int iCols, - int iInitialX, int iInitialY, - int iXPad, int iYPad) { - SpringLayout helper; - try { - helper = (SpringLayout)containerParent.getLayout(); - } catch (ClassCastException exc) { - Main.infoMessage("Error: The first argument to makeGrid must use SpringLayout."); - return; - } - - Spring iXPadSpring = Spring.constant(iXPad); - Spring iYPadSpring = Spring.constant(iYPad); - Spring iInitialXSpring = Spring.constant(iInitialX); - Spring iInitialYSpring = Spring.constant(iInitialY); - int max = iRows * iCols; - - // Calculate Springs that are the max of the width/height so that all - // cells have the same size. - Spring maxWidthSpring = helper.getConstraints(containerParent.getComponent(0)). - getWidth(); - Spring maxHeightSpring = helper.getConstraints(containerParent.getComponent(0)). - getWidth(); - for (int i = 1; i < max; i++) { - SpringLayout.Constraints cons = helper.getConstraints( - containerParent.getComponent(i)); - - maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth()); - maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight()); - } - - // Apply the new width/height Spring. This forces all the - // components to have the same size. - for (int i = 0; i < max; i++) { - SpringLayout.Constraints cons = helper.getConstraints( - containerParent.getComponent(i)); - - cons.setWidth(maxWidthSpring); - cons.setHeight(maxHeightSpring); - } - - // Then adjust the x/y constraints of all the cells so that they - // are aligned in a grid. - SpringLayout.Constraints lastCons = null; - SpringLayout.Constraints lastRowCons = null; - for (int i = 0; i < max; i++) { - SpringLayout.Constraints cons = helper.getConstraints( - containerParent.getComponent(i)); - if (i % iCols == 0) { //start of new iRow - lastRowCons = lastCons; - cons.setX(iInitialXSpring); - } else { //x position depends on previous component - cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST), - iXPadSpring)); - } - - if (i / iCols == 0) { //first iRow - cons.setY(iInitialYSpring); - } else { //y position depends on previous iRow - cons.setY(Spring.sum(lastRowCons.getConstraint(SpringLayout.SOUTH), - iYPadSpring)); - } - lastCons = cons; - } - - // Set the containerParent's size. - SpringLayout.Constraints pCons = helper.getConstraints(containerParent); - pCons.setConstraint(SpringLayout.SOUTH, - Spring.sum(Spring.constant(iYPad), lastCons.getConstraint(SpringLayout.SOUTH))); - pCons.setConstraint(SpringLayout.EAST, - Spring.sum(Spring.constant(iXPad), lastCons.getConstraint(SpringLayout.EAST))); - } - - /** - * This is a helper method for makeGrid. It returns the constraints for a specific cell. - * @param iRow Specifies the row to get the constraints for. - * @param iCol Specifies the column to get the constraints for. - * @param containerParent Specifies the parent container. - * @param iCols Specifies the number of columns being used. - * @return Returns the constraints object of the current SpringLayout. - */ - private static SpringLayout.Constraints getConstraintsForCell(int iRow, int iCol, - Container containerParent, int iCols) { - - SpringLayout helper = (SpringLayout) containerParent.getLayout(); - Component component = containerParent.getComponent(iRow * iCols + iCol); - return helper.getConstraints(component); - } - - /** - * Aligns the first <code>iRows</code> * <code>iCols</code> - * components of <code>containerParent</code> in - * a grid. Each component in a iColumn is as wide as the maximum - * preferred width of the components in that iColumn; - * height is similarly determined for each iRow. - * The containerParent is made just big enough to fit them all. - * @param iRows Specifies number of rows. - * @param iCols Specifies the number of columns. - * @param iInitialX Specifies the x location to start the grid at. - * @param iInitialY Specifies the y location to start the grid at. - * @param iXPad Specifies the x padding between the cells. - * @param iYPad Specifies the y padding between the cells. - */ - public static void makeCompactGrid(Container containerParent, - int iRows, int iCols, - int iInitialX, int iInitialY, - int iXPad, int iYPad) { - SpringLayout helper; - - try { - helper = (SpringLayout)containerParent.getLayout(); - } catch (ClassCastException exc) { - Main.infoMessage("Error: The first argument to makeCompactGrid must use SpringLayout."); - return; + /** + * Aligns the first <code>iRows</code> * <code>iCols</code> + * components of the parent in a grid. Each component is as big as the maximum + * preferred width and height of the components. + * The parent is made just big enough to fit them all. + * @param containerParent Specifies the container to be used + * @param iRows Specifies the number of rows to use. + * @param iCols Specifies the number of columns to use. + * @param iInitialX Specifies the x location to start the grid at. + * @param iInitialY Specifies the y location to start the grid at. + * @param iXPad Specifies the x padding between the cells. + * @param iYPad Specifies the y padding between the cells + */ + public static void makeGrid(Container containerParent, + int iRows, int iCols, + int iInitialX, int iInitialY, + int iXPad, int iYPad) { + SpringLayout helper; + try { + helper = (SpringLayout)containerParent.getLayout(); + } catch (ClassCastException exc) { + Main.infoMessage("Error: The first argument to makeGrid must use SpringLayout."); + return; + } + + Spring iXPadSpring = Spring.constant(iXPad); + Spring iYPadSpring = Spring.constant(iYPad); + Spring iInitialXSpring = Spring.constant(iInitialX); + Spring iInitialYSpring = Spring.constant(iInitialY); + int max = iRows * iCols; + + // Calculate Springs that are the max of the width/height so that all + // cells have the same size. + Spring maxWidthSpring = helper.getConstraints(containerParent.getComponent(0)). + getWidth(); + Spring maxHeightSpring = helper.getConstraints(containerParent.getComponent(0)). + getWidth(); + for (int i = 1; i < max; i++) { + SpringLayout.Constraints cons = helper.getConstraints( + containerParent.getComponent(i)); + + maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth()); + maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight()); + } + + // Apply the new width/height Spring. This forces all the + // components to have the same size. + for (int i = 0; i < max; i++) { + SpringLayout.Constraints cons = helper.getConstraints( + containerParent.getComponent(i)); + + cons.setWidth(maxWidthSpring); + cons.setHeight(maxHeightSpring); + } + + // Then adjust the x/y constraints of all the cells so that they + // are aligned in a grid. + SpringLayout.Constraints lastCons = null; + SpringLayout.Constraints lastRowCons = null; + for (int i = 0; i < max; i++) { + SpringLayout.Constraints cons = helper.getConstraints( + containerParent.getComponent(i)); + if (i % iCols == 0) { //start of new iRow + lastRowCons = lastCons; + cons.setX(iInitialXSpring); + } else { //x position depends on previous component + cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST), + iXPadSpring)); + } + + if (i / iCols == 0) { //first iRow + cons.setY(iInitialYSpring); + } else { //y position depends on previous iRow + cons.setY(Spring.sum(lastRowCons.getConstraint(SpringLayout.SOUTH), + iYPadSpring)); + } + lastCons = cons; + } + + // Set the containerParent's size. + SpringLayout.Constraints pCons = helper.getConstraints(containerParent); + pCons.setConstraint(SpringLayout.SOUTH, + Spring.sum(Spring.constant(iYPad), lastCons.getConstraint(SpringLayout.SOUTH))); + pCons.setConstraint(SpringLayout.EAST, + Spring.sum(Spring.constant(iXPad), lastCons.getConstraint(SpringLayout.EAST))); } - // Align all cells in each iColumn and make them the same width. - Spring x = Spring.constant(iInitialX); - for (int c = 0; c < iCols; c++) { - Spring width = Spring.constant(0); - for (int r = 0; r < iRows; r++) { - width = Spring.max(width, - getConstraintsForCell(r, c, containerParent, iCols).getWidth()); - } - - for (int r = 0; r < iRows; r++) { - SpringLayout.Constraints constraints = - getConstraintsForCell(r, c, containerParent, iCols); - constraints.setX(x); - constraints.setWidth(width); - } - x = Spring.sum(x, Spring.sum(width, Spring.constant(iXPad))); + /** + * This is a helper method for makeGrid. It returns the constraints for a specific cell. + * @param iRow Specifies the row to get the constraints for. + * @param iCol Specifies the column to get the constraints for. + * @param containerParent Specifies the parent container. + * @param iCols Specifies the number of columns being used. + * @return Returns the constraints object of the current SpringLayout. + */ + private static SpringLayout.Constraints getConstraintsForCell(int iRow, int iCol, + Container containerParent, int iCols) { + + SpringLayout helper = (SpringLayout) containerParent.getLayout(); + Component component = containerParent.getComponent(iRow * iCols + iCol); + return helper.getConstraints(component); } - // Align all cells in each iRow and make them the same height. - Spring y = Spring.constant(iInitialY); - for (int r = 0; r < iRows; r++) { - Spring height = Spring.constant(0); - - for (int c = 0; c < iCols; c++) { - height = Spring.max(height, - getConstraintsForCell(r, c, containerParent, iCols).getHeight()); - } - - for (int c = 0; c < iCols; c++) { - SpringLayout.Constraints constraints = - getConstraintsForCell(r, c, containerParent, iCols); - - constraints.setY(y); - constraints.setHeight(height); - } - - y = Spring.sum(y, Spring.sum(height, Spring.constant(iYPad))); + /** + * Aligns the first <code>iRows</code> * <code>iCols</code> + * components of <code>containerParent</code> in + * a grid. Each component in a iColumn is as wide as the maximum + * preferred width of the components in that iColumn; + * height is similarly determined for each iRow. + * The containerParent is made just big enough to fit them all. + * @param iRows Specifies number of rows. + * @param iCols Specifies the number of columns. + * @param iInitialX Specifies the x location to start the grid at. + * @param iInitialY Specifies the y location to start the grid at. + * @param iXPad Specifies the x padding between the cells. + * @param iYPad Specifies the y padding between the cells. + */ + public static void makeCompactGrid(Container containerParent, + int iRows, int iCols, + int iInitialX, int iInitialY, + int iXPad, int iYPad) { + SpringLayout helper; + + try { + helper = (SpringLayout)containerParent.getLayout(); + } catch (ClassCastException exc) { + Main.infoMessage("Error: The first argument to makeCompactGrid must use SpringLayout."); + return; + } + + // Align all cells in each iColumn and make them the same width. + Spring x = Spring.constant(iInitialX); + for (int c = 0; c < iCols; c++) { + Spring width = Spring.constant(0); + for (int r = 0; r < iRows; r++) { + width = Spring.max(width, + getConstraintsForCell(r, c, containerParent, iCols).getWidth()); + } + + for (int r = 0; r < iRows; r++) { + SpringLayout.Constraints constraints = + getConstraintsForCell(r, c, containerParent, iCols); + constraints.setX(x); + constraints.setWidth(width); + } + x = Spring.sum(x, Spring.sum(width, Spring.constant(iXPad))); + } + + // Align all cells in each iRow and make them the same height. + Spring y = Spring.constant(iInitialY); + for (int r = 0; r < iRows; r++) { + Spring height = Spring.constant(0); + + for (int c = 0; c < iCols; c++) { + height = Spring.max(height, + getConstraintsForCell(r, c, containerParent, iCols).getHeight()); + } + + for (int c = 0; c < iCols; c++) { + SpringLayout.Constraints constraints = + getConstraintsForCell(r, c, containerParent, iCols); + + constraints.setY(y); + constraints.setHeight(height); + } + + y = Spring.sum(y, Spring.sum(height, Spring.constant(iYPad))); + } + + // Set the containerParent's size. + SpringLayout.Constraints pCons = helper.getConstraints(containerParent); + pCons.setConstraint(SpringLayout.SOUTH, y); + pCons.setConstraint(SpringLayout.EAST, x); } - - // Set the containerParent's size. - SpringLayout.Constraints pCons = helper.getConstraints(containerParent); - pCons.setConstraint(SpringLayout.SOUTH, y); - pCons.setConstraint(SpringLayout.EAST, x); - } } |
