Skip to content

Commit

Permalink
Zaczynamy preferencje...
Browse files Browse the repository at this point in the history
  • Loading branch information
szmurlor committed May 5, 2015
1 parent 2235b12 commit 3a6de82
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/gui/CicuitSimulatorMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,28 @@ public void actionPerformed(ActionEvent actionEvent) {
}
}

} else if (actionEvent.getActionCommand().equals("exportNgSpice")) {
JFileChooser jfChooser = new JFileChooser();
jfChooser.setFileFilter(new FileNameExtensionFilter("NgSpice script (*.cir)","cir"));
jfChooser.setCurrentDirectory(lastFile);

int ret = jfChooser.showSaveDialog(rootPanel);
if (ret == JFileChooser.APPROVE_OPTION) {
lastFile = jfChooser.getSelectedFile();

CircuitSimulatorWriter csw = new CircuitSimulatorWriter();
try {
csw.writeNgSpice(jfChooser.getSelectedFile(), circuitPanel.getCircuitComponents(), circuitPanel.getCircuitConnnections());
} catch (IOException e) {
int mc = JOptionPane.ERROR_MESSAGE;
JOptionPane.showMessageDialog(null, "Podczas eksportu skryptu NgSpice wystąpił błąd: " + e.getMessage(), "Błąd zapisu", mc);
}
}

} else if (actionEvent.getActionCommand().equals("preferences")) {
PreferencesDialog pd = new PreferencesDialog();
pd.pack();
pd.setVisible(true);
}
}

Expand Down Expand Up @@ -160,12 +182,31 @@ public JMenuBar createMenu() {

menu.addSeparator();

item = new JMenuItem("Eksportuj do NgSpice");
item.setActionCommand("exportNgSpice");
item.addActionListener(this);
menu.add(item);

menu.addSeparator();

item = new JMenuItem("Zakończ");
item.setActionCommand("exit");
item.addActionListener(this);
menu.add(item);

menuBar.add(menu);

menu = new JMenu("Symulacja");

item = new JMenuItem("Preferencje");
item.setActionCommand("preferences");
item.addActionListener(this);

menu.add(item);

menuBar.add(menu);


return menuBar;
}
}
98 changes: 98 additions & 0 deletions src/gui/PreferencesDialog.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="gui.PreferencesDialog">
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="48" y="54" width="436" height="297"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<hspacer id="98af6">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="OK"/>
</properties>
</component>
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Cancel"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="e3588" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="304b7" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Plik wykonywalny NgSpice:"/>
</properties>
</component>
<hspacer id="f93e1">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<vspacer id="3d3d8">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="e6c91" class="javax.swing.JTextField" binding="txtNgSpiceExe">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="6197c" class="javax.swing.JButton" binding="cmdNgSpiceExe">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="..."/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>
66 changes: 66 additions & 0 deletions src/gui/PreferencesDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package gui;

import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.event.*;

public class PreferencesDialog extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JTextField txtNgSpiceExe;
private JButton cmdNgSpiceExe;

public PreferencesDialog() {
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);

buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});

buttonCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
});

// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}
});

// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
cmdNgSpiceExe.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
JFileChooser fc = new JFileChooser();
fc.addChoosableFileFilter(new FileNameExtensionFilter("NgSpice executable (*.exe)", "exe"));
if (fc.showOpenDialog(PreferencesDialog.this) == JFileChooser.APPROVE_OPTION) {
txtNgSpiceExe.setText( fc.getSelectedFile().getAbsolutePath() );
}
}
});
}

private void onOK() {
// add your code here
dispose();
}

private void onCancel() {
// add your code here if necessary
dispose();
}
}

0 comments on commit 3a6de82

Please sign in to comment.