protected final void showProgress(String message) { myProgressMessage.setText(message); if (myProgressPanel.getParent() == null) { myGlassLayer.setEnabled(false); myProgressIcon.resume(); myLayeredPane.add(myProgressPanel, LAYER_PROGRESS); myLayeredPane.repaint(); } }
private void createDesignerCard() { myLayeredPane = new MyLayeredPane(); mySurfaceArea = new ComponentEditableArea(myLayeredPane) { @Override protected void fireSelectionChanged() { super.fireSelectionChanged(); myLayeredPane.revalidate(); myLayeredPane.repaint(); } @Override public RadComponent findTarget(int x, int y, @Nullable ComponentTargetFilter filter) { if (myRootComponent != null) { FindComponentVisitor visitor = new FindComponentVisitor(myLayeredPane, filter, x, y); myRootComponent.accept(visitor, false); return visitor.getResult(); } return null; } @Override public InputTool findTargetTool(int x, int y) { return myDecorationLayer.findTargetTool(x, y); } @Override public void showSelection(boolean value) { myDecorationLayer.showSelection(value); } @Override public ComponentDecorator getRootSelectionDecorator() { return DesignerEditorPanel.this.getRootSelectionDecorator(); } @Nullable public EditOperation processRootOperation(OperationContext context) { return DesignerEditorPanel.this.processRootOperation(context); } @Override public FeedbackLayer getFeedbackLayer() { return myFeedbackLayer; } @Override public RadComponent getRootComponent() { return myRootComponent; } }; myPaletteListener = new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (DesignerToolWindowManager.getInstance(getProject()).getActiveDesigner() == DesignerEditorPanel.this) { Item paletteItem = (Item) PaletteManager.getInstance(getProject()).getActiveItem(); if (paletteItem != null) { myToolProvider.setActiveTool( new CreationTool(true, createCreationFactory(paletteItem))); } else if (myToolProvider.getActiveTool() instanceof CreationTool) { myToolProvider.loadDefaultTool(); } } } }; myToolProvider = new ToolProvider() { @Override public void loadDefaultTool() { setActiveTool(new SelectionTool()); } @Override public void setActiveTool(InputTool tool) { if (getActiveTool() instanceof CreationTool && !(tool instanceof CreationTool)) { PaletteManager.getInstance(getProject()).clearActiveItem(); } super.setActiveTool(tool); } @Override public boolean execute( final ThrowableRunnable<Exception> operation, String command, final boolean updateProperties) { final boolean[] is = {true}; CommandProcessor.getInstance() .executeCommand( getProject(), new Runnable() { public void run() { is[0] = DesignerEditorPanel.this.execute(operation, updateProperties); } }, command, null); return is[0]; } @Override public void execute(final List<EditOperation> operations, String command) { CommandProcessor.getInstance() .executeCommand( getProject(), new Runnable() { public void run() { DesignerEditorPanel.this.execute(operations); } }, command, null); } @Override public void showError(@NonNls String message, Throwable e) { DesignerEditorPanel.this.showError(message, e); } }; myGlassLayer = new GlassLayer(myToolProvider, mySurfaceArea); myLayeredPane.add(myGlassLayer, LAYER_GLASS); myDecorationLayer = new DecorationLayer(mySurfaceArea); myLayeredPane.add(myDecorationLayer, LAYER_DECORATION); myFeedbackLayer = new FeedbackLayer(); myLayeredPane.add(myFeedbackLayer, LAYER_FEEDBACK); JPanel content = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 1; gbc.fill = GridBagConstraints.VERTICAL; myVerticalCaption = new CaptionPanel(this, false); content.add(myVerticalCaption, gbc); gbc.gridx = 1; gbc.gridy = 0; gbc.fill = GridBagConstraints.HORIZONTAL; myHorizontalCaption = new CaptionPanel(this, true); content.add(myHorizontalCaption, gbc); gbc.gridx = 1; gbc.gridy = 1; gbc.weightx = 1; gbc.weighty = 1; gbc.fill = GridBagConstraints.BOTH; myScrollPane = ScrollPaneFactory.createScrollPane(myLayeredPane); myScrollPane.setBackground(Color.WHITE); content.add(myScrollPane, gbc); myHorizontalCaption.attachToScrollPane(myScrollPane); myVerticalCaption.attachToScrollPane(myScrollPane); myActionPanel = new DesignerActionPanel(this, myGlassLayer); myDesignerCard = new JPanel(new FillLayout()); myDesignerCard.add(myActionPanel.getToolbarComponent()); myDesignerCard.add(content); add(myDesignerCard, DESIGNER_CARD); PaletteManager.getInstance(getProject()).addSelectionListener(myPaletteListener); mySourceSelectionListener = new ComponentSelectionListener() { @Override public void selectionChanged(EditableArea area) { storeSourceSelectionState(); } }; mySurfaceArea.addSelectionListener(mySourceSelectionListener); }
/** Initializes the layout and the ribbon. */ private void initRibbon() { this.setLayout(new RibbonFrameLayout()); this.ribbon = new JRibbon(this); this.add(this.ribbon, BorderLayout.NORTH); // this.keyTipManager = new KeyTipManager(this); Toolkit.getDefaultToolkit() .addAWTEventListener( new AWTEventListener() { private boolean prevAltModif = false; @Override public void eventDispatched(AWTEvent event) { Object src = event.getSource(); if (src instanceof Component) { Component c = (Component) src; if ((c == JRibbonFrame.this) || (SwingUtilities.getWindowAncestor(c) == JRibbonFrame.this)) { if (event instanceof KeyEvent) { KeyEvent keyEvent = (KeyEvent) event; // System.out.println(keyEvent.getID() + ":" // + keyEvent.getKeyCode()); switch (keyEvent.getID()) { case KeyEvent.KEY_PRESSED: // if (keyEvent.getKeyCode() == // KeyEvent.VK_ESCAPE) { // keyTipManager.showPreviousChain(); // } break; case KeyEvent.KEY_RELEASED: boolean wasAltModif = prevAltModif; prevAltModif = keyEvent.getModifiersEx() == InputEvent.ALT_DOWN_MASK; if (wasAltModif && keyEvent.getKeyCode() == KeyEvent.VK_ALT) break; char keyChar = keyEvent.getKeyChar(); if (Character.isLetter(keyChar) || Character.isDigit(keyChar)) { // System.out.println("Will handle key press " // + keyChar); KeyTipManager.defaultManager().handleKeyPress(keyChar); } if ((keyEvent.getKeyCode() == KeyEvent.VK_ALT) || (keyEvent.getKeyCode() == KeyEvent.VK_F10)) { if (keyEvent.getModifiers() != 0 || keyEvent.getModifiersEx() != 0) break; boolean hadPopups = !PopupPanelManager.defaultManager().getShownPath().isEmpty(); PopupPanelManager.defaultManager().hidePopups(null); if (hadPopups || KeyTipManager.defaultManager().isShowingKeyTips()) { KeyTipManager.defaultManager().hideAllKeyTips(); } else { KeyTipManager.defaultManager().showRootKeyTipChain(JRibbonFrame.this); } } if (keyEvent.getKeyCode() == KeyEvent.VK_ESCAPE) { // System.out.println("In KTM"); KeyTipManager.defaultManager().showPreviousChain(); } break; } } if (event instanceof MouseEvent) { MouseEvent mouseEvent = (MouseEvent) event; switch (mouseEvent.getID()) { case MouseEvent.MOUSE_CLICKED: case MouseEvent.MOUSE_DRAGGED: case MouseEvent.MOUSE_PRESSED: case MouseEvent.MOUSE_RELEASED: KeyTipManager.defaultManager().hideAllKeyTips(); } } } } } }, AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK); final KeyTipLayer keyTipLayer = new KeyTipLayer(); JRootPane rootPane = this.getRootPane(); JLayeredPane layeredPane = rootPane.getLayeredPane(); final LayoutManager currLM = rootPane.getLayout(); rootPane.setLayout( new LayoutManager() { @Override public void addLayoutComponent(String name, Component comp) { currLM.addLayoutComponent(name, comp); } @Override public void layoutContainer(Container parent) { currLM.layoutContainer(parent); JRibbonFrame ribbonFrame = JRibbonFrame.this; if (ribbonFrame.getRootPane().getWindowDecorationStyle() != JRootPane.NONE) keyTipLayer.setBounds(ribbonFrame.getRootPane().getBounds()); else keyTipLayer.setBounds(ribbonFrame.getRootPane().getContentPane().getBounds()); } @Override public Dimension minimumLayoutSize(Container parent) { return currLM.minimumLayoutSize(parent); } @Override public Dimension preferredLayoutSize(Container parent) { return currLM.preferredLayoutSize(parent); } @Override public void removeLayoutComponent(Component comp) { currLM.removeLayoutComponent(comp); } }); // layeredPane.setLayout(new OverlayLayout(layeredPane)); layeredPane.add(keyTipLayer, (Integer) (JLayeredPane.DEFAULT_LAYER + 60)); this.addWindowListener( new WindowAdapter() { @Override public void windowDeactivated(WindowEvent e) { // hide all key tips on window deactivation KeyTipManager keyTipManager = KeyTipManager.defaultManager(); if (keyTipManager.isShowingKeyTips()) { keyTipManager.hideAllKeyTips(); } } }); KeyTipManager.defaultManager() .addKeyTipListener( new KeyTipManager.KeyTipListener() { @Override public void keyTipsHidden(KeyTipEvent event) { if (event.getSource() == JRibbonFrame.this) keyTipLayer.setVisible(false); } @Override public void keyTipsShown(KeyTipEvent event) { if (event.getSource() == JRibbonFrame.this) keyTipLayer.setVisible(true); } }); ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false); JPopupMenu.setDefaultLightWeightPopupEnabled(false); super.setIconImages(Arrays.asList(FlamingoUtilities.getBlankImage(16, 16))); }