WeekselectPanel选择一年中的某周

本文介绍了一种用于工作计划分配的周次选择面板组件的实现细节。该面板允许用户选择特定年份的周数,并显示每周的起始和结束日期。通过自定义颜色和按钮组实现了直观的用户界面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

系统要增加工作计划功能,让每个营业部每周末分派下周本部门每个人的工作量。
用到了这个周次选择Panel。网上随便搜搜没有,就自己弄了个。
界面如图:
[img]http://dl.iteye.com/upload/attachment/160424/c6cf4610-63c2-333e-aa8b-77885c52c5da.png[/img]

主功能代码
package transms.app._0all.util.weekselect;

import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import java.awt.GridLayout;
import java.awt.Color;
import java.awt.BorderLayout;
import java.awt.Insets;

import javax.swing.JButton;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JToggleButton;

import org.apache.log4j.Logger;

import transms.app._0all.util.VOUtil;
import transms.app._0all.util.providers.Colors;
import util.Info;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JToolBar;
import javax.swing.JComboBox;

public class WeekselectPanel extends JPanel {

private static final long serialVersionUID = 1L;

/**
* This is the default constructor
*/
public WeekselectPanel() {
super();
initialize();
selectedyear = Integer.valueOf(VOUtil.now().substring(0, 4));
getComboYear().setSelectedItem(String.valueOf(selectedyear));
try {
addWeeks(selectedyear);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setToday();
}

private int selectedyear = -1;

public String getYear() {
return String.valueOf(selectedyear);
}

private int selectedweek = -1;

public int getWeek() {
return selectedweek;
}

/**
* 选中今天
*/
private void setToday() {
try {
int currentweek = du.getWeekNumOfYearDay(VOUtil.now());
mapButton.get(currentweek).setSelected(true);
action(String.valueOf(currentweek));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Logger logger = Logger.getLogger(WeekselectPanel.class); // @jve:decl-index=0:

Map<Integer, JToggleButton> mapButton = new HashMap<Integer, JToggleButton>(); // @jve:decl-index=0:

Map<Integer, Color> mapMonthcolor = new HashMap<Integer, Color>(); // @jve:decl-index=0:

Map<Integer, Color> mapSeasoncolor = new HashMap<Integer, Color>(); // @jve:decl-index=0:

private JPanel panelWeek = null;

private JToolBar jToolBar = null;

private JComboBox comboYear = null;

private JButton jButtonOK = null;

{
mapMonthcolor.put(1, Colors.Chartreuse3);
mapMonthcolor.put(2, Colors.DarkOliveGreen2);
mapMonthcolor.put(3, Colors.DarkOrange1);
mapMonthcolor.put(4, Colors.Firebrick1);
mapMonthcolor.put(5, Colors.Ivory2);
mapMonthcolor.put(6, Colors.Khaki1);
mapMonthcolor.put(7, Colors.LightSalmon);
mapMonthcolor.put(8, Colors.OrangeRed);
mapMonthcolor.put(9, Colors.PaleGreen);
mapMonthcolor.put(10, Colors.PaleTurquoise1);
mapMonthcolor.put(11, Colors.Purple3);
mapMonthcolor.put(12, Color.CYAN);

mapSeasoncolor.put(1, Colors.Ivory2);
mapSeasoncolor.put(2, Colors.Ivory2);
mapSeasoncolor.put(3, Colors.Ivory2);
mapSeasoncolor.put(4, Colors.Chartreuse3);
mapSeasoncolor.put(5, Colors.Chartreuse3);
mapSeasoncolor.put(6, Colors.Chartreuse3);
mapSeasoncolor.put(7, Colors.Purple3);
mapSeasoncolor.put(8, Colors.Purple3);
mapSeasoncolor.put(9, Colors.Purple3);
mapSeasoncolor.put(10, Colors.DarkOrange1);
mapSeasoncolor.put(11, Colors.DarkOrange1);
mapSeasoncolor.put(12, Colors.DarkOrange1);
}

private DateUtil du = new DateUtil(); // @jve:decl-index=0:

private void addWeeks(int year) throws ParseException {
ButtonGroup bg = new ButtonGroup();
getPanelWeek().removeAll();
mapButton.clear();
for (int i = 1; i < 55; i++) {
String sun = du.getYearWeekFirstDay(year, i);
String sat = du.getYearWeekEndDay(year, i);
if (!sat.startsWith(String.valueOf(year))) {
continue;
}
if (mapButton.get(i) == null) {
JToggleButton button = new JToggleButton(String.valueOf(i));
mapButton.put(i, button);
getPanelWeek().add(mapButton.get(i));
bg.add(mapButton.get(i));
mapButton.get(i).addActionListener(getButtonAction());
}
mapButton.get(i).setMargin(new Insets(0, 0, 0, 0));
mapButton.get(i).setToolTipText(
i + " " + du.getMonth(sun) + " " + sun + " - " + sat);
mapButton.get(i).setForeground(mapMonthcolor.get(du.getMonth(sat)));
mapButton.get(i).setBackground(mapSeasoncolor.get(du.getMonth(sat)));
mapButton.get(i).setActionCommand(String.valueOf(i));

}
}

private ActionListener getButtonAction() {
return new ActionListener() {
public void actionPerformed(ActionEvent e) {
action(e.getActionCommand());
}
};
}

private void action(String actionCommand) {
selectedweek = Integer.valueOf(actionCommand);
try {
getJButtonOK().setText(
actionCommand
+ "周 "
+ du.getYearWeekFirstDay(Integer.valueOf(getComboYear()
.getSelectedItem().toString()), selectedweek)
+ Info.labelInfo("to")
+ du.getYearWeekEndDay(Integer.valueOf(getComboYear()
.getSelectedItem().toString()), selectedweek));
} catch (NumberFormatException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

}

/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setLayout(new BorderLayout());
this.setSize(312, 102);
this.add(getPanelWeek(), BorderLayout.CENTER);
this.add(getJToolBar(), BorderLayout.NORTH);
this.setBorder(BorderFactory.createEtchedBorder());
}

/**
* This method initializes panelWeek
*
* @return javax.swing.JPanel
*/
private JPanel getPanelWeek() {
if (panelWeek == null) {
GridLayout gridLayout1 = new GridLayout(0, 13);
panelWeek = new JPanel();
panelWeek.setLayout(gridLayout1);
}
return panelWeek;
}

/**
* This method initializes jToolBar
*
* @return javax.swing.JToolBar
*/
private JToolBar getJToolBar() {
if (jToolBar == null) {
jToolBar = new JToolBar();
jToolBar.add(getComboYear());
jToolBar.add(getJButtonOK());
}
return jToolBar;
}

/**
* This method initializes comboYear
*
* @return javax.swing.JComboBox
*/
private JComboBox getComboYear() {
if (comboYear == null) {
String[] years = { "2009", "2010", "2011", "2012", "2013", "2014", "2015",
"2016", "2017", "2018", "2019", "2020" };
comboYear = new JComboBox(years);
comboYear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
selectedyear = Integer
.valueOf(comboYear.getSelectedItem().toString());
try {
addWeeks(selectedyear);
} catch (NumberFormatException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
}
return comboYear;
}

/**
* This method initializes jButtonOK
*
* @return javax.swing.JButton
*/
private JButton getJButtonOK() {
if (jButtonOK == null) {
jButtonOK = new JButton();
jButtonOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
logger.info(selectedyear + " " + selectedweek);
}
});
}
return jButtonOK;
}

} // @jve:decl-index=0:visual-constraint="10,9"


日期处理工具,网上随便搜的:
package transms.app._0all.util.weekselect;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
* 说明: 取日期时间工具
*/
public class DateUtil {
/**
* @see 取得当前日期(格式为:yyyy-MM-dd)
* @return String
*/
public String GetDate() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String sDate = sdf.format(new Date());
return sDate;
}

/**
* @see 取得当前时间(格式为:yyy-MM-dd HH:mm:ss)
* @return String
*/
public static String GetDateTime() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String sDate = sdf.format(new Date());
return sDate;
}

