001: package com.vividsolutions.jump.workbench.ui.style;
002:
003: //[sstein 01.10.2005] changed to be able to work with real scale values
004:
005: import java.awt.Color;
006: import java.awt.GridBagConstraints;
007: import java.awt.GridBagLayout;
008: import java.awt.Insets;
009: import java.text.DecimalFormat;
010:
011: import javax.swing.ImageIcon;
012: import javax.swing.JCheckBox;
013: import javax.swing.JDialog;
014: import javax.swing.JLabel;
015: import javax.swing.JPanel;
016: import javax.swing.JTextField;
017: import javax.swing.SwingConstants;
018: import javax.swing.UIManager;
019: import javax.swing.UnsupportedLookAndFeelException;
020:
021: import com.vividsolutions.jump.I18N;
022: import com.vividsolutions.jump.util.MathUtil;
023: import com.vividsolutions.jump.workbench.model.Layer;
024: import com.vividsolutions.jump.workbench.ui.GUIUtil;
025: import com.vividsolutions.jump.workbench.ui.LayerViewPanel;
026: import com.vividsolutions.jump.workbench.ui.ValidatingTextField;
027: import com.vividsolutions.jump.workbench.ui.images.IconLoader;
028:
029: import javax.swing.JButton;
030:
031: import org.openjump.core.ui.util.ScreenScale;
032:
033: public class ScaleStylePanel extends JPanel implements StylePanel {
034:
035: private static final ImageIcon MAX_SCALE_ICON = IconLoader
036: .icon("Atom.gif");
037:
038: private static final ImageIcon MIN_SCALE_ICON = GUIUtil.resize(
039: IconLoader.icon("World2.gif"), 32);
040:
041: private JCheckBox enableScaleDependentRenderingCheckBox = null;
042:
043: private JLabel smallestScaleLabel = null;
044:
045: private JLabel largestScaleLabel = null;
046:
047: private JLabel smallestScale1Label = null;
048:
049: private JLabel largestScale1Label = null;
050:
051: private JLabel currentScale1Label = null;
052:
053: private ValidatingTextField smallestScaleTextField = null;
054:
055: private ValidatingTextField largestScaleTextField = null;
056:
057: private ValidatingTextField currentScaleTextField = null;
058:
059: private Layer layer;
060:
061: private LayerViewPanel panel;
062:
063: private JLabel currentScaleLabel = null;
064:
065: private JPanel fillerPanel = null;
066:
067: private JPanel spacerPanelInTopLeftCorner = null;
068:
069: private JLabel unitsPerPixelLabel = null;
070:
071: private JButton hideAboveCurrentScaleButton = null;
072:
073: private JButton hideBelowCurrentScaleButton = null;
074:
075: private static final Color TEXT_FIELD_BACKGROUND_COLOUR = new JTextField()
076: .getBackground();
077:
078: private JLabel smallestScaleIconLabel = null;
079:
080: private JLabel largestScaleIconLabel = null;
081:
082: private JPanel spacerPanelBelowCurrentScale = null;
083:
084: private JButton showAtThisScaleButton = null;
085:
086: private double scaleFactor = 0;
087:
088: private JPanel getFillerPanel() {
089: if (fillerPanel == null) {
090: fillerPanel = new JPanel();
091: }
092: return fillerPanel;
093: }
094:
095: public ScaleStylePanel(Layer layer, LayerViewPanel panel) {
096: super ();
097: initialize();
098: this .layer = layer;
099: this .panel = panel;
100:
101: /**
102: * [sstein : 01.10.2005]
103: * modifications to show the real scale and not the internal values
104: */
105: double internalScale = this .currentScale();
106: double realScale = ScreenScale.getHorizontalMapScale(panel
107: .getViewport());
108: this .scaleFactor = internalScale / realScale;
109:
110: Double internalMinScale = layer.getMinScale();
111: Double realMinScale = null;
112: if (internalMinScale != null) {
113: //-- not sure to use Math.floor (with respect to zoom into cm space
114: // but somehow necessary to avoid display like 6379.9999999 [sstein]
115: realMinScale = new Double(Math.floor(internalMinScale
116: .doubleValue()
117: / this .scaleFactor));
118: }
119:
120: Double internalMaxScale = layer.getMaxScale();
121: Double realMaxScale = null;
122: if (internalMaxScale != null) {
123: realMaxScale = new Double(Math.floor(internalMaxScale
124: .doubleValue()
125: / this .scaleFactor));
126: }
127: smallestScaleTextField
128: .setText(formatScaleLosslessly(realMinScale));
129: largestScaleTextField
130: .setText(formatScaleLosslessly(realMaxScale));
131: currentScaleTextField.setText(formatScaleLossily(realScale));
132: enableScaleDependentRenderingCheckBox.setSelected(layer
133: .isScaleDependentRenderingEnabled());
134: updateComponents();
135: }
136:
137: protected double currentScale() {
138: return 1d / panel.getViewport().getScale();
139: }
140:
141: private String formatScaleLosslessly(Double scale) {
142: return scale != null ? formatScaleLosslessly(scale
143: .doubleValue()) : "";
144: }
145:
146: private String formatScaleLosslessly(double scale) {
147: // Unlike #formatCurrentScale, this method is lossless [Jon Aquino
148: // 2005-03-31]
149: return scale == (int) scale ? "" + (int) scale : "" + scale;
150: }
151:
152: private void initialize() {
153: GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
154: GridBagConstraints gridBagConstraints18 = new GridBagConstraints();
155: smallestScaleIconLabel = new JLabel();
156: largestScaleIconLabel = new JLabel();
157: unitsPerPixelLabel = new JLabel();
158: GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
159: GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
160: GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
161: GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
162: largestScaleLabel = new JLabel();
163: smallestScaleLabel = new JLabel();
164: largestScale1Label = new JLabel();
165: currentScale1Label = new JLabel();
166: smallestScale1Label = new JLabel();
167: currentScaleLabel = new JLabel();
168: GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
169: GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
170: GridBagConstraints gridBagConstraints17 = new GridBagConstraints();
171: GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
172: GridBagConstraints gridBagConstraints31 = new GridBagConstraints();
173: GridBagConstraints gridBagConstraints13 = new GridBagConstraints();
174: GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
175: GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
176: GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
177: GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
178: GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
179: GridBagConstraints gridBagConstraints16 = new GridBagConstraints();
180: GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
181: this .setLayout(new GridBagLayout());
182: gridBagConstraints1.gridx = 1;
183: gridBagConstraints1.gridy = 4;
184: smallestScaleLabel.setText(I18N
185: .get("ui.style.ScaleStylePanel.smallest-scale"));
186: smallestScaleLabel.setToolTipText(I18N
187: .get("ui.style.ScaleStylePanel.larger-units-pixel"));
188: smallestScaleIconLabel.setIcon(MIN_SCALE_ICON);
189: largestScaleIconLabel.setIcon(MAX_SCALE_ICON);
190: gridBagConstraints5.gridx = 3;
191: gridBagConstraints5.gridy = 6;
192: smallestScale1Label.setText("1:");
193: currentScaleLabel.setText(I18N
194: .get("ui.style.ScaleStylePanel.current-scale"));
195: gridBagConstraints6.gridx = 3;
196: gridBagConstraints6.gridy = 8;
197: gridBagConstraints16.gridx = 3;
198: gridBagConstraints16.gridy = 2;
199: largestScale1Label.setText("1:");
200: currentScale1Label.setText("1:");
201: gridBagConstraints7.gridx = 4;
202: gridBagConstraints7.gridy = 6;
203: gridBagConstraints7.fill = java.awt.GridBagConstraints.HORIZONTAL;
204: gridBagConstraints7.insets = new java.awt.Insets(0, 2, 0, 0);
205: gridBagConstraints17.gridx = 4;
206: gridBagConstraints17.gridy = 2;
207: gridBagConstraints17.fill = java.awt.GridBagConstraints.HORIZONTAL;
208: gridBagConstraints17.insets = new java.awt.Insets(0, 2, 0, 0);
209: gridBagConstraints9.gridx = 4;
210: gridBagConstraints9.gridy = 8;
211: gridBagConstraints9.fill = java.awt.GridBagConstraints.HORIZONTAL;
212: gridBagConstraints9.insets = new java.awt.Insets(0, 2, 0, 0);
213: gridBagConstraints1.gridwidth = 5;
214: gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
215: gridBagConstraints3.anchor = java.awt.GridBagConstraints.WEST;
216: gridBagConstraints3.insets = new java.awt.Insets(5, 5, 5, 0);
217: gridBagConstraints4.anchor = java.awt.GridBagConstraints.WEST;
218: gridBagConstraints4.insets = new java.awt.Insets(5, 5, 5, 0);
219: gridBagConstraints5.insets = new java.awt.Insets(0, 10, 0, 0);
220: gridBagConstraints6.insets = new java.awt.Insets(0, 10, 0, 0);
221: gridBagConstraints16.insets = new java.awt.Insets(0, 10, 0, 0);
222: gridBagConstraints16.anchor = java.awt.GridBagConstraints.WEST;
223: gridBagConstraints10.gridx = 2;
224: gridBagConstraints10.gridy = 2;
225: gridBagConstraints10.anchor = java.awt.GridBagConstraints.WEST;
226: gridBagConstraints10.insets = new java.awt.Insets(0, 5, 0, 0);
227: gridBagConstraints10.gridwidth = 1;
228: gridBagConstraints3.gridx = 2;
229: gridBagConstraints3.gridy = 6;
230: gridBagConstraints4.gridx = 2;
231: gridBagConstraints4.gridy = 8;
232: gridBagConstraints11.gridx = 7;
233: gridBagConstraints11.gridy = 16;
234: gridBagConstraints11.fill = java.awt.GridBagConstraints.BOTH;
235: gridBagConstraints11.weightx = 1.0D;
236: gridBagConstraints11.weighty = 1.0D;
237: gridBagConstraints12.gridx = 0;
238: gridBagConstraints12.gridy = 0;
239: gridBagConstraints12.insets = new java.awt.Insets(2, 2, 2, 2);
240: gridBagConstraints13.gridx = 4;
241: gridBagConstraints13.gridy = 5;
242: unitsPerPixelLabel.setText(I18N
243: .get("ui.style.ScaleStylePanel.units-pixel"));
244: gridBagConstraints14.gridx = 7;
245: gridBagConstraints14.gridy = 6;
246: gridBagConstraints14.insets = new java.awt.Insets(4, 4, 4, 4);
247: gridBagConstraints14.fill = java.awt.GridBagConstraints.HORIZONTAL;
248: gridBagConstraints15.gridx = 7;
249: gridBagConstraints15.gridy = 8;
250: gridBagConstraints15.insets = new java.awt.Insets(4, 4, 4, 4);
251: gridBagConstraints15.fill = java.awt.GridBagConstraints.HORIZONTAL;
252: getShowAtThisScaleButton().setMargin(new Insets(0, 0, 0, 0));
253: getHideAboveCurrentScaleButton().setMargin(
254: new Insets(0, 0, 0, 0));
255: getHideBelowCurrentScaleButton().setMargin(
256: new Insets(0, 0, 0, 0));
257: getShowAtThisScaleButton().setMargin(new Insets(0, 0, 0, 0));
258: GUIUtil.shrinkFont(getHideAboveCurrentScaleButton());
259: GUIUtil.shrinkFont(getHideBelowCurrentScaleButton());
260: GUIUtil.shrinkFont(getShowAtThisScaleButton());
261: GUIUtil.shrinkFont(unitsPerPixelLabel);
262: largestScaleLabel.setText(I18N
263: .get("ui.style.ScaleStylePanel.largest-scale"));
264: largestScaleLabel.setToolTipText(I18N
265: .get("ui.style.ScaleStylePanel.smaller-units-pixel"));
266: gridBagConstraints2.gridx = 1;
267: gridBagConstraints2.gridy = 6;
268: gridBagConstraints31.gridx = 1;
269: gridBagConstraints31.gridy = 8;
270: gridBagConstraints2.insets = new java.awt.Insets(5, 40, 5, 0);
271: gridBagConstraints31.insets = new java.awt.Insets(5, 40, 5, 0);
272: gridBagConstraints18.gridx = 2;
273: gridBagConstraints18.gridy = 3;
274: gridBagConstraints21.gridx = 7;
275: gridBagConstraints21.gridy = 2;
276: gridBagConstraints21.fill = java.awt.GridBagConstraints.HORIZONTAL;
277: gridBagConstraints21.insets = new java.awt.Insets(4, 4, 4, 4);
278: this .add(getSpacerPanelInTopLeftCorner(), gridBagConstraints12);
279: this .add(getShowAtThisScaleButton(), gridBagConstraints21);
280: this .add(getEnableScaleDependentRenderingCheckBox(),
281: gridBagConstraints1);
282: this .add(currentScaleLabel, gridBagConstraints10);
283: this .add(smallestScaleLabel, gridBagConstraints3);
284: this .add(largestScaleLabel, gridBagConstraints4);
285: this .add(getFillerPanel(), gridBagConstraints11);
286: this .add(smallestScale1Label, gridBagConstraints5);
287: this .add(largestScale1Label, gridBagConstraints6);
288: this .add(unitsPerPixelLabel, gridBagConstraints13);
289: this
290: .add(getHideAboveCurrentScaleButton(),
291: gridBagConstraints14);
292: this
293: .add(getHideBelowCurrentScaleButton(),
294: gridBagConstraints15);
295: this .add(currentScale1Label, gridBagConstraints16);
296: this .add(smallestScaleIconLabel, gridBagConstraints2);
297: this .add(largestScaleIconLabel, gridBagConstraints31);
298: this .add(getSpacerPanelBelowCurrentScale(),
299: gridBagConstraints18);
300: this .add(getSmallestScaleTextField(), gridBagConstraints7);
301: this .add(getLargestScaleTextField(), gridBagConstraints9);
302: this .add(getCurrentScaleTextField(), gridBagConstraints17);
303: }
304:
305: public String getTitle() {
306: return I18N.get("ui.style.ScaleStylePanel.scale");
307: }
308:
309: public void updateStyles() {
310: layer.getLayerManager().deferFiringEvents(new Runnable() {
311: public void run() {
312: layer.setMinScale(getSmallestScale());
313: layer.setMaxScale(getLargestScale());
314: layer
315: .setScaleDependentRenderingEnabled(enableScaleDependentRenderingCheckBox
316: .isSelected());
317: }
318: });
319: layer.fireAppearanceChanged();
320: }
321:
322: public String validateInput() {
323: if (getSmallestScale() != null
324: && getLargestScale() != null
325: && getLargestScale().doubleValue() > getSmallestScale()
326: .doubleValue()) {
327: return I18N
328: .get("ui.style.ScaleStylePanel.units-pixel-at-smallest-scale-must-be-larger-than-units-pixel-at-largest-scale");
329: }
330: if (getLargestScale() != null
331: && getLargestScale().doubleValue() == 0) {
332: return I18N
333: .get("ui.style.ScaleStylePanel.units-pixel-at-largest-scale-must-be-greater-than-0");
334: }
335: if (getSmallestScale() != null
336: && getSmallestScale().doubleValue() == 0) {
337: return I18N
338: .get("ui.style.ScaleStylePanel.units-pixel-at-smallest-scale-must-be-greater-than-0");
339: }
340: return null;
341: }
342:
343: private Double getLargestScale() {
344: //[sstein 01.10.2005]
345: // change to be able to work with real scale values
346: return largestScaleTextField.getText().trim().length() > 0 ? new Double(
347: largestScaleTextField.getDouble() * this .scaleFactor)
348: : null;
349: }
350:
351: private Double getSmallestScale() {
352: //[sstein 01.10.2005]
353: // change to be able to work with real scale values
354: return smallestScaleTextField.getText().trim().length() > 0 ? new Double(
355: smallestScaleTextField.getDouble() * this .scaleFactor)
356: : null;
357: }
358:
359: private JCheckBox getEnableScaleDependentRenderingCheckBox() {
360: if (enableScaleDependentRenderingCheckBox == null) {
361: enableScaleDependentRenderingCheckBox = new JCheckBox();
362: enableScaleDependentRenderingCheckBox
363: .setText(I18N
364: .get("ui.style.ScaleStylePanel.only-show-layer-when-scale-is-between"));
365: enableScaleDependentRenderingCheckBox
366: .addActionListener(new java.awt.event.ActionListener() {
367: public void actionPerformed(
368: java.awt.event.ActionEvent e) {
369: updateComponents();
370: }
371: });
372: }
373: return enableScaleDependentRenderingCheckBox;
374: }
375:
376: private void updateComponents() {
377: smallestScaleTextField
378: .setBackground(enableScaleDependentRenderingCheckBox
379: .isSelected() ? TEXT_FIELD_BACKGROUND_COLOUR
380: : getBackground());
381: largestScaleTextField
382: .setBackground(enableScaleDependentRenderingCheckBox
383: .isSelected() ? TEXT_FIELD_BACKGROUND_COLOUR
384: : getBackground());
385: unitsPerPixelLabel
386: .setEnabled(enableScaleDependentRenderingCheckBox
387: .isSelected());
388: hideAboveCurrentScaleButton
389: .setEnabled(enableScaleDependentRenderingCheckBox
390: .isSelected());
391: smallestScaleLabel
392: .setEnabled(enableScaleDependentRenderingCheckBox
393: .isSelected());
394: smallestScale1Label
395: .setEnabled(enableScaleDependentRenderingCheckBox
396: .isSelected());
397: smallestScaleTextField
398: .setEnabled(enableScaleDependentRenderingCheckBox
399: .isSelected());
400: hideBelowCurrentScaleButton
401: .setEnabled(enableScaleDependentRenderingCheckBox
402: .isSelected());
403: largestScaleLabel
404: .setEnabled(enableScaleDependentRenderingCheckBox
405: .isSelected());
406: largestScale1Label
407: .setEnabled(enableScaleDependentRenderingCheckBox
408: .isSelected());
409: largestScaleTextField
410: .setEnabled(enableScaleDependentRenderingCheckBox
411: .isSelected());
412: }
413:
414: private ValidatingTextField getSmallestScaleTextField() {
415: if (smallestScaleTextField == null) {
416: smallestScaleTextField = createValidatingTextField();
417: }
418: return smallestScaleTextField;
419: }
420:
421: private ValidatingTextField getLargestScaleTextField() {
422: if (largestScaleTextField == null) {
423: largestScaleTextField = createValidatingTextField();
424: }
425: return largestScaleTextField;
426: }
427:
428: private ValidatingTextField getCurrentScaleTextField() {
429: if (currentScaleTextField == null) {
430: currentScaleTextField = createValidatingTextField();
431: currentScaleTextField.setEditable(false);
432: currentScaleTextField.setBackground(getBackground());
433: }
434: return currentScaleTextField;
435: }
436:
437: private ValidatingTextField createValidatingTextField() {
438: // Use GreaterThanOrEqualValidator rather than GreaterThanValidator,
439: // which won't let the user type a "0" even if they want to enter "0.1"
440: // [Jon Aquino 2005-03-22]
441: return new ValidatingTextField(
442: "",
443: 7,
444: SwingConstants.LEFT,
445: new ValidatingTextField.CompositeValidator(
446: new ValidatingTextField.Validator[] {
447: ValidatingTextField.DOUBLE_VALIDATOR,
448: new ValidatingTextField.GreaterThanOrEqualValidator(
449: 0) }),
450: ValidatingTextField.DUMMY_CLEANER);
451: }
452:
453: /**
454: * Nicer formatting, but the expense of possibly losing precision.
455: */
456: private String formatScaleLossily(double x) {
457: if (1 <= x && x <= 1E6) {
458: return new DecimalFormat("#").format(x);
459: }
460: if (1E-6 <= x && x <= 1) {
461: return new DecimalFormat("0.000000").format(x);
462: }
463: return new DecimalFormat("0.#E0").format(x);
464: }
465:
466: /**
467: * This method initializes spacerPanel
468: *
469: * @return javax.swing.JPanel
470: */
471: private JPanel getSpacerPanelInTopLeftCorner() {
472: if (spacerPanelInTopLeftCorner == null) {
473: spacerPanelInTopLeftCorner = new JPanel();
474: spacerPanelInTopLeftCorner.setLayout(new GridBagLayout());
475: }
476: return spacerPanelInTopLeftCorner;
477: }
478:
479: private JButton getHideAboveCurrentScaleButton() {
480: if (hideAboveCurrentScaleButton == null) {
481: hideAboveCurrentScaleButton = new JButton();
482: hideAboveCurrentScaleButton
483: .setText(I18N
484: .get("ui.style.ScaleStylePanel.hide-above-current-scale"));
485: hideAboveCurrentScaleButton
486: .addActionListener(new java.awt.event.ActionListener() {
487: public void actionPerformed(
488: java.awt.event.ActionEvent e) {
489: //[sstein] changed to show real scale instead currentScale
490: double realScale = 1 / scaleFactor
491: * currentScale();
492: smallestScaleTextField
493: .setText(formatScaleLossily(roundFirstSignificantFigureUp(realScale)));
494: }
495: });
496: }
497: return hideAboveCurrentScaleButton;
498: }
499:
500: /**
501: * Round the first significant figure up
502: */
503: private double roundFirstSignificantFigureUp(double x) {
504: return roundFirstSignificantFigure(x, 1);
505: }
506:
507: /**
508: * Round the first significant figure down
509: */
510: private double roundFirstSignificantFigureDown(double x) {
511: return roundFirstSignificantFigure(x, 0);
512: }
513:
514: private static double roundFirstSignificantFigure(double x, int i) {
515: double scale = Math.pow(10, Math.floor(MathUtil.base10Log(x)));
516: int firstSignificantFigure = (int) Math.floor(x / scale);
517: return (firstSignificantFigure + i) * scale;
518: }
519:
520: private JButton getHideBelowCurrentScaleButton() {
521: if (hideBelowCurrentScaleButton == null) {
522: hideBelowCurrentScaleButton = new JButton();
523: hideBelowCurrentScaleButton
524: .setText(I18N
525: .get("ui.style.ScaleStylePanel.hide-below-current-scale"));
526: hideBelowCurrentScaleButton
527: .addActionListener(new java.awt.event.ActionListener() {
528: public void actionPerformed(
529: java.awt.event.ActionEvent e) {
530: //[sstein] changed to show real scale instead currentScale
531: double realScale = 1 / scaleFactor
532: * currentScale();
533: largestScaleTextField
534: .setText(formatScaleLossily(roundFirstSignificantFigureDown(realScale)));
535: }
536: });
537: }
538: return hideBelowCurrentScaleButton;
539: }
540:
541: /**
542: * This method initializes jPanel
543: *
544: * @return javax.swing.JPanel
545: */
546: private JPanel getSpacerPanelBelowCurrentScale() {
547: if (spacerPanelBelowCurrentScale == null) {
548: spacerPanelBelowCurrentScale = new JPanel();
549: spacerPanelBelowCurrentScale.setLayout(new GridBagLayout());
550: spacerPanelBelowCurrentScale
551: .setPreferredSize(new java.awt.Dimension(0, 20));
552: }
553: return spacerPanelBelowCurrentScale;
554: }
555:
556: /**
557: * This method initializes showAtThisScaleButton
558: *
559: * @return javax.swing.JButton
560: */
561: private JButton getShowAtThisScaleButton() {
562: if (showAtThisScaleButton == null) {
563: showAtThisScaleButton = new JButton();
564: showAtThisScaleButton
565: .setText(I18N
566: .get("ui.style.ScaleStylePanel.show-at-this-scale"));
567: showAtThisScaleButton
568: .addActionListener(new java.awt.event.ActionListener() {
569: public void actionPerformed(
570: java.awt.event.ActionEvent e) {
571: if (!enableScaleDependentRenderingCheckBox
572: .isSelected()) {
573: enableScaleDependentRenderingCheckBox
574: .doClick();
575: }
576: if (getSmallestScale() != null
577: && currentScale() > getSmallestScale()
578: .doubleValue()) {
579: getHideAboveCurrentScaleButton()
580: .doClick();
581: }
582: if (getLargestScale() != null
583: && currentScale() < getLargestScale()
584: .doubleValue()) {
585: getHideBelowCurrentScaleButton()
586: .doClick();
587: }
588: }
589: });
590: }
591: return showAtThisScaleButton;
592: }
593:
594: public static void main(String[] args)
595: throws ClassNotFoundException, InstantiationException,
596: IllegalAccessException, UnsupportedLookAndFeelException {
597: /*
598: * System.out.println(roundFirstSignificantFigure(123, 1));
599: * System.out.println(roundFirstSignificantFigure(123, 0));
600: * System.out.println(roundFirstSignificantFigure(789, 1));
601: * System.out.println(roundFirstSignificantFigure(789, 0));
602: * System.out.println(roundFirstSignificantFigure(.00123, 1));
603: * System.out.println(roundFirstSignificantFigure(.00123, 0));
604: * System.out.println(roundFirstSignificantFigure(.00789, 1));
605: * System.out.println(roundFirstSignificantFigure(.00789, 0));
606: */
607: /*
608: * System.out.println(new DecimalFormat("0.#E0").format(0.00000123));
609: * System.exit(0);
610: */
611: UIManager.setLookAndFeel(UIManager
612: .getSystemLookAndFeelClassName());
613: JDialog dialog = new JDialog();
614: dialog.getContentPane().add(new ScaleStylePanel(new Layer() {
615: {
616: setMinScale(new Double(2));
617: setMaxScale(new Double(1));
618: }
619: }, null) {
620: protected double currentScale() {
621: return .000000123;
622: }
623: });
624: dialog.pack();
625: dialog.setVisible(true);
626: }
627: } // @jve:decl-index=0:visual-constraint="10,10"
|