-
Notifications
You must be signed in to change notification settings - Fork 0
Adds the dockable interface #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| package org.editor; | ||
|
|
||
| import com.vlsolutions.swing.docking.DockKey; | ||
| import com.vlsolutions.swing.docking.Dockable; | ||
| import java.awt.BasicStroke; | ||
|
Comment on lines
+3
to
5
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing interface implementation for Dockable You've imported the -public class CanvasFrame extends JPanel implements MouseListener, MouseMotionListener {
+public class CanvasFrame extends JPanel implements MouseListener, MouseMotionListener, Dockable {Also need to implement the required methods: @Override
public DockKey getDockKey() {
return key;
}
@Override
public Component getComponent() {
return this;
}Also applies to: 8-8 |
||
| import java.awt.BorderLayout; | ||
| import java.awt.Color; | ||
| import java.awt.Component; | ||
| import java.awt.Dimension; | ||
| import java.awt.Graphics; | ||
| import java.awt.Graphics2D; | ||
|
|
@@ -54,6 +57,7 @@ public class CanvasFrame extends JPanel implements MouseListener, MouseMotionLis | |
| private Point selectionEnd = null; | ||
|
|
||
| private static CanvasFrame _the = null; | ||
| private DockKey key = new DockKey("canvas"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion DockKey will remain unused without implementing Dockable This |
||
|
|
||
| private CanvasFrame() { | ||
| super(new BorderLayout()); | ||
|
|
@@ -319,5 +323,4 @@ private void drawCrosshair(Graphics2D g2) { | |
| g2.fillOval(mouseX - radius, mouseY - radius, radius * 2, radius * 2); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,11 @@ | ||||||||||||
| package org.editor; | ||||||||||||
|
|
||||||||||||
| import com.vlsolutions.swing.docking.DockKey; | ||||||||||||
| import com.vlsolutions.swing.docking.Dockable; | ||||||||||||
| import java.awt.BorderLayout; | ||||||||||||
| import java.awt.Component; | ||||||||||||
| import java.awt.event.FocusEvent; | ||||||||||||
| import java.awt.event.FocusListener; | ||||||||||||
| import java.io.File; | ||||||||||||
| import java.io.IOException; | ||||||||||||
| import java.nio.file.Path; | ||||||||||||
|
|
@@ -10,6 +15,8 @@ | |||||||||||
| import javax.swing.JOptionPane; | ||||||||||||
| import javax.swing.JPanel; | ||||||||||||
| import javax.swing.text.BadLocationException; | ||||||||||||
| import org.editor.fs.FileFilter; | ||||||||||||
| import org.editor.fs.FilePersistance; | ||||||||||||
| import org.editor.icons.Icons; | ||||||||||||
| import org.fife.ui.autocomplete.AutoCompletion; | ||||||||||||
| import org.fife.ui.autocomplete.BasicCompletion; | ||||||||||||
|
|
@@ -20,6 +27,8 @@ | |||||||||||
| import org.fife.ui.rsyntaxtextarea.CodeTemplateManager; | ||||||||||||
| import org.fife.ui.rsyntaxtextarea.FileLocation; | ||||||||||||
| import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; | ||||||||||||
| import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaHighlighter; | ||||||||||||
| import org.fife.ui.rsyntaxtextarea.SyntaxConstants; | ||||||||||||
| import org.fife.ui.rsyntaxtextarea.TextEditorPane; | ||||||||||||
| import org.fife.ui.rsyntaxtextarea.TokenMakerFactory; | ||||||||||||
| import org.fife.ui.rsyntaxtextarea.templates.CodeTemplate; | ||||||||||||
|
|
@@ -30,13 +39,19 @@ | |||||||||||
| * | ||||||||||||
| * @author hexaredecimal | ||||||||||||
| */ | ||||||||||||
| public class CodeEditor extends JPanel { | ||||||||||||
| public class CodeEditor extends JPanel implements Dockable { | ||||||||||||
|
|
||||||||||||
| public TextEditorPane textArea; | ||||||||||||
| public Path file = null; | ||||||||||||
| private boolean isTmp; | ||||||||||||
| private DockKey key; // = new DockKey("textEditor"); | ||||||||||||
| public int tabIndex =0; | ||||||||||||
|
|
||||||||||||
| public CodeEditor() { | ||||||||||||
| this(null); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| public CodeEditor(Path path) { | ||||||||||||
| super(new BorderLayout()); | ||||||||||||
| textArea = new TextEditorPane(); | ||||||||||||
| textArea.setCodeFoldingEnabled(true); | ||||||||||||
|
|
@@ -61,17 +76,55 @@ public CodeEditor() { | |||||||||||
| gutter.setBookmarkingEnabled(true); | ||||||||||||
| gutter.setBookmarkIcon(Icons.getIcon("bookmark")); | ||||||||||||
|
|
||||||||||||
| var self = this; | ||||||||||||
| textArea.addFocusListener(new FocusListener() { | ||||||||||||
| @Override | ||||||||||||
| public void focusGained(FocusEvent e) { | ||||||||||||
| EditorWindow.setSelectedEditor(self); | ||||||||||||
| getCursorPositionText(self); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| @Override | ||||||||||||
| public void focusLost(FocusEvent e) { | ||||||||||||
| } | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| this.addFocusListener(new FocusListener() { | ||||||||||||
| @Override | ||||||||||||
| public void focusGained(FocusEvent e) { | ||||||||||||
| EditorWindow.setSelectedEditor(self); | ||||||||||||
| getCursorPositionText(self); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| @Override | ||||||||||||
| public void focusLost(FocusEvent e) { | ||||||||||||
| } | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| try { | ||||||||||||
| var fp = File.createTempFile("piccasso-", "-tmp"); | ||||||||||||
| file = fp.toPath(); | ||||||||||||
| fp.deleteOnExit(); | ||||||||||||
| isTmp = true; | ||||||||||||
| String tip = "Source code editor"; | ||||||||||||
| var icon = Icons.getIcon("code-file"); | ||||||||||||
| if (path == null) { | ||||||||||||
| var fp = File.createTempFile("piccasso-", "-tmp"); | ||||||||||||
|
|
||||||||||||
| key = new DockKey(fp.getName(), fp.getName(), tip, icon); | ||||||||||||
| file = fp.toPath(); | ||||||||||||
| isTmp = true; | ||||||||||||
| fp.deleteOnExit(); | ||||||||||||
| } else { | ||||||||||||
| key = new DockKey(path.toFile().getName(), path.toFile().getName(), tip, icon); | ||||||||||||
| file = path; | ||||||||||||
| } | ||||||||||||
| key.setCloseEnabled(true); | ||||||||||||
| key.setAutoHideEnabled(true); | ||||||||||||
| this.putClientProperty("dockKey", key); | ||||||||||||
| } catch (IOException ex) { | ||||||||||||
| Logger.getLogger(CodeEditor.class.getName()).log(Level.SEVERE, null, ex); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| textArea | ||||||||||||
| .addCaretListener(e -> { | ||||||||||||
| EditorWindow.setSelectedEditor(this); | ||||||||||||
| getCursorPositionText(this); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
|
|
@@ -85,6 +138,8 @@ public boolean saveFile() { | |||||||||||
|
|
||||||||||||
| try { | ||||||||||||
| textArea.save(); | ||||||||||||
| FilePersistance.persistFile(file); | ||||||||||||
| EditorWindow.setSeletedTabTitle(file.toFile().getName()); | ||||||||||||
| EditorWindow.current_file.setText("Written to " + file); | ||||||||||||
| return true; | ||||||||||||
| } catch (IOException e) { | ||||||||||||
|
|
@@ -102,6 +157,9 @@ public void setIsTmp(boolean isTmp) { | |||||||||||
|
|
||||||||||||
| public boolean saveFileAs() { | ||||||||||||
| var fileChooser = new JFileChooser("."); | ||||||||||||
| fileChooser.setFileFilter(FileFilter.mdFilter); | ||||||||||||
| fileChooser.setFileFilter(FileFilter.picsFilter); | ||||||||||||
|
|
||||||||||||
|
Comment on lines
+160
to
+162
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only one If you want both “.md” and “.pics” filters: -fileChooser.setFileFilter(FileFilter.mdFilter);
-fileChooser.setFileFilter(FileFilter.picsFilter);
+fileChooser.addChoosableFileFilter(FileFilter.mdFilter);
+fileChooser.addChoosableFileFilter(FileFilter.picsFilter);
+fileChooser.setFileFilter(FileFilter.picsFilter); // default selection📝 Committable suggestion
Suggested change
|
||||||||||||
| int status = fileChooser.showSaveDialog(EditorWindow.win); | ||||||||||||
| if (status != JFileChooser.APPROVE_OPTION) { | ||||||||||||
| EditorWindow.current_file.setText("Save cancelled"); | ||||||||||||
|
|
@@ -113,8 +171,11 @@ public boolean saveFileAs() { | |||||||||||
| textArea.saveAs(loc); | ||||||||||||
| textArea.load(loc); | ||||||||||||
| file = path.toPath(); | ||||||||||||
| FilePersistance.persistFile(file); | ||||||||||||
| getCursorPositionText(this); | ||||||||||||
| EditorWindow.setSeletedTabTitle(path.getName()); | ||||||||||||
| EditorWindow.current_file.setText("Written to " + path); | ||||||||||||
| isTmp = false; | ||||||||||||
| return true; | ||||||||||||
| } catch (IOException ex) { | ||||||||||||
| JOptionPane.showMessageDialog(EditorWindow.win, ex); | ||||||||||||
|
|
@@ -192,4 +253,36 @@ public static void createTemplateManager() { | |||||||||||
| ctm.addTemplate(ct); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| public boolean load(File fp) { | ||||||||||||
| setIsTmp(false); | ||||||||||||
| var loc = FileLocation.create(fp); | ||||||||||||
| FilePersistance.persistFile(fp.toPath()); | ||||||||||||
| try { | ||||||||||||
| textArea.load(loc); | ||||||||||||
|
|
||||||||||||
| if (fp.getName().endsWith(".pics")) { | ||||||||||||
| textArea.setSyntaxEditingStyle("text/piccode"); | ||||||||||||
| } else if (fp.getName().endsWith(".md")) { | ||||||||||||
| textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_MARKDOWN); | ||||||||||||
| } else { | ||||||||||||
| textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return true; | ||||||||||||
| } catch (IOException ex) { | ||||||||||||
| JOptionPane.showMessageDialog(EditorWindow.win, ex); | ||||||||||||
| return false; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| @Override | ||||||||||||
| public DockKey getDockKey() { | ||||||||||||
| return key; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| @Override | ||||||||||||
| public Component getComponent() { | ||||||||||||
| return this; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package org.editor; | ||
|
|
||
| import com.vlsolutions.swing.docking.DockKey; | ||
| import com.vlsolutions.swing.docking.Dockable; | ||
| import java.awt.Component; | ||
| import java.awt.LayoutManager; | ||
| import javax.swing.JPanel; | ||
| import org.editor.icons.Icons; | ||
|
|
||
| /** | ||
| * | ||
| * @author hexaredecimal | ||
| */ | ||
| public class DockablePanel extends JPanel implements Dockable { | ||
| private DockKey key; | ||
|
|
||
| public DockablePanel(LayoutManager layout) { | ||
| super(layout); | ||
| key = new DockKey("dock-" + System.nanoTime()); | ||
| } | ||
|
|
||
| public DockablePanel(LayoutManager layout, String id) { | ||
| super(layout); | ||
| key = new DockKey(id); | ||
| } | ||
|
|
||
| public DockablePanel(LayoutManager layout, String id, String name, String tip, String icon) { | ||
| super(layout); | ||
| key = new DockKey(id, name, tip, Icons.getIcon(icon)); | ||
| } | ||
|
|
||
| @Override | ||
| public DockKey getDockKey() { | ||
| return key; | ||
| } | ||
|
|
||
| @Override | ||
| public Component getComponent() { | ||
| return this; | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
❓ Verification inconclusive
Verify usage of imported docking classes
You've added imports for
DockKeyandDockablefrom the docking framework, but the class doesn't seem to implement or use these interfaces/classes yet. These imports appear to be in preparation for future changes.🏁 Script executed:
Length of output: 77
Remove Unused Docking Imports
The imports for
com.vlsolutions.swing.docking.DockKeyandcom.vlsolutions.swing.docking.Dockableinsrc/main/java/org/editor/AccessFrame.javaare not referenced anywhere in the code. Please remove them until you actually implement docking support to keep the code clean:• File: src/main/java/org/editor/AccessFrame.java
Lines 3–4
📝 Committable suggestion