001: package discRack.presentation.dpanels;
002:
003: import discRack.presentation.delements.*;
004:
005: import discRack.presentation.*;
006:
007: import javax.swing.*;
008: import javax.swing.border.*;
009:
010: import java.awt.*;
011:
012: /**
013: * Base class for all panels that manage data of elements.
014: *
015: * @author Sasa Bojanic
016: * @version 1.0
017: */
018: public class DPanel extends JPanel {
019: public static final Dimension textFieldDimension = new Dimension(
020: 200, 20);
021: public static final Dimension tableDimension = new Dimension(700,
022: 375);
023:
024: private DSimpleElement myOwner;
025: private String title;
026:
027: public DPanel() {
028: super ();
029: }
030:
031: public DPanel(DSimpleElement myOwner, int noOfElements,
032: String title, boolean isVertical, boolean hasBorder) {
033:
034: super ();
035:
036: this .myOwner = myOwner;
037:
038: setTitle(title, hasBorder);
039:
040: setLayout(new BoxLayout(this , ((isVertical) ? BoxLayout.Y_AXIS
041: : BoxLayout.X_AXIS)));
042: setAlignmentX(Component.LEFT_ALIGNMENT);
043: setAlignmentY(Component.TOP_ALIGNMENT);
044:
045: if (myOwner != null) {
046: setEnabled(!myOwner.isReadOnly());
047: }
048:
049: }
050:
051: public void setTitle(String title, boolean hasBorder) {
052: this .title = title;
053:
054: int emptyBorderHSize = 10;
055: int emptyBorderVSize = 10;
056: if (!hasBorder) {
057: emptyBorderVSize = 1;
058: }
059: Border emptyb = BorderFactory.createEmptyBorder(
060: emptyBorderVSize, emptyBorderHSize, emptyBorderVSize,
061: emptyBorderHSize);
062: Border inb = BorderFactory.createEmptyBorder(0, 0, 0, 0);
063: if (hasBorder) {
064: inb = BorderFactory.createMatteBorder(1, 1, 1, 1,
065: Color.darkGray);
066: inb = BorderFactory.createTitledBorder(inb, title);
067: } else {
068: emptyb = BorderFactory.createTitledBorder(emptyb, title);
069: }
070: setBorder(BorderFactory.createCompoundBorder(emptyb, inb));
071: }
072:
073: public static void defaultErrorMessage(Window w, String elementTitle) {
074: String message = "The value must be defined, define it or press Cancel !!!";
075: String dialogTitle = "Value is not defined";
076:
077: DPanel.errorMessage(w, dialogTitle, elementTitle, message);
078: }
079:
080: public static void errorMessage(Window w, String dialogTitle,
081: String elementTitle, String message) {
082: JOptionPane.showMessageDialog(w, elementTitle + message,
083: dialogTitle, JOptionPane.ERROR_MESSAGE);
084: }
085:
086: public DSimpleElement getOwner() {
087: return myOwner;
088: }
089:
090: public String getTitle() {
091: return title;
092: }
093:
094: /**
095: * Checks if the element that owns panel
096: */
097: public boolean checkRequired() {
098: return true;
099: }
100:
101: // Always returns true, this is set because of panels that are never empty
102: // but this method is used when checking emptiness of group panel,
103: // and panels that do not override this method should not be ever considered
104: public boolean isEmpty() {
105: return true;
106: }
107:
108: public void setElements() {
109: return;
110: }
111:
112: /**
113: * Find the hosting window.
114: */
115: public Window getWindow() {
116: for (Container p = getParent(); p != null; p = p.getParent()) {
117: if (p instanceof Window) {
118: return (Window) p;
119: }
120: }
121: return null;
122: }
123:
124: }
|