imagetilelayer.java
来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 1,440 行 · 第 1/4 页
JAVA
1,440 行
for (Iterator it = list.iterator(); it.hasNext(); tileCount++) { dlm.addElement(it.next()); } } if (resultsList != null) { if (selectedIndicies != null) { resultsList.setSelectedIndices(selectedIndicies); } resultsList.repaint(); } } /** * The ImageTiles currently selected on the list in the GUI. */ protected ImageTile[] selectedTiles; /** * @return the ImageTile[] of tiles currently selected in the GUI. */ protected ImageTile[] getSelectedTiles() { return selectedTiles; } /** * Set the ImageTile[] of tiles currently selected in the GUI. * * @param sTiles */ protected void setSelectedTiles(ImageTile[] sTiles) { selectedTiles = sTiles; boolean allTilesDefective = areAllTilesDefective(sTiles); setGUIButtonEnableState(sTiles != null && sTiles.length > 0 && !allTilesDefective); if (allTilesDefective && icbp != null) { icbp.setGUIDeleteButtonEnableState(allTilesDefective); } checkShowHideStatus(); } protected boolean areAllTilesDefective(ImageTile[] sTiles) { boolean allTilesDefective = false; if (sTiles != null && sTiles.length > 0) { allTilesDefective = true; for (int i = 0; i < sTiles.length; i++) { if (!(sTiles[i] instanceof ErrImageTile)) { allTilesDefective = false; break; } } } return allTilesDefective; } /** * Checks the selected tiles from the visible list and tallies their * visibility. If all of the tiles are invisible, the GUI button will allow * them to be made visible. If any of them are visible, all of them can be * made invisible before the button will change them to the visible. * */ public void checkShowHideStatus() { ImageTile[] sTiles = getSelectedTiles(); boolean anyTilesVisible = (sTiles == null || sTiles.length == 0); if (sTiles != null) { for (int i = 0; i < sTiles.length; i++) { anyTilesVisible = sTiles[i].isVisible() || anyTilesVisible; } } showHideButton.setText(anyTilesVisible ? HIDE_TILES_TITLE : SHOW_TILES_TITLE); } /** * A list selection listener object for the JList. * * @author dietrick */ class ListManager implements ListSelectionListener, MouseListener, MouseMotionListener { public ListManager() { } public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false && resultsList != null) { // Reset the location selection; locateButton.setSelected(false); deselect(); int[] indicies = resultsList.getSelectedIndices(); ImageTile[] selectedTiles = new ImageTile[indicies.length]; if (indicies.length > 0) { ListModel listModel = getListModel(); for (int i = 0; i < indicies.length; i++) { selectedTiles[i] = (ImageTile) listModel.getElementAt(indicies[i]); } } setSelectedTiles(selectedTiles); } } public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } public void mousePressed(MouseEvent e) { checkMouseSelection(e); } public void mouseReleased(MouseEvent e) { checkMouseSelection(e); } protected void checkMouseSelection(MouseEvent e) { int selectedIndex = getResultListIndex(e); if (selectedIndex < 0) { resultsList.clearSelection(); } } public void mouseDragged(MouseEvent e) { // TODO Auto-generated method stub } public void mouseMoved(MouseEvent e) { int selectedIndex = getResultListIndex(e); if (selectedIndex >= 0) { Object it = getListModel().getElementAt(selectedIndex); if (it instanceof ErrImageTile) { resultsList.setToolTipText(((ErrImageTile) it).getProblemMessage()); return; } } resultsList.setToolTipText(null); } } /** * find out which list object was moused. * * @param e * @return */ protected int getResultListIndex(MouseEvent e) { int index = -1; if (resultsList != null) { double height = getResultsListCellHeight(); if (height == 0) { return index; } int nIndex = e.getY() / (int) height; if (nIndex < getListModel().getSize()) { index = nIndex; } } return index; } /** * Get the pixel height of each cell in the JList. * * @return */ protected double getResultsListCellHeight() { double height = 0; if (resultsList != null) { int rlFVI = resultsList.getFirstVisibleIndex(); Rectangle bounds = resultsList.getCellBounds(rlFVI, rlFVI); if (bounds != null) { height = bounds.getHeight(); } } return height; } public static int buttonSize = 16; public static ImageIcon warningImage; public static ImageIcon invisibleImage; protected static void initIcons() { DrawingAttributes blackDa = new DrawingAttributes(); DrawingAttributes invisDa = new DrawingAttributes(); invisDa.setLinePaint(OMColor.clear); invisDa.setFillPaint(OMColor.clear); DrawingAttributes yellowDa = new DrawingAttributes(); yellowDa.setLinePaint(OMColor.yellow); yellowDa.setFillPaint(OMColor.yellow); IconPart ip = new BasicIconPart(new Rectangle2D.Double(0, 0, 100, 100)); ip.setRenderingAttributes(invisDa); invisibleImage = OMIconFactory.getIcon(buttonSize, buttonSize, ip); IconPartList ipl = new IconPartList(); Polygon triangle = new Polygon(new int[] { 50, 90, 10, 50 }, new int[] { 10, 90, 90, 10 }, 4); BasicIconPart bip = new BasicIconPart(triangle); bip.setRenderingAttributes(yellowDa); ipl.add(bip); bip = new BasicIconPart(triangle); bip.setRenderingAttributes(yellowDa); ipl.add(bip); bip = new BasicIconPart(triangle); bip.setRenderingAttributes(blackDa); ipl.add(bip); bip = new BasicIconPart(new Line2D.Double(49, 35, 49, 65)); bip.setRenderingAttributes(blackDa); ipl.add(bip); bip = new BasicIconPart(new Line2D.Double(49, 75, 49, 77)); bip.setRenderingAttributes(blackDa); ipl.add(bip); bip = new BasicIconPart(new Line2D.Double(51, 35, 51, 65)); bip.setRenderingAttributes(blackDa); ipl.add(bip); bip = new BasicIconPart(new Line2D.Double(51, 75, 51, 77)); bip.setRenderingAttributes(blackDa); ipl.add(bip); warningImage = OMIconFactory.getIcon(buttonSize, buttonSize, ipl); } /** * Renders the JList cells. */ public static class ImageListCellRenderer extends JPanel implements ListCellRenderer { protected int buttonSize = 16; protected JLabel label = new JLabel(); protected JLabel statusMark = new JLabel(); public static Color fontColor = Color.BLACK; public static Color altFontColor = Color.BLACK; public static Color selectColor = Color.GRAY; public static Color notVisibleColor = new Color(100, 100, 100); public static Color regularBackgroundColor = Color.WHITE; public ImageListCellRenderer() { if (warningImage == null) { initIcons(); } setOpaque(true); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridbag); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0f; gridbag.setConstraints(label, c); this.add(label); c.fill = GridBagConstraints.NONE; c.weightx = 0f; gridbag.setConstraints(statusMark, c); this.add(statusMark); Font f = label.getFont(); f = new Font(f.getName(), f.getStyle(), f.getSize() - 1); label.setFont(f); setPreferredSize(new Dimension(20, buttonSize)); } public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value instanceof ImageTile) { ImageTile imageTile = (ImageTile) value; label.setText((String) imageTile.getAttribute(NAME_ATTRIBUTE)); if (!isSelected) { label.setForeground(imageTile.isVisible() ? fontColor : notVisibleColor); } if (value instanceof ErrImageTile) { statusMark.setIcon(warningImage); } else { statusMark.setIcon(invisibleImage); } } setBackground(isSelected ? selectColor : regularBackgroundColor); return this; } } /** * File filter created based on what the ImageReaders can handle. * * @author dietrick */ class ImageLoaderFileFilter extends FileFilter { Vector imageReaderLoaders; public ImageLoaderFileFilter(Vector imgDcdrLdrs) { imageReaderLoaders = imgDcdrLdrs; } public boolean accept(File f) { if (f.isDirectory()) { return true; } if (imageReaderLoaders != null) { for (Iterator it = imageReaderLoaders.iterator(); it.hasNext();) { if (((ImageReaderLoader) it.next()).isLoadable(f.getName())) { return true; } } } return false; } public String getDescription() { String description = i18n.get(ImageTileLayer.class, "fileFilterDescription", "Image File Formats Supported by Layer"); return description; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?