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

📄 panel.java

📁 手机资源管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

				return changed;
			} else {
				int step = posy + titleBarHeight - pre.getFocusy();
				scrollStep = (int) ((float) step / usedHeight * internalHeight);
				if (scrollBarPosy <= posy + titleBarHeight) {
					LScreen.console("scroll bar reach to front");
					changed = false;
					return changed;
				}
				scrollBarPosy -= scrollStep;
				int backStep = 0;
				if (scrollBarPosy <= posy + titleBarHeight) {
					backStep = posy + titleBarHeight - scrollBarPosy;
					scrollBarPosy += backStep;
					LScreen.console("scroll bar reach to end");
				}
				int rowMoveDistance = (int) ((float) (scrollStep - backStep)
						/ getInternalHeight() * usedHeight);

				for (int i = 0; i < rows.size(); i++) {

					Component r = (Component) rows.elementAt(i);
					// System.out.println("r's cordi: "+r.getPosy());
					r.setPosy(r.getPosy() + rowMoveDistance);
					// System.out.println("r's cordi: "+r.getPosy());
				}
			}
			changed = true;
		} else if (k == LUIConfig.DOWN) {

			LScreen.console("down pressed");

			Component next = getNext();
			System.out.println("rowPointer   " + rowPointer);
			Component c = (Component) rows.elementAt(rowPointer);

			if (c.getClass().getName().equals("com.cuit.lui.ChoiceGroup")
					&& c.isOnFocus) {

				changed = c.keyEvent(k);
				// return;
			}
			if (c.getClass().getName().equals("com.cuit.lui.ChoicePopup")
					&& c.isOnFocus && ((ChoicePopup) c).choiceBoxShow) {

				changed = c.keyEvent(k);
				// return;
			}

			if (!checkNeedScroll(next, k)) {

				return changed;
			} else {
				int step = next.getFocusy() + next.getHeight() - posy
						- titleBarHeight - internalHeight;
				scrollStep = (int) ((float) step / usedHeight * internalHeight);
				if (scrollBarPosy + scrollBarHeight >= posy + titleBarHeight
						+ getInternalHeight()) {

					LScreen.console("scroll bar reach to end");
					changed = false;
					return changed;
				}
				scrollBarPosy += scrollStep;
				int backStep = 0;
				if (scrollBarPosy + scrollBarHeight >= posy + titleBarHeight
						+ getInternalHeight()) {
					backStep = scrollBarPosy + scrollBarHeight
							- (posy + titleBarHeight + getInternalHeight());
					scrollBarPosy -= backStep;
					LScreen.console("scroll bar reach to end");
				}
				int rowMoveDistance = (int) ((float) (scrollStep - backStep)
						/ getInternalHeight() * usedHeight);

				for (int i = 0; i < rows.size(); i++) {

					Component r = (Component) rows.elementAt(i);
					// System.out.println("r's cordi: "+r.getPosy());
					r.setPosy(r.getPosy() - rowMoveDistance);
					// System.out.println("r's cordi: "+r.getPosy());
				}
			}
			changed = true;
		} else if (k == LUIConfig.FIRE) {
			Component c = (Component) rows.elementAt(rowPointer);
			if (c.getOnFocus() && c.ifCommand()) {

				changed = c.keyEvent(k);
				LScreen.console("row: " + rowPointer + " key fire processed");
			}

		}
		return changed;
	}

	public int getHeight() {
		return panelHeight;
	}

	public int getWidth() {
		return panelWidth;
	}

	public int getInternalWidth() {
		return getWidth() - scrollBarWidth;
	}

	public int getInternalHeight() {

		return internalHeight;
	}

	private Component getNext() {
		Component c = null;
		if (rowPointer >= 0) {
			c = (Component) rows.elementAt(rowPointer);
			String name = c.getClass().getName();
			if (name.equals("com.cuit.lui.ChoiceGroup") && c.isOnFocus) {

			} else if (name.equals("com.cuit.lui.ChoicePopup") && c.isOnFocus
					&& ((ChoicePopup) c).choiceBoxShow) {
				System.out.println("choice popup detected...");
			} else {
				// System.out.println("rowpointer++...");
				rowPointer++;
				c.setBorder(false);
				c.setOnFocus(false);
			}

		}
		if (rowPointer < 0) {
			rowPointer++;
		}
		if (rowPointer >= rows.size()) {
			rowPointer = rows.size() - 1;
			LScreen.console("row pointer wrap to front");
		}
		c = (Component) rows.elementAt(rowPointer);
		c.setBorder(true);
		c.setOnFocus(true);
		return c;
	}

	private Component getPrevious() {
		if (rowPointer < 0)
			rowPointer = 0;
		Component c = (Component) rows.elementAt(rowPointer);
		String name = c.getClass().getName();
		if (name.equals("com.cuit.lui.ChoiceGroup") && c.isOnFocus) {

		} else if (name.equals("com.cuit.lui.ChoicePopup") && c.isOnFocus
				&& ((ChoicePopup) c).choiceBoxShow) {
			System.out.println("choice popup detected...");

		} else {
			System.out.println("rowpointer--...");
			rowPointer--;
			c.setBorder(false);
			c.setOnFocus(false);

		}

		if (rowPointer < 0) {
			rowPointer = 0;
			LScreen.console("row pointer wrap to end");
		}
		c = (Component) rows.elementAt(rowPointer);
		c.setBorder(true);
		c.setOnFocus(true);
		return c;

	}

	private boolean checkNeedScroll(Component r, int dir) {
		boolean needScroll = false;
		if (dir == LUIConfig.UP) {
			if (r.getFocusy() < posy + titleBarHeight) {
				needScroll = true;
			}
		} else if (dir == LUIConfig.DOWN) {
			if (r.getFocusy() + r.getHeight() > posy + titleBarHeight
					+ internalHeight) {
				needScroll = true;
			}

		} else {
			LScreen.console("checkNeedScroll dir parameter invalid!");

		}
		if (needScroll && dir == LUIConfig.UP)
			System.out.println("scrolled up");
		return needScroll;
	}

	public void setTitleBarHeight(int th) {
		if (th < 0) {
			LScreen.warning("title bar height parameter invalid");
			return;
		}
		titleBarHeight = th;
	}

	public void setTaskBarHeight(int h) {
		if (h < 0) {
			LScreen.warning("task bar height parameter invalid");
			return;
		}
		taskBarHeight = h;
	}

	public void setScrollBarWidth(int w) {
		if (w < 0) {
			LScreen.warning("scroll bar width parameter invalid");
			return;
		}
		scrollBarWidth = w;
	}

	public void setRowPointer(int i) {
		if (i < -1 || i > rows.size() - 1) {
			LScreen.error("row pointer parameter invalid");
		} else {
			rowPointer = i;
		}
	}

	public void setTitle(String s) {
		title = s;
	}

	public int getTitleBarHeight() {
		return titleBarHeight;
	}

	public int getTaskBarHeight() {
		return taskBarHeight;
	}

	public int getScrollBarWidth() {
		return scrollBarWidth;
	}

	public int getRowPointer() {
		return rowPointer;
	}

	private void openPopup(int dir) {
		if (dir == LUIConfig.LEFT) {
			if (rightPopup != null) {
				rightPopup.setShow(false);
				rightPopup.setOnFocus(false);
			}

			leftPopup.setShow(true);
			leftPopup.setOnFocus(true);
			leftPopup.setRowPointer(0);
		} else if (dir == LUIConfig.RIGHT) {
			if (leftPopup != null) {
				leftPopup.setShow(false);
				leftPopup.setOnFocus(false);
			}

			rightPopup.setShow(true);
			rightPopup.setOnFocus(true);
			rightPopup.setRowPointer(0);
		} else {
			LScreen.error("open pop up direction parameter invalid");
		}
	}

	public void closePopup(int dir) {
		if (dir == LUIConfig.LEFT) {
			leftPopup.setShow(false);
			leftPopup.setOnFocus(false);
			Row r = (Row) leftPopup.rows.elementAt(leftPopup.rowPointer);
			r.setOnFocus(false);
			leftPopup.reset();
			leftPopup.refreshPanel();
		} else if (dir == LUIConfig.RIGHT) {
			rightPopup.setShow(false);
			rightPopup.setOnFocus(false);
			Row r = (Row) rightPopup.rows.elementAt(rightPopup.rowPointer);
			r.setOnFocus(false);
			rightPopup.reset();
			rightPopup.refreshPanel();
		} else {
			LScreen.error("close pop up direction parameter invalid");
		}
		setOnFocus(true);
	}

	protected void refreshPanel() {
		scrollBarPosx = getWidth() - scrollBarWidth;
		scrollBarPosy = posy + titleBarHeight + 1;
		Row r = (Row) rows.firstElement();
		int differ = r.getPosy() - rowStarty;

		for (int i = 0; i < rows.size(); i++) {
			r = (Row) rows.elementAt(i);
			r.setPosy(r.getPosy() - differ);
		}
	}

	public int getFocusy() {
		return posy;

	}

	public String getTitle() {
		return title;
	}

	public int size() {
		return rows.size();

	}

	public void addLeftCommand(Command c) {
		if (leftPopup != null && leftCommand != null) {
			LScreen.error("leftpopup or command has existed!");
			return;
		}
		leftCommand = c;
	}

	public void addRightCommand(Command c) {
		if (rightPopup != null && rightCommand != null) {
			LScreen.error("rightpopup or command has existed!");
			return;
		}
		rightCommand = c;
	}

	public void resetPointer() {
		rowPointer = -1;
	}

	public void reset() {
		if (leftPopup != null && leftPopup.isShow()) {
			closePopup(LUIConfig.LEFT);
		}
		if (rightPopup != null && rightPopup.isShow()) {
			closePopup(LUIConfig.RIGHT);
		}
		for (int i = 0; i < rows.size(); i++) {
			Component c = (Component) rows.elementAt(i);
			c.reset();
		}
		isOnFocus = false;
		isBorder = false;
		adjustLayout();
		resetPointer();

	}
	public void removeLeftCommand(){
		leftCommand=null;
	}
	public void removeRightCommand(){
		rightCommand=null;
	}

}

⌨️ 快捷键说明

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