1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Some small makeup

- use diamond notation <> to remove redundant type specification
- do no cache listeners, because it makes the code heavier for a
a very small gain in memory usage.
- removed redundant "this" keywords
This commit is contained in:
Cristian Maglie 2019-03-28 15:44:45 +01:00 committed by Martino Facchin
parent 2f68d2af1b
commit 3438b86699
2 changed files with 30 additions and 39 deletions

View File

@ -136,7 +136,7 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
minimumSize.setSize(minimumSize.getWidth() / 3, minimumSize.getHeight());
noLineEndingAlert.setMinimumSize(minimumSize);
lineEndings = new JComboBox<String>(new String[]{tr("No line ending"), tr("Newline"), tr("Carriage return"), tr("Both NL & CR")});
lineEndings = new JComboBox<>(new String[]{tr("No line ending"), tr("Newline"), tr("Carriage return"), tr("Both NL & CR")});
lineEndings.addActionListener((ActionEvent event) -> {
PreferencesData.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
noLineEndingAlert.setForeground(pane.getBackground());
@ -146,7 +146,7 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
lineEndings.setMaximumSize(lineEndings.getMinimumSize());
serialRates = new JComboBox<String>();
serialRates = new JComboBox<>();
for (String rate : serialRateStrings) {
serialRates.addItem(rate + " " + tr("baud"));
}

View File

@ -1880,9 +1880,6 @@ public class Base {
getEditors().forEach(Editor::applyPreferences);
}
private MouseWheelListener editorFontResizeMouseWheelListener = null;
private KeyListener editorFontResizeKeyListener = null;
/**
* Adds a {@link MouseWheelListener} and {@link KeyListener} to the given
* component that will make "CTRL scroll" and "CTRL +/-"
@ -1894,8 +1891,8 @@ public class Base {
* @param comp - The component to add the listener to.
*/
public void addEditorFontResizeListeners(Component comp) {
this.addEditorFontResizeMouseWheelListener(comp);
this.addEditorFontResizeKeyListener(comp);
addEditorFontResizeMouseWheelListener(comp);
addEditorFontResizeKeyListener(comp);
}
/**
@ -1907,20 +1904,17 @@ public class Base {
* @param comp - The component to add the listener to.
*/
public void addEditorFontResizeMouseWheelListener(Component comp) {
if (this.editorFontResizeMouseWheelListener == null) {
this.editorFontResizeMouseWheelListener = (MouseWheelEvent e) -> {
if (e.isControlDown()) {
if (e.getWheelRotation() < 0) {
this.handleFontSizeChange(1);
} else {
this.handleFontSizeChange(-1);
}
comp.addMouseWheelListener(e -> {
if (e.isControlDown()) {
if (e.getWheelRotation() < 0) {
this.handleFontSizeChange(1);
} else {
e.getComponent().getParent().dispatchEvent(e);
this.handleFontSizeChange(-1);
}
};
}
comp.addMouseWheelListener(this.editorFontResizeMouseWheelListener);
} else {
e.getComponent().getParent().dispatchEvent(e);
}
});
}
/**
@ -1930,29 +1924,26 @@ public class Base {
* @param comp - The component to add the listener to.
*/
public void addEditorFontResizeKeyListener(Component comp) {
if (this.editorFontResizeKeyListener == null) {
this.editorFontResizeKeyListener = new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK
|| e.getModifiersEx() == (KeyEvent.CTRL_DOWN_MASK
| KeyEvent.SHIFT_DOWN_MASK)) {
switch (e.getKeyCode()) {
case KeyEvent.VK_PLUS:
case KeyEvent.VK_EQUALS:
Base.this.handleFontSizeChange(1);
break;
case KeyEvent.VK_MINUS:
if (!e.isShiftDown()) {
Base.this.handleFontSizeChange(-1);
}
break;
comp.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK
|| e.getModifiersEx() == (KeyEvent.CTRL_DOWN_MASK
| KeyEvent.SHIFT_DOWN_MASK)) {
switch (e.getKeyCode()) {
case KeyEvent.VK_PLUS:
case KeyEvent.VK_EQUALS:
Base.this.handleFontSizeChange(1);
break;
case KeyEvent.VK_MINUS:
if (!e.isShiftDown()) {
Base.this.handleFontSizeChange(-1);
}
break;
}
}
};
}
comp.addKeyListener(this.editorFontResizeKeyListener);
}
});
}
public List<JMenu> getBoardsCustomMenus() {