Search in sources :

Example 1 with MechView

use of megamek.common.MechView in project megameklab by MegaMek.

the class MenuBarCreator method jMenuExportEntityText_actionPerformed.

public void jMenuExportEntityText_actionPerformed(ActionEvent event) {
    if (UnitUtil.validateUnit(parentFrame.getEntity()).length() > 0) {
        JOptionPane.showMessageDialog(parentFrame, "Warning: exporting an invalid unit!");
    }
    String unitName = parentFrame.getEntity().getChassis() + " " + parentFrame.getEntity().getModel();
    MechView mview = new MechView(parentFrame.getEntity(), true, true, false);
    FileDialog fDialog = new FileDialog(parentFrame, "Save As", FileDialog.SAVE);
    String filePathName = new File(System.getProperty("user.dir").toString()).getAbsolutePath();
    fDialog.setDirectory(filePathName);
    fDialog.setFile(unitName + ".txt");
    fDialog.setLocationRelativeTo(parentFrame);
    fDialog.setVisible(true);
    if (fDialog.getFile() != null) {
        filePathName = fDialog.getDirectory() + fDialog.getFile();
    } else {
        return;
    }
    try {
        FileOutputStream out = new FileOutputStream(filePathName);
        PrintStream p = new PrintStream(out);
        p.println(mview.getMechReadout());
        p.close();
        out.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : PrintStream(java.io.PrintStream) MechView(megamek.common.MechView) FileOutputStream(java.io.FileOutputStream) FileDialog(java.awt.FileDialog) File(java.io.File) BLKFile(megamek.common.loaders.BLKFile)

Example 2 with MechView

use of megamek.common.MechView in project megameklab by MegaMek.

the class MenuBarCreator method jMenuExportEntityClipboard_actionPerformed.

public void jMenuExportEntityClipboard_actionPerformed(ActionEvent event) {
    MechView mview = new MechView(parentFrame.getEntity(), true, true, false);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection stringSelection = new StringSelection(mview.getMechReadout());
    clipboard.setContents(stringSelection, this);
}
Also used : MechView(megamek.common.MechView) Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 3 with MechView

use of megamek.common.MechView in project megameklab by MegaMek.

the class PreviewTab method refresh.

public void refresh() {
    boolean populateTextFields = true;
    MechView mechView = null;
    try {
        mechView = new MechView(getInfantry(), false);
    } catch (Exception e) {
        e.printStackTrace();
        // error unit didn't load right. this is bad news.
        populateTextFields = false;
    }
    if (populateTextFields && (mechView != null)) {
        panelMekView.setMech(getInfantry());
    } else {
        panelMekView.reset();
    }
}
Also used : MechView(megamek.common.MechView)

Example 4 with MechView

use of megamek.common.MechView in project megameklab by MegaMek.

the class PreviewTab method refresh.

public void refresh() {
    boolean populateTextFields = true;
    MechView mechView = null;
    try {
        mechView = new MechView(getBattleArmor(), false);
    } catch (Exception e) {
        e.printStackTrace();
        // error unit didn't load right. this is bad news.
        populateTextFields = false;
    }
    if (populateTextFields && (mechView != null)) {
        panelMekView.setMech(getBattleArmor());
    } else {
        panelMekView.reset();
    }
}
Also used : MechView(megamek.common.MechView)

Example 5 with MechView

use of megamek.common.MechView in project megameklab by MegaMek.

the class MenuBarCreator method jMenuExportEntityHTML_actionPerformed.

public void jMenuExportEntityHTML_actionPerformed(ActionEvent event) {
    if (UnitUtil.validateUnit(parentFrame.getEntity()).length() > 0) {
        JOptionPane.showMessageDialog(parentFrame, "Warning: exporting an invalid unit!");
    }
    String unitName = parentFrame.getEntity().getChassis() + " " + parentFrame.getEntity().getModel();
    MechView mview = new MechView(parentFrame.getEntity(), false);
    FileDialog fDialog = new FileDialog(parentFrame, "Save As", FileDialog.SAVE);
    String filePathName = new File(System.getProperty("user.dir").toString()).getAbsolutePath();
    fDialog.setDirectory(filePathName);
    fDialog.setFile(unitName + ".html");
    fDialog.setLocationRelativeTo(parentFrame);
    fDialog.setVisible(true);
    if (fDialog.getFile() != null) {
        filePathName = fDialog.getDirectory() + fDialog.getFile();
    } else {
        return;
    }
    try {
        FileOutputStream out = new FileOutputStream(filePathName);
        PrintStream p = new PrintStream(out);
        p.println(mview.getMechReadout());
        p.close();
        out.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : PrintStream(java.io.PrintStream) MechView(megamek.common.MechView) FileOutputStream(java.io.FileOutputStream) FileDialog(java.awt.FileDialog) File(java.io.File) BLKFile(megamek.common.loaders.BLKFile)

Aggregations

MechView (megamek.common.MechView)10 FileDialog (java.awt.FileDialog)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 PrintStream (java.io.PrintStream)2 LocationFullException (megamek.common.LocationFullException)2 BLKFile (megamek.common.loaders.BLKFile)2 Dimension (java.awt.Dimension)1 Clipboard (java.awt.datatransfer.Clipboard)1 StringSelection (java.awt.datatransfer.StringSelection)1 JDialog (javax.swing.JDialog)1 JEditorPane (javax.swing.JEditorPane)1 JScrollPane (javax.swing.JScrollPane)1 DefaultCaret (javax.swing.text.DefaultCaret)1 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)1