Package javax.swing.event

Examples of javax.swing.event.ChangeListener


          UserPreferencesPanel.class, "newWallThicknessLabel.text"));
      final SpinnerLengthModel newWallThicknessSpinnerModel = new SpinnerLengthModel(
          0.5f, 0.125f, 5f, 0.005f, controller);
      this.newWallThicknessSpinner = new AutoCommitSpinner(newWallThicknessSpinnerModel);
      newWallThicknessSpinnerModel.setLength(controller.getNewWallThickness());
      newWallThicknessSpinnerModel.addChangeListener(new ChangeListener() {
          public void stateChanged(ChangeEvent ev) {
            controller.setNewWallThickness(newWallThicknessSpinnerModel.getLength());
          }
        });
      controller.addPropertyChangeListener(UserPreferencesController.Property.NEW_WALL_THICKNESS,
          new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent ev) {
              newWallThicknessSpinnerModel.setLength(controller.getNewWallThickness());
            }
          });
    }
   
    if (controller.isPropertyEditable(UserPreferencesController.Property.NEW_WALL_HEIGHT)) {
      // Create wall height label and spinner bound to controller NEW_WALL_HEIGHT property
      this.newWallHeightLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
          UserPreferencesPanel.class, "newWallHeightLabel.text"));
      final SpinnerLengthModel newWallHeightSpinnerModel = new SpinnerLengthModel(
          10f, 2f, 100f, 0.1f, controller);
      this.newWallHeightSpinner = new AutoCommitSpinner(newWallHeightSpinnerModel);
      newWallHeightSpinnerModel.setLength(controller.getNewWallHeight());
      newWallHeightSpinnerModel.addChangeListener(new ChangeListener() {
          public void stateChanged(ChangeEvent ev) {
            controller.setNewWallHeight(newWallHeightSpinnerModel.getLength());
          }
        });
      controller.addPropertyChangeListener(UserPreferencesController.Property.NEW_WALL_HEIGHT,
          new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent ev) {
              newWallHeightSpinnerModel.setLength(controller.getNewWallHeight());
            }
          });
    }
   
    if (controller.isPropertyEditable(UserPreferencesController.Property.AUTO_SAVE_DELAY_FOR_RECOVERY)) {
      this.autoSaveDelayForRecoveryCheckBox = new JCheckBox(SwingTools.getLocalizedLabelText(preferences,
          UserPreferencesPanel.class, "autoSaveDelayForRecoveryCheckBox.text"));
      final SpinnerNumberModel autoSaveDelayForRecoverySpinnerModel = new SpinnerNumberModel(10, 1, 60, 5) {
          @Override
          public Object getNextValue() {
            if (((Number)getValue()).intValue() == ((Number)getMinimum()).intValue()) {
              return getStepSize();
            } else {
              return super.getNextValue();
            }
          }
         
          @Override
          public Object getPreviousValue() {
            if (((Number)getValue()).intValue() - ((Number)getStepSize()).intValue() < ((Number)getMinimum()).intValue()) {
              return super.getMinimum();
            } else {
              return super.getPreviousValue();
            }
          }
        };
      this.autoSaveDelayForRecoverySpinner = new AutoCommitSpinner(autoSaveDelayForRecoverySpinnerModel);
      this.autoSaveDelayForRecoveryUnitLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
          UserPreferencesPanel.class, "autoSaveDelayForRecoveryUnitLabel.text"));
      updateAutoSaveDelayForRecoveryComponents(controller);
      this.autoSaveDelayForRecoveryCheckBox.addChangeListener(new ChangeListener() {
          public void stateChanged(ChangeEvent ev) {
            controller.setAutoSaveForRecoveryEnabled(autoSaveDelayForRecoveryCheckBox.isSelected());
          }
        });
      autoSaveDelayForRecoverySpinnerModel.addChangeListener(new ChangeListener() {
          public void stateChanged(ChangeEvent ev) {
            controller.setAutoSaveDelayForRecovery(((Number)autoSaveDelayForRecoverySpinnerModel.getValue()).intValue() * 60000);
          }
        });
      PropertyChangeListener listener = new PropertyChangeListener() {
View Full Code Here


    this.progressLabel.setFont(toolTipFont);
    this.progressLabel.setHorizontalAlignment(JLabel.CENTER);
   
    this.progressBar = new JProgressBar();
    this.progressBar.setIndeterminate(true);
    this.progressBar.getModel().addChangeListener(new ChangeListener() {
        private long timeAfterFirstImage;
       
        public void stateChanged(ChangeEvent ev) {
          int progressValue = progressBar.getValue();
          progressBar.setIndeterminate(progressValue <= progressBar.getMinimum() + 1);
          if (progressValue == progressBar.getMinimum()
              || progressValue == progressBar.getMaximum()) {
            progressLabel.setText("");
            if (progressValue == progressBar.getMinimum()) {
              int framesCount = progressBar.getMaximum() - progressBar.getMinimum();
              String progressLabelFormat = preferences.getLocalizedString(VideoPanel.class, "progressStartLabel.format");
              progressLabel.setText(String.format(progressLabelFormat, framesCount,
                  formatDuration(framesCount * 1000 / controller.getFrameRate())));
            }
          } else if (progressValue == progressBar.getMinimum() + 1) {
            this.timeAfterFirstImage = System.currentTimeMillis();
          } else {
            // Update progress label once the second image is generated
            // (the first one can take more time because of initialization process)
            String progressLabelFormat = preferences.getLocalizedString(VideoPanel.class, "progressLabel.format");
            long estimatedRemainingTime = (System.currentTimeMillis() - this.timeAfterFirstImage)
                / (progressValue - 1 - progressBar.getMinimum()) 
                * (progressBar.getMaximum() - progressValue - 1);
            String estimatedRemainingTimeText = formatDuration(estimatedRemainingTime);
            progressLabel.setText(String.format(progressLabelFormat,
                progressValue, progressBar.getMaximum(), estimatedRemainingTimeText));
          }         
        }

        /**
         * Returns a localized string of <code>duration</code> in millis.
         */
        private String formatDuration(long duration) {
          long durationInSeconds = duration / 1000;
          if (duration - durationInSeconds * 1000 >= 500) {
            durationInSeconds++;
          }
          String estimatedRemainingTimeText;
          if (durationInSeconds < 60) {
            estimatedRemainingTimeText = String.format(preferences.getLocalizedString(
                VideoPanel.class, "seconds.format"), durationInSeconds);
          } else if (durationInSeconds < 3600) {
            estimatedRemainingTimeText = String.format(preferences.getLocalizedString(
                VideoPanel.class, "minutesSeconds.format"), durationInSeconds / 60, durationInSeconds % 60);
          } else {
            long hours = durationInSeconds / 3600;
            long minutes = (durationInSeconds % 3600) / 60;
            estimatedRemainingTimeText = String.format(preferences.getLocalizedString(
                VideoPanel.class, "hoursMinutes.format"), hours, minutes);
          }
          return estimatedRemainingTimeText;
        }
      });
   
    // Create video format label and combo box bound to WIDTH, HEIGHT, ASPECT_RATIO and FRAME_RATE controller properties
    this.videoFormatLabel = new JLabel();
    this.videoFormatComboBox = new JComboBox(VIDEO_FORMATS);
    this.videoFormatComboBox.setMaximumRowCount(VIDEO_FORMATS.length);
    this.videoFormatComboBox.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value,
                                                      int index, boolean isSelected, boolean cellHasFocus) {
          VideoFormat videoFormat = (VideoFormat)value;
          String aspectRatio;
          switch (getAspectRatio(videoFormat)) {
            case RATIO_4_3 :
              aspectRatio = "4/3";
              break;
            case RATIO_16_9 :
            default :
              aspectRatio = "16/9";
              break;
          }
          Dimension videoSize = videoFormat.getSize();
          String displayedValue = String.format(videoFormatComboBoxFormat, videoSize.width, videoSize.height,
              aspectRatio, (int)videoFormat.getFrameRate());         
          return super.getListCellRendererComponent(list, displayedValue, index, isSelected,
              cellHasFocus);
        }
      });
    this.videoFormatComboBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
          controller.setWidth(((VideoFormat)videoFormatComboBox.getSelectedItem()).getSize().width);
          controller.setAspectRatio(getAspectRatio((VideoFormat)videoFormatComboBox.getSelectedItem()));
          controller.setFrameRate((int)((VideoFormat)videoFormatComboBox.getSelectedItem()).getFrameRate());
        }
      });
    PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          videoFormatComboBox.setSelectedItem(controller.getAspectRatio());
        }
      };
    controller.addPropertyChangeListener(VideoController.Property.WIDTH, propertyChangeListener);
    controller.addPropertyChangeListener(VideoController.Property.HEIGHT, propertyChangeListener);
    controller.addPropertyChangeListener(VideoController.Property.ASPECT_RATIO, propertyChangeListener);
    controller.addPropertyChangeListener(VideoController.Property.FRAME_RATE, propertyChangeListener);

    // Quality label and slider bound to QUALITY controller property
    this.qualityLabel = new JLabel();
    this.qualitySlider = new JSlider(1, controller.getQualityLevelCount()) {
        @Override
        public String getToolTipText(MouseEvent ev) {
          float valueUnderMouse = getSliderValueAt(this, ev.getX(), preferences);
          float valueToTick = valueUnderMouse - (float)Math.floor(valueUnderMouse);
          if (valueToTick < 0.25f || valueToTick > 0.75f) {
            // Display a tooltip that explains the different quality levels
            return "<html><table><tr valign='middle'>"
                + "<td><img border='1' src='"
                + new ResourceURLContent(PhotoPanel.class, "resources/quality" + Math.round(valueUnderMouse - qualitySlider.getMinimum()) + ".jpg").getURL() + "'></td>"
                + "<td>" + preferences.getLocalizedString(VideoPanel.class, "quality" + Math.round(valueUnderMouse - qualitySlider.getMinimum()) + "DescriptionLabel.text") + "</td>"
                + "</tr></table>";
          } else {
            return null;
          }
        }
      };
    // Add a listener that displays also the tool tip when user clicks on the slider
    this.qualitySlider.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(final MouseEvent ev) {
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                float valueUnderMouse = getSliderValueAt(qualitySlider, ev.getX(), preferences);
                if (qualitySlider.getValue() == Math.round(valueUnderMouse)) {
                  ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
                  int initialDelay = toolTipManager.getInitialDelay();
                  toolTipManager.setInitialDelay(Math.min(initialDelay, 150));
                  toolTipManager.mouseMoved(ev);
                  toolTipManager.setInitialDelay(initialDelay);
                }
              }
            });
        }
      });
    this.qualitySlider.setPaintLabels(true);
    this.qualitySlider.setPaintTicks(true);   
    this.qualitySlider.setMajorTickSpacing(1);
    this.qualitySlider.setSnapToTicks(true);
    final boolean offScreenImageSupported = Component3DManager.getInstance().isOffScreenImageSupported();
    this.qualitySlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          if (!offScreenImageSupported) {
            // Can't support 2 first quality levels if offscreen image isn't supported
            qualitySlider.setValue(Math.max(qualitySlider.getMinimum() + 2, qualitySlider.getValue()));
          }
          controller.setQuality(qualitySlider.getValue() - qualitySlider.getMinimum());
        }
      });
    controller.addPropertyChangeListener(VideoController.Property.QUALITY,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            qualitySlider.setValue(qualitySlider.getMinimum() + controller.getQuality());
            updateAdvancedComponents();
          }
        });
    this.qualitySlider.setValue(this.qualitySlider.getMinimum() + controller.getQuality());
   
    this.advancedComponentsSeparator = new JSeparator();

    // Create date and time labels and spinners bound to TIME controller property
    Date time = new Date(Camera.convertTimeToTimeZone(controller.getTime(), TimeZone.getDefault().getID()));
    this.dateLabel = new JLabel();
    final SpinnerDateModel dateSpinnerModel = new SpinnerDateModel();
    dateSpinnerModel.setValue(time);
    this.dateSpinner = new JSpinner(dateSpinnerModel);
    String datePattern = ((SimpleDateFormat)DateFormat.getDateInstance(DateFormat.SHORT)).toPattern();
    if (datePattern.indexOf("yyyy") == -1) {
      datePattern = datePattern.replace("yy", "yyyy");
    }
    JSpinner.DateEditor dateEditor = new JSpinner.DateEditor(this.dateSpinner, datePattern);
    this.dateSpinner.setEditor(dateEditor);
    SwingTools.addAutoSelectionOnFocusGain(dateEditor.getTextField());
   
    this.timeLabel = new JLabel();
    final SpinnerDateModel timeSpinnerModel = new SpinnerDateModel();
    timeSpinnerModel.setValue(time);
    this.timeSpinner = new JSpinner(timeSpinnerModel);
    // From http://en.wikipedia.org/wiki/12-hour_clock#Use_by_country
    String [] twelveHoursCountries = {
        "AU"// Australia
        "BD"// Bangladesh
        "CA"// Canada (excluding Quebec, in French)
        "CO"// Colombia
        "EG"// Egypt
        "HN"// Honduras
        "JO"// Jordan
        "MX"// Mexico
        "MY"// Malaysia
        "NI"// Nicaragua
        "NZ"// New Zealand
        "PH"// Philippines
        "PK"// Pakistan
        "SA"// Saudi Arabia
        "SV"// El Salvador
        "US"// United States
        "VE"}; // Venezuela        
    SimpleDateFormat timeInstance;
    if ("en".equals(Locale.getDefault().getLanguage())) {
      if (Arrays.binarySearch(twelveHoursCountries, Locale.getDefault().getCountry()) >= 0) {
        timeInstance = (SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US); // 12 hours notation
      } else {
        timeInstance = (SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.SHORT, Locale.UK); // 24 hours notation
      }
    } else {
      timeInstance = (SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.SHORT);
    }
    JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(this.timeSpinner, timeInstance.toPattern());
    this.timeSpinner.setEditor(timeEditor);
    SwingTools.addAutoSelectionOnFocusGain(timeEditor.getTextField());

    final PropertyChangeListener timeChangeListener = new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent ev) {
        Date date = new Date(Camera.convertTimeToTimeZone(controller.getTime(), TimeZone.getDefault().getID()));
        dateSpinnerModel.setValue(date);
        timeSpinnerModel.setValue(date);
      }
    };
    controller.addPropertyChangeListener(VideoController.Property.TIME, timeChangeListener);
    final ChangeListener dateTimeChangeListener = new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(VideoController.Property.TIME, timeChangeListener);
          // Merge date and time
          GregorianCalendar dateCalendar = new GregorianCalendar();
          dateCalendar.setTime((Date)dateSpinnerModel.getValue());
View Full Code Here

    // Create width label and spinner bound to WIDTH controller property
    this.widthLabel = new JLabel();
    final SpinnerNumberModel widthSpinnerModel = new SpinnerNumberModel(480, 10, 10000, 10);
    this.widthSpinner = new AutoCommitSpinner(widthSpinnerModel);
    widthSpinnerModel.setValue(controller.getWidth());
    widthSpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.setWidth(((Number)widthSpinnerModel.getValue()).intValue());
        }
      });
    controller.addPropertyChangeListener(PhotoController.Property.WIDTH,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            widthSpinnerModel.setValue(controller.getWidth());
          }
        });

   
    // Create height label and spinner bound to HEIGHT controller property
    this.heightLabel = new JLabel();
    final SpinnerNumberModel heightSpinnerModel = new SpinnerNumberModel(480, 10, 10000, 10);
    this.heightSpinner = new AutoCommitSpinner(heightSpinnerModel);
    heightSpinnerModel.setValue(controller.getHeight());
    heightSpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.setHeight(((Number)heightSpinnerModel.getValue()).intValue());
        }
      });
    controller.addPropertyChangeListener(PhotoController.Property.HEIGHT,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            heightSpinnerModel.setValue(controller.getHeight());
          }
        });

    // Create apply proportions check box bound to ASPECT_RATIO controller property
    boolean notFreeAspectRatio = controller.getAspectRatio() != AspectRatio.FREE_RATIO;
    this.applyProportionsCheckBox = new JCheckBox();
    this.applyProportionsCheckBox.setSelected(notFreeAspectRatio);
    this.applyProportionsCheckBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
          controller.setAspectRatio(applyProportionsCheckBox.isSelected()
              ? (AspectRatio)aspectRatioComboBox.getSelectedItem()
              : AspectRatio.FREE_RATIO);
        }
      });
    this.aspectRatioComboBox = new JComboBox(new Object [] {
        AspectRatio.VIEW_3D_RATIO,
        AspectRatio.SQUARE_RATIO,
        AspectRatio.RATIO_4_3,
        AspectRatio.RATIO_3_2,
        AspectRatio.RATIO_16_9,
        AspectRatio.RATIO_2_1});
    this.aspectRatioComboBox.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value,
                                                      int index, boolean isSelected, boolean cellHasFocus) {
          AspectRatio aspectRatio = (AspectRatio)value;
          String displayedValue = "";
          if (aspectRatio != AspectRatio.FREE_RATIO) {
            switch (aspectRatio) {
              case VIEW_3D_RATIO :
                displayedValue = preferences.getLocalizedString(
                    PhotoPanel.class, "aspectRatioComboBox.view3DRatio.text");
                break;
              case SQUARE_RATIO :
                displayedValue = preferences.getLocalizedString(
                    PhotoPanel.class, "aspectRatioComboBox.squareRatio.text");
                break;
              case RATIO_4_3 :
                displayedValue = "4/3";
                break;
              case RATIO_3_2 :
                displayedValue = "3/2";
                break;
              case RATIO_16_9 :
                displayedValue = "16/9";
                break;
              case RATIO_2_1 :
                displayedValue = "2/1";
                break;
            }
          }
          return super.getListCellRendererComponent(list, displayedValue, index, isSelected,
              cellHasFocus);
        }
      });
    this.aspectRatioComboBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
          controller.setAspectRatio((AspectRatio)aspectRatioComboBox.getSelectedItem());
        }
      });
    this.aspectRatioComboBox.setEnabled(notFreeAspectRatio);
    this.aspectRatioComboBox.setSelectedItem(controller.getAspectRatio());
    controller.addPropertyChangeListener(PhotoController.Property.ASPECT_RATIO,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            boolean notFreeAspectRatio = controller.getAspectRatio() != AspectRatio.FREE_RATIO;
            applyProportionsCheckBox.setSelected(notFreeAspectRatio);
            aspectRatioComboBox.setEnabled(notFreeAspectRatio);
            aspectRatioComboBox.setSelectedItem(controller.getAspectRatio());
          }
        });

    // Quality label and slider bound to QUALITY controller property
    this.qualityLabel = new JLabel();
    this.qualitySlider = new JSlider(1, controller.getQualityLevelCount()) {
        @Override
        public String getToolTipText(MouseEvent ev) {
          float valueUnderMouse = getSliderValueAt(this, ev.getX(), preferences);
          float valueToTick = valueUnderMouse - (float)Math.floor(valueUnderMouse);
          if (valueToTick < 0.25f || valueToTick > 0.75f) {
            // Display a tooltip that explains the different quality levels
            return "<html><table><tr valign='middle'>"
                + "<td><img border='1' src='"
                + new ResourceURLContent(PhotoPanel.class, "resources/quality" + Math.round(valueUnderMouse - qualitySlider.getMinimum()) + ".jpg").getURL() + "'></td>"
                + "<td>" + preferences.getLocalizedString(PhotoPanel.class, "quality" + Math.round(valueUnderMouse - qualitySlider.getMinimum()) + "DescriptionLabel.text") + "</td>"
                + "</tr></table>";
          } else {
            return null;
          }
        }
      };
    // Add a listener that displays also the tool tip when user clicks on the slider
    this.qualitySlider.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(final MouseEvent ev) {
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                float valueUnderMouse = getSliderValueAt(qualitySlider, ev.getX(), preferences);
                if (qualitySlider.getValue() == Math.round(valueUnderMouse)) {
                  ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
                  int initialDelay = toolTipManager.getInitialDelay();
                  toolTipManager.setInitialDelay(Math.min(initialDelay, 150));
                  toolTipManager.mouseMoved(ev);
                  toolTipManager.setInitialDelay(initialDelay);
                }
              }
            });
        }
      });
    this.qualitySlider.setPaintLabels(true);
    this.qualitySlider.setPaintTicks(true);   
    this.qualitySlider.setMajorTickSpacing(1);
    this.qualitySlider.setSnapToTicks(true);
    final boolean offScreenImageSupported = Component3DManager.getInstance().isOffScreenImageSupported();
    this.qualitySlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          if (!offScreenImageSupported) {
            // Can't support 2 first quality levels if offscreen image isn't supported
            qualitySlider.setValue(Math.max(qualitySlider.getMinimum() + 2, qualitySlider.getValue()));
          }
          controller.setQuality(qualitySlider.getValue() - qualitySlider.getMinimum());
        }
      });
    controller.addPropertyChangeListener(PhotoController.Property.QUALITY,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            qualitySlider.setValue(qualitySlider.getMinimum() + controller.getQuality());
            updateAdvancedComponents();
          }
        });
    this.qualitySlider.setValue(this.qualitySlider.getMinimum() + controller.getQuality());

    this.advancedComponentsSeparator = new JSeparator();

    // Create date and time labels and spinners bound to TIME controller property
    Date time = new Date(Camera.convertTimeToTimeZone(controller.getTime(), TimeZone.getDefault().getID()));
    this.dateLabel = new JLabel();
    final SpinnerDateModel dateSpinnerModel = new SpinnerDateModel();
    dateSpinnerModel.setValue(time);
    this.dateSpinner = new JSpinner(dateSpinnerModel);
    String datePattern = ((SimpleDateFormat)DateFormat.getDateInstance(DateFormat.SHORT)).toPattern();
    if (datePattern.indexOf("yyyy") == -1) {
      datePattern = datePattern.replace("yy", "yyyy");
    }
    JSpinner.DateEditor dateEditor = new JSpinner.DateEditor(this.dateSpinner, datePattern);
    this.dateSpinner.setEditor(dateEditor);
    SwingTools.addAutoSelectionOnFocusGain(dateEditor.getTextField());
   
    this.timeLabel = new JLabel();
    final SpinnerDateModel timeSpinnerModel = new SpinnerDateModel();
    timeSpinnerModel.setValue(time);
    this.timeSpinner = new JSpinner(timeSpinnerModel);
    // From http://en.wikipedia.org/wiki/12-hour_clock#Use_by_country
    String [] twelveHoursCountries = {
        "AU"// Australia
        "BD"// Bangladesh
        "CA"// Canada (excluding Quebec, in French)
        "CO"// Colombia
        "EG"// Egypt
        "HN"// Honduras
        "JO"// Jordan
        "MX"// Mexico
        "MY"// Malaysia
        "NI"// Nicaragua
        "NZ"// New Zealand
        "PH"// Philippines
        "PK"// Pakistan
        "SA"// Saudi Arabia
        "SV"// El Salvador
        "US"// United States
        "VE"}; // Venezuela        
    SimpleDateFormat timeInstance;
    if ("en".equals(Locale.getDefault().getLanguage())) {
      if (Arrays.binarySearch(twelveHoursCountries, Locale.getDefault().getCountry()) >= 0) {
        timeInstance = (SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US); // 12 hours notation
      } else {
        timeInstance = (SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.SHORT, Locale.UK); // 24 hours notation
      }
    } else {
      timeInstance = (SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.SHORT);
    }
    JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(this.timeSpinner, timeInstance.toPattern());
    this.timeSpinner.setEditor(timeEditor);
    SwingTools.addAutoSelectionOnFocusGain(timeEditor.getTextField());

    final PropertyChangeListener timeChangeListener = new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent ev) {
        Date date = new Date(Camera.convertTimeToTimeZone(controller.getTime(), TimeZone.getDefault().getID()));
        dateSpinnerModel.setValue(date);
        timeSpinnerModel.setValue(date);
      }
    };
    controller.addPropertyChangeListener(PhotoController.Property.TIME, timeChangeListener);
    final ChangeListener dateTimeChangeListener = new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(PhotoController.Property.TIME, timeChangeListener);
          // Merge date and time
          GregorianCalendar dateCalendar = new GregorianCalendar();
          dateCalendar.setTime((Date)dateSpinnerModel.getValue());
