use of javafx.scene.control.TableColumn in project jvarkit by lindenb.
the class BamStage method reloadData.
@Override
void reloadData() {
updateStatusBar(AlertType.NONE, "");
final int max_items = super.maxItemsLimitSpinner.getValue();
final List<SAMRecord> L = new ArrayList<SAMRecord>(max_items);
final String location = this.gotoField.getText().trim();
final CloseableIterator<SAMRecord> iter;
final java.util.function.Predicate<SAMRecord> recFilter = makeFlagPredicate();
Long canvasFirstRecordGenomicIndex = null;
Long canvasLastRecordGenomicIndex = null;
try {
if (location.isEmpty()) {
iter = this.getBamFile().iterator();
} else if (location.equalsIgnoreCase("unmapped")) {
iter = this.getBamFile().queryUnmapped();
} else {
final Interval interval = parseInterval(location);
if (interval == null) {
iter = null;
} else {
iter = this.getBamFile().iterator(interval.getContig(), interval.getStart(), interval.getEnd());
}
}
} catch (final IOException err) {
err.printStackTrace();
JfxNgs.showExceptionDialog(this, err);
return;
}
Optional<BamJavascripFilter> bamjsfilter = Optional.empty();
if (this.owner.javascriptCompiler.isPresent() && !this.javascriptArea.getText().trim().isEmpty()) {
try {
bamjsfilter = Optional.of(new BamJavascripFilter(this.getBamFile().getHeader(), Optional.of(this.owner.javascriptCompiler.get().compile(this.javascriptArea.getText()))));
} catch (final Exception err) {
LOG.warning(err.getMessage());
updateStatusBar(AlertType.ERROR, err);
bamjsfilter = Optional.empty();
}
}
final Map<ContigPos, Pileup> pos2pileup = new TreeMap<>();
final Function<ContigPos, Pileup> getpileup = new Function<ContigPos, Pileup>() {
@Override
public Pileup apply(ContigPos t) {
Pileup p = pos2pileup.get(t);
if (p == null) {
p = new Pileup(t.contig, t.position);
pos2pileup.put(t, p);
}
return p;
}
};
int count_items = 0;
while (iter != null && iter.hasNext() && count_items < max_items) {
final SAMRecord rec = iter.next();
++count_items;
if (bamjsfilter.isPresent()) {
if (bamjsfilter.get().eval(rec) == null)
continue;
}
if (!recFilter.test(rec))
continue;
L.add(rec);
/* get bounds for canvas genmic browser */
if (!rec.getReadUnmappedFlag() && rec.getCigar() != null) {
final long endIndex = convertContigPosToGenomicIndex(rec.getContig(), rec.getUnclippedEnd());
if (canvasFirstRecordGenomicIndex == null) {
canvasFirstRecordGenomicIndex = convertContigPosToGenomicIndex(rec.getContig(), rec.getUnclippedStart());
canvasLastRecordGenomicIndex = endIndex;
} else if (canvasLastRecordGenomicIndex < endIndex) {
canvasLastRecordGenomicIndex = endIndex;
}
}
/* FILL pileup */
if (!rec.getReadUnmappedFlag() && rec.getCigar() != null) {
int refpos = rec.getUnclippedStart();
int readpos = 0;
final byte[] bases = rec.getReadBases();
final byte[] quals = rec.getOriginalBaseQualities();
/**
* function getting the ith base
*/
final Function<Integer, Character> getBaseAt = new Function<Integer, Character>() {
@Override
public Character apply(Integer readPos) {
char c;
if (bases == null || bases.length <= readPos) {
return '?';
} else {
c = (char) bases[readPos];
}
c = (rec.getReadNegativeStrandFlag() ? Character.toLowerCase(c) : Character.toUpperCase(c));
return c;
}
};
/**
* function getting the ith base quality
*/
final Function<Integer, Character> getQualAt = new Function<Integer, Character>() {
@Override
public Character apply(Integer readPos) {
char c;
if (quals == null || quals.length <= readPos) {
return '#';
} else {
c = (char) quals[readPos];
}
return c;
}
};
for (final CigarElement ce : rec.getCigar()) {
switch(ce.getOperator()) {
case P:
break;
case N:
case D:
{
refpos += ce.getLength();
break;
}
case H:
{
for (int i = 0; i < ce.getLength(); ++i) {
final Pileup p = getpileup.apply(new ContigPos(rec.getContig(), refpos));
p.watch('-', '#', ce.getOperator());
++refpos;
}
break;
}
case I:
{
for (int i = 0; i < ce.getLength(); ++i) {
final Pileup p = getpileup.apply(new ContigPos(rec.getContig(), refpos));
p.watch('<', getQualAt.apply(readpos), ce.getOperator());
readpos++;
}
break;
}
case S:
for (int i = 0; i < ce.getLength(); ++i) {
final Pileup p = getpileup.apply(new ContigPos(rec.getContig(), refpos));
p.watch('-', getQualAt.apply(readpos), ce.getOperator());
++readpos;
++refpos;
}
break;
case EQ:
case X:
case M:
for (int i = 0; i < ce.getLength(); ++i) {
final Pileup p = getpileup.apply(new ContigPos(rec.getContig(), refpos));
p.watch(getBaseAt.apply(readpos), getQualAt.apply(readpos), ce.getOperator());
++readpos;
++refpos;
}
break;
}
}
}
}
if (iter != null)
iter.close();
this.canvasScrolVInCoverage.setMin(0);
final int max_depth = pos2pileup.values().stream().map(P -> P.depth()).max((A, B) -> (A.compareTo(B))).orElse(0);
this.canvasScrolVInCoverage.setMax(max_depth + 1);
this.canvasScrolVInCoverage.setValue(0);
this.recordTable.getItems().setAll(L);
this.pileupTable.getItems().setAll(pos2pileup.values());
if (canvasFirstRecordGenomicIndex != null && canvasLastRecordGenomicIndex != null && canvasFirstRecordGenomicIndex.longValue() < canvasLastRecordGenomicIndex.longValue()) {
this.canvasScrollHGenomicLoc.setMin(canvasFirstRecordGenomicIndex);
this.canvasScrollHGenomicLoc.setMax(canvasLastRecordGenomicIndex);
// this.canvasScrollHGenomicLoc.setUnitIncrement(1);
// this.canvasScrollHGenomicLoc.setBlockIncrement(Math.max(1.0,Math.min( canvasLastRecordGenomicIndex-canvasFirstRecordGenomicIndex, this.canvas.getWidth())));
this.canvasScrollHGenomicLoc.setValue(canvasFirstRecordGenomicIndex);
} else {
this.canvasScrollHGenomicLoc.setMin(0);
this.canvasScrollHGenomicLoc.setMax(0);
this.canvasScrollHGenomicLoc.setValue(0);
this.canvasScrollHGenomicLoc.setBlockIncrement(0);
this.canvasScrollHGenomicLoc.setUnitIncrement(1);
}
if (!this.recordTable.getItems().isEmpty()) {
final int last_index = this.recordTable.getItems().size() - 1;
if (!this.recordTable.getItems().get(0).getReadUnmappedFlag() && !this.recordTable.getItems().get(last_index).getReadUnmappedFlag()) {
super.seqDictionaryCanvas.setItemsInterval(new ContigPos(this.recordTable.getItems().get(0).getContig(), this.recordTable.getItems().get(0).getStart()), new ContigPos(this.recordTable.getItems().get(last_index).getContig(), this.recordTable.getItems().get(last_index).getEnd()));
if (this.recordTable.getItems().get(0).getContig().equals(this.recordTable.getItems().get(last_index).getContig())) {
this.gotoField.setText(this.recordTable.getItems().get(0).getContig() + ":" + this.recordTable.getItems().get(0).getStart() + "-" + this.recordTable.getItems().get(last_index).getEnd());
}
} else {
super.seqDictionaryCanvas.setItemsInterval(null, null);
}
} else {
super.seqDictionaryCanvas.setItemsInterval(null, null);
}
/* show hide columns for paired end data if no paired data found */
{
final boolean contains_paired = this.recordTable.getItems().stream().anyMatch(S -> S.getReadPairedFlag());
for (final TableColumn<SAMRecord, ?> tc : this.pairedEndColumns) tc.setVisible(contains_paired);
}
repaintCanvas();
}
use of javafx.scene.control.TableColumn in project jvarkit by lindenb.
the class VcfStage method buildSampleTab.
/**
* build table of Sample
*/
private Tab buildSampleTab() {
final boolean editable = this.name2sampledef.size() > 1;
final BorderPane pane = new BorderPane(this.sampleTable);
pane.setPadding(new Insets(10));
this.sampleTable.setEditable(editable);
if (!getVcfFile().getPedigree().isEmpty()) {
this.sampleTable.getColumns().add(makeColumn("Family", R -> {
if (R.getPedSample().isPresent()) {
return R.getPedSample().get().getFamily();
}
return null;
}));
}
this.sampleTable.getColumns().add(makeColumn("Name", R -> R.getName()));
final TableColumn<SampleDef, Boolean> selectCol = new TableColumn<>("Display");
selectCol.setCellValueFactory(new PropertyValueFactory<>("displayed"));
selectCol.setCellFactory(col -> {
CheckBoxTableCell<SampleDef, Boolean> cell = new CheckBoxTableCell<>(index -> {
return sampleTable.getItems().get(index).displayedProperty();
});
return cell;
});
selectCol.setEditable(editable);
this.sampleTable.getColumns().add(selectCol);
this.sampleTable.getColumns().add(makeColumn("Description", R -> R.getDescription()));
this.sampleTable.setPlaceholder(new Label("No Sample."));
this.sampleTable.getItems().addAll(this.name2sampledef.values());
if (!getVcfFile().getPedigree().isEmpty()) {
this.sampleTable.getColumns().add(makeColumn("Father", R -> {
if (R.getPedSample().isPresent()) {
final PedFile.Sample parent = R.getPedSample().get().getFather();
return parent == null ? null : parent.getName();
}
return (String) null;
}));
this.sampleTable.getColumns().add(makeColumn("Mother", R -> {
if (R.getPedSample().isPresent()) {
final PedFile.Sample parent = R.getPedSample().get().getMother();
return parent == null ? null : parent.getName();
}
return (String) null;
}));
this.sampleTable.getColumns().add(makeColumn("Sex", R -> {
if (R.getPedSample().isPresent()) {
return R.getPedSample().get().getSex().name();
}
return (String) null;
}));
this.sampleTable.getColumns().add(makeColumn("Status", R -> {
if (R.getPedSample().isPresent()) {
return R.getPedSample().get().getStatus().name();
}
return (String) null;
}));
}
final HBox top = new HBox();
top.setPadding(new Insets(10));
Button but = new Button("Select all");
but.setOnAction(AE -> {
for (final SampleDef def : name2sampledef.values()) {
def.setDisplayed(true);
}
if (getCurrentSelectedItem().isPresent()) {
refreshGenotypeTable(getCurrentSelectedItem().get());
}
});
top.getChildren().add(but);
but = new Button("Unselect all");
but.setOnAction(AE -> {
for (final SampleDef def : name2sampledef.values()) {
def.setDisplayed(false);
}
if (getCurrentSelectedItem().isPresent()) {
refreshGenotypeTable(getCurrentSelectedItem().get());
}
});
top.getChildren().add(but);
pane.setTop(top);
final Tab tab = new Tab("Samples", pane);
tab.setClosable(false);
return tab;
}
use of javafx.scene.control.TableColumn in project jvarkit by lindenb.
the class JvarkitCentral method start.
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Jvarkit-Central");
StackPane root = new StackPane();
root.setPadding(new Insets(2));
final TableView<Class<?>> tableView = new TableView<>();
final TableColumn<Class<?>, String> nameCol = new TableColumn<>("Name");
nameCol.setCellValueFactory(CB -> {
final String value;
Class<?> clazz = CB.getValue();
final Program program = clazz.getAnnotation(Program.class);
if (!Launcher.class.isAssignableFrom(clazz) || program == null) {
value = null;
} else {
value = program.name();
}
return new SimpleStringProperty(value);
});
final TableColumn<Class<?>, String> descCol = new TableColumn<>("Description");
descCol.setCellValueFactory(CB -> {
final String value;
Class<?> clazz = CB.getValue();
final Program program = clazz.getAnnotation(Program.class);
if (!Launcher.class.isAssignableFrom(clazz) || program == null) {
value = null;
} else {
value = program.description();
}
return new SimpleStringProperty(value);
});
tableView.getColumns().addAll(nameCol, descCol);
final BorderPane borderPane1 = new BorderPane(tableView);
borderPane1.setPadding(new Insets(10));
final Button but = new Button("New Instance...");
but.setOnAction(AE -> {
final Class<?> clazz = tableView.getSelectionModel().getSelectedItem();
if (clazz == null)
return;
final Program program = clazz.getAnnotation(Program.class);
if (!Launcher.class.isAssignableFrom(clazz) || program == null)
return;
createNewInstanceOf(clazz);
});
FlowPane bottom = new FlowPane(but);
borderPane1.setBottom(bottom);
tableView.getItems().addAll(String.class, Integer.class, VCFFilterJS.class, BioAlcidae.class);
root.getChildren().add(borderPane1);
// root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
use of javafx.scene.control.TableColumn in project latexdraw by arnobl.
the class BadaboomController method initialize.
@SuppressWarnings("unchecked")
@Override
public void initialize(final URL location, final ResourceBundle resources) {
final ObservableList<TableColumn<Throwable, ?>> cols = table.getColumns();
((TableColumn<Throwable, String>) cols.get(0)).setCellValueFactory(cell -> new ReadOnlyStringWrapper(cell.getValue().toString()));
((TableColumn<Throwable, String>) cols.get(1)).setCellValueFactory(cell -> new ReadOnlyStringWrapper(cell.getValue().getMessage()));
((TableColumn<Throwable, String>) cols.get(2)).setCellValueFactory(cell -> {
final StackTraceElement[] stackTrace = cell.getValue().getStackTrace();
final String msg = stackTrace != null && stackTrace.length > 0 ? stackTrace[0].toString() : "";
return new ReadOnlyStringWrapper(msg);
});
cols.forEach(col -> col.prefWidthProperty().bind(table.widthProperty().divide(3)));
table.setItems(FXCollections.observableArrayList(BadaboomCollector.INSTANCE));
table.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
final Callable<String> converter = () -> {
final Throwable ex = table.getSelectionModel().getSelectedItem();
if (ex == null)
return "";
// NON-NLS
return Arrays.stream(ex.getStackTrace()).map(Object::toString).collect(Collectors.joining("\n\tat ", ex.toString() + "\n\tat ", ""));
};
stack.textProperty().bind(Bindings.createStringBinding(converter, table.getSelectionModel().selectedItemProperty()));
}
use of javafx.scene.control.TableColumn in project CST-135 by psradke.
the class FinalSale method start.
@Override
public void start(Stage primaryStage) throws Exception {
// Background image
BackgroundImage backImg = new BackgroundImage(new Image("file:src/DispenserDesign/Background&ButtonImages/FinalSalePage/FinalSaleBackground.png", 810, 720, false, true), BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT, BackgroundSize.DEFAULT);
// PANE CREATION
// Home and Back Buttons Pane
GridPane buttons = new GridPane();
buttons.setHgap(10);
buttons.setVgap(10);
buttons.setPadding(new Insets(0, 10, 0, 10));
// TableView Cart Pane
GridPane cartView = new GridPane();
cartView.setHgap(9);
cartView.setVgap(9);
cartView.setOpacity(0.9);
cartView.setPadding(new Insets(0, 10, 0, 10));
// Delete and Purchase Buttons Pane
GridPane buttons2 = new GridPane();
buttons2.setHgap(10);
buttons2.setVgap(10);
buttons2.setPadding(new Insets(0, 10, 0, 10));
// Main Pane for arrangement
VBox vBox = new VBox();
vBox.setPadding(new Insets(10, 10, 10, 10));
vBox.getChildren().addAll(buttons, cartView, buttons2);
// Background Pane
StackPane root = new StackPane();
root.setMaxSize(800, 610);
root.setMinSize(800, 610);
root.setBackground(new Background(backImg));
root.setPadding(new Insets(0, 10, 0, 10));
root.getChildren().add(vBox);
// BUTTON CREATION
// Home Button
Button home = new Button("", new ImageView(new Image("file:src/DispenserDesign/Background&ButtonImages/NavigationButtons/HomeButton.png")));
home.setBackground(Background.EMPTY);
home.setMaxSize(5, 10);
home.setMinSize(5, 10);
buttons.add(home, 9, 2);
// home.setOnAction(e -> {
// homePage.setScene(scene);
// });
// Back Button
Button back = new Button("", new ImageView(new Image("file:src/DispenserDesign/Background&ButtonImages/NavigationButtons/BackButton.png")));
back.setBackground(Background.EMPTY);
back.setMaxSize(5, 10);
back.setMinSize(5, 10);
buttons.add(back, 64, 2);
back.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Back");
}
});
// Purchase Button
Button purchase = new Button("", new ImageView(new Image("file:src/DispenserDesign/Background&ButtonImages/FinalSalePage/Purchase.png")));
purchase.setBackground(Background.EMPTY);
purchase.setMaxSize(5, 10);
purchase.setMinSize(5, 10);
buttons2.add(purchase, 36, 11);
purchase.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Purcahse");
}
});
// Delete Button
// Button delete = new Button("Delete Product");
// delete.setOnAction(e -> deleteClicked());
// CREATE TABLE FOR DISPLAYING CART
TableView<Product> table;
// Name column
TableColumn<Product, String> nameCol = new TableColumn<>("Name");
nameCol.setMinWidth(150);
nameCol.setCellValueFactory(new PropertyValueFactory<>("name"));
// Price column
TableColumn<Product, Double> priceCol = new TableColumn<>("Price");
priceCol.setMinWidth(20);
priceCol.setCellValueFactory(new PropertyValueFactory<>("price"));
// Weight column
TableColumn<Product, Double> weightCol = new TableColumn<>("Weight");
weightCol.setMinWidth(50);
weightCol.setCellValueFactory(new PropertyValueFactory<>("weight"));
// Quantity column
TableColumn<Product, Double> quantityCol = new TableColumn<>("Quantity");
quantityCol.setMinWidth(20);
quantityCol.setCellValueFactory(new PropertyValueFactory<>("quantity"));
table = new TableView<>();
table.setItems(getProduct());
table.setBackground(Background.EMPTY);
table.setMaxSize(620, 313);
table.setMinSize(620, 313);
table.getColumns().addAll(nameCol, priceCol, weightCol, quantityCol);
cartView.add(table, 7, 18);
Scene scene = new Scene(root, 800, 710);
primaryStage.setTitle("Checkout");
primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.show();
}
Aggregations