1 23 package info.monitorenter.gui.chart.layout; 24 25 import info.monitorenter.gui.chart.Chart2D; 26 import info.monitorenter.gui.chart.IAxis; 27 import info.monitorenter.gui.chart.ITrace2D; 28 import info.monitorenter.gui.chart.ITracePainter; 29 import info.monitorenter.gui.chart.axis.AxisLinear; 30 import info.monitorenter.gui.chart.axis.AxisLog10; 31 import info.monitorenter.gui.chart.axis.AxisLogE; 32 import info.monitorenter.gui.chart.events.AxisActionSetGrid; 33 import info.monitorenter.gui.chart.events.AxisActionSetRange; 34 import info.monitorenter.gui.chart.events.AxisActionSetRangePolicy; 35 import info.monitorenter.gui.chart.events.Chart2DActionSetAxis; 36 import info.monitorenter.gui.chart.events.Chart2DActionSetCustomGridColorSingleton; 37 import info.monitorenter.gui.chart.events.Chart2DActionSetGridColor; 38 import info.monitorenter.gui.chart.events.JComponentActionSetBackground; 39 import info.monitorenter.gui.chart.events.JComponentActionSetCustomBackgroundSingleton; 40 import info.monitorenter.gui.chart.events.JComponentActionSetCustomForegroundSingleton; 41 import info.monitorenter.gui.chart.events.JComponentActionSetForeground; 42 import info.monitorenter.gui.chart.events.PopupListener; 43 import info.monitorenter.gui.chart.events.Trace2DActionAddRemoveTracePainter; 44 import info.monitorenter.gui.chart.events.Trace2DActionSetColor; 45 import info.monitorenter.gui.chart.events.Trace2DActionSetCustomColor; 46 import info.monitorenter.gui.chart.events.Trace2DActionSetName; 47 import info.monitorenter.gui.chart.events.Trace2DActionSetStroke; 48 import info.monitorenter.gui.chart.events.Trace2DActionSetVisible; 49 import info.monitorenter.gui.chart.events.Trace2DActionSetZindex; 50 import info.monitorenter.gui.chart.events.Trace2DActionZindexDecrease; 51 import info.monitorenter.gui.chart.events.Trace2DActionZindexIncrease; 52 import info.monitorenter.gui.chart.rangepolicies.RangePolicyFixedViewport; 53 import info.monitorenter.gui.chart.rangepolicies.RangePolicyForcedPoint; 54 import info.monitorenter.gui.chart.rangepolicies.RangePolicyHighestValues; 55 import info.monitorenter.gui.chart.rangepolicies.RangePolicyMinimumViewport; 56 import info.monitorenter.gui.chart.rangepolicies.RangePolicyUnbounded; 57 import info.monitorenter.gui.chart.traces.painters.TracePainterDisc; 58 import info.monitorenter.gui.chart.traces.painters.TracePainterFill; 59 import info.monitorenter.gui.chart.traces.painters.TracePainterPolyline; 60 import info.monitorenter.util.Range; 61 62 import java.awt.BasicStroke ; 63 import java.awt.Color ; 64 import java.awt.Component ; 65 import java.awt.Font ; 66 import java.awt.Stroke ; 67 import java.awt.event.ActionEvent ; 68 import java.beans.PropertyChangeEvent ; 69 import java.beans.PropertyChangeListener ; 70 import java.lang.ref.WeakReference ; 71 72 import javax.swing.AbstractAction ; 73 import javax.swing.AbstractButton ; 74 import javax.swing.Action ; 75 import javax.swing.ButtonGroup ; 76 import javax.swing.JCheckBoxMenuItem ; 77 import javax.swing.JComponent ; 78 import javax.swing.JLabel ; 79 import javax.swing.JMenu ; 80 import javax.swing.JMenuBar ; 81 import javax.swing.JMenuItem ; 82 import javax.swing.JPopupMenu ; 83 import javax.swing.JRadioButtonMenuItem ; 84 85 96 public final class LayoutFactory { 97 98 114 public static class BasicPropertyAdaptSupport implements PropertyChangeListener { 115 116 123 private Component m_adaptee; 124 125 126 protected WeakReference m_delegate; 127 128 135 public BasicPropertyAdaptSupport(final Component delegate, final Component adaptee) { 136 this.m_delegate = new WeakReference (delegate); 137 this.m_adaptee = adaptee; 138 delegate.setFont(adaptee.getFont()); 139 delegate.setBackground(adaptee.getBackground()); 140 delegate.setForeground(adaptee.getForeground()); 141 adaptee.addPropertyChangeListener(this); 142 } 143 144 154 public void finalize() throws Throwable { 155 super.finalize(); 156 this.m_adaptee.removePropertyChangeListener(this); 157 } 158 159 162 public void propertyChange(final PropertyChangeEvent evt) { 163 String prop = evt.getPropertyName(); 164 Object reference = this.m_delegate.get(); 165 if (reference != null) { 166 Component component = (Component ) reference; 167 if (prop.equals(Chart2D.PROPERTY_BACKGROUND_COLOR)) { 168 Color color = (Color) evt.getNewValue(); 169 Color foreground = component.getForeground(); 170 if (color.equals(foreground)) { 171 component.setForeground(component.getBackground()); 172 } 173 component.setBackground(color); 174 component.repaint(); 175 } else if (prop.equals(Chart2D.PROPERTY_FONT)) { 176 Font font = (Font ) evt.getNewValue(); 177 component.setFont(font); 178 } else if (prop.equals(Chart2D.PROPERTY_FOREGROUND_COLOR)) { 179 Color color = (Color) evt.getNewValue(); 180 Color background = component.getBackground(); 181 if (color.equals(background)) { 182 component.setBackground(component.getForeground()); 183 } 184 component.setForeground(color); 185 } 186 } else { 187 ((Component ) evt.getSource()).removePropertyChangeListener(this); 190 } 191 } 192 } 193 194 203 private static class OrderingCheckBoxMenuItem 204 extends LayoutFactory.PropertyChangeCheckBoxMenuItem { 205 206 217 private final class JMenuOrderingAction 218 extends AbstractAction { 219 220 223 private static final long serialVersionUID = 3835159462649672505L; 224 225 230 private Action m_action; 231 232 244 private JMenuOrderingAction(final Action delegate) { 245 this.m_action = delegate; 246 } 247 248 251 public void actionPerformed(final ActionEvent e) { 252 this.m_action.actionPerformed(e); 253 JCheckBoxMenuItem item = (JCheckBoxMenuItem ) e.getSource(); 255 boolean state = item.getState(); 256 if (state) { 257 LayoutFactory.OrderingCheckBoxMenuItem.this.m_menu 258 .remove(LayoutFactory.OrderingCheckBoxMenuItem.this); 259 LayoutFactory.OrderingCheckBoxMenuItem.this.m_menu.add( 260 LayoutFactory.OrderingCheckBoxMenuItem.this, 0); 261 } else { 262 LayoutFactory.OrderingCheckBoxMenuItem.this.m_menu 263 .remove(LayoutFactory.OrderingCheckBoxMenuItem.this); 264 LayoutFactory.OrderingCheckBoxMenuItem.this.m_menu 265 .add(LayoutFactory.OrderingCheckBoxMenuItem.this); 266 } 267 268 } 269 270 273 public void addPropertyChangeListener(final PropertyChangeListener listener) { 274 this.m_action.addPropertyChangeListener(listener); 275 } 276 277 280 public boolean equals(final Object obj) { 281 return this.m_action.equals(obj); 282 } 283 284 287 public Object getValue(final String key) { 288 return this.m_action.getValue(key); 289 } 290 291 294 public int hashCode() { 295 return this.m_action.hashCode(); 296 } 297 298 301 public boolean isEnabled() { 302 return this.m_action.isEnabled(); 303 } 304 305 309 public void putValue(final String key, final Object value) { 310 this.m_action.putValue(key, value); 311 } 312 313 316 public void removePropertyChangeListener(final PropertyChangeListener listener) { 317 this.m_action.removePropertyChangeListener(listener); 318 } 319 320 323 public void setEnabled(final boolean b) { 324 this.m_action.setEnabled(b); 325 } 326 327 330 public String toString() { 331 return this.m_action.toString(); 332 } 333 } 334 335 338 private static final long serialVersionUID = 3834870273894857017L; 339 340 341 private JMenu m_menu; 342 343 361 public OrderingCheckBoxMenuItem(final JComponent component, final Action action, 362 final JMenu container, final boolean checked) { 363 super(component, checked); 364 this.m_menu = container; 365 super.setAction(new JMenuOrderingAction(action)); 366 } 367 } 368 369 389 public static class PropertyChangeCheckBoxMenuItem 390 extends JCheckBoxMenuItem { 391 392 393 public static final String PROPERTY_SELECTED = ""; 394 395 398 private static final long serialVersionUID = 3690196534012752439L; 399 400 420 public PropertyChangeCheckBoxMenuItem(final JComponent component, final Action action, 421 final boolean checked) { 422 super(action); 423 this.setState(checked); 424 new BasicPropertyAdaptSupport(this, component); 425 if (action != null) { 426 action.addPropertyChangeListener(new SelectionPropertyAdaptSupport(this)); 427 } 428 } 429 430 443 protected PropertyChangeCheckBoxMenuItem(final JComponent component, final boolean checked) { 444 this(component, null, checked); 445 } 446 447 450 public void setAction(final Action a) { 451 if (a != null) { 452 super.setAction(a); 453 a.addPropertyChangeListener(new SelectionPropertyAdaptSupport(this)); 454 } 455 } 456 } 457 458 479 private static class PropertyChangeJRadioButtonMenuItem 480 extends JRadioButtonMenuItem { 481 482 491 protected PropertyChangeJRadioButtonMenuItem(final JComponent component) { 492 this(component, null); 493 } 494 495 511 public PropertyChangeJRadioButtonMenuItem(final JComponent component, final Action action) { 512 super(action); 513 new BasicPropertyAdaptSupport(this, component); 514 if (action != null) { 515 action.addPropertyChangeListener(new SelectionPropertyAdaptSupport(this)); 516 } 517 518 } 519 520 523 public void setAction(final Action a) { 524 if (a != null) { 525 super.setAction(a); 526 a.addPropertyChangeListener(new SelectionPropertyAdaptSupport(this)); 527 } 528 } 529 530 } 531 532 552 private static class SelectionAdaptJRadioButtonMenuItem 553 extends JRadioButtonMenuItem { 554 555 568 public SelectionAdaptJRadioButtonMenuItem(final Action action) { 569 super(action); 570 if (action != null) { 571 action.addPropertyChangeListener(new SelectionPropertyAdaptSupport(this)); 572 } 573 } 574 575 578 public void setAction(final Action a) { 579 if (a != null) { 580 super.setAction(a); 581 a.addPropertyChangeListener(new SelectionPropertyAdaptSupport(this)); 582 } 583 } 584 585 } 586 587 607 private static class SelectionAdaptJCheckBoxMenuItem 608 extends JCheckBoxMenuItem { 609 610 626 public SelectionAdaptJCheckBoxMenuItem(final Action action, final boolean state) { 627 super(action); 628 this.setSelected(state); 629 if (action != null) { 630 action.addPropertyChangeListener(new SelectionPropertyAdaptSupport(this)); 631 } 632 } 633 634 637 public void setAction(final Action a) { 638 if (a != null) { 639 super.setAction(a); 640 a.addPropertyChangeListener(new SelectionPropertyAdaptSupport(this)); 641 } 642 } 643 644 } 645 646 655 private static class PropertyChangeMenu 656 extends JMenu { 657 660 private static final long serialVersionUID = 3256437027795973685L; 661 662 673 public PropertyChangeMenu(final JComponent component, final String name) { 674 super(name); 675 new BasicPropertyAdaptSupport(this, component); 676 677 } 678 } 679 680 689 private static class PropertyChangeMenuItem 690 extends JMenuItem { 691 692 695 private static final long serialVersionUID = 3690196534012752439L; 696 697 708 public PropertyChangeMenuItem(final JComponent component, final Action action) { 709 super(action); 710 new BasicPropertyAdaptSupport(this, component); 711 } 712 } 713 714 723 724 private static class PropertyChangePopupMenu 725 extends JPopupMenu { 726 727 730 private static final long serialVersionUID = 3617013061525780016L; 731 732 736 public PropertyChangePopupMenu(final JComponent component) { 737 new BasicPropertyAdaptSupport(this, component); 738 } 739 } 740 741 750 751 private static class PropertyChangeJMenuBar 752 extends JMenuBar { 753 754 758 public PropertyChangeJMenuBar(final JComponent component) { 759 new BasicPropertyAdaptSupport(this, component); 760 } 761 } 762 763 779 public static class SelectionPropertyAdaptSupport implements PropertyChangeListener { 780 781 782 protected WeakReference m_delegate; 783 784 789 public SelectionPropertyAdaptSupport(final AbstractButton delegate) { 790 this.m_delegate = new WeakReference (delegate); 791 } 792 793 796 public void propertyChange(final PropertyChangeEvent evt) { 797 String prop = evt.getPropertyName(); 798 AbstractButton button = (AbstractButton ) this.m_delegate.get(); 799 if (button != null) { 800 if (prop.equals(LayoutFactory.PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED)) { 801 boolean state = ((Boolean ) evt.getNewValue()).booleanValue(); 802 button.setSelected(state); 803 } 804 } else { 805 ((Component ) evt.getSource()).removePropertyChangeListener(this); 806 } 807 } 808 809 } 810 811 821 final class TraceJLabel 822 extends JLabel implements PropertyChangeListener { 823 824 827 private static final long serialVersionUID = 3617290112636172342L; 828 829 836 public TraceJLabel(final String name) { 837 super(name); 838 } 839 840 843 public void propertyChange(final PropertyChangeEvent evt) { 844 String propertyName = evt.getPropertyName(); 845 if (propertyName.equals(ITrace2D.PROPERTY_COLOR)) { 846 Color color = (Color) evt.getNewValue(); 847 Color background = this.getBackground(); 848 if (color.equals(background)) { 849 this.setBackground(this.getForeground()); 850 } 851 this.setForeground(color); 852 } else if (propertyName.equals(Chart2D.PROPERTY_BACKGROUND_COLOR)) { 853 Color background = (Color) evt.getNewValue(); 854 Color foreground = this.getForeground(); 855 if (background.equals(foreground)) { 856 this.setForeground(this.getBackground()); 857 } 858 this.setBackground(background); 859 } else if (propertyName.equals(Chart2D.PROPERTY_FONT)) { 860 Font font = (Font ) evt.getNewValue(); 861 this.setFont(font); 862 } else if (propertyName.equals(ITrace2D.PROPERTY_NAME)) { 863 String name = (String ) evt.getNewValue(); 864 this.setText(name); 865 } 866 } 867 } 868 869 870 private static LayoutFactory instance; 871 872 878 public static LayoutFactory getInstance() { 879 if (LayoutFactory.instance == null) { 880 LayoutFactory.instance = new LayoutFactory(); 881 } 882 return LayoutFactory.instance; 883 } 884 885 888 private String [] m_strokeNames; 889 890 893 private Stroke[] m_strokes; 894 895 899 private LayoutFactory() { 900 super(); 901 this.m_strokes = new Stroke[6]; 902 this.m_strokeNames = new String [6]; 903 this.m_strokes[0] = new BasicStroke (); 904 this.m_strokeNames[0] = "basic"; 905 this.m_strokes[1] = new BasicStroke (2); 906 this.m_strokeNames[1] = "thick"; 907 this.m_strokes[2] = new BasicStroke (6, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10.0f, 908 new float[] {0, 10f }, 0f); 909 this.m_strokeNames[2] = "round caps"; 910 this.m_strokes[3] = new BasicStroke (1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.5f, 911 new float[] {5f, 5f }, 2.5f); 912 this.m_strokeNames[3] = "dashed"; 913 this.m_strokes[4] = new BasicStroke (6, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 10.0f, 914 new float[] {0, 10f }, 0f); 915 this.m_strokeNames[4] = "square caps"; 916 this.m_strokes[5] = new BasicStroke (3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.5f, 917 new float[] {2f, 2f }, 1f); 918 this.m_strokeNames[5] = "dashed thick"; 919 } 920 921 941 protected JMenuItem createAxisMenuItem(final IAxis axis, final int axisDimension, 942 final boolean adaptUI2Chart) { 943 final Chart2D chart = axis.getAccessor().getChart(); 944 JMenuItem item; 945 946 JMenuItem axisMenuItem; 948 if (adaptUI2Chart) { 949 axisMenuItem = new PropertyChangeMenu(chart, "Axis" + axis.getAccessor().toString()); 950 } else { 951 axisMenuItem = new JMenu ("Axis" + axis.getAccessor().toString()); 952 } 953 954 axisMenuItem.add(createAxisTypeMenu(chart, axis, axisDimension, adaptUI2Chart)); 955 956 axisMenuItem.add(createAxisRangePolicyMenu(chart, axis, adaptUI2Chart)); 957 958 if (adaptUI2Chart) { 960 item = new PropertyChangeMenuItem(chart, new AxisActionSetRange(axis, "Range")); 961 } else { 962 item = new JMenuItem (new AxisActionSetRange(axis, "Range")); 963 } 964 axisMenuItem.add(item); 965 966 if (adaptUI2Chart) { 968 item = new PropertyChangeCheckBoxMenuItem(chart, new AxisActionSetGrid(axis, "Grid"), axis 969 .isPaintGrid()); 970 } else { 971 item = new SelectionAdaptJCheckBoxMenuItem(new AxisActionSetGrid(axis, "Grid"), axis 972 .isPaintGrid()); 973 } 974 axisMenuItem.add(item); 975 return axisMenuItem; 976 } 977 978 995 public JMenu createAxisRangePolicyMenu(final Chart2D chart, final IAxis axis, 996 final boolean adaptUI2Chart) { 997 JMenuItem item; 998 JMenu axisRangePolicy; 1000 if (adaptUI2Chart) { 1001 axisRangePolicy = new PropertyChangeMenu(chart, "Range policy"); 1002 } else { 1003 axisRangePolicy = new JMenu ("Range policy"); 1004 } 1005 ButtonGroup buttonGroup = new ButtonGroup (); 1007 Class rangePolicyClass = axis.getRangePolicy().getClass(); 1009 if (adaptUI2Chart) { 1010 item = new PropertyChangeJRadioButtonMenuItem(chart, new AxisActionSetRangePolicy(axis, 1011 "Fixed viewport", new RangePolicyFixedViewport())); 1012 } else { 1013 item = new SelectionAdaptJRadioButtonMenuItem(new AxisActionSetRangePolicy(axis, 1014 "Fixed viewport", new RangePolicyFixedViewport())); 1015 } 1016 item 1017 .setToolTipText("Zooms or expands to the configured range without respect to the data to display. "); 1018 axisRangePolicy.add(item); 1019 buttonGroup.add(item); 1020 if (rangePolicyClass == RangePolicyFixedViewport.class) { 1021 buttonGroup.setSelected(item.getModel(), true); 1022 } 1023 1024 if (adaptUI2Chart) { 1025 item = new PropertyChangeJRadioButtonMenuItem(chart, new AxisActionSetRangePolicy(axis, 1026 "Minimum viewport", new RangePolicyUnbounded())); 1027 } else { 1028 item = new SelectionAdaptJRadioButtonMenuItem(new AxisActionSetRangePolicy(axis, 1029 "Minimum viewport", new RangePolicyUnbounded())); 1030 } 1031 axisRangePolicy.add(item); 1032 item.setToolTipText("Ensures all data is shown with minimal bounds."); 1033 buttonGroup.add(item); 1034 if (rangePolicyClass == RangePolicyUnbounded.class) { 1035 buttonGroup.setSelected(item.getModel(), true); 1036 } 1037 1038 if (adaptUI2Chart) { 1039 item = new PropertyChangeJRadioButtonMenuItem(chart, new AxisActionSetRangePolicy(axis, 1040 "Minimum viewport with range", new RangePolicyMinimumViewport(new Range(10, 10)))); 1041 } else { 1042 item = new SelectionAdaptJRadioButtonMenuItem(new AxisActionSetRangePolicy(axis, 1043 "Minimum viewport with range", new RangePolicyMinimumViewport(new Range(10, 10)))); 1044 } 1045 item.setToolTipText("Ensures that all data is shown and expands if range is higher. "); 1046 axisRangePolicy.add(item); 1047 buttonGroup.add(item); 1048 if (rangePolicyClass == RangePolicyMinimumViewport.class) { 1049 buttonGroup.setSelected(item.getModel(), true); 1050 } 1051 1052 if (adaptUI2Chart) { 1053 item = new PropertyChangeJRadioButtonMenuItem(chart, new AxisActionSetRangePolicy(axis, 1054 "Ensure visible point", new RangePolicyForcedPoint(0))); 1055 } else { 1056 item = new SelectionAdaptJRadioButtonMenuItem(new AxisActionSetRangePolicy(axis, 1057 "Ensure visible point", new RangePolicyForcedPoint(0))); 1058 } 1059 item.setToolTipText("Only the minimum value of the axis' range will be ensured to be visible."); 1060 axisRangePolicy.add(item); 1061 buttonGroup.add(item); 1062 if (rangePolicyClass == RangePolicyForcedPoint.class) { 1063 buttonGroup.setSelected(item.getModel(), true); 1064 } 1065 1066 if (adaptUI2Chart) { 1067 item = new PropertyChangeJRadioButtonMenuItem(chart, new AxisActionSetRangePolicy(axis, 1068 "Highest points within max-50 to max.", new RangePolicyHighestValues(50))); 1069 } else { 1070 item = new SelectionAdaptJRadioButtonMenuItem(new AxisActionSetRangePolicy(axis, 1071 "Highest points within max-50 to max.", new RangePolicyHighestValues(50))); 1072 } 1073 item.setToolTipText("Shows the highest values from max-50 to max."); 1074 axisRangePolicy.add(item); 1075 buttonGroup.add(item); 1076 if (rangePolicyClass == RangePolicyHighestValues.class) { 1077 buttonGroup.setSelected(item.getModel(), true); 1078 } 1079 return axisRangePolicy; 1080 } 1081 1082 1103 public JMenu createAxisTypeMenu(final Chart2D chart, final IAxis axis, final int axisDimension, 1104 final boolean adaptUI2Chart) { 1105 JMenu axisType; 1107 if (adaptUI2Chart) { 1108 axisType = new PropertyChangeMenu(chart, "Type"); 1109 } else { 1110 axisType = new JMenu ("Type"); 1111 } 1112 ButtonGroup buttonGroup = new ButtonGroup (); 1114 Class typeClass = axis.getClass(); 1116 JMenuItem item; 1117 1118 if (adaptUI2Chart) { 1119 item = new PropertyChangeJRadioButtonMenuItem(chart, new Chart2DActionSetAxis(chart, 1120 new AxisLinear(), "Linear", axisDimension)); 1121 } else { 1122 item = new SelectionAdaptJRadioButtonMenuItem(new Chart2DActionSetAxis(chart, 1123 new AxisLinear(), "Linear", axisDimension)); 1124 } 1125 axisType.add(item); 1126 buttonGroup.add(item); 1127 if (typeClass == AxisLinear.class) { 1128 buttonGroup.setSelected(item.getModel(), true); 1129 } 1130 if (adaptUI2Chart) { 1131 item = new PropertyChangeJRadioButtonMenuItem(chart, new Chart2DActionSetAxis(chart, 1132 new AxisLogE(), "Log E", axisDimension)); 1133 } else { 1134 item = new SelectionAdaptJRadioButtonMenuItem(new Chart2DActionSetAxis(chart, new AxisLogE(), 1135 "Log E", axisDimension)); 1136 } 1137 axisType.add(item); 1138 buttonGroup.add(item); 1139 if (typeClass == AxisLogE.class) { 1140 buttonGroup.setSelected(item.getModel(), true); 1141 } 1142 if (adaptUI2Chart) { 1143 item = new PropertyChangeJRadioButtonMenuItem(chart, new Chart2DActionSetAxis(chart, 1144 new AxisLog10(), "Log 10", axisDimension)); 1145 } else { 1146 item = new SelectionAdaptJRadioButtonMenuItem(new Chart2DActionSetAxis(chart, 1147 new AxisLog10(), "Log 10", axisDimension)); 1148 } 1149 axisType.add(item); 1150 buttonGroup.add(item); 1151 if (typeClass == AxisLog10.class) { 1152 buttonGroup.setSelected(item.getModel(), true); 1153 } 1154 1155 return axisType; 1156 } 1157 1158 1171 public JMenu createBackgroundColorMenu(final Chart2D chart, final boolean adaptUI2Chart) { 1172 Color backgroundColor = chart.getBackground(); 1173 boolean nonStandardColor = true; 1174 1175 JMenuItem item; 1177 JMenu bgColorMenu; 1178 if (adaptUI2Chart) { 1179 bgColorMenu = new PropertyChangeMenu(chart, "Background color"); 1180 } else { 1181 bgColorMenu = new JMenu ("Background color"); 1182 } 1183 1184 ButtonGroup buttonGroup = new ButtonGroup (); 1185 if (adaptUI2Chart) { 1186 item = new PropertyChangeJRadioButtonMenuItem(chart, new JComponentActionSetBackground(chart, 1187 "White", Color.WHITE)); 1188 } else { 1189 item = new SelectionAdaptJRadioButtonMenuItem(new JComponentActionSetBackground(chart, 1190 "White", Color.WHITE)); 1191 } 1192 if (backgroundColor.equals(Color.WHITE)) { 1193 item.setSelected(true); 1194 nonStandardColor = false; 1195 } 1196 buttonGroup.add(item); 1197 bgColorMenu.add(item); 1198 if (adaptUI2Chart) { 1199 item = new PropertyChangeJRadioButtonMenuItem(chart, new JComponentActionSetBackground(chart, 1200 "Gray", Color.GRAY)); 1201 } else { 1202 item = new SelectionAdaptJRadioButtonMenuItem(new JComponentActionSetBackground(chart, 1203 "Gray", Color.GRAY)); 1204 } 1205 if (backgroundColor.equals(Color.GRAY)) { 1206 item.setSelected(true); 1207 nonStandardColor = false; 1208 } 1209 buttonGroup.add(item); 1210 bgColorMenu.add(item); 1211 if (adaptUI2Chart) { 1212 item = new PropertyChangeJRadioButtonMenuItem(chart, new JComponentActionSetBackground(chart, 1213 "Light gray", Color.LIGHT_GRAY)); 1214 } else { 1215 item = new SelectionAdaptJRadioButtonMenuItem(new JComponentActionSetBackground(chart, 1216 "Light gray", Color.LIGHT_GRAY)); 1217 } 1218 if (backgroundColor.equals(Color.LIGHT_GRAY)) { 1219 item.setSelected(true); 1220 nonStandardColor = false; 1221 } 1222 buttonGroup.add(item); 1223 bgColorMenu.add(item); 1224 if (adaptUI2Chart) { 1225 item = new PropertyChangeJRadioButtonMenuItem(chart, new JComponentActionSetBackground(chart, 1226 "Black", Color.BLACK)); 1227 } else { 1228 item = new SelectionAdaptJRadioButtonMenuItem(new JComponentActionSetBackground(chart, 1229 "Black", Color.BLACK)); 1230 } 1231 if (backgroundColor.equals(Color.BLACK)) { 1232 item.setSelected(true); 1233 nonStandardColor = false; 1234 } 1235 buttonGroup.add(item); 1236 bgColorMenu.add(item); 1237 if (adaptUI2Chart) { 1238 item = new PropertyChangeJRadioButtonMenuItem(chart, 1239 JComponentActionSetCustomBackgroundSingleton.getInstance(chart, "Custom Color")); 1240 } else { 1241 item = new SelectionAdaptJRadioButtonMenuItem(JComponentActionSetCustomBackgroundSingleton 1242 .getInstance(chart, "Custom Color")); 1243 } 1244 item.setSelected(nonStandardColor); 1245 buttonGroup.add(item); 1246 bgColorMenu.add(item); 1247 return bgColorMenu; 1248 } 1249 1250 1263 public JMenuItem createForegroundColorMenu(final Chart2D chart, final boolean adaptUI2Chart) { 1264 1265 Color foregroundColor = chart.getForeground(); 1266 boolean nonStandardColor = true; 1267 ButtonGroup buttonGroup = new ButtonGroup (); 1268 1269 JMenuItem item; 1270 JMenu fgColorMenu; 1271 if (adaptUI2Chart) { 1272 fgColorMenu = new PropertyChangeMenu(chart, "Foreground color"); 1273 } else { 1274 fgColorMenu = new JMenu ("Foreground color"); 1275 } 1276 if (adaptUI2Chart) { 1277 item = new PropertyChangeJRadioButtonMenuItem(chart, new JComponentActionSetForeground(chart, 1278 "White", Color.WHITE)); 1279 } else { 1280 item = new SelectionAdaptJRadioButtonMenuItem(new JComponentActionSetForeground(chart, 1281 "White", Color.WHITE)); 1282 } 1283 if (foregroundColor.equals(Color.WHITE)) { 1284 item.setSelected(true); 1285 nonStandardColor = false; 1286 } 1287 buttonGroup.add(item); 1288 fgColorMenu.add(item); 1289 if (adaptUI2Chart) { 1290 item = new PropertyChangeJRadioButtonMenuItem(chart, new JComponentActionSetForeground(chart, 1291 "Gray", Color.GRAY)); 1292 } else { 1293 item = new SelectionAdaptJRadioButtonMenuItem(new JComponentActionSetForeground(chart, 1294 "Gray", Color.GRAY)); 1295 } 1296 if (foregroundColor.equals(Color.GRAY)) { 1297 item.setSelected(true); 1298 nonStandardColor = false; 1299 } 1300 buttonGroup.add(item); 1301 fgColorMenu.add(item); 1302 if (adaptUI2Chart) { 1303 item = new PropertyChangeJRadioButtonMenuItem(chart, new JComponentActionSetForeground(chart, 1304 "Light gray", Color.LIGHT_GRAY)); 1305 } else { 1306 item = new SelectionAdaptJRadioButtonMenuItem(new JComponentActionSetForeground(chart, 1307 "Light gray", Color.LIGHT_GRAY)); 1308 } 1309 if (foregroundColor.equals(Color.LIGHT_GRAY)) { 1310 item.setSelected(true); 1311 nonStandardColor = false; 1312 } 1313 buttonGroup.add(item); 1314 fgColorMenu.add(item); 1315 if (adaptUI2Chart) { 1316 item = new PropertyChangeJRadioButtonMenuItem(chart, new JComponentActionSetForeground(chart, 1317 "Black", Color.BLACK)); 1318 } else { 1319 item = new SelectionAdaptJRadioButtonMenuItem(new JComponentActionSetForeground(chart, 1320 "Black", Color.BLACK)); 1321 } 1322 if (foregroundColor.equals(Color.BLACK)) { 1323 item.setSelected(true); 1324 nonStandardColor = false; 1325 } 1326 buttonGroup.add(item); 1327 fgColorMenu.add(item); 1328 if (adaptUI2Chart) { 1329 item = new PropertyChangeJRadioButtonMenuItem(chart, 1330 JComponentActionSetCustomForegroundSingleton.getInstance(chart, "Custom Color")); 1331 } else { 1332 item = new SelectionAdaptJRadioButtonMenuItem(JComponentActionSetCustomForegroundSingleton 1333 .getInstance(chart, "Custom Color")); 1334 } 1335 item.setSelected(nonStandardColor); 1336 buttonGroup.add(item); 1337 fgColorMenu.add(item); 1338 return fgColorMenu; 1339 } 1340 1341 1354 public JMenu createGridColorMenu(final Chart2D chart, final boolean adaptUI2Chart) { 1355 JMenuItem item; 1356 Color gridColor = chart.getGridColor(); 1357 boolean nonStandardColor = true; 1358 ButtonGroup buttonGroup = new ButtonGroup (); 1359 1360 JMenu gridColorMenu; 1361 if (adaptUI2Chart) { 1362 gridColorMenu = new PropertyChangeMenu(chart, "Grid color"); 1363 } else { 1364 gridColorMenu = new JMenu ("Grid color"); 1365 } 1366 1367 if (adaptUI2Chart) { 1368 item = new PropertyChangeJRadioButtonMenuItem(chart, new Chart2DActionSetGridColor(chart, 1369 "Gray", Color.GRAY)); 1370 } else { 1371 item = new SelectionAdaptJRadioButtonMenuItem(new Chart2DActionSetGridColor(chart, "Gray", 1372 Color.GRAY)); 1373 } 1374 if (gridColor.equals(Color.GRAY)) { 1375 item.setSelected(true); 1376 nonStandardColor = false; 1377 } 1378 buttonGroup.add(item); 1379 gridColorMenu.add(item); 1380 if (adaptUI2Chart) { 1381 item = new PropertyChangeJRadioButtonMenuItem(chart, new Chart2DActionSetGridColor(chart, 1382 "Light gray", Color.LIGHT_GRAY)); 1383 } else { 1384 item = new SelectionAdaptJRadioButtonMenuItem(new Chart2DActionSetGridColor(chart, 1385 "Light gray", Color.LIGHT_GRAY)); 1386 } 1387 if (gridColor.equals(Color.LIGHT_GRAY)) { 1388 item.setSelected(true); 1389 nonStandardColor = false; 1390 } 1391 1392 buttonGroup.add(item); 1393 gridColorMenu.add(item); 1394 if (adaptUI2Chart) { 1395 item = new PropertyChangeJRadioButtonMenuItem(chart, new Chart2DActionSetGridColor(chart, 1396 "Black", Color.BLACK)); 1397 } else { 1398 item = new SelectionAdaptJRadioButtonMenuItem(new Chart2DActionSetGridColor(chart, "Black", 1399 Color.BLACK)); 1400 } 1401 if (gridColor.equals(Color.BLACK)) { 1402 item.setSelected(true); 1403 nonStandardColor = false; 1404 } 1405 buttonGroup.add(item); 1406 gridColorMenu.add(item); 1407 if (adaptUI2Chart) { 1408 item = new PropertyChangeJRadioButtonMenuItem(chart, new Chart2DActionSetGridColor(chart, 1409 "White", Color.WHITE)); 1410 } else { 1411 item = new SelectionAdaptJRadioButtonMenuItem(new Chart2DActionSetGridColor(chart, "White", 1412 Color.WHITE)); 1413 } 1414 if (gridColor.equals(Color.WHITE)) { 1415 item.setSelected(true); 1416 nonStandardColor = false; 1417 } 1418 buttonGroup.add(item); 1419 gridColorMenu.add(item); 1420 if (adaptUI2Chart) { 1421 item = new PropertyChangeJRadioButtonMenuItem(chart, Chart2DActionSetCustomGridColorSingleton 1422 .getInstance(chart, "Custom")); 1423 } else { 1424 item = new SelectionAdaptJRadioButtonMenuItem(Chart2DActionSetCustomGridColorSingleton 1425 .getInstance(chart, "Custom")); 1426 } 1427 item.setSelected(nonStandardColor); 1428 buttonGroup.add(item); 1429 gridColorMenu.add(item); 1430 return gridColorMenu; 1431 } 1432 1433 1444 public void createPopupMenu(final Chart2D chart, final boolean adaptUI2Chart) { 1445 1446 1448 JMenu axisMenu; 1450 if (adaptUI2Chart) { 1451 axisMenu = new PropertyChangeMenu(chart, "Axis"); 1452 } else { 1453 axisMenu = new JMenu ("Axis"); 1454 } 1455 1457 JMenuItem xAxisMenuItem = this.createAxisMenuItem(chart.getAxisX(), Chart2D.X, adaptUI2Chart); 1459 axisMenu.add(xAxisMenuItem); 1460 JMenuItem yAxisMenuItem = this.createAxisMenuItem(chart.getAxisY(), Chart2D.Y, adaptUI2Chart); 1462 axisMenu.add(yAxisMenuItem); 1463 1464 JPopupMenu popup; 1466 if (adaptUI2Chart) { 1467 popup = new PropertyChangePopupMenu(chart); 1468 } else { 1469 popup = new JPopupMenu (); 1470 } 1471 popup.add(createBackgroundColorMenu(chart, adaptUI2Chart)); 1472 popup.add(createForegroundColorMenu(chart, adaptUI2Chart)); 1473 popup.add(createGridColorMenu(chart, adaptUI2Chart)); 1474 popup.add(axisMenu); 1475 chart.addMouseListener(new PopupListener(popup)); 1476 } 1477 1478 1489 public JMenuBar createMenuBar(final Chart2D chart, final boolean adaptUI2Chart) { 1490 1491 JMenu chartMenu = createMenu(chart, adaptUI2Chart); 1492 JMenuBar menubar; 1493 if (adaptUI2Chart) { 1494 menubar = new PropertyChangeJMenuBar(chart); 1495 } else { 1496 menubar = new JMenuBar (); 1497 } 1498 menubar.add(chartMenu); 1499 return menubar; 1500 } 1501 1502 1513 public JMenu createMenu(final Chart2D chart, final boolean adaptUI2Chart) { 1514 1515 JMenu chartMenu; 1516 if (adaptUI2Chart) { 1517 chartMenu = new PropertyChangeMenu(chart, "Chart"); 1518 } else { 1519 chartMenu = new JMenu ("Chart"); 1520 } 1521 1522 JMenu axisMenu; 1524 if (adaptUI2Chart) { 1525 axisMenu = new PropertyChangeMenu(chart, "Axis"); 1526 } else { 1527 axisMenu = new JMenu ("Axis"); 1528 } 1529 1531 JMenuItem xAxisMenuItem = this.createAxisMenuItem(chart.getAxisX(), Chart2D.X, adaptUI2Chart); 1533 axisMenu.add(xAxisMenuItem); 1534 JMenuItem yAxisMenuItem = this.createAxisMenuItem(chart.getAxisY(), Chart2D.Y, adaptUI2Chart); 1536 axisMenu.add(yAxisMenuItem); 1537 1538 chartMenu.add(createBackgroundColorMenu(chart, adaptUI2Chart)); 1540 chartMenu.add(createForegroundColorMenu(chart, adaptUI2Chart)); 1541 chartMenu.add(createGridColorMenu(chart, adaptUI2Chart)); 1542 chartMenu.add(axisMenu); 1543 1544 return chartMenu; 1545 } 1546 1547 1566 public JLabel createContextMenuLable(final Chart2D chart, final ITrace2D trace) { 1567 TraceJLabel ret = new TraceJLabel(trace.getLable()); 1568 1569 JPopupMenu popup = new PropertyChangePopupMenu(chart); 1571 Color background = chart.getBackground(); 1573 ret.setBackground(background); 1574 ret.setForeground(trace.getColor()); 1575 1576 JMenu colorMenu = new PropertyChangeMenu(chart, "Color"); 1578 JMenuItem item = new PropertyChangeMenuItem(chart, new Trace2DActionSetColor(trace, "Red", 1579 Color.RED)); 1580 colorMenu.add(item); 1581 item = new PropertyChangeMenuItem(chart, new Trace2DActionSetColor(trace, "Green", Color.GREEN)); 1582 colorMenu.add(item); 1583 item = new PropertyChangeMenuItem(chart, new Trace2DActionSetColor(trace, "Blue", Color.BLUE)); 1584 colorMenu.add(item); 1585 item = new PropertyChangeMenuItem(chart, new Trace2DActionSetColor(trace, "Gray", Color.GRAY)); 1586 colorMenu.add(item); 1587 item = new PropertyChangeMenuItem(chart, new Trace2DActionSetColor(trace, "Magenta", 1588 Color.MAGENTA)); 1589 colorMenu.add(item); 1590 item = new PropertyChangeMenuItem(chart, new Trace2DActionSetColor(trace, "Pink", Color.PINK)); 1591 colorMenu.add(item); 1592 item = new PropertyChangeMenuItem(chart, new Trace2DActionSetColor(trace, "Black", Color.BLACK)); 1593 colorMenu.add(item); 1594 item = new PropertyChangeMenuItem(chart, new Trace2DActionSetCustomColor(trace, "Custom", ret)); 1595 colorMenu.add(item); 1596 1597 JMenu zIndexMenu = new PropertyChangeMenu(chart, "layer"); 1599 zIndexMenu.setBackground(background); 1600 item = new PropertyChangeMenuItem(chart, new Trace2DActionSetZindex(trace, "bring to front", 0)); 1601 zIndexMenu.add(item); 1602 item = new PropertyChangeMenuItem(chart, new Trace2DActionSetZindex(trace, "send to back", 1603 ITrace2D.ZINDEX_MAX)); 1604 zIndexMenu.add(item); 1605 item = new PropertyChangeMenuItem(chart, new Trace2DActionZindexDecrease(trace, "forward", 2)); 1606 zIndexMenu.add(item); 1607 item = new PropertyChangeMenuItem(chart, new Trace2DActionZindexIncrease(trace, "backwards", 2)); 1608 zIndexMenu.add(item); 1609 1610 item = new PropertyChangeCheckBoxMenuItem(chart, new Trace2DActionSetVisible(trace, "Visible"), 1612 trace.isVisible()); 1613 popup.add(item); 1614 1615 item = new PropertyChangeMenuItem(chart, new Trace2DActionSetName(trace, "Name", chart)); 1617 popup.add(item); 1618 1619 JMenu strokesMenu = new PropertyChangeMenu(chart, "Stroke"); 1621 for (int i = 0; i < this.m_strokes.length; i++) { 1622 item = new PropertyChangeMenuItem(chart, new Trace2DActionSetStroke(trace, 1623 this.m_strokeNames[i], this.m_strokes[i])); 1624 strokesMenu.add(item); 1625 } 1626 1627 JMenu painterMenu = new PropertyChangeMenu(chart, "renderer"); 1629 ITracePainter painter = new TracePainterDisc(4); 1630 item = new OrderingCheckBoxMenuItem(chart, new Trace2DActionAddRemoveTracePainter(trace, 1631 "discs", painter), painterMenu, trace.containsTracePainter(painter)); 1632 if (trace.getTracePainters().contains(painter)) { 1633 item.setSelected(true); 1634 } 1635 painterMenu.add(item); 1636 1637 painter = new TracePainterPolyline(); 1638 item = new OrderingCheckBoxMenuItem(chart, new Trace2DActionAddRemoveTracePainter(trace, 1639 "line", painter), painterMenu, trace.containsTracePainter(painter)); 1640 painterMenu.add(item); 1641 if (trace.getTracePainters().contains(painter)) { 1642 item.setSelected(true); 1643 } 1644 1645 painter = new TracePainterFill(chart); 1646 item = new OrderingCheckBoxMenuItem(chart, new Trace2DActionAddRemoveTracePainter(trace, 1647 "fill", painter), painterMenu, trace.containsTracePainter(painter)); 1648 painterMenu.add(item); 1649 if (trace.getTracePainters().contains(painter)) { 1650 item.setSelected(true); 1651 } 1652 1653 popup.add(colorMenu); 1655 popup.add(zIndexMenu); 1656 popup.add(strokesMenu); 1657 popup.add(painterMenu); 1658 1659 ret.addMouseListener(new PopupListener(popup)); 1660 new BasicPropertyAdaptSupport(ret, chart); 1661 return ret; 1662 } 1663} 1664 | Popular Tags |