Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@
<artifactId>rstaui</artifactId>
<version>3.3.1</version>
</dependency>


<dependency>
<groupId>org.bidib.jbidib.com.vldocking</groupId>
<artifactId>vldocking</artifactId>
<version>3.0.10</version>
</dependency>

</dependencies>

<build>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/editor/AccessFrame.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.editor;

import com.vlsolutions.swing.docking.DockKey;
import com.vlsolutions.swing.docking.Dockable;
Comment on lines +3 to +4
Copy link
Contributor

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 DockKey and Dockable from 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:

#!/bin/bash
# Check if AccessFrame implements Dockable in other parts of the codebase
rg -A 3 "AccessFrame.*implements.*Dockable"

# Check if there are other files where AccessFrame is used with docking functionality
rg "new DockKey.*AccessFrame"

Length of output: 77


Remove Unused Docking Imports

The imports for com.vlsolutions.swing.docking.DockKey and com.vlsolutions.swing.docking.Dockable in src/main/java/org/editor/AccessFrame.java are 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

- import com.vlsolutions.swing.docking.DockKey;
- import com.vlsolutions.swing.docking.Dockable;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import com.vlsolutions.swing.docking.DockKey;
import com.vlsolutions.swing.docking.Dockable;

import org.editor.events.Actions;
import java.awt.BorderLayout;
import java.awt.Color;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/editor/CanvasFrame.java
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Missing interface implementation for Dockable

You've imported the Dockable interface and added a DockKey field, but CanvasFrame doesn't implement the Dockable interface. This appears to be incomplete integration with the docking framework.

-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;
Expand Down Expand Up @@ -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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

DockKey will remain unused without implementing Dockable

This DockKey field has been added but won't be utilized by the docking framework until the class implements the Dockable interface.


private CanvasFrame() {
super(new BorderLayout());
Expand Down Expand Up @@ -319,5 +323,4 @@ private void drawCrosshair(Graphics2D g2) {
g2.fillOval(mouseX - radius, mouseY - radius, radius * 2, radius * 2);
}
}

}
103 changes: 98 additions & 5 deletions src/main/java/org/editor/CodeEditor.java
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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
});

Expand All @@ -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) {
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Only one FileFilter is active – the second setFileFilter overwrites the first

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fileChooser.setFileFilter(FileFilter.mdFilter);
fileChooser.setFileFilter(FileFilter.picsFilter);
fileChooser.addChoosableFileFilter(FileFilter.mdFilter);
fileChooser.addChoosableFileFilter(FileFilter.picsFilter);
fileChooser.setFileFilter(FileFilter.picsFilter); // default selection

int status = fileChooser.showSaveDialog(EditorWindow.win);
if (status != JFileChooser.APPROVE_OPTION) {
EditorWindow.current_file.setText("Save cancelled");
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}
42 changes: 42 additions & 0 deletions src/main/java/org/editor/DockablePanel.java
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;
}

}
Loading