You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

480 lines
24 KiB
Java

/*
* Copyright (c) 2015, Netsyms Technologies
* All rights reserved.
*
*
* CODE LICENSE ==========
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* 4. You adhere to the Media License detailed below. If you do not, this license
* is automatically revoked and you must purge all copies of the software you
* possess, in source or binary form.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* MEDIA LICENSE ==========
* All images and other graphical files ("media") included with this
* software are copyright (c) 2015 Netsyms Technologies. You may not distribute
* the graphics or any program, source code repository, or other digital storage
* media containing them without permission from Netsyms Technologies.
* This ban on distribution only applies to publicly available systems.
* A password-protected network file share, USB drive, or other storage scheme that
* cannot be easily accessed by the public is generally allowed. If in doubt,
* contact Netsyms Technologies. If Netsyms Technologies allows or denies
* you permission, that decision is considered final and binding.
*
* You may only use the media for personal,
* non-commercial, non-educational use unless:
* 1, You have paid for the software and media via the SyMAT website,
* or 2, you are using it as part of the 15-day trial period.
* Other uses are prohibited without permission.
* If any part of this license is deemed unenforcable, the remainder
* of the license remains in full effect.
*/
package net.apocalypselabs.symat;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
import net.apocalypselabs.symat.plugin.Plugin;
/**
*
* @author Skylar
*/
public class PackagePlugin extends javax.swing.JInternalFrame {
private final JFileChooser fcimg = new JFileChooser();
private final JFileChooser fcexp = new JFileChooser();
private ImageIcon icon;
/**
*
* @param code
* @param lang
*/
public PackagePlugin(String code, int lang) {
this();
try {
icon = new ImageIcon(
ImageIO.read(PackagePlugin.class.getResource("images/plugin.png")));
} catch (IOException ex) {
Debug.stacktrace(ex);
}
langSelect.setSelectedIndex(lang);
codeBox.setText(code);
iconPreview.setIcon(icon);
}
/**
* Creates new form PackagePlugin
*/
public PackagePlugin() {
fcimg.setFileFilter(new FileNameExtensionFilter(
"Image (jpeg,jpg,gif,png,bmp)",
"jpeg", "jpg", "gif", "png", "bmp"));
fcexp.setFileFilter(new FileNameExtensionFilter(
"Plugin (sypl)",
"sypl"));
initComponents();
author.setText(PrefStorage.getSetting("author"));
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jTabbedPane1 = new javax.swing.JTabbedPane();
jPanel1 = new javax.swing.JPanel();
pluginName = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
packageID = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
website = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
author = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
version = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
shortDesc = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
longDesc = new javax.swing.JTextArea();
jPanel4 = new javax.swing.JPanel();
jLabel9 = new javax.swing.JLabel();
iconPreview = new javax.swing.JLabel();
openIconBtn = new javax.swing.JButton();
jLabel10 = new javax.swing.JLabel();
defaultIconBtn = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jLabel8 = new javax.swing.JLabel();
langSelect = new javax.swing.JComboBox();
jScrollPane2 = new javax.swing.JScrollPane();
codeBox = new javax.swing.JTextArea();
jPanel3 = new javax.swing.JPanel();
savePlugin = new javax.swing.JButton();
setClosable(true);
setIconifiable(true);
setTitle("Package Plugin");
setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/net/apocalypselabs/symat/icons/plugins.png"))); // NOI18N
jLabel1.setText("Plugin Name:");
jLabel2.setText("Package ID:");
jLabel3.setText("Website:");
jLabel4.setText("Author:");
jLabel5.setText("Version:");
jLabel6.setText("Description:");
jLabel7.setText("Long Description:");
longDesc.setColumns(20);
longDesc.setRows(5);
jScrollPane1.setViewportView(longDesc);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel7)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(website, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(version, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(pluginName)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(author))
.addComponent(packageID)
.addComponent(shortDesc))))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(pluginName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addComponent(author, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(packageID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(website, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(version, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(shortDesc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
.addContainerGap())
);
jTabbedPane1.addTab("Metadata", jPanel1);
jLabel9.setText("Icon:");
iconPreview.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
iconPreview.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
openIconBtn.setText("Open icon...");
openIconBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
openIconBtnActionPerformed(evt);
}
});
jLabel10.setText("Recommended icon size is 100x76.");
jLabel10.setVerticalAlignment(javax.swing.SwingConstants.TOP);
defaultIconBtn.setText("Use default");
defaultIconBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
defaultIconBtnActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(iconPreview, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(openIconBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(defaultIconBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addComponent(jLabel9))
.addGap(0, 181, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(openIconBtn)
.addGap(18, 18, 18)
.addComponent(defaultIconBtn))
.addComponent(iconPreview, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)
.addContainerGap())
);
jTabbedPane1.addTab("Icon", jPanel4);
jLabel8.setText("Language:");
langSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "JavaScript", "Python", "Java" }));
codeBox.setColumns(20);
codeBox.setRows(5);
jScrollPane2.setViewportView(codeBox);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(langSelect, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(langSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)
.addContainerGap())
);
jTabbedPane1.addTab("Code", jPanel2);
savePlugin.setText("Save Plugin");
savePlugin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
savePluginActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(savePlugin, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(235, Short.MAX_VALUE))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(savePlugin, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(131, Short.MAX_VALUE))
);
jTabbedPane1.addTab("Publish", jPanel3);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTabbedPane1)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTabbedPane1)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void savePluginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_savePluginActionPerformed
Plugin p = new Plugin();
try {
p.setTitle(pluginName.getText());
p.setAuthor(author.getText());
p.setLongTitle(shortDesc.getText());
p.setDesc(longDesc.getText());
p.setPackage(packageID.getText());
p.setVersion(version.getText());
p.setWebsite(website.getText());
p.setLang(langSelect.getSelectedIndex());
p.setScript(codeBox.getText());
p.setIcon(icon);
if (p.getTitle().equals("")
|| p.getAuthor().equals("")
|| p.getPackage().equals("")
|| p.getVersion().equals("")
|| p.getScript().equals("")
|| p.getIcon() == null) {
throw new Exception("One or more required fields are empty.");
}
} catch (Exception ex) {
Debug.stacktrace(ex);
JOptionPane.showInternalMessageDialog(this,
"Error. Please check your data.\n\n" + ex.getMessage());
return;
}
int result = fcexp.showDialog(this, "Publish");
if (result == JFileChooser.APPROVE_OPTION) {
try {
FileOutputStream fout = new FileOutputStream(FileUtils.getFileWithExtension(fcexp));
try (ObjectOutputStream oos = new ObjectOutputStream(fout)) {
oos.writeObject(p);
oos.close();
}
JOptionPane.showInternalMessageDialog(this,
"Publish complete!");
} catch (Exception ex) {
Debug.stacktrace(ex);
JOptionPane.showInternalMessageDialog(this,
"Error saving file.\n\n" + ex.getMessage());
}
}
}//GEN-LAST:event_savePluginActionPerformed
private void openIconBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openIconBtnActionPerformed
int result = fcimg.showDialog(this, "Select Icon");
if (result == JFileChooser.APPROVE_OPTION) {
try {
icon = new ImageIcon(ImageIO.read(fcimg.getSelectedFile()));
iconPreview.setIcon(icon);
} catch (Exception ex) {
Debug.stacktrace(ex);
JOptionPane.showInternalMessageDialog(this,
"Error opening image.\n\n" + ex.getMessage());
}
}
}//GEN-LAST:event_openIconBtnActionPerformed
private void defaultIconBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultIconBtnActionPerformed
try {
icon = new ImageIcon(
ImageIO.read(PackagePlugin.class.getResource("images/plugin.png")));
iconPreview.setIcon(icon);
} catch (IOException ex) {
Debug.stacktrace(ex);
JOptionPane.showInternalMessageDialog(this,
"Error opening default icon.\n\n" + ex.getMessage());
}
}//GEN-LAST:event_defaultIconBtnActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField author;
private javax.swing.JTextArea codeBox;
private javax.swing.JButton defaultIconBtn;
private javax.swing.JLabel iconPreview;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JComboBox langSelect;
private javax.swing.JTextArea longDesc;
private javax.swing.JButton openIconBtn;
private javax.swing.JTextField packageID;
private javax.swing.JTextField pluginName;
private javax.swing.JButton savePlugin;
private javax.swing.JTextField shortDesc;
private javax.swing.JTextField version;
private javax.swing.JTextField website;
// End of variables declaration//GEN-END:variables
}