1 45 46 47 package swingwtx.swing; 48 49 import org.eclipse.swt.widgets.*; 50 import org.eclipse.swt.*; 51 52 public class JProgressBar extends swingwtx.swing.JComponent implements SwingConstants { 53 54 private ProgressBar ppeer = null; 55 private int pMin = 0; 56 private int pMax = 0; 57 private int pValue = 0; 58 59 public JProgressBar() {} 60 public JProgressBar(int orient) { } 61 public JProgressBar(int min, int max) { pMin = min; pMax = max; } 62 public JProgressBar(int orient, int min, int max) { pMin = min; pMax = max; } 63 64 public void setMaximum(final int max) { 65 SwingUtilities.invokeAsync(new Runnable () { 66 public void run() { 67 setMaximumT(max); 68 } 69 }); 70 } 71 72 public void setMinimum(final int min) { 73 SwingUtilities.invokeAsync(new Runnable () { 74 public void run() { 75 setMinimumT(min); 76 } 77 }); 78 } 79 80 public void setValue(final int value) { 81 pValue = value; 82 SwingUtilities.invokeAsync(new Runnable () { 83 public void run() { 84 setValueT(value); 85 } 86 }); 87 } 88 89 protected void setMaximumT(int max) { if (!SwingWTUtils.isSWTControlAvailable(ppeer)) pMax = max; else ppeer.setMaximum(max); } 90 protected void setMinimumT(int min) { if (!SwingWTUtils.isSWTControlAvailable(ppeer)) pMin = min; else ppeer.setMinimum(min); } 91 protected void setValueT(int value) { if (SwingWTUtils.isSWTControlAvailable(ppeer)) ppeer.setSelection(value); } 92 public int getMaximum() { return pMax; } 93 public int getMinimum() { return pMin; } 94 public int getValue() { return pValue; } 95 public double getPercentComplete() { return ( ((double) (getValue() - getMinimum())) / ((double) (getMaximum() - getMinimum())) * 100); } 96 public void setStringPainted(boolean b) { } 97 public boolean getStringPainted() { return false; } 98 public void setString(String s) {} 99 public String getString() { return ""; } 100 101 106 public void setSwingWTParent(swingwt.awt.Container parent) throws Exception { 107 descendantHasPeer = true; 108 109 ppeer = new ProgressBar(parent.getComposite(), SWT.BORDER | SWT.SMOOTH); 110 111 ppeer.setMaximum(pMax); 112 ppeer.setMinimum(pMin); 113 ppeer.setSelection(pValue); 114 115 peer = ppeer; 116 this.parent = parent; 117 } 118 119 } 120 | Popular Tags |