mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-16 16:34:47 -04:00
fixed a bug in auto scale mode
This commit is contained in:
parent
4d95d67745
commit
e01ca85158
@ -968,9 +968,9 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
|
|||||||
transform.translate(dif.x, dif.y);
|
transform.translate(dif.x, dif.y);
|
||||||
transform.scale(f, f);
|
transform.scale(f, f);
|
||||||
transform.translate(-dif.x, -dif.y);
|
transform.translate(-dif.x, -dif.y);
|
||||||
|
isManualScale = true;
|
||||||
if (circuitScrollPanel != null)
|
if (circuitScrollPanel != null)
|
||||||
circuitScrollPanel.transformChanged(transform);
|
circuitScrollPanel.transformChanged(transform);
|
||||||
isManualScale = true;
|
|
||||||
graphicHasChanged();
|
graphicHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -982,9 +982,9 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
|
|||||||
*/
|
*/
|
||||||
public void translateCircuit(int dx, int dy) {
|
public void translateCircuit(int dx, int dy) {
|
||||||
transform.translate(dx, dy);
|
transform.translate(dx, dy);
|
||||||
|
isManualScale = true;
|
||||||
if (circuitScrollPanel != null)
|
if (circuitScrollPanel != null)
|
||||||
circuitScrollPanel.transformChanged(transform);
|
circuitScrollPanel.transformChanged(transform);
|
||||||
isManualScale = true;
|
|
||||||
graphicHasChanged();
|
graphicHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -999,6 +999,8 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
|
|||||||
matrix[4] = x;
|
matrix[4] = x;
|
||||||
transform = new AffineTransform(matrix);
|
transform = new AffineTransform(matrix);
|
||||||
isManualScale = true;
|
isManualScale = true;
|
||||||
|
if (circuitScrollPanel != null)
|
||||||
|
circuitScrollPanel.transformChanged(transform);
|
||||||
graphicHasChanged();
|
graphicHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1013,6 +1015,8 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
|
|||||||
matrix[5] = y;
|
matrix[5] = y;
|
||||||
transform = new AffineTransform(matrix);
|
transform = new AffineTransform(matrix);
|
||||||
isManualScale = true;
|
isManualScale = true;
|
||||||
|
if (circuitScrollPanel != null)
|
||||||
|
circuitScrollPanel.transformChanged(transform);
|
||||||
graphicHasChanged();
|
graphicHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1234,6 +1238,13 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
|
|||||||
undoManager.addListener(listener);
|
undoManager.addListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true is component is in manual scale mode
|
||||||
|
*/
|
||||||
|
boolean isManualScale() {
|
||||||
|
return isManualScale;
|
||||||
|
}
|
||||||
|
|
||||||
private final class PlusMinusAction extends ToolTipAction {
|
private final class PlusMinusAction extends ToolTipAction {
|
||||||
private final int delta;
|
private final int delta;
|
||||||
|
|
||||||
@ -1307,10 +1318,10 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
|
|||||||
Vector delta = newPos.sub(pos);
|
Vector delta = newPos.sub(pos);
|
||||||
double s = transform.getScaleX();
|
double s = transform.getScaleX();
|
||||||
transform.translate(delta.x / s, delta.y / s);
|
transform.translate(delta.x / s, delta.y / s);
|
||||||
|
isManualScale = true;
|
||||||
if (circuitScrollPanel != null)
|
if (circuitScrollPanel != null)
|
||||||
circuitScrollPanel.transformChanged(transform);
|
circuitScrollPanel.transformChanged(transform);
|
||||||
pos = newPos;
|
pos = newPos;
|
||||||
isManualScale = true;
|
|
||||||
graphicHasChanged();
|
graphicHasChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1602,9 +1613,9 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
|
|||||||
public void delete() {
|
public void delete() {
|
||||||
if (!isLocked()) {
|
if (!isLocked()) {
|
||||||
getCircuit().delete(visualElement);
|
getCircuit().delete(visualElement);
|
||||||
|
isManualScale = true;
|
||||||
modify(new ModifyDeleteElement(originalVisualElement));
|
modify(new ModifyDeleteElement(originalVisualElement));
|
||||||
mouseNormal.activate();
|
mouseNormal.activate();
|
||||||
isManualScale = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1669,9 +1680,9 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
|
|||||||
@Override
|
@Override
|
||||||
public void delete() {
|
public void delete() {
|
||||||
getCircuit().delete(wire);
|
getCircuit().delete(wire);
|
||||||
|
isManualScale = true;
|
||||||
modify(new ModifyDeleteWire(originalWire));
|
modify(new ModifyDeleteWire(originalWire));
|
||||||
mouseNormal.activate();
|
mouseNormal.activate();
|
||||||
isManualScale = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1999,9 +2010,9 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
|
|||||||
@Override
|
@Override
|
||||||
public void delete() {
|
public void delete() {
|
||||||
if (!isLocked()) {
|
if (!isLocked()) {
|
||||||
|
isManualScale = true;
|
||||||
modify(new ModifyDeleteRect(Vector.min(corner1, corner2), Vector.max(corner1, corner2)));
|
modify(new ModifyDeleteRect(Vector.min(corner1, corner2), Vector.max(corner1, corner2)));
|
||||||
mouseNormal.activate();
|
mouseNormal.activate();
|
||||||
isManualScale = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public class CircuitScrollPanel extends JPanel {
|
|||||||
private static final int BORDER = SIZE * 10;
|
private static final int BORDER = SIZE * 10;
|
||||||
private final CircuitComponent circuitComponent;
|
private final CircuitComponent circuitComponent;
|
||||||
private final JScrollBar horizontal;
|
private final JScrollBar horizontal;
|
||||||
private final JScrollBar vertcal;
|
private final JScrollBar vertical;
|
||||||
private GraphicMinMax graphicMinMax;
|
private GraphicMinMax graphicMinMax;
|
||||||
private AffineTransform transform;
|
private AffineTransform transform;
|
||||||
|
|
||||||
@ -36,17 +36,18 @@ public class CircuitScrollPanel extends JPanel {
|
|||||||
public CircuitScrollPanel(CircuitComponent circuitComponent) {
|
public CircuitScrollPanel(CircuitComponent circuitComponent) {
|
||||||
super(new BorderLayout());
|
super(new BorderLayout());
|
||||||
horizontal = new JScrollBar(JScrollBar.HORIZONTAL);
|
horizontal = new JScrollBar(JScrollBar.HORIZONTAL);
|
||||||
vertcal = new JScrollBar(JScrollBar.VERTICAL);
|
vertical = new JScrollBar(JScrollBar.VERTICAL);
|
||||||
|
|
||||||
this.circuitComponent = circuitComponent;
|
this.circuitComponent = circuitComponent;
|
||||||
add(circuitComponent, BorderLayout.CENTER);
|
add(circuitComponent, BorderLayout.CENTER);
|
||||||
add(horizontal, BorderLayout.SOUTH);
|
add(horizontal, BorderLayout.SOUTH);
|
||||||
add(vertcal, BorderLayout.EAST);
|
add(vertical, BorderLayout.EAST);
|
||||||
|
|
||||||
horizontal.addAdjustmentListener(adjustmentEvent -> {
|
horizontal.addAdjustmentListener(adjustmentEvent -> {
|
||||||
if (adjustmentEvent.getValueIsAdjusting())
|
if (adjustmentEvent.getValueIsAdjusting())
|
||||||
circuitComponent.translateCircuitToX(-adjustmentEvent.getValue() * transform.getScaleX());
|
circuitComponent.translateCircuitToX(-adjustmentEvent.getValue() * transform.getScaleX());
|
||||||
});
|
});
|
||||||
vertcal.addAdjustmentListener(adjustmentEvent -> {
|
vertical.addAdjustmentListener(adjustmentEvent -> {
|
||||||
if (adjustmentEvent.getValueIsAdjusting())
|
if (adjustmentEvent.getValueIsAdjusting())
|
||||||
circuitComponent.translateCircuitToY(-adjustmentEvent.getValue() * transform.getScaleY());
|
circuitComponent.translateCircuitToY(-adjustmentEvent.getValue() * transform.getScaleY());
|
||||||
});
|
});
|
||||||
@ -89,27 +90,34 @@ public class CircuitScrollPanel extends JPanel {
|
|||||||
private void updateBars() {
|
private void updateBars() {
|
||||||
GraphicMinMax gr = getCircuitSize();
|
GraphicMinMax gr = getCircuitSize();
|
||||||
|
|
||||||
if (gr.getMin() == null || gr.getMax() == null) {
|
if (gr.getMin() == null || gr.getMax() == null || !circuitComponent.isManualScale()) {
|
||||||
horizontal.setVisible(false);
|
horizontal.setVisible(false);
|
||||||
vertcal.setVisible(false);
|
vertical.setVisible(false);
|
||||||
} else {
|
} else {
|
||||||
Point2D min = new Point2D.Float();
|
Point2D min = new Point2D.Float();
|
||||||
Point2D max = new Point2D.Float();
|
Point2D max0 = new Point2D.Float();
|
||||||
try {
|
try {
|
||||||
transform.inverseTransform(new Point2D.Float(0, 0), min);
|
transform.inverseTransform(new Point2D.Float(0, 0), min);
|
||||||
transform.inverseTransform(new Point2D.Float(getWidth(), getHeight()), max);
|
transform.inverseTransform(new Point2D.Float(getWidth(), getHeight()), max0);
|
||||||
int viewDx = (int) (max.getX() - min.getX());
|
int viewDx = (int) (max0.getX() - min.getX());
|
||||||
int viewDy = (int) (max.getY() - min.getY());
|
int viewDy = (int) (max0.getY() - min.getY());
|
||||||
int valueX = (int) min.getX();
|
int valueX = (int) min.getX();
|
||||||
int valueY = (int) min.getY();
|
int valueY = (int) min.getY();
|
||||||
horizontal.setValues(valueX, viewDx, gr.getMin().x - BORDER, gr.getMax().x + BORDER);
|
horizontal.setValues(valueX, viewDx, gr.getMin().x - BORDER, gr.getMax().x + BORDER);
|
||||||
horizontal.setVisible(viewDx < gr.getMax().x - gr.getMin().x + 2 * BORDER);
|
vertical.setValues(valueY, viewDy, gr.getMin().y - BORDER, gr.getMax().y + BORDER);
|
||||||
vertcal.setValues(valueY, viewDy, gr.getMin().y - BORDER, gr.getMax().y + BORDER);
|
|
||||||
vertcal.setVisible(viewDy < gr.getMax().y - gr.getMin().y + 2 * BORDER);
|
|
||||||
|
checkVisibility(horizontal, viewDx, gr.getMax().x - gr.getMin().x + 2 * BORDER);
|
||||||
|
checkVisibility(vertical, viewDy, gr.getMax().y - gr.getMin().y + 2 * BORDER);
|
||||||
} catch (NoninvertibleTransformException e) {
|
} catch (NoninvertibleTransformException e) {
|
||||||
// can not happen! Scaling is never zero!
|
// can not happen! Scaling is never zero!
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkVisibility(JScrollBar bar, int view, int size) {
|
||||||
|
bar.setVisible(view < size);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user