Skip to content

Commit

Permalink
Some small makeup
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
cmaglie authored and facchinm committed Jul 18, 2019
1 parent 2f68d2a commit 3438b86
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 39 deletions.
4 changes: 2 additions & 2 deletions app/src/processing/app/AbstractTextMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void windowGainedFocus(WindowEvent e) {
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());
Expand All @@ -146,7 +146,7 @@ public void windowGainedFocus(WindowEvent e) {

lineEndings.setMaximumSize(lineEndings.getMinimumSize());

serialRates = new JComboBox<String>();
serialRates = new JComboBox<>();
for (String rate : serialRateStrings) {
serialRates.addItem(rate + " " + tr("baud"));
}
Expand Down
65 changes: 28 additions & 37 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1880,9 +1880,6 @@ public void handleFontSizeChange(int change) {
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 +/-"
Expand All @@ -1894,8 +1891,8 @@ public void handleFontSizeChange(int change) {
* @param comp - The component to add the listener to.
*/
public void addEditorFontResizeListeners(Component comp) {
this.addEditorFontResizeMouseWheelListener(comp);
this.addEditorFontResizeKeyListener(comp);
addEditorFontResizeMouseWheelListener(comp);
addEditorFontResizeKeyListener(comp);
}

/**
Expand All @@ -1907,20 +1904,17 @@ public void addEditorFontResizeListeners(Component comp) {
* @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);
}
});
}

/**
Expand All @@ -1930,29 +1924,26 @@ public void addEditorFontResizeMouseWheelListener(Component comp) {
* @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() {
Expand Down

0 comments on commit 3438b86

Please sign in to comment.