/**
* @see 按指定格式取得当前时间()
* @return String
*/
public String GetTimeFormat(String strFormat) {
SimpleDateFormat sdf = new SimpleDateFormat(strFormat);
String sDate = sdf.format(new Date());
return sDate;
}

/**
* @see 取得指定时间的给定格式()
* @return String
* @throws ParseException
*/
public String SetDateFormat(String myDate, String strFormat) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat(strFormat);
String sDate = sdf.format(sdf.parse(myDate));
return sDate;
}

public String FormatDateTime(String strDateTime, String strFormat) {
String sDateTime = strDateTime;
try {
Calendar Cal = parseDateTime(strDateTime);
SimpleDateFormat sdf = null;
sdf = new SimpleDateFormat(strFormat);
sDateTime = sdf.format(Cal.getTime());
} catch (Exception e) {
}
return sDateTime;
}

public static Calendar parseDateTime(String baseDate) {
Calendar cal = null;
cal = new GregorianCalendar();
int yy = Integer.parseInt(baseDate.substring(0, 4));
int mm = Integer.parseInt(baseDate.substring(5, 7)) - 1;
int dd = Integer.parseInt(baseDate.substring(8, 10));
int hh = 0;
int mi = 0;
int ss = 0;
if (baseDate.length() > 12) {
hh = Integer.parseInt(baseDate.substring(11, 13));
mi = Integer.parseInt(baseDate.substring(14, 16));
ss = Integer.parseInt(baseDate.substring(17, 19));
}
cal.set(yy, mm, dd, hh, mi, ss);
return cal;
}

