⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datefield.java

📁 j2me is based on j2mepolish, client & server for mobile application. menu sample
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
					//# }
					//# buffer.append( ++month )
				          //# .append("-");
					//# if (day < 10) {
						//# buffer.append( '0' );
					//# }
					//# buffer.append( day )
						  //# .append("-");
					//# if (year < 10) {
						//# buffer.append( "000");
					//# } else if (year < 100) {
						//# buffer.append( "00");
					//# } else if (year < 1000) {
						//# buffer.append( "0");
					//# }
					//# buffer.append( year );
				//#elif polish.DateFormat == de
					//# if (day < 10) {
						//# buffer.append( '0' );
					//# }
					//# buffer.append( day )
						  //# .append(".");
					//# if (month < 9) {
						//# buffer.append('0');
					//# }
					//# buffer.append( ++month )
				          //# .append(".");
					//# if (year < 10) {
						//# buffer.append( "000");
					//# } else if (year < 100) {
						//# buffer.append( "00");
					//# } else if (year < 1000) {
						//# buffer.append( "0");
					//# }
					//# buffer.append( year );
				//#elif polish.DateFormat == fr
					//# if (day < 10) {
						//# buffer.append( '0' );
					//# }
					//# buffer.append( day )
						//# .append("/");
					//# if (month < 9) {
						//# buffer.append('0');
					//# }
					//# buffer.append( ++month )
					    //# .append("/");
					//# if (year < 10) {
						//# buffer.append( "000");
					//# } else if (year < 100) {
						//# buffer.append( "00");
					//# } else if (year < 1000) {
						//# buffer.append( "0");
					//# }
					//# buffer.append( year );
				//#elif polish.DateFormat == mdy
					if (month < 9) {
						buffer.append('0');
					}
					buffer.append( ++month )
					//#if polish.DateFormatSeparator:defined
.append("-");
					//#else
					        //# .append("-");
					//#endif
					if (day < 10) {
						buffer.append( '0' );
					}
					buffer.append( day )
					//#if polish.DateFormatSeparator:defined
