Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Add context menu for faster operation
Browse files Browse the repository at this point in the history
  • Loading branch information
hiran committed Aug 27, 2023
1 parent 666b324 commit 59221ca
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 153 deletions.
22 changes: 16 additions & 6 deletions src/main/java/oolite/starter/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,26 @@ protected void done() {
newSplash = null;
}

if (mf.configuration.getActiveInstallation() == null) {
// point user to creating an active installation
if (mf.configuration.getInstallations().isEmpty()) {
mf.jTabbedPane1.setEnabledAt(0, false);
mf.jTabbedPane1.setEnabledAt(1, false);
mf.jTabbedPane1.setSelectedIndex(2);

StringBuilder message = new StringBuilder("<html>");
message.append("<p>I see a lot of blanks on this here board... Kid, you gotta do something about it.</p>");
message.append("<p>Have at least one active Oolite version. You need one. It's pretty much compulsory.<br/>");
message.append("Hit the Add button and fill in the form, at least once to add Oolite versions.<br/>");
message.append("Don't forget to select one of them, then hit the Activate button.</p>");
message.append("<p>Then you can juggle OXPs or start the game. And maybe touch the Save button once in a while.</p>");
message.append("<p>Have at least one Oolite version. You need one. It's pretty much compulsory.<br/>");
message.append("Hit the Scan or Add button and fill in the form, at least once to add Oolite versions.<br/>");
message.append("</html>");

MrGimlet.showMessage(mf, message.toString());
} else if (mf.configuration.getActiveInstallation() == null) {
// point user to creating an active installation
mf.jTabbedPane1.setSelectedIndex(2);

StringBuilder message = new StringBuilder("<html>");
message.append("<p>Much better. But still I see a lot of blanks... Kid, now do something about it.</p>");
message.append("<p>Selected one of your Oolite versions. Otherwise this app would not know what to do.<br/>");
message.append("<p>Choose one from the list and click Select.<br/>");
message.append("</html>");

MrGimlet.showMessage(mf, message.toString());
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/oolite/starter/model/Expansion.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import oolite.starter.Oolite;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -759,4 +761,16 @@ public List<ExpansionReference> getOptionalRefs() {
}
return result;
}

/**
* Returns true if this expansion is nested inside another expansion directory.
*
* @return true if it is nested, false otherwise
*/
public boolean isNested() {
Pattern p = Pattern.compile("\\.oxp.+\\.oxp", Pattern.CASE_INSENSITIVE);
String file = String.valueOf(getLocalFile());
Matcher m = p.matcher(file);
return m.find();
}
}
6 changes: 6 additions & 0 deletions src/main/java/oolite/starter/ui/ExpansionPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ private void update() {
} else {
spRequires.setBorder(UIManager.getLookAndFeel().getDefaults().getBorder("ScrollPane.border"));
}