View Full Code Here

        nameVisibleCheckBox.setNullable(ev.getNewValue() == null);
        nameVisibleCheckBox.setValue((Boolean)ev.getNewValue());
      }
    };
    controller.addPropertyChangeListener(HomeFurnitureController.Property.NAME_VISIBLE, nameVisibleChangeListener);
    this.nameVisibleCheckBox.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(HomeFurnitureController.Property.NAME_VISIBLE, nameVisibleChangeListener);
          controller.setNameVisible(nameVisibleCheckBox.getValue());
          controller.addPropertyChangeListener(HomeFurnitureController.Property.NAME_VISIBLE, nameVisibleChangeListener);
        }
      });
   
    // Create X label and its spinner bound to X controller property
    this.xLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "xLabel.text", unitName));
    final NullableSpinner.NullableSpinnerLengthModel xSpinnerModel =
        new NullableSpinner.NullableSpinnerLengthModel(preferences, -100000f, 100000f);
    this.xSpinner = new NullableSpinner(xSpinnerModel);
    xSpinnerModel.setNullable(controller.getX() == null);
    xSpinnerModel.setLength(controller.getX());
    final PropertyChangeListener xChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          xSpinnerModel.setNullable(ev.getNewValue() == null);
          xSpinnerModel.setLength((Float)ev.getNewValue());
        }
      };
    controller.addPropertyChangeListener(HomeFurnitureController.Property.X, xChangeListener);
    xSpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(HomeFurnitureController.Property.X, xChangeListener);
          controller.setX(xSpinnerModel.getLength());
          controller.addPropertyChangeListener(HomeFurnitureController.Property.X, xChangeListener);
        }
      });
   
    // Create Y label and its spinner bound to Y controller property
    this.yLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "yLabel.text", unitName));
    final NullableSpinner.NullableSpinnerLengthModel ySpinnerModel =
        new NullableSpinner.NullableSpinnerLengthModel(preferences, -100000f, 100000f);
    this.ySpinner = new NullableSpinner(ySpinnerModel);
    ySpinnerModel.setNullable(controller.getY() == null);
    ySpinnerModel.setLength(controller.getY());
    final PropertyChangeListener yChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          ySpinnerModel.setNullable(ev.getNewValue() == null);
          ySpinnerModel.setLength((Float)ev.getNewValue());
        }
      };
    controller.addPropertyChangeListener(HomeFurnitureController.Property.Y, yChangeListener);
    ySpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(HomeFurnitureController.Property.Y, yChangeListener);
          controller.setY(ySpinnerModel.getLength());
          controller.addPropertyChangeListener(HomeFurnitureController.Property.Y, yChangeListener);
        }
      });
   
    // Create elevation label and its spinner bound to ELEVATION controller property
    this.elevationLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "elevationLabel.text", unitName));
    final NullableSpinner.NullableSpinnerLengthModel elevationSpinnerModel =
        new NullableSpinner.NullableSpinnerLengthModel(preferences, 0f, 2500f);
    this.elevationSpinner = new NullableSpinner(elevationSpinnerModel);
    elevationSpinnerModel.setNullable(controller.getElevation() == null);
    elevationSpinnerModel.setLength(controller.getElevation());
    final PropertyChangeListener elevationChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          elevationSpinnerModel.setNullable(ev.getNewValue() == null);
          elevationSpinnerModel.setLength((Float)ev.getNewValue());
        }
      };
    controller.addPropertyChangeListener(HomeFurnitureController.Property.ELEVATION,
        elevationChangeListener);
    elevationSpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(HomeFurnitureController.Property.ELEVATION,
              elevationChangeListener);
          controller.setElevation(elevationSpinnerModel.getLength());
          controller.addPropertyChangeListener(HomeFurnitureController.Property.ELEVATION,
              elevationChangeListener);
        }
      });
   
    // Create angle label and its spinner bound to ANGLE_IN_DEGREES controller property
    this.angleLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "angleLabel.text"));
    final NullableSpinner.NullableSpinnerNumberModel angleSpinnerModel =
        new NullableSpinner.NullableSpinnerNumberModel(0, 0, 360, 1);
    this.angleSpinner = new NullableSpinner(angleSpinnerModel);
    Integer angle = controller.getAngleInDegrees();
    angleSpinnerModel.setNullable(angle == null);
    angleSpinnerModel.setValue(angle);
    final PropertyChangeListener angleChangeListener = new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent ev) {
        Float newAngle = (Float)ev.getNewValue();
        angleSpinnerModel.setNullable(newAngle == null);
        angleSpinnerModel.setValue(newAngle);
      }
    };
    controller.addPropertyChangeListener(HomeFurnitureController.Property.ANGLE_IN_DEGREES, angleChangeListener);
    angleSpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(HomeFurnitureController.Property.ANGLE_IN_DEGREES, angleChangeListener);
          Number value = (Number)angleSpinnerModel.getValue();
          if (value == null) {
            controller.setAngleInDegrees(null);
          } else {
            controller.setAngleInDegrees(value.intValue());
          }
          controller.addPropertyChangeListener(HomeFurnitureController.Property.ANGLE_IN_DEGREES, angleChangeListener);
        }
      });
  
    // Create base plan item check box bound to BASE_PLAN_ITEM controller property
    this.basePlanItemCheckBox = new NullableCheckBox(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "basePlanItemCheckBox.text"));
    String basePlanItemToolTip = preferences.getLocalizedString(
        HomeFurniturePanel.class, "basePlanItemCheckBox.tooltip");
    if (basePlanItemToolTip.length() > 0) {
      this.basePlanItemCheckBox.setToolTipText(basePlanItemToolTip);
    }
    this.basePlanItemCheckBox.setNullable(controller.getBasePlanItem() == null);
    this.basePlanItemCheckBox.setValue(controller.getBasePlanItem());
    final PropertyChangeListener basePlanItemModelChangeListener = new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent ev) {
        basePlanItemCheckBox.setNullable(ev.getNewValue() == null);
        basePlanItemCheckBox.setValue((Boolean)ev.getNewValue());
      }
    };
    controller.addPropertyChangeListener(HomeFurnitureController.Property.BASE_PLAN_ITEM, basePlanItemModelChangeListener);
    this.basePlanItemCheckBox.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(HomeFurnitureController.Property.BASE_PLAN_ITEM, basePlanItemModelChangeListener);
          controller.setBasePlanItem(basePlanItemCheckBox.getValue());
          controller.addPropertyChangeListener(HomeFurnitureController.Property.BASE_PLAN_ITEM, basePlanItemModelChangeListener);
        }
      });
    this.basePlanItemCheckBox.setEnabled(controller.isBasePlanItemEditable());

    // Create width label and its spinner bound to WIDTH controller property
    this.widthLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "widthLabel.text", unitName));
    final float minimumLength = preferences.getLengthUnit().getMinimumLength();
    final NullableSpinner.NullableSpinnerLengthModel widthSpinnerModel =
        new NullableSpinner.NullableSpinnerLengthModel(preferences, minimumLength, 100000f);
    this.widthSpinner = new NullableSpinner(widthSpinnerModel);
    final PropertyChangeListener widthChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          Float width = controller.getWidth();
          widthSpinnerModel.setNullable(width == null);
          widthSpinnerModel.setLength(width);
          if (width != null) {
            widthSpinnerModel.setMinimum(Math.min(width, minimumLength));
          }
        }
      };
    widthChangeListener.propertyChange(null);
    controller.addPropertyChangeListener(HomeFurnitureController.Property.WIDTH, widthChangeListener);
    widthSpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(HomeFurnitureController.Property.WIDTH, widthChangeListener);
          controller.setWidth(widthSpinnerModel.getLength());
          controller.addPropertyChangeListener(HomeFurnitureController.Property.WIDTH, widthChangeListener);
        }
      });
   
    // Create depth label and its spinner bound to DEPTH controller property
    this.depthLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "depthLabel.text", unitName));
    final NullableSpinner.NullableSpinnerLengthModel depthSpinnerModel =
        new NullableSpinner.NullableSpinnerLengthModel(preferences, minimumLength, 100000f);
    this.depthSpinner = new NullableSpinner(depthSpinnerModel);
    final PropertyChangeListener depthChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          Float depth = controller.getDepth();
          depthSpinnerModel.setNullable(depth == null);
          depthSpinnerModel.setLength(depth);
          if (depth != null) {
            depthSpinnerModel.setMinimum(Math.min(depth, minimumLength));
          }
        }
      };
    depthChangeListener.propertyChange(null);
    controller.addPropertyChangeListener(HomeFurnitureController.Property.DEPTH, depthChangeListener);
    depthSpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(HomeFurnitureController.Property.DEPTH, depthChangeListener);
          controller.setDepth(depthSpinnerModel.getLength());
          controller.addPropertyChangeListener(HomeFurnitureController.Property.DEPTH, depthChangeListener);
        }
      });
   
    // Create height label and its spinner bound to HEIGHT controller property
    this.heightLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "heightLabel.text", unitName));
    final NullableSpinner.NullableSpinnerLengthModel heightSpinnerModel =
        new NullableSpinner.NullableSpinnerLengthModel(preferences, minimumLength, 100000f);
    this.heightSpinner = new NullableSpinner(heightSpinnerModel);
    final PropertyChangeListener heightChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          Float height = controller.getHeight();
          heightSpinnerModel.setNullable(height == null);
          heightSpinnerModel.setLength(height);
          if (height != null) {
            heightSpinnerModel.setMinimum(Math.min(height, minimumLength));
          }
        }
      };
    heightChangeListener.propertyChange(null);
    controller.addPropertyChangeListener(HomeFurnitureController.Property.HEIGHT, heightChangeListener);
    heightSpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(HomeFurnitureController.Property.HEIGHT, heightChangeListener);
          controller.setHeight(heightSpinnerModel.getLength());
          controller.addPropertyChangeListener(HomeFurnitureController.Property.HEIGHT, heightChangeListener);
        }
      });
   
    // Create keep proportions check box bound to PROPORTIONAL controller property
    this.keepProportionsCheckBox = new JCheckBox(SwingTools.getLocalizedLabelText(preferences,
        ImportedFurnitureWizardStepsPanel.class, "keepProportionsCheckBox.text"));
    this.keepProportionsCheckBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
          controller.setProportional(keepProportionsCheckBox.isSelected());
        }
      });
    this.keepProportionsCheckBox.setSelected(controller.isProportional());
    controller.addPropertyChangeListener(HomeFurnitureController.Property.PROPORTIONAL,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            // If proportional property changes update keep proportions check box
            keepProportionsCheckBox.setSelected(controller.isProportional());
          }
        });

    // Create mirror check box bound to MODEL_MIRRORED controller property
    this.mirroredModelCheckBox = new NullableCheckBox(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "mirroredModelCheckBox.text"));
    String mirroredModelToolTip = preferences.getLocalizedString(
        HomeFurniturePanel.class, "mirroredModelCheckBox.tooltip");
    if (mirroredModelToolTip.length() > 0) {
      this.mirroredModelCheckBox.setToolTipText(mirroredModelToolTip);
    }
    this.mirroredModelCheckBox.setNullable(controller.getModelMirrored() == null);
    this.mirroredModelCheckBox.setValue(controller.getModelMirrored());
    final PropertyChangeListener mirroredModelChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          mirroredModelCheckBox.setNullable(ev.getNewValue() == null);
          mirroredModelCheckBox.setValue((Boolean)ev.getNewValue());
        }
      };
    controller.addPropertyChangeListener(HomeFurnitureController.Property.MODEL_MIRRORED, mirroredModelChangeListener);
    this.mirroredModelCheckBox.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(HomeFurnitureController.Property.MODEL_MIRRORED, mirroredModelChangeListener);
          controller.setModelMirrored(mirroredModelCheckBox.getValue());
          controller.addPropertyChangeListener(HomeFurnitureController.Property.MODEL_MIRRORED, mirroredModelChangeListener);
        }
      });
   
    // Create radio buttons bound to COLOR and TEXTURE controller properties
    this.defaultColorAndTextureRadioButton = new JRadioButton(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "defaultColorAndTextureRadioButton.text"));
    this.defaultColorAndTextureRadioButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          if (defaultColorAndTextureRadioButton.isSelected()) {
            controller.setPaint(HomeFurnitureController.FurniturePaint.DEFAULT);
          }
        }
      });
    controller.addPropertyChangeListener(HomeFurnitureController.Property.PAINT,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            updateColorAndTextureRadioButtons(controller);
          }
        });
    this.colorRadioButton = new JRadioButton(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "colorRadioButton.text"));
    this.colorRadioButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          if (colorRadioButton.isSelected()) {
            controller.setPaint(HomeFurnitureController.FurniturePaint.COLORED);
          }
        }
      });
   
    this.colorButton = new ColorButton();
    this.colorButton.setColorDialogTitle(preferences.getLocalizedString(
        HomeFurniturePanel.class, "colorDialog.title"));
    this.colorButton.setColor(controller.getColor());
    this.colorButton.addPropertyChangeListener(ColorButton.COLOR_PROPERTY,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            controller.setColor(colorButton.getColor());
            controller.setPaint(HomeFurnitureController.FurniturePaint.COLORED);
          }
        });
    controller.addPropertyChangeListener(HomeFurnitureController.Property.COLOR,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            colorButton.setColor(controller.getColor());
          }
        });

    this.textureRadioButton = new JRadioButton(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "textureRadioButton.text"));
    this.textureRadioButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          if (textureRadioButton.isSelected()) {
            controller.setPaint(HomeFurnitureController.FurniturePaint.TEXTURED);
          }
        }
      });
   
    TextureChoiceController textureController = controller.getTextureController();
    if (textureController != null) {
      this.textureComponent = (JComponent)textureController.getView();
    }

    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(this.defaultColorAndTextureRadioButton);
    buttonGroup.add(this.colorRadioButton);
    buttonGroup.add(this.textureRadioButton);
    updateColorAndTextureRadioButtons(controller);

    // Create radio buttons bound to SHININESS controller properties
    this.defaultShininessRadioButton = new JRadioButton(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "defaultShininessRadioButton.text"));
    this.defaultShininessRadioButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          if (defaultShininessRadioButton.isSelected()) {
            controller.setShininess(HomeFurnitureController.FurnitureShininess.DEFAULT);
          }
        }
      });
    controller.addPropertyChangeListener(HomeFurnitureController.Property.SHININESS,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            updateShininessRadioButtons(controller);
          }
        });
    this.mattRadioButton = new JRadioButton(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "mattRadioButton.text"));
    this.mattRadioButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          if (mattRadioButton.isSelected()) {
            controller.setShininess(HomeFurnitureController.FurnitureShininess.MATT);
          }
        }
      });
    this.shinyRadioButton = new JRadioButton(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "shinyRadioButton.text"));
    this.shinyRadioButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          if (shinyRadioButton.isSelected()) {
            controller.setShininess(HomeFurnitureController.FurnitureShininess.SHINY);
          }
        }
      });
   
    buttonGroup = new ButtonGroup();
    buttonGroup.add(this.defaultShininessRadioButton);
    buttonGroup.add(this.mattRadioButton);
    buttonGroup.add(this.shinyRadioButton);
    updateShininessRadioButtons(controller);

    // Create visible check box bound to VISIBLE controller property
    this.visibleCheckBox = new NullableCheckBox(SwingTools.getLocalizedLabelText(preferences,
        HomeFurniturePanel.class, "visibleCheckBox.text"));
    this.visibleCheckBox.setNullable(controller.getVisible() == null);
    this.visibleCheckBox.setValue(controller.getVisible());
    final PropertyChangeListener visibleChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          visibleCheckBox.setNullable(ev.getNewValue() == null);
          visibleCheckBox.setValue((Boolean)ev.getNewValue());
        }
      };
    controller.addPropertyChangeListener(HomeFurnitureController.Property.VISIBLE, visibleChangeListener);
    this.visibleCheckBox.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(HomeFurnitureController.Property.VISIBLE, visibleChangeListener);
          controller.setVisible(visibleCheckBox.getValue());
          controller.addPropertyChangeListener(HomeFurnitureController.Property.VISIBLE, visibleChangeListener);
        }
      });
   
    // Create power label and its spinner bound to POWER controller property
    if (controller.isLightPowerEditable()) {
      this.lightPowerLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
          HomeFurniturePanel.class, "lightPowerLabel.text", unitName));
      final NullableSpinner.NullableSpinnerNumberModel lightPowerSpinnerModel =
          new NullableSpinner.NullableSpinnerNumberModel(0, 0, 100, 5);
      this.lightPowerSpinner = new NullableSpinner(lightPowerSpinnerModel);
      lightPowerSpinnerModel.setNullable(controller.getLightPower() == null);
      lightPowerSpinnerModel.setValue(controller.getLightPower() != null ? Math.round(controller.getLightPower() * 100) : null);
      final PropertyChangeListener lightPowerChangeListener = new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            Float lightPower = (Float)ev.getNewValue();
            lightPowerSpinnerModel.setNullable(lightPower == null);
            lightPowerSpinnerModel.setValue(lightPower != null ? Math.round((Float)ev.getNewValue() * 100) : null);
          }
        };
      controller.addPropertyChangeListener(HomeFurnitureController.Property.LIGHT_POWER, lightPowerChangeListener);
      lightPowerSpinnerModel.addChangeListener(new ChangeListener() {
          public void stateChanged(ChangeEvent ev) {
            controller.removePropertyChangeListener(HomeFurnitureController.Property.LIGHT_POWER, lightPowerChangeListener);
            controller.setLightPower(((Number)lightPowerSpinnerModel.getValue()).floatValue() / 100f);
            controller.addPropertyChangeListener(HomeFurnitureController.Property.LIGHT_POWER, lightPowerChangeListener);
          }
View Full Code Here

        areaVisibleCheckBox.setNullable(ev.getNewValue() == null);
        areaVisibleCheckBox.setValue((Boolean)ev.getNewValue());
      }
    };
    controller.addPropertyChangeListener(RoomController.Property.AREA_VISIBLE, visibleChangeListener);
    this.areaVisibleCheckBox.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(RoomController.Property.AREA_VISIBLE, visibleChangeListener);
          controller.setAreaVisible(areaVisibleCheckBox.getValue());
          controller.addPropertyChangeListener(RoomController.Property.AREA_VISIBLE, visibleChangeListener);
        }
      });

    // Create floor visible check box bound to FLOOR_VISIBLE controller property
    this.floorVisibleCheckBox = new NullableCheckBox(SwingTools.getLocalizedLabelText(preferences,
        RoomPanel.class, "floorVisibleCheckBox.text"));
    this.floorVisibleCheckBox.setNullable(controller.getFloorVisible() == null);
    this.floorVisibleCheckBox.setValue(controller.getFloorVisible());
    final PropertyChangeListener floorVisibleChangeListener = new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent ev) {
        floorVisibleCheckBox.setNullable(ev.getNewValue() == null);
        floorVisibleCheckBox.setValue((Boolean)ev.getNewValue());
      }
    };
    controller.addPropertyChangeListener(RoomController.Property.FLOOR_VISIBLE, floorVisibleChangeListener);
    this.floorVisibleCheckBox.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(RoomController.Property.FLOOR_VISIBLE, floorVisibleChangeListener);
          controller.setFloorVisible(floorVisibleCheckBox.getValue());
          controller.addPropertyChangeListener(RoomController.Property.FLOOR_VISIBLE, floorVisibleChangeListener);
        }
      });
   
    // Floor color and texture buttons bound to floor controller properties
    this.floorColorRadioButton = new JRadioButton(SwingTools.getLocalizedLabelText(preferences,
        RoomPanel.class, "floorColorRadioButton.text"));
    this.floorColorRadioButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          if (floorColorRadioButton.isSelected()) {
            controller.setFloorPaint(RoomController.RoomPaint.COLORED);
          }
        }
      });
    controller.addPropertyChangeListener(RoomController.Property.FLOOR_PAINT,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            updateFloorColorRadioButtons(controller);
          }
        });
   
    this.floorColorButton = new ColorButton();
    this.floorColorButton.setColorDialogTitle(preferences.getLocalizedString(
        RoomPanel.class, "floorColorDialog.title"));
    this.floorColorButton.setColor(controller.getFloorColor());
    this.floorColorButton.addPropertyChangeListener(ColorButton.COLOR_PROPERTY,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            controller.setFloorColor(floorColorButton.getColor());
            controller.setFloorPaint(RoomController.RoomPaint.COLORED);
          }
        });
    controller.addPropertyChangeListener(RoomController.Property.FLOOR_COLOR,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            floorColorButton.setColor(controller.getFloorColor());
          }
        });

    this.floorTextureRadioButton = new JRadioButton(SwingTools.getLocalizedLabelText(preferences,
        RoomPanel.class, "floorTextureRadioButton.text"));
    this.floorTextureRadioButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          if (floorTextureRadioButton.isSelected()) {
            controller.setFloorPaint(RoomController.RoomPaint.TEXTURED);
          }
        }
      });
   
    this.floorTextureComponent = (JComponent)controller.getFloorTextureController().getView();
   
    ButtonGroup floorButtonColorGroup = new ButtonGroup();
    floorButtonColorGroup.add(this.floorColorRadioButton);
    floorButtonColorGroup.add(this.floorTextureRadioButton);
    updateFloorColorRadioButtons(controller);
   
    // Floor shininess radio buttons bound to FLOOR_SHININESS controller property
    this.floorMattRadioButton = new JRadioButton(SwingTools.getLocalizedLabelText(preferences,
        RoomPanel.class, "floorMattRadioButton.text"));
    this.floorMattRadioButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          if (floorMattRadioButton.isSelected()) {
            controller.setFloorShininess(0f);
          }
        }
      });
    PropertyChangeListener floorShininessListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          updateFloorShininessRadioButtons(controller);
        }
      };
    controller.addPropertyChangeListener(RoomController.Property.FLOOR_SHININESS,
        floorShininessListener);

    this.floorShinyRadioButton = new JRadioButton(SwingTools.getLocalizedLabelText(preferences,
        RoomPanel.class, "floorShinyRadioButton.text"));
    this.floorShinyRadioButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          if (floorShinyRadioButton.isSelected()) {
            controller.setFloorShininess(0.25f);
          }
        }
      });
    controller.addPropertyChangeListener(RoomController.Property.FLOOR_SHININESS,
        floorShininessListener);
   
    ButtonGroup floorShininessButtonGroup = new ButtonGroup();
    floorShininessButtonGroup.add(this.floorMattRadioButton);
    floorShininessButtonGroup.add(this.floorShinyRadioButton);
    updateFloorShininessRadioButtons(controller);

    // Create ceiling visible check box bound to CEILING_VISIBLE controller property
    this.ceilingVisibleCheckBox = new NullableCheckBox(SwingTools.getLocalizedLabelText(preferences,
        RoomPanel.class, "ceilingVisibleCheckBox.text"));
    this.ceilingVisibleCheckBox.setNullable(controller.getCeilingVisible() == null);
    this.ceilingVisibleCheckBox.setValue(controller.getCeilingVisible());
    final PropertyChangeListener ceilingVisibleChangeListener = new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent ev) {
        ceilingVisibleCheckBox.setNullable(ev.getNewValue() == null);
        ceilingVisibleCheckBox.setValue((Boolean)ev.getNewValue());
      }
    };
    controller.addPropertyChangeListener(RoomController.Property.CEILING_VISIBLE, ceilingVisibleChangeListener);
    this.ceilingVisibleCheckBox.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(RoomController.Property.CEILING_VISIBLE, ceilingVisibleChangeListener);
          controller.setCeilingVisible(ceilingVisibleCheckBox.getValue());
          controller.addPropertyChangeListener(RoomController.Property.CEILING_VISIBLE, ceilingVisibleChangeListener);
        }
      });

    // Ceiling color and texture buttons bound to ceiling controller properties
    this.ceilingColorRadioButton = new JRadioButton(SwingTools.getLocalizedLabelText(preferences,
        RoomPanel.class, "ceilingColorRadioButton.text"));
    this.ceilingColorRadioButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
          if (ceilingColorRadioButton.isSelected()) {
            controller.setCeilingPaint(RoomController.RoomPaint.COLORED);
          }
        }
      });
    controller.addPropertyChangeListener(RoomController.Property.CEILING_PAINT,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            updateCeilingColorRadioButtons(controller);
          }
        });

    this.ceilingColorButton = new ColorButton();
    this.ceilingColorButton.setColor(controller.getCeilingColor());
    this.ceilingColorButton.setColorDialogTitle(preferences.getLocalizedString(
        RoomPanel.class, "ceilingColorDialog.title"));
    this.ceilingColorButton.addPropertyChangeListener(ColorButton.COLOR_PROPERTY,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            controller.setCeilingColor(ceilingColorButton.getColor());
            controller.setCeilingPaint(RoomController.RoomPaint.COLORED);
          }
        });
    controller.addPropertyChangeListener(RoomController.Property.CEILING_COLOR,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            ceilingColorButton.setColor(controller.getCeilingColor());
          }
        });
   
    this.ceilingTextureRadioButton = new JRadioButton(SwingTools.getLocalizedLabelText(preferences,
        RoomPanel.class, "ceilingTextureRadioButton.text"));
    this.ceilingTextureRadioButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
          if (ceilingTextureRadioButton.isSelected()) {
            controller.setCeilingPaint(RoomController.RoomPaint.TEXTURED);
          }
        }
      });
 
    this.ceilingTextureComponent = (JComponent)controller.getCeilingTextureController().getView();

    ButtonGroup ceilingColorButtonGroup = new ButtonGroup();
    ceilingColorButtonGroup.add(this.ceilingColorRadioButton);
    ceilingColorButtonGroup.add(this.ceilingTextureRadioButton);
    updateCeilingColorRadioButtons(controller);

    // Ceiling shininess radio buttons bound to CEILING_SHININESS controller property
    this.ceilingMattRadioButton = new JRadioButton(SwingTools.getLocalizedLabelText(preferences,
        RoomPanel.class, "ceilingMattRadioButton.text"));
    this.ceilingMattRadioButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          if (ceilingMattRadioButton.isSelected()) {
            controller.setCeilingShininess(0f);
          }
        }
      });
    PropertyChangeListener ceilingShininessListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          updateCeilingShininessRadioButtons(controller);
        }
      };
    controller.addPropertyChangeListener(RoomController.Property.CEILING_SHININESS,
        ceilingShininessListener);

    this.ceilingShinyRadioButton = new JRadioButton(SwingTools.getLocalizedLabelText(preferences,
        RoomPanel.class, "ceilingShinyRadioButton.text"));
    this.ceilingShinyRadioButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          if (ceilingShinyRadioButton.isSelected()) {
            controller.setCeilingShininess(0.25f);
          }
        }
