📄 bsmapeditwindow.java
字号:
BSChooseJIDDialog dlg = new BSChooseJIDDialog(
docked? ((BSMapWinManager)winMan).mainFrame : frame,
"Add buddy", ((BSMapWinManager)winMan).getRoster());
dlg.setVisible(true);
if (dlg.jid != null)
mapView.addBuddy(dlg.jid);
}
public void setClusterName(String defaultName) {
BSNameDialog dlg = new BSNameDialog(
docked? ((BSMapWinManager)winMan).mainFrame : frame,
"Set cluster name", defaultName);
dlg.setVisible(true);
if (dlg.name != null)
mapView.setClusterName(dlg.name);
}
protected String getImgName() {
JFileChooser fileChooser = new JFileChooser(mapView.getMapPath());
fileChooser.setFileFilter(new ImageFilter());
fileChooser.setDialogTitle("Choose image");
if (JFileChooser.APPROVE_OPTION ==
fileChooser.showOpenDialog(docked? ((BSMapWinManager)winMan).mainFrame : frame)) {
File imgFile = fileChooser.getSelectedFile();
String imgName = imgFile.getName();
if (!FileCopier.copyFile(imgFile,
new File(mapView.getMapPath() + "/" + mapView.getOriginID()
+ "/" + imgName))) {
JOptionPane.showMessageDialog(docked? ((BSMapWinManager)winMan).mainFrame : frame,
"Copying image file failed",
"Set bitmap error",
JOptionPane.ERROR_MESSAGE);
return null;
}
return imgName;
}
else
return null;
}
public void setImg() {
if (!mapView.isSelectedLayerEditable()) {
JOptionPane.showMessageDialog(docked? ((BSMapWinManager)winMan).mainFrame : frame,
"Cannot change referenced map",
"Set bitmap error",
JOptionPane.ERROR_MESSAGE);
return;
}
String imgName = getImgName();
if (imgName == null)
return;
mapView.setImg(imgName, "100", "100");
}
public void setLayer() {
/*if (!mapView.isSelectedTopLevelLayer()) {
JOptionPane.showMessageDialog(docked? winMan.mainFrame : frame,
"Cannot change referenced map",
"Set priority error",
JOptionPane.ERROR_MESSAGE);
return;
}*/
LayerTag layer = mapView.getSelectedLayer();
if (layer == null) return;
BSLayerDialog dlg = new BSLayerDialog(
docked? ((BSMapWinManager)winMan).mainFrame : frame,
layer.getOffsetXInt(), layer.getOffsetYInt(),
layer.getScaleFloat(),
0, 20, layer.getPriorityInt());
dlg.show();
if (dlg.confirmed)
mapView.setLayerProperties(dlg.offsetX, dlg.offsetY, dlg.scale,
dlg.priority);
}
public void deleteLayer() {
LayerTag layer = mapView.getSelectedLayer();
if (layer == null) return;
/*if (!mapView.isSelectedTopLevelLayer()) {
JOptionPane.showMessageDialog(docked? winMan.mainFrame : frame,
"Cannot change referenced map",
"Set priority error",
JOptionPane.ERROR_MESSAGE);
return;
}*/
mapView.deleteLayer();
}
public void addLayer() {
Object[] options = {"Add inline layer",
"Add referenced map",
"Cancel"};
int result = JOptionPane.showOptionDialog(
this,
"Do you want to define a new layer directly in this map\n "
+ "or add a layer referencing an existing map file?",
"Add new layer",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, options, options[1]);
if (result == 1)
addInsetMap();
else if (result == 0)
addInlineLayer();
}
public void addInsetMap() {
// gets the file of map for the new layer
JFileChooser fileChooser = new JFileChooser(mapView.getMapPath());
fileChooser.setFileFilter(new BSMapFilter());
fileChooser.setDialogTitle("Open map");
if (JFileChooser.APPROVE_OPTION ==
fileChooser.showOpenDialog(docked? ((BSMapWinManager)winMan).mainFrame : frame)) {
File mapFile = fileChooser.getSelectedFile();
String mapName = mapFile.getName();
// copies the map file into working directory
if (!FileCopier.copyFile(mapFile,
new File(mapView.getMapPath() + "/" + mapView.getOriginID()
+ "/" + mapName))) {
JOptionPane.showMessageDialog(docked? ((BSMapWinManager)winMan).mainFrame : frame,
"Copying map file failed",
"Add map error",
JOptionPane.ERROR_MESSAGE);
return;
}
// reads the inserted map
String mapOrigin = mapFile.getParentFile().getName();
MapTag newMap = ((BSMapWinManager)winMan).getMap(mapOrigin, mapName);
if (newMap == null) {
JOptionPane.showMessageDialog(docked? ((BSMapWinManager)winMan).mainFrame : frame,
"Specified file is not valid map",
"Add map error",
JOptionPane.ERROR_MESSAGE);
return;
}
// copies all necessary referenced files into working directory
if (!((BSMapWinManager)winMan).copyFilesForMap(newMap, mapOrigin, mapView.getOriginID())) {
JOptionPane.showMessageDialog(docked? ((BSMapWinManager)winMan).mainFrame : frame,
"Could not copy all referenced files",
"Add map error",
JOptionPane.ERROR_MESSAGE);
return;
}
// adds the new map into the editted one
mapView.addMap(newMap);
initLayersComboBox();
}
}
/** Adds a new inline defined layer. */
public void addInlineLayer() {
String imgName = getImgName();
if (imgName == null)
return;
mapView.addLayerWithImg(imgName, "100", "100");
initLayersComboBox();
}
/** Sends the map to given JID. Calls BSMapWinManager method. */
public void sendMap(JID jid, String subject, String body) {
((BSMapWinManager)winMan).sendMap(mapView.getMapID(), mapView.getOriginID(), jid, subject, body);
}
/** Saves the map using given new originID and mapID.
* Calls BSMapWinManager method. */
public void saveMapAs(String originID, String mapID,
String newOriginID, String newMapID) {
((BSMapWinManager)winMan).saveMap(originID, mapID, newOriginID, newMapID);
MapTag map = ((BSMapWinManager)winMan).getMap(newOriginID, newMapID);
// copies all necessary referenced files into working directory
if (!((BSMapWinManager)winMan).copyFilesForMap(map, originID, newOriginID)) {
JOptionPane.showMessageDialog(docked? ((BSMapWinManager)winMan).mainFrame : frame,
"Could not copy all referenced files",
"Add map error",
JOptionPane.ERROR_MESSAGE);
return;
}
}
/** Opens chat with given JID. Calls BSMapWinManager method. */
public void openChat(JID jid) {
((BSMapWinManager)winMan).openChat(jid);
}
/** Sends file to JID. Calls BSMapWinManager method. */
public void sendFile(JID jid) {
((BSMapWinManager)winMan).sendFile(jid);
}
/** Sends subscription request to JID. Calls BSMapWinManager method. */
public void sendSubscriptionRequest(JID jid) {
((BSMapWinManager)winMan).sendSubscriptionRequest(jid);
}
/** Returns ID of the map */
public String getMapID() {
if (mapView == null) return "";
return mapView.getMapID();
}
/** Returns origin ID of the map */
public String getOriginID() {
if (mapView == null) return "";
return mapView.getOriginID();
}
public void cancelListening() {
/*if (mapView != null)
mapView.cancelListening();*/
}
public void itemStateChanged(ItemEvent itemEvent) {
if (itemEvent.getStateChange() == ItemEvent.SELECTED) {
String layerName = (String) itemEvent.getItem();
if (!dontSetLayer)
setSelectedLayer(layerName);
}
}
public void setSelectedLayer(String layerName) {
if (!dontSetLayer) {
dontSetLayer = true;
if (layersComboBox != null)
layersComboBox.setSelectedItem(layerName);
if (mapView != null)
mapView.setSelectedLayer(layerName);
dontSetLayer = false;
}
}
public void setDocked(boolean docked, boolean select) {
super.setDocked(docked, select);
if (!docked)
frame.pack();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -