Browse Source

看到一个诡异代码

master
daniel 8 years ago
parent
commit
83459633ba
  1. 42
      designer_base/src/com/fr/design/mainframe/loghandler/LogHandlerBar.java

42
designer_base/src/com/fr/design/mainframe/loghandler/LogHandlerBar.java

@ -3,13 +3,14 @@ package com.fr.design.mainframe.loghandler;
import com.fr.base.BaseUtils; import com.fr.base.BaseUtils;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.stable.script.Atom;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
import java.util.concurrent.atomic.AtomicBoolean;
public class LogHandlerBar extends JPanel implements ItemSelectable { public class LogHandlerBar extends JPanel implements ItemSelectable {
@ -25,8 +26,6 @@ public class LogHandlerBar extends JPanel implements ItemSelectable {
private int SERVERNUM = 0; private int SERVERNUM = 0;
private boolean isWithSerious; private boolean isWithSerious;
private int i;
private Timer timer;
public LogHandlerBar() { public LogHandlerBar() {
this(null); this(null);
@ -86,35 +85,14 @@ public class LogHandlerBar extends JPanel implements ItemSelectable {
timerPaint(); timerPaint();
} }
private static final int UNKNOWN_COUNT = 5;
private AtomicBoolean painting = new AtomicBoolean(false);
public synchronized void timerPaint() {
isWithSerious = true; public void timerPaint() {
timer = new Timer(500, null); if(!painting.get()) {
ActionListener taskAction = new ActionListener() { painting.set(true);
public void actionPerformed(ActionEvent e) { repaint();
if (i < UNKNOWN_COUNT) { painting.set(false);
isWithSerious = (i & 1) == 0 ? true : false;
repaint();
} else if (i == UNKNOWN_COUNT) {
if (timer == null) {
return;
}
timer.stop();
timer = null;
i = 0;
isWithSerious = true;
return;
}
i++;
}
};
if (timer != null) {
timer.addActionListener(taskAction);
}
// taskAction里还有可能置空timer.
if (timer != null) {
timer.start();
} }
} }

Loading…
Cancel
Save