View Full Code Here

        ImportedFurnitureWizardStepsPanel.class, "widthLabel.text", unitName));
    final float minimumLength = preferences.getLengthUnit().getMinimumLength();
    final NullableSpinner.NullableSpinnerLengthModel widthSpinnerModel =
        new NullableSpinner.NullableSpinnerLengthModel(preferences, Math.min(controller.getWidth(), minimumLength), 100000f);
    this.widthSpinner = new NullableSpinner(widthSpinnerModel);
    widthSpinnerModel.addChangeListener(new ChangeListener () {
        public void stateChanged(ChangeEvent ev) {
          widthSpinnerModel.removeChangeListener(this);
          // If width spinner value changes update controller
          controller.setWidth(widthSpinnerModel.getLength());
          widthSpinnerModel.addChangeListener(this);
        }
      });
    controller.addPropertyChangeListener(ImportedFurnitureWizardController.Property.WIDTH,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            // If width changes update width spinner
            widthSpinnerModel.setLength(controller.getWidth());
            widthSpinnerModel.setMinimum(Math.min(controller.getWidth(), minimumLength));
          }
        });
   
    this.depthLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
        ImportedFurnitureWizardStepsPanel.class, "depthLabel.text", unitName));
    final NullableSpinner.NullableSpinnerLengthModel depthSpinnerModel =
        new NullableSpinner.NullableSpinnerLengthModel(preferences, Math.min(controller.getDepth(), minimumLength), 100000f);
    this.depthSpinner = new NullableSpinner(depthSpinnerModel);
    depthSpinnerModel.addChangeListener(new ChangeListener () {
        public void stateChanged(ChangeEvent ev) {
          depthSpinnerModel.removeChangeListener(this);
          // If depth spinner value changes update controller
          controller.setDepth(depthSpinnerModel.getLength());
          depthSpinnerModel.addChangeListener(this);
        }
      });
    controller.addPropertyChangeListener(ImportedFurnitureWizardController.Property.DEPTH,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            // If depth changes update depth spinner
            depthSpinnerModel.setLength(controller.getDepth());
            depthSpinnerModel.setMinimum(Math.min(controller.getDepth(), minimumLength));
          }
        });
   
    this.heightLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
            ImportedFurnitureWizardStepsPanel.class, "heightLabel.text", unitName));
    final NullableSpinner.NullableSpinnerLengthModel heightSpinnerModel =
        new NullableSpinner.NullableSpinnerLengthModel(preferences, Math.min(controller.getHeight(), minimumLength), 100000f);
    this.heightSpinner = new NullableSpinner(heightSpinnerModel);
    heightSpinnerModel.addChangeListener(new ChangeListener () {
        public void stateChanged(ChangeEvent ev) {
          heightSpinnerModel.removeChangeListener(this);
          // If width spinner value changes update controller
          controller.setHeight(heightSpinnerModel.getLength());
          heightSpinnerModel.addChangeListener(this);
        }
      });
    controller.addPropertyChangeListener(ImportedFurnitureWizardController.Property.HEIGHT,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            // If height changes update height spinner
            heightSpinnerModel.setLength(controller.getHeight());
            heightSpinnerModel.setMinimum(Math.min(controller.getHeight(), minimumLength));
          }
        });
    this.keepProportionsCheckBox = new JCheckBox(SwingTools.getLocalizedLabelText(preferences,
        ImportedFurnitureWizardStepsPanel.class, "keepProportionsCheckBox.text"));
    this.keepProportionsCheckBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
          controller.setProportional(keepProportionsCheckBox.isSelected());
        }
      });
    controller.addPropertyChangeListener(ImportedFurnitureWizardController.Property.PROPORTIONAL,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            // If proportional property changes update keep proportions check box
            keepProportionsCheckBox.setSelected(controller.isProportional());
          }
        });
   
    this.elevationLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
        ImportedFurnitureWizardStepsPanel.class, "elevationLabel.text", unitName));
    final NullableSpinner.NullableSpinnerLengthModel elevationSpinnerModel =
        new NullableSpinner.NullableSpinnerLengthModel(preferences, 0f, 2500f);
    this.elevationSpinner = new NullableSpinner(elevationSpinnerModel);
    elevationSpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          widthSpinnerModel.removeChangeListener(this);
          controller.setElevation(elevationSpinnerModel.getLength());
          widthSpinnerModel.addChangeListener(this);
        }
