imagetilelayer.java
来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 1,440 行 · 第 1/4 页
JAVA
1,440 行
* called in a non-AWT thread. * * @return OMGraphicList retrieved from getList(), or a new list of that * list is null. */ protected OMGraphicList loadImages() { clearImageTileList(); OMGraphicList ret = getList(); if (ret == null) { ret = new OMGraphicList(); setList(ret); } else { ret.clear(); } if (filePaths != null) { for (Iterator it = filePaths.iterator(); it.hasNext();) { loadImage((String) it.next(), ret); } } return ret; } /** * If filePath is a file, the ImageReaderLoaders are used to try to load * and place the image. If filePath is a directory, this method is called * for each file contained within. ImageTile objects are created from the * image files. * * @param filePath * @param ret The OMGraphicList to add any ImageTiles to. */ protected void loadImage(String filePath, OMGraphicList ret) { File file = new File(filePath); if (file.exists() && file.isDirectory()) { String[] files = file.list(); for (int i = 0; i < files.length; i++) { loadImage(filePath + "/" + files[i], ret); } } else { fireStatusUpdate(LayerStatusEvent.START_WORKING); try { URL fileURL = PropUtils.getResourceOrFileOrURL(filePath); if (fileURL != null) { if (imageReaderLoaders != null) { ImageTile imageTile = null; for (Iterator it = imageReaderLoaders.iterator(); it.hasNext();) { ImageReaderLoader idl = (ImageReaderLoader) it.next(); if (idl.isLoadable(filePath)) { ImageReader id = idl.getImageReader(fileURL); ImageTile tmpImageTile = id.getImageTile(imageCache); if (imageTile == null) { imageTile = tmpImageTile; } else if (tmpImageTile != null && imageTile instanceof ErrImageTile) { imageTile = tmpImageTile; } if (imageTile != null && !(imageTile instanceof ErrImageTile)) { break; } } } // Need to check for null in case none of the // ImageReaders could handle the file. if (imageTile != null) { addImageToLists(imageTile, ret, fileURL); } } else { logger.warning("ImageReaders not configured in " + getName() + " ImageTileLayer."); } } else { logger.warning("Can't get URL from " + filePath); } } catch (MalformedURLException murle) { } } } /** * A method to handle a newly created ImageTile object from the loadImage * method. * * @param imageTile The new ImageTile * @param ret An OMGraphicList to add the ImageTile to. * @param fileURL A URL describing the location of the source image file. */ protected void addImageToLists(ImageTile imageTile, OMGraphicList ret, URL fileURL) { imageTile.generate(getProjection()); ret.add(imageTile); addImageTileToList(imageTile); imageTile.putAttribute(FILE_PATH_ATTRIBUTE, fileURL.getPath()); // Probably need to check for the last slash // and grab that part. imageTile.putAttribute(NAME_ATTRIBUTE, fileURL.getFile()); selectedDrawingAttributes.setTo(imageTile); // Let's just assume that we're working with // the main list here at the top level, and we // can paint the images we have. repaint(); if (resultsList != null) { resultsList.repaint(); } } public final static String NAME_ATTRIBUTE = "NAME"; public final static String FILE_PATH_ATTRIBUTE = "FILE_PATH"; protected JPanel itPanel; protected JList resultsList; protected DefaultListModel listModel; protected ListManager listManager; JButton showHideButton; JButton gotoButton; JToggleButton locateButton; ImageControlButtonPanel icbp; /** * Gets the gui controls associated with the layer. * * @return IPanel for layer controls. */ public Component getGUI() { if (itPanel == null) { itPanel = new JPanel(); GridBagConstraints c = new GridBagConstraints(); GridBagLayout gridbag = new GridBagLayout(); itPanel.setLayout(gridbag); icbp = new ImageControlButtonPanel(); gridbag.setConstraints(icbp, c); itPanel.add(icbp); resultsList = new JList(getListModel()); resultsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); listManager = new ListManager(); resultsList.addListSelectionListener(listManager); resultsList.addMouseListener(listManager); resultsList.addMouseMotionListener(listManager); resultsList.setCellRenderer(new ImageListCellRenderer()); JScrollPane listScrollPane = new JScrollPane(resultsList); listScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); listScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); c.fill = GridBagConstraints.BOTH; c.weightx = 1.0f; c.weighty = 1.0f; c.insets = new Insets(5, 5, 5, 5); c.gridwidth = GridBagConstraints.REMAINDER; gridbag.setConstraints(listScrollPane, c); itPanel.add(listScrollPane); JPanel buttonPanel = new JPanel(); GridBagLayout bGridbag = new GridBagLayout(); GridBagConstraints bc = new GridBagConstraints(); showHideButton = new JButton(HIDE_TILES_TITLE); showHideButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { showHideTiles(((JButton) ae.getSource()).getText(), getSelectedTiles()); } }); bGridbag.setConstraints(showHideButton, bc); buttonPanel.add(showHideButton); gotoButton = new JButton(i18n.get(ImageTileLayer.class, "gotoButton", "Go To")); gotoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { goTo(getSelectedTiles()); } }); bGridbag.setConstraints(gotoButton, bc); buttonPanel.add(gotoButton); locateButton = new JToggleButton(i18n.get(ImageTileLayer.class, "locateButton", "Highlight")); locateButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JToggleButton jtb = (JToggleButton) ae.getSource(); setSelection(getSelectedTiles(), jtb.isSelected()); } }); bGridbag.setConstraints(locateButton, bc); buttonPanel.add(locateButton); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0f; c.weighty = 0f; c.insets = new Insets(0, 5, 5, 5); gridbag.setConstraints(buttonPanel, c); itPanel.add(buttonPanel); setGUIButtonEnableState(false); } return itPanel; } /** * A modified LayerControlButtonPanel that is used to control which image * files are available and their display order relative to each other on the * image stack. * * @author dietrick */ class ImageControlButtonPanel extends LayerControlButtonPanel { public ImageControlButtonPanel() { super(); add = new JButton(addgif); add.setActionCommand(LayersPanel.LayerAddCmd); add.setToolTipText(i18n.get(ImageTileLayer.class, "addImage", I18n.TOOLTIP, "Add images(s)")); add.addActionListener(ImageControlButtonPanel.this); add(add); // Fix the tooltips: delete.setToolTipText(i18n.get(ImageTileLayer.class, "deleteImage", I18n.TOOLTIP, "Remove image(s)")); delete.setEnabled(true); top.setToolTipText(i18n.get(ImageTileLayer.class, "moveImageToTop", I18n.TOOLTIP, "Move selected image(s) to top")); up.setToolTipText(i18n.get(ImageTileLayer.class, "moveImageUp", I18n.TOOLTIP, "Move selected image(s) up")); down.setToolTipText(i18n.get(ImageTileLayer.class, "moveImageDown", "Move selected image(s) down")); bottom.setToolTipText(i18n.get(ImageTileLayer.class, "moveImageToBottom", I18n.TOOLTIP, "Move selected image(s) to bottom")); } public void actionPerformed(ActionEvent ae) { String cmd = ae.getActionCommand(); if (cmd == LayersPanel.LayerAddCmd) { addNewImagesWithFileChooser(); } else if (cmd == LayersPanel.LayerRemoveCmd) { removeImages(getSelectedTiles()); } else if (cmd == LayersPanel.LayerDownCmd) { moveOneSlotToBottom(getSelectedTiles()); ImageTileLayer.this.repaint(); } else if (cmd == LayersPanel.LayerBottomCmd) { moveToBottom(getSelectedTiles()); ImageTileLayer.this.repaint(); } else if (cmd == LayersPanel.LayerTopCmd) { moveToTop(getSelectedTiles()); ImageTileLayer.this.repaint(); } else if (cmd == LayersPanel.LayerUpCmd) { moveOneSlotToTop(getSelectedTiles()); ImageTileLayer.this.repaint(); } } public void setGUIButtonEnableState(boolean somethingSelected) { delete.setEnabled(somethingSelected); top.setEnabled(somethingSelected); up.setEnabled(somethingSelected); down.setEnabled(somethingSelected); bottom.setEnabled(somethingSelected); } public void setGUIDeleteButtonEnableState(boolean state) { delete.setEnabled(state); } } /** * Changes the visibility setting on all ImageTile objects. * * @param visible */ protected void setVisibilityOnAllTiles(boolean visible) { OMGraphicList list = getList(); if (list != null) { for (Iterator it = list.iterator(); it.hasNext();) { ((OMGraphic) it.next()).setVisible(visible); } repaint(); } } /** * Action method called when the show/hide button is pressed. * * @param text if SHOW_TILES_TITLE, tiles made visible. * @param selectedTiles2 */ protected void showHideTiles(String text, ImageTile[] selectedTiles2) { boolean isVisible = (text == SHOW_TILES_TITLE); for (int i = 0; i < selectedTiles2.length; i++) { selectedTiles2[i].setVisible(isVisible); } checkShowHideStatus(); repaint(); if (resultsList != null) { resultsList.repaint(); } } /** * Move all the selected tiles down one space. * * @param selectedTiles2 */ protected void moveOneSlotToBottom(ImageTile[] selectedTiles2) { OMGraphicList list = getList(); if (list != null && selectedTiles != null && selectedTiles.length > 0) { for (int i = selectedTiles2.length - 1; i >= 0; i--) { ImageTile tile = selectedTiles2[i]; list.moveIndexedOneToBottom(list.indexOf(tile)); } rebuildListModel(); } } /** * Move all of the selected tiles to the bottom of the stack. * * @param selectedTiles2 */ protected void moveToBottom(ImageTile[] selectedTiles2) { OMGraphicList list = getList(); if (list != null && selectedTiles != null && selectedTiles.length > 0) { for (int i = 0; i < selectedTiles2.length; i++) { ImageTile tile = selectedTiles2[i]; list.moveIndexedToBottom(list.indexOf(tile)); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?