public int getDay(String strDate) {
Calendar cal = parseDateTime(strDate);
return cal.get(Calendar.DATE);
}

public int getMonth(String strDate) {
Calendar cal = parseDateTime(strDate);
return cal.get(Calendar.MONTH) + 1;
}

public int getWeekDay(String strDate) {
Calendar cal = parseDateTime(strDate);
return cal.get(Calendar.DAY_OF_WEEK);
}

public String getWeekDayName(String strDate) {
String mName[] = { "日", "一", "二", "三", "四", "五", "六" };
int iWeek = getWeekDay(strDate);
iWeek = iWeek - 1;
return "星期" + mName[iWeek];
}

public int getYear(String strDate) {
Calendar cal = parseDateTime(strDate);
return cal.get(Calendar.YEAR) + 1900;
}

public String DateAdd(String strDate, int iCount, int iType) {
Calendar Cal = parseDateTime(strDate);
int pType = 0;
if (iType == 0) {
pType = 1;
} else if (iType == 1) {
pType = 2;
} else if (iType == 2) {
pType = 5;
} else if (iType == 3) {
pType = 10;
} else if (iType == 4) {
pType = 12;
} else if (iType == 5) {
pType = 13;
}
Cal.add(pType, iCount);
SimpleDateFormat sdf = null;
if (iType <= 2)
sdf = new SimpleDateFormat("yyyy-MM-dd");
else
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String sDate = sdf.format(Cal.getTime());
return sDate;
}

public String DateAdd(String strOption, int iDays, String strStartDate) {
if (!strOption.equals("d"))
;
return strStartDate;
}

public int DateDiff(String strDateBegin, String strDateEnd, int iType) {
Calendar calBegin = parseDateTime(strDateBegin);
Calendar calEnd = parseDateTime(strDateEnd);
long lBegin = calBegin.getTimeInMillis();
long lEnd = calEnd.getTimeInMillis();
int ss = (int) ((lBegin - lEnd) / 1000L);
int min = ss / 60;
int hour = min / 60;
int day = hour / 24;
if (iType == 0)
return hour;
if (iType == 1)
return min;
if (iType == 2)
return day;
else
return -1;
}

/***************************************************************************
* @功能 判断某年是否为闰年
* @return boolean
* @throws ParseException
**************************************************************************/
public boolean isLeapYear(int yearNum) {
boolean isLeep = false;
/** 判断是否为闰年,赋值给一标识符flag */
if ((yearNum % 4 == 0) && (yearNum % 100 != 0)) {
isLeep = true;
} else if (yearNum % 400 == 0) {
isLeep = true;
} else {
isLeep = false;
}
return isLeep;
}

/***************************************************************************
* @功能 计算当前日期某年的第几周
* @return interger
* @throws ParseException
**************************************************************************/
public int getWeekNumOfYear() {
Calendar calendar = Calendar.getInstance();
int iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR);
return iWeekNum;
}

