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

📄 panel.java

📁 最强手机阅读器Anyview3.0版的界面代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		int height = getHeight() - getTopHeight() - getBottomHeight();
		int left = width - Settings.SCROLLBAR_WIDTH - adjustx;
		int top = getTop() + getTopHeight();
		Theme.drawScrollBarShade(g, left, top, height - 1);

		//算出滚动条应该在的位置
		if (showscrollbar) {
			scrollbartop = getTop() + getTopHeight() + (height - scrollbarHeight) * verticalOffset
					/ (internalHeight - height);
		}
		Theme.drawScrollBarFront(g, left, scrollbartop, scrollbarHeight);
	}

	public boolean isAnimated() {
		if (animateDir != Settings.ANIMATE_NONE) {
			//System.out.println("return true.......");
			return true;
		}

		if (pointerPressed && !pointerInscrollbar) {
			//System.out.println(System.currentTimeMillis() - pointerPressedtime);
			//			if (System.currentTimeMillis() - pointerPressedtime > 2000) {
			//				setBusymode(true);
			//			}
			return true;
		}

		for (int i = 0; i < components.size(); i++) {
			Row row = (Row) components.get(i);
			if (row.getTop() + row.getHeight() < verticalOffset) {
				continue;
			}
			if (row.getTop() > verticalOffset + viewportHeight) {
				break;
			}
			if (row.isAnimated(verticalOffset, viewportHeight)) {
				return true;
			}
		}

		return false;
	}

	/**
	 * 重置当前panel所有的热点
	 *
	 */
	public void resetPointer() {
		currentPointer = -1;
		hotpots.clear();
		for (int i = 0; i < components.size(); i++) {
			Row row = (Row) components.get(i);
			row.resetPointer(hotpots);
		}
		if (hotpots.size() > 0) {
			currentPointer = 0;
			((Component) hotpots.get(0)).setSelected(true);
		}
	}

	/**
	 * 设置当前热点
	 * @param index
	 */
	public void setPointer(int index) {
		int oldpointer = currentPointer;
		if (null == hotpots || hotpots.size() == 0 || index < 0) {
			return;
		}
		if (index > hotpots.size() - 1) {
			return;
		}
		currentPointer = index;

		((Component) hotpots.get(oldpointer)).setSelected(false);
		((Component) hotpots.get(currentPointer)).setSelected(true);
	}

	public void setPointer(DisplayableBlock disp) {
		if (null == disp && null == hotpots || hotpots.size() == 0) {
			return;
		}
		for (int i = 0; i < hotpots.size(); i++) {
			DisplayableBlock d = (DisplayableBlock) hotpots.get(i);
			if (d == disp) {
				currentPointer = i;
				return;
			}
		}
	}

	/**
	 * 返回当前的选择点
	 * @return
	 */
	public Component getCurrentPointer() {
		if (currentPointer == -1) {
			return null;
		} else {
			return ((Component) hotpots.get(currentPointer));
		}
	}

	public void commandAction(Command cmd, Component c) {

	}

	/**
	 * 清除当前面板,一般后面会和validate()配合使用
	 */
	public void clear() {
		components.clear();
		hotpots.clear();
		currentPointer = -1;
		showscrollbar = false;
	}

	/**
	 * 返回底部命令栏的高度
	 * @return
	 */
	public int getBottomHeight() {
		if (showBottom) {
			return 20;
		} else {
			return 0;
		}
	}

	public void setTitle(String label) {
		int w = getFont().stringWidth(label);
		int lw = 10;
		int max = (getWidth() - lw);
		if (w < max) {
			this.title = label;
			return;
		}
		// trim label to an acceptable size.
		char[] lch = label.toCharArray();
		max = max - getFont().stringWidth("...");

		StringBuffer res = new StringBuffer();
		int sum = 0;
		for (int i = 0; i < lch.length && sum < max; ++i) {
			sum += getFont().charWidth(lch[i]);
			res.append(lch[i]);
		}

		this.title = res.toString() + "...";
	}

	public String getTitle() {
		return title;
	}

	public void repaint() {
		MainCanvas.getInstance().repaint();
	}

	public boolean isPointerIn(int x, int y) {
		return false;
	}

	public boolean pointerPressed(int x, int y) {
		pressedComponent = null; //触摸屏按下时点击到的控件
		pointerPressed = true; //触摸屏按下时
		pointerPressedtime = System.currentTimeMillis(); //触摸屏按下时的时间
		pointerInscrollbar = false; //是否在滚动条上
		lastPointerX = x;
		lastPointerY = y;

		//判断是否在左、右软键上
		if (getBottomHeight() > 0) {
			if (y > mainCanvas.getHeight() - getBottomHeight()) { //在底栏上				
				return false;
			}
		}

		//是否在顶栏上
		if (getTopHeight() > 0) {
			if (y < getTopHeight()) {
				return false;
			}
		}

		//在否在滚动条上
		if (showscrollbar) {
			if (x > mainCanvas.getWidth() - Settings.SCROLLBAR_WIDTH) {
				pointerInscrollbar = true;
				return false;
			}
		}

		for (int i = 0; i < hotpots.size(); i++) {
			Component c = (Component) hotpots.get(i);
			if (componentInScreen(c)) {
				if (c.isPointerIn(x, y + verticalOffset)) {
					((Component) hotpots.get(currentPointer)).setSelected(false);
					c.setSelected(true);
					pressedComponent = c;
					currentPointer = i;
					return true;
				}
			}
		}

		return false;
	}

	public boolean pointerDragged(int x, int y) {
		//目前只处理滚动条上的拖动事件
		if (lastPointerX < mainCanvas.getWidth() - Settings.SCROLLBAR_WIDTH) {
			return false;
		}

		int dis = y - lastPointerY;
		if ((dis > 8 || dis < -8) && showscrollbar) {
			lastPointerY = y;
			int height = mainCanvas.getHeight() - getBottomHeight();
			dis = dis * internalHeight / (height - scrollbarHeight);
			verticalOffset += dis;
			if (verticalOffset <= 0) {
				verticalOffset = 0;
			}
			if (verticalOffset > internalHeight - viewportHeight) {
				verticalOffset = internalHeight - viewportHeight;
			}
			return true;
		}
		return false;
	}

	public boolean pointerReleased(int x, int y) {
		if (pointerPressed) {
			if (System.currentTimeMillis() - pointerPressedtime > 2000) {
				setBusymode(false);
			}
		}

		//pressedComponent = null; //触摸屏按下时点击到的控件
		pointerPressed = false; //触摸屏按下时
		//pointerPressedtime = System.currentTimeMillis(); //触摸屏按下时的时间
		//pointerInscrollbar = false; //是否在滚动条上
		//lastPointerX = lastPointerY = -1;

		//判断上次是不是在底栏上的命令
		if (getBottomHeight() > 0) {
			if (lastPointerY > mainCanvas.getHeight() - getBottomHeight()) { //上次在底栏上
				if (y > mainCanvas.getHeight() - getBottomHeight()) { //这次也在底栏上
					String str = "";
					if (null != leftCmd) {
						str = leftCmd.getLabel();
						if (x < mainCanvas.getWidth() / 2 && lastPointerX < mainCanvas.getWidth() / 2) { //两次都在左软键上
							return keyReleased(Settings.VKEY_LSOFT);
						}
						/*if (Anyview.hasPointerEvents) {
						 
						 } else {
						 if ((x > 2 && x < 2 + SysDotFont.stringWidth(str))
						 && (lastPointerX > 2 && lastPointerX < SysDotFont.stringWidth(str))) { //两次都在左软键上
						 return keyReleased(Settings.VKEY_LSOFT);
						 }
						 }*/
					}

					if (null != rightCmd) {
						str = rightCmd.getLabel();
						if (x > getWidth() / 2 && lastPointerX > mainCanvas.getWidth() / 2) { //两次都在右软键上
							return keyReleased(Settings.VKEY_RSOFT);
						}
						/*if (Anyview.hasPointerEvents) {
						 
						 } else {
						 if ((x > mainCanvas.getWidth() - SysDotFont.stringWidth(str) - 3 && x < mainCanvas
						 .getWidth() - 3)
						 && (lastPointerX > mainCanvas.getWidth() - SysDotFont.stringWidth(str) - 3 && lastPointerX < mainCanvas
						 .getWidth() - 3)) { //两次都在右软键上
						 return keyReleased(Settings.VKEY_RSOFT);
						 }
						 }*/
					}

					return false;
				} else {
					return false;
				}
			}
		}

		//并不判断是不是滚动条上的命令

		//判断释放时是不是上次点击的东西
		if (null != pressedComponent && pressedComponent.isPointerIn(x, y + verticalOffset)) {
			return keyReleased(Settings.VKEY_FIRE);
		}
		return false;
	}

	public void callback(Component component, Command cmd, Object[] parameters) {

	}

	/*public void showAlert(String message, Image img) {
	 showAlert(message, img, new int[]{Settings.VKEY_NONE});	
	 }*/

	public void showAlert(String message) { //默认使用右软键、#关闭警告窗口
		showAlert(message, null, new int[] { Settings.VKEY_RSOFT, Settings.VKEY_POUND });
	}

	/**
	 * add by zhangjian
	 * @param message
	 * @param img
	 * @param key
	 */
	public void showAlert(String message, Image img, int[] key) {
		alert = new AlertPanel(message, key);
		mainCanvas.showPopup(alert);
	}

	public void closeAlert() {
		Component c = mainCanvas.getTopComponent();
		if (null != c && c instanceof AlertPanel) {
			mainCanvas.closePopup();
		}
	}

	public Image getLogo() {
		return logo;
	}

	public void setLogo(Image logo) {
		this.logo = logo;
	}

	/**
	 * 设置热点的行为
	 * @param recycle true表示可以循环
	 */
	public void setRecycle(boolean recycle) {
		this.recycle = recycle;
	}

	/**
	 * panel再次激活时执行的操作
	 * 在菜单关闭,或者上级panel关闭时调用
	 */
	protected void reActive() {
		if (null != leftPopup) {
			leftPopup.validate();
			if (PopMenu.alignLeft) {
				leftPopup.setLocation(1, mainCanvas.getHeight() - leftPopup.getHeight() - getBottomHeight());
			} else {
				leftPopup.setLocation(getWidth() - 1 - leftPopup.getWidth(), mainCanvas.getHeight()
						- leftPopup.getHeight() - getBottomHeight());
			}
			//System.out.println("leftPopup = " + leftPopup.getTop() + ", " + leftPopup.getHeight());
		}

		if (null != rightPopup) {
			rightPopup.validate();
			if (PopMenu.alignLeft) {
				rightPopup.setLocation(getWidth() - 1 - rightPopup.getWidth(), mainCanvas.getHeight()
						- rightPopup.getHeight() - getBottomHeight());
			} else {
				rightPopup.setLocation(1, mainCanvas.getHeight() - rightPopup.getHeight() - getBottomHeight());
			}
		}
	}

	//当一个panel转为非激活状态时的操作
	protected void deActive() {

	}

	/**
	 * 当一个窗口激活后执行
	 */
	protected void afterActive() {

	}

	public boolean isBusymode() {
		return MainCanvas.isBusymode();
	}

	public void setBusymode(boolean busymode) {
		MainCanvas.setBusymode(busymode);
	}

	public void setBusymode(boolean busymode, int x, int y) {
		MainCanvas.setBusymode(busymode, x, y);
	}

	public void close() {

	}
}

⌨️ 快捷键说明

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