-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for selecting optional components to install as part of…
… an update. <package version="1.1"> <component id="base" required="true"> <title>Base Game</title> <description>The base game files.</description> </component> <component id="eduardo" default="true"> <title>Picture of Eduardo</title> <description>Draws a picture of Eduardo on your screen.</description> </component> <component id="alice"> <title>Picture of Alice</title> <description>Draws a picture of Alice on your screen.</description> </component> <filegroup source="http://example.com/update/" dest="."> <!-- Eduardo doesn't want to exist with Alice around --> <file size="1024" component="eduardo, !alice">eduardo.png</file> <file size="1024" component="alice">alice.png</file> </filegroup> </package>
- Loading branch information
Showing
9 changed files
with
508 additions
and
29 deletions.
There are no files selected for viewing
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
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
148 changes: 148 additions & 0 deletions
148
src/main/java/com/sk89q/mclauncher/SelectComponentsDialog.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
* SK's Minecraft Launcher | ||
* Copyright (C) 2010, 2011 Albert Pham <http://www.sk89q.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.sk89q.mclauncher; | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.Dimension; | ||
import java.awt.FlowLayout; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
|
||
import javax.swing.BorderFactory; | ||
import javax.swing.JButton; | ||
import javax.swing.JDialog; | ||
import javax.swing.JFrame; | ||
import javax.swing.JLabel; | ||
import javax.swing.JPanel; | ||
import javax.swing.JScrollPane; | ||
import javax.swing.JTable; | ||
import javax.swing.JTextArea; | ||
import javax.swing.ListSelectionModel; | ||
import javax.swing.event.ListSelectionEvent; | ||
import javax.swing.event.ListSelectionListener; | ||
import javax.swing.table.TableCellRenderer; | ||
|
||
import com.sk89q.mclauncher.model.Component; | ||
import com.sk89q.mclauncher.model.ComponentTableModel; | ||
import com.sk89q.mclauncher.model.PackageManifest; | ||
|
||
public class SelectComponentsDialog extends JDialog { | ||
|
||
private static final long serialVersionUID = -8771235345163527656L; | ||
|
||
private final PackageManifest manifest; | ||
|
||
private JTable table; | ||
|
||
public SelectComponentsDialog(JFrame frame, PackageManifest manifest) { | ||
super(frame, "Select Install Options", true); | ||
|
||
this.manifest = manifest; | ||
|
||
setResizable(true); | ||
buildUI(); | ||
pack(); | ||
setSize(320, 500); | ||
setLocationRelativeTo(frame); | ||
} | ||
|
||
private void buildUI() { | ||
JPanel container = new JPanel(); | ||
container.setLayout(new BorderLayout(8, 8)); | ||
container.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); | ||
|
||
JLabel infoLabel = new JLabel( | ||
"<html>To change these later, select 'Re-select install options' " + | ||
"after clicking 'More Options' on the launcher."); | ||
container.add(infoLabel, BorderLayout.NORTH); | ||
|
||
table = new JTable() { | ||
private static final long serialVersionUID = 4897191210730076435L; | ||
|
||
@Override | ||
public java.awt.Component prepareRenderer(TableCellRenderer renderer, int row, int col) { | ||
java.awt.Component c = super.prepareRenderer(renderer, row, col); | ||
if (col == 0) { | ||
c.setEnabled(!((Component) (getModel()).getValueAt(row, 1)).isRequired()); | ||
} | ||
return c; | ||
} | ||
}; | ||
|
||
table.setTableHeader(null); | ||
table.setShowGrid(false); | ||
table.setRowHeight(table.getRowHeight() + 2); | ||
table.setIntercellSpacing(new Dimension(0, 0)); | ||
table.setFillsViewportHeight(true); | ||
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); | ||
table.setModel(new ComponentTableModel(manifest.getComponents())); | ||
table.getColumnModel().getColumn(0).setMaxWidth(30); | ||
JScrollPane tableScroll = new JScrollPane(table); | ||
container.add(tableScroll, BorderLayout.CENTER); | ||
|
||
JPanel bottomPanel = new JPanel(); | ||
bottomPanel.setLayout(new BorderLayout(0, 8)); | ||
container.add(bottomPanel, BorderLayout.SOUTH); | ||
|
||
JLabel descLabel = new JLabel("<html><b>Description:</b>"); | ||
bottomPanel.add(descLabel, BorderLayout.NORTH); | ||
|
||
final JTextArea descArea = new JTextArea("Select an option to see its description.") { | ||
private static final long serialVersionUID = 4339941505774335040L; | ||
|
||
@Override | ||
public Dimension getPreferredSize() { | ||
return new Dimension((int) super.getPreferredSize().getWidth(), 100); | ||
} | ||
}; | ||
descArea.setFont(descLabel.getFont()); | ||
descArea.setBackground(descLabel.getBackground()); | ||
descArea.setEditable(false); | ||
descArea.setWrapStyleWord(true); | ||
descArea.setLineWrap(true); | ||
JScrollPane descScroll = new JScrollPane(descArea, | ||
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, | ||
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); | ||
bottomPanel.add(descScroll, BorderLayout.CENTER); | ||
|
||
add(container, BorderLayout.CENTER); | ||
|
||
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { | ||
@Override | ||
public void valueChanged(ListSelectionEvent e) { | ||
Component component = (Component) (table.getModel()).getValueAt(table.getSelectedRow(), 1); | ||
descArea.setText(component.getDescription()); | ||
} | ||
}); | ||
|
||
JPanel buttonsPanel = new JPanel(); | ||
buttonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 5)); | ||
JButton installButton = new JButton("Continue..."); | ||
buttonsPanel.add(installButton); | ||
bottomPanel.add(buttonsPanel, BorderLayout.SOUTH); | ||
|
||
installButton.addActionListener(new ActionListener() { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
dispose(); | ||
} | ||
}); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.sk89q.mclauncher.model; | ||
|
||
import javax.xml.bind.annotation.XmlAttribute; | ||
import javax.xml.bind.annotation.XmlElement; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
import javax.xml.bind.annotation.XmlTransient; | ||
|
||
@XmlRootElement(name = "component") | ||
public class Component { | ||
|
||
private String id; | ||
private String title; | ||
private String description; | ||
private boolean defaultSelected; | ||
private boolean required; | ||
|
||
private transient boolean selected; | ||
|
||
@XmlAttribute(name = "id") | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
@XmlElement | ||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
@XmlElement | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
@XmlAttribute(name = "default") | ||
public boolean isDefaultSelected() { | ||
return defaultSelected; | ||
} | ||
|
||
public void setDefaultSelected(boolean defaultSelected) { | ||
this.defaultSelected = defaultSelected; | ||
if (defaultSelected) { | ||
selected = true; | ||
} | ||
} | ||
|
||
@XmlAttribute(name = "required") | ||
public boolean isRequired() { | ||
return required; | ||
} | ||
|
||
public void setRequired(boolean required) { | ||
this.required = required; | ||
} | ||
|
||
@XmlTransient | ||
public boolean isSelected() { | ||
return required || selected; | ||
} | ||
|
||
public void setSelected(boolean selected) { | ||
this.selected = selected; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getTitle(); | ||
} | ||
|
||
} |
Oops, something went wrong.