From: <dam...@us...> - 2006-03-20 00:55:40
|
Revision: 975 Author: damokles Date: 2006-03-19 16:55:22 -0800 (Sun, 19 Mar 2006) ViewCVS: http://svn.sourceforge.net/azcvsupdater/?rev=975&view=rev Log Message: ----------- added btn "Hide All" and killShell(); Modified Paths: -------------- trunk/AZMultiUser/lbms/azmultiuser/remote/client/firefrog/dialogs/MessageDialog.java Modified: trunk/AZMultiUser/lbms/azmultiuser/remote/client/firefrog/dialogs/MessageDialog.java =================================================================== --- trunk/AZMultiUser/lbms/azmultiuser/remote/client/firefrog/dialogs/MessageDialog.java 2006-03-20 00:21:06 UTC (rev 974) +++ trunk/AZMultiUser/lbms/azmultiuser/remote/client/firefrog/dialogs/MessageDialog.java 2006-03-20 00:55:22 UTC (rev 975) @@ -5,6 +5,9 @@ */ package lbms.azmultiuser.remote.client.firefrog.dialogs; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.StringTokenizer; import lbms.azmultiuser.remote.client.firefrog.FireFrogMain; @@ -37,6 +40,7 @@ private Display display; private int steps; private Image popupImage; + private static List<MessageDialog> messageDiags = Collections.synchronizedList(new ArrayList<MessageDialog>()); TimerEvent timerEvent; /** @@ -51,11 +55,12 @@ public MessageDialog(final Display display, final boolean bautoclose, final int timeToClose, final int steps, final String title, final String message){ - if(!Boolean.parseBoolean(FireFrogMain.getFFM().getProperties().getProperty("popups_enabled", "true"))) - return; + if(!Boolean.parseBoolean(FireFrogMain.getFFM().getProperties().getProperty("popups_enabled", "true"))) + return; - this.display = display; + this.display = display; this.steps = steps; + messageDiags.add(this); display.asyncExec(new Runnable (){ public void run() { @@ -88,8 +93,8 @@ gc.drawText(title, 10, 8, true); titleFont.dispose(); gc.setFont(messageFont); - Rectangle rect = new Rectangle(60,45,150,150); - printString(gc,message,rect); + Rectangle rect = new Rectangle(60,45,150,150); + printString(gc,message,rect); messageFont.dispose(); @@ -99,16 +104,24 @@ Button btnOK = new Button(splash, SWT.PUSH); btnOK.setText("OK"); + Button btnHideAll = new Button(splash, SWT.PUSH); + btnHideAll.setText("Hide All"); + Label lblImage = new Label(splash,SWT.NULL); lblImage.setImage(popupImage); FormData formData; formData = new FormData(); - formData.right = new FormAttachment(100,-5); + formData.right = new FormAttachment(100,-60); formData.bottom = new FormAttachment(100,-5); btnOK.setLayoutData(formData); formData = new FormData(); + formData.right = new FormAttachment(100,-5); + formData.bottom = new FormAttachment(100,-5); + btnHideAll.setLayoutData(formData); + + formData = new FormData(); formData.left = new FormAttachment(0,0); formData.top = new FormAttachment(0,0); lblImage.setLayoutData(formData); @@ -123,12 +136,20 @@ } }); - btnOK.addListener(SWT.Selection, new Listener(){ + btnOK.addListener(SWT.Selection, new Listener(){ public void handleEvent(Event arg0) { hideShell(); } }); - showShell(); + btnHideAll.addListener(SWT.Selection, new Listener(){ + public void handleEvent(Event arg0) { + MessageDialog[] list = messageDiags.toArray(new MessageDialog[] {}); + for (MessageDialog md:list) { + md.killShell(); + } + } + }); + showShell(); } }); } @@ -173,7 +194,7 @@ public void hideShell() { if (timerEvent != null) timerEvent.cancel(); - + messageDiags.remove(this); display.asyncExec(new Runnable() { public void run() { Rectangle splashRect = splash.getBounds(); @@ -208,81 +229,92 @@ }); } - public static boolean printString(GC gc,String string,Rectangle printArea) { - int x0 = printArea.x; - int y0 = printArea.y; - int height = 0; - Rectangle oldClipping = gc.getClipping(); + public void killShell() { + if (timerEvent != null) timerEvent.cancel(); + messageDiags.remove(this); + display.asyncExec(new Runnable() { + public void run() { + splash.close(); + popupImage.dispose(); + } + }); + } - //Protect the GC from drawing outside the drawing area - gc.setClipping(printArea); + public static boolean printString(GC gc,String string,Rectangle printArea) { + int x0 = printArea.x; + int y0 = printArea.y; + int height = 0; + Rectangle oldClipping = gc.getClipping(); - //We need to add some cariage return ... - String sTabsReplaced = string.replaceAll("\t", " "); + //Protect the GC from drawing outside the drawing area + gc.setClipping(printArea); - StringBuffer outputLine = new StringBuffer(); + //We need to add some cariage return ... + String sTabsReplaced = string.replaceAll("\t", " "); - // Process string line by line - StringTokenizer stLine = new StringTokenizer(sTabsReplaced,"\n"); - while(stLine.hasMoreElements()) { - int iLineHeight = 0; - String sLine = stLine.nextToken(); - if (gc.stringExtent(sLine).x > printArea.width) { - //System.out.println("Line: "+ sLine); - StringTokenizer stWord = new StringTokenizer(sLine, " "); - String space = ""; - int iLineLength = 0; - iLineHeight = gc.stringExtent(" ").y; + StringBuffer outputLine = new StringBuffer(); - // Process line word by word - while(stWord.hasMoreElements()) { - String word = stWord.nextToken(); + // Process string line by line + StringTokenizer stLine = new StringTokenizer(sTabsReplaced,"\n"); + while(stLine.hasMoreElements()) { + int iLineHeight = 0; + String sLine = stLine.nextToken(); + if (gc.stringExtent(sLine).x > printArea.width) { + //System.out.println("Line: "+ sLine); + StringTokenizer stWord = new StringTokenizer(sLine, " "); + String space = ""; + int iLineLength = 0; + iLineHeight = gc.stringExtent(" ").y; - // check if word is longer than our print area, and split it - Point ptWordSize = gc.stringExtent(word + " "); - while (ptWordSize.x > printArea.width) { - int endIndex = word.length() - 1; - do { - endIndex--; - ptWordSize = gc.stringExtent(word.substring(0, endIndex) + " "); - } while (endIndex > 3 && ptWordSize.x + iLineLength > printArea.width); - // append part that will fit - outputLine.append(space) - .append(word.substring(0, endIndex)) - .append("\n"); - height += ptWordSize.y; + // Process line word by word + while(stWord.hasMoreElements()) { + String word = stWord.nextToken(); - // setup word as the remaining part that didn't fit - word = word.substring(endIndex); - ptWordSize = gc.stringExtent(word + " "); - iLineLength = 0; - } - iLineLength += ptWordSize.x; - //System.out.println(outputLine + " : " + word + " : " + iLineLength); - if(iLineLength > printArea.width) { - iLineLength = ptWordSize.x; - height += iLineHeight; - iLineHeight = ptWordSize.y; - space = "\n"; - } - if (iLineHeight < ptWordSize.y) - iLineHeight = ptWordSize.y; + // check if word is longer than our print area, and split it + Point ptWordSize = gc.stringExtent(word + " "); + while (ptWordSize.x > printArea.width) { + int endIndex = word.length() - 1; + do { + endIndex--; + ptWordSize = gc.stringExtent(word.substring(0, endIndex) + " "); + } while (endIndex > 3 && ptWordSize.x + iLineLength > printArea.width); + // append part that will fit + outputLine.append(space) + .append(word.substring(0, endIndex)) + .append("\n"); + height += ptWordSize.y; - outputLine.append(space).append(word); - space = " "; - } - } else { - outputLine.append(sLine); - iLineHeight = gc.stringExtent(sLine).y; - } - outputLine.append("\n"); - height += iLineHeight; - } + // setup word as the remaining part that didn't fit + word = word.substring(endIndex); + ptWordSize = gc.stringExtent(word + " "); + iLineLength = 0; + } + iLineLength += ptWordSize.x; + //System.out.println(outputLine + " : " + word + " : " + iLineLength); + if(iLineLength > printArea.width) { + iLineLength = ptWordSize.x; + height += iLineHeight; + iLineHeight = ptWordSize.y; + space = "\n"; + } + if (iLineHeight < ptWordSize.y) + iLineHeight = ptWordSize.y; - String sOutputLine = outputLine.toString(); - gc.drawText(sOutputLine,x0,y0,true); - gc.setClipping(oldClipping); - return height <= printArea.height; - } + outputLine.append(space).append(word); + space = " "; + } + } else { + outputLine.append(sLine); + iLineHeight = gc.stringExtent(sLine).y; + } + outputLine.append("\n"); + height += iLineHeight; + } + String sOutputLine = outputLine.toString(); + gc.drawText(sOutputLine,x0,y0,true); + gc.setClipping(oldClipping); + return height <= printArea.height; + } + }//EOF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |