📄 tileset.java
字号:
// HTMLParser Library $Name: v1_6_20051112 $ - A java-based parser for HTML// http://sourceforge.org/projects/htmlparser// Copyright (C) 2003 Derrick Oswald//// Revision Control Information//// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexerapplications/thumbelina/TileSet.java,v $// $Author: derrickoswald $// $Date: 2004/07/31 16:42:30 $// $Revision: 1.2 $//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//package org.htmlparser.lexerapplications.thumbelina;import java.awt.Rectangle;import java.util.Enumeration;import java.util.Vector;/** * Class to track picture regions. */public class TileSet/* extends java.awt.Canvas implements java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.WindowListener*/{ /** * The list of Pictures. */ protected Vector mRegions; /** * Construct a tile set. */ public TileSet () { mRegions = new Vector (); } /** * Get the number of tiles in this collection. * @return The number of pictures showing. * Note that the same image and URL may be showing * (different pieces) in several locations. */ public int getSize () { return (mRegions.size ()); } /** * Get the list of pictures. * @return An enumeration over the picture objects in this set. */ public Enumeration getPictures () { return (mRegions.elements ()); } /** * Add a single picture to the list. * @param r The picture to add. */ public void add (final Picture r) { Vector regions; // this will be the new set Enumeration e; Picture rover; Rectangle intersection; Vector splits; Enumeration frags; regions = new Vector (); for (e = getPictures (); e.hasMoreElements (); ) { rover = (Picture)e.nextElement (); if (rover.intersects (r)) { intersection = rover.intersection (r); if (!intersection.equals (rover)) { // incoming lies completely within the existing picture // or touches the existing picture somehow splits = split (r, rover, false); for (frags = splits.elements (); frags.hasMoreElements (); ) regions.addElement (frags.nextElement ()); } else // incoming covers existing... drop the existing picture // but be sure to release the image memory rover.setImage (null); } else // no conflict, keep the existing regions.addElement (rover); } regions.addElement (r); mRegions = regions; } /** * Split the large picture. * Strategy: split horizontally (full width strips top and bottom). * NOTE: top and bottom make sense only in terms of AWT coordinates. * @param small The incoming picture. * @param large The encompassing picture. The attributes of this one * are propagated to the fragments. * @param keep If <code>true</code>, the center area is kept, * otherwise discarded. * @return The fragments from the large picture. */ private Vector split ( final Picture small, final Picture large, final boolean keep) { Picture m; Vector ret; ret = new Vector (); if (large.intersects (small)) { Rectangle intersection = large.intersection (small); // if tops don't match split off the top if ((intersection.y + intersection.height) != (large.y + large.height)) { m = new Picture (large); m.y = (intersection.y + intersection.height); m.height = (large.y + large.height) - m.y; ret.addElement (m); } // if left sides don't match make a left fragment if (intersection.x != large.x) { m = new Picture (large); m.y = intersection.y; m.width = intersection.x - large.x; m.height = intersection.height; ret.addElement (m); } // the center bit if (keep) { m = new Picture (large); m.x = intersection.x; m.y = intersection.y; m.width = intersection.width; m.height = intersection.height; ret.addElement (m); } // if right sides don't match make a right fragment if ((intersection.x + intersection.width) != (large.x + large.width)) { m = new Picture (large); m.x = intersection.x + intersection.width; m.y = intersection.y; m.width = (large.x + large.width) - m.x; m.height = intersection.height; ret.addElement (m); } // if bottoms don't match split off the bottom if (intersection.y != large.y) { m = new Picture (large); m.height = (intersection.y - large.y); ret.addElement (m); } } return (ret); } /** * Find the Picture at position x,y * @param x The x coordinate of the point to examine. * @param y The y coordinate of the point to examine. * @return The picture at that point, or <code>null</code> * if there are none. */ public Picture pictureAt (final int x, final int y) { Picture m; Picture ret; ret = null; for (int i = 0; (null == ret) && (i < mRegions.size ()); i++) { m = (Picture)mRegions.elementAt (i); if (m.contains (x, y)) ret = m; } return (ret); } /** * Move the given picture to the top of the Z order. * @param picture The picture to add. */ public void bringToTop (final Picture picture) { Picture m; Picture ret; ret = null; for (int i = 0; (null == ret) && (i < mRegions.size ()); ) { m = (Picture)mRegions.elementAt (i); if (picture.same (m)) mRegions.removeElementAt (i); else i++; } add (picture); }// //// // Unit test.// ////// // and need to add:// extends// java.awt.Canvas// implements// java.awt.event.ActionListener,// java.awt.event.MouseListener,// java.awt.event.WindowListener// // to the class definition//// boolean mVerbose;// int mCounter;// java.awt.Point origin;// Rectangle last;// int type;//// static java.awt.MenuBar menuMain;// static java.awt.Menu Options;// static java.awt.MenuItem repeat;// static java.awt.MenuItem clear;// static java.awt.TextField status;//// // checks if adding the rectangle causes an overlap// boolean checkAdd (Rectangle r, Vector v)// {// Enumeration e;// boolean ret;// ret = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -