gaugelfimpl.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 1,445 行 · 第 1/4 页
JAVA
1,445 行
"GaugeLFImpl: uCallTraverse, dir=" +dir); break; } break; // Gauge increases top to bottom, vertically case Graphics.BOTTOM: switch (dir) { case Canvas.LEFT: intTraverse = initialTraverse; if (initialTraverse) { focusBtn = I_DEC_BTN; } break; case Canvas.RIGHT: intTraverse = initialTraverse; if (initialTraverse) { focusBtn = I_INC_BTN; } break; case Canvas.UP: if (initialTraverse) { intTraverse = true; focusBtn = I_INC_BTN; } else { intTraverse = (focusBtn != I_DEC_BTN); focusBtn = I_DEC_BTN; } break; case Canvas.DOWN: if (initialTraverse) { intTraverse = true; focusBtn = I_DEC_BTN; } else { intTraverse = (focusBtn != I_INC_BTN); focusBtn = I_INC_BTN; } break; default: Logging.report(Logging.ERROR, LogChannels.LC_HIGHUI, "GaugeLFImpl: uCallTraverse, dir=" +dir); break; } break; default: Logging.report(Logging.ERROR, LogChannels.LC_HIGHUI, "GaugeLFImpl: uCallTraverse," + "GaugeSkin.ORIENTATION=" + GaugeSkin.ORIENTATION); break; } } switch (focusBtn) { case I_INC_BTN: visRect[X] = GaugeSkin.INC_BTN_X; visRect[Y] = GaugeSkin.INC_BTN_Y; if (GaugeSkin.IMAGE_INC_BTN != null) { visRect[WIDTH] = GaugeSkin.IMAGE_INC_BTN.getWidth(); visRect[HEIGHT] = GaugeSkin.IMAGE_INC_BTN.getHeight(); } else { visRect[WIDTH] = 15; visRect[HEIGHT] = 15; } break; case I_DEC_BTN: visRect[X] = GaugeSkin.DEC_BTN_X; visRect[Y] = GaugeSkin.DEC_BTN_Y; if (GaugeSkin.IMAGE_DEC_BTN != null) { visRect[WIDTH] = GaugeSkin.IMAGE_DEC_BTN.getWidth(); visRect[HEIGHT] = GaugeSkin.IMAGE_DEC_BTN.getHeight(); } else { visRect[WIDTH] = 15; visRect[HEIGHT] = 15; } break; default: Logging.report(Logging.ERROR, LogChannels.LC_HIGHUI, "GaugeLFImpl: uCallTraverse, focusBtn=" +focusBtn); break; } // Gauge should always return true on at least the initial // traverse, or any internal traverse between the two buttons if (initialTraverse || intTraverse) { initialTraverse = false; uRequestPaint(); return true; } return false; } /** * Called by the system to indicate traversal has left this Item. */ void uCallTraverseOut() { super.uCallTraverseOut(); initialTraverse = true; } /** * Called by the system to signal a key repeat * * @param keyCode the key code of the key that has been pressed */ void uCallKeyRepeated(int keyCode) { uCallKeyPressed(keyCode); } /** * Called by the system to signal a key press. * * @param keyCode the key code of the key that has been pressed */ void uCallKeyPressed(int keyCode) { if (keyCode != Constants.KEYCODE_SELECT || !gauge.interactive) { return; } Form form = null; synchronized (Display.LCDUILock) { int maxValue = gauge.maxValue; int oldValue = gauge.value; int value = oldValue; switch (focusBtn) { case I_INC_BTN: value++; break; case I_DEC_BTN: value--; break; default: Logging.report(Logging.ERROR, LogChannels.LC_HIGHUI, "GaugeLFImpl: uCallKeyPressed, focusBtn=" + focusBtn); break; } gauge.setValueImpl(value); // IMPL NOTE: paint optimization lRequestPaint(); if (value != oldValue) { // notify the ItemStateChangedListener form = (Form)gauge.owner; } } // end synchronized // SYNC NOTE: We make sure we notify the ItemStateChangedListener // outside of LCDUILock if (form != null) { form.uCallItemStateChanged(gauge); } } /** * Called by the system to signal a pointer press * * @param x the x coordinate of the pointer down * @param y the y coordinate of the pointer down * * @see #getInteractionModes */ void uCallPointerPressed(int x, int y) { if (gauge.interactive) { pointerArea = getPointerArea(x, y); switch(pointerArea) { case DEC_BTN_AREA: focusBtn = I_DEC_BTN; uRequestPaint(); break; case INC_BTN_AREA: focusBtn = I_INC_BTN; uRequestPaint(); break; default: break; } } } /** * Get the area of gauge the pointer cliked in. * @param x x coordinate of pointer * @param y y coordinate of pointer * @return the gauge area is returned. The possible values are * * @see #INVALID_AREA if pointer is out of gauge's bounds * @see #INC_BTN_AREA if pointer is on the increment button * @see #DEC_BTN_AREA if pointer is on the decrement button * @see #METER_AREA if pointer is on the meter */ private int getPointerArea(int x, int y) { int area = INVALID_AREA; x -= contentBounds[X]; y -= contentBounds[Y]; if (area == INVALID_AREA && GaugeSkin.IMAGE_DEC_BTN != null && // check coordinates x >= GaugeSkin.DEC_BTN_X && y > GaugeSkin.DEC_BTN_Y && x <= (GaugeSkin.DEC_BTN_X + GaugeSkin.IMAGE_DEC_BTN.getWidth()) && y <= (GaugeSkin.DEC_BTN_Y + GaugeSkin.IMAGE_DEC_BTN.getHeight())) { area = DEC_BTN_AREA; } if (area == INVALID_AREA && GaugeSkin.IMAGE_INC_BTN != null && // check coordinates x >= GaugeSkin.INC_BTN_X && y > GaugeSkin.INC_BTN_Y && x <= (GaugeSkin.INC_BTN_X + GaugeSkin.IMAGE_INC_BTN.getWidth()) && y <= (GaugeSkin.INC_BTN_Y + GaugeSkin.IMAGE_INC_BTN.getHeight())) { area = INC_BTN_AREA; } if (area == INVALID_AREA && // check coordinates x >= GaugeSkin.METER_X && y > GaugeSkin.METER_Y && x <= (GaugeSkin.METER_X + GaugeSkin.IMAGE_METER_FULL.getWidth()) && y <= (GaugeSkin.METER_Y + GaugeSkin.IMAGE_METER_FULL.getHeight())) { area = METER_AREA; } return area; } /** * Called by the system to signal a pointer release * * @param x the x coordinate of the pointer up * @param y the x coordinate of the pointer up */ void uCallPointerReleased(int x, int y) { if (gauge.interactive) { int newArea = getPointerArea(x, y); if (pointerArea == newArea) { switch (pointerArea) { case DEC_BTN_AREA: case INC_BTN_AREA: uCallKeyPressed(Constants.KEYCODE_SELECT); break; case METER_AREA: { Form form = null; synchronized (Display.LCDUILock) { int oldValue = gauge.value; int locationOnMeter = x - contentBounds[X] - GaugeSkin.METER_X; float percent = locationOnMeter * 100 / GaugeSkin.IMAGE_METER_FULL.getWidth(); float value = percent / 100 * gauge.maxValue; /* round the value */ int intValue = (int)value; float remainder = value - intValue; if (remainder > 0.5) { intValue++; } gauge.setValueImpl(intValue); lRequestPaint(); if (intValue != oldValue) { // notify the ItemStateChangedListener form = (Form)gauge.owner; } } // SYNC NOTE: We make sure we notify the ItemStateChangedListener // outside of LCDUILock if (form != null) { form.uCallItemStateChanged(gauge); } } break; default: break; } // end of switch } // pointerArea == newArea } // interactive gauge } /** * Called by the system to notify this Item it is being shown * * <p>The default implementation of this method updates * the 'visible' state */ void lCallShowNotify() { super.lCallShowNotify(); // Start update task for CONTINUOUS_RUNNING gauge upon visible if (gauge.maxValue == Gauge.INDEFINITE && gauge.value == Gauge.CONTINUOUS_RUNNING) { startGaugeUpdateTask(); } } /** * Called by the system to notify this Item it is being hidden * * <p>The default implementation of this method updates * the 'visible' state */ void lCallHideNotify() { super.lCallHideNotify(); cancelGaugeUpdateTask(); } /** * Paints the content area of this Gauge. * Graphics is translated to contents origin. * @param g The graphics where Gauge content should be painted * @param w The width available for the Item's content * @param h The height available for the Item's content */ void lPaintContent(Graphics g, int w, int h) { if (gauge.interactive) { lPaintInteractiveGauge(g, w, h, gauge.maxValue, gauge.value); } else if (gauge.maxValue == Gauge.INDEFINITE) { lPaintIndefinite(g, w, h, gauge.maxValue, gauge.value); } else { lPaintProgressBar(g, w, h, gauge.maxValue, gauge.value); } } void lPaintInteractiveGauge(Graphics g, int w, int h, int maxValue, int value) { // case: interactive gauge // draw background, if present if (GaugeSkin.IMAGE_BG != null) { g.drawImage(GaugeSkin.IMAGE_BG, 0, 0, Graphics.LEFT | Graphics.TOP); } else { g.setColor(0xCCCCCC); g.fillRect(0, 0, GaugeSkin.WIDTH, GaugeSkin.HEIGHT); g.setColor(0); return; // we return early on interactive gauge if there are // no images because its rather complicated to draw // otherwise, at least right now }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?