Fix for logFragment usage

This commit is contained in:
Alexander Nozik 2017-05-17 23:03:58 +03:00
parent 4e5b3bb885
commit 68042c72d6
4 changed files with 11 additions and 140 deletions

View File

@ -76,8 +76,7 @@ public class PKT8View extends DeviceViewConnection<PKT8Device> implements Initia
public void open(@NotNull PKT8Device device) throws Exception { public void open(@NotNull PKT8Device device) throws Exception {
super.open(device); super.open(device);
this.logFragment = new LogFragment(); this.logFragment = new LogFragment();
logFragment.addLogHandler(device.getContext().getLogger()); logFragment.addRootLogHandler();
logFragment.hookStd();//TODO to be removed later
plotFragment = new PKT8PlotFragment(device); plotFragment = new PKT8PlotFragment(device);
startStopButton.selectedProperty().setValue(getDevice().isMeasuring()); startStopButton.selectedProperty().setValue(getDevice().isMeasuring());

View File

@ -75,7 +75,7 @@ public class MspViewController extends DeviceViewConnection<MspDevice> implement
private final TimePlottableGroup plottables = new TimePlottableGroup(); private final TimePlottableGroup plottables = new TimePlottableGroup();
// private Configuration viewConfig; // private Configuration viewConfig;
private JFreeChartFrame plot; private JFreeChartFrame plot;
private LogFragment logArea; private LogFragment logFragment;
private final ConfigChangeListener viewConfigObserver = new ConfigChangeListener() { private final ConfigChangeListener viewConfigObserver = new ConfigChangeListener() {
@ -118,8 +118,9 @@ public class MspViewController extends DeviceViewConnection<MspDevice> implement
*/ */
@Override @Override
public void initialize(URL url, ResourceBundle rb) { public void initialize(URL url, ResourceBundle rb) {
logArea = new LogFragment(); logFragment = new LogFragment();
new FragmentWindow(logArea).bindTo(consoleButton); new FragmentWindow(logFragment).bindTo(consoleButton);
logFragment.addRootLogHandler();
fillamentSelector.setItems(FXCollections.observableArrayList(1, 2)); fillamentSelector.setItems(FXCollections.observableArrayList(1, 2));
fillamentSelector.setConverter(new StringConverter<Integer>() { fillamentSelector.setConverter(new StringConverter<Integer>() {
@Override @Override
@ -237,21 +238,21 @@ public class MspViewController extends DeviceViewConnection<MspDevice> implement
@Override @Override
public void acceptMessage(String message) { public void acceptMessage(String message) {
Platform.runLater(() -> { Platform.runLater(() -> {
logArea.appendLine("RECIEVE: " + message); logFragment.appendLine("RECIEVE: " + message);
}); });
} }
@Override @Override
public void acceptRequest(String message) { public void acceptRequest(String message) {
Platform.runLater(() -> { Platform.runLater(() -> {
logArea.appendLine("SEND: " + message); logFragment.appendLine("SEND: " + message);
}); });
} }
@Override @Override
public void error(String errorMessage, Throwable error) { public void error(String errorMessage, Throwable error) {
Platform.runLater(() -> { Platform.runLater(() -> {
logArea.appendLine("ERROR: " + errorMessage); logFragment.appendLine("ERROR: " + errorMessage);
showError(errorMessage); showError(errorMessage);
}); });

View File

@ -38,135 +38,6 @@ public class ReadVac extends NumassControlApplication<VacCollectorDevice> {
protected boolean acceptDevice(Meta meta) { protected boolean acceptDevice(Meta meta) {
return Objects.equals(meta.getString("type", ""), "numass:vac"); return Objects.equals(meta.getString("type", ""), "numass:vac");
} }
// private VacCollectorDevice device;
//
// @Override
// public void start(Stage primaryStage) throws Exception {
// Locale.setDefault(Locale.US);// чтобы отделение десятичных знаков было точкой
// ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
// rootLogger.setLevel(Level.INFO);
//
// DeviceViewConnection<VacCollectorDevice> controller = buildView();
//
// Scene scene = new Scene(controller.getPane());
//
// primaryStage.setScene(scene);
// primaryStage.show();
//
// device = setupDevice(controller);
// primaryStage.setTitle("Numass vacuum measurements");
// }
//
//
// private VacCollectorDevice setupDevice(DeviceConnection<VacCollectorDevice> controller) {
// Meta config = NumassControlUtils.getConfig(this)
// .orElseGet(() -> NumassControlUtils.readResourceMeta("/config/devices.xml"));
//
// Context ctx = NumassControlUtils.setupContext(config);
// Meta mspConfig = NumassControlUtils.findDeviceMeta(config, this::acceptDevice)
// .orElseThrow(() -> new RuntimeException("Device configuration not found"));
//
//
// try {
// D d = getDeviceFactory().build(ctx, mspConfig);
// d.init();
// NumassControlUtils.connectStorage(d, config);
// Platform.runLater(() -> {
// d.connect(controller, Roles.VIEW_ROLE, Roles.DEVICE_LISTENER_ROLE);
// });
// return d;
// } catch (ControlException e) {
// throw new RuntimeException("Failed to build device", e);
// }
// }
//
// @Override
// public void stop() throws Exception {
// super.stop();
// if (device != null) {
// device.shutdown();
// device.getContext().close();
// }
// }
// VacCollectorView controller;
// Logger logger = LoggerFactory.getLogger("ReadVac");
//
// /**
// * @param args the command line arguments
// */
// public static void main(String[] args) {
// launch(args);
// }
//
// @Override
// public void start(Stage primaryStage) throws Exception {
// String configFileName = getParameters().getNamed().get("config");
// if (configFileName == null) {
// configFileName = "devices.xml";
// }
// File configFile = new File(configFileName);
// Meta config;
// if (configFile.exists()) {
// config = MetaFileReader.read(configFile).build();
// } else {
// config = Meta.empty();
// }
//
// Context context = Global.instance();
//
// collector.init();
//
// FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacCollector.fxml"));
// loader.load();
// controller = loader.getController();
// controller.setDevice(collector);
// controller.setLogger(logger);
//
// controller.setLoaderFactory((VacCollectorDevice device, Storage localStorage) -> {
// try {
// String runName = ClientUtils.getRunName(config);
//// String runName = device.meta().getString("numass.run", "");
//// if (config.hasMeta("numass.server")) {
//// try {
//// logger.info("Obtaining run information from cetral server...");
//// NumassClient client = new NumassClient(get);
//// runName = client.getCurrentRun().getString("path", "");
//// logger.info("Run name is '{}'", runName);
//// } catch (Exception ex) {
//// logger.warn("Failed to download current run information", ex);
//// }
//// }
//
// TableFormatBuilder format = new TableFormatBuilder().setType("timestamp", ValueType.TIME);
// device.getSensors().stream().forEach((s) -> {
// format.setType(s.getName(), ValueType.NUMBER);
// });
//
// PointLoader pl = LoaderFactory.buildPointLoder(localStorage, "vactms", runName, "timestamp", format.build());
// return pl;
//
// } catch (StorageException ex) {
// throw new RuntimeException(ex);
// }
// });
// Scene scene = new Scene(loader.getRoot(), 800, 700);
//
// primaryStage.setTitle("Numass vacuum measurements");
// primaryStage.setScene(scene);
// primaryStage.show();
//// controller.startMeasurement();
// }
//
// @Override
// public void stop() throws Exception {
// if (controller != null) {
// controller.stopMeasurement();
// controller.getDevice().shutdown();
// }
// super.stop();
// }
} }

View File

@ -117,9 +117,9 @@ public class VacCollectorView extends DeviceViewConnection<VacCollectorDevice> i
} }
}); });
LogFragment consoleWindow = new LogFragment(); LogFragment logFragment = new LogFragment();
new FragmentWindow(consoleWindow).bindTo(logButton); new FragmentWindow(logFragment).bindTo(logButton);
consoleWindow.hookStd(); logFragment.addRootLogHandler();
} }
@Override @Override