Skip to content

Commit

Permalink
Converted anonymous to static private classes
Browse files Browse the repository at this point in the history
  • Loading branch information
RetGal committed Apr 30, 2022
1 parent a264345 commit f380522
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 57 deletions.
23 changes: 13 additions & 10 deletions src/main/java/mpo/dayon/assistant/gui/AssistantFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,7 @@ void onHttpStarting(int port) {
actions.getStopAction().setEnabled(true);
actions.getNetworkConfigurationAction().setEnabled(false);
actions.getIpAddressAction().setEnabled(false);
center = new JPanel() {
final ImageIcon waiting = getOrCreateIcon(ImageNames.WAITING);
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
final int x = (getWidth() - waiting.getIconWidth()) / 2;
final int y = (getHeight() - waiting.getIconHeight()) / 2;
g.drawImage(waiting.getImage(), x, y, this);
}
};
center = new Spinner();
add(center, BorderLayout.CENTER);
getStatusBar().setMessage(translate("listening", port));
}
Expand Down Expand Up @@ -467,4 +458,16 @@ private void fireOnKeyReleased(int keyCode, char keyChar) {
xListener.onKeyReleased(keyCode, keyChar);
}
}

private static class Spinner extends JPanel {
final ImageIcon waiting = getOrCreateIcon(ImageNames.WAITING);

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
final int x = (getWidth() - waiting.getIconWidth()) / 2;
final int y = (getHeight() - waiting.getIconHeight()) / 2;
g.drawImage(waiting.getImage(), x, y, this);
}
}
}
22 changes: 15 additions & 7 deletions src/main/java/mpo/dayon/assisted/gui/ConnectionSettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,21 @@ public JTabbedPane getTabbedPane() {
}

private MouseAdapter clearTextOnDoubleClick(JTextField textField) {
return new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
textField.setText(null);
}
return new Cleanser(textField);
}

private static class Cleanser extends MouseAdapter {
private final JTextField textField;

public Cleanser(JTextField textField) {
this.textField = textField;
}

@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
textField.setText(null);
}
};
}
}
}
62 changes: 28 additions & 34 deletions src/main/java/mpo/dayon/common/gui/statusbar/StatusBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,7 @@ public class StatusBar extends JPanel {

public StatusBar() {
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
setBorder(new EtchedBorder() {

@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
g.translate(x, y);

g.setColor(etchType == LOWERED ? getShadowColor(c) : getHighlightColor(c));
g.drawLine(0, 0, width, 0);

g.setColor(etchType == LOWERED ? getHighlightColor(c) : getShadowColor(c));
g.drawLine(1, 1, width, 1);

g.translate(-x, -y);
}
});

setBorder(new EtchedBorderPainter());
add(Box.createHorizontalStrut(5));
add(message);
add(Box.createHorizontalGlue());
Expand All @@ -56,52 +41,61 @@ public void setSessionDuration(String sessionDuration) {

public void addCounter(Counter<?> counter, int width) {
final JLabel lbl = new JLabel(counter.getUid());

lbl.setHorizontalAlignment(SwingConstants.CENTER);

lbl.setSize(new Dimension(width, 5));
lbl.setPreferredSize(new Dimension(width, 5));

lbl.setToolTipText(counter.getShortDescription());

counter.addListener((CounterListener) (counter1, value) -> lbl.setText(counter1.formatInstantValue(value)));

add(lbl);
}

public void addRamInfo() {
final JLabel lbl = new JLabel();

lbl.setHorizontalAlignment(SwingConstants.CENTER);

lbl.setSize(new Dimension(110, 5));
lbl.setPreferredSize(new Dimension(110, 5));

BigBrother.get().registerRamInfo(new TimerTask() {
@Override
public void run() {
lbl.setText(SystemUtilities.getRamInfo());
}
});
BigBrother.get().registerRamInfo(new MemoryCounter(lbl));
lbl.setToolTipText(translate("memory.info" ));

add(lbl);
}

public void addConnectionDuration() {
sessionDuration.setHorizontalAlignment(SwingConstants.CENTER);

sessionDuration.setSize(new java.awt.Dimension(100, 5));
sessionDuration.setPreferredSize(new java.awt.Dimension(100, 5));
sessionDuration.setToolTipText(translate("session.duration" ));

add(sessionDuration);
}

public void addSeparator() {
final JToolBar.Separator separator = new JToolBar.Separator();
separator.setOrientation(SwingConstants.VERTICAL);

add(separator);
}

private static class MemoryCounter extends TimerTask {
private final JLabel lbl;

public MemoryCounter(JLabel lbl) {
this.lbl = lbl;
}

@Override
public void run() {
lbl.setText(SystemUtilities.getRamInfo());
}
}

private static class EtchedBorderPainter extends EtchedBorder {

@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
g.translate(x, y);
g.setColor(etchType == LOWERED ? getShadowColor(c) : getHighlightColor(c));
g.drawLine(0, 0, width, 0);
g.setColor(etchType == LOWERED ? getHighlightColor(c) : getShadowColor(c));
g.drawLine(1, 1, width, 1);
g.translate(-x, -y);
}
}
}
20 changes: 14 additions & 6 deletions src/main/java/mpo/dayon/common/monitoring/BigBrother.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,23 @@ public static BigBrother get() {
* @param instantRatePeriod millis
*/
public void registerCounter(final Counter<?> counter, final long instantRatePeriod) {
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
counter.computeAndResetInstantValue();
}
}, 0, instantRatePeriod);
timer.scheduleAtFixedRate(new SecondsCounter(counter), 0, instantRatePeriod);
}

public void registerRamInfo(TimerTask callback) {
timer.scheduleAtFixedRate(callback, 0, 1000);
}

private static class SecondsCounter extends TimerTask {
private final Counter<?> counter;

public SecondsCounter(Counter<?> counter) {
this.counter = counter;
}

@Override
public void run() {
counter.computeAndResetInstantValue();
}
}
}

0 comments on commit f380522

Please sign in to comment.