Vim delimitmate append blank line after closing bracket - text

I have installed delimitmate to auto-close parantheses/brackets.
I had to do this remapping in my .vimrc file: inoremap { {<CR>}<up><end><CR>.
I am required to also append a blank/new line AFTER the closing bracket like so:
Expected:
public int get() {
//code
}
*append new line after typing '{'
#Override
public String toString() {
//code
}
Current: No newline added after auto-closing bracket
public int get() {
//code
}
#Override
public String toString() {
//code
}
Would appreciate any help in remapping the key to add a newline after the closing bracket.

Related

Why does android studio only let me set text (on a button or text view) by chars (and not strings?)

Whether I try to change a textView or a button, why does Android Studio require that I pass only chars and not strings in the setText() method?
Strings are automatically converted to CharSequences when necessary (or are CharSequences; can't remember. The point is, they're compatible):
public class Main {
public static void testF(CharSequence seq) {
System.out.println(seq);
}
public static void main(String[] args) {
testF("Hello"); // Prints "Hello"
}
}
This would have been a good thing to try on your own or search for first.

Why does this code warned unreachable in Groovy?

I was thinking to return a map with several directories list. But the very first caused a warning for me:
def enlistFiles() {
return
[downloadFolder: downloadFolder.listFiles( new FileFilter() {
#Override
boolean accept(File file) {
return !file.isDirectory()
}
})]
}
"Code unreachable"
Why?
Anything below line 3 will not be executed. The return key word should not be followed by a line break.
Your code should be:
def enlistFiles() {
return [downloadFolder: downloadFolder.listFiles( new FileFilter() {
#Override
boolean accept(File file) {
return !file.isDirectory()
}
})]
}

Changing the font colour of TreeNode in GXT 3

How do I change the font colour of a TreeNode in GXT 3?
I've tried returning SafeHtml from the ValueProvider, but that just seems to call toString() on the SafeHtml object. I've also tried to get hold of the Element in ValueProvider.getValue() but it always returns null.
In GXT 2 we were using a ModelStringProvider and returning HTML, but I can't find anything similar that exists.
Here's some example code I've tried:
tree=new Tree<NavigableModel<Integer>, String>(treeStore, new ValueProvider<NavigableModel<Integer>, String>() {
public String getValue(NavigableModel<Integer> _model) {
TreeNode<NavigableModel<Integer>> treeNode=tree.findNode(_model);
StringBuilder sb=new StringBuilder();
if (!_model.getActive()) {
// All elements return null
XElement elem=tree.getView().getElement(treeNode);
if(elem!=null) {
elem.getStyle().setColor("red");
}
// treeNode.getElement().getStyle().setColor("red");
// treeNode.getTextElement().getStyle().setColor("red");
// sb.appendHtmlConstant("<span class=\"item-deleted\">");
}
sb.append(_model.get("name"));
if (idsCheckBox.getValue()) {
sb.append(" ("+_model.get("id")+")");
}
// if (!_model.getActive()) {
// sb.appendHtmlConstant("</span>");
// }
return(sb.toString());
}
public String getPath() {
return("name");
}
public void setValue(NavigableModel<Integer> object, String value) {
}
});
Figured it out!
I needed to use SafeHtml for the ValueProvider and set the Tree cell to a SafeHtmlCell e.g.
tree=new Tree<NavigableModel<Integer>, SafeHtml>(treeStore, new ValueProvider<NavigableModel<Integer>, SafeHtml>() {
public SafeHtml getValue(NavigableModel<Integer> _model) {
SafeHtmlBuilder sb=new SafeHtmlBuilder();
if(_model==null) return sb.toSafeHtml();
if (!_model.getActive()) {
// My class to make the text red if this model isn't active
sb.appendHtmlConstant("<span class=\"item-deleted\">");
}
sb.appendEscaped((String)_model.get("name"));
if (!_model.getActive()) {
sb.appendHtmlConstant("</span>");
}
return(sb.toSafeHtml());
}
public void setValue(NavigableModel<Integer> object, SafeHtml value) {
}
public String getPath() {
return("name");
}
});
// Set the cell to SafeHtmlCell to use the SafeHtml returned by ValueProvider
tree.setCell(new SafeHtmlCell());
Hopefully this will help someone else.

Replace Text with number in TextField

I have this field in which I insert port number. I would like to convert the string automatically into number:
fieldNport = new TextField();
fieldNport.setPrefSize(180, 24);
fieldNport.setFont(Font.font("Tahoma", 11));
grid.add(fieldNport, 1, 1);
Can you tell how I can do this? I cannot find suitable example in stack overflow.
EDIT:
Maybe this:
fieldNport.textProperty().addListener(new ChangeListener()
{
#Override
public void changed(ObservableValue o, Object oldVal, Object newVal)
{
try
{
int Nport = Integer.parseInt((String) oldVal);
}
catch (NumberFormatException e)
{
}
}
});
Starting with JavaFX 8u40, you can set a TextFormatter object on a text field:
UnaryOperator<Change> filter = change -> {
String text = change.getText();
if (text.matches("[0-9]*")) {
return change;
}
return null;
};
TextFormatter<String> textFormatter = new TextFormatter<>(filter);
fieldNport = new TextField();
fieldNport.setTextFormatter(textFormatter);
This avoids both subclassing and duplicate change events that you will get when you add a change listener to the text property and modify the text in that listener.
You can write something like this :
fieldNPort.text.addListener(new ChangeListener(){
#Override public void changed(ObservableValue o,Object oldVal, Object newVal){
//Some Code
//Here you can use Integer.parseInt methods inside a try/catch
//because parseInt throws Exceptions
}
});
Here are all the things you'd need about properties and Listeners in JavaFX:
http://docs.oracle.com/javafx/2/binding/jfxpub-binding.htm
If you have any question, I'll be glad to help.
Maybe this is what you need:
fieldNPort= new TextField()
{
#Override
public void replaceText(int start, int end, String text)
{
if (text.matches("[0-9]*"))
{
super.replaceText(start, end, text);
}
}
#Override
public void replaceSelection(String text)
{
if (text.matches("[0-9]*"))
{
super.replaceSelection(text);
}
}
};
This will restrict the users from entering anything but numbers(you can modify the regex expression to your needs) and then you do not have to worry about Integer.parseInt throwing any exception.

Dependency Property usage in Silverlight

I am just following the code examples of a Beginning SilverLight book and here is part of the code about user controls and Dependeny Property that I have typed from the book into my IDE:
public class CoolDownButtonControl: Control
{
public static readonly DependencyProperty CoolDownSecondsProperty =
DependencyProperty.Register(
"CoolDownSeconds",
typeof(int),
typeof(CoolDownButtonControl),
new PropertyMetadata(
new PropertyChangedCallback(
CoolDownButtonControl.OnCoolDownSecondsPropertyChanged
)
)
);
public int CoolDownSeconds
{
get
{
return (int)GetValue(CoolDownSecondsProperty);
}
set
{
SetValue(CoolDownSecondsProperty, value);
}
}
private static void OnCoolDownSecondsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
CoolDownButtonControl cdBuutton = d as CoolDownButtonControl;
cdBuutton.OnCoolDownButtonChange(null);
}
}
The problem is that IDE highlights the line of cdBuutton.OnCoolDownButtonChange(null); complaining about
CoolDownButtonControl does not contain a definition for
OnCoolDownButtonChange
As I am new to this and hoping to learn it from this example I couldn't figure out what is wrong and how to fix it?
You should add that method too, something like this:
protected virtual void OnCoolDownButtonChange(RoutedEventArgs e)
{
}

Resources