Created
June 24, 2012 22:00
-
-
Save michalkozminski/2985172 to your computer and use it in GitHub Desktop.
Java GUI with JRuby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'java' | |
require 'forms-1.3.0.jar' | |
require 'miglayout15-swing.jar' | |
include_class "net.miginfocom.swing.MigLayout" | |
include_class 'javax.swing.AbstractAction' | |
include_class 'javax.swing.Action' | |
require 'gui.jar' | |
class Gui < Java::Gui | |
def jRubyAcion | |
puts "it works" | |
end | |
end | |
Gui.main([]) | |
class SaveProject | |
def self.perform | |
end | |
def initialize(inputs) | |
@inputs = inputs | |
end | |
end | |
class OpenProject | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.EventQueue; | |
public class Gui { | |
private JFrame frmWebappswordSdk; | |
private JTextField nameField; | |
private JPanel submodulesPanel; | |
private JComboBox langBox; | |
private ArrayList<JCheckBox> methods = new ArrayList<JCheckBox>(); | |
private ArrayList<JComboBox> submodules = new ArrayList<JComboBox>(); | |
private final Action action = new SwingAction(); | |
/** | |
* Launch the application. | |
*/ | |
public static void main(String[] args) { | |
EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
try { | |
Gui window = new Gui(); | |
window.frmWebappswordSdk.setVisible(true); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
}); | |
} | |
/** | |
* Create the application. | |
*/ | |
public Gui() { | |
initialize(); | |
} | |
/** | |
* Initialize the contents of the frame. | |
*/ | |
private void initialize() { | |
frmWebappswordSdk = new JFrame(); | |
frmWebappswordSdk.setTitle("App"); | |
frmWebappswordSdk.setBounds(100, 100, 478, 348); | |
frmWebappswordSdk.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
frmWebappswordSdk.getContentPane().setLayout(new BorderLayout(0, 0)); | |
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT); | |
frmWebappswordSdk.getContentPane().add(tabbedPane, BorderLayout.CENTER); | |
JPanel info = new JPanel(); | |
tabbedPane.addTab("Info", null, info, null); | |
info.setLayout(new MigLayout("", "[311px][grow]", "[16px][16px][][][grow]")); | |
JLabel nameLabel = new JLabel("Name"); | |
info.add(nameLabel, "flowx,cell 0 0,alignx left"); | |
nameField = new JTextField(); | |
info.add(nameField, "cell 1 0,alignx left"); | |
nameField.setColumns(20); | |
JLabel langLabel = new JLabel("Lang"); | |
info.add(langLabel, "cell 0 1,alignx left"); | |
langBox = new JComboBox(); | |
langBox.setModel(new DefaultComboBoxModel(new String[] {"PHP"})); | |
info.add(langBox, "cell 1 1,growx"); | |
JLabel methodsLabel = new JLabel("Methods"); | |
info.add(methodsLabel, "cell 0 2,alignx left"); | |
JCheckBox methodCheckBox = new JCheckBox("New check box"); | |
info.add(methodCheckBox, "flowy,cell 1 2"); | |
methods.add(methodCheckBox); | |
JCheckBox chckbxNewCheckBox_1 = new JCheckBox("New check box"); | |
info.add(chckbxNewCheckBox_1, "cell 1 2"); | |
methods.add(chckbxNewCheckBox_1); | |
JLabel submodulesLabel = new JLabel("Submodules"); | |
info.add(submodulesLabel, "cell 0 3,alignx left"); | |
JButton addSubmoduleButton = new JButton("+"); | |
addSubmoduleButton.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent arg0) { | |
JComboBox submoduleBox = new JComboBox(); | |
submoduleBox.setModel(new DefaultComboBoxModel(new String[] {"PHP"})); | |
submodulesPanel.add(submoduleBox); | |
submodules.add(submoduleBox); | |
} | |
}); | |
info.add(addSubmoduleButton, "flowx,cell 1 3,aligny baseline"); | |
submodulesPanel = new JPanel(); | |
info.add(submodulesPanel, "cell 1 4,grow"); | |
submodulesPanel.setLayout(new GridLayout(0, 1, 0, 0)); | |
JComboBox submoduleBox = new JComboBox(); | |
submodulesPanel.add(submoduleBox); | |
JPanel installers = new JPanel(); | |
tabbedPane.addTab("Installers", null, installers, null); | |
installers.setLayout(new GridLayout(0, 1, 0, 0)); | |
JTabbedPane installersTabs = new JTabbedPane(JTabbedPane.TOP); | |
installers.add(installersTabs); | |
JEditorPane installersEditor = new JEditorPane(); | |
installersTabs.addTab("New tab", null, installersEditor, null); | |
JPanel validators = new JPanel(); | |
tabbedPane.addTab("Validators", null, validators, null); | |
validators.setLayout(new GridLayout(1, 0, 0, 0)); | |
JEditorPane editorPane_1 = new JEditorPane(); | |
validators.add(editorPane_1); | |
JMenuBar menuBar = new JMenuBar(); | |
frmWebappswordSdk.getContentPane().add(menuBar, BorderLayout.NORTH); | |
JMenu mnFile = new JMenu("File"); | |
menuBar.add(mnFile); | |
JMenuItem mntmNew = new JMenuItem("New"); | |
mnFile.add(mntmNew); | |
JMenuItem mntmSave = new JMenuItem("Save"); | |
mntmSave.setAction(action); | |
mnFile.add(mntmSave); | |
JMenuItem mntmOpen = new JMenuItem("Open"); | |
mnFile.add(mntmOpen); | |
} | |
public void jRubyAcion(){ | |
System.out.print("test"); | |
} | |
private class SwingAction extends AbstractAction { | |
public SwingAction() { | |
putValue(NAME, "Save"); | |
putValue(SHORT_DESCRIPTION, "Some short description"); | |
} | |
public void actionPerformed(ActionEvent e) { | |
jRubyAcion(); | |
Hashtable result = new Hashtable(); | |
result.put("name", nameField.getText()); | |
result.put("lang", langBox.getSelectedItem()); | |
ArrayList<String> submodulesArray = new ArrayList<String>(); | |
for(JComboBox submodule : submodules) | |
submodulesArray.add((String)submodule.getSelectedItem()); | |
ArrayList<String> methodsArray = new ArrayList<String>(); | |
for(JCheckBox method : methods){ | |
if(method.isSelected()) | |
methodsArray.add(method.getText()); | |
} | |
result.put("submodules", submodulesArray); | |
result.put("methods", methodsArray); | |
System.out.print("perform"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment