Skip to content

Commit

Permalink
Merge pull request #1 from cwisniew/merge-addon-dev
Browse files Browse the repository at this point in the history
Merge addon dev
  • Loading branch information
Sparky200 authored May 24, 2024
2 parents 50db900 + 57c9ff7 commit 87aced0
Show file tree
Hide file tree
Showing 29 changed files with 738 additions and 63 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ dependencies {
// Built In Add-on Libraries
implementation 'com.github.RPTools:maptool-builtin-addons:1.3'

// File watcher library to work around some inconsistencies with java.nio.file.WatchService
implementation 'io.methvin:directory-watcher:0.18.0'

// For advanced dice roller
implementation 'com.github.RPTools:advanced-dice-roller:1.0.3'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,48 +275,136 @@
</splitpane>
</children>
</grid>
<grid id="78150" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="78150" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title-resource-bundle="net/rptools/maptool/language/i18n" title-key="library.dialog.development.label"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<hspacer id="28b4a">
<grid id="3827a" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<vspacer id="61f72">
<properties/>
<border type="none"/>
<children>
<component id="35630" class="javax.swing.JButton" binding="copyStatSheetThemeButton" default-binding="true">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="net/rptools/maptool/language/i18n" key="library.dialog.copyMTStatSheetTheme"/>
</properties>
</component>
<component id="456e5" class="javax.swing.JButton" binding="copyThemeCSS">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="net/rptools/maptool/language/i18n" key="library.dialog.copyMTThemeCSS"/>
</properties>
</component>
<component id="3aa17" class="javax.swing.JButton" binding="createAddonSkeletonButton">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="net/rptools/maptool/language/i18n" key="library.dialog.addon.createNew"/>
</properties>
</component>
<component id="9fe05" class="javax.swing.JButton" binding="exportAddOn">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="net/rptools/maptool/language/i18n" key="library.dialog.addon.export"/>
</properties>
</component>
</children>
</grid>
<grid id="16c05" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<properties/>
<border type="none"/>
<children>
<component id="507e" class="javax.swing.JCheckBox" binding="enableExternalAddOnCheckBox" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="net/rptools/maptool/language/i18n" key="library.dialog.externalAddon"/>
</properties>
</component>
<scrollpane id="50486">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<name value="externalAddOnTable"/>
</properties>
<border type="none"/>
<children>
<component id="54fd" class="javax.swing.JTable" binding="externalAddonTable">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
<grid id="823fa" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="f3d7" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="net/rptools/maptool/language/i18n" key="library.dialog.directory.label"/>
</properties>
</component>
<hspacer id="ee2c6">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="8ac99" class="javax.swing.JTextField" binding="directoryTextField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="4e8f9" class="javax.swing.JButton" binding="browseButton">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="net/rptools/maptool/language/i18n" key="Button.browse"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<component id="fde58" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="net/rptools/maptool/language/i18n" key="library.dialog.copy.title"/>
</properties>
</component>
<component id="456e5" class="javax.swing.JButton" binding="copyThemeCSS">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="net/rptools/maptool/language/i18n" key="library.dialog.copyMTThemeCSS"/>
</properties>
</component>
<component id="35630" class="javax.swing.JButton" binding="copyStatSheetThemeButton" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="net/rptools/maptool/language/i18n" key="library.dialog.copyMTStatSheetTheme"/>
</properties>
</component>
</children>
</grid>
</children>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.KeyStroke;
import net.rptools.maptool.client.AppActions.MapPreviewFileChooser;
Expand Down Expand Up @@ -69,6 +71,12 @@ public class AddOnLibrariesDialogView extends JDialog {
private JButton viewLicenseFileButton;
private JButton copyThemeCSS;
private JButton copyStatSheetThemeButton;
private JCheckBox enableExternalAddOnCheckBox;
private JTable externalAddonTable;
private JButton createAddonSkeletonButton;
private JTextField directoryTextField;
private JButton browseButton;
private JButton exportAddOn;

private LibraryInfo selectedAddOn;

Expand All @@ -80,6 +88,9 @@ public AddOnLibrariesDialogView() {
addOnLibraryTable.setModel(new AddOnLibrariesTableModel());
addOnLibraryTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

externalAddonTable.setModel(new ExternalAddOnLibrariesTableModel());
externalAddonTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

buttonRemove.setEnabled(false);
addOnLibraryTable
.getSelectionModel()
Expand Down Expand Up @@ -205,6 +216,38 @@ public void actionPerformed(ActionEvent e) {
.setContents(new StringSelection(themeCss), null);
});
});

