added support for setting line ruler style classes
refs #21
diff --git a/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/internal/LineNumberSupport.java b/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/internal/LineNumberSupport.java
index 8dd4848..fc57cf5 100644
--- a/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/internal/LineNumberSupport.java
+++ b/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/internal/LineNumberSupport.java
@@ -1,6 +1,7 @@
package org.eclipse.fx.text.ui.internal;
import java.util.Collections;
+import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
@@ -34,12 +35,12 @@
this.nr = nr;
}
public int getNr() {
- return nr;
+ return this.nr;
}
@Override
public Object getModel() {
- return nr;
+ return this.nr;
}
@Override
@@ -47,7 +48,7 @@
final int prime = 31;
int result = 1;
result = prime * result + getOuterType().hashCode();
- result = prime * result + nr;
+ result = prime * result + this.nr;
return result;
}
@Override
@@ -61,7 +62,7 @@
LineNrAnnotation other = (LineNrAnnotation) obj;
if (!getOuterType().equals(other.getOuterType()))
return false;
- if (nr != other.nr)
+ if (this.nr != other.nr)
return false;
return true;
}
@@ -96,7 +97,7 @@
@Override
public DoubleProperty getWidth() {
- return w;
+ return this.w;
}
@Override
@@ -122,6 +123,11 @@
public String toString() {
return "LineNrAP@" + hashCode(); //$NON-NLS-1$
}
+
+ @Override
+ public Optional<String> getStyleClass() {
+ return Optional.of("line-number-ruler"); //$NON-NLS-1$
+ }
}
diff --git a/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/internal/WrappedLineRulerAnnotationPresenter.java b/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/internal/WrappedLineRulerAnnotationPresenter.java
index 814034b..52fc59a 100644
--- a/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/internal/WrappedLineRulerAnnotationPresenter.java
+++ b/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/internal/WrappedLineRulerAnnotationPresenter.java
@@ -1,5 +1,6 @@
package org.eclipse.fx.text.ui.internal;
+import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
@@ -23,12 +24,12 @@
@Override
public LayoutHint getLayoutHint() {
- return LayoutHint.valueOf(wrapped.getLayoutHint().toString());
+ return LayoutHint.valueOf(this.wrapped.getLayoutHint().toString());
}
@Override
public int getOrder() {
- return wrapped.getOrder();
+ return this.wrapped.getOrder();
}
private org.eclipse.jface.text.source.Annotation unwrap(Annotation annotation) {
@@ -42,14 +43,14 @@
@Override
public boolean isApplicable(Annotation annotation) {
if (annotation instanceof WrappedAnnotation) {
- return wrapped.isApplicable(unwrap(annotation));
+ return this.wrapped.isApplicable(unwrap(annotation));
}
return false;
}
@Override
public Node createNode() {
- return wrapped.createNode();
+ return this.wrapped.createNode();
}
@Override
@@ -64,7 +65,7 @@
@Override
public void updateNode(Node node, Set<Annotation> annotation) {
- wrapped.updateNode(node, unwrap(annotation));
+ this.wrapped.updateNode(node, unwrap(annotation));
}
@Override
@@ -84,10 +85,15 @@
}
});
}
+
+ @Override
+ public Optional<String> getStyleClass() {
+ return this.wrapped.getStyleClass();
+ }
@Override
public String toString() {
- return "WAP("+wrapped+")@" + hashCode(); //$NON-NLS-2$
+ return "WAP("+this.wrapped+")@" + hashCode(); //$NON-NLS-2$
}
}
diff --git a/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/source/ILineRulerAnnotationPresenter.java b/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/source/ILineRulerAnnotationPresenter.java
index de5ce96..12ac3de 100644
--- a/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/source/ILineRulerAnnotationPresenter.java
+++ b/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/source/ILineRulerAnnotationPresenter.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.fx.text.ui.source;
+import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
@@ -96,4 +97,6 @@
// empty by default
}
+ default Optional<String> getStyleClass() { return Optional.empty(); }
+
}
diff --git a/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/model/LineRulerAnnotationPresenter.java b/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/model/LineRulerAnnotationPresenter.java
index 5fd0a02..ae08e53 100644
--- a/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/model/LineRulerAnnotationPresenter.java
+++ b/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/model/LineRulerAnnotationPresenter.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.fx.ui.controls.styledtext.model;
+import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
@@ -49,4 +50,6 @@
}
default void initialize(LineRuler lineRuler) {}
+
+ default Optional<String> getStyleClass() { return Optional.empty(); }
}
diff --git a/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/skin/StyledTextSkin.java b/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/skin/StyledTextSkin.java
index 5925526..1888d1d 100644
--- a/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/skin/StyledTextSkin.java
+++ b/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/skin/StyledTextSkin.java
@@ -97,6 +97,7 @@
private LineHelper lineHelper;
+ private static final String CSS_CLASS_LINE_RULER_AREA = "line-ruler-area"; //$NON-NLS-1$
private static final String CSS_CLASS_LINE_RULER = "line-ruler"; //$NON-NLS-1$
private static final String CSS_CLASS_SPACER = "spacer"; //$NON-NLS-1$
private static final String CSS_LIST_VIEW = "list-view"; //$NON-NLS-1$
@@ -131,6 +132,7 @@
this.rootContainer.setSpacing(0);
this.lineRulerArea = new HBox();
+ this.lineRulerArea.getStyleClass().setAll(CSS_CLASS_LINE_RULER_AREA);
// Align with ContentView insets!
this.lineRulerArea.setPadding(new Insets(0,0,0,0));
this.rootContainer.getChildren().add(this.lineRulerArea);
@@ -146,7 +148,7 @@
});
Region spacer = new Region();
- spacer.getStyleClass().addAll(CSS_CLASS_LINE_RULER, CSS_CLASS_SPACER);
+ spacer.getStyleClass().addAll(CSS_CLASS_SPACER);
spacer.setMinWidth(2);
spacer.setMaxWidth(2);
this.rootContainer.getChildren().add(spacer);
@@ -319,6 +321,11 @@
BiConsumer<Node, Set<Annotation>> populator = ap::updateNode;
LineRuler flow = new LineRuler(ap.getLayoutHint(), converter, needsPresentation, nodeFactory, populator);
+
+ flow.getStyleClass().setAll(CSS_CLASS_LINE_RULER);
+ // add the styleclass from the provider
+ ap.getStyleClass().ifPresent(flow.getStyleClass()::add);
+
// VerticalLineFlow<Integer, Annotation> flow = new
// VerticalLineFlow<Integer, Annotation>(converter,
// needsPresentation, nodeFactory, populator);
@@ -368,11 +375,6 @@
};
this.sortedLineRulerFlows = FXCollections.observableArrayList();
- this.sortedLineRulerFlows.addListener((ListChangeListener<LineRuler>) (c) -> {
- for (LineRuler flow : this.sortedLineRulerFlows) {
- flow.getStyleClass().setAll(CSS_CLASS_LINE_RULER);
- }
- });
FXBindUtil.uniMapBindList(this.sortedLineRulerPresenters, this.sortedLineRulerFlows, map);
FXBindUtil.uniMapBindList(this.sortedLineRulerFlows, this.lineRulerArea.getChildren(), (flow) -> (Node) flow);
this.sortedLineRulerFlows.addListener((ListChangeListener<? super LineRuler>) (c) -> {
@@ -438,7 +440,7 @@
this.content.setOnDragOver(e -> {
Point2D coords = new Point2D(e.getX(), e.getY());
- Optional<Integer> lineIndex = content.getLineIndex(coords);
+ Optional<Integer> lineIndex = this.content.getLineIndex(coords);
if (lineIndex.isPresent()) {
if (lineIndex.get() != -1) {
@@ -463,7 +465,7 @@
String insert = e.getDragboard().getString();
Point2D coords = new Point2D(e.getX(), e.getY());
- Optional<Integer> lineIndex = content.getLineIndex(coords);
+ Optional<Integer> lineIndex = this.content.getLineIndex(coords);
if (lineIndex.isPresent() && lineIndex.get() != -1) {
getSkinnable().getContent().replaceTextRange(lineIndex.get(), 0, insert);
getSkinnable().setCaretOffset(lineIndex.get() + insert.length());
@@ -641,10 +643,10 @@
}
public int getVisibleLineCount() {
- return scroller.visibleLineCountProperty().get();
+ return this.scroller.visibleLineCountProperty().get();
}
public Bounds getContentBounds() {
- return content.getLayoutBounds();
+ return this.content.getLayoutBounds();
}
}
\ No newline at end of file