Initial commit

This commit is contained in:
Zukero
2015-02-23 22:43:19 +01:00
commit 59d8ad1cdb
212 changed files with 29432 additions and 0 deletions

View File

@@ -0,0 +1,143 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import com.gpl.rpg.atcontentstudio.ConfigCache;
public class WorkspaceSelector extends JFrame {
private static final long serialVersionUID = 7518745499760748574L;
public String selected = null;
public WorkspaceSelector() {
super("Select your workspace");
setIconImage(DefaultIcons.getMainIconImage());
//Data
final List<File> workspaces = ConfigCache.getKnownWorkspaces();
final List<String> wsPaths = new ArrayList<String>();
//Active widgets declaration
final JComboBox combo = new JComboBox();
final JButton browse = new JButton("Browse...");
final JButton cancel = new JButton("Cancel");
final JButton ok = new JButton("Ok");
//Widgets behavior
combo.setEditable(true);
for (File f : workspaces) {
String path = f.getAbsolutePath();
wsPaths.add(path);
combo.addItem(path);
}
if (ConfigCache.getLatestWorkspace() != null) {
combo.setSelectedItem(wsPaths.get(workspaces.indexOf(ConfigCache.getLatestWorkspace())));
}
combo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (combo.getSelectedItem() != null) {
ok.setEnabled(true);
}
}
});
ok.setEnabled(ConfigCache.getLatestWorkspace() != null);
ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
WorkspaceSelector.this.selected = (String) combo.getSelectedItem();
WorkspaceSelector.this.dispose();
}
});
cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
WorkspaceSelector.this.selected = null;
WorkspaceSelector.this.dispose();
}
});
browse.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fc;
if(workspaces.isEmpty()) {
fc = new JFileChooser();
} else {
if (ConfigCache.getLatestWorkspace() != null) {
fc = new JFileChooser(ConfigCache.getLatestWorkspace());
} else {
fc = new JFileChooser(workspaces.get(0));
}
}
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setMultiSelectionEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
int result = fc.showSaveDialog(WorkspaceSelector.this);
if (result == JFileChooser.APPROVE_OPTION) {
String selected = fc.getSelectedFile().getAbsolutePath();
for (String s : wsPaths) {
if (s.equals(selected)) {
selected = s;
}
}
combo.setSelectedItem(selected);
}
}
});
//Layout, labels and dialog behavior.
setTitle("Select your workspace");
JPanel dialogPane = new JPanel();
dialogPane.setLayout(new BorderLayout());
dialogPane.add(new JLabel("Workspace : "), BorderLayout.WEST);
dialogPane.add(combo, BorderLayout.CENTER);
dialogPane.add(browse, BorderLayout.EAST);
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.EAST;
c.gridx = 0;
c.gridy = 0;
c.weightx = 1;
buttonPane.add(new JLabel(), c);
c.fill = GridBagConstraints.VERTICAL;
c.weightx = 0;
c.gridx++;
buttonPane.add(cancel, c);
c.gridx++;
buttonPane.add(ok, c);
dialogPane.add(buttonPane, BorderLayout.SOUTH);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setContentPane(dialogPane);
setResizable(false);
}
}