From 8dcdff7fb2e53cc2eae22fe7983c2990c39e4aa5 Mon Sep 17 00:00:00 2001 From: lyy289065406 <289065406@qq.com> Date: Tue, 30 Oct 2018 17:56:58 +0800 Subject: [PATCH] =?UTF-8?q?1.1.=E8=A1=A5=E5=85=85=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E4=B8=8E=E6=98=9F=E6=9C=9F=E7=9A=84=E8=A7=A6=E5=8F=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/exp/cron/ui/CronUI.java | 2 +- src/main/java/exp/cron/ui/_DayPanel.java | 129 +++++++++++++++++++++ src/main/java/exp/cron/ui/_WeekPanel.java | 127 +++++++++++++++++++- src/main/java/exp/cron/ui/__TimePanel.java | 29 +++-- 4 files changed, 273 insertions(+), 14 deletions(-) diff --git a/src/main/java/exp/cron/ui/CronUI.java b/src/main/java/exp/cron/ui/CronUI.java index 5cf4eb6..95a9fd4 100644 --- a/src/main/java/exp/cron/ui/CronUI.java +++ b/src/main/java/exp/cron/ui/CronUI.java @@ -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; diff --git a/src/main/java/exp/cron/ui/_DayPanel.java b/src/main/java/exp/cron/ui/_DayPanel.java index 5e0deb7..5530666 100644 --- a/src/main/java/exp/cron/ui/_DayPanel.java +++ b/src/main/java/exp/cron/ui/_DayPanel.java @@ -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 { @@ -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( @@ -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 @@ -41,6 +90,32 @@ protected CheckBoxGroup initSequence() { return new CheckBoxGroup(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(); @@ -89,4 +164,58 @@ protected void setSeqBtnListener(List 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(); + } + }); + } + } diff --git a/src/main/java/exp/cron/ui/_WeekPanel.java b/src/main/java/exp/cron/ui/_WeekPanel.java index a107dff..81cadc7 100644 --- a/src/main/java/exp/cron/ui/_WeekPanel.java +++ b/src/main/java/exp/cron/ui/_WeekPanel.java @@ -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; @@ -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( @@ -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 @@ -51,13 +92,19 @@ protected CheckBoxGroup initSequence() { return new CheckBoxGroup(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(" 之间触发") ) ); } @@ -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())) { @@ -122,4 +191,52 @@ protected void setSeqBtnListener(List 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(); + } + }); + } + } diff --git a/src/main/java/exp/cron/ui/__TimePanel.java b/src/main/java/exp/cron/ui/__TimePanel.java index cc2ae1d..2a30f4f 100644 --- a/src/main/java/exp/cron/ui/__TimePanel.java +++ b/src/main/java/exp/cron/ui/__TimePanel.java @@ -32,6 +32,8 @@ abstract class __TimePanel extends JPanel { protected String name; + protected ButtonGroup btnGroup; + protected JRadioButton everyBtn; protected JRadioButton rangeBtn; @@ -64,33 +66,40 @@ private JPanel init(String name, int seqRow) { this.tfTo = new JTextField(5); this.tfBegin = new JTextField(5); this.tfStep = new JTextField(5); - initTips(); this.everyBtn = new JRadioButton(StrUtils.concat("每", name, "触发 (*)")); this.rangeBtn = new JRadioButton("范围触发 (x-y)"); this.stepBtn = new JRadioButton("周期触发 (x/y)"); this.seqBtn = new JRadioButton("定点触发 (a,b,c,...)"); - ButtonGroup bg = new ButtonGroup(); - bg.add(everyBtn); - bg.add(rangeBtn); - bg.add(stepBtn); - bg.add(seqBtn); + this.btnGroup = new ButtonGroup(); + btnGroup.add(everyBtn); + btnGroup.add(rangeBtn); + btnGroup.add(stepBtn); + btnGroup.add(seqBtn); + + initComponents(); + initTips(); this.seqCBG = initSequence(); return SwingUtils.getVFlowPanel( getEveryPanel(), getRangePanel(), getStepPanel(), - getSequencePanel(), + getExtPanel(), // 扩展面板 + getSequencePanel(), SwingUtils.addBorder( seqCBG.toGridPanel(seqRow), StrUtils.concat("[", name, "] 列表")) ); } + protected void initComponents() { + // Undo + } + protected abstract void initTips(); - + protected JPanel getEveryPanel() { return SwingUtils.addPanel(everyBtn); } @@ -115,6 +124,10 @@ tfStep, new JLabel(StrUtils.concat(" ", name, "触发")) ); } + protected JPanel getExtPanel() { + return new JPanel(); + } + protected JPanel getSequencePanel() { return SwingUtils.getPairsPanel(seqBtn, new JLabel(StrUtils.concat(" , 在以下指定的若干", name, "触发 : ")));