1 10 11 12 package org.enhydra.jawe.xml.panels; 13 14 import org.enhydra.jawe.xml.*; 15 16 import javax.swing.*; 17 import javax.swing.border.*; 18 19 import java.awt.*; 20 21 public class XMLPanel extends JPanel { 22 23 public static int GRID_LAYOUT=0; 24 public static int BOX_LAYOUT=1; 25 26 private XMLElement myOwner; 27 private String title; 28 29 public XMLPanel () { 30 super(); 31 } 32 33 public XMLPanel (XMLElement myOwner,int noOfElements,String title,int layout, 34 boolean isVertical,boolean hasBorder) { 35 36 super(); 37 38 this.myOwner=myOwner; 39 40 setTitle(title,hasBorder); 41 42 if (layout==XMLPanel.BOX_LAYOUT) { 43 setLayout(new BoxLayout(this,((isVertical) ? BoxLayout.Y_AXIS:BoxLayout.X_AXIS))); 44 } 45 else { 46 setLayout(new GridLayout 47 (((isVertical) ? noOfElements : 1),((isVertical) ? 1 : noOfElements))); 48 } 49 setAlignmentX(Component.LEFT_ALIGNMENT); 50 setAlignmentY(Component.TOP_ALIGNMENT); 51 52 if (myOwner!=null) { 53 setEnabled(!myOwner.isReadOnly()); 54 } 55 56 } 57 58 public void setTitle (String title,boolean hasBorder) { 59 this.title=title; 60 61 int emptyBorderHSize=5; 62 int emptyBorderVSize=1; 63 64 Border emptyb=BorderFactory.createEmptyBorder(emptyBorderVSize,emptyBorderHSize, 65 emptyBorderVSize,emptyBorderHSize); 66 Border inb=BorderFactory.createEmptyBorder(0,0,0,0); 67 if (hasBorder) { 68 inb=BorderFactory.createMatteBorder(1,1,1,1,Color.darkGray); 69 inb=BorderFactory.createTitledBorder(inb,title); 70 } 71 else { 72 emptyb=BorderFactory.createTitledBorder(emptyb,title); 73 } 74 setBorder(BorderFactory.createCompoundBorder(emptyb,inb)); 75 } 76 77 public static void defaultErrorMessage (Window w,String elementTitle) { 78 String message=XMLUtil.getLanguageDependentString("ErrorValueMustBeDefined"); 79 String dialogTitle=XMLUtil.getLanguageDependentString("DialogValueIsNotDefined"); 80 XMLPanel.errorMessage(w,dialogTitle,elementTitle,message); 81 } 82 83 public static void errorMessage (Window w,String dialogTitle,String elementTitle,String message) { 84 JOptionPane.showMessageDialog(w,elementTitle+message, 85 dialogTitle,JOptionPane.ERROR_MESSAGE); 86 } 87 88 public XMLElement getOwner () { 89 return myOwner; 90 } 91 92 public String getTitle() { 93 return title; 94 } 95 96 99 public boolean checkRequired () { 100 return true; 101 } 102 103 public boolean isEmpty () { 107 return true; 108 } 109 110 public void setElements () { 111 return; 112 } 113 114 117 public JDialog getDialog () { 118 for (Container p = getParent(); p != null; p = p.getParent()) { 119 if (p instanceof JDialog) { 120 return (JDialog)p; 121 } 122 } 123 return null; 124 } 125 126 } 127 | Popular Tags |