1 package net.suberic.util.gui.propedit; 2 import javax.swing.*; 3 import java.awt.Dimension ; 4 import java.util.logging.Logger ; 5 6 10 public abstract class LabelValuePropertyEditor extends SwingPropertyEditor { 11 protected java.awt.Container labelComponent; 14 15 protected java.awt.Container valueComponent; 18 19 30 protected void updateEditorEnabled() { 31 if (valueComponent != null) 32 valueComponent.setEnabled(isEditorEnabled()); 33 if (labelComponent != null) 34 labelComponent.setEnabled(isEditorEnabled()); 35 } 36 37 40 public JLabel createLabel() { 41 String defaultLabel; 42 int dotIndex = property.lastIndexOf("."); 43 if (dotIndex == -1) 44 defaultLabel = new String (property); 45 else 46 defaultLabel = property.substring(dotIndex+1); 47 48 JLabel returnValue = new JLabel(manager.getProperty(editorTemplate + ".label", defaultLabel)); 49 50 return returnValue; 51 } 52 53 56 public java.awt.Container getValueComponent() { 57 return valueComponent; 58 } 59 60 63 public java.awt.Container getLabelComponent() { 64 return labelComponent; 65 } 66 67 70 public Dimension getMinimumLabelSize() { 71 if (labelComponent != null) { 72 return labelComponent.getMinimumSize(); 73 } else { 74 return new Dimension (0,0); 75 } 76 } 77 78 81 public Dimension getMinimumValueSize() { 82 if (valueComponent != null) { 83 return valueComponent.getMinimumSize(); 84 } else { 85 return new Dimension (0,0); 86 } 87 } 88 89 92 public Dimension getMinimumTotalSize() { 93 return this.getMinimumSize(); 94 } 95 96 99 public void setSizes(Dimension labelSize, Dimension valueSize) { 100 if (labelComponent != null) 101 labelComponent.setSize(labelSize); 102 if (valueComponent != null) 103 valueComponent.setSize(valueSize); 104 } 105 106 109 public void setWidths(int labelWidth, int valueWidth) { 110 if (labelComponent != null) 111 labelComponent.setSize(new Dimension (labelWidth, labelComponent.getSize().height)); 112 if (valueComponent != null) 113 valueComponent.setSize(new Dimension (valueWidth, valueComponent.getSize().height)); 114 } 115 116 119 public void setHeights(int labelHeight, int valueHeight) { 120 if (labelComponent != null) 121 labelComponent.setSize(new Dimension (labelComponent.getSize().width, labelHeight)); 122 if (valueComponent != null) 123 valueComponent.setSize(new Dimension (valueComponent.getSize().width, valueHeight)); 124 } 125 126 129 public PropertyEditorPane getPropertyEditorPane() { 130 return getPropertyEditorPane(valueComponent); 131 } 132 133 136 public String getDisplayValue() { 137 java.awt.Container labelComponent = getLabelComponent(); 138 if (labelComponent instanceof JLabel) { 139 return ((JLabel) labelComponent).getText(); 140 } else { 141 return getProperty(); 142 } 143 } 144 145 148 public boolean acceptDefaultFocus() { 149 if (isEditorEnabled()) { 150 156 valueComponent.requestFocusInWindow(); 157 return true; 158 } else { 159 return false; 160 } 161 } 162 } 163 | Popular Tags |