Examples of JSpinner


Examples of javax.swing.JSpinner

    // Retrieve ImportedFurnitureWizardStepsPanel components
    BackgroundImageWizardStepsPanel panel = (BackgroundImageWizardStepsPanel)TestUtilities.findComponent(
        wizardDialog, BackgroundImageWizardStepsPanel.class);
    JButton imageChoiceOrChangeButton = (JButton)TestUtilities.getField(panel, "imageChoiceOrChangeButton");
    JSpinner scaleDistanceSpinner = (JSpinner)TestUtilities.getField(panel, "scaleDistanceSpinner");
    JSpinner xOriginSpinner = (JSpinner)TestUtilities.getField(panel, "xOriginSpinner");
    JSpinner yOriginSpinner = (JSpinner)TestUtilities.getField(panel, "yOriginSpinner");
   
    // Check current step is image
    assertStepShowing(panel, true, false, false);   
   
    // 3. Choose tested image
    String imageChoiceOrChangeButtonText = imageChoiceOrChangeButton.getText();
    tester.click(imageChoiceOrChangeButton);
    // Wait 100 ms to let time to Java to load the image
    Thread.sleep(100);
    // Check choice button text changed
    assertFalse("Choice button text didn't change",
        imageChoiceOrChangeButtonText.equals(imageChoiceOrChangeButton.getText()));
    // Click on next button
    WizardPane view = (WizardPane)TestUtilities.findComponent(wizardDialog, WizardPane.class);
    // Retrieve wizard view next button
    final JButton nextFinishOptionButton = (JButton)TestUtilities.getField(view, "nextFinishOptionButton");
    assertTrue("Next button isn't enabled", nextFinishOptionButton.isEnabled());
    tester.click(nextFinishOptionButton);
    // Check current step is scale
    assertStepShowing(panel, false, true, false);
   
    // 4. Check scale distance spinner value is empty
    assertEquals("Scale distance spinner isn't empty", null, scaleDistanceSpinner.getValue());
    assertFalse("Next button is enabled", nextFinishOptionButton.isEnabled());
    // Check scale spinner field has focus
    tester.waitForIdle();
    assertSame("Scale spinner doesn't have focus", ((JSpinner.DefaultEditor)scaleDistanceSpinner.getEditor()).getTextField(),
        KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());   
    // Enter as scale
    tester.actionKeyString("100");   
    // Check next button is enabled
    assertTrue("Next button isn't enabled", nextFinishOptionButton.isEnabled());
    tester.click(nextFinishOptionButton);
    // Check current step is origin
    assertStepShowing(panel, false, false, true);
   
    // 5. Check origin x and y spinners value is 0
    assertEquals("Wrong origin x spinner value", new Float(0), xOriginSpinner.getValue());
    assertEquals("Wrong origin y spinner value", new Float(0), yOriginSpinner.getValue());
    assertTrue("Next button isn't enabled", nextFinishOptionButton.isEnabled());
    tester.waitForIdle();
    assertSame("Origin x spinner doesn't have focus", ((JSpinner.DefaultEditor)xOriginSpinner.getEditor()).getTextField(),
        KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());   
    // Change origin
View Full Code Here

Examples of javax.swing.JSpinner

        wall1.getLeftSideColor(), wall1.getLeftSideTexture(),
        null, wall1.getRightSideTexture(), wallController);
   
    // 4. Increase length in dialog
    DialogView wallView = wallController.getView();
    JSpinner distanceToEndPointSpinner =
        (JSpinner)TestUtilities.getField(wallView, "distanceToEndPointSpinner");
    distanceToEndPointSpinner.setValue((Float)distanceToEndPointSpinner.getValue() + 20f);
    // Check wall end coordinates changed accordingly
    assertTrue("Wrong X end", Math.abs(wall1.getXEnd() + 20f * (float)Math.cos(Math.PI / 4) - wallController.getXEnd()) < 1E-5);
    assertTrue("Wrong Y end", Math.abs(wall1.getYEnd() + 20f * (float)Math.sin(Math.PI / 4) - wallController.getYEnd()) < 1E-5);
   
    // 5. Add a second selected wall to home
