Skip to content

Commit

Permalink
Version 0.2.1.
Browse files Browse the repository at this point in the history
* Save last scroll position.
* Modify read dialog.
  • Loading branch information
shigenobu committed Nov 30, 2023
1 parent 2366616 commit d928bc3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.walksocket</groupId>
<artifactId>ebonyrack</artifactId>
<version>0.2.0</version>
<version>0.2.1</version>
<packaging>jar</packaging>

<name>ebonyrack</name>
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/com/walksocket/er/component/main/Root.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import com.walksocket.er.component.main.root.Workspace;
import com.walksocket.er.config.CfgProject;
import java.awt.BorderLayout;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;

Expand All @@ -32,6 +35,11 @@ public class Root extends JPanel {
*/
private final Workspace workspace;

/**
* resized.
*/
private boolean resized;

/**
* Constructor.
*
Expand All @@ -41,6 +49,10 @@ public class Root extends JPanel {
public Root(Main main, CfgProject cfgProject) {
this.main = main;

// invisible
var root = this;
root.setVisible(false);

// layout
setLayout(new BorderLayout());

Expand Down Expand Up @@ -89,7 +101,36 @@ public Root(Main main, CfgProject cfgProject) {
var scrollPaneWorkspace = new JScrollPane(workspace, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPaneWorkspace.getHorizontalScrollBar().setUnitIncrement(30);
scrollPaneWorkspace.getHorizontalScrollBar().addAdjustmentListener(adjustmentEvent -> {
var sb = (JScrollBar) adjustmentEvent.getSource();
if (!sb.getValueIsAdjusting() && resized) {
cfgProject.pos.workspaceHorizontalScroll = sb.getValue();
Config.save();
}
});
scrollPaneWorkspace.getVerticalScrollBar().setUnitIncrement(30);
scrollPaneWorkspace.getVerticalScrollBar().addAdjustmentListener(adjustmentEvent -> {
var sb = (JScrollBar) adjustmentEvent.getSource();
if (!sb.getValueIsAdjusting() && resized) {
cfgProject.pos.workspaceVerticalScroll = sb.getValue();
Config.save();
}
});
workspace.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
if (!resized) {
scrollPaneWorkspace.getHorizontalScrollBar()
.setValue(cfgProject.pos.workspaceHorizontalScroll);
scrollPaneWorkspace.getVerticalScrollBar()
.setValue(cfgProject.pos.workspaceVerticalScroll);
resized = true;

// visible
root.setVisible(true);
}
}
});
sp.setRightComponent(scrollPaneWorkspace);

// sync side between workspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
Expand Down Expand Up @@ -93,7 +94,8 @@ protected void paintComponent(Graphics g) {
viewFrame.updateScaleRatio(scaleRatio);

var g2 = (Graphics2D) g.create();
g2.drawImage(captureImage, 0, 0, w, h, new Color(73, 70, 44, 8), null);
g2.drawImage(captureImage.getScaledInstance(w, h, Image.SCALE_DEFAULT), 0, 0, w, h,
new Color(73, 70, 44, 8), null);
g2.dispose();

var p = workspace.getParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private JPanel getDataPanel() {
chooser.setFileFilter(new FileNameExtensionFilter("*" + dotFormat,
format));
chooser.setSelectedFile(new File(file));
var result = chooser.showSaveDialog(this);
var result = chooser.showOpenDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
var fileName = chooser.getSelectedFile().getAbsolutePath();
if (!fileName.endsWith(dotFormat)) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/walksocket/er/config/CfgProjectPos.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ public class CfgProjectPos {
* side divider.
*/
public int sideDivider;

/**
* workspace horizontal scroll.
*/
public int workspaceHorizontalScroll;

/**
* workspace vertical scroll.
*/
public int workspaceVerticalScroll;
}

0 comments on commit d928bc3

Please sign in to comment.