Java 类java.util.Observer 实例源码

项目:neoscada    文件:DataItemHolder.java   
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 ();
}
项目:osumer    文件:Queue.java   
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();
            }
        }

    });
}
项目:JavaGraph    文件:TextTab.java   
@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);
                }
            }
        }
    };
}
项目:JavaGraph    文件:StateDisplay.java   
/** 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);
                }
            }
        }
    };
}
项目:JavaGraph    文件:LabelTree.java   
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());
}
项目:opentest    文件:AppiumTestAction.java   
@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();
                        }
                    }
                }
            }
        });
    }
}
项目:excel-util4j    文件:TestImportHandler.java   
@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());
    }
}
项目:excel-util4j    文件:TestImportHandler.java   
@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());
    }
}
项目:excel-util4j    文件:TestImportHandler.java   
@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());
    }
}
项目:java-design-pattern    文件:Application.java   
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)));
}
项目:java-design-pattern    文件:WeatherObserverTest.java   
@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);
}
项目:TrainPonctuality    文件:MainActivity.java   
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);
}
项目:openjdk-jdk10    文件:NullClassLoader.java   
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());
        }
    }
项目:rapidminer    文件:MacroViewer.java   
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) {
                    }
                }
            });
        }
    };
}
项目:neoscada    文件:ItemRegistration.java   
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 () );
}
项目:neoscada    文件:DataItemObservableValue.java   
private Observer createObserver ()
{
    return new Observer () {

        @Override
        public void update ( final Observable o, final Object arg )
        {
            if ( arg instanceof DataItemValue )
            {
                handleUpdate ( this, (DataItemValue)arg );
            }
        }
    };
}
项目:neoscada    文件:DataItemObservableValue.java   
protected synchronized void handleUpdate ( final Observer observer, DataItemValue value )
{
    if ( observer != this.observer )
    {
        return;
    }

    if ( this.invalidValuePolicy.isInvalid ( value ) )
    {
        value = this.invalidValuePolicy.processInvalid ( value );
    }

    fireChange ( this.value, this.value = value );
}
项目:graphium    文件:CurrentGraphVersionCacheImpl.java   
public void setNewGraphVersionObserver(List<Observer> observers) {
    if (observers != null) {
        for (Observer observer : observers) {
            addObserver(observer);
        }
    }
}
项目:TrainPonctuality    文件:InputArrivalActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_input_arrival);
    setTitle(R.string.titleArrival);

    txtArrivalDate = (TextView) findViewById(R.id.txtArrivalDate);
    txtArrivalTime = (TextView) findViewById(R.id.txtArrivalTime);
    txtArrivalStation = (TextView) findViewById(R.id.txtLocation);

    Bundle data = getIntent().getExtras();
    currentTravel = data.getParcelable("travel");

    setArrivalDateTime(GregorianCalendar.getInstance());

    locationObserver = new Observer() {
        @Override
        public void update(Observable o, Object arg) {
            Log.i(TAG, "update: Stopping Location");
            LocationProxy.getInstance().stopRequest(getApplicationContext());
            autoSelectStation();
        }
    };
    Log.i(TAG, "onCreate: AddObserver");
    LocationProxy.getInstance().addObserver(locationObserver);
    autoSelectStation();
}
项目:JavaGraph    文件:LTSDisplay.java   
private Observer createErrorListener() {
    return new Observer() {
        @Override
        public void update(Observable o, Object arg) {
            FormatError error = (FormatError) arg;
            if (error != null) {
                getSimulatorModel().setState(error.getState());
            }
        }
    };
}
项目:JavaGraph    文件:GraphEditorTab.java   
@Override
protected Observer createErrorListener() {
    return new Observer() {
        @Override
        public void update(Observable o, Object arg) {
            if (arg != null) {
                JCell<?> errorCell = getJModel().getErrorMap()
                    .get(arg);
                if (errorCell != null) {
                    getJGraph().setSelectionCell(errorCell);
                }
            }
        }
    };
}
项目:JavaGraph    文件:GraphTab.java   
@Override
protected Observer createErrorListener() {
    return new Observer() {
        @Override
        public void update(Observable o, Object arg) {
            if (arg != null) {
                JCell<?> errorCell = getJModel().getErrorMap()
                    .get(arg);
                if (errorCell != null) {
                    getJGraph().setSelectionCell(errorCell);
                }
            }
        }
    };
}
项目:JavaGraph    文件:Simulator.java   
/**
 * Creates an observer for the error panel that will select the
 * erroneous part of the resource upon selection of an error.
 */
private Observer createListListener() {
    return new Observer() {
        @Override
        public void update(Observable observable, Object arg) {
            if (arg != null) {
                selectDisplayPart((SelectableListEntry) arg);
            }
        }
    };
}
项目:UDOOBluLib-android    文件:SeqObserverQueue.java   
/**
 * Adds the specified observer to the list of observers. If it is already
 * registered, it is not added a second time.
 *
 * @param observer the Observer to add.
 */
