diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesConfig.java new file mode 100644 index 0000000000..b82cc1ff5d --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesConfig.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018 Charlie Waters + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.notes; + +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; + +@ConfigGroup( + keyName = "notes", + name = "Notes", + description = "Configuration for the Notes plugin" +) +public interface NotesConfig extends Config +{ + @ConfigItem( + keyName = "notesData", + name = "", + description = "", + hidden = true + ) + default String notesData() + { + return ""; + } + + @ConfigItem( + keyName = "notesData", + name = "", + description = "" + ) + void notesData(String str); +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesPanel.java new file mode 100644 index 0000000000..c214e23381 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesPanel.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2018 Charlie Waters + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.notes; + +import javax.swing.BorderFactory; +import javax.swing.JEditorPane; +import javax.swing.JLabel; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; + +import lombok.extern.slf4j.Slf4j; +import net.runelite.client.ui.PluginPanel; + +import java.awt.BorderLayout; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; + +@Slf4j +public class NotesPanel extends PluginPanel +{ + private final JEditorPane notesEditor = new JEditorPane(); + + void init(NotesConfig config) + { + // this may or may not qualify as a hack + // but this lets the editor pane expand to fill the whole parent panel + getParent().setLayout(new BorderLayout()); + getParent().add(this, BorderLayout.CENTER); + + setLayout(new BorderLayout()); + setBorder(BorderFactory.createEmptyBorder(2, 6, 6, 6)); + + final JLabel notesHeader = new JLabel("Notes"); + add(notesHeader, BorderLayout.NORTH); + + notesEditor.setContentType("text/plain"); + + // load note text + String data = config.notesData(); + notesEditor.setText(data); + + notesEditor.addFocusListener(new FocusListener() + { + @Override + public void focusGained(FocusEvent e) + { + + } + + @Override + public void focusLost(FocusEvent e) + { + notesChanged(notesEditor.getDocument()); + } + + private void notesChanged(Document doc) + { + try + { + // get document text and save to config whenever editor is changed + String data = doc.getText(0, doc.getLength()); + config.notesData(data); + } + catch (BadLocationException ex) + { + log.warn("Notes Document Bad Location: " + ex); + } + } + }); + add(notesEditor, BorderLayout.CENTER); + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesPlugin.java new file mode 100644 index 0000000000..7d00d21013 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesPlugin.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2018 Charlie Waters + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.notes; + +import javax.imageio.ImageIO; +import javax.inject.Inject; + +import com.google.inject.Provides; +import net.runelite.client.config.ConfigManager; +import net.runelite.client.plugins.Plugin; +import net.runelite.client.plugins.PluginDescriptor; +import net.runelite.client.ui.ClientUI; +import net.runelite.client.ui.NavigationButton; +import lombok.extern.slf4j.Slf4j; + +@PluginDescriptor( + name = "Notes", + loadWhenOutdated = true +) +@Slf4j +public class NotesPlugin extends Plugin +{ + @Inject + private ClientUI ui; + + @Inject + private NotesConfig config; + + private NotesPanel panel; + private NavigationButton navButton; + + @Provides + NotesConfig getConfig(ConfigManager configManager) + { + return configManager.getConfig(NotesConfig.class); + } + + @Override + protected void startUp() throws Exception + { + panel = injector.getInstance(NotesPanel.class); + panel.init(config); + + navButton = new NavigationButton( + "Notes", + ImageIO.read(getClass().getResourceAsStream("notes_icon.png")), + () -> panel + ); + + ui.getPluginToolbar().addNavigation(navButton); + } + + @Override + protected void shutDown() + { + ui.getPluginToolbar().removeNavigation(navButton); + } +} diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/notes/notes_icon.png b/runelite-client/src/main/resources/net/runelite/client/plugins/notes/notes_icon.png new file mode 100644 index 0000000000..e94292baf1 Binary files /dev/null and b/runelite-client/src/main/resources/net/runelite/client/plugins/notes/notes_icon.png differ