Craig Raw
5 years ago
13 changed files with 140 additions and 52 deletions
@ -0,0 +1,16 @@ |
|||
package com.sparrowwallet.sparrow.control; |
|||
|
|||
import javafx.scene.text.Font; |
|||
|
|||
import java.awt.*; |
|||
|
|||
public class CopyableIdLabel extends CopyableLabel { |
|||
public CopyableIdLabel() { |
|||
this(""); |
|||
} |
|||
|
|||
public CopyableIdLabel(String text) { |
|||
super(text); |
|||
setFont(Font.font("Courier")); |
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
package com.sparrowwallet.sparrow.control; |
|||
|
|||
import javafx.scene.control.TextField; |
|||
|
|||
public class CopyableLabel extends TextField { |
|||
public CopyableLabel() { |
|||
this(""); |
|||
} |
|||
|
|||
public CopyableLabel(String text) { |
|||
super(text); |
|||
|
|||
this.setEditable(false); |
|||
this.getStyleClass().add("copyable-label"); |
|||
this.setPrefWidth(10); |
|||
this.textProperty().addListener((ob, o, n) -> { |
|||
// expand the textfield
|
|||
double width = TextUtils.computeTextWidth(this.getFont(), this.getText(), 0.0D) + 2; |
|||
this.setPrefWidth(width); |
|||
this.setMaxWidth(width); |
|||
}); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,37 @@ |
|||
package com.sparrowwallet.sparrow.control; |
|||
|
|||
import javafx.scene.text.Font; |
|||
import javafx.scene.text.Text; |
|||
import javafx.scene.text.TextBoundsType; |
|||
|
|||
public class TextUtils { |
|||
static final Text helper; |
|||
static final double DEFAULT_WRAPPING_WIDTH; |
|||
static final double DEFAULT_LINE_SPACING; |
|||
static final String DEFAULT_TEXT; |
|||
static final TextBoundsType DEFAULT_BOUNDS_TYPE; |
|||
|
|||
static { |
|||
helper = new Text(); |
|||
DEFAULT_WRAPPING_WIDTH = helper.getWrappingWidth(); |
|||
DEFAULT_LINE_SPACING = helper.getLineSpacing(); |
|||
DEFAULT_TEXT = helper.getText(); |
|||
DEFAULT_BOUNDS_TYPE = helper.getBoundsType(); |
|||
} |
|||
|
|||
public static double computeTextWidth(Font font, String text, double help0) { |
|||
helper.setText(text); |
|||
helper.setFont(font); |
|||
|
|||
helper.setWrappingWidth(0.0D); |
|||
helper.setLineSpacing(0.0D); |
|||
double d = Math.min(helper.prefWidth(-1.0D), help0); |
|||
helper.setWrappingWidth((int) Math.ceil(d)); |
|||
d = Math.ceil(helper.getLayoutBounds().getWidth()); |
|||
|
|||
helper.setWrappingWidth(DEFAULT_WRAPPING_WIDTH); |
|||
helper.setLineSpacing(DEFAULT_LINE_SPACING); |
|||
helper.setText(DEFAULT_TEXT); |
|||
return d; |
|||
} |
|||
} |
Loading…
Reference in new issue