1 19 20 package org.netbeans.core.windows.view.ui.slides; 21 22 import java.awt.Component ; 23 import java.awt.Rectangle ; 24 import javax.swing.JComponent ; 25 import javax.swing.JLayeredPane ; 26 import javax.swing.event.ChangeEvent ; 27 import javax.swing.event.ChangeListener ; 28 import org.netbeans.core.windows.Constants; 29 import org.netbeans.swing.tabcontrol.SlideBarDataModel; 30 31 32 39 class SlideOperationImpl implements SlideOperation, ChangeListener { 40 41 42 private final int type; 43 45 private final Component component; 46 47 private final SlidingFx effect; 48 49 private final boolean requestsActivation; 50 51 private final String side; 52 53 protected Rectangle startBounds; 54 55 protected Rectangle finishBounds; 56 57 private JLayeredPane pane; 58 59 private Integer layer; 60 61 62 SlideOperationImpl(int type, Component component, int orientation, 63 SlidingFx effect, boolean requestsActivation) { 64 this(type, component, orientation2Side(orientation), effect, requestsActivation); 65 } 66 67 SlideOperationImpl(int type, Component component, String side, 68 SlidingFx effect, boolean requestsActivation) { 69 this.type = type; 70 this.component = component; 71 this.effect = effect; 72 this.requestsActivation = requestsActivation; 73 this.side = side; 74 } 75 76 public void run(JLayeredPane pane, Integer layer) { 77 if (effect != null && effect.shouldOperationWait()) { 78 this.pane = pane; 81 this.layer = layer; 82 effect.setFinishListener(this); 83 effect.showEffect(pane, layer, this); 84 } else { 85 if (effect != null) { 86 effect.showEffect(pane, layer, this); 87 } 88 performOperation(pane, layer); 89 } 90 } 91 92 93 public void stateChanged(ChangeEvent e) { 94 performOperation(pane, layer); 95 pane = null; 96 layer = null; 97 } 98 99 private void performOperation(JLayeredPane pane, Integer layer) { 100 switch (type) { 102 case SLIDE_IN: 103 component.setBounds(finishBounds); 104 pane.add(component, layer); 105 break; 106 case SLIDE_OUT: 107 pane.remove(component); 108 break; 109 case SLIDE_RESIZE: 110 component.setBounds(finishBounds); 111 ((JComponent )component).revalidate(); 112 break; 113 } 114 } 115 116 public void setFinishBounds(Rectangle bounds) { 117 this.finishBounds = bounds; 118 } 119 120 public void setStartBounds(Rectangle bounds) { 121 this.startBounds = bounds; 122 } 123 124 public String getSide() { 125 return side; 126 } 127 128 public Component getComponent() { 129 return component; 130 } 131 132 public Rectangle getFinishBounds() { 133 return finishBounds; 134 } 135 136 public Rectangle getStartBounds() { 137 return startBounds; 138 } 139 140 public boolean requestsActivation() { 141 return requestsActivation; 142 } 143 144 protected static String orientation2Side (int orientation) { 145 String side = Constants.LEFT; 146 if (orientation == SlideBarDataModel.WEST) { 147 side = Constants.LEFT; 148 } else if (orientation == SlideBarDataModel.EAST) { 149 side = Constants.RIGHT; 150 } else if (orientation == SlideBarDataModel.SOUTH) { 151 side = Constants.BOTTOM; 152 } 153 return side; 154 } 155 156 public int getType () { 157 return type; 158 } 159 160 public void prepareEffect() { 161 if (effect != null) { 162 effect.prepareEffect(this); 163 } 164 } 165 166 static int side2Orientation(String side) { 167 int orientation = SlideBarDataModel.WEST; 168 if (Constants.LEFT.equals(side)) { 169 orientation = SlideBarDataModel.WEST; 170 } else if (Constants.RIGHT.equals(side)) { 171 orientation = SlideBarDataModel.EAST; 172 } else if (Constants.BOTTOM.equals(side)) { 173 orientation = SlideBarDataModel.SOUTH; 174 } 175 return orientation; 176 } 177 } 178 | Popular Tags |