// check if we have nested OXPs.
if (data.isNested()) {
btDisable.setEnabled(false);
}

}
validate();
repaint();
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/oolite/starter/ui/ExpansionsPanel.form
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
</Container>
<Container class="javax.swing.JSplitPane" name="jSplitPane1">
<Properties>
<Property name="dividerSize" type="int" value="7"/>
<Property name="resizeWeight" type="double" value="0.5"/>
<Property name="oneTouchExpandable" type="boolean" value="true"/>
</Properties>
Expand Down Expand Up @@ -290,13 +291,13 @@
</Column>
</Table>
</Property>
<Property name="componentPopupMenu" type="javax.swing.JPopupMenu" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="default"/>
</Property>
<Property name="selectionModel" type="javax.swing.ListSelectionModel" editor="org.netbeans.modules.form.editors2.JTableSelectionModelEditor">
<JTableSelectionModel selectionMode="0"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new MyJTable()"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
Expand Down
109 changes: 107 additions & 2 deletions src/main/java/oolite/starter/ui/ExpansionsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,27 @@
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.RowFilter;
import javax.swing.RowSorter;
import javax.swing.SortOrder;
Expand Down Expand Up @@ -101,6 +108,7 @@ public ExpansionsPanel() {
if (!lse.getValueIsAdjusting()) {
// we have a final value - let's render it
showDetailsOfSelection();
setPopupMenu();
}
});
jTable1.setDefaultRenderer(Object.class, new AnnotationRenderer(jTable1.getDefaultRenderer(Object.class), Configuration.COLOR_ATTENTION));
Expand Down Expand Up @@ -139,7 +147,7 @@ private void applyFilter() {
if (!"".equals(txtFilterText.getText())) {
try {
String re = "(?i)" + txtFilterText.getText();
log.warn("re={}", re);
log.trace("re={}", re);
filters.add(RowFilter.regexFilter(re));
} catch (Exception e) {
log.info("Cannot apply regexp filter", e);
Expand All @@ -153,6 +161,10 @@ private void applyFilter() {
updateBadges();
}

/**
* Sets the details panel data to the selected row.
* Usually call this when the selected row changed.
*/
private void showDetailsOfSelection() {
int rowIndex = jTable1.getSelectedRow();
if (rowIndex >=0) {
Expand All @@ -163,6 +175,98 @@ private void showDetailsOfSelection() {
ep.setData(null);
}
}

/**
* Sets the JTable popup menu.
* Usually call this when the selected row changed.
*/
private void setPopupMenu() {
JPopupMenu popupMenu = new JPopupMenu();
int rowIndex = jTable1.getSelectedRow();
if (rowIndex >=0) {
rowIndex = jTable1.convertRowIndexToModel(rowIndex);
final Expansion row = model.getRow(rowIndex);

if (row.isOnline()) {
popupMenu.add(new AbstractAction("Copy Download URL") {
@Override
public void actionPerformed(ActionEvent ae) {
StringSelection stringSelection = new StringSelection(row.getDownloadUrl());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
log.warn("Download URL copied to clipboard");

// todo: add user notification, some balloon popup
}
});
}
if (!row.isLocal()) {
popupMenu.add(new AbstractAction("Install") {
@Override
public void actionPerformed(ActionEvent ae) {
// todo: Run in background thread
// todo: notify user about result
try {
row.install();
setPopupMenu();
} catch (Exception e) {
log.error("Could not install {}", row);
}
}
});
} else {
if (!row.isNested()) {
if (row.isEnabled()) {
popupMenu.add(new AbstractAction("Disable") {
@Override
public void actionPerformed(ActionEvent ae) {
// todo: Run in background thread
// todo: notify user about result
try {
row.disable();
setPopupMenu();
} catch (Exception e) {
log.error("Could not disable {}", row);
}
}
});
} else {
popupMenu.add(new AbstractAction("Enable") {
@Override
public void actionPerformed(ActionEvent ae) {
// todo: Run in background thread
// todo: notify user about result
try {
row.enable();
setPopupMenu();
} catch (Exception e) {
log.error("Could not enable {}", row);
}
}
});
}
}

if (popupMenu.getComponentCount()>0) {
popupMenu.add(new JSeparator());
}
popupMenu.add(new AbstractAction("Delete") {
@Override
public void actionPerformed(ActionEvent ae) {
// todo: Run in background thread
// todo: notify user about result
try {
row.remove();
setPopupMenu();
} catch (Exception e) {
log.error("Could not remove {}", row);
}
}
});
}
}
jTable1.setComponentPopupMenu(popupMenu);
}

/**
* Sets the Oolite instance to run the savegames from.
Expand Down Expand Up @@ -275,7 +379,7 @@ private void initComponents() {
btReload = new javax.swing.JButton();
jSplitPane1 = new javax.swing.JSplitPane();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new MyJTable();
jTable1 = new javax.swing.JTable();
pnStatus = new javax.swing.JPanel();

setName("OXPs/OXZs"); // NOI18N
Expand Down Expand Up @@ -426,6 +530,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {

add(jpToolbar, java.awt.BorderLayout.PAGE_START);

jSplitPane1.setDividerSize(7);
jSplitPane1.setResizeWeight(0.5);
jSplitPane1.setOneTouchExpandable(true);

Expand Down
1 change: 1 addition & 0 deletions src/main/java/oolite/starter/ui/InstallationsPanel.form
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<Container class="javax.swing.JSplitPane" name="jSplitPane1">
<Properties>
<Property name="dividerLocation" type="int" value="300"/>
<Property name="dividerSize" type="int" value="7"/>
<Property name="resizeWeight" type="double" value="0.5"/>
<Property name="oneTouchExpandable" type="boolean" value="true"/>
</Properties>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/oolite/starter/ui/InstallationsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
add(jPanel1, java.awt.BorderLayout.PAGE_START);

jSplitPane1.setDividerLocation(300);
jSplitPane1.setDividerSize(7);
jSplitPane1.setResizeWeight(0.5);
jSplitPane1.setOneTouchExpandable(true);

Expand Down

0 comments on commit 59221ca

Please sign in to comment.