createAddonSkeletonButton.addActionListener(
e -> {
createAddonSkeleton();
});

enableExternalAddOnCheckBox.addActionListener(
e -> {
setExternalAddOnControlsEnabled(enableExternalAddOnCheckBox.isSelected());
directoryTextField.setEnabled(enableExternalAddOnCheckBox.isSelected());
new LibraryManager()
.setExternalLibrariesEnabled(enableExternalAddOnCheckBox.isSelected());
});

browseButton.addActionListener(
e -> {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(I18N.getText("library.dialog.import.title"));
});

LibraryManager libraryManager = new LibraryManager();
enableExternalAddOnCheckBox.setSelected(libraryManager.externalLibrariesEnabled());
setExternalAddOnControlsEnabled(enableExternalAddOnCheckBox.isSelected());
}

private void setExternalAddOnControlsEnabled(boolean selected) {
externalAddonTable.setEnabled(enableExternalAddOnCheckBox.isSelected());
browseButton.setEnabled(enableExternalAddOnCheckBox.isSelected());
}

private void createAddonSkeleton() {
// TODO: CDW
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This software Copyright by the RPTools.net development team, and
* licensed under the Affero GPL Version 3 or, at your option, any later
* version.
*
* MapTool Source Code 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.
*
* You should have received a copy of the GNU Affero General Public
* License * along with this source Code. If not, please visit
* <http://www.gnu.org/licenses/> and specifically the Affero license
* text at <http://www.gnu.org/licenses/agpl.html>.
*/
package net.rptools.maptool.client.ui.addon;

import java.util.List;
import javax.swing.JButton;
import javax.swing.table.AbstractTableModel;
import net.rptools.maptool.language.I18N;
import net.rptools.maptool.model.library.LibraryInfo;
import net.rptools.maptool.model.library.LibraryManager;

public class ExternalAddOnLibrariesTableModel extends AbstractTableModel {

@Override
public int getRowCount() {
return new LibraryManager().getExternalAddOnLibraries().size();
}

@Override
public int getColumnCount() {
return 5;
}

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
List<LibraryInfo> addons = new LibraryManager().getExternalAddOnLibraries();

return switch (columnIndex) {
case 0 -> addons.get(rowIndex).name();
case 1 -> addons.get(rowIndex).version();
case 2 -> addons.get(rowIndex).namespace();
case 3 -> addons.get(rowIndex).backingDirectory();
case 4 -> {
var button = new JButton();
button.setText("library.dialog.addon.refresh");
button.addActionListener(
e -> {
refresh(rowIndex);
});
yield button;
}
default -> null;
};
}

@Override
public String getColumnName(int column) {
return switch (column) {
case 0 -> I18N.getText("library.dialog.addon.name");
case 1 -> I18N.getText("library.dialog.addon.version");
case 2 -> I18N.getText("library.dialog.addon.namespace");
case 3 -> I18N.getText("library.dialog.addon.subdir");
case 4 -> I18N.getText("library.dialog.addon.refresh");
default -> null;
};
}

void refresh(int rowIndex) {
// TODO: CDW
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package net.rptools.maptool.model.library;

import java.nio.file.Path;

/** Record that contains the information about a library. */
public record LibraryInfo(
String name,
Expand All @@ -27,5 +29,6 @@ public record LibraryInfo(
String shortDescription,
boolean allowsUrlAccess,
String readMeFile,
String licenseFile) {}
String licenseFile,
Path backingDirectory) {}
;
Loading

0 comments on commit 87aced0

Please sign in to comment.