show selection size on demand

removed scroll buttons in toolbox
This commit is contained in:
bancika
2011-01-24 18:17:13 +00:00
parent fb5baf9571
commit b33b6b6495
8 changed files with 83 additions and 94 deletions
@@ -1,15 +1,15 @@
<map> <map>
<entry> <entry>
<string>metric</string> <string>lastPath</string>
<boolean>true</boolean> <string>C:\Documents and Settings\Branislav Stojkovic\Desktop\oldFiles</string>
</entry> </entry>
<entry> <entry>
<string>zoom</string> <string>zoom</string>
<double>1.0</double> <double>1.0</double>
</entry> </entry>
<entry> <entry>
<string>lastPath</string> <string>metric</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string> <boolean>true</boolean>
</entry> </entry>
<entry> <entry>
<string>default.org.diylc.components.misc.Label:Color</string> <string>default.org.diylc.components.misc.Label:Color</string>
@@ -48,10 +48,6 @@ public enum EventType {
* object containing selection size (x = width, y = height). Size is * object containing selection size (x = width, y = height). Size is
* expressed in the default measure (cm for metric, inches for imperial). * expressed in the default measure (cm for metric, inches for imperial).
*/ */
SELECTION_SIZE_CHANGED,
/**
* Called when display needs to be repainted. No parameters are passed.
*/
REPAINT, REPAINT,
/** /**
* Called when new component slot has been changed. The only parameter is * Called when new component slot has been changed. The only parameter is
@@ -4,6 +4,7 @@ import java.awt.Cursor;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.geom.Point2D;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -304,4 +305,10 @@ public interface IPlugInPort {
void ungroupSelectedComponents(); void ungroupSelectedComponents();
void setLayerLocked(int layerZOrder, boolean locked); void setLayerLocked(int layerZOrder, boolean locked);
/**
* @return selection size expressed in either inches or centimeters, based
* on the user preference.
*/
Point2D calculateSelectionDimension();
} }
@@ -30,7 +30,7 @@ public enum IconLoader {
"faq.png"), Component("component.png"), Plugin("plugin.png"), Manual("manual.png"), Donate( "faq.png"), Component("component.png"), Plugin("plugin.png"), Manual("manual.png"), Donate(
"donate.png"), Bug("bug.png"), IconLarge("icon_large.png"), IconMedium( "donate.png"), Bug("bug.png"), IconLarge("icon_large.png"), IconMedium(
"icon_medium.png"), IconSmall("icon_small.png"), DocumentEdit("document_edit.png"), EditComponent( "icon_medium.png"), IconSmall("icon_small.png"), DocumentEdit("document_edit.png"), EditComponent(
"edit_component.png"); "edit_component.png"), Size("size.png");
protected String name; protected String name;
Binary file not shown.

After

Width:  |  Height:  |  Size: 550 B

