Permalink
Browse files

Update the news panel (using data events) when a configuration is added.

  • Loading branch information...
sk89q committed Jun 11, 2013
1 parent 1cc6c2a commit d91a577a230240693d39cb3417bd3b14efdb76be
@@ -39,6 +39,8 @@
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
+import javax.swing.event.ListDataEvent;
+import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
@@ -54,7 +56,8 @@
* The classic view with a list of configurations on the left and news on
* the right side.
*/
-public class ClassicView extends LauncherView implements ListSelectionListener {
+public class ClassicView extends LauncherView
+ implements ListSelectionListener, ListDataListener {
private static final long serialVersionUID = -2985136389385217242L;
private static final int PAD = 12;
@@ -68,6 +71,8 @@ public ClassicView(LauncherFrame frame, final LaunchOptions launchOptions) {
addComponents();
+ configurationList.getModel().addListDataListener(this);
+
// Select the initial configuration
ListModel model = configurationList.getModel();
Configuration startupConfiguration = options.getConfigurations()
@@ -352,7 +357,8 @@ public void actionPerformed(ActionEvent e) {
}
private void updateNews() {
- Configuration configuration = (Configuration) configurationList.getSelectedValue();
+ Configuration configuration =
+ (Configuration) configurationList.getSelectedValue();
if (newsPanel != null) {
URL url = configuration.getNewsUrl();
@@ -379,4 +385,24 @@ public void valueChanged(ListSelectionEvent e) {
updateNews();
}
+ @Override
+ public void intervalAdded(ListDataEvent e) {
+ updateNews();
+ }
+
+ @Override
+ public void intervalRemoved(ListDataEvent e) {
+ updateNews();
+ }
+
+ @Override
+ public void contentsChanged(ListDataEvent e) {
+ updateNews();
+ }
+
+ @Override
+ public void cleanUp() {
+ configurationList.getModel().removeListDataListener(this);
+ }
+
}
@@ -28,6 +28,7 @@
import javax.swing.SwingUtilities;
import com.sk89q.mclauncher.config.Configuration;
+import com.sk89q.mclauncher.config.ConfigurationList;
import com.sk89q.mclauncher.config.LauncherOptions;
import com.sk89q.mclauncher.model.UpdateManifest;
import com.sk89q.mclauncher.update.UpdateManifestFetcher;
@@ -87,9 +88,11 @@ protected void execute() throws ExecutionException {
"The manfiest at the URL has an invalid news URL.");
}
- options.getConfigurations().register(configuration);
- options.getConfigurations().sortByDate();
-
+ ConfigurationList configurations = options.getConfigurations();
+ configurations.register(configuration);
+ configurations.sortByDate();
+ configurations.update(configuration);
+
if (!options.save()) {
throw new ExecutionException(
"Your options could not be saved to disk.");
@@ -19,8 +19,11 @@
package com.sk89q.mclauncher;
import java.awt.BorderLayout;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
import javax.swing.JFrame;
+import javax.swing.WindowConstants;
import com.sk89q.mclauncher.config.Configuration;
import com.sk89q.mclauncher.config.Identity;
@@ -52,7 +55,6 @@
public LauncherFrame() {
setTitle("SK's Minecraft Launcher");
setSize(620, 500);
- setDefaultCloseOperation(DISPOSE_ON_CLOSE);
SwingHelper.setLookAndFeel();
SwingHelper.setIconImage(this, "/resources/icon.png");
@@ -61,8 +63,15 @@ public LauncherFrame() {
view = new ClassicView(this, launchOptions);
add(view, BorderLayout.CENTER);
-
- setLocationRelativeTo(null);
+
+ setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+ addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent event) {
+ view.cleanUp();
+ dispose();
+ }
+ });
}
/**
@@ -44,5 +44,9 @@ public LauncherView(LauncherFrame frame, LaunchOptions launchOptions) {
public void selectAfterSort() {
}
+
+ public void cleanUp() {
+
+ }
}

0 comments on commit d91a577

Please sign in to comment.