-
Notifications
You must be signed in to change notification settings - Fork 10
Changes for discussion #36
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 |
|---|---|---|
|
|
@@ -19,7 +19,6 @@ | |
| import java.awt.*; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.net.URL; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.StandardOpenOption; | ||
|
|
@@ -46,28 +45,21 @@ | |
| * business logic. | ||
| */ | ||
| public class MainFrame extends JFrame { | ||
|
|
||
| private static final long serialVersionUID = 2628641249775639871L; | ||
|
|
||
| // --- Subsystems --- | ||
| private final RenderingEngine renderingEngine; | ||
| private final Timer debounceTimer; | ||
| private final RecentFilesManager recentFilesManager; // NEW: Manager instance | ||
|
|
||
| // --- File Handling State --- | ||
| private final JFileChooser fileChooser; | ||
| private Path currentFilePath = null; | ||
| // --- UI Components (Injected by Sierra) --- | ||
| // Stores the path of the currently loaded file | ||
|
|
||
| @Outlet | ||
| private JMenuBar menuBar; | ||
|
|
||
| @Outlet | ||
| private JMenuItem openItem; | ||
| // Stores the path of the currently loaded file | ||
| private Path currentFilePath = null; | ||
|
|
||
| @Outlet | ||
| private JMenuItem saveItem; | ||
| // --- UI Components (Injected by Sierra) --- | ||
|
Contributor
Author
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. Current convention is to declare outlets as follows, although obviously either will work. Initializing the value to |
||
| private @Outlet JMenuBar menuBar = null; | ||
| private @Outlet JMenuItem openItem = null; | ||
| private @Outlet JMenuItem saveItem = null; | ||
|
|
||
| @Outlet | ||
| private JMenu recentMenu; | ||
|
|
@@ -81,9 +73,6 @@ public class MainFrame extends JFrame { | |
| @Outlet | ||
| private JSplitPane splitPane; | ||
|
|
||
| @Outlet | ||
|
Contributor
Author
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. This outlet is not needed when the editor pane is declared in markup - see below. |
||
| private JScrollPane editorScrollPane; | ||
|
|
||
| @Outlet | ||
| private JPanel previewPanel; | ||
|
|
||
|
|
@@ -93,33 +82,31 @@ public class MainFrame extends JFrame { | |
| @Outlet | ||
| private JLabel filePathLabel; // The <label> for the file path | ||
|
|
||
| // --- Manually Created Components --- | ||
| private RSyntaxTextArea editorPane; | ||
|
Contributor
Author
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. Moved to markup. |
||
| @Outlet | ||
| private RSyntaxTextArea editorPane; | ||
|
Contributor
Author
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. Existing Sierra code uses spaces rather than tabs. |
||
|
|
||
| public MainFrame() { | ||
| super("Sierra UI Previewer"); | ||
|
Contributor
Author
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. Minor - |
||
| this.renderingEngine = new RenderingEngine(); | ||
| renderingEngine = new RenderingEngine(); | ||
|
|
||
| this.recentFilesManager = new RecentFilesManager(MainFrame.class); | ||
| recentFilesManager = new RecentFilesManager(MainFrame.class); | ||
|
|
||
| setContentPane(UILoader.load(this, "MainFrame.xml")); | ||
| // @todo see why it wasn't working to set in xml | ||
|
|
||
| // This is an overloaded setter; BeanAdapter only recognizes the version | ||
| // with the same type as the getter | ||
| splitPane.setDividerLocation(0.5); | ||
| splitPane.setResizeWeight(0.5); | ||
|
|
||
| this.fileChooser = new JFileChooser(); | ||
| FileNameExtensionFilter xmlFilter = new FileNameExtensionFilter("XML Files (*.xml)", "xml"); | ||
| fileChooser = new JFileChooser(); | ||
| var xmlFilter = new FileNameExtensionFilter("XML Files (*.xml)", "xml"); | ||
|
Contributor
Author
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. Current Sierra code uses the |
||
| fileChooser.setFileFilter(xmlFilter); | ||
| fileChooser.setAcceptAllFileFilterUsed(false); | ||
|
|
||
| setupMenuBar(); | ||
|
|
||
| setupCustomEditor(); | ||
|
|
||
| // 5. Set layout for previewPanel | ||
| // previewPanel.setLayout(new BorderLayout()); | ||
|
|
||
| this.debounceTimer = setupDebounceTimer(); | ||
| debounceTimer = setupDebounceTimer(); | ||
|
|
||
| // Wire editor events | ||
| editorPane.getDocument().addDocumentListener(new DocumentListener() { | ||
|
|
@@ -141,8 +128,8 @@ public void changedUpdate(DocumentEvent e) { | |
| } | ||
| }); | ||
|
|
||
| URL iconURL = getClass().getResource("/sierra.png"); | ||
| Image icon = new ImageIcon(iconURL).getImage(); | ||
| var iconURL = getClass().getResource("/sierra.png"); | ||
| var icon = new ImageIcon(iconURL).getImage(); | ||
| this.setIconImage(icon); | ||
|
|
||
| // 8. Trigger an initial render | ||
|
|
@@ -228,11 +215,7 @@ private CompletionProvider createCompletionProvider() { | |
| * placeholder that Sierra injected. | ||
| */ | ||
| private void setupCustomEditor() { | ||
| editorPane = new RSyntaxTextArea(25, 80); | ||
|
Contributor
Author
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. Moved to markup. |
||
| editorPane.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML); | ||
| editorPane.setCodeFoldingEnabled(true); | ||
| editorPane.setAntiAliasingEnabled(true); | ||
| editorPane.setEditable(true); // Ensure it's editable | ||
|
|
||
| CompletionProvider provider = createCompletionProvider(); | ||
|
|
||
|
|
@@ -245,8 +228,6 @@ private void setupCustomEditor() { | |
| if (provider != null) { | ||
| ac.install(editorPane); | ||
| } | ||
|
|
||
| editorScrollPane.setViewportView(editorPane); | ||
| } | ||
|
|
||
| // --- Rendering/Control Logic --- | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,8 +49,7 @@ private void loadRecentFiles() { | |
| // Split the string by the separator, convert to Path objects, and collect. | ||
| recentFiles.addAll(Arrays.stream(savedList.split(PATH_SEPARATOR)) | ||
| .filter(s -> !s.trim().isEmpty()) | ||
| .map(Paths::get) | ||
| .collect(Collectors.toList())); | ||
| .map(Paths::get).toList()); | ||
|
Contributor
Author
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.
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -77,7 +76,7 @@ public void addFile(Path path) { | |
| recentFiles.remove(path); | ||
|
|
||
| // 2. Add to the front (most recent) | ||
| recentFiles.add(0, path); | ||
| recentFiles.addFirst(path); | ||
|
Contributor
Author
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.
|
||
|
|
||
| // 3. Trim the list if it exceeds the max size | ||
| if (recentFiles.size() > MAX_RECENT_FILES) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,21 +14,21 @@ | |
| package org.httprpc.sierra.previewer; | ||
|
|
||
| import com.formdev.flatlaf.FlatLightLaf; | ||
| import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; | ||
| import org.httprpc.sierra.UILoader; | ||
|
|
||
| import javax.swing.*; | ||
|
|
||
| public class SierraPreviewerApp { | ||
|
|
||
| public static void main(String[] args) { | ||
| FlatLightLaf.setup(); | ||
|
Contributor
Author
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. This is the recommended way to initialize FlatLaf. |
||
|
|
||
| UILoader.bind("syntax-text-area", RSyntaxTextArea.class, RSyntaxTextArea::new); | ||
|
|
||
| // Run all UI code on the Event Dispatch Thread (EDT) | ||
| SwingUtilities.invokeLater(() -> { | ||
| try { | ||
| // Set a modern Look and Feel if available | ||
| UIManager.setLookAndFeel(new FlatLightLaf()); | ||
| } catch (Exception e) { | ||
| System.err.println("Could not set System Look and Feel."); | ||
| } | ||
|
|
||
| MainFrame frame = new MainFrame(); | ||
| var frame = new MainFrame(); | ||
| frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
| frame.setSize(1200, 800); | ||
| frame.setLocationRelativeTo(null); // Center on screen | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,20 +62,15 @@ public SierraXMLCompletionProvider() { | |
| } | ||
|
|
||
| private void loadTags() { | ||
|
Contributor
Author
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. Minor simplification that avoids unnecessary local declarations. |
||
| Iterable<String> tagNames = UILoader.getTags(); | ||
| for (String tagName : tagNames) { | ||
| tagCompletions.add(new BasicCompletion(this, tagName, "Sierra UI Element")); | ||
| Class<?> type = UILoader.getType(tagName); | ||
| Map<String, String> attributes = getAttributesForClass(type); | ||
| elementAttributeDefinitions.put(tagName, attributes); | ||
| for (var tag : UILoader.getTags()) { | ||
| tagCompletions.add(new BasicCompletion(this, tag, "Sierra UI Element")); | ||
| elementAttributeDefinitions.put(tag, getAttributesForClass(UILoader.getType(tag))); | ||
| } | ||
|
|
||
| tagCompletions.sort(Comparator.comparing(Completion::getInputText)); | ||
|
|
||
|
|
||
| baseClassAttributeDefinitions.put(JComponent.class.getName(), getAttributesForClass(JComponent.class)); | ||
| addCommonAttributes(); | ||
|
|
||
| } | ||
|
|
||
| private void addCommonAttributes() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE column-panel SYSTEM "sierra.dtd"> | ||
|
|
||
| <column-panel> | ||
| <menu-bar name="menuBar"> | ||
| <menu text="File"> | ||
|
|
@@ -12,26 +12,18 @@ | |
| </menu> | ||
| <menu text="About"> | ||
| <menu-item name="aboutItem" text="About Previewer"/> | ||
| </menu> | ||
| </menu> | ||
| </menu-bar> | ||
|
|
||
| <split-pane name="splitPane" weight="1"> | ||
| <scroll-pane name="editorScrollPane" weight="1"> | ||
| <label text="XML will appear here." | ||
| horizontalAlignment="center" | ||
| verticalAlignment="center" | ||
| foreground="gray" | ||
| weight="1"/> | ||
| </scroll-pane> | ||
| <column-panel name="previewPanel" padding="5, 5, 5, 5" weight="1"> | ||
| <label text="Preview will appear here." | ||
| horizontalAlignment="center" | ||
| verticalAlignment="center" | ||
| foreground="gray" | ||
| weight="1"/> | ||
| </column-panel> | ||
| </split-pane> | ||
|
|
||
| <label name="filePathLabel" text="" padding="4, 6, 4, 6"/> | ||
| <split-pane name="splitPane" resizeWeight="0.5" weight="1"> | ||
| <scroll-pane weight="1"> | ||
| <syntax-text-area name="editorPane" columns="80" rows="25" | ||
|
Contributor
Author
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. Declare editor in markup.
Contributor
Author
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. I just realized that this will make it seem like "syntax-text-area" is part of the standard distribution, which it is not. So maybe this is not a good idea after all.
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. Yeah agree - only valid widgets should be in the xml - even if they are placeholders to be replaced at runtime |
||
| codeFoldingEnabled="true" | ||
| antiAliasingEnabled="true"/> | ||
| </scroll-pane> | ||
| <column-panel name="previewPanel" padding="5, 5, 5, 5" weight="1"/> | ||
|
Contributor
Author
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. Drop placeholder label that didn't seem to be visible in UI.
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. yeah at one point I had it showing and then somehow messed it up |
||
| </split-pane> | ||
|
|
||
| <label name="filePathLabel" padding="4, 6, 4, 6"/> | ||
| <label name="statusBar" text="Ready." padding="2, 5, 2, 5"/> | ||
| </column-panel> | ||
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.
Unless you plan to serialize the frame instance, this declaration isn't strictly necessary.