Skip to content

Commit

Permalink
1.1.补充日期与星期的触发器
Browse files Browse the repository at this point in the history
  • Loading branch information
lyy289065406 committed Oct 30, 2018
1 parent c0e2de2 commit 8dcdff7
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main/java/exp/cron/ui/CronUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class CronUI extends MainWindow {

private final static int WIDTH = 800;

private final static int HEIGHT = 580;
private final static int HEIGHT = 680;

private Cron cron;

Expand Down
129 changes: 129 additions & 0 deletions src/main/java/exp/cron/ui/_DayPanel.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package exp.cron.ui;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import exp.libs.utils.num.NumUtils;
import exp.libs.utils.other.StrUtils;
import exp.libs.warp.task.cron.Cron;
import exp.libs.warp.task.cron._Day;
import exp.libs.warp.ui.SwingUtils;
import exp.libs.warp.ui.cpt.cbg.CheckBoxGroup;

public class _DayPanel extends __TimePanel {
Expand All @@ -17,10 +25,46 @@ public class _DayPanel extends __TimePanel {

private final static int DAY = 31;

private JRadioButton afterBtn;

private JTextField tfAfter;

private JRadioButton workBtn;

private JTextField tfWork;

private JRadioButton lastBtn;

private JRadioButton lastWorkBtn;

protected _DayPanel(Cron cron, String name) {
super(cron, name, 4);
}

@Override
protected void initComponents() {
this.tfAfter = new JTextField(5);
this.afterBtn = new JRadioButton("下一天触发 (C)");
btnGroup.add(afterBtn);
setAfterBtnListener();


this.tfWork = new JTextField(5);
this.workBtn = new JRadioButton("工作日触发 (W)");
btnGroup.add(workBtn);
setWorkBtnListener();


this.lastBtn = new JRadioButton("仅月末最后一天触发 (L)");
btnGroup.add(lastBtn);
setLastBtnListener();


this.lastWorkBtn = new JRadioButton("仅当月最后一个工作日触发 (LW)");
btnGroup.add(lastWorkBtn);
setLastWorkBtnListener();
}

@Override
protected void initTips() {
tfFrom.setToolTipText(StrUtils.concat(
Expand All @@ -30,6 +74,11 @@ protected void initTips() {
tfBegin.setToolTipText(StrUtils.concat(
"取值范围: [", _Day.MIN, ",", _Day.MAX, "]"));
tfStep.setToolTipText(StrUtils.concat("取值范围: [", STEP, ",+∞)"));

tfWork.setToolTipText(StrUtils.concat(
"取值范围: [", _Day.MIN, ",", _Day.MAX, "]"));
tfAfter.setToolTipText(StrUtils.concat(
"取值范围: [", _Day.MIN, ",", _Day.MAX, "]"));
}

@Override
Expand All @@ -41,6 +90,32 @@ protected CheckBoxGroup<String> initSequence() {
return new CheckBoxGroup<String>(days);
}

@Override
protected JPanel getEveryPanel() {
return SwingUtils.getHFlowPanel(FlowLayout.LEFT,
everyBtn, lastBtn, lastWorkBtn);
}

@Override
protected JPanel getExtPanel() {
return SwingUtils.getVFlowPanel(

SwingUtils.getPairsPanel(workBtn,
SwingUtils.getHFlowPanel(FlowLayout.LEFT,
new JLabel(":离当月 "), tfWork,
new JLabel(StrUtils.concat(" ", name, "最近的工作日触发"))
)
),

SwingUtils.getPairsPanel(afterBtn,
SwingUtils.getHFlowPanel(FlowLayout.LEFT,
new JLabel(":在当月 "), tfAfter,
new JLabel(StrUtils.concat(" ", name, "后的第一天触发"))
)
)
);
}

@Override
protected void setEveryBtnListener() {
cron.Day().withEvery();
Expand Down Expand Up @@ -89,4 +164,58 @@ protected void setSeqBtnListener(List<JCheckBox> selecteds) {
cron.Day().withSequence(seqs);
}

private void setAfterBtnListener() {
afterBtn.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
if(StrUtils.isEmpty(tfAfter.getText())) {
tfAfter.setText(String.valueOf(_Day.MIN));
}

int day = NumUtils.toInt(tfAfter.getText(), _Day.MIN);
cron.Day().withAfterDay(day);
CronUI.getInstn().updateCron();
}
});
}

private void setWorkBtnListener() {
workBtn.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
if(StrUtils.isEmpty(tfWork.getText())) {
tfWork.setText(String.valueOf(_Day.MIN));
}

int day = NumUtils.toInt(tfWork.getText(), _Day.MIN);
cron.Day().withWorkday(day);
CronUI.getInstn().updateCron();
}
});
}

private void setLastBtnListener() {
lastBtn.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
cron.Day().withLastDay();
CronUI.getInstn().updateCron();
}
});
}

private void setLastWorkBtnListener() {
lastWorkBtn.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
cron.Day().withLastWorkday();
CronUI.getInstn().updateCron();
}
});
}

}
127 changes: 122 additions & 5 deletions src/main/java/exp/cron/ui/_WeekPanel.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package exp.cron.ui;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import exp.libs.utils.num.NumUtils;
import exp.libs.utils.other.StrUtils;
Expand All @@ -17,15 +21,45 @@

