use of megamek.common.MechFileParser in project megameklab by MegaMek.
the class MenuBarCreator method jMenuInsertImageFile_actionPerformed.
private void jMenuInsertImageFile_actionPerformed() {
String filePathName = System.getProperty("user.dir").toString() + "/data/mechfiles/";
File unitFile = new File(filePathName);
JFileChooser f = new JFileChooser(filePathName);
f.setLocation(parentFrame.getLocation().x + 150, parentFrame.getLocation().y + 100);
f.setDialogTitle("Load Mech");
f.setDialogType(JFileChooser.OPEN_DIALOG);
f.setMultiSelectionEnabled(false);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Unit Files", "blk", "mtf", "hmp");
// Add a filter for mul files
f.setFileFilter(filter);
int returnVal = f.showOpenDialog(parentFrame);
if ((returnVal != JFileChooser.APPROVE_OPTION) || (f.getSelectedFile() == null)) {
// I want a file, y'know!
return;
}
unitFile = f.getSelectedFile();
try {
Entity tempEntity = new MechFileParser(unitFile).getEntity();
if (UnitUtil.validateUnit(parentFrame.getEntity()).trim().length() > 0) {
JOptionPane.showMessageDialog(parentFrame, "Warning:Invalid unit, it might load incorrectly!");
}
FileDialog fDialog = new FileDialog(parentFrame, "Image Path", FileDialog.LOAD);
if (parentFrame.getEntity().getFluff().getMMLImagePath().trim().length() > 0) {
String fullPath = new File(parentFrame.getEntity().getFluff().getMMLImagePath()).getAbsolutePath();
String imageName = fullPath.substring(fullPath.lastIndexOf(File.separatorChar) + 1);
fullPath = fullPath.substring(0, fullPath.lastIndexOf(File.separatorChar) + 1);
fDialog.setDirectory(fullPath);
fDialog.setFile(imageName);
} else {
fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + "mech" + File.separatorChar);
fDialog.setFile(parentFrame.getEntity().getChassis() + " " + parentFrame.getEntity().getModel() + ".png");
}
fDialog.setLocationRelativeTo(parentFrame);
fDialog.setVisible(true);
if (fDialog.getFile() != null) {
String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath();
relativeFilePath = "." + File.separatorChar + relativeFilePath.substring(new File(System.getProperty("user.dir").toString()).getAbsolutePath().length() + 1);
parentFrame.getEntity().getFluff().setMMLImagePath(relativeFilePath);
BLKFile.encode(unitFile.getAbsolutePath(), tempEntity);
}
} catch (Exception ex) {
}
return;
}
use of megamek.common.MechFileParser in project megameklab by MegaMek.
the class MenuBarCreator method jMenuGetUnitWeightBreakdownFromFile_actionPerformed.
private void jMenuGetUnitWeightBreakdownFromFile_actionPerformed() {
Entity tempEntity = null;
String filePathName = System.getProperty("user.dir").toString() + "/data/mechfiles/";
File unitFile = new File(filePathName);
JFileChooser f = new JFileChooser(filePathName);
f.setLocation(parentFrame.getLocation().x + 150, parentFrame.getLocation().y + 100);
f.setDialogTitle("Choose Unit");
f.setDialogType(JFileChooser.OPEN_DIALOG);
f.setMultiSelectionEnabled(false);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Unit Files", "blk", "mtf", "hmp");
// Add a filter for mul files
f.setFileFilter(filter);
int returnVal = f.showOpenDialog(parentFrame);
if ((returnVal != JFileChooser.APPROVE_OPTION) || (f.getSelectedFile() == null)) {
// I want a file, y'know!
return;
}
unitFile = f.getSelectedFile();
try {
tempEntity = new MechFileParser(unitFile).getEntity();
} catch (Exception ex) {
JOptionPane.showMessageDialog(parentFrame, String.format("Warning:Invalid unit, it might load incorrectly!\n%1$s", ex.getMessage()));
} finally {
UnitUtil.showUnitWeightBreakDown(tempEntity, parentFrame);
}
}
use of megamek.common.MechFileParser in project megameklab by MegaMek.
the class UnitPrintQueueDialog method actionPerformed.
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == bCancel) {
dispose();
}
if (ae.getSource() == bPrint) {
UnitPrintManager.printAllUnits(units, chSinglePrint.isSelected());
dispose();
}
if (ae.getSource().equals(bSelectCache)) {
UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(clientgui);
unitLoadingDialog.setVisible(true);
UnitSelectorDialog viewer = new UnitSelectorDialog(clientgui, unitLoadingDialog, true);
viewer.setVisible(false);
Entity entity = viewer.getChosenEntity();
if (entity != null) {
units.add(entity);
refresh();
}
} else if (ae.getSource().equals(bSelectFile)) {
String filePathName = System.getProperty("user.dir").toString() + "/data/mechfiles/";
JFileChooser f = new JFileChooser(filePathName);
f.setLocation(clientgui.getLocation().x + 150, clientgui.getLocation().y + 100);
f.setDialogTitle("Print Unit File");
f.setMultiSelectionEnabled(true);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Unit Files", "blk", "mtf");
// Add a filter
f.setFileFilter(filter);
int returnVal = f.showOpenDialog(clientgui);
if ((returnVal != JFileChooser.APPROVE_OPTION) || (f.getSelectedFile() == null)) {
// I want a file, y'know!
return;
}
for (File entityFile : f.getSelectedFiles()) {
try {
Entity tempEntity = new MechFileParser(entityFile).getEntity();
units.add(tempEntity);
} catch (Exception ex) {
ex.printStackTrace();
}
}
refresh();
} else if (ae.getSource().equals(bRemove)) {
if (unitList.getSelectedIndices().length > 0) {
for (int pos = unitList.getSelectedIndices().length - 1; pos >= 0; pos--) {
units.remove(unitList.getSelectedIndices()[pos]);
}
refresh();
}
}
}
use of megamek.common.MechFileParser in project megameklab by MegaMek.
the class MenuBarCreator method jMenuGetUnitValidationFromFile_actionPerformed.
private void jMenuGetUnitValidationFromFile_actionPerformed() {
Entity tempEntity = null;
String filePathName = System.getProperty("user.dir").toString() + "/data/mechfiles/";
File unitFile = new File(filePathName);
JFileChooser f = new JFileChooser(filePathName);
f.setLocation(parentFrame.getLocation().x + 150, parentFrame.getLocation().y + 100);
f.setDialogTitle("Choose Unit");
f.setDialogType(JFileChooser.OPEN_DIALOG);
f.setMultiSelectionEnabled(false);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Unit Files", "blk", "mtf", "hmp");
// Add a filter for mul files
f.setFileFilter(filter);
int returnVal = f.showOpenDialog(parentFrame);
if ((returnVal != JFileChooser.APPROVE_OPTION) || (f.getSelectedFile() == null)) {
// I want a file, y'know!
return;
}
unitFile = f.getSelectedFile();
try {
tempEntity = new MechFileParser(unitFile).getEntity();
} catch (Exception ex) {
JOptionPane.showMessageDialog(parentFrame, String.format("Warning:Invalid unit, it might load incorrectly!\n%1$s", ex.getMessage()));
} finally {
UnitUtil.showValidation(tempEntity, parentFrame);
}
}
use of megamek.common.MechFileParser in project megameklab by MegaMek.
the class MenuBarCreator method jMenuGetUnitBVFromFile_actionPerformed.
private void jMenuGetUnitBVFromFile_actionPerformed() {
Entity tempEntity = null;
String filePathName = System.getProperty("user.dir").toString() + "/data/mechfiles/";
File unitFile = new File(filePathName);
JFileChooser f = new JFileChooser(filePathName);
f.setLocation(parentFrame.getLocation().x + 150, parentFrame.getLocation().y + 100);
f.setDialogTitle("Choose Unit");
f.setDialogType(JFileChooser.OPEN_DIALOG);
f.setMultiSelectionEnabled(false);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Unit Files", "blk", "mtf", "hmp");
// Add a filter for mul files
f.setFileFilter(filter);
int returnVal = f.showOpenDialog(parentFrame);
if ((returnVal != JFileChooser.APPROVE_OPTION) || (f.getSelectedFile() == null)) {
// I want a file, y'know!
return;
}
unitFile = f.getSelectedFile();
try {
tempEntity = new MechFileParser(unitFile).getEntity();
} catch (Exception ex) {
JOptionPane.showMessageDialog(parentFrame, String.format("Warning:Invalid unit, it might load incorrectly!\n%1$s", ex.getMessage()));
} finally {
tempEntity.calculateBattleValue(true, true);
UnitUtil.showBVCalculations(tempEntity.getBVText(), parentFrame);
}
}
Aggregations