Tabnine Logo
TextSizingUtility
Code IndexAdd Tabnine to your IDE (free)

How to use
TextSizingUtility
in
ch.sahits.game.openpatrician.javafx.control

Best Java code snippets using ch.sahits.game.openpatrician.javafx.control.TextSizingUtility (Showing top 19 results out of 315)

origin: ch.sahits.game/OpenPatricianJavaFX

/**
 * Initialize the page splitter.
 * @param pageHeigth height of a page
 * @param pageWidth width of a page
 * @param lineSpacing spacing between two lines
 * @param initialHeigth initial height of the page
 * @param font to be used.
 */
public PageSplitter(double pageHeigth, double pageWidth,
    double lineSpacing, double initialHeigth, Font font) {
  super();
  this.pageHeigth = pageHeigth;
  this.pageWidth = pageWidth;
  this.lineSpacing = lineSpacing;
  this.initialHeigth = initialHeigth;
  this.font = font;
  sizing = new TextSizingUtility();
}
/**
origin: ch.sahits.game/OpenPatricianJavaFX

/**
 * Calculate the dimensions of a string using the font with the number of characters.
 * The height  and width are the maximum value, the width of a character is an average value.
 * @param size number of carachters for wich to calculate the dimensions
 * @param font to be used
 * @return dimensions of a String containing Tg to calculate the heigth and n for the width calculation.
 */
@Override
public Dimension2D calculate(int size, Font font) {
  double height = computeTextHeight(font, "Tg", Double.MAX_VALUE);
  double width = computeTextWidth(font, "n", Double.MAX_VALUE);
  return new Dimension2D(width*size*.8, height*1.2);
}
origin: ch.sahits.game/OpenPatricianJavaFX

private Dimension2D calculateButtonDimensions(
    final OpenPatricianButton button) {
  Dimension2D dim = new TextSizingUtility().calculate(button.getText(), button.getFont());
  return new Dimension2D(dim.getWidth()*1.2, dim.getHeight()*1.2);
}
origin: ch.sahits.game/OpenPatricianJavaFX

/**
 * Create the labels and add them to the group.
 * @param g group the labels are added to
 * @param centerPoint central point around which the labels are placed.
 */
private void createAndAddLabels(Group g, final Point2D centerPoint) {
  List<String> values = control.valuesProperty();
  angles = new ArrayList<>(values.size());
  double angle = currentRotation.doubleValue() + 180;
  double step = (180.0 - 2 * currentRotation.doubleValue()) / (values.size() - 1);
  int radius = 120;
  for (String value : values) {
    angles.add(angle);
    Point2D basePoint = calculateBasePoint(centerPoint, radius, angle);
    Dimension2D dim = sizeing.calculate(value, control.getFont());
    Label l = new Label(value);
    l.setFont(control.getFont());
    l.getStyleClass().add("openPatricianSlider");
    l.setTranslateX(basePoint.getX() - dim.getWidth() * calculateMoveFactor(angle));
    l.setTranslateY(basePoint.getY() - dim.getHeight());
    g.getChildren().add(l);
    angle += step;
  }
  double initialAngle = Math.max(INITIAL_ROTATION, control.getSelectedIndex() * step);
  currentRotation.setValue(initialAngle);
}
/**
origin: ch.sahits.game/OpenPatricianJavaFX

public String calculateEllipsis(Font font, final String text, double maxWidth){
  double ellipsisWidth = sizing.calculate(ELLIPSIS, font).getWidth();
  int guessNbChars = Math.min(sizing.guessNumberOfCharacters(maxWidth - ellipsisWidth, font), text.length());
  String substr;
  if (guessNbChars == text.length()) {
  double currentCalculatedWidth = sizing.calculate(substr, font).getWidth();
    reducedNbCharacters = true;
    substr = text.substring(0, guessNbChars)+ELLIPSIS;
    currentCalculatedWidth = sizing.calculate(substr, font).getWidth();
        substr = text.substring(0, guessNbChars) + ELLIPSIS;
      currentCalculatedWidth = sizing.calculate(substr, font).getWidth();
origin: ch.sahits.game/OpenPatricianJavaFX

/**
 * Compute the line height and add it to the page height.
 * @param line to be checked
 * @param currentPageHeight current page height without <code>line</code>
 * @return new page height
 */
private double updatePageHeight(String line, double currentPageHeight) {
  double lineHeigth = sizing.computeTextHeight(font, line, Double.MAX_VALUE);
  currentPageHeight += lineSpacing + lineHeigth;
  return currentPageHeight;
}

origin: ch.sahits.game/OpenPatricianJavaFX

