Skip to content

Commit 3438b86

Browse files
cmagliefacchinm
authored andcommitted
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
1 parent 2f68d2a commit 3438b86

File tree

2 files changed

+30
-39
lines changed

2 files changed

+30
-39
lines changed

app/src/processing/app/AbstractTextMonitor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void windowGainedFocus(WindowEvent e) {
136136
minimumSize.setSize(minimumSize.getWidth() / 3, minimumSize.getHeight());
137137
noLineEndingAlert.setMinimumSize(minimumSize);
138138

139-
lineEndings = new JComboBox<String>(new String[]{tr("No line ending"), tr("Newline"), tr("Carriage return"), tr("Both NL & CR")});
139+
lineEndings = new JComboBox<>(new String[]{tr("No line ending"), tr("Newline"), tr("Carriage return"), tr("Both NL & CR")});
140140
lineEndings.addActionListener((ActionEvent event) -> {
141141
PreferencesData.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
142142
noLineEndingAlert.setForeground(pane.getBackground());
@@ -146,7 +146,7 @@ public void windowGainedFocus(WindowEvent e) {
146146

147147
lineEndings.setMaximumSize(lineEndings.getMinimumSize());
148148

149-
serialRates = new JComboBox<String>();
149+
serialRates = new JComboBox<>();
150150
for (String rate : serialRateStrings) {
151151
serialRates.addItem(rate + " " + tr("baud"));
152152
}

app/src/processing/app/Base.java

+28-37
Original file line numberDiff line numberDiff line change
@@ -1880,9 +1880,6 @@ public void handleFontSizeChange(int change) {
18801880
getEditors().forEach(Editor::applyPreferences);
18811881
}
18821882

1883-
private MouseWheelListener editorFontResizeMouseWheelListener = null;
1884-
private KeyListener editorFontResizeKeyListener = null;
1885-
18861883
/**
18871884
* Adds a {@link MouseWheelListener} and {@link KeyListener} to the given
18881885
* component that will make "CTRL scroll" and "CTRL +/-"
@@ -1894,8 +1891,8 @@ public void handleFontSizeChange(int change) {
18941891
* @param comp - The component to add the listener to.
18951892
*/
18961893
public void addEditorFontResizeListeners(Component comp) {
1897-
this.addEditorFontResizeMouseWheelListener(comp);
1898-
this.addEditorFontResizeKeyListener(comp);
1894+
addEditorFontResizeMouseWheelListener(comp);
1895+
addEditorFontResizeKeyListener(comp);
18991896
}
19001897

19011898
/**
@@ -1907,20 +1904,17 @@ public void addEditorFontResizeListeners(Component comp) {
19071904
* @param comp - The component to add the listener to.
19081905
*/
19091906
public void addEditorFontResizeMouseWheelListener(Component comp) {
1910-
if (this.editorFontResizeMouseWheelListener == null) {
1911-
this.editorFontResizeMouseWheelListener = (MouseWheelEvent e) -> {
1912-
if (e.isControlDown()) {
1913-
if (e.getWheelRotation() < 0) {
1914-
this.handleFontSizeChange(1);
1915-
} else {
1916-
this.handleFontSizeChange(-1);
1917-
}
1907+
comp.addMouseWheelListener(e -> {
1908+
if (e.isControlDown()) {
1909+
if (e.getWheelRotation() < 0) {
1910+
this.handleFontSizeChange(1);
19181911
} else {
1919-
e.getComponent().getParent().dispatchEvent(e);
1912+
this.handleFontSizeChange(-1);
19201913
}
1921-
};
1922-
}
1923-
comp.addMouseWheelListener(this.editorFontResizeMouseWheelListener);
1914+
} else {
1915+
e.getComponent().getParent().dispatchEvent(e);
1916+
}
1917+
});
19241918
}
19251919

19261920
/**
@@ -1930,29 +1924,26 @@ public void addEditorFontResizeMouseWheelListener(Component comp) {
19301924
* @param comp - The component to add the listener to.
19311925
*/
19321926
public void addEditorFontResizeKeyListener(Component comp) {
1933-
if (this.editorFontResizeKeyListener == null) {
1934-
this.editorFontResizeKeyListener = new KeyAdapter() {
1935-
@Override
1936-
public void keyPressed(KeyEvent e) {
1937-
if (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK
1938-
|| e.getModifiersEx() == (KeyEvent.CTRL_DOWN_MASK
1939-
| KeyEvent.SHIFT_DOWN_MASK)) {
1940-
switch (e.getKeyCode()) {
1941-
case KeyEvent.VK_PLUS:
1942-
case KeyEvent.VK_EQUALS:
1943-
Base.this.handleFontSizeChange(1);
1944-
break;
1945-
case KeyEvent.VK_MINUS:
1946-
if (!e.isShiftDown()) {
1947-
Base.this.handleFontSizeChange(-1);
1948-
}
1949-
break;
1927+
comp.addKeyListener(new KeyAdapter() {
1928+
@Override
1929+
public void keyPressed(KeyEvent e) {
1930+
if (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK
1931+
|| e.getModifiersEx() == (KeyEvent.CTRL_DOWN_MASK
1932+
| KeyEvent.SHIFT_DOWN_MASK)) {
1933+
switch (e.getKeyCode()) {
1934+
case KeyEvent.VK_PLUS:
1935+
case KeyEvent.VK_EQUALS:
1936+
Base.this.handleFontSizeChange(1);
1937+
break;
1938+
case KeyEvent.VK_MINUS:
1939+
if (!e.isShiftDown()) {
1940+
Base.this.handleFontSizeChange(-1);
19501941
}
1942+
break;
19511943
}
19521944
}
1953-
};
1954-
}
1955-
comp.addKeyListener(this.editorFontResizeKeyListener);
1945+
}
1946+
});
19561947
}
19571948

19581949
public List<JMenu> getBoardsCustomMenus() {

0 commit comments

Comments
 (0)