View Full Code Here

Examples of javax.swing.JSpinner

    // Retrieve Home3DAttributesPanel components
    Home3DAttributesPanel panel = (Home3DAttributesPanel)TestUtilities.findComponent(
        attributesDialog, Home3DAttributesPanel.class);
    Home3DAttributesController panelController =
        (Home3DAttributesController)TestUtilities.getField(panel, "controller");
    JSpinner observerFieldOfViewSpinner =
        (JSpinner)TestUtilities.getField(panel, "observerFieldOfViewSpinner");
    JSpinner observerHeightSpinner =
        (JSpinner)TestUtilities.getField(panel, "observerHeightSpinner");
    ColorButton groundColorButton = 
        (ColorButton)TestUtilities.getField(panel, "groundColorButton");
    ColorButton skyColorButton =
        (ColorButton)TestUtilities.getField(panel, "skyColorButton");
    JSlider brightnessSlider =
        (JSlider)TestUtilities.getField(panel, "brightnessSlider");
    JSlider wallsTransparencySlider =
        (JSlider)TestUtilities.getField(panel, "wallsTransparencySlider");
    // Check edited values
    float oldCameraFieldOfView = observerCamera.getFieldOfView();
    float oldCameraHeight = observerCamera.getHeight();
    int oldGroundColor = home.getEnvironment().getGroundColor();
    TextureImage oldGroundTexture = home.getEnvironment().getGroundTexture();
    int oldSkyColor = home.getEnvironment().getSkyColor();
    int oldLightColor = home.getEnvironment().getLightColor();
    float oldWallsAlpha = home.getEnvironment().getWallsAlpha();
    assertEquals("Wrong field of view", (int)Math.round(Math.toDegrees(oldCameraFieldOfView)),
        observerFieldOfViewSpinner.getValue());
    assertEquals("Wrong height", (float)Math.round(oldCameraHeight * 100) / 100,
        observerHeightSpinner.getValue());
    assertEquals("Wrong ground color", oldGroundColor,
        groundColorButton.getColor().intValue());
    assertEquals("Wrong ground texture", oldGroundTexture,
        panelController.getGroundTextureController().getTexture());
    assertEquals("Wrong sky color", oldSkyColor,
        skyColorButton.getColor().intValue());
    assertEquals("Wrong brightness", oldLightColor & 0xFF,
        brightnessSlider.getValue());
    assertEquals("Wrong transparency", (int)(oldWallsAlpha * 255),
        wallsTransparencySlider.getValue());
   
    // 12. Change dialog box values
    observerFieldOfViewSpinner.setValue(90);
    observerHeightSpinner.setValue(300f);
    groundColorButton.setColor(0xFFFFFF);
    skyColorButton.setColor(0x000000);
    brightnessSlider.setValue(128);
    wallsTransparencySlider.setValue(128);
    // Click on Ok in dialog box
View Full Code Here