/**
 * Guess the number of characters that can be displayed in <code>destWidth</code>.
 * The number is guessed as an arbitrary width per character for the font is assumed.
 * @param destWidth destination with
 * @param font to used for the text
 * @return number of characters that should match into <code>destWidth</code>
 */
public int guessNumberOfCharacters(double destWidth, Font font) {
  double width = computeTextWidth(font, "n", Double.MAX_VALUE);
  return (int) Math.floor(destWidth/(width*0.8));
}
/**
origin: ch.sahits.game/OpenPatricianJavaFX

private void calculateDimensions(OpenPatricianWoodenTextInput input) {
  Dimension2D dim = sizing.calculate(input.getSize(), input.getFont());
  double inputHeigth = textField.getHeight();
  width.set(dim.getWidth());
  height.set(Math.max(dim.getHeight(), inputHeigth));
  textField.setMaxSize(width.doubleValue(), height.doubleValue());
  setImage();
}
origin: ch.sahits.game/OpenPatricianJavaFX

double computeTextHeight(Font font, String text, double wrappingWidth) {
  return computeTextHeight(font, text, wrappingWidth, 0);
}
origin: ch.sahits.game/OpenPatricianJavaFX

double lineWidth = sizing.computeTextWidth(font, oneLine.toString(), Double.MAX_VALUE);
  lineWidth = sizing.computeTextWidth(font, l.getLine(), Double.MAX_VALUE);
  if (!isLineTooLong(lineWidth)) {
  lineWidth = sizing.computeTextWidth(font, word, Double.MAX_VALUE);
  if (isLineTooLong(lineWidth)) {
    if (!tokenizer.hasMoreTokens()) {
origin: ch.sahits.game/OpenPatricianDisplay

@Bean
@Lazy
public TextSizingUtility textSizingUtility() {
  return new TextSizingUtility();
}
origin: ch.sahits.game/OpenPatricianJavaFX

/**
 * Calculate the dimensions of a string using the font with the characters in the string.
 * The height and width are the maximum value. The text will not be wrapped.
 * @param text for which to calculate the dimensions
 * @param font to be used for the calculation
 * @return Bounding box for the text using font.
 */
@Override
public Dimension2D calculate(String text, Font font) {
  double height = computeTextHeight(font, text, Double.MAX_VALUE);
  double width = computeTextWidth(font, text, Double.MAX_VALUE);
  return new Dimension2D(width, height*1.2);
}
origin: ch.sahits.game/OpenPatricianJavaFX

