use of org.apache.pivot.wtk.TextInput in project pivot by apache.
the class ComponentInspectorSkin method addIntControl.
private static Component addIntControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
int value = dictionary.getInt(key);
TextInput textInput = new TextInput();
textInput.setTextSize(10);
textInput.setMaximumLength(10);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(value));
section.add(textInput);
Form.setLabel(textInput, key);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
try {
dictionary.put(key, Integer.parseInt(textInputLocal.getText()));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
int valueLocal = dictionary.getInt(key);
textInputLocal.setText(String.valueOf(valueLocal));
}
}
}
});
return textInput;
}
use of org.apache.pivot.wtk.TextInput in project pivot by apache.
the class ComponentInspectorSkin method updateDoubleControl.
private void updateDoubleControl(Dictionary<String, Object> dictionary, String key) {
TextInput textInput = (TextInput) controls.get(key);
if (textInput != null) {
double value = (Double) dictionary.get(key);
textInput.setText(String.valueOf(value));
}
}
use of org.apache.pivot.wtk.TextInput in project pivot by apache.
the class ComponentInspectorSkin method addSpanControl.
private static Component addSpanControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
Span span = (Span) dictionary.get(key);
BoxPane boxPane = new BoxPane(Orientation.VERTICAL);
section.add(boxPane);
Form.setLabel(boxPane, key);
FlowPane flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
TextInput textInput = new TextInput();
textInput.setTextSize(10);
textInput.setMaximumLength(10);
textInput.setValidator(new IntValidator());
textInput.setText(span == null ? "" : String.valueOf(span.start));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Span spanLocal = (Span) dictionary.get(key);
try {
int start = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Span(start, spanLocal == null ? start : spanLocal.end));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(spanLocal == null ? "" : String.valueOf(spanLocal.start));
}
}
}
});
Label label = new Label("start");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
textInput = new TextInput();
textInput.setTextSize(10);
textInput.setMaximumLength(10);
textInput.setValidator(new IntValidator());
textInput.setText(span == null ? "" : String.valueOf(span.end));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Span spanLocal = (Span) dictionary.get(key);
try {
int end = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Span(spanLocal == null ? end : spanLocal.start, end));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(spanLocal == null ? "" : String.valueOf(spanLocal.end));
}
}
}
});
label = new Label("end");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
return boxPane;
}
use of org.apache.pivot.wtk.TextInput in project pivot by apache.
the class ComponentInspectorSkin method updateSpanControl.
private void updateSpanControl(Dictionary<String, Object> dictionary, String key) {
BoxPane boxPane = (BoxPane) controls.get(key);
if (boxPane != null) {
Span span = (Span) dictionary.get(key);
TextInput startTextInput = (TextInput) ((FlowPane) boxPane.get(0)).get(0);
TextInput endTextInput = (TextInput) ((FlowPane) boxPane.get(1)).get(0);
startTextInput.setText(span == null ? "" : String.valueOf(span.start));
endTextInput.setText(span == null ? "" : String.valueOf(span.end));
}
}
use of org.apache.pivot.wtk.TextInput in project pivot by apache.
the class StockTrackerWindow method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
// Add stocks table view event handlers
stocksTableView.getTableViewRowListeners().add(new TableViewRowListener() {
@Override
public void rowsSorted(TableView tableView) {
List<?> tableData = stocksTableView.getTableData();
if (tableData.getLength() > 0) {
stocksTableView.setSelectedIndex(0);
}
}
});
stocksTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener() {
@Override
public void selectedRangesChanged(TableView tableView, Sequence<Span> previousSelectedRanges) {
int firstSelectedIndex = stocksTableView.getFirstSelectedIndex();
removeSymbolsAction.setEnabled(firstSelectedIndex != -1);
refreshDetail();
}
});
stocksTableView.getTableViewSortListeners().add(new TableViewSortListener() {
@Override
public void sortChanged(TableView tableView) {
@SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableView.getTableData();
tableData.setComparator(new TableViewRowComparator(tableView));
}
});
stocksTableView.getComponentKeyListeners().add(new ComponentKeyListener() {
@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
if (keyCode == Keyboard.KeyCode.DELETE || keyCode == Keyboard.KeyCode.BACKSPACE) {
removeSymbolsAction.perform(component);
} else if (keyCode == Keyboard.KeyCode.A && Keyboard.isPressed(Platform.getCommandModifier())) {
stocksTableView.selectAll();
}
return false;
}
});
// Add symbol text input event handlers
symbolTextInput.getTextInputContentListeners().add(new TextInputContentListener() {
@Override
public void textChanged(TextInput textInput) {
addSymbolAction.setEnabled(textInput.getCharacterCount() > 0);
}
});
symbolTextInput.getComponentKeyListeners().add(new ComponentKeyListener() {
@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
if (keyCode == Keyboard.KeyCode.ENTER) {
if (addSymbolAction.isEnabled()) {
addSymbolAction.perform(component);
}
}
return false;
}
});
// Assign actions to add and remove symbol buttons
addSymbolButton.setAction(addSymbolAction);
removeSymbolsButton.setAction(removeSymbolsAction);
// Add a button press listener to open the Yahoo! Finance web page when
// the link is clicked
yahooFinanceButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(new URL(YAHOO_FINANCE_HOME).toURI());
} catch (MalformedURLException exception) {
throw new RuntimeException(exception);
} catch (URISyntaxException exception) {
throw new RuntimeException(exception);
} catch (IOException exception) {
System.out.println("Unable to open " + YAHOO_FINANCE_HOME + " in default browser.");
}
}
});
}
Aggregations