/***************************************************************************
* @功能 计算指定日期某年的第几周
* @return interger
* @throws ParseException
**************************************************************************/
public int getWeekNumOfYearDay(String strDate) throws ParseException {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date curDate = format.parse(strDate);
calendar.setTime(curDate);
int iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR);
return iWeekNum;
}

/***************************************************************************
* @功能 计算某年某周的开始日期
* @return interger
* @throws ParseException
**************************************************************************/
public String getYearWeekFirstDay(int yearNum, int weekNum) throws ParseException {

Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, yearNum);
cal.set(Calendar.WEEK_OF_YEAR, weekNum);
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
// 分别取得当前日期的年、月、日
String tempYear = Integer.toString(cal.get(Calendar.YEAR));
String tempMonth = Integer.toString(cal.get(Calendar.MONTH) + 1);
String tempDay = Integer.toString(cal.get(Calendar.DATE));
String tempDate = tempYear + "-" + tempMonth + "-" + tempDay;
return SetDateFormat(tempDate, "yyyy-MM-dd");

}

/***************************************************************************
* @功能 计算某年某周的结束日期
* @return interger
* @throws ParseException
**************************************************************************/
public String getYearWeekEndDay(int yearNum, int weekNum) throws ParseException {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, yearNum);
cal.set(Calendar.WEEK_OF_YEAR, weekNum + 1);
cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
// 分别取得当前日期的年、月、日
String tempYear = Integer.toString(cal.get(Calendar.YEAR));
String tempMonth = Integer.toString(cal.get(Calendar.MONTH) + 1);
String tempDay = Integer.toString(cal.get(Calendar.DATE));
String tempDate = tempYear + "-" + tempMonth + "-" + tempDay;
return SetDateFormat(tempDate, "yyyy-MM-dd");
}

/***************************************************************************
* @功能 计算某年某月的开始日期
* @return interger
* @throws ParseException
**************************************************************************/
public String getYearMonthFirstDay(int yearNum, int monthNum) throws ParseException {

// 分别取得当前日期的年、月、日
String tempYear = Integer.toString(yearNum);
String tempMonth = Integer.toString(monthNum);
String tempDay = "1";
String tempDate = tempYear + "-" + tempMonth + "-" + tempDay;
return SetDateFormat(tempDate, "yyyy-MM-dd");

}

/***************************************************************************
* @功能 计算某年某月的结束日期
* @return interger
* @throws ParseException
**************************************************************************/
public String getYearMonthEndDay(int yearNum, int monthNum) throws ParseException {

// 分别取得当前日期的年、月、日
String tempYear = Integer.toString(yearNum);
String tempMonth = Integer.toString(monthNum);
String tempDay = "31";
if (tempMonth.equals("1") || tempMonth.equals("3") || tempMonth.equals("5")
|| tempMonth.equals("7") || tempMonth.equals("8")
|| tempMonth.equals("10") || tempMonth.equals("12")) {
tempDay = "31";
}
if (tempMonth.equals("4") || tempMonth.equals("6") || tempMonth.equals("9")
|| tempMonth.equals("11")) {
tempDay = "30";
}
if (tempMonth.equals("2")) {
if (isLeapYear(yearNum)) {
tempDay = "29";
} else {
tempDay = "28";
}
}
// System.out.println("tempDay:" + tempDay);
String tempDate = tempYear + "-" + tempMonth + "-" + tempDay;
return SetDateFormat(tempDate, "yyyy-MM-dd");
}
}


自定义颜色类:
package transms.app._0all.util.providers;

import java.awt.Color;

