Browse Source

看到一个诡异代码

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

38
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;
public synchronized void timerPaint() { private AtomicBoolean painting = new AtomicBoolean(false);
isWithSerious = true;
timer = new Timer(500, null); public void timerPaint() {
ActionListener taskAction = new ActionListener() { if(!painting.get()) {
public void actionPerformed(ActionEvent e) { painting.set(true);
if (i < UNKNOWN_COUNT) {
isWithSerious = (i & 1) == 0 ? true : false;
repaint(); repaint();
} else if (i == UNKNOWN_COUNT) { painting.set(false);
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