public void addObserver(Observer observer) {
    if (observer == null) {
        throw new NullPointerException("observer == null");
    }
    observers.add(observer);
}
项目:Phial    文件:KVSaverTest.java   
@Test
public void save_notifies_about_change() {
    final Observer observable = Mockito.mock(Observer.class);
    saver.addObserver(observable);
    saver.save("cat", "key1", "val1");

    Mockito.verify(observable).update(Mockito.eq(saver), Mockito.any());
}
项目:Phial    文件:KVSaverTest.java   
@Test
public void update_notifies_about_change() {
    final Observer observable = Mockito.mock(Observer.class);
    saver.save("cat", "key1", "val1");
    saver.addObserver(observable);
    saver.save("cat", "key1", "val2");

    Mockito.verify(observable).update(Mockito.eq(saver), Mockito.any());
}
项目:Phial    文件:KVSaverTest.java   
@Test
public void remove_key_notifies_about_change() {
    final Observer observable = Mockito.mock(Observer.class);
    saver.save("cat", "key1", "val1");
    saver.addObserver(observable);
    saver.remove("cat", "key1");

    Mockito.verify(observable).update(Mockito.eq(saver), Mockito.any());
}
项目:Phial    文件:KVSaverTest.java   
@Test
public void remove_category_notifies_about_change() {
    final Observer observable = Mockito.mock(Observer.class);
    saver.save("cat", "key1", "val1");
    saver.addObserver(observable);
    saver.remove("cat");

    Mockito.verify(observable).update(Mockito.eq(saver), Mockito.any());
}
项目:excel-util4j    文件:ImportHandler.java   
/**
 * <p>导入excel方法</p>
 *
 * @param excel 需要导入的excel对象
 * @param sheetNo excel中sheet的编号
 * @param processObserver 进度处理器
 * @param pojos 导入对象的pojo类
 * @return RowRecord的list,通过getResult可以获取导入结果
 */
public List<RowRecord> importExcel(AbstractExcel excel, int sheetNo, Observer processObserver, Class<?>... pojos) {

    List<Map<String, Object>> excelDataList = excel.readExcel(sheetNo);

    List<RowRecord> rowRecordList = new ArrayList<>();
    for (int i = 0; i < excelDataList.size(); i ++) {
        Map<String, Object> excelData = excelDataList.get(i);
        rowRecordList.add(handler.rowRecordCreate(excelData, i + 2));
    }

    // 根据repairer判断有3或4个步骤,进度为处理数量*3或4
    int step = 3;
    if (repairer != null)
        step = 4;
    Process process = null;
    if (processObserver != null) {
        process = new Process((long) (rowRecordList.size() * step));
        process.addObserver(processObserver);
    }

    // 步骤1
    if (!handler.handle(rowRecordList, process, pojos) && mode == TransactionMode.MULTIPLE)
        return rowRecordList;
    // 步骤2
    if (!validator.valid(rowRecordList, process) && mode == TransactionMode.MULTIPLE)
        return rowRecordList;
    // 步骤3 持久化前修正rowRecord,如:密码md5加密转换
    if (repairer != null) repaire(rowRecordList, process);
    // 步骤4
    persistencor.persist(rowRecordList, mode, process);
    return rowRecordList;
}
项目:springfx    文件:SecondPresentation.java   
@FXML
void initialize() {
    messageTf.setText(model.getMessage());

    model.addObserver(new Observer() {

        public void update(Observable o, Object arg) {
            messageTf.setText(model.getMessage());
        }
    });
}
项目:Pixie    文件:AttributesDefinition.java   
/**
 * Allows another module to put an observer into the current module.
 *
 * @param o - the observer to be added
 */
public void addObserver(Observer o) {
    observable.addObserver(o);

    // notify to remove the gui key event dispatcher
    observable.notifyObservers(ObservedActions.Action.REMOVE_GUI_KEY_EVENT_DISPATCHER);
}
项目:Pixie    文件:BoundingBoxWindow.java   
/**
 * Allows another module to put an observer into the current module.
 *
 * @param o - the observer to be added
 */
public void addObserver(Observer o) {
    observable.addObserver(o);

    // notify to remove the gui key event dispatcher
    observable.notifyObservers(ObservedActions.Action.REMOVE_GUI_KEY_EVENT_DISPATCHER);
}
项目:Pixie    文件:UserConfigs.java   
/**
 * Allows another module to put an observer into the current module.
 *
 * @param o - the observer to be added
 */
public void addObserver(Observer o) {
    observable.addObserver(o);

    // notify to remove the gui key event dispatcher
    observable.notifyObservers(ObservedActions.Action.REMOVE_GUI_KEY_EVENT_DISPATCHER);
}
项目:GOF    文件:Product.java   
public void setBidAmount(Observer observer,BigDecimal newBidAmount){
    System.out.println("-----------------New bid placed----------------");
    int res=bidAmount.compareTo(newBidAmount);
    if(res==-1){
        this.observer=observer;
        this.bidAmount=newBidAmount;
        setChanged();
        notifyObservers();
    }
    else {
        System.out.println("New bid amount cannot be less or equal to current bid amount: "+this.bidAmount);
    }
}
项目:Pluto-Android    文件:AsyncTaskManager.java   
public void addTask(Observer task) {
    super.addObserver(task);
}
项目:an2linuxclient    文件:PairingConnection.java   
void addObserver(Observer observer) {
    observable.addObserver(observer);
}
项目:dapay    文件:BlinktradeAPI.java   
public void GetBookUpdates(Observer o) {
    book_data.addObserver(o);
}
项目:rapidminer    文件:ColumnMetaData.java   
/** Used to inform the validator about the ColumnMetaData object **/
@Override
public synchronized void addObserver(Observer o) {
    super.addObserver(o);
}
项目:sstore-soft    文件:EventObserver.java   
protected Observer getObserver() {
    return (this.observer);
}
项目:Roomie    文件:Game.java   
public void addObservers(Observer observer)
{
    pressedButtonId.addObserver(observer);
    currentEvent.addObserver(observer);
}