📄 boardeditor.java
字号:
/** * Saves the board in PNG image format. */ public void boardSaveImage() { if(curfileImage == null) { boardSaveAsImage(); return; } Dialog waitD = new Dialog(this.frame, Messages.getString("BoardEditor.waitDialog.title")); //$NON-NLS-1$ waitD.add(new Label(Messages.getString("BoardEditor.waitDialog.message"))); //$NON-NLS-1$ waitD.setSize(250,130); // move to middle of screen waitD.setLocation( frame.getSize().width / 2 - waitD.getSize().width / 2, frame.getSize().height / 2 - waitD.getSize().height / 2); waitD.setVisible(true); frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); waitD.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // save! int filter = 0; //0 - no filter; 1 - sub; 2 - up int compressionLevel = 9; // 0 to 9 with 0 being no compression PngEncoder png = new PngEncoder( bv.getEntireBoardImage(), PngEncoder.NO_ALPHA, filter, compressionLevel); try { FileOutputStream outfile = new FileOutputStream( curfileImage ); byte[] pngbytes; pngbytes = png.pngEncode(); if (pngbytes == null) { System.out.println("Failed to save board as image:Null image"); //$NON-NLS-1$ } else { outfile.write( pngbytes ); } outfile.flush(); outfile.close(); } catch (IOException e) { e.printStackTrace(); } waitD.setVisible(false); frame.setCursor(Cursor.getDefaultCursor()); } /** * Opens a file dialog box to select a file to save as; * saves the board to the file. */ public void boardSaveAs() { FileDialog fd = new FileDialog(frame, Messages.getString("BoardEditor.saveBoardAs"), FileDialog.SAVE); //$NON-NLS-1$ fd.setDirectory("data" + File.separator + "boards"); //$NON-NLS-1$ //$NON-NLS-2$ fd.setLocation(frame.getLocation().x + 150, frame.getLocation().y + 100); fd.setVisible(true); if(fd.getFile() == null) { // I want a file, y'know! return; } curpath = fd.getDirectory(); curfile = fd.getFile(); // make sure the file ends in board if (!curfile.toLowerCase().endsWith(".board")) { //$NON-NLS-1$ curfile += ".board"; //$NON-NLS-1$ } frame.setTitle(Messages.getString("BoardEditor.title0") + curfile); //$NON-NLS-1$ boardSave(); } /** * Opens a file dialog box to select a file to save as; * saves the board to the file as an image. Useful * for printing boards. */ public void boardSaveAsImage() { FileDialog fd = new FileDialog(frame, Messages.getString("BoardEditor.saveAsImage"), FileDialog.SAVE); //$NON-NLS-1$ // fd.setDirectory("data" + File.separator + "boards"); fd.setLocation(frame.getLocation().x + 150, frame.getLocation().y + 100); // Add a filter for PNG files fd.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return (null != name && name.endsWith(".png")); //$NON-NLS-1$ } }); // use base directory by default fd.setDirectory("."); //$NON-NLS-1$ // Default to the board's name (if it has one). String fileName = null; if (null != curfile && curfile.length() > 0) { fileName = curfile.toUpperCase(); if (fileName.endsWith(".BOARD")) { //$NON-NLS-1$ int length = fileName.length(); fileName = fileName.substring (0, length-6); } fileName = fileName.toLowerCase() + ".png"; //$NON-NLS-1$ fd.setFile (fileName); } // Open the dialog and wait for it's return. fd.setVisible(true); if(fd.getFile() == null) { // I want a file, y'know! return; } curpath = fd.getDirectory(); curfileImage = fd.getFile(); // make sure the file ends in board if (!curfileImage.toLowerCase().endsWith(".png")) { //$NON-NLS-1$ curfileImage += ".png"; //$NON-NLS-1$ } frame.setTitle(Messages.getString("BoardEditor.title0") + curfileImage); //$NON-NLS-1$ boardSaveImage(); } // // ItemListener // public void itemStateChanged(ItemEvent ie) { if (ie.getSource() == lisTerrain) { refreshTerrainFromList(); } else if ( ie.getSource() == cheRoadsAutoExit ) { // Set the new value for the option, and refrest the board. board.setRoadsAutoExit(cheRoadsAutoExit.getState()); bv.updateBoard(); repaintWorkingHex(); } } // // TextListener // public void textValueChanged(TextEvent te) { if (te.getSource() == texElev) { int value; try { value = Integer.parseInt(texElev.getText()); } catch (NumberFormatException ex) { return; } if (value != curHex.getElevation()) { curHex.setElevation(value); repaintWorkingHex(); } } else if (te.getSource() == texTheme) { curHex.setTheme(texTheme.getText()); repaintWorkingHex(); } } /** * Called when the user selects the "Help->About" menu item. */ private void showAbout() { // Do we need to create the "about" dialog? if ( this.about == null ) { this.about = new CommonAboutDialog( this.frame ); } // Show the about dialog. this.about.setVisible(true); } /** * Called when the user selects the "Help->Contents" menu item. */ private void showHelp() { // Do we need to create the "help" dialog? if ( this.help == null ) { File helpfile = new File( "docs", "editor-readme.txt" ); //$NON-NLS-1$ this.help = new CommonHelpDialog( this.frame, helpfile ); } // Show the help dialog. this.help.setVisible(true); } /** * Called when the user selects the "View->Client Settings" menu item. */ private void showSettings() { // Do we need to create the "settings" dialog? if ( this.setdlg == null ) { this.setdlg = new CommonSettingsDialog( this.frame ); } // Show the settings dialog. this.setdlg.setVisible(true); } // // ActionListener // public void actionPerformed(ActionEvent ae) { if (ae.getActionCommand().equalsIgnoreCase("fileBoardNew")) { //$NON-NLS-1$ boardNew(); } else if (ae.getActionCommand().equalsIgnoreCase("fileBoardOpen")) { //$NON-NLS-1$ boardLoad(); } else if (ae.getActionCommand().equalsIgnoreCase("fileBoardSave")) { //$NON-NLS-1$ boardSave(); } else if (ae.getActionCommand().equalsIgnoreCase("fileBoardSaveAs")) { //$NON-NLS-1$ boardSaveAs(); } else if (ae.getActionCommand().equalsIgnoreCase("fileBoardSaveAsImage")) { //$NON-NLS-1$ boardSaveAsImage(); } else if (ae.getSource() == butDelTerrain && lisTerrain.getSelectedItem() != null) { ITerrain toRemove = Terrains.getTerrainFactory().createTerrain(lisTerrain.getSelectedItem()); curHex.removeTerrain(toRemove.getType()); refreshTerrainList(); repaintWorkingHex(); } else if (ae.getSource() == butAddTerrain) { addSetTerrain(); } else if (ae.getSource() == butElevUp && curHex.getElevation() < 9) { curHex.setElevation(curHex.getElevation() + 1); texElev.setText(Integer.toString(curHex.getElevation())); repaintWorkingHex(); } else if (ae.getSource() == butElevDown && curHex.getElevation() > -5) { curHex.setElevation(curHex.getElevation() - 1); texElev.setText(Integer.toString(curHex.getElevation())); repaintWorkingHex(); } else if (ae.getSource() == butTerrExits) { ExitsDialog ed = new ExitsDialog(frame); cheTerrExitSpecified.setState(true); ed.setExits(Integer.parseInt(texTerrExits.getText())); ed.setVisible(true); texTerrExits.setText(Integer.toString(ed.getExits())); addSetTerrain(); } else if (ae.getActionCommand().equalsIgnoreCase("viewMiniMap")) { //$NON-NLS-1$ toggleMap(); } else if (ae.getActionCommand().equals(ClientGUI.VIEW_ZOOM_IN)) { bv.zoomIn(); } else if (ae.getActionCommand().equals(ClientGUI.VIEW_ZOOM_OUT)) { bv.zoomOut(); } else if (ae.getActionCommand().equalsIgnoreCase("helpAbout")) { //$NON-NLS-1$ showAbout(); } else if (ae.getActionCommand().equalsIgnoreCase("helpContents")) { //$NON-NLS-1$ showHelp(); } else if (ae.getActionCommand().equalsIgnoreCase("viewClientSettings")) { //$NON-NLS-1$ showSettings(); } } /** * Displays the currently selected hex picture, in * component form */ private class HexCanvas extends Canvas { public HexCanvas() { super(); setSize(72, 72); } public void paint(Graphics g) { update(g); } public void update(Graphics g) { if(curHex != null) { TilesetManager tm = bv.getTilesetManager(); g.drawImage(tm.baseFor(curHex), 0, 0, this); if (tm.supersFor(curHex) != null) { for (Iterator i = tm.supersFor(curHex).iterator(); i.hasNext();) { g.drawImage((Image)i.next(), 0, 0, this); g.drawString(Messages.getString("BoardEditor.SUPER"), 0, 10); //$NON-NLS-1$ } } g.setFont(new Font("SansSerif", Font.PLAIN, 9)); //$NON-NLS-1$ g.drawString(Messages.getString("BoardEditor.LEVEL") + curHex.getElevation(), 24, 70); //$NON-NLS-1$ } else { g.clearRect(0, 0, 72, 72); } } } /** * @return the frame this is displayed in */ public Frame getFrame() { return frame; } /** Toggles the minimap window Also, toggles the minimap enabled setting */ public void toggleMap() { setMapVisible(!minimapW.isVisible()); } public void setMapVisible(boolean visible) { minimapW.setVisible(visible); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -