1 package discRack.presentation.dpanels; 2 3 import discRack.presentation.delements.*; 4 5 import discRack.presentation.*; 6 7 import javax.swing.*; 8 import javax.swing.border.*; 9 10 import java.awt.*; 11 12 18 public class DPanel extends JPanel { 19 public static final Dimension textFieldDimension=new Dimension(200,20); 20 public static final Dimension tableDimension=new Dimension(700,375); 21 22 23 private DSimpleElement myOwner; 24 private String title; 25 26 public DPanel () { 27 super(); 28 } 29 30 public DPanel (DSimpleElement myOwner,int noOfElements,String title, 31 boolean isVertical,boolean hasBorder) { 32 33 super(); 34 35 this.myOwner=myOwner; 36 37 setTitle(title,hasBorder); 38 39 setLayout(new BoxLayout(this,((isVertical) ? BoxLayout.Y_AXIS:BoxLayout.X_AXIS))); 40 setAlignmentX(Component.LEFT_ALIGNMENT); 41 setAlignmentY(Component.TOP_ALIGNMENT); 42 43 if (myOwner!=null) { 44 setEnabled(!myOwner.isReadOnly()); 45 } 46 47 } 48 49 public void setTitle (String title,boolean hasBorder) { 50 this.title=title; 51 52 int emptyBorderHSize=10; 53 int emptyBorderVSize=10; 54 if (!hasBorder) { 55 emptyBorderVSize=1; 56 } 57 Border emptyb=BorderFactory.createEmptyBorder(emptyBorderVSize,emptyBorderHSize, 58 emptyBorderVSize,emptyBorderHSize); 59 Border inb=BorderFactory.createEmptyBorder(0,0,0,0); 60 if (hasBorder) { 61 inb=BorderFactory.createMatteBorder(1,1,1,1,Color.darkGray); 62 inb=BorderFactory.createTitledBorder(inb,title); 63 } 64 else { 65 emptyb=BorderFactory.createTitledBorder(emptyb,title); 66 } 67 setBorder(BorderFactory.createCompoundBorder(emptyb,inb)); 68 } 69 70 public static void defaultErrorMessage (Window w,String elementTitle) { 71 String message="The value must be defined, define it or press Cancel !!!"; 72 String dialogTitle="Value is not defined"; 73 74 DPanel.errorMessage(w,dialogTitle,elementTitle,message); 75 } 76 77 public static void errorMessage (Window w,String dialogTitle,String elementTitle,String message) { 78 JOptionPane.showMessageDialog(w,elementTitle+message, 79 dialogTitle,JOptionPane.ERROR_MESSAGE); 80 } 81 82 public DSimpleElement getOwner () { 83 return myOwner; 84 } 85 86 public String getTitle() { 87 return title; 88 } 89 90 93 public boolean checkRequired () { 94 return true; 95 } 96 97 public boolean isEmpty () { 101 return true; 102 } 103 104 public void setElements () { 105 return; 106 } 107 108 111 public Window getWindow () { 112 for (Container p = getParent(); p != null; p = p.getParent()) { 113 if (p instanceof Window) { 114 return (Window)p; 115 } 116 } 117 return null; 118 } 119 120 } 121 | Popular Tags |