/** Tests that trigger is called after the value is changed */ public void testValueChange() { final MyProperties props = new MyProperties(); String path = "test.mondrian.properties.change.value"; BooleanProperty boolProp = new BooleanProperty(props, path, false); assertTrue("Check property value NOT false", !boolProp.get()); // set via the 'set' method final boolean prevBoolean = boolProp.set(true); assertEquals(false, prevBoolean); // now explicitly set the property final Object prevObject = props.setProperty(path, "false"); assertEquals("true", prevObject); String v = props.getProperty(path); assertTrue("Check property value is null", v != null); assertTrue("Check property value is true", (!Boolean.valueOf(v).booleanValue())); final State state = new State(); state.triggerCalled = false; state.triggerValue = null; final Trigger trigger = new Trigger() { public boolean isPersistent() { return false; } public int phase() { return Trigger.PRIMARY_PHASE; } public void execute(Property property, String value) { state.triggerCalled = true; state.triggerValue = value; } }; boolProp.addTrigger(trigger); String falseStr = "false"; props.setProperty(path, falseStr); assertTrue("Check trigger was called", !state.triggerCalled); String trueStr = "true"; props.setProperty(path, trueStr); assertTrue("Check trigger was NOT called", state.triggerCalled); assertTrue("Check trigger value was null", (state.triggerValue != null)); assertTrue("Check trigger value is NOT correct", state.triggerValue.equals(trueStr)); }
/** * Returns the main control panel. * * @param mainFrame The main test frame. * @param mainTabbedPane The main tabbed pane. * @param mainTabPreviewPainter The preview painter of the main tabbed pane. * @param toolbar The toolbar of the main test frame. * @return The main control panel. */ public static JPanel getMainControlPanel( final JFrame mainFrame, final JTabbedPane mainTabbedPane, final MyMainTabPreviewPainter mainTabPreviewPainter, final JToolBar toolbar) { FormLayout lm = new FormLayout("right:pref, 4dlu, fill:pref:grow", ""); DefaultFormBuilder builder = new DefaultFormBuilder(lm); // builder.setDefaultDialogBorder(); builder.appendSeparator("Title pane settings"); final JCheckBox markAsModified = new JCheckBox("Marked modified"); markAsModified.setOpaque(false); markAsModified.setSelected(false); markAsModified.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { mainFrame .getRootPane() .putClientProperty( SubstanceLookAndFeel.WINDOW_MODIFIED, (markAsModified.isSelected() ? Boolean.TRUE : false)); } }); builder.append("Modified", markAsModified); final JCheckBox heapPanel = new JCheckBox("Has heap panel"); heapPanel.setOpaque(false); heapPanel.setSelected(false); heapPanel.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SubstanceLookAndFeel.setWidgetVisible( mainFrame.getRootPane(), heapPanel.isSelected(), SubstanceWidgetType.TITLE_PANE_HEAP_STATUS); } }); builder.append("Heap panel", heapPanel); JButton changeTitleButton = new JButton("Change"); changeTitleButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String random = "abcdefghijklmnopqrstuvwxyz "; int length = 60 + (int) (150 * Math.random()); String title = ""; while (length > 0) { title += random.charAt((int) (random.length() * Math.random())); length--; } mainFrame.setTitle(title); } }); builder.append("Title string", changeTitleButton); builder.appendSeparator("Miscellaneous"); final JCheckBox defaultRoundedCorners = new JCheckBox("by default"); defaultRoundedCorners.setOpaque(false); boolean roundable = Boolean.valueOf( System.getProperty(SubstanceLookAndFeel.WINDOW_ROUNDED_CORNERS_PROPERTY, "True")); defaultRoundedCorners.setSelected(roundable); defaultRoundedCorners.setEnabled(roundable); defaultRoundedCorners.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { UIManager.put( SubstanceLookAndFeel.WINDOW_ROUNDED_CORNERS, defaultRoundedCorners.isSelected()); } }); builder.append("Rounded Windows", defaultRoundedCorners); final JCheckBox useThemedDefaultIconsCheckBox = new JCheckBox("use themed icons"); useThemedDefaultIconsCheckBox.setOpaque(false); useThemedDefaultIconsCheckBox.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { UIManager.put( SubstanceLookAndFeel.USE_THEMED_DEFAULT_ICONS, useThemedDefaultIconsCheckBox.isSelected() ? Boolean.TRUE : null); mainFrame.repaint(); } }); } }); builder.append("Themed icons", useThemedDefaultIconsCheckBox); final JCheckBox useConstantThemesOnDialogs = new JCheckBox("use constant themes"); useConstantThemesOnDialogs.setOpaque(false); useConstantThemesOnDialogs.setSelected(SubstanceLookAndFeel.isToUseConstantThemesOnDialogs()); useConstantThemesOnDialogs.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { SubstanceLookAndFeel.setToUseConstantThemesOnDialogs( useConstantThemesOnDialogs.isSelected()); SubstanceLookAndFeel.setSkin( SubstanceLookAndFeel.getCurrentSkin(mainFrame.getRootPane())); } }); } }); builder.append("Option pane icons", useConstantThemesOnDialogs); final JComboBox placementCombo = new JComboBox(new Object[] {"top", "bottom", "left", "right"}); placementCombo.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String selected = (String) placementCombo.getSelectedItem(); if ("top".equals(selected)) mainTabbedPane.setTabPlacement(JTabbedPane.TOP); if ("bottom".equals(selected)) mainTabbedPane.setTabPlacement(JTabbedPane.BOTTOM); if ("left".equals(selected)) mainTabbedPane.setTabPlacement(JTabbedPane.LEFT); if ("right".equals(selected)) mainTabbedPane.setTabPlacement(JTabbedPane.RIGHT); } }); builder.append("Placement", placementCombo); try { final JComboBox overviewKindCombo = new FlexiComboBox<TabOverviewKind>( TabOverviewKind.GRID, TabOverviewKind.MENU_CAROUSEL, TabOverviewKind.ROUND_CAROUSEL) { @Override public String getCaption(TabOverviewKind item) { return item.getName(); } }; overviewKindCombo.setSelectedItem( LafWidgetUtilities2.getTabPreviewPainter(mainTabbedPane).getOverviewKind(mainTabbedPane)); overviewKindCombo.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { mainTabPreviewPainter.setTabOverviewKind( (TabOverviewKind) overviewKindCombo.getSelectedItem()); } }); builder.append("Overview kind", overviewKindCombo); } catch (NoClassDefFoundError ignored) { } final JComboBox menuGutterFillCombo = new FlexiComboBox<MenuGutterFillKind>( MenuGutterFillKind.NONE, MenuGutterFillKind.SOFT, MenuGutterFillKind.HARD, MenuGutterFillKind.SOFT_FILL, MenuGutterFillKind.HARD_FILL) { @Override public String getCaption(MenuGutterFillKind item) { return item.name(); } }; menuGutterFillCombo.setSelectedItem(MenuGutterFillKind.HARD); menuGutterFillCombo.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { UIManager.put( SubstanceLookAndFeel.MENU_GUTTER_FILL_KIND, menuGutterFillCombo.getSelectedItem()); } }); builder.append("Menu fill", menuGutterFillCombo); final JComboBox focusKindCombo = new FlexiComboBox<FocusKind>(FocusKind.values()) { @Override public String getCaption(FocusKind item) { return item.name(); } }; focusKindCombo.setSelectedItem(FocusKind.ALL_INNER); focusKindCombo.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { UIManager.put(SubstanceLookAndFeel.FOCUS_KIND, focusKindCombo.getSelectedItem()); } }); builder.append("Focus kind", focusKindCombo); JButton buttonGlassPane = new JButton("Show"); buttonGlassPane.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JPanel glassPane = new JPanel() { @Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D graphics = (Graphics2D) g; int height = getHeight(); int width = getWidth(); Composite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) 0.4); graphics.setComposite(c); for (int i = 0; i < height; i++) { Color color = (i % 2 == 0) ? new Color(200, 200, 255) : new Color(230, 230, 255); graphics.setColor(color); graphics.drawLine(0, i, width, i); } Composite c2 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) 1.0); graphics.setComposite(c2); } }; glassPane.setOpaque(false); glassPane.addMouseListener(new MouseAdapter() {}); glassPane.addKeyListener(new KeyAdapter() {}); mainFrame.setGlassPane(glassPane); new Thread() { @Override public void run() { glassPane.setVisible(true); try { Thread.sleep(5000); } catch (InterruptedException ie) { ie.printStackTrace(); } glassPane.setVisible(false); } }.start(); } }); builder.append("Glass pane", buttonGlassPane); builder.appendSeparator("Custom animations"); final JCheckBox allowFocusLoopAnimations = new JCheckBox("Allow animation"); allowFocusLoopAnimations.setOpaque(false); allowFocusLoopAnimations.setSelected( AnimationConfigurationManager.getInstance() .isAnimationAllowed(AnimationFacet.FOCUS_LOOP_ANIMATION, null)); allowFocusLoopAnimations.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (allowFocusLoopAnimations.isSelected()) { AnimationConfigurationManager.getInstance() .allowAnimations(AnimationFacet.FOCUS_LOOP_ANIMATION); } else { AnimationConfigurationManager.getInstance() .disallowAnimations(AnimationFacet.FOCUS_LOOP_ANIMATION); } } }); builder.append("Focus loop", allowFocusLoopAnimations); final JCheckBox allowGlowIconAnimations = new JCheckBox("Allow animation"); allowGlowIconAnimations.setOpaque(false); allowGlowIconAnimations.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (allowGlowIconAnimations.isSelected()) { AnimationConfigurationManager.getInstance().allowAnimations(AnimationFacet.ICON_GLOW); } else { AnimationConfigurationManager.getInstance() .disallowAnimations(AnimationFacet.ICON_GLOW); } } }); builder.append("Icon glow", allowGlowIconAnimations); final JCheckBox allowGhostIconAnimations = new JCheckBox("Allow animation"); allowGhostIconAnimations.setOpaque(false); allowGhostIconAnimations.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (allowGhostIconAnimations.isSelected()) { AnimationConfigurationManager.getInstance() .allowAnimations(AnimationFacet.GHOSTING_ICON_ROLLOVER); } else { AnimationConfigurationManager.getInstance() .disallowAnimations(AnimationFacet.GHOSTING_ICON_ROLLOVER); } } }); builder.append("Icon rollover", allowGhostIconAnimations); final JCheckBox allowGhostPressAnimations = new JCheckBox("Allow animation"); allowGhostPressAnimations.setOpaque(false); allowGhostPressAnimations.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (allowGhostPressAnimations.isSelected()) { AnimationConfigurationManager.getInstance() .allowAnimations(AnimationFacet.GHOSTING_BUTTON_PRESS); } else { AnimationConfigurationManager.getInstance() .disallowAnimations(AnimationFacet.GHOSTING_BUTTON_PRESS); } } }); builder.append("Button press", allowGhostPressAnimations); builder.appendSeparator("Toolbar"); final JCheckBox isToolbarFlat = new JCheckBox("Is flat"); isToolbarFlat.setOpaque(false); isToolbarFlat.setSelected(true); isToolbarFlat.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { toolbar.putClientProperty( SubstanceLookAndFeel.FLAT_PROPERTY, isToolbarFlat.isSelected()); toolbar.repaint(); } }); builder.append("Flat", isToolbarFlat); builder.appendSeparator("Menu bar"); final JCheckBox menuSearch = new JCheckBox("Has menu search"); menuSearch.setOpaque(false); menuSearch.setSelected(false); menuSearch.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SubstanceLookAndFeel.setWidgetVisible( mainFrame.getRootPane(), menuSearch.isSelected(), SubstanceWidgetType.MENU_SEARCH); } }); builder.append("Menu search", menuSearch); final JCheckBox menuLocale = new JCheckBox("Has custom locale"); menuLocale.setOpaque(false); menuLocale.setSelected(false); menuLocale.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (menuLocale.isSelected()) { mainFrame.getJMenuBar().setLocale(Locale.FRENCH); mainFrame .getJMenuBar() .putClientProperty(LafWidget.IGNORE_GLOBAL_LOCALE, Boolean.TRUE); } else { mainFrame.getJMenuBar().putClientProperty(LafWidget.IGNORE_GLOBAL_LOCALE, null); } } }); builder.append("Menu locale", menuLocale); JPanel result = builder.getPanel(); result.setName("Main control panel"); return result; }
/** Checks that triggers are called in the correct order. */ public void testTriggerCallOrder() { final MyProperties props = new MyProperties(); String path = "test.mondrian.properties.call.order"; BooleanProperty boolProp = new BooleanProperty(props, path, false); final State2 state = new State2(); state.callCounter = 0; // now explicitly set the property props.setProperty(path, "false"); String v = props.getProperty(path); assertTrue("Check property value is null", (v != null)); assertTrue("Check property value is true", (!Boolean.valueOf(v).booleanValue())); // primaryOne Trigger primaryOneTrigger = new Trigger() { public boolean isPersistent() { return false; } public int phase() { return Trigger.PRIMARY_PHASE; } public void execute(Property property, String value) { state.primaryOne = state.callCounter++; } }; boolProp.addTrigger(primaryOneTrigger); // secondaryOne Trigger secondaryOneTrigger = new Trigger() { public boolean isPersistent() { return false; } public int phase() { return Trigger.SECONDARY_PHASE; } public void execute(Property property, String value) { state.secondaryOne = state.callCounter++; } }; boolProp.addTrigger(secondaryOneTrigger); // tertiaryOne Trigger tertiaryOneTrigger = new Trigger() { public boolean isPersistent() { return false; } public int phase() { return Trigger.TERTIARY_PHASE; } public void execute(Property property, String value) { state.tertiaryOne = state.callCounter++; } }; boolProp.addTrigger(tertiaryOneTrigger); // tertiaryTwo Trigger tertiaryTwoTrigger = new Trigger() { public boolean isPersistent() { return false; } public int phase() { return Trigger.TERTIARY_PHASE; } public void execute(Property property, String value) { state.tertiaryTwo = state.callCounter++; } }; boolProp.addTrigger(tertiaryTwoTrigger); // secondaryTwo Trigger secondaryTwoTrigger = new Trigger() { public boolean isPersistent() { return false; } public int phase() { return Trigger.SECONDARY_PHASE; } public void execute(Property property, String value) { state.secondaryTwo = state.callCounter++; } }; boolProp.addTrigger(secondaryTwoTrigger); // primaryTwo Trigger primaryTwoTrigger = new Trigger() { public boolean isPersistent() { return false; } public int phase() { return Trigger.PRIMARY_PHASE; } public void execute(Property property, String value) { state.primaryTwo = state.callCounter++; } }; boolProp.addTrigger(primaryTwoTrigger); String falseStr = "false"; props.setProperty(path, falseStr); assertTrue("Check trigger was called", (state.callCounter == 0)); String trueStr = "true"; props.setProperty(path, trueStr); assertTrue("Check trigger was NOT called", (state.callCounter != 0)); assertTrue("Check triggers was NOT called correct number of times", (state.callCounter == 6)); // now make sure that primary are called before secondary which are // before tertiary assertTrue("Check primaryOne > secondaryOne", (state.primaryOne < state.secondaryOne)); assertTrue("Check primaryOne > secondaryTwo", (state.primaryOne < state.secondaryTwo)); assertTrue("Check primaryOne > tertiaryOne", (state.primaryOne < state.tertiaryOne)); assertTrue("Check primaryOne > tertiaryTwo", (state.primaryOne < state.tertiaryTwo)); assertTrue("Check primaryTwo > secondaryOne", (state.primaryTwo < state.secondaryOne)); assertTrue("Check primaryTwo > secondaryTwo", (state.primaryTwo < state.secondaryTwo)); assertTrue("Check primaryTwo > tertiaryOne", (state.primaryTwo < state.tertiaryOne)); assertTrue("Check primaryTwo > tertiaryTwo", (state.primaryTwo < state.tertiaryTwo)); assertTrue("Check secondaryOne > tertiaryOne", (state.secondaryOne < state.tertiaryOne)); assertTrue("Check secondaryOne > tertiaryTwo", (state.secondaryOne < state.tertiaryTwo)); assertTrue("Check secondaryTwo > tertiaryOne", (state.secondaryTwo < state.tertiaryOne)); assertTrue("Check secondaryTwo > tertiaryTwo", (state.secondaryTwo < state.tertiaryTwo)); // remove some of the triggers boolProp.removeTrigger(primaryTwoTrigger); boolProp.removeTrigger(secondaryTwoTrigger); boolProp.removeTrigger(tertiaryTwoTrigger); // reset state.callCounter = 0; state.primaryOne = 0; state.primaryTwo = 0; state.secondaryOne = 0; state.secondaryTwo = 0; state.tertiaryOne = 0; state.tertiaryTwo = 0; props.setProperty(path, falseStr); assertTrue("Check trigger was NOT called", (state.callCounter != 0)); assertTrue("Check triggers was NOT called correct number of times", (state.callCounter == 3)); // now make sure that primary are called before secondary which are // before tertiary assertTrue("Check primaryOne > secondaryOne", (state.primaryOne < state.secondaryOne)); assertTrue("Check primaryOne > tertiaryOne", (state.primaryOne < state.tertiaryOne)); assertTrue("Check secondaryOne > tertiaryOne", (state.secondaryOne < state.tertiaryOne)); }