Examples of javax.swing.JSpinner

    // 3. Edit walls
    JDialog attributesDialog = showWallPanel(preferences, controller, frame, tester);
    // Retrieve WallPanel components
    WallPanel wallPanel = (WallPanel)TestUtilities.findComponent(
        attributesDialog, WallPanel.class);
    JSpinner xStartSpinner =
        (JSpinner)TestUtilities.getField(wallPanel, "xStartSpinner");
    JSpinner xEndSpinner =
        (JSpinner)TestUtilities.getField(wallPanel, "xEndSpinner");
    TextureChoiceComponent rightSideTextureComponent =
        (TextureChoiceComponent)TestUtilities.getField(wallPanel, "rightSideTextureComponent");
    // Check xStartSpinner and xEndSpinner panels aren't visible
    assertFalse("X start spinner panel is visible", xStartSpinner.getParent().isVisible());
    assertFalse("X end spinner panel is visible", xEndSpinner.getParent().isVisible());
    // Edit right side texture
    JDialog textureDialog = showTexturePanel(preferences, rightSideTextureComponent, false, attributesDialog, tester);
    JList availableTexturesList = (JList)new BasicFinder().find(textureDialog,
        new ClassMatcher(JList.class, true));
    int textureCount = availableTexturesList.getModel().getSize();
    CatalogTexture defaultTexture = (CatalogTexture)availableTexturesList.getSelectedValue();
    // Import texture
    JDialog textureWizardDialog = showImportTextureWizard(preferences, frame, tester, false);   
    // Retrieve ImportedFurnitureWizardStepsPanel components
    ImportedTextureWizardStepsPanel panel = (ImportedTextureWizardStepsPanel)TestUtilities.findComponent(
        textureWizardDialog, ImportedTextureWizardStepsPanel.class);
    final JButton imageChoiceOrChangeButton = (JButton)TestUtilities.getField(panel, "imageChoiceOrChangeButton");
    final JTextField nameTextField = (JTextField)TestUtilities.getField(panel, "nameTextField");
    JComboBox categoryComboBox = (JComboBox)TestUtilities.getField(panel, "categoryComboBox");
    JSpinner widthSpinner = (JSpinner)TestUtilities.getField(panel, "widthSpinner");
    JSpinner heightSpinner = (JSpinner)TestUtilities.getField(panel, "heightSpinner");
   
    // Check current step is image
    tester.waitForIdle();
    assertStepShowing(panel, true, false);   
    WizardPane view = (WizardPane)TestUtilities.findComponent(textureWizardDialog, WizardPane.class);
    // Check wizard view next button is disabled
    final JButton nextFinishOptionButton = (JButton)TestUtilities.getField(view, "nextFinishOptionButton");
    assertFalse("Next button is enabled", nextFinishOptionButton.isEnabled());
   
    // 4. Choose tested image
    String imageChoiceOrChangeButtonText = imageChoiceOrChangeButton.getText();
    tester.invokeAndWait(new Runnable() {
        public void run() {
          imageChoiceOrChangeButton.doClick();
        }
      });
    // Wait 200 ms to let time to Java to load the image
    Thread.sleep(200);
    // Check choice button text changed
    assertFalse("Choice button text didn't change",
        imageChoiceOrChangeButtonText.equals(imageChoiceOrChangeButton.getText()));
    // Click on next button
    tester.invokeAndWait(new Runnable() {
        public void run() {
          nextFinishOptionButton.doClick();
        }
      });
    // Check current step is attributes
    assertStepShowing(panel, false, true);

    // 5. Check default furniture name is the presentation name proposed by content manager
    assertEquals("Wrong default name",
        contentManager.getPresentationName(testedImageName.toString(), ContentManager.ContentType.IMAGE),
        nameTextField.getText());
    // Check name text field has focus
    assertSame("Name text field doesn't have focus", nameTextField,
        KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());   
    // Check default category is user category 
    String userCategoryName = preferences.getLocalizedString(
        ImportedTextureWizardStepsPanel.class, "userCategory");
    assertEquals("Wrong default category", userCategoryName,
        ((TexturesCategory)categoryComboBox.getSelectedItem()).getName());
    // Rename texture 
    final String textureTestName = "#@" + System.currentTimeMillis() + "@#";
    tester.invokeAndWait(new Runnable() {
      public void run() {
        nameTextField.setText(textureTestName);   
      }
    });
    // Check next button is enabled again
    assertTrue("Next button isn't enabled", nextFinishOptionButton.isEnabled());

    // 6. Change width with a value 5 times greater
    float width = (Float)widthSpinner.getValue();
    float height = (Float)heightSpinner.getValue();
    widthSpinner.setValue(width * 5);
    // Check height is 5 times greater
    float newWidth = (Float)widthSpinner.getValue();
    float newHeight = (Float)heightSpinner.getValue();
    assertEquals("width", 5 * width, newWidth);
    assertEquals("height", 5 * height, newHeight);
   
    tester.invokeAndWait(new Runnable() {
        public void run() {
View Full Code Here

Examples of javax.swing.JSpinner

    // 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)
View Full Code Here

Examples of javax.swing.JSpinner

    // 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)
View Full Code Here

Examples of javax.swing.JSpinner

        (JRadioButton)TestUtilities.getField(panel, "topViewRadioButton");
    JRadioButton monochromeRadioButton =
        (JRadioButton)TestUtilities.getField(panel, "monochromeRadioButton");
    JRadioButton floorColorOrTextureRadioButton =
        (JRadioButton)TestUtilities.getField(panel, "floorColorOrTextureRadioButton");
    JSpinner newWallThicknessSpinner =
        (JSpinner)TestUtilities.getField(panel, "newWallThicknessSpinner");
    JSpinner newHomeWallHeightSpinner =
        (JSpinner)TestUtilities.getField(panel, "newWallHeightSpinner");
    // Check panel components value
    assertTrue("Centimeter radio button isn't selected", centimeterRadioButton.isSelected());
    assertFalse("Inch radio button is selected",  inchRadioButton.isSelected());
    assertFalse("Meter radio button is selected", meterRadioButton.isSelected());
    assertFalse("Millimeter radio button is selected", millimeterRadioButton.isSelected());
    assertTrue("Magnestism isn't selected", magnetismCheckBox.isSelected());
    assertTrue("Rulers isn't selected", rulersCheckBox.isSelected());
    assertTrue("Grid isn't selected", gridCheckBox.isSelected());
    assertTrue("Catalog icon radio button isn't selected", catalogIconRadioButton.isSelected());
    assertFalse("Top view button is selected",  topViewRadioButton.isSelected());
    assertTrue("Monochrome radio button isn't selected", monochromeRadioButton.isSelected());
    assertFalse("Floor color radio button is selected",  floorColorOrTextureRadioButton.isSelected());
    assertEquals("Wrong default thickness",
        newWallThicknessSpinner.getValue(), defaultPreferences.getNewWallThickness());
    assertEquals("Wrong default wall height",
        newHomeWallHeightSpinner.getValue(), defaultPreferences.getNewWallHeight());
   
    // 3. Change panel values
    inchRadioButton.setSelected(true);
    magnetismCheckBox.setSelected(false);
    rulersCheckBox.setSelected(false);
    gridCheckBox.setSelected(false);
    topViewRadioButton.setSelected(true);
    floorColorOrTextureRadioButton.setSelected(true);
    newWallThicknessSpinner.setValue(1);
    newHomeWallHeightSpinner.setValue(100);
   
    // 4. Retrieve panel values into preferences
    controller.modifyUserPreferences();
    // Check preferences value
    assertPreferencesEqual(LengthUnit.INCH, false, false, false,
View Full Code Here

Examples of javax.swing.JSpinner

    JDialog furnitureDialog = showHomeFurniturePanel(preferences, controller, tester);
    // Retrieve HomeFurniturePanel components
    HomeFurniturePanel panel = (HomeFurniturePanel)TestUtilities.findComponent(
        furnitureDialog, HomeFurniturePanel.class);
    JTextField nameTextField = (JTextField)TestUtilities.getField(panel, "nameTextField");
    JSpinner xSpinner = (JSpinner)TestUtilities.getField(panel, "xSpinner");
    JSpinner ySpinner = (JSpinner)TestUtilities.getField(panel, "ySpinner");
    assertEquals("Wrong name", piece1.getName(), nameTextField.getText());
    assertEquals("Wrong X", new Float(piece1.getX()), xSpinner.getValue());
    assertNull("Wrong Y", ySpinner.getValue());
    // Edit values
    tester.waitForIdle();
    assertTrue("Name text field doesn't have focus", nameTextField.hasFocus());
    // Check text field is selected when it gains focus
    assertEquals("Name text isn't selected", nameTextField.getText(), nameTextField.getSelectedText());
    tester.actionKeyStroke(KeyEvent.VK_TAB);
    tester.actionKeyStroke(KeyEvent.VK_TAB);
    tester.waitForIdle();
    assertTrue("X field doesn't have focus", ((DefaultEditor)xSpinner.getEditor()).getTextField().hasFocus());
    tester.actionKeyStroke(KeyEvent.VK_TAB);
    tester.waitForIdle();
    JFormattedTextField ySpinnerTextField = ((DefaultEditor)ySpinner.getEditor()).getTextField();
    assertTrue("Y field doesn't have focus", ySpinnerTextField.hasFocus());
    // Test if numbers greater than 10000 are correctly handled
    tester.actionKeyString("10020");
    tester.actionKeyStroke(KeyEvent.VK_TAB);
    tester.waitForIdle();
    assertFalse("Y field still has focus", ySpinnerTextField.hasFocus());
    assertEquals("Wrong Y", new Float(10020), ySpinner.getValue());
    tester.actionKeyPress(KeyEvent.VK_SHIFT);
    tester.actionKeyStroke(KeyEvent.VK_TAB);
    tester.actionKeyRelease(KeyEvent.VK_SHIFT);
    tester.waitForIdle();
    assertTrue("Y field doesn't have focus", ySpinnerTextField.hasFocus());
View Full Code Here

Examples of javax.swing.JSpinner

    final JButton turnDownButton = (JButton)TestUtilities.getField(panel, "turnDownButton");
    JCheckBox backFaceShownCheckBox = (JCheckBox)TestUtilities.getField(panel, "backFaceShownCheckBox");
    final JTextField nameTextField = (JTextField)TestUtilities.getField(panel, "nameTextField");
    final JCheckBox addToCatalogCheckBox = (JCheckBox)TestUtilities.getField(panel, "addToCatalogCheckBox");
    final JComboBox categoryComboBox = (JComboBox)TestUtilities.getField(panel, "categoryComboBox");
    final JSpinner widthSpinner = (JSpinner)TestUtilities.getField(panel, "widthSpinner");
    JSpinner heightSpinner = (JSpinner)TestUtilities.getField(panel, "heightSpinner");
    JSpinner depthSpinner = (JSpinner)TestUtilities.getField(panel, "depthSpinner");
    final JCheckBox keepProportionsCheckBox = (JCheckBox)TestUtilities.getField(panel, "keepProportionsCheckBox");
    JSpinner elevationSpinner = (JSpinner)TestUtilities.getField(panel, "elevationSpinner");
    JCheckBox movableCheckBox = (JCheckBox)TestUtilities.getField(panel, "movableCheckBox");
    JCheckBox doorOrWindowCheckBox = (JCheckBox)TestUtilities.getField(panel, "doorOrWindowCheckBox");
    ColorButton colorButton = (ColorButton)TestUtilities.getField(panel, "colorButton");
    final JButton clearColorButton = (JButton)TestUtilities.getField(panel, "clearColorButton");
   
    // Check current step is model
    tester.waitForIdle();
    assertStepShowing(panel, true, false, false, false);   
   
    // 3. Choose tested model
    String modelChoiceOrChangeButtonText = modelChoiceOrChangeButton.getText();
    tester.invokeAndWait(new Runnable() {
        public void run() {
          modelChoiceOrChangeButton.doClick();
        }
      });
    // Wait 1 s to let time to Java 3D to load the model
    Thread.sleep(1000);
    // Check choice button text changed
    assertFalse("Choice button text didn't change",
        modelChoiceOrChangeButtonText.equals(modelChoiceOrChangeButton.getText()));
    // Click on next button
    WizardPane view = (WizardPane)TestUtilities.findComponent(frame, WizardPane.class);
    // Retrieve wizard view next button
    final JButton nextFinishOptionButton = (JButton)TestUtilities.getField(view, "nextFinishOptionButton");
    assertTrue("Next button isn't enabled", nextFinishOptionButton.isEnabled());   
    tester.invokeAndWait(new Runnable() {
        public void run() {
          nextFinishOptionButton.doClick();
        }
      });
    // Check current step is rotation
    assertStepShowing(panel, false, true, false, false);   
    // Check back face shown check box isn't selected by default
    assertFalse("Back face shown check box is selected", backFaceShownCheckBox.isSelected());
   
    // 4. Click on left button
    float width = (Float)widthSpinner.getValue();
    float depth = (Float)depthSpinner.getValue();
    float height = (Float)heightSpinner.getValue();
    tester.invokeAndWait(new Runnable() {
        public void run() {
          turnLeftButton.doClick();
        }
      });
    // Check depth and width values were swapped
    float newWidth = (Float)widthSpinner.getValue();
    float newDepth = (Float)depthSpinner.getValue();
    float newHeight = (Float)heightSpinner.getValue();
    TestUtilities.assertEqualsWithinEpsilon("Incorrect width", depth, newWidth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect depth", width, newDepth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect height", height, newHeight, 1E-3f);
    // Click on down button
    width = newWidth;
    depth = newDepth;
    height = newHeight;
    tester.invokeAndWait(new Runnable() {
        public void run() {
          turnDownButton.doClick();
        }
      });
    // Check height and depth values were swapped
    newWidth = (Float)widthSpinner.getValue();
    newDepth = (Float)depthSpinner.getValue();
    newHeight = (Float)heightSpinner.getValue();
    TestUtilities.assertEqualsWithinEpsilon("Incorrect width", width, newWidth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect depth", height, newDepth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect height", depth, newHeight, 1E-3f);
   
    // 5. Click on next button
    assertTrue("Next button isn't enabled", nextFinishOptionButton.isEnabled());
    tester.invokeAndWait(new Runnable() {
        public void run() {
          nextFinishOptionButton.doClick();
        }
      });
    // Check current step is attributes
    assertStepShowing(panel, false, false, true, false);   
       
    // 6. Check default furniture name is the presentation name proposed by content manager
    assertEquals("Wrong default name"
        contentManager.getPresentationName(testedModelName.toString(), ContentManager.ContentType.MODEL),
        nameTextField.getText());
    // Check Add to catalog check box isn't selected and category combo box
    // is disabled when furniture is imported in home
    assertFalse("Add to catalog check box is selected", addToCatalogCheckBox.isSelected());
    assertFalse("Category combo box isn't disabled", categoryComboBox.isEnabled());
    // Check default category is first category 
    final FurnitureCategory firstCategory = preferences.getFurnitureCatalog().getCategories().get(0);
    assertEquals("Wrong default category", firstCategory, categoryComboBox.getSelectedItem());
    // Rename furniture with the name of the catalog first piece
    tester.invokeAndWait(new Runnable() {
        public void run() {
          nameTextField.setText(firstCategory.getFurniture().get(0).getName());
        }
      });
    // Check next button is enabled
    assertTrue("Next button isn't enabled", nextFinishOptionButton.isEnabled());
    // Select Add to catalog check box
    tester.invokeAndWait(new Runnable() {
        public void run() {
          addToCatalogCheckBox.setSelected(true);
        }
      });
    // Check next button is disabled because imported furniture has a wrong name
    assertFalse("Next button isn't disabled", nextFinishOptionButton.isEnabled());
    // Rename furniture and its category
    final String pieceTestName = "#@" + System.currentTimeMillis() + "@#";
    final String categoryTestName = "sdfghjkl";
    tester.invokeAndWait(new Runnable() {
        public void run() {
          nameTextField.setText(pieceTestName);
          categoryComboBox.getEditor().selectAll();
        }
      });
    tester.actionKeyString(categoryComboBox.getEditor().getEditorComponent(), categoryTestName);   
    // Check next button is enabled again
    assertTrue("Next button isn't enabled", nextFinishOptionButton.isEnabled());
   
    // 7. Check keep proportions check box is selected by default
    assertTrue("Keep proportions check box isn't selected", keepProportionsCheckBox.isSelected());
    // Change width with a value 10 times greater
    width = newWidth;
    depth = newDepth;
    height = newHeight;
    final float enteredWidth = newWidth * 10;
    tester.invokeAndWait(new Runnable() {
        public void run() {
          widthSpinner.setValue(enteredWidth);
        }
      });
    // Check height and depth values are 10 times greater
    newWidth = (Float)widthSpinner.getValue();
    newDepth = (Float)depthSpinner.getValue();
    newHeight = (Float)heightSpinner.getValue();
    TestUtilities.assertEqualsWithinEpsilon("Incorrect width", 10 * width, newWidth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect depth", 10 * depth, newDepth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect height", 10 * height, newHeight, 1E-3f);
    // Deselect keep proportions check box
    tester.invokeAndWait(new Runnable() {
        public void run() {
          keepProportionsCheckBox.setSelected(false);
        }
      });      
    // Change width with a value 2 times greater
    width = newWidth;
    depth = newDepth;
    height = newHeight;
    final float twiceValue = newWidth * 2;
    tester.invokeAndWait(new Runnable() {
        public void run() {
          widthSpinner.setValue(twiceValue);
        }
      });
    // Check height and depth values didn't change
    newWidth = (Float)widthSpinner.getValue();
    newDepth = (Float)depthSpinner.getValue();
    newHeight = (Float)heightSpinner.getValue();
    TestUtilities.assertEqualsWithinEpsilon("Incorrect width", 2 * width, newWidth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect depth", depth, newDepth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect height", height, newHeight, 1E-3f);

    // 8. Change elevation, movable, door or window, color default values
    assertEquals("Wrong default elevation", 0f, (Float)elevationSpinner.getValue());
    elevationSpinner.setValue(10);
    assertTrue("Movable check box isn't selected", movableCheckBox.isSelected());
    movableCheckBox.setSelected(false);
    assertFalse("Door or window check box is selected", doorOrWindowCheckBox.isSelected());
    doorOrWindowCheckBox.setSelected(true);
    assertEquals("Wrong default color", null, colorButton.getColor());
View Full Code Here

Examples of javax.swing.JSpinner

    // Create X label and its spinner bound to X controller property
    this.xLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
        CompassPanel.class, "xLabel.text", unitName));
    final NullableSpinner.NullableSpinnerLengthModel xSpinnerModel =
        new NullableSpinner.NullableSpinnerLengthModel(preferences, -100000f, 100000f);
    this.xSpinner = new JSpinner(xSpinnerModel);
    xSpinnerModel.setLength(controller.getX());
    final PropertyChangeListener xChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          xSpinnerModel.setLength((Float)ev.getNewValue());
        }
      };
    controller.addPropertyChangeListener(CompassController.Property.X, xChangeListener);
    xSpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(CompassController.Property.X, xChangeListener);
          controller.setX(xSpinnerModel.getLength());
          controller.addPropertyChangeListener(CompassController.Property.X, xChangeListener);
        }
      });
   
    // Create Y label and its spinner bound to Y controller property
    this.yLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
        CompassPanel.class, "yLabel.text", unitName));
    final NullableSpinner.NullableSpinnerLengthModel ySpinnerModel =
        new NullableSpinner.NullableSpinnerLengthModel(preferences, -100000f, 100000f);
    this.ySpinner = new NullableSpinner(ySpinnerModel);
    ySpinnerModel.setLength(controller.getY());
    final PropertyChangeListener yChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          ySpinnerModel.setLength((Float)ev.getNewValue());
        }
      };
    controller.addPropertyChangeListener(CompassController.Property.Y, yChangeListener);
    ySpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(CompassController.Property.Y, yChangeListener);
          controller.setY(ySpinnerModel.getLength());
          controller.addPropertyChangeListener(CompassController.Property.Y, yChangeListener);
        }
      });
   
    // Create diameter label and its spinner bound to DIAMETER controller property
    this.diameterLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
        CompassPanel.class, "diameterLabel.text", unitName));
    final NullableSpinner.NullableSpinnerLengthModel diameterSpinnerModel =
        new NullableSpinner.NullableSpinnerLengthModel(preferences, 0.1f, 2500f);
    this.diameterSpinner = new NullableSpinner(diameterSpinnerModel);
    diameterSpinnerModel.setLength(controller.getDiameter());
    final PropertyChangeListener diameterChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          diameterSpinnerModel.setLength((Float)ev.getNewValue());
        }
      };
    controller.addPropertyChangeListener(CompassController.Property.DIAMETER,
        diameterChangeListener);
    diameterSpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(CompassController.Property.DIAMETER,
              diameterChangeListener);
          controller.setDiameter(diameterSpinnerModel.getLength());
          controller.addPropertyChangeListener(CompassController.Property.DIAMETER,
              diameterChangeListener);
        }
      });
   
    // Create visible check box bound to VISIBLE controller property
    this.visibleCheckBox = new JCheckBox(SwingTools.getLocalizedLabelText(preferences,
        CompassPanel.class, "visibleCheckBox.text"));
    this.visibleCheckBox.setSelected(controller.isVisible());
    final PropertyChangeListener visibleChangeListener = new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent ev) {
        visibleCheckBox.setSelected((Boolean)ev.getNewValue());
      }
    };
    controller.addPropertyChangeListener(CompassController.Property.VISIBLE, visibleChangeListener);
    this.visibleCheckBox.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(CompassController.Property.VISIBLE, visibleChangeListener);
          controller.setVisible(visibleCheckBox.isSelected());
          controller.addPropertyChangeListener(CompassController.Property.VISIBLE, visibleChangeListener);
        }
      });

    this.latitudeLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences, CompassPanel.class, "latitudeLabel.text"));
    final SpinnerNumberModel latitudeSpinnerModel = new SpinnerNumberModel(new Float(0), new Float(-90), new Float(90), new Float(5));
    this.latitudeSpinner = new JSpinner(latitudeSpinnerModel);
    // Change positive / negative notation by North / South
    JFormattedTextField textField = ((DefaultEditor)this.latitudeSpinner.getEditor()).getTextField();
    NumberFormatter numberFormatter = (NumberFormatter)((DefaultFormatterFactory)textField.getFormatterFactory()).getDefaultFormatter();
    numberFormatter.setFormat(new DecimalFormat("N ##0.000;S ##0.000"));
    textField.setFormatterFactory(new DefaultFormatterFactory(numberFormatter));
    SwingTools.addAutoSelectionOnFocusGain(textField);
    latitudeSpinnerModel.setValue(controller.getLatitudeInDegrees());
    final PropertyChangeListener latitudeChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          latitudeSpinnerModel.setValue((Float)ev.getNewValue());
        }
      };
    controller.addPropertyChangeListener(CompassController.Property.LATITUDE_IN_DEGREES, latitudeChangeListener);
    latitudeSpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(CompassController.Property.LATITUDE_IN_DEGREES, latitudeChangeListener);
          controller.setLatitudeInDegrees(((Number)latitudeSpinnerModel.getValue()).floatValue());
          controller.addPropertyChangeListener(CompassController.Property.LATITUDE_IN_DEGREES, latitudeChangeListener);
        }
      });
   
    this.longitudeLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences, CompassPanel.class, "longitudeLabel.text"));
    final SpinnerNumberModel longitudeSpinnerModel = new SpinnerNumberModel(new Float(0), new Float(-180), new Float(180), new Float(5));
    this.longitudeSpinner = new JSpinner(longitudeSpinnerModel);
    // Change positive / negative notation by East / West
    textField = ((DefaultEditor)this.longitudeSpinner.getEditor()).getTextField();
    numberFormatter = (NumberFormatter)((DefaultFormatterFactory)textField.getFormatterFactory()).getDefaultFormatter();
    numberFormatter.setFormat(new DecimalFormat("E ##0.000;W ##0.000"));
    textField.setFormatterFactory(new DefaultFormatterFactory(numberFormatter));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.