1 32 33 package it.businesslogic.ireport.gui; 34 35 import it.businesslogic.ireport.gui.event.*; 36 import java.beans.*; 37 import javax.swing.*; 38 import java.awt.datatransfer.DataFlavor ; 39 import java.awt.datatransfer.Transferable ; 40 import java.awt.dnd.DnDConstants ; 41 import java.awt.dnd.DropTarget ; 42 import java.awt.dnd.DropTargetContext ; 43 import java.awt.dnd.DropTargetDragEvent ; 44 import java.awt.dnd.DropTargetDropEvent ; 45 import java.awt.dnd.DropTargetEvent ; 46 import java.awt.dnd.DropTargetListener ; 47 48 57 public class JMDIDesktopPane extends javax.swing.JDesktopPane implements java.io.Serializable { 58 59 private DropTarget dropTarget; 60 private DropTargetListener dtListener; 61 private int acceptableActions = DnDConstants.ACTION_COPY_OR_MOVE; 62 63 64 private static final String PROP_SAMPLE_PROPERTY = "SampleProperty"; 65 66 private String sampleProperty; 67 68 private PropertyChangeSupport propertySupport; 69 70 71 private javax.swing.event.EventListenerList listenerList = null; 72 73 74 public JMDIDesktopPane() { 75 super(); 76 propertySupport = new PropertyChangeSupport( this ); 77 78 this.dtListener = new DTListener(); 79 80 this.dropTarget = new DropTarget (this, 82 this.acceptableActions, 83 this.dtListener, 84 true); 85 } 86 87 public void internalFrameActivated(JMDIFrame jMDIFrame) 88 { 89 this.fireInternalFrameActivatedListenerInternalFrameActivated(new InternalFrameActivatedEvent(jMDIFrame)); 90 } 91 92 public void internalFrameClosed(JMDIFrame jMDIFrame) 93 { 94 if (this.getAllFrames().length == 1) 95 { 96 this.fireInternalFrameActivatedListenerInternalFrameActivated(new InternalFrameActivatedEvent(null) ); 97 } 98 this.fireInternalFrameActivatedListenerInternalFrameActivated(new InternalFrameActivatedEvent(jMDIFrame, InternalFrameActivatedEvent.CLOSED ) ); 99 } 100 101 102 public String getSampleProperty() { 103 return sampleProperty; 104 } 105 106 public void setSampleProperty(String value) { 107 String oldValue = sampleProperty; 108 sampleProperty = value; 109 propertySupport.firePropertyChange(PROP_SAMPLE_PROPERTY, oldValue, sampleProperty); 110 } 111 112 113 public void addPropertyChangeListener(PropertyChangeListener listener) { 114 if (listener == null || propertySupport == null) return; 115 propertySupport.addPropertyChangeListener(listener); 116 } 117 118 public void removePropertyChangeListener(PropertyChangeListener listener) { 119 propertySupport.removePropertyChangeListener(listener); 120 } 121 122 126 public synchronized void addInternalFrameActivatedListener(it.businesslogic.ireport.gui.event.InternalFrameActivatedListener listener) { 127 if (listenerList == null ) { 128 listenerList = new javax.swing.event.EventListenerList (); 129 } 130 listenerList.add(it.businesslogic.ireport.gui.event.InternalFrameActivatedListener.class, listener); 131 } 132 133 137 public synchronized void removeInternalFrameActivatedListener(it.businesslogic.ireport.gui.event.InternalFrameActivatedListener listener) { 138 listenerList.remove(it.businesslogic.ireport.gui.event.InternalFrameActivatedListener.class, listener); 139 } 140 141 146 private void fireInternalFrameActivatedListenerInternalFrameActivated(it.businesslogic.ireport.gui.event.InternalFrameActivatedEvent event) { 147 if (listenerList == null) return; 148 Object [] listeners = listenerList.getListenerList(); 149 for (int i = listeners.length-2; i>=0; i-=2) { 150 if (listeners[i]==it.businesslogic.ireport.gui.event.InternalFrameActivatedListener.class) { 151 ((it.businesslogic.ireport.gui.event.InternalFrameActivatedListener)listeners[i+1]).internalFrameActivated(event); 152 } 153 } 154 } 155 156 public void cascade() 157 { 158 JInternalFrame[] frames = this.getAllFrames(); 159 if (frames.length == 0) return; 160 161 JInternalFrame activeframe = this.getSelectedFrame(); 162 163 int position =0; 164 for (int i=0; i<frames.length; ++i) 165 { 166 try { 167 frames[i].setMaximum(false); 168 frames[i].setIcon(false); 169 frames[i].moveToFront(); 170 } catch (Exception ex){} 171 if (frames[i] != activeframe) 172 { 173 frames[i].setLocation(position,position); 174 175 position += 24; 176 } 177 } 178 179 if (activeframe != null) 180 { 181 activeframe.moveToFront(); 182 activeframe.setLocation(position,position); 183 } 184 } 185 186 188 public void tileVertically() 189 { 190 JInternalFrame[] frames_tmp = this.getAllFrames(); 191 192 if (frames_tmp.length == 0) return; 193 194 JInternalFrame[] frames = new JInternalFrame[frames_tmp.length]; 195 if (this.getSelectedFrame() == null && frames_tmp[0].isIcon()) 196 { 197 try { 198 frames_tmp[0].setIcon(false); 199 frames_tmp[0].setSelected(true); 200 } catch (Exception ex){ return; } 201 } 202 frames[0] = this.getSelectedFrame(); 203 204 int k=1; 205 for (int i=0; i<frames_tmp.length; ++i) 206 { 207 if (frames_tmp[i] == frames[0]) continue; 208 frames[k] = frames_tmp[i]; 209 k++; 210 } 211 212 214 215 int w = getWidth() / frames.length; 216 int lastWidth = 0; 217 if( frames.length > 1) 218 lastWidth = getWidth() - (w * (frames.length - 1)); 219 else 220 lastWidth = w; 221 222 int h = getHeight(); 223 int posX = 0; 224 int countVisible = 0; 225 226 for (int i=0; i<frames.length; ++i) 227 { 228 try { 229 frames[i].setMaximum(false); 230 frames[i].setIcon(false); 231 frames[i].moveToFront(); 232 } catch (Exception ex){} 233 234 if( i < frames.length) { 235 frames[i].setLocation(posX, 0); 236 frames[i].setSize(w, h); 237 posX += w; 238 } 239 else { frames[i].setLocation(posX, 0); 241 frames[i].setSize(lastWidth, h); 242 } 243 } 244 } 245 246 248 public void tileHorizontally() 249 { 250 JInternalFrame[] frames_tmp = this.getAllFrames(); 251 252 if (frames_tmp.length == 0) return; 253 254 JInternalFrame[] frames = new JInternalFrame[frames_tmp.length]; 255 if (this.getSelectedFrame() == null && frames_tmp[0].isIcon()) 256 { 257 try { 258 frames_tmp[0].setIcon(false); 259 frames_tmp[0].setSelected(true); 260 } catch (Exception ex){ return; } 261 } 262 frames[0] = this.getSelectedFrame(); 263 264 int k=1; 265 for (int i=0; i<frames_tmp.length; ++i) 266 { 267 if (frames_tmp[i] == frames[0]) continue; 268 else 269 { 270 frames[k] = frames_tmp[i]; 271 k++; 272 } 273 } 274 275 277 278 int w = getWidth() ; 279 280 281 int h = getHeight() / frames.length; 282 283 int lastHeight = 0; 284 if( frames.length > 1) 285 lastHeight = getHeight() - (h * (frames.length - 1)); 286 else 287 lastHeight = h; 288 289 int posY = 0; 290 int countVisible = 0; 291 292 for (int i=0; i<frames.length; ++i) 293 { 294 try { 295 frames[i].setMaximum(false); 296 frames[i].setIcon(false); 297 frames[i].moveToFront(); 298 } catch (Exception ex){} 299 300 if( i < frames.length) { 301 frames[i].setLocation(0,posY); 302 frames[i].setSize(w, h); 303 posY += h; 304 } 305 else { frames[i].setLocation(0,posY); 307 frames[i].setSize(w,lastHeight); 308 } 309 } 310 311 } 312 313 315 public void tileAnodine() 316 { 317 JInternalFrame[] frames_tmp = this.getAllFrames(); 318 319 if (frames_tmp.length == 0) return; 320 321 JInternalFrame[] frames = new JInternalFrame[frames_tmp.length]; 322 323 if (this.getSelectedFrame() == null && frames_tmp[0].isIcon()) 324 { 325 try { 326 frames_tmp[0].setIcon(false); 327 frames_tmp[0].setSelected(true); 328 } catch (Exception ex){ return; } 329 } 330 331 frames[0] = this.getSelectedFrame(); 332 int k=1; 333 for (int i=0; i<frames_tmp.length; ++i) 334 { 335 if (frames_tmp[i] == frames[0]) continue; 336 frames[k] = frames_tmp[i]; 337 k++; 338 } 339 340 int numVisible=frames.length; 341 if(numVisible<1)return; 342 int numCols= (int)Math.sqrt(numVisible); int[] numRows=new int[numCols]; 345 int numCurCol=0; 346 while(numCurCol<numCols){ 347 numRows[numCurCol]=numCols; numCurCol++; 349 } 350 int numDiff=numVisible-(numCols*numCols); int numCurDiffCol=numCols; while(numDiff>0){ 353 numCurDiffCol--; 354 numRows[numCurDiffCol]++; if(numCurDiffCol<1)numCurDiffCol=numCols; numDiff--; 357 } 358 numCurCol=0; 359 int numCurRow=0; 360 int curX=0; 361 int curY=0; 362 int xQuantum= getWidth()/numCols; 366 int yQuantum= getHeight()/numRows[numCurCol]; 367 368 for (int i=0; i<frames.length; ++i) 369 { 370 try { 371 frames[i].setMaximum(false); 372 frames[i].setIcon(false); 373 frames[i].moveToFront(); 374 } catch (Exception ex){} 375 376 frames[i].setLocation(curX,curY); 377 frames[i].setSize(xQuantum, yQuantum); 378 numCurRow++; 379 curY+=yQuantum; 380 if(numCurRow==numRows[numCurCol]){ 381 numCurRow=0; 382 numCurCol++; 383 curY=0; 384 curX+=xQuantum; 385 if(numCurCol!=numCols)yQuantum= getHeight()/numRows[numCurCol]; 386 } 387 } 388 } 389 390 391 392 } 393 394 | Popular Tags |