本文整理汇总了Java中java.util.Observer类的典型用法代码示例。如果您正苦于以下问题:Java Observer类的具体用法?Java Observer怎么用?Java Observer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Observer类属于java.util包,在下文中一共展示了Observer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DataItemHolder
import java.util.Observer; //导入依赖的package包/类
public DataItemHolder ( final BundleContext context, final Item item, final DataSourceListener listener )
{
super ( context, item, null );
this.listener = listener;
this.observer = new Observer () {
@Override
public void update ( final Observable o, final Object arg )
{
DataItemHolder.this.update ( o, arg );
}
};
init ();
}
示例2: start
import java.util.Observer; //导入依赖的package包/类
public void start() {
runBeforeActions();
setStartTime(System.nanoTime());
downloader.download();
downloader.deleteObservers();
downloader.addObserver(new Observer() {
@Override
public void update(Observable arg0, Object arg1) {
if (downloader.getStatus() == Downloader.COMPLETED) {
runAfterActions();
}
}
});
}
示例3: createErrorListener
import java.util.Observer; //导入依赖的package包/类
@Override
protected Observer createErrorListener() {
return new Observer() {
@Override
public void update(Observable observable, Object arg) {
if (arg != null) {
FormatError error = (FormatError) arg;
if (error.getNumbers()
.size() > 1) {
int line = error.getNumbers()
.get(0);
int column = error.getNumbers()
.get(1);
select(line, column);
}
}
}
};
}
示例4: createErrorListener
import java.util.Observer; //导入依赖的package包/类
/** Creates the listener of the error panel. */
private Observer createErrorListener() {
return new Observer() {
@Override
public void update(Observable o, Object arg) {
if (arg != null) {
AspectJCell errorCell = getJGraph().getModel()
.getErrorMap()
.get(arg);
if (errorCell != null) {
getJGraph().setSelectionCell(errorCell);
}
}
}
};
}
示例5: installListeners
import java.util.Observer; //导入依赖的package包/类
void installListeners() {
getJGraph().addPropertyChangeListener(org.jgraph.JGraph.GRAPH_MODEL_PROPERTY,
new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
updateModel();
}
});
getJGraph().addGraphSelectionListener(new GraphSelectionListener() {
@Override
public void valueChanged(GraphSelectionEvent e) {
clearSelection();
}
});
getFilter().addObserver(new Observer() {
@Override
@SuppressWarnings("unchecked")
public void update(Observable o, Object arg) {
LabelTree.this.repaint();
getJGraph().refreshCells((Set<JCell<G>>) arg);
}
});
addMouseListener(new MyMouseListener());
}
示例6: initialize
import java.util.Observer; //导入依赖的package包/类
@Override
public void initialize() {
super.initialize();
// We run this code in the "initialize" method and not in the constructor,
// because at the time the constructor is run, the "actor" field of the
// test action is not yet populated.
if (!AppiumTestAction.initialized) {
AppiumTestAction.initialized = true;
this.getActor().addObserver(new Observer() {
@Override
public void update(Observable eventSource, Object eventData) {
if (eventSource instanceof ITestActor) {
if (eventData == TestActorEvents.TEST_COMPLETED) {
if (!AppiumHelper.getConfig().getBoolean("appium.reuseDriver", false)) {
AppiumHelper.discardDriver();
}
}
}
}
});
}
}
示例7: testImportExcelSingletonSuccess
import java.util.Observer; //导入依赖的package包/类
@Test
public void testImportExcelSingletonSuccess() {
ResetTestValue.reset();
ImportHandler handler = new ImportHandler(
new RowRecordHandlerImpl(),
new RowRecordPersistencorHibernateImpl(factory), TransactionMode.SINGLETON);
List<RowRecord> list = handler.importExcel(
ExcelFactory.newExcel(new File("D:/test/schoolman.xlsx")),
new Observer() {
@Override
public void update(Observable o, Object arg) {
Process process = (Process) arg;
System.out.println("进度:" + process.getProcess() + ",当前阶段:" + process.getNode());
}
},
SchoolMan.class);
for (RowRecord rr : list) {
System.out.println(rr.getResult().getMsg());
}
}
示例8: testImportExcelSingletonError
import java.util.Observer; //导入依赖的package包/类
@Test
public void testImportExcelSingletonError() {
ResetTestValue.reset();
ImportHandler handler = new ImportHandler(
new RowRecordPersistencorHibernateImpl(factory), TransactionMode.SINGLETON);
List<RowRecord> list = handler.importExcel(
ExcelFactory.newExcel(new File("D:/test/schoolman_error.xlsx")),
new Observer() {
@Override
public void update(Observable o, Object arg) {
Process process = (Process) arg;
System.out.println("进度:" + process.getProcess() + ",当前阶段:" + process.getNode());
}
},
SchoolMan.class);
for (RowRecord rr : list) {
System.out.println("行号:" + rr.getRowNo() + ", 错误信息:" + rr.getResult().getMsg());
}
}
示例9: testImportExcelMultipleSuccess
import java.util.Observer; //导入依赖的package包/类
@Test
public void testImportExcelMultipleSuccess() {
ResetTestValue.reset();
ImportHandler handler = new ImportHandler(
new RowRecordPersistencorHibernateImpl(factory), TransactionMode.MULTIPLE);
List<RowRecord> list = handler.importExcel(
ExcelFactory.newExcel(new File("D:/test/schoolman.xlsx")),
new Observer() {
@Override
public void update(Observable o, Object arg) {
Process process = (Process) arg;
System.out.println("进度:" + process.getProcess() + ",当前阶段:" + process.getNode());
}
},
SchoolMan.class);
for (RowRecord rr : list) {
System.out.println(rr.getResult().getMsg());
}
}
示例10: main
import java.util.Observer; //导入依赖的package包/类
public static void main(String[] args) {
Observer observer1 = new WeatherObserver();
Observer observer2 = new WeatherObserver();
Observer observer3 = new WeatherObserver();
WeatherSubject weatherSubject = new WeatherSubject.Builder("Shanghai")
.temperature(22f)
.humidity(0.8f)
.forecastTemperatures(Arrays.asList(0.5f, 0.8f, 1.5f))
.build();
weatherSubject.addObserver(observer1);
weatherSubject.addObserver(observer2);
weatherSubject.addObserver(observer3);
weatherSubject.setWeatherSubject(new WeatherSubject.Builder("Shanghai")
.temperature(28f)
.humidity(9.8f)
.forecastTemperatures(Arrays.asList(2.5f, 8.8f, 4.5f)));
}
示例11: testWeaterObserver
import java.util.Observer; //导入依赖的package包/类
@Test
public void testWeaterObserver() throws Exception {
Observer observer1 = mock(WeatherObserver.class);
Observer observer2 = mock(WeatherObserver.class);
WeatherSubject weatherSubject = new WeatherSubject.Builder("Shanghai")
.temperature(22f)
.humidity(0.8f)
.forecastTemperatures(Arrays.asList(0.5f, 0.8f, 1.5f))
.build();
weatherSubject.addObserver(observer1);
weatherSubject.addObserver(observer2);
weatherSubject.setWeatherSubject(new WeatherSubject.Builder("Shanghai")
.temperature(28f)
.humidity(9.8f)
.forecastTemperatures(Arrays.asList(2.5f, 8.8f, 4.5f)));
verify(observer1).update(weatherSubject, null);
verify(observer2).update(weatherSubject, null);
}
示例12: startGps
import java.util.Observer; //导入依赖的package包/类
private void startGps() {
locationObserver = new Observer() {
@Override
public void update(Observable o, Object arg) {
Log.i(TAG, "update: Stopping Location");
LocationProxy.getInstance().stopRequest(getApplicationContext());
}
};
Log.i(TAG, "onCreate: AddObserver");
LocationProxy.getInstance().addObserver(locationObserver);
//Initializing location
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_PERMISSION_GPS);
else
LocationProxy.getInstance().startRequest(this);
}
示例13: main
import java.util.Observer; //导入依赖的package包/类
public static void main(String[] args) {
System.err.println(
"\nTest creating proxy class with the null class loader.\n");
try {
ClassLoader ld = null;
Class p = Proxy.getProxyClass(ld, new Class[] { Runnable.class, Observer.class });
System.err.println("proxy class: " + p);
ClassLoader loader = p.getClassLoader();
System.err.println("proxy class's class loader: " + loader);
if (loader != null) {
throw new RuntimeException(
"proxy class not defined in the null class loader");
}
System.err.println("\nTEST PASSED");
} catch (Throwable e) {
System.err.println("\nTEST FAILED:");
e.printStackTrace();
throw new RuntimeException("TEST FAILED: " + e.toString());
}
}
示例14: MacroViewer
import java.util.Observer; //导入依赖的package包/类
public MacroViewer() {
setLayout(new BorderLayout());
macroTable = new ExtendedJTable(dataModel, true, false, true);
macroTable.setRowHeight(PropertyPanel.VALUE_CELL_EDITOR_HEIGHT);
macroTable.setRowHighlighting(true);
scrollPane = new ExtendedJScrollPane(macroTable);
scrollPane.setBorder(BorderFactory.createEmptyBorder(10, 5, 0, 5));
add(scrollPane, BorderLayout.CENTER);
updateQueue = new UpdateQueue(MACRO_VIEWER_DOCK_KEY);
updateQueue.start();
macroObserver = new Observer() {
@Override
public void update(Observable o, Object arg) {
updateQueue.execute(new Runnable() {
@Override
public void run() {
updateMacros();
try {
Thread.sleep(1000); // Sleep 1sec to avoid update flooding
} catch (InterruptedException e) {
}
}
});
}
};
}
示例15: attach
import java.util.Observer; //导入依赖的package包/类
private void attach ( final ConnectionService connectionService )
{
detach ();
this.item = new DataItem ( this.itemDescriptor.getItemId () );
this.item.addObserver ( new Observer () {
@Override
public void update ( final Observable o, final Object arg )
{
ItemRegistration.this.handleUpdate ( (DataItemValue)arg );
}
} );
this.item.register ( connectionService.getItemManager () );
}