1 19 27 28 package org.netbeans.modules.xml.schema.abe; 29 30 import java.awt.Component ; 31 import java.awt.event.MouseAdapter ; 32 import java.awt.event.MouseEvent ; 33 import javax.swing.SpringLayout ; 34 35 39 public class ExtraPropertiesPanel extends AutoSizingPanel{ 40 private static final long serialVersionUID = 7526472295622776147L; 41 SpringLayout layout; 42 boolean leftToRight = true; 43 44 public ExtraPropertiesPanel(boolean leftToRight, InstanceUIContext context) { 45 super(context); 46 if(leftToRight){ 47 setFixedHeight(true); 48 setHorizontalScaling(true); 49 setFixedPanelHeight(AttributePanel.getAttributePanelHeight()); 50 setInterComponentSpacing(5); 51 }else{ 52 setVerticalScaling(true); 53 setInterComponentSpacing(-2); 54 } 55 setOpaque(false); 56 this.leftToRight = leftToRight; 57 } 58 59 public void append(Component component, boolean transmitEvent2parent){ 60 if(leftToRight) 61 appendRight(component, transmitEvent2parent); 62 else 63 appendBelow(component); 64 65 } 66 67 Component lastComponent; 68 private void appendRight(Component component, boolean transmitEvent2Parent){ 69 boolean alreadyAdded = false; 70 if(layout == null){ 71 layout = new SpringLayout (); 72 setLayout(layout); 73 alreadyAdded = true; 74 add(component); 75 layout.putConstraint(SpringLayout.WEST, component, getInterComponentSpacing(), 76 SpringLayout.WEST, this); 77 lastComponent = component; 78 } 79 if(!alreadyAdded){ 80 add(component); 81 layout.putConstraint(SpringLayout.WEST, component, getInterComponentSpacing(), 82 SpringLayout.EAST, lastComponent); 83 } 84 layout.putConstraint(SpringLayout.NORTH, component, 0, 85 SpringLayout.NORTH, this); 86 lastComponent = component; 87 if(transmitEvent2Parent) 88 component.addMouseListener(new MouseAdapter (){ 89 public void mouseReleased(MouseEvent e) { 90 ExtraPropertiesPanel.this.dispatchEvent(e); 91 } 92 93 public void mouseClicked(MouseEvent e) { 94 ExtraPropertiesPanel.this.dispatchEvent(e); 95 } 96 97 public void mousePressed(MouseEvent e) { 98 ExtraPropertiesPanel.this.dispatchEvent(e); 99 } 100 101 }); 102 } 103 104 private void appendBelow(Component component){ 105 boolean alreadyAdded = false; 106 if(layout == null){ 107 layout = new SpringLayout (); 108 setLayout(layout); 109 alreadyAdded = true; 110 add(component); 111 layout.putConstraint(SpringLayout.NORTH, component, getInterComponentSpacing(), 112 SpringLayout.NORTH, this); 113 lastComponent = component; 114 } 115 if(!alreadyAdded){ 116 add(component); 117 layout.putConstraint(SpringLayout.NORTH, component, getInterComponentSpacing(), 118 SpringLayout.SOUTH, lastComponent); 119 } 120 layout.putConstraint(SpringLayout.WEST, component, 0, 121 SpringLayout.WEST, this); 122 lastComponent = component; 123 124 component.addMouseListener(new MouseAdapter (){ 125 public void mouseReleased(MouseEvent e) { 126 ExtraPropertiesPanel.this.dispatchEvent(e); 127 } 128 129 public void mouseClicked(MouseEvent e) { 130 ExtraPropertiesPanel.this.dispatchEvent(e); 131 } 132 133 public void mousePressed(MouseEvent e) { 134 ExtraPropertiesPanel.this.dispatchEvent(e); 135 } 136 137 }); 138 } 139 140 public void cleanupAll(){ 141 for(Component child: getComponents()){ 142 remove(child); 143 } 144 layout = null; 145 } 146 147 148 149 } 150 | Popular Tags |