import java.util.logging.LogRecord;
import java.util.logging.Logger;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import net.pterodactylus.jsite.core.CoreListener;
import net.pterodactylus.jsite.core.JSiteException;
import net.pterodactylus.jsite.core.Node;
+import net.pterodactylus.jsite.core.Project;
import net.pterodactylus.jsite.i18n.I18n;
import net.pterodactylus.jsite.i18n.gui.I18nAction;
-import net.pterodactylus.jsite.project.Project;
import net.pterodactylus.util.image.IconLoader;
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.logging.Logging;
/**
* The Swing user interface.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
public class SwingInterface implements CoreListener, LoggingListener, PropertyChangeListener {
/** The “add project” action. */
private I18nAction addProjectAction;
+ /** The “insert project” actions. */
+ private Map<Project, I18nAction> insertProjectActions = new HashMap<Project, I18nAction>();
+
/** The “clone project” actions. */
private Map<Project, I18nAction> cloneProjectActions = new HashMap<Project, I18nAction>();
/**
* Creates a new swing interface.
- *
+ *
* @param core
* The core to operate on
* @param configDirectory
/**
* Returns the core that is controlled by the Swing interface.
- *
+ *
* @return The core
*/
Core getCore() {
/**
* Returns the main window of the Swing interface.
- *
+ *
* @return The main window
*/
MainWindow getMainWindow() {
/**
* Returns whether the advanced mode is activated.
- *
+ *
* @return <code>true</code> if the advanced mode is activated,
* <code>false</code> if the simple mode is activated
*/
/**
* Returns the “configure” action.
- *
+ *
* @return The “configure” action
*/
I18nAction getConfigureAction() {
/**
* Returns the “import config” action.
- *
+ *
* @return The “import config” action
*/
I18nAction getImportConfigAction() {
/**
* Returns the “quit” action.
- *
+ *
* @return The “quit” action
*/
I18nAction getQuitAction() {
/**
* Returns the “add node” action.
- *
+ *
* @return The “add node” action
*/
I18nAction getAddNodeAction() {
/**
* Returns the “connect to node” action for the given node.
- *
+ *
* @param node
* The node go get the “connect” action for
* @return The “connect to node” action
/**
* Returns the “disconnect from node” action for the given node.
- *
+ *
* @param node
* The node go get the “disconnect” action for
* @return The “disconnect from node” action
/**
* Returns the “edit node” action for the given node.
- *
+ *
* @param node
* The node to edit
* @return The “edit node” action
/**
* Returns the “delete node” action for the given node.
- *
+ *
* @param node
* The node to delete
* @return The “delete node” action
/**
* Returns all language actions.
- *
+ *
* @return All language actions
*/
List<I18nAction> getLanguageActions() {
/**
* Returns the “about” action.
- *
+ *
* @return The “about” action
*/
I18nAction getHelpAboutAction() {
/**
* Returns the “add project” action.
- *
+ *
* @return The “add project” action
*/
I18nAction getAddProjectAction() {
}
/**
+ * Returns the “insert project” action for the given project.
+ *
+ * @param project
+ * The project to get the “insert project” action for
+ * @return The “insert project” action
+ */
+ I18nAction getInsertProjectAction(Project project) {
+ return insertProjectActions.get(project);
+ }
+
+ /**
* Returns the “clone project” action for the given project.
- *
+ *
* @param project
* The project to get the “clone project” action for
* @return The “clone project” action
/**
* Returns the “delete project” action for the given project.
- *
+ *
* @param project
* The project to get the “delete project” action for
* @return The “delete project” action
/**
* Returns all currently configured nodes.
- *
+ *
* @return All configured nodes
*/
List<Node> getNodes() {
/**
* Returns a list of all projects.
- *
+ *
* @return All projects
*/
List<Project> getProjects() {
/**
* Returns the thread pool used for off-thread processes.
- *
+ *
* @return The thread pool
*/
Executor getThreadPool() {
}
};
List<Locale> availableLanguages = I18n.findAvailableLanguages();
- for (final Locale locale: availableLanguages) {
- I18nAction languageAction = new I18nAction("general.language." + locale.getLanguage()) {
+ for (final Locale locale : availableLanguages) {
+ String language = locale.getLanguage();
+ I18nAction languageAction = new I18nAction("general.language." + language, IconLoader.loadIcon("/flag-" + language + ".png")) {
@SuppressWarnings("synthetic-access")
public void actionPerformed(ActionEvent e) {
}
};
- if (I18n.getLocale().getLanguage().equals(locale.getLanguage())) {
+ if (I18n.getLocale().getLanguage().equals(language)) {
languageAction.setEnabled(false);
}
languageActions.add(languageAction);
/**
* Edits the given node.
- *
+ *
* @param node
* The node to edit
*/
/**
* Deletes the given node.
- *
+ *
* @param node
* The node to delete
*/
/**
* Connects to the node.
- *
+ *
* @param node
* The node to connect to
*/
/**
* Disconnects from the node.
- *
+ *
* @param node
* The node to disconnect from
*/
/**
* Changes the language of the interface. This method also disables the
* action for the newly set language and enables all others.
- *
+ *
* @param newLocale
* The new language
* @param languageAction
* The action that triggered the change
*/
private void changeLanguage(Locale newLocale, I18nAction languageAction) {
- for (I18nAction i18nAction: languageActions) {
+ for (I18nAction i18nAction : languageActions) {
i18nAction.setEnabled(i18nAction != languageAction);
}
I18n.setLocale(newLocale);
private void addProject() {
try {
core.createProject();
- } catch (JSiteException nne1) {
- /* TODO - add i18n */
- JOptionPane.showMessageDialog(mainWindow, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE);
+ } catch (JSiteException jse1) {
+ JOptionPane.showMessageDialog(mainWindow, I18n.get("mainWindow.error.notConnected.message"), I18n.get("mainWindow.error.notConnected.title"), JOptionPane.ERROR_MESSAGE);
} catch (IOException e) {
/* TODO - add i18n */
JOptionPane.showMessageDialog(mainWindow, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE);
}
/**
+ * Inserts the given project.
+ *
+ * @param project
+ * The project to insert
+ */
+ private void insertProject(Project project) {
+ Node targetNode = project.getNode();
+ if (targetNode == null) {
+ JComboBox nodeComboBox = new JComboBox();
+ for (Node node : nodeList) {
+ ((DefaultComboBoxModel) nodeComboBox.getModel()).addElement(node.getName() + " (" + node.getHostname() + ":" + node.getPort() + ")");
+ }
+ int selectedOption = JOptionPane.showConfirmDialog(mainWindow, new Object[] { I18n.get("nodeSelectionDialog.selectNode.text"), nodeComboBox }, I18n.get("nodeSelectionDialog.noNodeSelected.text"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
+ if (selectedOption == JOptionPane.CANCEL_OPTION) {
+ return;
+ }
+ int selectedNodeIndex = nodeComboBox.getSelectedIndex();
+ logger.log(Level.FINE, "selected node index: " + selectedNodeIndex);
+ targetNode = nodeList.get(selectedNodeIndex);
+ }
+ logger.log(Level.INFO, "Inserting project “" + project.getName() + "” to node “" + targetNode.getName() + "”...");
+ if (!core.isNodeConnected(targetNode)) {
+ JOptionPane.showMessageDialog(mainWindow, I18n.get("mainWindow.error.nodeNotConnected.message", targetNode.getName()), I18n.get("mainWindow.error.nodeNotConnected.title", targetNode.getName()), JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ core.insertProject(targetNode, project);
+ }
+
+ /**
* Clones a project.
- *
+ *
* @param project
* The project to clone
*/
/**
* Deletes a project.
- *
+ *
* @param project
* The project to delete
*/
*/
public void loadingProjectsDone(String directory) {
mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.projectLoadingDone"));
- for (Project project: core.getProjects()) {
+ for (Project project : core.getProjects()) {
projectAdded(project, false);
}
}
* @param switchToProject
*/
private void projectAdded(final Project project, boolean switchToProject) {
+ insertProjectActions.put(project, new I18nAction("mainWindow.button.insertProject") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ insertProject(project);
+ }
+ });
cloneProjectActions.put(project, new I18nAction("mainWindow.button.cloneProject") {
/**
}
/**
- * @see net.pterodactylus.jsite.core.CoreListener#projectInsertStarted(net.pterodactylus.jsite.project.Project)
+ * @see net.pterodactylus.jsite.core.CoreListener#projectInsertStarted(net.pterodactylus.jsite.core.Project)
*/
public void projectInsertStarted(Project project) {
mainWindow.projectInsertStarted(project);
}
/**
- * @see net.pterodactylus.jsite.core.CoreListener#projectInsertProgressed(net.pterodactylus.jsite.project.Project,
+ * @see net.pterodactylus.jsite.core.CoreListener#projectInsertProgressed(net.pterodactylus.jsite.core.Project,
* int, int, int, int, int, boolean)
*/
public void projectInsertProgressed(Project project, int totalBlocks, int requiredBlocks, int successfulBlocks, int failedBlocks, int fatallyFailedBlocks, boolean finalizedTotal) {
}
/**
- * @see net.pterodactylus.jsite.core.CoreListener#projectInsertGeneratedURI(net.pterodactylus.jsite.project.Project,
+ * @see net.pterodactylus.jsite.core.CoreListener#projectInsertGeneratedURI(net.pterodactylus.jsite.core.Project,
* java.lang.String)
*/
public void projectInsertGeneratedURI(Project project, String uri) {
}
/**
- * @see net.pterodactylus.jsite.core.CoreListener#projectInsertFinished(net.pterodactylus.jsite.project.Project,
+ * @see net.pterodactylus.jsite.core.CoreListener#projectInsertFinished(net.pterodactylus.jsite.core.Project,
* boolean)
*/
public void projectInsertFinished(Project project, boolean success) {