2012-09-17 16 views
5

मैं ऑपरेशन शुरू करते समय कर्सर को बदलने की कोशिश कर रहा हूं। मैं कर्सर ऑपरेशन समाप्त होने तक व्यस्त दिखाना चाहता हूं। मेरे पास ऑपरेशन लिस्टर के लिए एक अलग वर्ग है। मुझे यकीन नहीं है कि कर्सर को कैसे असाइन किया जाए? AplotBaseDialog वर्ग सेएसडब्ल्यूटी - एक व्यस्त कर्सर दिखा रहा है

कॉल

listOp.addOperationListener(new MyOperationListener(this) { 
    etc.... 
} 

अलग वर्ग

public abstract class MyOperationListener implements InterfaceAIFOperationListener { 
    Cursor busyCursor = null; 
    AplotBaseDialog w = null; 

    public MyOperationListener(AplotBaseDialog win) { 

    **Should this not be getCurrent?** 
    busyCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_WAIT); 

    w = win; 
    } // end constructor 

    public void startOperation(String startMessage) { 
    ** should this be getting a Shell form the AplotBaseDialog? ** 
    w.???.setCursor(busyCursor); 

    } // end startOperation() 

    public void endOperation() { 
    try { 
     endOperationImpl(); 
    } 
    finally { 
     w.???.setCursor(null); 
    } 
    } // end endOperation() 

    abstract protected void endOperationImpl(); 
} // end class MyOperationListener 

संपादित

plotButton.addSelectionListener(new SelectionAdapter() { 
     public void widgetSelected(SelectionEvent e) { 
      BusyIndicator.showWhile(Display.getDefault(), new Runnable(){ 
       public void run(){ 
        startPrinterListOperation(); 
       } 
      }); 
     } 
    }); 

संपादित

private void startPrinterListOperation() { 

    listOp = new AplotPrinterListOperation(appReg.getString("aplot.message.GETPRINTERLIST"), session); 
    listOp.addOperationListener(new MyOperationListener(this) { 
    public void endOperationImpl() { 
     try { 
      printers.clear(); 
      printers.addAll((ArrayList<PrinterProfile>) listOp.getPrinters()); 
      Display.getDefault().asyncExec(new Runnable() { 
       public void run() { 

       showAplotPlotterDialog(); 
       } 
      }); 
     } 
     finally { 

      listOp.removeOperationListener(this); 
      listOp = null; 
     } 
    } 
    }); 
    session.queueOperation(listOp); 


} // end startPrinterListOperation() 

उत्तर

4

इस्तेमाल कर सकते हैं यह मेरे लिए काम करता है:

private static boolean wait = false; 

private static Cursor cursor = null; 

public static void main(String[] args) { 
    final Display display = new Display(); 
    final Shell shell = new Shell(display); 
    shell.setLayout(new FillLayout()); 

    Button button = new Button(shell, SWT.PUSH); 
    button.setText("Change cursor"); 

    button.addListener(SWT.Selection, new Listener() { 

     @Override 
     public void handleEvent(Event arg0) { 
      wait = !wait; 

      if(cursor != null) 
       cursor.dispose(); 

      cursor = wait ? new Cursor(display, SWT.CURSOR_WAIT) : new Cursor(display, SWT.CURSOR_ARROW); 

      shell.setCursor(cursor); 
     } 
    }); 


    shell.setSize(200,200); 
    shell.open(); 
    while (!shell.isDisposed()) { 
     if (!display.readAndDispatch()) { 
      display.sleep(); 
     } 
    } 
    display.dispose(); 

    if(cursor != null) 
     cursor.dispose(); 
} 

बस setCursor(Display, int) के माध्यम से अपने युक्त खोल के कर्सर की स्थापना की।

यदि आप कर्सर को पूरे खोल के लिए नहीं बदलना चाहते हैं, तो अपनी पसंद के Composite या Control का उपयोग करें।


याद रखें कि आप dispose() करने के लिए है कि प्रत्येक Cursor उदाहरण आप अपने आप को पैदा करते हैं।

+0

मैंने मूल रूप से उपरोक्त लाइनों को अपनी ऑपरेशन विधि में जोड़ा क्योंकि यह संवाद शुरू होने से ठीक पहले शुरू हुआ और ऐसा लगता है। मैं वास्तव में चाहता हूं कि मैं यह पता लगा सकता हूं कि इसे अमूर्त ऑपरेशन क्लास में कैसे काम किया जाए। लेकिन ऐसा लगता है कि यह वही प्रभाव है। - धन्यवाद – jkteater

4

आप

BusyIndicator.showWhile(Display.getDefault(), new Runnable(){ 

    public void run(){ 
     //your code 
    } 
    }); 
+0

मैंने इसे अपने बटन एक्शन में डालने की कोशिश की, लेकिन यह कुछ भी नहीं किया। कृपया – jkteater

+0

से ऊपर देखें क्या आप प्रारंभिक प्रिंटर लिस्टऑपरेशन() में जो कर रहे हैं उसे पोस्ट कर सकते हैं? क्या आपको कोई अपवाद दिखता है? –

+0

कोई अपवाद नहीं - – jkteater

संबंधित मुद्दे