mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
update file icons
scroll the main pane to center after starting
This commit is contained in:
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 972 B |
Binary file not shown.
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.3 KiB |
Binary file not shown.
Binary file not shown.
@@ -25,7 +25,6 @@ import java.io.IOException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
@@ -130,7 +129,6 @@ public class DIYLCStarter {
|
|||||||
|
|
||||||
MainFrame mainFrame = new MainFrame();
|
MainFrame mainFrame = new MainFrame();
|
||||||
mainFrame.setLocationRelativeTo(null);
|
mainFrame.setLocationRelativeTo(null);
|
||||||
mainFrame.setExtendedState(mainFrame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
|
|
||||||
|
|
||||||
splash.setVisible(false);
|
splash.setVisible(false);
|
||||||
splash.dispose();
|
splash.dispose();
|
||||||
|
|||||||
@@ -21,68 +21,68 @@
|
|||||||
*/
|
*/
|
||||||
package org.diylc.swing.gui;
|
package org.diylc.swing.gui;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.awt.Dimension;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowEvent;
|
||||||
import java.awt.event.WindowEvent;
|
import java.io.File;
|
||||||
import java.io.File;
|
import java.util.Arrays;
|
||||||
import java.util.Arrays;
|
import java.util.EnumSet;
|
||||||
import java.util.EnumSet;
|
import java.util.HashMap;
|
||||||
import java.util.HashMap;
|
import java.util.List;
|
||||||
import java.util.List;
|
import java.util.Map;
|
||||||
import java.util.Map;
|
import java.util.Set;
|
||||||
import java.util.Set;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.ButtonGroup;
|
import javax.swing.ButtonGroup;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.JCheckBoxMenuItem;
|
import javax.swing.JCheckBoxMenuItem;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
import javax.swing.JMenuBar;
|
import javax.swing.JMenuBar;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JRadioButtonMenuItem;
|
import javax.swing.JRadioButtonMenuItem;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.SwingWorker;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.Timer;
|
import javax.swing.SwingWorker;
|
||||||
import javax.swing.event.MenuEvent;
|
import javax.swing.Timer;
|
||||||
import javax.swing.event.MenuListener;
|
import javax.swing.event.MenuEvent;
|
||||||
|
import javax.swing.event.MenuListener;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||||
import org.diylc.common.BadPositionException;
|
import org.diylc.common.BadPositionException;
|
||||||
import org.diylc.common.EventType;
|
import org.diylc.common.EventType;
|
||||||
import org.diylc.common.IPlugIn;
|
import org.diylc.common.IPlugIn;
|
||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.common.IPlugInPort;
|
||||||
import org.diylc.common.ITask;
|
import org.diylc.common.ITask;
|
||||||
import org.diylc.common.PropertyWrapper;
|
import org.diylc.common.PropertyWrapper;
|
||||||
import org.diylc.core.IView;
|
import org.diylc.core.IView;
|
||||||
import org.diylc.images.IconLoader;
|
import org.diylc.images.IconLoader;
|
||||||
import org.diylc.presenter.Presenter;
|
import org.diylc.presenter.Presenter;
|
||||||
import org.diylc.swing.IDynamicSubmenuHandler;
|
import org.diylc.swing.IDynamicSubmenuHandler;
|
||||||
import org.diylc.swing.ISwingUI;
|
import org.diylc.swing.ISwingUI;
|
||||||
import org.diylc.swing.gui.actionbar.ActionBarPlugin;
|
import org.diylc.swing.gui.actionbar.ActionBarPlugin;
|
||||||
import org.diylc.swing.gui.editor.PropertyEditorDialog;
|
import org.diylc.swing.gui.editor.PropertyEditorDialog;
|
||||||
import org.diylc.swing.plugins.autosave.AutoSavePlugin;
|
import org.diylc.swing.plugins.autosave.AutoSavePlugin;
|
||||||
import org.diylc.swing.plugins.canvas.CanvasPlugin;
|
import org.diylc.swing.plugins.canvas.CanvasPlugin;
|
||||||
import org.diylc.swing.plugins.cloud.CloudPlugIn;
|
import org.diylc.swing.plugins.cloud.CloudPlugIn;
|
||||||
import org.diylc.swing.plugins.config.ConfigPlugin;
|
import org.diylc.swing.plugins.config.ConfigPlugin;
|
||||||
import org.diylc.swing.plugins.edit.EditMenuPlugin;
|
import org.diylc.swing.plugins.edit.EditMenuPlugin;
|
||||||
import org.diylc.swing.plugins.file.FileFilterEnum;
|
import org.diylc.swing.plugins.file.FileFilterEnum;
|
||||||
import org.diylc.swing.plugins.file.FileMenuPlugin;
|
import org.diylc.swing.plugins.file.FileMenuPlugin;
|
||||||
import org.diylc.swing.plugins.help.HelpMenuPlugin;
|
import org.diylc.swing.plugins.help.HelpMenuPlugin;
|
||||||
import org.diylc.swing.plugins.layers.LayersMenuPlugin;
|
import org.diylc.swing.plugins.layers.LayersMenuPlugin;
|
||||||
import org.diylc.swing.plugins.statusbar.StatusBar;
|
import org.diylc.swing.plugins.statusbar.StatusBar;
|
||||||
import org.diylc.swing.plugins.toolbox.ToolBox;
|
import org.diylc.swing.plugins.toolbox.ToolBox;
|
||||||
import org.diylc.swing.plugins.tree.ComponentTree;
|
import org.diylc.swing.plugins.tree.ComponentTree;
|
||||||
import org.diylc.swingframework.ButtonDialog;
|
import org.diylc.swingframework.ButtonDialog;
|
||||||
|
|
||||||
public class MainFrame extends JFrame implements ISwingUI {
|
public class MainFrame extends JFrame implements ISwingUI {
|
||||||
@@ -159,11 +159,42 @@ public class MainFrame extends JFrame implements ISwingUI {
|
|||||||
presenter.dispose();
|
presenter.dispose();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
setGlassPane(new CustomGlassPane());
|
setGlassPane(new CustomGlassPane());
|
||||||
// getGlassPane().setVisible(true);
|
// getGlassPane().setVisible(true);
|
||||||
|
|
||||||
|
// maximize the screen
|
||||||
|
setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// wait some time for size to update
|
||||||
|
// TODO: find a better solution
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// Important! Notify the canvas to center the scrolls and show the content
|
||||||
|
canvasPlugin.scrollToCenterAndShowContents();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setExtendedState(int state) {
|
||||||
|
super.setExtendedState(state);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Presenter getPresenter() {
|
public Presenter getPresenter() {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import javax.swing.JMenu;
|
|||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
import javax.swing.JScrollBar;
|
import javax.swing.JScrollBar;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
@@ -115,6 +116,21 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the scroll pane location to center and shows the contents. This method must be called when
|
||||||
|
* the frame is initialized or the contents will remain hidden.
|
||||||
|
*
|
||||||
|
* TODO: figure out a better way
|
||||||
|
*/
|
||||||
|
public void scrollToCenterAndShowContents() {
|
||||||
|
JScrollPane scroll = getScrollPane();
|
||||||
|
Dimension totalSize = plugInPort.getCanvasDimensions(true, true);
|
||||||
|
Dimension visibleSize = scroll.getSize();
|
||||||
|
scroll.getHorizontalScrollBar().setValue((totalSize.width - visibleSize.width) / 2);
|
||||||
|
scroll.getVerticalScrollBar().setValue((totalSize.height - visibleSize.height) / 2);
|
||||||
|
getScrollPane().getViewport().setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(IPlugInPort plugInPort) {
|
public void connect(IPlugInPort plugInPort) {
|
||||||
this.plugInPort = plugInPort;
|
this.plugInPort = plugInPort;
|
||||||
@@ -124,21 +140,22 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
LOG.error("Could not install canvas plugin", e);
|
LOG.error("Could not install canvas plugin", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
getScrollPane().setRulerVisible(ConfigurationManager.getInstance().readBoolean(IPlugInPort.SHOW_RULERS_KEY, true));
|
getScrollPane().setRulerVisible(
|
||||||
|
ConfigurationManager.getInstance().readBoolean(IPlugInPort.SHOW_RULERS_KEY, true));
|
||||||
|
|
||||||
// revalidate canvas on scrolling when we render visible rect only
|
// revalidate canvas on scrolling when we render visible rect only
|
||||||
if (CanvasPanel.RENDER_VISIBLE_RECT_ONLY) {
|
if (CanvasPanel.RENDER_VISIBLE_RECT_ONLY) {
|
||||||
getScrollPane().getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {
|
getScrollPane().getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void adjustmentValueChanged(AdjustmentEvent e) {
|
public void adjustmentValueChanged(AdjustmentEvent e) {
|
||||||
getCanvasPanel().invalidateCache();
|
getCanvasPanel().invalidateCache();
|
||||||
getCanvasPanel().revalidate();
|
getCanvasPanel().revalidate();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
getScrollPane().getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
|
getScrollPane().getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void adjustmentValueChanged(AdjustmentEvent e) {
|
public void adjustmentValueChanged(AdjustmentEvent e) {
|
||||||
getCanvasPanel().invalidateCache();
|
getCanvasPanel().invalidateCache();
|
||||||
@@ -147,47 +164,53 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.SHOW_RULERS_KEY, new IConfigListener() {
|
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.SHOW_RULERS_KEY,
|
||||||
|
new IConfigListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void valueChanged(String key, Object value) {
|
public void valueChanged(String key, Object value) {
|
||||||
if (IPlugInPort.SHOW_RULERS_KEY.equals(key))
|
if (IPlugInPort.SHOW_RULERS_KEY.equals(key))
|
||||||
getScrollPane().setRulerVisible((Boolean) value);
|
getScrollPane().setRulerVisible((Boolean) value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.HARDWARE_ACCELERATION, new IConfigListener() {
|
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.HARDWARE_ACCELERATION,
|
||||||
|
new IConfigListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void valueChanged(String key, Object value) {
|
public void valueChanged(String key, Object value) {
|
||||||
canvasPanel.setUseHardwareAcceleration((Boolean) value);
|
canvasPanel.setUseHardwareAcceleration((Boolean) value);
|
||||||
scrollPane.setUseHardwareAcceleration((Boolean) value);
|
scrollPane.setUseHardwareAcceleration((Boolean) value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.METRIC_KEY, new IConfigListener() {
|
|
||||||
|
|
||||||
@Override
|
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.METRIC_KEY,
|
||||||
public void valueChanged(String key, Object value) {
|
new IConfigListener() {
|
||||||
updateZeroLocation();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.EXTRA_SPACE_KEY, new IConfigListener() {
|
@Override
|
||||||
|
public void valueChanged(String key, Object value) {
|
||||||
|
updateZeroLocation();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
@Override
|
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.EXTRA_SPACE_KEY,
|
||||||
public void valueChanged(String key, Object value) {
|
new IConfigListener() {
|
||||||
refreshSize();
|
|
||||||
// Scroll to the center.
|
@Override
|
||||||
Rectangle visibleRect = canvasPanel.getVisibleRect();
|
public void valueChanged(String key, Object value) {
|
||||||
visibleRect.setLocation((canvasPanel.getWidth() - visibleRect.width) / 2,
|
refreshSize();
|
||||||
(canvasPanel.getHeight() - visibleRect.height) / 2);
|
// Scroll to the center.
|
||||||
canvasPanel.scrollRectToVisible(visibleRect);
|
Rectangle visibleRect = canvasPanel.getVisibleRect();
|
||||||
canvasPanel.revalidate();
|
visibleRect.setLocation((canvasPanel.getWidth() - visibleRect.width) / 2,
|
||||||
|
(canvasPanel.getHeight() - visibleRect.height) / 2);
|
||||||
updateZeroLocation();
|
canvasPanel.scrollRectToVisible(visibleRect);
|
||||||
}
|
canvasPanel.revalidate();
|
||||||
});
|
|
||||||
|
updateZeroLocation();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
getScrollPane().getViewport().setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CanvasPanel getCanvasPanel() {
|
public CanvasPanel getCanvasPanel() {
|
||||||
@@ -201,8 +224,9 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
if (scrollPane.isMouseScrollMode() || e.getButton() == MouseEvent.BUTTON2)
|
if (scrollPane.isMouseScrollMode() || e.getButton() == MouseEvent.BUTTON2)
|
||||||
return;
|
return;
|
||||||
plugInPort.mouseClicked(e.getPoint(), e.getButton(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(),
|
plugInPort.mouseClicked(e.getPoint(), e.getButton(),
|
||||||
e.isShiftDown(), e.isAltDown(), e.getClickCount());
|
Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(), e.isAltDown(),
|
||||||
|
e.getClickCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -220,15 +244,16 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (plugInPort.getNewComponentTypeSlot() == null
|
if (plugInPort.getNewComponentTypeSlot() == null && (e.isPopupTrigger()
|
||||||
&& (e.isPopupTrigger() || (pressedEvent != null && pressedEvent.isPopupTrigger()))) {
|
|| (pressedEvent != null && pressedEvent.isPopupTrigger()))) {
|
||||||
// Enable actions.
|
// Enable actions.
|
||||||
boolean enabled = !plugInPort.getSelectedComponents().isEmpty();
|
boolean enabled = !plugInPort.getSelectedComponents().isEmpty();
|
||||||
getCutAction().setEnabled(enabled);
|
getCutAction().setEnabled(enabled);
|
||||||
getCopyAction().setEnabled(enabled);
|
getCopyAction().setEnabled(enabled);
|
||||||
getDuplicateAction().setEnabled(enabled);
|
getDuplicateAction().setEnabled(enabled);
|
||||||
try {
|
try {
|
||||||
getPasteAction().setEnabled(clipboard.isDataFlavorAvailable(ComponentTransferable.listFlavor));
|
getPasteAction().setEnabled(
|
||||||
|
clipboard.isDataFlavorAvailable(ComponentTransferable.listFlavor));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
getPasteAction().setEnabled(false);
|
getPasteAction().setEnabled(false);
|
||||||
}
|
}
|
||||||
@@ -247,7 +272,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
getMirrorHorizontallyAction().setEnabled(enabled);
|
getMirrorHorizontallyAction().setEnabled(enabled);
|
||||||
getMirrorVerticallyAction().setEnabled(enabled);
|
getMirrorVerticallyAction().setEnabled(enabled);
|
||||||
|
|
||||||
getSaveAsTemplateAction().setEnabled(plugInPort.getSelectedComponents().size() == 1);
|
getSaveAsTemplateAction()
|
||||||
|
.setEnabled(plugInPort.getSelectedComponents().size() == 1);
|
||||||
getSaveAsBlockAction().setEnabled(plugInPort.getSelectedComponents().size() > 1);
|
getSaveAsBlockAction().setEnabled(plugInPort.getSelectedComponents().size() > 1);
|
||||||
|
|
||||||
showPopupAt(e.getX(), e.getY());
|
showPopupAt(e.getX(), e.getY());
|
||||||
@@ -261,8 +287,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
if (plugInPort.keyPressed(e.getKeyCode(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(),
|
if (plugInPort.keyPressed(e.getKeyCode(),
|
||||||
e.isShiftDown(), e.isAltDown())) {
|
Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(), e.isAltDown())) {
|
||||||
e.consume();
|
e.consume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -275,8 +301,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
if (scrollPane.isMouseScrollMode())
|
if (scrollPane.isMouseScrollMode())
|
||||||
return;
|
return;
|
||||||
canvasPanel.setCursor(plugInPort.getCursorAt(e.getPoint()));
|
canvasPanel.setCursor(plugInPort.getCursorAt(e.getPoint()));
|
||||||
plugInPort.mouseMoved(e.getPoint(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(),
|
plugInPort.mouseMoved(e.getPoint(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(),
|
||||||
e.isAltDown());
|
e.isShiftDown(), e.isAltDown());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -285,9 +311,9 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
|
|
||||||
private RulerScrollPane getScrollPane() {
|
private RulerScrollPane getScrollPane() {
|
||||||
if (scrollPane == null) {
|
if (scrollPane == null) {
|
||||||
scrollPane =
|
scrollPane = new RulerScrollPane(getCanvasPanel(),
|
||||||
new RulerScrollPane(getCanvasPanel(), new ProjectDrawingProvider(plugInPort, true, false, true), new Size(1d,
|
new ProjectDrawingProvider(plugInPort, true, false, true),
|
||||||
SizeUnit.cm).convertToPixels(), new Size(1d, SizeUnit.in).convertToPixels());
|
new Size(1d, SizeUnit.cm).convertToPixels(), new Size(1d, SizeUnit.in).convertToPixels());
|
||||||
boolean metric = ConfigurationManager.getInstance().readBoolean(Presenter.METRIC_KEY, true);
|
boolean metric = ConfigurationManager.getInstance().readBoolean(Presenter.METRIC_KEY, true);
|
||||||
|
|
||||||
boolean useHardwareAcceleration =
|
boolean useHardwareAcceleration =
|
||||||
@@ -303,7 +329,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
plugInPort.setMetric(isMetric);
|
plugInPort.setMetric(isMetric);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
double extraSpace = plugInPort.getExtraSpace();
|
double extraSpace = plugInPort.getExtraSpace();
|
||||||
scrollPane.setZeroLocation(new Point2D.Double(extraSpace, extraSpace));
|
scrollPane.setZeroLocation(new Point2D.Double(extraSpace, extraSpace));
|
||||||
|
|
||||||
@@ -317,7 +343,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
final JScrollBar horizontalScrollBar = scrollPane.getHorizontalScrollBar();
|
final JScrollBar horizontalScrollBar = scrollPane.getHorizontalScrollBar();
|
||||||
final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
|
final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
|
||||||
|
|
||||||
boolean wheelZoom = ConfigurationManager.getInstance().readBoolean(IPlugInPort.WHEEL_ZOOM_KEY, false);
|
boolean wheelZoom =
|
||||||
|
ConfigurationManager.getInstance().readBoolean(IPlugInPort.WHEEL_ZOOM_KEY, false);
|
||||||
|
|
||||||
if (wheelZoom || (Utils.isMac() ? e.isMetaDown() : e.isControlDown())) {
|
if (wheelZoom || (Utils.isMac() ? e.isMetaDown() : e.isControlDown())) {
|
||||||
|
|
||||||
@@ -349,32 +376,30 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
|
|
||||||
if (selectionBounds == null) {
|
if (selectionBounds == null) {
|
||||||
// center to cursor
|
// center to cursor
|
||||||
Point desiredPos =
|
Point desiredPos = new Point((int) (1d * mousePos.x / oldZoom * newZoom),
|
||||||
new Point((int) (1d * mousePos.x / oldZoom * newZoom), (int) (1d * mousePos.y / oldZoom * newZoom));
|
(int) (1d * mousePos.y / oldZoom * newZoom));
|
||||||
int dx = desiredPos.x - mousePos.x;
|
int dx = desiredPos.x - mousePos.x;
|
||||||
int dy = desiredPos.y - mousePos.y;
|
int dy = desiredPos.y - mousePos.y;
|
||||||
horizontal.setValue(horizontal.getValue() + dx);
|
horizontal.setValue(horizontal.getValue() + dx);
|
||||||
vertical.setValue(vertical.getValue() + dy);
|
vertical.setValue(vertical.getValue() + dy);
|
||||||
} else {
|
} else {
|
||||||
// center to selection
|
// center to selection
|
||||||
horizontal.setValue((int) (selectionBounds.getX() + selectionBounds.getWidth() / 2 - visibleRect
|
horizontal.setValue((int) (selectionBounds.getX() + selectionBounds.getWidth() / 2
|
||||||
.getWidth() / 2));
|
- visibleRect.getWidth() / 2));
|
||||||
vertical.setValue((int) (selectionBounds.getY() + selectionBounds.getHeight() / 2 - visibleRect
|
vertical.setValue((int) (selectionBounds.getY() + selectionBounds.getHeight() / 2
|
||||||
.getHeight() / 2));
|
- visibleRect.getHeight() / 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (e.isShiftDown()) {
|
if (e.isShiftDown()) {
|
||||||
int iScrollAmount = e.getScrollAmount();
|
int iScrollAmount = e.getScrollAmount();
|
||||||
int iNewValue =
|
int iNewValue = horizontalScrollBar.getValue()
|
||||||
horizontalScrollBar.getValue() + horizontalScrollBar.getBlockIncrement() * iScrollAmount
|
+ horizontalScrollBar.getBlockIncrement() * iScrollAmount * e.getWheelRotation();
|
||||||
* e.getWheelRotation();
|
|
||||||
if (iNewValue <= horizontalScrollBar.getMaximum())
|
if (iNewValue <= horizontalScrollBar.getMaximum())
|
||||||
horizontalScrollBar.setValue(iNewValue);
|
horizontalScrollBar.setValue(iNewValue);
|
||||||
} else {
|
} else {
|
||||||
int iScrollAmount = e.getScrollAmount();
|
int iScrollAmount = e.getScrollAmount();
|
||||||
int iNewValue =
|
int iNewValue = verticalScrollBar.getValue()
|
||||||
verticalScrollBar.getValue() + verticalScrollBar.getBlockIncrement() * iScrollAmount
|
+ verticalScrollBar.getBlockIncrement() * iScrollAmount * e.getWheelRotation();
|
||||||
* e.getWheelRotation();
|
|
||||||
if (iNewValue <= verticalScrollBar.getMaximum())
|
if (iNewValue <= verticalScrollBar.getMaximum())
|
||||||
verticalScrollBar.setValue(iNewValue);
|
verticalScrollBar.setValue(iNewValue);
|
||||||
}
|
}
|
||||||
@@ -556,30 +581,32 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
|
|
||||||
public ActionFactory.RotateSelectionAction getRotateClockwiseAction() {
|
public ActionFactory.RotateSelectionAction getRotateClockwiseAction() {
|
||||||
if (rotateClockwiseAction == null) {
|
if (rotateClockwiseAction == null) {
|
||||||
rotateClockwiseAction = ActionFactory.getInstance().createRotateSelectionAction(plugInPort, 1);
|
rotateClockwiseAction =
|
||||||
|
ActionFactory.getInstance().createRotateSelectionAction(plugInPort, 1);
|
||||||
}
|
}
|
||||||
return rotateClockwiseAction;
|
return rotateClockwiseAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionFactory.RotateSelectionAction getRotateCounterclockwiseAction() {
|
public ActionFactory.RotateSelectionAction getRotateCounterclockwiseAction() {
|
||||||
if (rotateCounterclockwiseAction == null) {
|
if (rotateCounterclockwiseAction == null) {
|
||||||
rotateCounterclockwiseAction = ActionFactory.getInstance().createRotateSelectionAction(plugInPort, -1);
|
rotateCounterclockwiseAction =
|
||||||
|
ActionFactory.getInstance().createRotateSelectionAction(plugInPort, -1);
|
||||||
}
|
}
|
||||||
return rotateCounterclockwiseAction;
|
return rotateCounterclockwiseAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionFactory.MirrorSelectionAction getMirrorHorizontallyAction() {
|
public ActionFactory.MirrorSelectionAction getMirrorHorizontallyAction() {
|
||||||
if (mirrorHorizontallyAction == null) {
|
if (mirrorHorizontallyAction == null) {
|
||||||
mirrorHorizontallyAction =
|
mirrorHorizontallyAction = ActionFactory.getInstance().createMirrorSelectionAction(plugInPort,
|
||||||
ActionFactory.getInstance().createMirrorSelectionAction(plugInPort, IComponentTransformer.HORIZONTAL);
|
IComponentTransformer.HORIZONTAL);
|
||||||
}
|
}
|
||||||
return mirrorHorizontallyAction;
|
return mirrorHorizontallyAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionFactory.MirrorSelectionAction getMirrorVerticallyAction() {
|
public ActionFactory.MirrorSelectionAction getMirrorVerticallyAction() {
|
||||||
if (mirrorVerticallyAction == null) {
|
if (mirrorVerticallyAction == null) {
|
||||||
mirrorVerticallyAction =
|
mirrorVerticallyAction = ActionFactory.getInstance().createMirrorSelectionAction(plugInPort,
|
||||||
ActionFactory.getInstance().createMirrorSelectionAction(plugInPort, IComponentTransformer.VERTICAL);
|
IComponentTransformer.VERTICAL);
|
||||||
}
|
}
|
||||||
return mirrorVerticallyAction;
|
return mirrorVerticallyAction;
|
||||||
}
|
}
|
||||||
@@ -635,23 +662,24 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
|
|
||||||
public ActionFactory.ExpandSelectionAction getExpandSelectionAllAction() {
|
public ActionFactory.ExpandSelectionAction getExpandSelectionAllAction() {
|
||||||
if (expandSelectionAllAction == null) {
|
if (expandSelectionAllAction == null) {
|
||||||
expandSelectionAllAction = ActionFactory.getInstance().createExpandSelectionAction(plugInPort, ExpansionMode.ALL);
|
expandSelectionAllAction =
|
||||||
|
ActionFactory.getInstance().createExpandSelectionAction(plugInPort, ExpansionMode.ALL);
|
||||||
}
|
}
|
||||||
return expandSelectionAllAction;
|
return expandSelectionAllAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionFactory.ExpandSelectionAction getExpandSelectionImmediateAction() {
|
public ActionFactory.ExpandSelectionAction getExpandSelectionImmediateAction() {
|
||||||
if (expandSelectionImmediateAction == null) {
|
if (expandSelectionImmediateAction == null) {
|
||||||
expandSelectionImmediateAction =
|
expandSelectionImmediateAction = ActionFactory.getInstance()
|
||||||
ActionFactory.getInstance().createExpandSelectionAction(plugInPort, ExpansionMode.IMMEDIATE);
|
.createExpandSelectionAction(plugInPort, ExpansionMode.IMMEDIATE);
|
||||||
}
|
}
|
||||||
return expandSelectionImmediateAction;
|
return expandSelectionImmediateAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionFactory.ExpandSelectionAction getExpandSelectionSameTypeAction() {
|
public ActionFactory.ExpandSelectionAction getExpandSelectionSameTypeAction() {
|
||||||
if (expandSelectionSameTypeAction == null) {
|
if (expandSelectionSameTypeAction == null) {
|
||||||
expandSelectionSameTypeAction =
|
expandSelectionSameTypeAction = ActionFactory.getInstance()
|
||||||
ActionFactory.getInstance().createExpandSelectionAction(plugInPort, ExpansionMode.SAME_TYPE);
|
.createExpandSelectionAction(plugInPort, ExpansionMode.SAME_TYPE);
|
||||||
}
|
}
|
||||||
return expandSelectionSameTypeAction;
|
return expandSelectionSameTypeAction;
|
||||||
}
|
}
|
||||||
@@ -675,7 +703,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
canvasPanel.scrollRectToVisible(visibleRect);
|
canvasPanel.scrollRectToVisible(visibleRect);
|
||||||
canvasPanel.revalidate();
|
canvasPanel.revalidate();
|
||||||
}
|
}
|
||||||
@@ -688,12 +716,12 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
// Try to set the visible area to be centered with the previous
|
// Try to set the visible area to be centered with the previous
|
||||||
// one.
|
// one.
|
||||||
double zoomFactor = (Double) params[0] / zoomLevel;
|
double zoomFactor = (Double) params[0] / zoomLevel;
|
||||||
visibleRect.setBounds((int) (visibleRect.x * zoomFactor), (int) (visibleRect.y * zoomFactor),
|
visibleRect.setBounds((int) (visibleRect.x * zoomFactor),
|
||||||
visibleRect.width, visibleRect.height);
|
(int) (visibleRect.y * zoomFactor), visibleRect.width, visibleRect.height);
|
||||||
|
|
||||||
canvasPanel.scrollRectToVisible(visibleRect);
|
canvasPanel.scrollRectToVisible(visibleRect);
|
||||||
canvasPanel.revalidate();
|
canvasPanel.revalidate();
|
||||||
|
|
||||||
updateZeroLocation();
|
updateZeroLocation();
|
||||||
|
|
||||||
zoomLevel = (Double) params[0];
|
zoomLevel = (Double) params[0];
|
||||||
@@ -717,9 +745,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refreshSize() {
|
private void refreshSize() {
|
||||||
Dimension d =
|
Dimension d = plugInPort.getCanvasDimensions(true,
|
||||||
plugInPort.getCanvasDimensions(true,
|
ConfigurationManager.getInstance().readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true));
|
||||||
ConfigurationManager.getInstance().readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true));
|
|
||||||
canvasPanel.setSize(d);
|
canvasPanel.setSize(d);
|
||||||
canvasPanel.setPreferredSize(d);
|
canvasPanel.setPreferredSize(d);
|
||||||
getScrollPane().setZoomLevel(plugInPort.getZoomLevel());
|
getScrollPane().setZoomLevel(plugInPort.getZoomLevel());
|
||||||
@@ -729,11 +756,12 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
* Causes ruler scroll pane to refresh by sending a fake mouse moved message to the canvasPanel.
|
* Causes ruler scroll pane to refresh by sending a fake mouse moved message to the canvasPanel.
|
||||||
*/
|
*/
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
MouseEvent event = new MouseEvent(canvasPanel, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, 1, 1,// canvasPanel.getWidth()
|
MouseEvent event =
|
||||||
// /
|
new MouseEvent(canvasPanel, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, 1, 1, // canvasPanel.getWidth()
|
||||||
// 2,
|
// /
|
||||||
// canvasPanel.getHeight() / 2,
|
// 2,
|
||||||
0, false);
|
// canvasPanel.getHeight() / 2,
|
||||||
|
0, false);
|
||||||
canvasPanel.dispatchEvent(event);
|
canvasPanel.dispatchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user