private void calculateNewDimension(Font font) {
  final ObservableList<OpenPatricianSpinnerOptionDataModel> options = spinner.getOptions();
  Dimension2D dim4heigth = sizing.calculate(1, font);
  double maxWidth = spinner.getMaxWidth(); // This must be initialized before appended to the scene
  double destinationHeigth = dim4heigth.getHeight();
    Dimension2D dim4width = sizing.calculate(word, font);
    if (dim4width.getWidth() > dim.getWidth()) {
      double percentage = dim.getWidth() / dim4width.getWidth();
origin: ch.sahits.game/OpenPatricianJavaFX

public OpenPatricianSliderSkin(OpenPatricianSlider slider) {
  super(slider);
  control = slider;
  
  currentRotation = new SimpleDoubleProperty(this, "currentRotation", INITIAL_ROTATION);
  sizeing = new TextSizingUtility();
  
  final SteeringWheelGroup background = new SteeringWheelGroup(control.getInitialWidth(), currentRotation.doubleValue());
  background.setManaged(false); 
  Group g = new Group(background);
  
  final Point2D centerPoint = new Point2D(control.getInitialWidth()/2, control.getInitialWidth()/2);
  
  createAndAddLabels(g, centerPoint);
  
  background.setTranslateX(centerPoint.getX() - background.getImageWidth()/2);
  background.setTranslateY(centerPoint.getY() - background.getImageWidth()/2 - yTranslation);
  getChildren().add(g);
}
/**
origin: ch.sahits.game/OpenPatricianJavaFX

private void calculateNewDimenstions(OpenPatricianRadioButton radioButton, String text, Image rbBG) {
  InputStream is;
  final int remainWidth = 28; // width that is left from the background
  final int destHight = 27;
  final double xStart = rbBG.getWidth();
  final int yStart = 0;
  Dimension2D dim = sizing.calculate(text, radioButton.getFont());
  double width = dim.getWidth();
  double destWidth = width-remainWidth + 10;
  String fileName = imageFactory.getFileNameExt(destWidth,destHight,remainWidth);
  is = getClass().getResourceAsStream(fileName);
  Image slab = new Image(is, destWidth, destHight, false, true);
  slabView.setImage(slab);
  slabView.translateXProperty().set(xStart);
  slabView.translateYProperty().set(yStart);
  double posX = destWidth/2+(xStart-remainWidth-10);
  label.translateXProperty().set(posX);
}
origin: ch.sahits.game/OpenPatricianJavaFX

  private void calculateDimensions(OpenPatricianDialogInput input) {
    Dimension2D dim = sizing.calculate(input.getSize(), input.getFont());
    width.set(dim.getWidth());
    height.set(dim.getHeight() + 10);
    textField.setMaxSize(width.doubleValue(), height.doubleValue());
  }
}
origin: ch.sahits.game/OpenPatricianJavaFX

public DisplayMessageOverlayLabelSkin(DisplayMessageOverlayLabel control, TextSizingUtility sizing) {
  super(control);
  textLength.set(sizing.calculate(control.getText(), control.getFont()).getWidth());
  control.fontProperty().addListener((observable, oldFont, newFont) ->
      textLength.set(sizing.calculate(control.getText(), newFont).getWidth()));
  control.textProperty().addListener((observable, oldText, newText) ->
      textLength.set(sizing.calculate(newText, control.getFont()).getWidth()));
  InputStream is = getClass().getResourceAsStream("waxButton-middle.png");
  waxBtnMiddle = new Image(is);
origin: ch.sahits.game/OpenPatricianJavaFX

public OpenPatricianWoodenTextInputSkin(OpenPatricianWoodenTextInput input) {
  super(input);
  textField = new TextField(input.getText());
  imgView = new ImageView();
  calculateDimensions(input);
  textField.textProperty().bindBidirectional(input.textProperty());
  textField.getStyleClass().add("openPatricianWoodenTextInput");
  Insets padding = textField.getPadding();
  Insets newPadding = new Insets(0, padding.getRight(), 0, padding.getLeft());
  textField.setPadding(newPadding);
  // Listeners
  input.sizeProperty().addListener((observable, oldValue, newValue) -> calculateDimensions(input));
  textField.heightProperty().addListener((observable, oldValue, newValue) -> {
    Dimension2D dim = sizing.calculate(input.getSize(), input.getFont());
    height.set(Math.max(dim.getHeight(), newValue.doubleValue()));
    setImage();
  });
  
  
  StackPane stack = new StackPane();
  stack.getChildren().addAll(imgView, textField);
  Group group = new Group(stack);
  group.setManaged(false);
  
  getChildren().add(group);
}
origin: ch.sahits.game/OpenPatricianJavaFX

  background.setWidth(newValue.getWidth());
  background.setHeight(newValue.getHeight());
  Dimension2D titleDim = textSize.calculate(control.getTitle(), openPatrician24);
  title.setLayoutX((newValue.getWidth() - titleDim.getWidth())/2 + frame.getInsetBackground().getX());
  titleBackground.setLayoutX((newValue.getWidth() - titleWidth)/2 + frame.getInsetBackground().getX() + 20);
  background.setLayoutX(newValue.getX());
  background.setLayoutY(newValue.getX());
  Dimension2D titleDim = textSize.calculate(control.getTitle(), openPatrician24);
  descBackground.setFitHeight(newValue.getHeight() - 1080 * localScale + 2);
  Dimension2D descDimension = textSize.calculate(control.getDescription(), openPatrician18);
  double wrappingWidth = Math.min(descDimension.getWidth(), newValue.getWidth());
  desc.setWrappingWidth(wrappingWidth);
});
title.textProperty().addListener((observable, oldValue, newValue) -> {
  Dimension2D titleDim = textSize.calculate(control.getTitle(), openPatrician24);
  title.setLayoutX((frame.getBackgroundDimension().getWidth() - titleDim.getWidth())/2 + frame.getInsetBackground().getX());
});
desc.textProperty().addListener((observable, oldValue, newValue) -> {
  Dimension2D descDimension = textSize.calculate(control.getDescription(), openPatrician18);
  double wrappingWidth = Math.min(descDimension.getWidth(), frame.getInnerDimension().getWidth());
  desc.setWrappingWidth(wrappingWidth);
ch.sahits.game.openpatrician.javafx.controlTextSizingUtility

Javadoc

Utility class to define the dimensions of texts used with a certain font.

Most used methods

  • <init>
  • calculate
    Calculate the dimensions of a string using the font with the characters in the string. The height an
  • computeTextHeight
  • computeTextWidth
  • guessNumberOfCharacters
    Guess the number of characters that can be displayed in destWidth. The number is guessed as an arbit

Popular in Java

  • Start an intent from android
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getApplicationContext (Context)
  • getContentResolver (Context)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now