mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
* WIP - Adds support for aliasing P25 Phase 2 tones.Playlist editor - adds editor support for alias actions * Playlist editor implementation and integration into application is complete. Adds JavaFX window monitoring to persist window size/location across application runs. Co-authored-by: Denny <denny@denny-desktop>
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
*
|
||||
* * ******************************************************************************
|
||||
* * Copyright (C) 2014-2020 Dennis Sheirer
|
||||
* *
|
||||
* * This program is free software: you can redistribute it and/or modify
|
||||
* * it under the terms of the GNU General Public License as published by
|
||||
* * the Free Software Foundation, either version 3 of the License, or
|
||||
* * (at your option) any later version.
|
||||
* *
|
||||
* * This program is distributed in the hope that it will be useful,
|
||||
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* * GNU General Public License for more details.
|
||||
* *
|
||||
* * You should have received a copy of the GNU General Public License
|
||||
* * along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* * *****************************************************************************
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.gui.control;
|
||||
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.TextFormatter;
|
||||
import javafx.util.converter.IntegerStringConverter;
|
||||
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
/**
|
||||
* Text field control for integer values.
|
||||
*/
|
||||
public class IntegerTextField extends TextField
|
||||
{
|
||||
private static final String REGEX = "[1-9][0-9]*";
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
*/
|
||||
public IntegerTextField()
|
||||
{
|
||||
UnaryOperator<TextFormatter.Change> filter = change ->
|
||||
{
|
||||
String newText = change.getControlNewText();
|
||||
|
||||
if(newText.isEmpty() || newText.matches(REGEX))
|
||||
{
|
||||
return change;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
setTextFormatter(new TextFormatter<Integer>(new IntegerStringConverter(), 0, filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Current integer value of the control, or null if the value is not parsable as an integer
|
||||
*/
|
||||
public Integer get()
|
||||
{
|
||||
String rawText = getText();
|
||||
|
||||
try
|
||||
{
|
||||
return Integer.parseInt(rawText);
|
||||
}
|
||||
catch(Exception pe)
|
||||
{
|
||||
//Do nothing ... we couldn't parse the value
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the integer value in the control
|
||||
*/
|
||||
public void set(int value)
|
||||
{
|
||||
setText(String.valueOf(value));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user