.append("-");
					//#else
					        //# .append("-");
					//#endif
					if (year < 10) {
						buffer.append( "000");
					} else if (year < 100) {
						buffer.append( "00");
					} else if (year < 1000) {
						buffer.append( "0");
					}
					buffer.append( year );
				//#elif polish.DateFormat == dmy
					//# if (day < 10) {
						//# buffer.append( '0' );
					//# }
					//# buffer.append( day )
					//#if polish.DateFormatSeparator:defined
						//#= .append("${polish.DateFormatSeparator}");
					//#else
					        //# .append("-");
					//#endif
					//# if (month < 9) {
						//# buffer.append('0');
					//# }
					//# buffer.append( ++month )
					//#if polish.DateFormatSeparator:defined
						//#= .append("${polish.DateFormatSeparator}");
					//#else
					        //# .append("-");
					//#endif
					//# if (year < 10) {
						//# buffer.append( "000");
					//# } else if (year < 100) {
						//# buffer.append( "00");
					//# } else if (year < 1000) {
						//# buffer.append( "0");
					//# }
					//# buffer.append( year );
				//#else
					//# // default to YMD
					//# if (year < 10) {
						//# buffer.append( "000");
					//# } else if (year < 100) {
						//# buffer.append( "00");
					//# } else if (year < 1000) {
						//# buffer.append( "0");
					//# }
					//# buffer.append( year )
					//#if polish.DateFormatSeparator:defined
						//#= .append("${polish.DateFormatSeparator}");
					//#else
					        //# .append("-");
					//#endif
					//# if (month < 9) {
						//# buffer.append('0');
					//# }
					//# buffer.append( ++month )
					//#if polish.DateFormatSeparator:defined
						//#= .append("${polish.DateFormatSeparator}");
					//#else
					        //# .append("-");
					//#endif
					//# if (day < 10) {
						//# buffer.append( '0' );
					//# }
					//# buffer.append( day );
				//#endif
				if  (this.inputMode == DATE_TIME) {
					buffer.append(' ');
				}
			}
			if ((this.inputMode == TIME) || (this.inputMode == DATE_TIME)) {
				int hour = this.calendar.get( Calendar.HOUR_OF_DAY );
				if (hour < 10) {
					buffer.append('0');
				}
				buffer.append( hour )
				      .append(':');
				int minute = this.calendar.get( Calendar.MINUTE );
				if (minute < 10) {
					buffer.append('0');
				}
				buffer.append( minute );
			}
			this.text = buffer.toString();
		} // date != null
		if (this.isInitialized) {
			this.isInitialized = false;
			repaint();
		}
	}

	/**
	 * Gets input mode for this date field. Valid input modes are
	 * <code>DATE</code>, <code>TIME</code> and <code>DATE_TIME</code>.
	 * 
	 * @return input mode of this field
	 * @see #setInputMode(int)
	 */
	public int getInputMode()
	{
		return this.inputMode;
	}

	/**
	 * Set input mode for this date field. Valid input modes are
	 * <code>DATE</code>, <code>TIME</code> and <code>DATE_TIME</code>.
	 * 
	 * @param mode the input mode, must be one of DATE, TIME or DATE_TIME
	 * @throws IllegalArgumentException if an invalid value is specified
	 * @see #getInputMode()
	 */
	public void setInputMode(int mode)
	{
		//#if polish.blackberry
			//# if (this.blackberryDateField != null && mode != this.inputMode) {
				//# this.blackberryDateField.setInputMode( mode );
			//# }
		//#endif
		this.inputMode = mode;
		//#if !tmp.directInput
		if (this.midpDateField != null) {
			this.midpDateField.setInputMode(mode);
		}
		//#endif
		setDate( this.date ); 
	}

	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#paint(int, int, javax.microedition.lcdui.Graphics)
	 */
	public void paintContent(int x, int y, int leftBorder, int rightBorder, Graphics g) {
		//#if polish.blackberry
	    	//# if (this.isFocused && !StyleSheet.currentScreen.isMenuOpened() ) {
				//# this.blackberryDateField.setPaintPosition( x, y );
			//# } else {
				//# super.paintContent(x, y, leftBorder, rightBorder, g);
			//# }
		//#else
	    	super.paintContent(x, y, leftBorder, rightBorder, g);
		//#endif
		//#if tmp.directInput && !polish.blackberry
			//# if ( this.isFocused ) {
				//#if polish.css.font-bitmap
					//# if (this.bitMapFontViewer != null) {
						//# //System.out.println("this.editIndex="+ this.editIndex );
						//#ifdef polish.css.text-horizontal-adjustment
							//# x += this.textHorizontalAdjustment;
						//#endif
						//# if (this.isLayoutCenter) {
							//# x = leftBorder + (rightBorder - leftBorder)/2 - this.bitMapFontViewer.getWidth()/2;
						//# } else if (this.isLayoutRight) {
							//# x = rightBorder - this.bitMapFontViewer.getWidth();
						//# }
						//# g.setColor( this.textComplementColor );
						//# g.fillRect( x + this.caretX - 1, y  - 1, this.caretWidth + 1, this.fontHeight + 1 );
						//# BitMapFontViewer viewer;
						//# if (this.showCaret && (viewer = this.caretViewer) != null) {
							//# //System.out.println("caretX=" + this.caretX + ", x=" + x);
							//# viewer.paint(x + this.caretX, y, g);
						//# }
					//# } else {
				//#endif
						//# String head = this.text.substring( 0, this.editIndex );
						//# int headWidth = this.font.stringWidth( head );
						//# char editChar = this.text.charAt( this.editIndex );
						//# int editWidth = this.font.charWidth( editChar );
						//# if ( this.isLayoutCenter ) {
							//# int centerX = leftBorder + (rightBorder - leftBorder) / 2;
							//#ifdef polish.css.text-horizontal-adjustment
								//# centerX += this.textHorizontalAdjustment;
							//#endif
							//# int completeWidth = this.font.stringWidth( this.text );
							//# x = centerX - ( completeWidth / 2 );
						//# } else if ( this.isLayoutRight ) {
							//# int completeWidth = this.font.stringWidth( this.text );
							//# x = rightBorder - completeWidth;					
						//# }
						//# g.fillRect( x + headWidth - 1, y  - 1, editWidth + 1, this.font.getHeight() );
//# 						
						//# if (this.showCaret) {
							//# g.setColor( this.textComplementColor );
							//# g.drawChar( editChar, x + headWidth, y, Graphics.TOP | Graphics.LEFT );
						//# }
				//#if polish.css.font-bitmap
					//# }
				//#endif
			//# }
		//#elif !polish.blackberry
			if (this.showCaret) {
				if (this.text == null) {
					// when the text is null the appropriate font and color
					// might not have been set, so set them now:
					g.setFont( this.font );
					g.setColor( this.textColor );
				}
				if (this.isLayoutCenter) {
					int centerX = leftBorder 
						+ (rightBorder - leftBorder) / 2 
						+ this.originalWidth / 2
						+ 2;
					if (this.originalHeight > 0) {
						y += this.originalHeight - this.font.getHeight();
					}
					g.drawChar('|', centerX, y, Graphics.TOP | Graphics.LEFT );
				} else {
					x += this.originalWidth + 2;
					if (this.originalHeight > 0) {
						y += this.originalHeight - this.font.getHeight();
					}
					g.drawChar('|', x, y, Graphics.TOP | Graphics.LEFT );
				}
			}
		//#endif
	}


	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#initItem()
	 */
	protected void initContent(int firstLineWidth, int lineWidth) {
		if (this.date == null) {
			setDate( null );
		}
		// init StringItem:
		super.initContent(firstLineWidth, lineWidth);
		this.originalWidth = this.contentWidth;
		this.originalHeight = this.contentHeight;
		if (this.contentWidth < this.minimumWidth) {
			this.contentWidth = this.minimumWidth;
		} 
		if (this.contentHeight < this.minimumHeight) {
			this.contentHeight = this.minimumHeight;
		} else  if (this.contentHeight < this.font.getHeight()) {
			this.contentHeight = this.font.getHeight();
			this.originalHeight = this.contentHeight;
		}
		//#if polish.css.font-bitmap && tmp.directInput
			//# if (this.bitMapFontViewer != null) {			
				//# if (this.caretViewer == null) {
					//# char editChar = this.text.charAt( 0 );
					//# BitMapFontViewer viewer = this.bitMapFont.getViewer( "" + editChar );
					//# this.caretViewer = viewer;
					//# this.caretWidth = viewer.getWidth();
					//# this.caretX = 0;
					//# this.fontHeight = viewer.getFontHeight();
				//# }
			//# }
		//#endif
		//#if polish.blackberry
			//# if (!this.isFocused) {
				//# return;
			//# }
			//# this.blackberryDateField.setFont( this.font, this.textColor );
			//# // allow extra pixels for the cursor:
			//# this.blackberryDateField.layout( this.contentWidth+8, this.contentHeight );
			//# //System.out.println("TextField: editField.getText()="+ this.editField.getText() );
			//# XYRect rect = this.blackberryDateField.getExtent();
			//# this.contentWidth = rect.width;
			//# this.contentHeight = rect.height;
		//#endif			
	}

	//#ifdef polish.useDynamicStyles
	//# /* (non-Javadoc)
	 //# * @see de.enough.polish.ui.Item#getCssSelector()
	 //# */
	//# protected String createCssSelector() {
		//# return "datefield";
	//# }
	//#endif

	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#setStyle(de.enough.polish.ui.Style)
	 */
	public void setStyle(Style style) {
		super.setStyle(style);
		//#ifdef polish.css.datefield-width
			//# Integer width = style.getIntProperty(33);
			//# if (width != null) {
				//# this.minimumWidth = width.intValue();
			//# }
		//#endif
		//#ifdef polish.css.datefield-height
			//# Integer height = style.getIntProperty(34);
			//# if (height != null) {
				//# this.minimumHeight = height.intValue();
			//# }
		//#endif
		//#if tmp.directInput
			//# this.textComplementColor = 
				//# ((255 - (( 0xFF0000 & this.textColor ) >> 16)) << 16)
				//# | ((255 - (( 0x00FF00 & this.textColor ) >> 8)) << 8)
				//# | (255 - ( 0x0000FF & this.textColor ) );				
		//#endif
	}
	
	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#animate()
	 */
	public boolean animate() {
		long currentTime = System.currentTimeMillis();
		if ( currentTime - this.lastCaretSwitch > 500 ) {
			this.lastCaretSwitch = currentTime;
			this.showCaret = ! this.showCaret;
			return true;
		} else {
			return false;
		}
	}
	
	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#defocus(de.enough.polish.ui.Style)
	 */
	protected void defocus(Style originalStyle) {
		super.defocus(originalStyle);
		this.showCaret = false;
		//#if polish.blackberry
			//# this.blackberryDateField.focusRemove();
		//#endif
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -