airspacebuilder.java
来自「world wind java sdk 源码」· Java 代码 · 共 1,830 行 · 第 1/5 页
JAVA
1,830 行
this.setSelectionEditing(false); } this.selectedEntry.setSelected(false); } this.selectedEntry = entry; if (this.selectedEntry != null) { this.selectedEntry.setSelected(true); } } protected boolean isSelectionEditing() { return this.selectedEntry != null && this.selectedEntry.isEditing(); } protected void setSelectionEditing(boolean editing) { if (this.selectedEntry == null) { throw new IllegalStateException(); } if (this.selectedEntry.isEditing() == editing) { throw new IllegalStateException(); } this.selectedEntry.setEditing(editing); AirspaceEditor editor = this.selectedEntry.getEditor(); editor.setArmed(editing); if (editing) { this.editorController.setEditor(editor); insertBeforePlacenames(this.getApp().getWwd(), editor); } else { this.editorController.setEditor(null); this.getApp().getWwd().getModel().getLayers().remove(editor); } int index = this.getModel().getIndexForEntry(this.selectedEntry); this.getModel().fireTableRowsUpdated(index, index); } protected void viewSelectionChanged() { int[] indices = this.getView().getSelectedIndices(); if (indices != null) { for (AirspaceEntry entry : this.getEntriesFor(indices)) { this.selectEntry(entry, false); } } this.getApp().getWwd().redraw(); } protected AirspaceEntry[] getSelectedEntries() { int[] indices = this.getView().getSelectedIndices(); if (indices != null) { return this.getEntriesFor(indices); } return new AirspaceEntry[0]; } protected AirspaceEntry[] getEntriesFor(int[] indices) { AirspaceEntry[] entries = new AirspaceEntry[indices.length]; for (int i = 0; i < indices.length; i++) { entries[i] = this.getModel().getEntry(indices[i]); } return entries; } protected AirspaceEntry getEntryFor(Airspace airspace) { for (AirspaceEntry entry : this.getModel().getEntries()) { if (entry.getAirspace() == airspace) { return entry; } } return null; } //protected ToolTip createToolTip(Object object, Point pickPoint) //{ // AirspaceEntry pickedEntry = null; // // if (object instanceof Airspace) // { // pickedEntry = this.getEntryFor((Airspace) object); // } // else if (object instanceof AirspaceControlPoint) // { // pickedEntry = this.getEntryFor(((AirspaceControlPoint) object).getAirspace()); // } // // if (pickedEntry == null) // { // return null; // } // // StringBuilder sb = new StringBuilder(); // sb.append("<html>"); // // if (object instanceof Airspace) // { // if (pickedEntry.toString() != null) // { // sb.append(pickedEntry.toString()); // } // // if (pickedEntry.isEditing()) // { // if (sb.length() > 0) // { // sb.append("<br/>"); // } // // sb.append("<b>Click & Drag to move</b>"); // sb.append("<br/>"); // sb.append("<b>Shift + Click & Drag to raise/lower</b>"); // // if (pickedEntry.getAirspace() instanceof Polygon) // { // sb.append("<br/>"); // sb.append("<b>Alt + Click to add points</b>"); // } // } // } // else //noinspection ConstantConditions // if (object instanceof AirspaceControlPoint) // { // sb.append("<b>Click & Drag to adjust</b>"); // sb.append("<br/>"); // sb.append("<b>Shift + Click & Drag to resize</b>"); // if (pickedEntry.getAirspace() instanceof Polygon) // { // sb.append("<br/>"); // sb.append("<b>Ctrl + Click to delete</b>"); // } // } // // sb.append("</html>"); // // int canvasHeight = this.getApp().getWwd().getHeight(); // Point wwPoint = new Point(pickPoint.x, canvasHeight - pickPoint.y - 1); // // return new ToolTip(sb.toString(), wwPoint, 1.0); //} protected void zoomTo(LatLon latLon, Angle heading, Angle pitch, double zoom) { OrbitView view = (OrbitView) this.getApp().getWwd().getView(); Globe globe = this.getApp().getWwd().getModel().getGlobe(); ViewStateIterator vsi = FlyToOrbitViewStateIterator.createPanToIterator(view, globe, new Position(latLon, 0), heading, pitch, zoom, true); view.stopMovement(); view.applyStateIterator(vsi); } protected void openFromURL() { Object input = JOptionPane.showInputDialog(this.getApp(), "Enter a URL: ", "Open Shapes from URL", JOptionPane.QUESTION_MESSAGE, null, null, null); if (input == null) return; URL url = null; try { url = new URL(input.toString()); } catch (IOException e) { e.printStackTrace(); } if (url != null) { this.openFromURL(url); } } protected void openFromURL(final URL url) { Thread t = new Thread(new Runnable() { public void run() { final ArrayList<Airspace> airspaces = new ArrayList<Airspace>(); try { loadAirspacesFromURL(url, airspaces); } finally { SwingUtilities.invokeLater(new Runnable() { public void run() { setAirspaces(airspaces); setEnabled(true); getApp().setCursor(null); getApp().getWwd().redraw(); } }); } } }); this.setEnabled(false); getApp().setCursor(new Cursor(Cursor.WAIT_CURSOR)); t.start(); } protected void loadAirspacesFromURL(URL url, Collection<Airspace> airspaces) { File file = null; try { file = File.createTempFile("AirspaceBuilder-TempFile", null); InputStream is = url.openStream(); OutputStream os = new FileOutputStream(file); byte[] buffer = new byte[4096]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } is.close(); os.close(); } catch (IOException e) { e.printStackTrace(); } if (file == null) return; try { ZipFile zipFile = new ZipFile(file); ZipEntry entry = null; for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements(); entry = e.nextElement()) { if (entry == null) continue; String name = entry.getName(); name = this.getFileName(name); if (!(name.startsWith("gov.nasa.worldwind.render.airspaces") && name.endsWith(".xml"))) continue; String[] tokens = name.split("-"); try { Class c = Class.forName(tokens[0]); Airspace airspace = (Airspace) c.newInstance(); BufferedReader input = new BufferedReader(new InputStreamReader(zipFile.getInputStream(entry))); String s = input.readLine(); airspace.restoreState(s); airspaces.add(airspace); if (tokens.length >= 2) { airspace.setValue(AVKey.DISPLAY_NAME, tokens[1]); } } catch (Exception ex) { ex.printStackTrace(); } } } catch (IOException e) { e.printStackTrace(); } } protected void openFromFile() { if (this.fileChooser == null) { this.fileChooser = new JFileChooser(); this.fileChooser.setCurrentDirectory(new File(Configuration.getUserHomeDirectory())); } this.fileChooser.setDialogTitle("Choose Airspace File Directory"); this.fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); this.fileChooser.setMultiSelectionEnabled(false); int status = this.fileChooser.showOpenDialog(null); if (status != JFileChooser.APPROVE_OPTION) return; final File dir = this.fileChooser.getSelectedFile(); if (dir == null) return; Thread t = new Thread(new Runnable() { public void run() { final ArrayList<Airspace> airspaces = new ArrayList<Airspace>(); try { File[] files = dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.startsWith("gov.nasa.worldwind.render.airspaces") && name.endsWith(".xml"); } }); for (File file : files) { String[] name = file.getName().split("-"); try { Class c = Class.forName(name[0]); Airspace airspace = (Airspace) c.newInstance(); BufferedReader input = new BufferedReader(new FileReader(file)); String s = input.readLine(); airspace.restoreState(s); airspaces.add(airspace); if (name.length >= 2) { airspace.setValue(AVKey.DISPLAY_NAME, name[1]); } } catch (Exception e) { e.printStackTrace(); } } } finally { SwingUtilities.invokeLater(new Runnable() { public void run()
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?