issue - GH#93: Add scrollbar to design canvas
MODIFY
builder/src/main/java/builder/Builder.java
builder/src/main/java/builder/Builder.java
@@ -108,6 +108,12 @@ public class Builder extends JDesktopPane {
/** The Constant NEW_PROJECT. */
public static final String NEW_PROJECT = " - unnamed project";
+ /** The canvas width */
+ public static int CANVAS_WIDTH;
+
+ /** The canvas height */
+ public static int CANVAS_HEIGHT;
+
/** The frame. */
private JFrame frame;
@@ -315,7 +321,14 @@ public class Builder extends JDesktopPane {
int height = Math.max(GeneralEditor.getInstance().getHeight()+40, 700);
frame.setPreferredSize(new Dimension(width, height));
frame.pack();
- CommonUtil.getInstance().setWinOffsets(controller.getPanel().getSize(),
+
+ // setup our canvas offsets
+ // NOTE: we can't use controller.getPanel().getSize()
+ // since its a scrollpane thats much larger than actual screen size
+ CANVAS_WIDTH = GeneralEditor.getInstance().getWidth()+205;
+ CANVAS_HEIGHT = GeneralEditor.getInstance().getHeight()+235;
+ Dimension canvasSz = new Dimension(CANVAS_WIDTH, CANVAS_HEIGHT);
+ CommonUtil.getInstance().setWinOffsets(canvasSz,
GeneralEditor.getInstance().getWidth(),
GeneralEditor.getInstance().getHeight());
frame.setLocationRelativeTo(null);

MODIFY
builder/src/main/java/builder/controller/Controller.java
builder/src/main/java/builder/controller/Controller.java
@@ -58,6 +58,7 @@ import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
+import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.filechooser.FileFilter;
@@ -192,7 +193,9 @@ public class Controller extends JInternalFrame
MsgBoard.getInstance().subscribe(this);
layout = new CardLayout();
cards = new JPanel(layout);
- this.add(cards);
+ JScrollPane scrollPane = new JScrollPane(cards);
+
+ this.add(scrollPane);
this.setTitle(title);
createFirstPage();
this.setVisible(true);
@@ -853,28 +856,9 @@ public class Controller extends JInternalFrame
*/
@Override
public Dimension getPreferredSize() {
- return new Dimension(generalEditor.getWidth(), generalEditor.getHeight());
+ return new Dimension(1200,1200);
}
- /**
- * getMaximumSize
- *
- * @see javax.swing.JComponent#getMaximumSize()
- */
- @Override
- public Dimension getMaximumSize() {
- return new Dimension(generalEditor.getWidth(), generalEditor.getHeight());
- }
-
- /**
- * getMinimumSize
- *
- * @see javax.swing.JComponent#getMinimumSize()
- */
- @Override
- public Dimension getMinimumSize() {
- return new Dimension(generalEditor.getWidth(), generalEditor.getHeight());
- }
/**
* updateEvent
@@ -1322,15 +1306,26 @@ public class Controller extends JInternalFrame
generalEditor.getHeight() != displayHeight) {
displayWidth = generalEditor.getWidth();
displayHeight = generalEditor.getHeight();
- getPanel().setPreferredSize(new Dimension(displayWidth, displayHeight));
+// getPanel().setPreferredSize(new Dimension(displayWidth, displayHeight));
int width = Math.max(displayWidth + 600, 700);
int height = Math.max(displayHeight + 40, 700);
Dimension d = new Dimension(width, height);
topFrame.setPreferredSize(d);
topFrame.setMaximumSize(d);
topFrame.setMinimumSize(d);
+ Builder.CANVAS_WIDTH = GeneralEditor.getInstance().getWidth()+205;
+ Builder.CANVAS_HEIGHT = GeneralEditor.getInstance().getHeight()+235;
+ Dimension canvasSz = new Dimension(Builder.CANVAS_WIDTH, Builder.CANVAS_HEIGHT);
+ CommonUtil.getInstance().setWinOffsets(canvasSz,
+ GeneralEditor.getInstance().getWidth(),
+ GeneralEditor.getInstance().getHeight());
+
topFrame.revalidate();
- CommonUtil.getInstance().setWinOffsets(getPanel().getSize(), displayWidth, displayHeight);
+ MsgEvent ev = new MsgEvent();
+ ev.message ="";
+ ev.parent = "";
+ ev.code = MsgEvent.CANVAS_MODEL_CHANGE;
+ MsgBoard.getInstance().publish(ev);
topFrame.repaint();
}
refreshView(); // refresh view no matter what changed.

MODIFY
builder/src/main/java/builder/views/PagePane.java
builder/src/main/java/builder/views/PagePane.java
@@ -51,6 +51,7 @@ import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
+import builder.Builder;
import builder.commands.Command;
import builder.commands.DragWidgetCommand;
import builder.commands.History;
@@ -153,6 +154,12 @@ public class PagePane extends JPanel implements iSubscriber {
/** The inverse AffineTransform at. */
private AffineTransform inv_at;
+ /** The canvas width */
+ int canvasWidth;
+
+ /** The canvas height */
+ int canvasHeight;
+
/**
* Instantiates a new page pane.
*/
@@ -165,6 +172,8 @@ public class PagePane extends JPanel implements iSubscriber {
gridModel = (GridModel) GridEditor.getInstance().getModel();
model = new PageModel();
mousePt = new Point(generalModel.getWidth() / 2, generalModel.getHeight() / 2);
+ canvasWidth = Builder.CANVAS_WIDTH;
+ canvasHeight = Builder.CANVAS_HEIGHT;
this.addMouseListener(new MouseHandler());
this.addMouseMotionListener(new MouseMotionHandler());
this.addKeyListener(new DeleteKeyListener());
@@ -208,13 +217,14 @@ public class PagePane extends JPanel implements iSubscriber {
Graphics2D g2d = (Graphics2D) g.create();
if (bZoom) {
at = new AffineTransform();
- Dimension d = this.getSize();
+ Dimension d = new Dimension(canvasWidth, canvasHeight);
double xRel = ((double)d.getWidth() - (double)gridModel.getWidth()) / 2.0;
double yRel = ((double)d.getHeight() - (double)gridModel.getHeight()) / 2.0;;
double zoomDiv = zoomFactor / prevZoomFactor;
xOffset = (zoomDiv) * (xOffset) + (1 - zoomDiv) * xRel;
+
yOffset = (zoomDiv) * (yOffset) + (1 - zoomDiv) * yRel;
at.translate(xOffset, yOffset);
at.scale(zoomFactor, zoomFactor);
@@ -260,6 +270,13 @@ public class PagePane extends JPanel implements iSubscriber {
zoomFactor *= 1.1;
bZoom = true;
ToolBar.getInstance().btn_zoom_out.setEnabled(true);
+ canvasWidth = (int)(Builder.CANVAS_WIDTH * zoomFactor);
+ canvasHeight = (int)(Builder.CANVAS_HEIGHT * zoomFactor);
+ System.out.println("in: " + zoomFactor + " zw: " + canvasWidth + " zh: " + canvasHeight);
+ Dimension canvasSz = new Dimension((int)canvasWidth, (int)canvasHeight);
+ CommonUtil.getInstance().setWinOffsets(canvasSz,
+ GeneralEditor.getInstance().getWidth(),
+ GeneralEditor.getInstance().getHeight());
repaint();
}
@@ -271,6 +288,13 @@ public class PagePane extends JPanel implements iSubscriber {
if (zoomFactor < 1.1)
ToolBar.getInstance().btn_zoom_out.setEnabled(false);
bZoom = true;
+ canvasWidth = (int)(Builder.CANVAS_WIDTH * zoomFactor);
+ canvasHeight = (int)(Builder.CANVAS_HEIGHT * zoomFactor);
+ System.out.println("out: " + zoomFactor + " zw: " + canvasWidth + " zh: " + canvasHeight);
+ Dimension canvasSz = new Dimension((int)canvasWidth, (int)canvasHeight);
+ CommonUtil.getInstance().setWinOffsets(canvasSz,
+ GeneralEditor.getInstance().getWidth(),
+ GeneralEditor.getInstance().getHeight());
repaint();
}
@@ -777,29 +801,8 @@ public class PagePane extends JPanel implements iSubscriber {
*/
@Override
public Dimension getPreferredSize() {
- return new Dimension(gridModel.getWidth(), gridModel.getHeight());
- }
-
- /**
- * getMaximumSize.
- *
- * @return the maximum size
- * @see javax.swing.JComponent#getMaximumSize()
- */
- @Override
- public Dimension getMaximumSize() {
- return new Dimension(gridModel.getWidth(), gridModel.getHeight());
- }
-
- /**
- * getMinimumSize.
- *
- * @return the minimum size
- * @see javax.swing.JComponent#getMinimumSize()
- */
- @Override
- public Dimension getMinimumSize() {
- return new Dimension(gridModel.getWidth(), gridModel.getHeight());
+// return new Dimension(gridModel.getWidth(), gridModel.getHeight());
+ return new Dimension(1200, 1200);
}
/**
@@ -849,7 +852,9 @@ public class PagePane extends JPanel implements iSubscriber {
selectNone();
repaint();
} else if (e.code == MsgEvent.CANVAS_MODEL_CHANGE) {
- CommonUtil.getInstance().setWinOffsets(this.getSize(),
+ canvasWidth = (int)(Builder.CANVAS_WIDTH * zoomFactor);
+ canvasHeight = (int)(Builder.CANVAS_HEIGHT * zoomFactor);
+ CommonUtil.getInstance().setWinOffsets(new Dimension(canvasWidth, canvasHeight),
generalModel.getWidth(),
generalModel.getHeight());
repaint();

issue #39 - GH#93: Add scrollbar to design canvas