public class Colors extends Color {

private static final long serialVersionUID = 3680677118390160469L;

public Colors(int rgb) {
super(rgb);
}

/**
* 淡黄
*/
public static final Color Khaki1 = new Color(255, 246, 143);

/**
* 浅蓝
*/
public static final Color PaleTurquoise1 = new Color(187, 255, 255);

/**
* 背景色
*/
public static final Color Ivory2 = new Color(238, 238, 224);

/**
* 火红
*/
public static final Color Firebrick1 = new Color(255, 48, 48);

/**
* 暗绿
*/
public static final Color Chartreuse3 = new Color(69, 139, 0);

/**
* 紫
*/
public static final Color Purple3 = new Color(125, 38, 205);

/**
* 橘红
*/
public static final Color OrangeRed = new Color(255, 69, 0);

/**
* 暗橙
*/
public static final Color DarkOrange1 = new Color(255, 127, 0);

/**
* 暗橄榄绿
*/
public static final Color DarkOliveGreen2 = new Color(188, 238, 104);

/**
* 淡红
*/
public static final Color LightSalmon = new Color(255, 160, 122);

/**
* 淡绿
*/
public static final Color PaleGreen = new Color(152, 251, 152);
}
电动汽车数据集:2025年3K+记录 真实电动汽车数据:特斯拉、宝马、日产车型,含2025年电池规格和销售数据 关于数据集 电动汽车数据集 这个合成数据集包含许多品牌和年份的电动汽车和插电式车型的记录,捕捉技术规格、性能、定价、制造来源、销售和安全相关属性。每一行代表由vehicle_ID标识的唯一车辆列表。 关键特性 覆盖范围:全球制造商和车型组合,包括纯电动汽车和插电式混合动力汽车。 范围:电池化学成分、容量、续航里程、充电标准和速度、价格、产地、自主水平、排放、安全等级、销售和保修。 时间跨度:模型跨度多年(包括传统和即将推出的)。 数据质量说明: 某些行可能缺少某些字段(空白)。 几个分类字段包含不同的、特定于供应商的值(例如,Charging_Type、Battery_Type)。 各列中的单位混合在一起;注意kWh、km、hr、USD、g/km和额定值。 列 列类型描述示例 Vehicle_ID整数每个车辆记录的唯一标识符。1 制造商分类汽车品牌或OEM。特斯拉 型号类别特定型号名称/变体。型号Y 与记录关联的年份整数模型。2024 电池_类型分类使用的电池化学/技术。磷酸铁锂 Battery_Capacity_kWh浮充电池标称容量,单位为千瓦时。75.0 Range_km整数表示充满电后的行驶里程(公里)。505 充电类型主要充电接口或功能。CCS、NACS、CHAdeMO、DCFC、V2G、V2H、V2L Charge_Time_hr浮动充电的大致时间(小时),上下文因充电方法而异。7.5 价格_USD浮动参考车辆价格(美元).85000.00 颜色类别主要外观颜色或饰面。午夜黑 制造国_制造类别车辆制造/组装的国家。美国 Autonomous_Level浮点自动化能力级别(例如0-5),可能包括子级别的小
内容概要:本文详细介绍了IEEE论文《Predefined-Time Sensorless Admittance Tracking Control for Teleoperation Systems With Error Constraint and Personalized Compliant Performance》的复现与分析。论文提出了一种预定义时间的无传感器导纳跟踪控制方案,适用于存在模型不确定性的遥操作系统。该方案通过具有可调刚度参数的导纳结构和预定义时间观测器(PTO),结合非奇异预定义时间终端滑模流形和预定义时间性能函数,实现了快速准确的导纳轨迹跟踪,并确保误差约束。文中详细展示了系统参数定义、EMG信号处理、预定义时间观测器、预定义时间控制器、可调刚度导纳模型及主仿真系统的代码实现。此外,还增加了动态刚度调节器、改进的广义动量观测器和安全约束模块,以增强系统的鲁棒性和安全性。 适合人群:具备一定自动化控制理论基础和编程能力的研究人员、工程师,尤其是从事机器人遥操作、人机交互等领域工作的专业人士。 使用场景及目标:①理解预定义时间控制理论及其在遥操作系统中的应用;②掌握无传感器力观测技术,减少系统复杂度;③学习如何利用肌电信号实现个性化顺应性能调整;④探索如何在保证误差约束的前提下提高系统的响应速度和精度。 阅读建议:本文内容涉及较多的数学推导和技术细节,建议读者先熟悉基本的控制理论和Python编程,重点理解各个模块的功能和相互关系。同时,可以通过运行提供的代码示例,加深对理论概念的理解,并根据自身需求调整参数进行实验验证。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值