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