Skip to content

Commit

Permalink
Merge remote-tracking branch 'dmmxzz/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
eric0828 committed Oct 31, 2014
2 parents 97805e8 + 31dff76 commit e1a1202
Show file tree
Hide file tree
Showing 13 changed files with 874 additions and 101 deletions.
Binary file added resources/icons/trash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 22 additions & 4 deletions src/com/lottery/action/ImportLotteryAllAction.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.lottery.action;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFileChooser;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;

import com.lottery.component.ProgressPanel;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;

Expand All @@ -22,7 +24,15 @@
*/
public class ImportLotteryAllAction implements ActionListener {

@Override
private ProgressPanel progressPanel;
private Frame frame;

public ImportLotteryAllAction(Frame frame, ProgressPanel progressPanel) {
this.frame = frame;
this.progressPanel = progressPanel;
}

@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
Expand Down Expand Up @@ -53,8 +63,16 @@ public String getDescription() {
if (state == 1) {
return;
} else {
File file = fileChooser.getSelectedFile();
processImport(file);
final File file = fileChooser.getSelectedFile();
progressPanel.start();
Thread performer = new Thread(new Runnable() {
public void run() {
processImport(file);
progressPanel.stop();
JOptionPane.showMessageDialog(frame, "导入全排列数据成功!", "系统消息", JOptionPane.INFORMATION_MESSAGE);
}
}, "导入全排列数据");
performer.start();
}

}
Expand Down
22 changes: 20 additions & 2 deletions src/com/lottery/action/ImportLotteryAnyAction.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.lottery.action;

import com.lottery.common.SpringBeanFactory;
import com.lottery.component.ProgressPanel;
import com.lottery.model.LotteryAny;
import com.lottery.service.LotteryAnyService;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;

import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
Expand All @@ -21,6 +23,14 @@
*/
public class ImportLotteryAnyAction implements ActionListener {

private ProgressPanel progressPanel;
private Frame frame;

public ImportLotteryAnyAction(Frame frame, ProgressPanel progressPanel) {
this.frame = frame;
this.progressPanel = progressPanel;
}

@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
Expand Down Expand Up @@ -52,8 +62,16 @@ public String getDescription() {
if (state == 1) {
return;
} else {
File file = fileChooser.getSelectedFile();
processImport(file);
final File file = fileChooser.getSelectedFile();
progressPanel.start();
Thread performer = new Thread(new Runnable() {
public void run() {
processImport(file);
progressPanel.stop();
JOptionPane.showMessageDialog(frame, "导入中奖数据成功!", "系统消息", JOptionPane.INFORMATION_MESSAGE);
}
}, "导入中奖数据");
performer.start();
}

}
Expand Down
14 changes: 14 additions & 0 deletions src/com/lottery/component/ApplicationConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.lottery.component;

import java.awt.*;

/**
* Created by tasly on 2014/10/22.
*/
public class ApplicationConfig {
public static Color COLOR_PANEL_BACKGROUND = new Color(224, 235, 247); //충겼교쒼
public static Color COLOR_UI_TEXT = new Color(116, 185, 235); //UI匡俚奈
public static Color COLOR_UI_FRAME = new Color(255, 183, 0);//UI긋움奈(뼝)
public static Color COLOR_TOOLBAR_FRAME = new Color(186, 201, 219); //묏야으긋움
public static Font FONT_UI_TEXT = new Font("菓흡錤붚", Font.PLAIN, 14); //UI俚竟
}
31 changes: 31 additions & 0 deletions src/com/lottery/component/CrystalComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.lottery.component;

import javax.swing.*;
import java.awt.event.MouseEvent;

/**
* Created by tasly on 2014/10/22.
*/
public class CrystalComponent extends JButton {
protected boolean isMouseEntered; // Êó±ê½øÈë±êÖ¾

public CrystalComponent() {
this.addMouseListener(new CrystalComponentMouseListenr(this));
}

public void mouseClicked(MouseEvent e) {
}

public void mouseEntered(MouseEvent e) {
}

public void mouseExited(MouseEvent e) {
}

public void mousePressed(MouseEvent e) {
}

public void mouseReleased(MouseEvent e) {

}
}
46 changes: 46 additions & 0 deletions src/com/lottery/component/CrystalComponentMouseListenr.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.lottery.component;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
* Created by tasly on 2014/10/22.
*/
public class CrystalComponentMouseListenr implements MouseListener {
private CrystalComponent crystalComponent;

public CrystalComponentMouseListenr(CrystalComponent crystalComponent) {
this.crystalComponent = crystalComponent;
}

public void mouseClicked(MouseEvent e) {
crystalComponent.mouseClicked(e);
crystalComponent.updateUI();
}

public void mouseEntered(MouseEvent e) {
crystalComponent.mouseEntered(e);
crystalComponent.isMouseEntered = true;
crystalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
crystalComponent.updateUI();

}

public void mouseExited(MouseEvent e) {
crystalComponent.mouseExited(e);
crystalComponent.isMouseEntered = false;
crystalComponent.setCursor(Cursor.getDefaultCursor());
crystalComponent.updateUI();
}

public void mousePressed(MouseEvent e) {
crystalComponent.mousePressed(e);
crystalComponent.updateUI();
}

public void mouseReleased(MouseEvent e) {
crystalComponent.mouseReleased(e);
crystalComponent.updateUI();
}
}
114 changes: 114 additions & 0 deletions src/com/lottery/component/CrystalImageButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.lottery.component;

import java.awt.*;
import java.awt.event.MouseEvent;

/**
* Created by tasly on 2014/10/22.
*/
public class CrystalImageButton extends ImageButton {
private int frameType = 0; // 边框
public static int FRAME_RIGHT = 1;
public static int FRAME_AROUND = 4;

private int mbStatus = 0;// 鼠标事件状态 0: 鼠标弹起,1:鼠标按下
private boolean clicked = false; // 按下

private float alpha = 1f; // 不透明

public CrystalImageButton(String name) {
setName(name);
setOpaque(false);
setBorderPainted(false);
}

public void mouseEntered(MouseEvent e) {
if (clicked)
return;
new Thread() {
public void run() {
float a = 0f;
while (a <= 1f) {
alpha = a;
CrystalImageButton.this.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
a += 0.1;
}
}
}.start();
}

public void mouseExited(MouseEvent e) {
}

public int getFrameType() {
return frameType;
}

public void setFrameType(int frameType) {
this.frameType = frameType;
}

public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
AlphaComposite composite = AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, alpha);
g2.setComposite(composite);

// 绘制边框
if (this.isMouseEntered) {
PaintUtils.drawButtonBackground(g2, this, new Color(253, 236, 219),
new Color(253, 223, 187), new Color(255, 206, 105),
new Color(255, 255, 222));
}
// 按钮被按下的效果
if (clicked) {
PaintUtils.drawButtonBackground(g2, this, new Color(255, 199, 99),
new Color(253, 236, 219), new Color(253, 236, 219),
new Color(255, 199, 99));
}
composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f);
g2.setComposite(composite);
if (frameType == FRAME_AROUND) {
g.setColor(ApplicationConfig.COLOR_TOOLBAR_FRAME);
g.drawRoundRect(1, 1, getWidth() - 4, getHeight() - 2, 3, 3);
} else if (frameType == FRAME_RIGHT) {
g.setColor(ApplicationConfig.COLOR_TOOLBAR_FRAME);
g.drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 2);
}

