1 21 22 package org.opensubsystems.patterns.thickclient.application.swt; 23 24 import org.eclipse.swt.events.SelectionEvent; 25 import org.eclipse.swt.widgets.Text; 26 import org.opensubsystems.patterns.thickclient.application.ModificationListener; 27 import org.opensubsystems.patterns.thickclient.application.TextProcessor; 28 29 37 public class TextModificationSelectionAdapter extends DelegatingSelectionAdapter 38 { 39 41 44 public static final String FUNCTION_CLEAR = "clear"; 45 46 49 public static final String FUNCTION_CLEAR_ALL = "clearall"; 50 51 53 57 protected TextProcessor m_processor; 58 59 62 protected ModificationListener m_listener; 63 64 68 protected String m_strFunction; 69 70 73 protected Text m_destination; 74 75 77 88 public TextModificationSelectionAdapter( 89 TextProcessor processor, 90 ModificationListener listener, 91 String strFunction, 92 Text destination 93 ) 94 { 95 m_processor = processor; 96 m_listener = listener; 97 m_strFunction = strFunction; 98 m_destination = destination; 99 } 100 101 103 106 public void widgetSelected( 107 SelectionEvent event 108 ) 109 { 110 if (m_destination != null) 111 { 112 String strCurrent; 113 114 if (FUNCTION_CLEAR.equals(m_strFunction)) 115 { 116 strCurrent = m_destination.getText(); 117 if (strCurrent.length() > 0) 118 { 119 m_destination.setText(strCurrent.substring(0, strCurrent.length() - 1)); 120 m_destination.setSelection(m_destination.getText().length(), 121 m_destination.getText().length()); 122 } 123 } 124 else if (FUNCTION_CLEAR_ALL.equals(m_strFunction)) 125 { 126 m_destination.setText(""); 127 } 128 else 129 { 130 if (m_processor != null) 131 { 132 m_strFunction = m_processor.processText(m_strFunction); 133 } 134 m_destination.append(m_strFunction); 135 } 136 137 m_destination.setFocus(); 138 } 139 140 if (m_listener != null) 141 { 142 m_listener.modified(); 143 } 144 } 145 } 146 | Popular Tags |