View Full Code Here

          }
        });
      timer.setInitialDelay(0);
     
      // Update camera when button is armed
      addChangeListener(new ChangeListener() {
          public void stateChanged(ChangeEvent ev) {
            if (getModel().isArmed()
                && !timer.isRunning()) {
              timer.restart();
            } else if (!getModel().isArmed()
View Full Code Here

        ImportedTextureWizardStepsPanel.class, "widthLabel.text", unitName));
    float minimumLength = preferences.getLengthUnit().getMinimumLength();
    final NullableSpinner.NullableSpinnerLengthModel widthSpinnerModel =
        new NullableSpinner.NullableSpinnerLengthModel(preferences, minimumLength, 100000f);
    this.widthSpinner = new NullableSpinner(widthSpinnerModel);
    widthSpinnerModel.addChangeListener(new ChangeListener () {
        public void stateChanged(ChangeEvent ev) {
          widthSpinnerModel.removeChangeListener(this);
          // If width spinner value changes update controller
          controller.setWidth(widthSpinnerModel.getLength());
          widthSpinnerModel.addChangeListener(this);
        }
      });
    controller.addPropertyChangeListener(ImportedTextureWizardController.Property.WIDTH,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            // If width changes update width spinner
            widthSpinnerModel.setLength(controller.getWidth());
          }
        });
   
    this.heightLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
            ImportedTextureWizardStepsPanel.class, "heightLabel.text", unitName));
    final NullableSpinner.NullableSpinnerLengthModel heightSpinnerModel =
        new NullableSpinner.NullableSpinnerLengthModel(preferences, minimumLength, 100000f);
    this.heightSpinner = new NullableSpinner(heightSpinnerModel);
    heightSpinnerModel.addChangeListener(new ChangeListener () {
        public void stateChanged(ChangeEvent ev) {
          heightSpinnerModel.removeChangeListener(this);
          // If width spinner value changes update controller
          controller.setHeight(heightSpinnerModel.getLength());
          heightSpinnerModel.addChangeListener(this);
View Full Code Here

      @Override
      public void actionPerformed(ActionEvent e) {
        _datastoreListPanel.setSelectedDatastorePanel(DatastorePanel.this);
      }
    });
    _checkBox.addChangeListener(new ChangeListener() {
      @Override
      public void stateChanged(ChangeEvent e) {
        setOpaque(isSelected());
        updateUI();
      }
View Full Code Here

    detailPanel.setTabPlacement(JTabbedPane.BOTTOM);

    detailPanel.setBorder(null);

    detailPanel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
          for(Iterator it = detailMap.keySet().iterator(); it.hasNext();) {
            ServiceReference sr = (ServiceReference)it.next();
            Object obj = detailMap.get(sr);
View Full Code Here

TOP

Related Classes of javax.swing.event.ChangeListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.