public class _WeekPanel extends __TimePanel {

// FIXME L W C

/** serialVersionUID */
private static final long serialVersionUID = -1330320169878793721L;

private JRadioButton orderBtn;

private JTextField tfWeek;

private JTextField tfIndex;

private JRadioButton afterBtn;

private JTextField tfAfter;

private JRadioButton lastBtn;

protected _WeekPanel(Cron cron, String name) {
super(cron, name, 1);
}

@Override
protected void initComponents() {
this.tfWeek = new JTextField(5);
this.tfIndex = new JTextField(5);
this.orderBtn = new JRadioButton("索引触发 (x#y)");
btnGroup.add(orderBtn);
setOrderBtnListener();


this.tfAfter = new JTextField(5);
this.afterBtn = new JRadioButton("下一天触发 (C)");
btnGroup.add(afterBtn);
setAfterBtnListener();


this.lastBtn = new JRadioButton("仅周六触发 (L)");
btnGroup.add(lastBtn);
setLastBtnListener();
}

@Override
protected void initTips() {
tfFrom.setToolTipText(StrUtils.concat(
Expand All @@ -35,6 +69,13 @@ protected void initTips() {
tfBegin.setToolTipText(StrUtils.concat(
"取值范围: [", _Week.MIN, ",", _Week.MAX, "]"));
tfStep.setToolTipText(StrUtils.concat("取值范围: [", STEP, ",+∞)"));


tfWeek.setToolTipText(StrUtils.concat(
"取值范围: [", _Week.MIN, ",", _Week.MAX, "]"));
tfIndex.setToolTipText(StrUtils.concat("取值范围: [", STEP, ",+∞)"));
tfAfter.setToolTipText(StrUtils.concat(
"取值范围: [", _Week.MIN, ",", _Week.MAX, "]"));
}

@Override
Expand All @@ -51,13 +92,19 @@ protected CheckBoxGroup<String> initSequence() {
return new CheckBoxGroup<String>(months);
}

protected JPanel getEveryPanel() {
return SwingUtils.getHFlowPanel(FlowLayout.LEFT,
everyBtn,
new JLabel(" (注:星期1=周日、星期2=周一、星期3=周二、星期4=周三、星期5=周四、星期6=周五、星期7=周六)"));
}

@Override
protected JPanel getRangePanel() {
return SwingUtils.getPairsPanel(rangeBtn,
SwingUtils.getHFlowPanel(FlowLayout.LEFT,
new JLabel(StrUtils.concat(" :在", name, " ")), tfFrom,
new JLabel(StrUtils.concat(" 到", name, " ")),
tfTo, new JLabel(" 之间触发 (注:星期1=周日、星期2=周一、...、星期7=周六)")
tfTo, new JLabel(" 之间触发")
)
);
}
Expand All @@ -68,16 +115,38 @@ protected JPanel getStepPanel() {
SwingUtils.getHFlowPanel(FlowLayout.LEFT,
new JLabel(StrUtils.concat(" :从", name, " ")), tfBegin,
new JLabel(StrUtils.concat(" 开始, 每隔 ")),
tfStep, new JLabel(" 周触发 (注:星期1=周日、星期2=周一、...、星期7=周六)")
tfStep, new JLabel(" 周触发")
)
);
}

@Override
protected JPanel getExtPanel() {
return SwingUtils.getVFlowPanel(
SwingUtils.getPairsPanel(afterBtn,
SwingUtils.getHFlowPanel(FlowLayout.LEFT,
new JLabel(StrUtils.concat(":在", name, " ")), tfAfter,
new JLabel(" 后的第一天触发")
)
),

SwingUtils.getPairsPanel(orderBtn,
SwingUtils.getHFlowPanel(FlowLayout.LEFT,
new JLabel(StrUtils.concat(":在当月的第 ")), tfIndex,
new JLabel(StrUtils.concat(" 个", name, " ")), tfWeek,
new JLabel(" 触发")
)
),

SwingUtils.addPanel(lastBtn)
);
}

@Override
protected void setEveryBtnListener() {
cron.Week().withEvery();
}

@Override
protected void setRangeBtnListener() {
if(StrUtils.isEmpty(tfFrom.getText())) {
Expand Down Expand Up @@ -122,4 +191,52 @@ protected void setSeqBtnListener(List<JCheckBox> selecteds) {
cron.Week().withSequence(seqs);
}

private void setOrderBtnListener() {
orderBtn.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
if(StrUtils.isEmpty(tfWeek.getText())) {
tfWeek.setText(String.valueOf(_Week.MIN));
}

if(StrUtils.isEmpty(tfIndex.getText())) {
tfIndex.setText(String.valueOf(STEP));
}

int week = NumUtils.toInt(tfWeek.getText(), _Week.MIN);
int index = NumUtils.toInt(tfIndex.getText(), STEP);
cron.Week().withOrder(week, index);
CronUI.getInstn().updateCron();
}
});
}

private void setAfterBtnListener() {
afterBtn.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
if(StrUtils.isEmpty(tfAfter.getText())) {
tfAfter.setText(String.valueOf(_Week.MIN));
}

int week = NumUtils.toInt(tfAfter.getText(), _Week.MIN);
cron.Week().withAfterWeek(week);
CronUI.getInstn().updateCron();
}
});
}

private void setLastBtnListener() {
lastBtn.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
cron.Week().withLastDay();
CronUI.getInstn().updateCron();
}
});
}

}
Loading

0 comments on commit 8dcdff7

Please sign in to comment.