@@ -729,8 +729,6 @@ public class Presenter implements IPlugInPort {
if (repaint) { if (repaint) {
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
} }
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
calculateSelectionDimension());
return true; return true;
} }
@@ -841,8 +839,6 @@ public class Presenter implements IPlugInPort {
@Override @Override
public void setMetric(boolean isMetric) { public void setMetric(boolean isMetric) {
ConfigurationManager.getInstance().writeValue(Presenter.METRIC_KEY, isMetric); ConfigurationManager.getInstance().writeValue(Presenter.METRIC_KEY, isMetric);
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
calculateSelectionDimension());
} }
@Override @Override
@@ -909,12 +905,6 @@ public class Presenter implements IPlugInPort {
includeStuckComponents(controlPointMap); includeStuckComponents(controlPointMap);
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents, messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents,
controlPointMap.keySet()); controlPointMap.keySet());
fireSelectionSizeChanged();
}
private void fireSelectionSizeChanged() {
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
calculateSelectionDimension());
} }
/** /**
@@ -956,11 +946,8 @@ public class Presenter implements IPlugInPort {
return components; return components;
} }
/** @Override
* @return selection size expressed in either inches or centimeters, based public Point2D calculateSelectionDimension() {
* on the user preference.
*/
private Point2D calculateSelectionDimension() {
if (selectedComponents.isEmpty()) { if (selectedComponents.isEmpty()) {
return null; return null;
} }
@@ -1041,8 +1028,6 @@ public class Presenter implements IPlugInPort {
projectFileManager.notifyFileChange(); projectFileManager.notifyFileChange();
} }
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
calculateSelectionDimension());
} }
} }
@@ -6,6 +6,8 @@ import java.awt.GridBagLayout;
import java.awt.Point; import java.awt.Point;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.Format; import java.text.Format;
@@ -20,9 +22,9 @@ import java.util.Map;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JComboBox; import javax.swing.JComboBox;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.diylc.common.BadPositionException; import org.diylc.common.BadPositionException;
@@ -32,9 +34,9 @@ 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.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.images.IconLoader;
import org.diylc.presenter.Presenter; import org.diylc.presenter.Presenter;
import org.diylc.swing.ISwingUI; import org.diylc.swing.ISwingUI;
import org.diylc.swing.gui.MainFrame;
import com.diyfever.gui.MemoryBar; import com.diyfever.gui.MemoryBar;
import com.diyfever.gui.miscutils.ConfigurationManager; import com.diyfever.gui.miscutils.ConfigurationManager;
@@ -123,11 +125,27 @@ public class StatusBar extends JPanel implements IPlugIn {
public JLabel getSizeLabel() { public JLabel getSizeLabel() {
if (sizeLabel == null) { if (sizeLabel == null) {
sizeLabel = new JLabel("N/A"); sizeLabel = new JLabel(IconLoader.Size.getIcon());
sizeLabel.setToolTipText("Selection Size"); sizeLabel.setFocusable(true);
sizeLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder( sizeLabel.setToolTipText("Click to calculate selection size");
0, 1, 0, 1, UIManager.getColor("Separator.shadow")), BorderFactory sizeLabel.addMouseListener(new MouseAdapter() {
.createEmptyBorder(0, 4, 0, 4)));
@Override
public void mouseClicked(MouseEvent e) {
Point2D size = plugInPort.calculateSelectionDimension();
boolean metric = ConfigurationManager.getInstance().readBoolean(
Presenter.METRIC_KEY, true);
String text;
if (size == null) {
text = "Selection is empty.";
} else {
text = "Selection size: " + sizeFormat.format(size.getX()) + " x "
+ sizeFormat.format(size.getY()) + (metric ? " cm" : " in");
}
JOptionPane.showMessageDialog(SwingUtilities.getRootPane(StatusBar.this), text,
"Information", JOptionPane.INFORMATION_MESSAGE);
}
});
} }
return sizeLabel; return sizeLabel;
} }
@@ -151,10 +169,10 @@ public class StatusBar extends JPanel implements IPlugIn {
gbc.gridx = 1; gbc.gridx = 1;
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 0; gbc.weightx = 0;
add(getSizeLabel(), gbc); add(zoomPanel, gbc);
gbc.gridx = 2; gbc.gridx = 2;
add(zoomPanel, gbc); add(getSizeLabel(), gbc);
gbc.gridx = 3; gbc.gridx = 3;
add(getUpdateLabel(), gbc); add(getUpdateLabel(), gbc);
@@ -179,8 +197,7 @@ public class StatusBar extends JPanel implements IPlugIn {
@Override @Override
public EnumSet<EventType> getSubscribedEventTypes() { public EnumSet<EventType> getSubscribedEventTypes() {
return EnumSet.of(EventType.ZOOM_CHANGED, EventType.SLOT_CHANGED, return EnumSet.of(EventType.ZOOM_CHANGED, EventType.SLOT_CHANGED,
EventType.AVAILABLE_CTRL_POINTS_CHANGED, EventType.SELECTION_SIZE_CHANGED, EventType.AVAILABLE_CTRL_POINTS_CHANGED, EventType.SELECTION_CHANGED);
EventType.SELECTION_CHANGED);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -217,18 +234,6 @@ public class StatusBar extends JPanel implements IPlugIn {
Collections.sort(this.stuckComponentNames); Collections.sort(this.stuckComponentNames);
refreshStatusText(); refreshStatusText();
break; break;
case SELECTION_SIZE_CHANGED:
Point2D size = (Point2D) params[0];
boolean metric = ConfigurationManager.getInstance().readBoolean(Presenter.METRIC_KEY,
true);
if (size == null) {
getSizeLabel().setText("N/A");
} else {
getSizeLabel().setText(
sizeFormat.format(size.getX()) + " x " + sizeFormat.format(size.getY())
+ (metric ? " cm" : " in"));
}
break;
case SLOT_CHANGED: case SLOT_CHANGED:
componentSlot = (ComponentType) params[0]; componentSlot = (ComponentType) params[0];
controlPointSlot = (Point) params[1]; controlPointSlot = (Point) params[1];
@@ -3,13 +3,6 @@ package org.diylc.swing.plugins.toolbox;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Component; import java.awt.Component;
import java.awt.Container; import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -49,45 +42,48 @@ class ComponentTabbedPane extends JTabbedPane {
JPanel panel = createTab((componentTypes.get(category))); JPanel panel = createTab((componentTypes.get(category)));
addTab(category, panel); addTab(category, panel);
} }
setPreferredSize(new Dimension(-1, Presenter.ICON_SIZE + ComponentButton.MARGIN * 2 + 38));
} }
private JPanel createTab(List<ComponentType> componentTypes) { private JPanel createTab(List<ComponentType> componentTypes) {
JPanel panel = new JPanel(new BorderLayout()); JPanel panel = new JPanel(new BorderLayout());
final JScrollPane scrollPane = createComponentScrollBar(componentTypes); // final JScrollPane scrollPane =
// createComponentScrollBar(componentTypes);
panel.setOpaque(false); panel.setOpaque(false);
JButton leftButton = new JButton("<"); panel.add(createComponentPanel(componentTypes), BorderLayout.CENTER);
leftButton.addActionListener(new ActionListener() { // JButton leftButton = new JButton("<");
// leftButton.addActionListener(new ActionListener() {
@Override //
public void actionPerformed(ActionEvent e) { // @Override
Rectangle rect = scrollPane.getVisibleRect(); // public void actionPerformed(ActionEvent e) {
if (rect.x > SCROLL_STEP) { // Rectangle rect = scrollPane.getVisibleRect();
rect.translate(-SCROLL_STEP, 0); // if (rect.x > SCROLL_STEP) {
} else { // rect.translate(-SCROLL_STEP, 0);
rect.translate(-rect.x, 0); // } else {
} // rect.translate(-rect.x, 0);
} // }
}); // }
leftButton.setMargin(new Insets(0, 2, 0, 2)); // });
JButton rightButton = new JButton(">"); // leftButton.setMargin(new Insets(0, 2, 0, 2));
rightButton.addActionListener(new ActionListener() { // JButton rightButton = new JButton(">");
// rightButton.addActionListener(new ActionListener() {
@Override //
public void actionPerformed(ActionEvent e) { // @Override
Rectangle rect = scrollPane.getVisibleRect(); // public void actionPerformed(ActionEvent e) {
if (rect.x + rect.width < scrollPane.getViewport().getSize().width - SCROLL_STEP) { // Rectangle rect = scrollPane.getVisibleRect();
rect.translate(SCROLL_STEP, 0); // if (rect.x + rect.width < scrollPane.getViewport().getSize().width -
} else { // SCROLL_STEP) {
rect.translate(scrollPane.getViewport().getSize().width - rect.x - rect.width, // rect.translate(SCROLL_STEP, 0);
0); // } else {
} // rect.translate(scrollPane.getViewport().getSize().width - rect.x -
} // rect.width,
}); // 0);
rightButton.setMargin(new Insets(0, 2, 0, 2)); // }
panel.add(leftButton, BorderLayout.WEST); // }
panel.add(scrollPane); // });
panel.add(rightButton, BorderLayout.EAST); // rightButton.setMargin(new Insets(0, 2, 0, 2));
// panel.add(leftButton, BorderLayout.WEST);
// panel.add(scrollPane);
// panel.add(rightButton, BorderLayout.EAST);
return panel; return panel;
} }