形式
Java
投稿日時
2021-01-23 15:24
公開期間
無期限
  1. import java.awt.Color;
  2. import java.awt.Dimension;
  3. import java.awt.FlowLayout;
  4. import java.awt.Font;
  5. import java.awt.GridLayout;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.MouseAdapter;
  9. import java.awt.event.MouseEvent;
  10. import java.util.Calendar;
  11. import java.util.GregorianCalendar;
  12. import java.util.regex.Matcher;
  13. import java.util.regex.Pattern;
  14. import javax.swing.BoxLayout;
  15. import javax.swing.JButton;
  16. import javax.swing.JComponent;
  17. import javax.swing.JLabel;
  18. import javax.swing.JMenuItem;
  19. import javax.swing.JPanel;
  20. import javax.swing.JPopupMenu;
  21. import javax.swing.JSpinner;
  22. import javax.swing.JTextField;
  23. import javax.swing.SpinnerNumberModel;
  24. import javax.swing.SwingConstants;
  25. import javax.swing.border.Border;
  26. import javax.swing.border.LineBorder;
  27. import javax.swing.event.ChangeEvent;
  28. import javax.swing.event.ChangeListener;
  29. /*
  30. * カレンダー部品
  31. */
  32. public class JCalendar extends JPanel {
  33. /*******************************************************************************
  34. * 定数
  35. ******************************************************************************/
  36. private static final int DAY_FONT_SIZE = 14;
  37. private static final Dimension DAY_BUTTON_SIZE = new Dimension(30,25);
  38. private static final int YEAR_SPINNER_WIDTH = 85;
  39. private static final int MONTH_SPINNER_WIDTH = 70;
  40. private static final int YM_FONT_SIZE = 10;
  41. private static final int YM_BUTTON_WIDTH = 30;
  42. private static final int YM_LABEL_WIDTH = 100;
  43. private static final int YM_HEIGHT = 30;
  44. private static final int COLNUM = 7;
  45. private static final int ROWNUM = 6;
  46. private static final String[] WEEK_NAMES =
  47. new String[] {"日", "月", "火", "水", "木", "金", "土"};
  48. private static final Border BORDER_NORMAL = null;
  49. private static final Border BORDER_SELECTED = new LineBorder(Color.BLACK, 2);
  50. private static final String ESCKEYACTION = "JCalendar.ESCAPE";
  51. enum Style{
  52. Spinner,
  53. Button,
  54. };
  55. /*******************************************************************************
  56. * 部品
  57. ******************************************************************************/
  58. private JSpinner jSpinnerYear = null;
  59. private JSpinner jSpinnerMonth = null;
  60. private JButton jButtonYearMinus = null;
  61. private JButton jButtonMonthMinus = null;
  62. private JLabel jLabelYearMonth = null;
  63. private JButton jButtonMonthPlus = null;
  64. private JButton jButtonYearPlus = null;
  65. private JLabel[] jLabelWeeks = new JLabel[COLNUM];
  66. private JButton[][] jButtonDays = new JButton[ROWNUM][COLNUM];
  67. private Font fontNormal = null;
  68. private Font fontToday = null;
  69. private Font fontWeek = null;
  70. private Font fontYearMonth = null;
  71. private CalendarListener listener = null;
  72. private GregorianCalendar calSelDate = null;
  73. private GregorianCalendar calMinDate = null;
  74. private GregorianCalendar calMaxDate = null;
  75. private Style style = Style.Button;
  76. private boolean popupMenuEnabled = true;
  77. /*******************************************************************************
  78. * コンストラクタ
  79. ******************************************************************************/
  80. public JCalendar() {
  81. this(Style.Button, true);
  82. }
  83. public JCalendar(Style s, boolean b){
  84. style = s;
  85. popupMenuEnabled = b;
  86. setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
  87. createFont();
  88. add(createYearMonthPanel());
  89. add(createDayPanel());
  90. setSelectedDate((GregorianCalendar)null);
  91. }
  92. /*******************************************************************************
  93. * 公開メソッド
  94. ******************************************************************************/
  95. /*
  96. * リスナーを登録する
  97. */
  98. public void setListener(CalendarListener l){
  99. listener = l;
  100. }
  101. /*
  102. * 選択日をYYYY/MM/DD形式で指定する
  103. */
  104. public void setSelectedDate(String date){
  105. setSelectedDate(getCalendar(date));
  106. }
  107. /*
  108. * 選択日をGregorianCalendarクラスで指定する
  109. */
  110. public void setSelectedDate(GregorianCalendar cal){
  111. calSelDate = cal;
  112. if (cal == null)
  113. cal = new GregorianCalendar();
  114. setYearMonth(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1);
  115. updateDayButtons();
  116. }
  117. /*
  118. * 有効な最小日をYYYY/MM/DD形式で指定する
  119. */
  120. public void setMinDate(String date){
  121. setMinDate(getCalendar(date));
  122. }
  123. /*
  124. * 有効な最小日をGregorianCalendarクラスで指定する
  125. */
  126. public void setMinDate(GregorianCalendar cal){
  127. calMinDate = cal;
  128. }
  129. /*
  130. * 有効な最大日をYYYY/MM/DD形式で指定する
  131. */
  132. public void setMaxDate(String date){
  133. setMaxDate(getCalendar(date));
  134. }
  135. /*
  136. * 有効な最大日をGregorianCalendarクラスで指定する
  137. */
  138. public void setMaxDate(GregorianCalendar cal){
  139. calMaxDate = cal;
  140. }
  141. /*
  142. * キーボードフォーカスを取得する
  143. *
  144. * (非 Javadoc)
  145. * @see javax.swing.JComponent#requestFocus()
  146. */
  147. @Override
  148. public void requestFocus(){
  149. if (style == Style.Spinner){
  150. JTextField tm = ((JSpinner.DefaultEditor)jSpinnerMonth.getEditor()).getTextField();
  151. tm.requestFocus();
  152. }
  153. }
  154. /*******************************************************************************
  155. * コンポーネント
  156. ******************************************************************************/
  157. /*
  158. * フォントを生成する
  159. */
  160. private void createFont(){
  161. JButton b = new JButton();
  162. Font font = b.getFont();
  163. fontNormal = font.deriveFont(font.getStyle() & ~Font.BOLD, DAY_FONT_SIZE);
  164. fontToday = font.deriveFont(font.getStyle() | Font.BOLD, DAY_FONT_SIZE);
  165. fontWeek = font.deriveFont(font.getStyle() | Font.BOLD, DAY_FONT_SIZE);
  166. fontYearMonth = font.deriveFont(font.getStyle() | Font.BOLD, YM_FONT_SIZE);
  167. }
  168. /*
  169. * 年月選択用パネル
  170. */
  171. private JPanel createYearMonthPanel(){
  172. JPanel panel = new JPanel();
  173. if (style == Style.Spinner){
  174. FlowLayout layout = new FlowLayout();
  175. layout.setHgap(10);
  176. layout.setVgap(0);
  177. panel.setLayout(layout);
  178. jSpinnerYear = createYearSpinner();
  179. jSpinnerMonth = createMonthSpinner();
  180. panel.add(jSpinnerYear);
  181. panel.add(jSpinnerMonth);
  182. }
  183. else{
  184. FlowLayout layout = new FlowLayout();
  185. layout.setHgap(0);
  186. layout.setVgap(0);
  187. panel.setLayout(layout);
  188. jButtonYearMinus = createYMButton("<<", "前年へ移動", ma_yearMinus);
  189. jButtonMonthMinus = createYMButton("<", "前月へ移動", ma_monthMinus);
  190. jLabelYearMonth = createYMLabel();
  191. jButtonMonthPlus = createYMButton(">", "翌月へ移動", ma_monthPlus);
  192. jButtonYearPlus = createYMButton(">>", "翌年へ移動", ma_yearPlus);
  193. panel.add(jButtonYearMinus);
  194. panel.add(jButtonMonthMinus);
  195. panel.add(jLabelYearMonth);
  196. panel.add(jButtonMonthPlus);
  197. panel.add(jButtonYearPlus);
  198. }
  199. return panel;
  200. }
  201. /*
  202. * 年選択用スピナーを作成する
  203. */
  204. private JSpinner createYearSpinner(){
  205. JSpinner spinner = new JSpinner();
  206. spinner.setModel(new SpinnerNumberModel(2021, 2000, 2999, 1 ));
  207. spinner.setEditor(new JSpinner.NumberEditor(spinner, "#年"));
  208. spinner.addChangeListener(cl_yearChanged);
  209. Dimension dy = spinner.getPreferredSize();
  210. dy.width = YEAR_SPINNER_WIDTH;
  211. spinner.setPreferredSize(dy);
  212. return spinner;
  213. }
  214. /*
  215. * 月選択用スピナーを作成する
  216. */
  217. private JSpinner createMonthSpinner() {
  218. JSpinner spinner = new JSpinner();
  219. spinner.setModel(new SpinnerNumberModel(1, 0, 13, 1 ));
  220. spinner.setEditor(new JSpinner.NumberEditor(spinner, "#月"));
  221. spinner.addChangeListener(cl_monthChanged);
  222. Dimension dm = jSpinnerMonth.getPreferredSize();
  223. dm.width = MONTH_SPINNER_WIDTH;
  224. spinner.setPreferredSize(dm);
  225. return spinner;
  226. }
  227. /*
  228. * 年月用ボタンを作成する
  229. */
  230. private JButton createYMButton(String text, String tooltip, MouseAdapter ma){
  231. JButton button = new JButton();
  232. button.setText(text);
  233. button.setPreferredSize(new Dimension(YM_BUTTON_WIDTH, YM_HEIGHT));
  234. button.setFont(fontWeek);
  235. button.setFont(fontYearMonth);
  236. button.setToolTipText(tooltip + (popupMenuEnabled ? "(右クリックでメニュー)" : ""));
  237. button.setBorderPainted(false);
  238. button.setFocusPainted(false);
  239. button.setContentAreaFilled(false);
  240. button.addMouseListener(ma_flatButton);
  241. button.addMouseListener(ma);
  242. return button;
  243. }
  244. /*
  245. * 年月用ラベルを作成する
  246. */
  247. private JLabel createYMLabel(){
  248. JLabel label = new JLabel();
  249. label.setBackground(Color.LIGHT_GRAY);
  250. label.setPreferredSize(new Dimension(YM_LABEL_WIDTH, YM_HEIGHT));
  251. label.setHorizontalAlignment(JLabel.CENTER);
  252. label.setToolTipText(popupMenuEnabled ? "(右クリックでメニュー)" : "");
  253. label.addMouseListener(ma_ymLabel);
  254. return label;
  255. }
  256. /*
  257. * カレンダーパネル
  258. */
  259. private JPanel createDayPanel(){
  260. JPanel panel = new JPanel();
  261. GridLayout layout = new GridLayout(ROWNUM+1, COLNUM);
  262. layout.setHgap(1);
  263. layout.setVgap(1);
  264. panel.setLayout(layout);
  265. for( int c=0; c<COLNUM; c++) {
  266. JLabel label = createWeekLabel(c);
  267. panel.add(label);
  268. jLabelWeeks[c] = label;
  269. }
  270. JCalendar cal = this;
  271. ActionListener al_daySelected = new ActionListener(){
  272. @Override
  273. public void actionPerformed(ActionEvent e) {
  274. JButton button = (JButton) e.getSource();
  275. String date = String.format("%04d/%02d/%02d",
  276. getSelectedYear(),
  277. getSelectedMonth(),
  278. Integer.valueOf(button.getText()));
  279. if (listener != null)
  280. listener.notifyDateChange(cal, date);
  281. }
  282. };
  283. for( int r=0; r<ROWNUM; r++) {
  284. for( int c=0; c<COLNUM; c++) {
  285. JButton button = createDayButton(c, al_daySelected);
  286. panel.add(button);
  287. jButtonDays[r][c] = button;
  288. }
  289. }
  290. return panel;
  291. }
  292. /*
  293. * 曜日用ラベルを作成する
  294. */
  295. private JLabel createWeekLabel(int c){
  296. JLabel label = new JLabel(WEEK_NAMES[c]);
  297. label.setHorizontalAlignment(SwingConstants.CENTER);
  298. label.setVerticalAlignment(SwingConstants.CENTER);
  299. label.setPreferredSize(DAY_BUTTON_SIZE);
  300. label.setOpaque(true);
  301. label.setBorder(null);
  302. label.setForeground(c == 0 ? Color.RED : c == 6 ? Color.BLUE : Color.BLACK);
  303. label.setFont(fontWeek);
  304. return label;
  305. }
  306. /*
  307. * 日付用ボタンを作成する
  308. */
  309. private JButton createDayButton(int c, ActionListener al){
  310. JButton button = new JButton();
  311. button.setHorizontalAlignment(SwingConstants.CENTER);
  312. button.setVerticalAlignment(SwingConstants.CENTER);
  313. button.setOpaque(true);
  314. button.setPreferredSize(DAY_BUTTON_SIZE);
  315. button.setForeground(c == 0 ? Color.RED : c == 6 ? Color.BLUE : Color.BLACK);
  316. button.setBorderPainted(false);
  317. button.setFocusPainted(false);
  318. button.setContentAreaFilled(false);
  319. button.addMouseListener(ma_flatButton);
  320. button.addActionListener(al);
  321. return button;
  322. }
  323. /*******************************************************************************
  324. * リスナー
  325. ******************************************************************************/
  326. /*
  327. * 年の選択変更
  328. */
  329. private ChangeListener cl_yearChanged = new ChangeListener(){
  330. public void stateChanged(ChangeEvent e) {
  331. updateDayButtons();
  332. }
  333. };
  334. /*
  335. * 月の選択変更
  336. */
  337. private ChangeListener cl_monthChanged = new ChangeListener(){
  338. public void stateChanged(ChangeEvent e) {
  339. int month = getSelectedMonth();
  340. if (month >= 13){
  341. jSpinnerYear.setValue((int)jSpinnerYear.getValue()+1);
  342. jSpinnerMonth.setValue(1);
  343. }
  344. else if (month <= 0){
  345. jSpinnerYear.setValue((int)jSpinnerYear.getValue()-1);
  346. jSpinnerMonth.setValue(12);
  347. }
  348. updateDayButtons();
  349. }
  350. };
  351. /*
  352. * 前年へ
  353. */
  354. private MouseAdapter ma_yearMinus = new MouseAdapter(){
  355. @Override
  356. public void mouseClicked(MouseEvent e) {
  357. setYearMonth(getSelectedYear()-1, getSelectedMonth());
  358. updateDayButtons();
  359. }
  360. };
  361. /*
  362. * 前月へ
  363. */
  364. private MouseAdapter ma_monthMinus = new MouseAdapter(){
  365. @Override
  366. public void mouseClicked(MouseEvent e) {
  367. int year = getSelectedYear();
  368. int month = getSelectedMonth()-1;
  369. if (month <= 0){
  370. year --;
  371. month = 12;
  372. }
  373. setYearMonth(year, month);
  374. updateDayButtons();
  375. }
  376. };
  377. /*
  378. * 翌月へ
  379. */
  380. private MouseAdapter ma_monthPlus = new MouseAdapter(){
  381. @Override
  382. public void mouseClicked(MouseEvent e) {
  383. int year = getSelectedYear();
  384. int month = getSelectedMonth()+1;
  385. if (month >= 13){
  386. year ++;
  387. month = 1;
  388. }
  389. setYearMonth(year, month);
  390. updateDayButtons();
  391. }
  392. };
  393. /*
  394. * 翌年へ
  395. */
  396. private MouseAdapter ma_yearPlus = new MouseAdapter(){
  397. @Override
  398. public void mouseClicked(MouseEvent e) {
  399. setYearMonth(getSelectedYear()+1, getSelectedMonth());
  400. updateDayButtons();
  401. }
  402. };
  403. /*
  404. * 年月ラベルのマウスリスナー
  405. */
  406. MouseAdapter ma_ymLabel = new MouseAdapter(){
  407. @Override
  408. public void mousePressed(MouseEvent e) {
  409. if (e.getButton() == MouseEvent.BUTTON3){
  410. JLabel label = (JLabel)e.getSource();
  411. Dimension sz = label.getSize();
  412. if (e.getX() < sz.width/2){
  413. showYearMenu(label, e.getX(), e.getY());
  414. }
  415. else{
  416. showMonthMenu(label, e.getX(), e.getY());
  417. }
  418. }
  419. }
  420. };
  421. /*
  422. * フラットボタンのマウスリスナー
  423. */
  424. MouseAdapter ma_flatButton = new MouseAdapter(){
  425. @Override
  426. public void mousePressed(MouseEvent e) {
  427. JButton button = (JButton) e.getSource();
  428. if (e.getButton() == MouseEvent.BUTTON3){
  429. if (button == jButtonYearMinus || button == jButtonYearPlus)
  430. showYearMenu(button, e.getX(), e.getY());
  431. else if (button == jButtonMonthMinus || button == jButtonMonthPlus)
  432. showMonthMenu(button, e.getX(), e.getY());
  433. }
  434. }
  435. @Override
  436. public void mouseEntered(MouseEvent e) {
  437. JButton button = (JButton) e.getSource();
  438. if (button.isEnabled())
  439. button.setContentAreaFilled(true);
  440. }
  441. @Override
  442. public void mouseExited(MouseEvent e) {
  443. JButton button = (JButton) e.getSource();
  444. if (button.isEnabled())
  445. button.setContentAreaFilled(false);
  446. }
  447. };
  448. /*******************************************************************************
  449. * 内部関数
  450. ******************************************************************************/
  451. /*
  452. * カレンダーを更新する
  453. */
  454. private void updateDayButtons(){
  455. int year = getSelectedYear();
  456. int month = getSelectedMonth();
  457. GregorianCalendar cal = new GregorianCalendar();
  458. cal.set(Calendar.YEAR, year);
  459. cal.set(Calendar.MONTH, month-1);
  460. cal.set(Calendar.DATE, 1);
  461. int dow0 = cal.get(Calendar.DAY_OF_WEEK);
  462. clearDayButtons();
  463. int dayNum = cal.getActualMaximum(Calendar.DATE);
  464. for( int day=1; day<=dayNum; day++ ) {
  465. int no = day + dow0 - 2;
  466. JButton button = jButtonDays[no/COLNUM][no%COLNUM];
  467. button.setText(Integer.toString(day));
  468. }
  469. for( int r=0; r<ROWNUM; r++) {
  470. for( int c=0; c<COLNUM; c++) {
  471. JButton button = jButtonDays[r][c];
  472. int day = r*COLNUM + c + 2 - dow0;
  473. boolean valid = isValidDate(year, month, day);
  474. boolean selected = isSelectedDate(year, month, day);
  475. boolean today = isTodayDate(year, month, day);
  476. button.setFont(today ? fontToday : fontNormal);
  477. button.setBorder(selected ? BORDER_SELECTED : BORDER_NORMAL);
  478. button.setVisible( button.getText().length() != 0 );
  479. button.setEnabled(valid);
  480. button.setBorderPainted(selected);
  481. button.setContentAreaFilled(!valid);
  482. }
  483. }
  484. }
  485. /*
  486. * 日付ボタンのテキストをクリアする
  487. */
  488. private void clearDayButtons(){
  489. for( int r=0; r<ROWNUM; r++) {
  490. for( int c=0; c<COLNUM; c++) {
  491. JButton button = jButtonDays[r][c];
  492. button.setText("");
  493. }
  494. }
  495. }
  496. /*
  497. * 西暦年選択メニューを表示する
  498. */
  499. private void showYearMenu(JComponent comp, int x, int y){
  500. if (!popupMenuEnabled)
  501. return;
  502. // メニューの作成
  503. JPopupMenu menu = new JPopupMenu();
  504. ActionListener al = new ActionListener(){
  505. @Override
  506. public void actionPerformed(ActionEvent e) {
  507. JMenuItem item = (JMenuItem) e.getSource();
  508. Matcher ma = Pattern.compile("(\\d+)年").matcher(item.getText());
  509. if (ma.find()){
  510. setYearMonth(Integer.parseInt(ma.group(1)), getSelectedMonth());
  511. updateDayButtons();
  512. }
  513. }
  514. };
  515. Calendar cal = new GregorianCalendar();
  516. int yearSel = getSelectedYear();
  517. for (int year=yearSel-6; year<=yearSel+6; year++){
  518. JMenuItem item = new JMenuItem(year + "年");
  519. if (year == cal.get(Calendar.YEAR)){
  520. Font f = item.getFont();
  521. item.setFont(f.deriveFont(f.getStyle()|Font.BOLD));
  522. }
  523. item.addActionListener(al);
  524. menu.add(item);
  525. }
  526. menu.show(comp, x, y);
  527. }
  528. /*
  529. * 月選択メニューを表示する
  530. */
  531. private void showMonthMenu(JComponent comp, int x, int y){
  532. if (!popupMenuEnabled)
  533. return;
  534. // メニューの作成
  535. JPopupMenu menu = new JPopupMenu();
  536. ActionListener al = new ActionListener(){
  537. @Override
  538. public void actionPerformed(ActionEvent e) {
  539. JMenuItem item = (JMenuItem) e.getSource();
  540. Matcher ma = Pattern.compile("(\\d+)月").matcher(item.getText());
  541. if (ma.find()){
  542. setYearMonth(getSelectedYear(), Integer.parseInt(ma.group(1)));
  543. updateDayButtons();
  544. }
  545. }
  546. };
  547. Calendar cal = new GregorianCalendar();
  548. int yearSel = getSelectedYear();
  549. for (int month=1; month<=12; month++){
  550. JMenuItem item = new JMenuItem(month + "月");
  551. if (yearSel == cal.get(Calendar.YEAR) && month == cal.get(Calendar.MONTH)+1){
  552. Font f = item.getFont();
  553. item.setFont(f.deriveFont(f.getStyle()|Font.BOLD));
  554. }
  555. item.addActionListener(al);
  556. menu.add(item);
  557. }
  558. menu.show(comp, x, y);
  559. }
  560. /*
  561. * 選択中の年月を部品に反映する
  562. */
  563. private void setYearMonth(int year, int month){
  564. if (style == Style.Spinner){
  565. jSpinnerYear.setValue(year);
  566. jSpinnerMonth.setValue(month);
  567. }
  568. else{
  569. jLabelYearMonth.setText(String.format("%d年%d月", year, month));
  570. Calendar cal = new GregorianCalendar();
  571. Font f = jLabelYearMonth.getFont();
  572. if (year == cal.get(Calendar.YEAR) && month == cal.get(Calendar.MONTH)+1){
  573. jLabelYearMonth.setFont(f.deriveFont(f.getStyle()|Font.BOLD));
  574. }
  575. else{
  576. jLabelYearMonth.setFont(f.deriveFont(f.getStyle()&~Font.BOLD));
  577. }
  578. }
  579. }
  580. /*
  581. * 選択中の西暦年を取得する
  582. */
  583. private int getSelectedYear(){
  584. if (style == Style.Spinner)
  585. return (int)jSpinnerYear.getValue();
  586. else{
  587. Matcher ma = Pattern.compile("(\\d+)年(\\d+)月").matcher(jLabelYearMonth.getText());
  588. return ma.find() ? Integer.parseInt(ma.group(1)) : 2000;
  589. }
  590. }
  591. /*
  592. * 選択中の月を取得する
  593. */
  594. private int getSelectedMonth(){
  595. if (style == Style.Spinner)
  596. return (int)jSpinnerMonth.getValue();
  597. else{
  598. Matcher ma = Pattern.compile("(\\d+)年(\\d+)月").matcher(jLabelYearMonth.getText());
  599. return ma.find() ? Integer.parseInt(ma.group(2)) : 1;
  600. }
  601. }
  602. /*
  603. * 指定された日が選択日かどうかを取得する
  604. */
  605. private boolean isSelectedDate(int year, int month, int day){
  606. if (calSelDate == null)
  607. return false;
  608. return
  609. calSelDate.get(Calendar.YEAR) == year &&
  610. calSelDate.get(Calendar.MONTH) == month-1 &&
  611. calSelDate.get(Calendar.DATE) == day;
  612. }
  613. /*
  614. * 指定された日が当日かどうかを取得する
  615. */
  616. private boolean isTodayDate(int year, int month, int day){
  617. Calendar cal = new GregorianCalendar();
  618. return
  619. cal.get(Calendar.YEAR) == year &&
  620. cal.get(Calendar.MONTH) == month-1 &&
  621. cal.get(Calendar.DATE) == day;
  622. }
  623. /*
  624. * 指定された日が有効かどうかを返す
  625. */
  626. private boolean isValidDate(int year, int month, int day){
  627. GregorianCalendar cal = new GregorianCalendar(year, month-1, day);
  628. long time = cal.getTimeInMillis();
  629. if (calMinDate != null){
  630. long timeMin = calMinDate.getTimeInMillis();
  631. if (time < timeMin)
  632. return false;
  633. }
  634. if (calMaxDate != null){
  635. long timeMax = calMaxDate.getTimeInMillis();
  636. if (time > timeMax)
  637. return false;
  638. }
  639. return true;
  640. }
  641. /*
  642. * YYYY/MM/DD形式からGregorianCalendarクラスを取得する
  643. */
  644. public static GregorianCalendar getCalendar(String date) {
  645. Matcher ma = Pattern.compile("^(\\d{4})/(\\d{1,2})/(\\d{1,2})$").matcher(date);
  646. if ( ! ma.find()) {
  647. return null;
  648. }
  649. return new GregorianCalendar(
  650. Integer.valueOf(ma.group(1)),
  651. Integer.valueOf(ma.group(2))-1,
  652. Integer.valueOf(ma.group(3)),
  653. 0,
  654. 0,
  655. 0);
  656. }
  657. }
ダウンロード 印刷用表示

このコピペの URL

JavaScript での埋め込み

iframe での埋め込み

元のテキスト