imagetilelayer.java
来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 1,440 行 · 第 1/4 页
JAVA
1,440 行
rebuildListModel(); } } /** * Move all of the selected tiles up one space. * * @param selectedTiles2 */ protected void moveOneSlotToTop(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.moveIndexedOneToTop(list.indexOf(tile)); } rebuildListModel(); } } /** * Move all of the selected tiles to the top of the stack. * * @param selectedTiles2 */ protected void moveToTop(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.moveIndexedToTop(list.indexOf(tile)); } rebuildListModel(); } } /** * MapBean is used to reset the projection of the map over the selected * images. */ protected MapBean mapBean; /** * Figure out where the images are and move the MapBean over them. * * @param selectedTiles2 */ protected void goTo(ImageTile[] selectedTiles2) { if (mapBean == null) { MapHandler bc = (MapHandler) getBeanContext(); if (bc != null) { mapBean = (MapBean) bc.get(com.bbn.openmap.MapBean.class); } } if (mapBean != null) { if (selectedTiles != null && selectedTiles.length > 0) { Rectangle2D rec = null; for (int i = selectedTiles2.length - 1; i >= 0; i--) { ImageTile tile = selectedTiles2[i]; if (rec == null) { rec = new Rectangle2D.Float(tile.getLRLon(), tile.getLRLat(), 0f, 0f); rec.add(tile.getULLon(), tile.getULLat()); } else { rec.add(tile.getULLon(), tile.getULLat()); rec.add(tile.getLRLon(), tile.getLRLat()); } } if (rec != null) { LatLonPoint center = new LatLonPoint(rec.getCenterY(), rec.getCenterX()); LatLonPoint anchor1 = new LatLonPoint(rec.getMaxY(), rec.getMinX()); LatLonPoint anchor2 = new LatLonPoint(rec.getMinY(), rec.getMaxX()); Proj proj = (Proj) mapBean.getProjection(); float scale = com.bbn.openmap.proj.ProjMath.getScale(anchor1, anchor2, proj); if (logger.isLoggable(Level.FINE)) { logger.info("Images cover " + anchor1 + " to " + anchor2 + ", scale adjusted to " + scale); } proj.setCenter(center); proj.setScale(scale); mapBean.setProjection(proj); } } } } /** * Note the provided tiles as being highlighted. Selection, in this case, * means the OMGraphic selection. * * @param selectedTiles2 */ protected void select(ImageTile[] selectedTiles2) { setSelection(selectedTiles2, true); } /** * Note the provided tiles as being highlighted or not. Selection, in this * case, means the OMGraphic selection. * * @param selectedTiles2 */ protected void setSelection(ImageTile[] selectedTiles2, boolean isSelected) { for (int i = 0; i < selectedTiles2.length; i++) { selectedTiles2[i].setSelected(isSelected); } repaint(); } /** * Un-highlight all of the tiles. */ public void deselect() { OMGraphicList list = getList(); if (list != null) { for (Iterator it = list.iterator(); it.hasNext();) { ((OMGraphic) it.next()).setSelected(false); } repaint(); } } /** * Take the drawing attributes held by the layer and push the settings on * all of the ImageTiles. */ public void resetSelectAttributes() { OMGraphicList list = getList(); if (list != null) { for (Iterator it = list.iterator(); it.hasNext();) { selectedDrawingAttributes.setTo((OMGraphic) it.next()); } repaint(); } } /** * Remove the selected tiles from the image stack. Asks the user for * confirmation. * * @param selectedTiles2 */ protected void removeImages(ImageTile[] selectedTiles2) { ImageTile[] selectedTiles = getSelectedTiles(); if (selectedTiles != null && selectedTiles.length > 0) { String confirmStringMulti = i18n.get(ImageTileLayer.class, "removeConfirmMultiple", "Are you sure you want to remove these images from the layer?"); String confirmStringSolo = i18n.get(ImageTileLayer.class, "removeConfirmSolo", "Are you sure you want to remove this image from the layer?"); String confirmTitleString = i18n.get(ImageTileLayer.class, "removeConfirmTitle", "Remove Images?"); int answer = JOptionPane.showConfirmDialog(this, (selectedTiles.length == 1 ? confirmStringSolo : confirmStringMulti), confirmTitleString, JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.YES_OPTION) { OMGraphicList list = getList(); if (list != null) { for (int i = 0; i < selectedTiles.length; i++) { ImageTile selectedTile = selectedTiles[i]; list.remove(selectedTile); ((DefaultListModel) getListModel()).removeElement(selectedTile); } if (resultsList != null) { resultsList.repaint(); } repaint(); } } } } /** * Asks the user to choose a new file or directory to load. The * ImageReaderLoaders are consulted to only allow files that can be handled * to be selectable. */ protected void addNewImagesWithFileChooser() { // Need to get File Chooser, and allow the user to add a directory or // file. We could even set up filters to check the ImageReaderLoaders // available to this Layer and limit file selection based on matches. We // should also report to the user what files were loaded using a dialog // window, // or we could simply select the new images and scroll the list to make // those images visible. File startingPoint = new File(Environment.get("lastchosendirectory", System.getProperty("user.home"))); JFileChooser chooser = new JFileChooser(startingPoint); String title = i18n.get(ImageTileLayer.class, "addImagesWindowTitle", "Add Images"); chooser.setDialogTitle(title); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooser.setFileFilter(new ImageLoaderFileFilter(imageReaderLoaders)); String acceptButtonText = i18n.get(ImageTileLayer.class, "acceptButtonText", "Add"); int state = chooser.showDialog(null, acceptButtonText); try { // only bother trying to read the file if there is one // for some reason, the APPROVE_OPTION said it was a // boolean during compile and didn't work in this next // statement if ((state != JFileChooser.CANCEL_OPTION) && (state != JFileChooser.ERROR_OPTION)) { String newFile = chooser.getSelectedFile().getCanonicalPath(); int dirIndex = newFile.lastIndexOf(File.separator); if (dirIndex >= 0) { // store the selected file for later Environment.set("lastchosendirectory", newFile.substring(0, dirIndex)); } OMGraphicList list = getList(); if (list == null) { list = new OMGraphicList(); setList(list); } LoadImageThread lit = new LoadImageThread(newFile, list); lit.start(); } } catch (IOException ioe) { JOptionPane.showMessageDialog(null, ioe.getMessage(), "Error picking file", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } } /** * A special Thread subclass to handle image loading, so it's not managed by * the AWT thread. * * @author dietrick */ class LoadImageThread extends Thread { String fileToOpen; OMGraphicList listToAddTo; public LoadImageThread(String fto, OMGraphicList ltat) { fileToOpen = fto; listToAddTo = ltat; } public void run() { loadImage(fileToOpen, listToAddTo); fireStatusUpdate(LayerStatusEvent.FINISH_WORKING); } } /** * Set the GUI button state to be enabled or not based on something on the * list being selected. * * @param somethingSelected whether something is selected. */ protected void setGUIButtonEnableState(boolean somethingSelected) { if (icbp != null) { icbp.setGUIButtonEnableState(somethingSelected); showHideButton.setEnabled(somethingSelected); gotoButton.setEnabled(somethingSelected); locateButton.setEnabled(somethingSelected); } } /** * The ListModel used by the JList, displaying the images. * * @return */ protected synchronized ListModel getListModel() { if (listModel == null) { listModel = new DefaultListModel(); } return listModel; } /** * Add an ImageTile to the list model. * * @param tile */ protected void addImageTileToList(ImageTile tile) { ((DefaultListModel) getListModel()).addElement(tile); } /** * Clear the list model. */ protected void clearImageTileList() { ((DefaultListModel) getListModel()).clear(); } /** * Remove an ImageTile from the ListModel. * * @param tile * @return */ protected boolean removeImageTileFromList(ImageTile tile) { return ((DefaultListModel) getListModel()).removeElement(tile); } /** * Rebuild the list model contents based on the ImageTiles contained on the * OMGraphicList. * */ protected void rebuildListModel() { DefaultListModel dlm = (DefaultListModel) getListModel(); OMGraphicList list = getList(); int[] selectedIndicies = null; boolean checkForIndicies = false; if (list != null) { if (selectedTiles != null && selectedTiles.length > 0) { selectedIndicies = new int[selectedTiles.length]; checkForIndicies = true; } int tileCount = 0; for (Iterator it = list.iterator(); it.hasNext(); tileCount++) { ImageTile imageTile = (ImageTile) it.next(); if (checkForIndicies) { for (int i = 0; i < selectedTiles.length; i++) { if (imageTile == selectedTiles[i]) { for (int j = 0; j < selectedIndicies.length; j++) { selectedIndicies[j] = tileCount + j; } checkForIndicies = false; } } } } // Causes value changed() to be called, which then unsets selected // tiles. So we need to find out which tiles were selected above, // and then set them again later. dlm.clear();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?