// 消除锯齿
PaintUtils.setFractionalmetricsOn(g2);
// 文字风格
g.setColor(ApplicationConfig.COLOR_UI_TEXT);
g.setFont(ApplicationConfig.FONT_UI_TEXT);

// 绘制图标
if (getImage() != null) {
g.drawImage(getImage(),
(getWidth() - getImage().getWidth(this)) / 2, 5 + mbStatus,
this);
g.drawString(getName(), (getWidth() - getName().length()
* ApplicationConfig.FONT_UI_TEXT.getSize()) / 2,
getImage().getHeight(this) + mbStatus);
} else {
g.drawString(getName(), (getWidth() - getName().length()
* ApplicationConfig.FONT_UI_TEXT.getSize()) / 2, 10 + mbStatus);
}
}

public void pushButton(boolean x) {
clicked = x;
}

public void mousePressed(MouseEvent e) {
mbStatus = 1;
}

public void mouseReleased(MouseEvent e) {
mbStatus = 0;
}
}
27 changes: 27 additions & 0 deletions src/com/lottery/component/ImageButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.lottery.component;

import java.awt.*;

/**
* Created by tasly on 2014/10/22.
*/
public class ImageButton extends CrystalComponent {
private String name; //Ãû³Æ
private Image image; //ͼ±ê

public Image getImage() {
return image;
}

public void setImage(Image image) {
this.image = image;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
48 changes: 48 additions & 0 deletions src/com/lottery/component/MemoryPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.lottery.component;

import javax.swing.*;
import java.awt.*;

/**
* Created by tasly on 2014/10/21.
*/
public class MemoryPanel extends JPanel {
//状态条的颜色
private Color edgeColor = new Color(82, 115, 214);
private Color centerColor = new Color(180, 200, 230);

public void paint(Graphics g) {
super.paint(g);
//得到当前组件(JPanel)的大小
Dimension dimension = getSize();
//得到各边框的宽度
Insets insets = getInsets();
int left = insets.left;
int top = insets.top;
//得到内存使用状态信息
Runtime runtime = Runtime.getRuntime();
long freeMemory = runtime.freeMemory();
long totalMemory = runtime.totalMemory();
//组件(JPanel)除去左、右边框后的宽度
int insideWidth = dimension.width - (insets.left + insets.right);
//内存使用量的显示宽度
int usedAmount = insideWidth - (int) (((long) insideWidth * freeMemory) / totalMemory);
int insideHeight = dimension.height - (insets.bottom + insets.top);
Graphics2D g2 = (Graphics2D) g;
//设置渐变效果的画笔
g2.setPaint(new GradientPaint(left, top, edgeColor, left, insideHeight / 2, centerColor, true));
g.fillRect(left, top, usedAmount, insideHeight);
g.setColor(getBackground());
g.fillRect(left + usedAmount, top, insideWidth - usedAmount, insideHeight);
g.setFont(getFont());
g.setColor(Color.black);
//显示状态的文字
String memory = (Long.toString((totalMemory - freeMemory) / 1048576L) + "M of " + Long.toString(totalMemory / 1048576L) + 'M');
//确定文字的显示位置
FontMetrics fontmetrics = g.getFontMetrics();
int stringWidth = fontmetrics.charsWidth(memory.toCharArray(), 0, memory.length());
int stringHeight = fontmetrics.getHeight() - fontmetrics.getDescent();
//显示文字
g.drawString(memory, left + (insideWidth - stringWidth) / 2, top + (insideHeight + stringHeight) / 2);
}
}
Loading

0 comments on commit e1a1202

Please sign in to comment.