@Override public void layoutContainer(final Container parent) { final int componentCount = parent.getComponentCount(); if (componentCount == 0) return; final EditorEx history = myHistoryViewer; final EditorEx editor = componentCount == 2 ? myConsoleEditor : null; if (editor == null) { parent.getComponent(0).setBounds(parent.getBounds()); return; } final Dimension panelSize = parent.getSize(); if (panelSize.getHeight() <= 0) return; final Dimension historySize = history.getContentSize(); final Dimension editorSize = editor.getContentSize(); final Dimension newEditorSize = new Dimension(); // deal with width final int width = Math.max(editorSize.width, historySize.width); newEditorSize.width = width + editor.getScrollPane().getHorizontalScrollBar().getHeight(); history.getSoftWrapModel().forceAdditionalColumnsUsage(); editor .getSettings() .setAdditionalColumnsCount( 2 + (width - editorSize.width) / EditorUtil.getSpaceWidth(Font.PLAIN, editor)); history .getSettings() .setAdditionalColumnsCount( 2 + (width - historySize.width) / EditorUtil.getSpaceWidth(Font.PLAIN, history)); // deal with height if (historySize.width == 0) historySize.height = 0; final int minHistorySize = historySize.height > 0 ? 2 * history.getLineHeight() + (myShowSeparatorLine ? SEPARATOR_THICKNESS : 0) : 0; final int minEditorSize = editor.isViewer() ? 0 : editor.getLineHeight(); final int editorPreferred = editor.isViewer() ? 0 : Math.max(minEditorSize, editorSize.height); final int historyPreferred = Math.max(minHistorySize, historySize.height); if (panelSize.height < minEditorSize) { newEditorSize.height = panelSize.height; } else if (panelSize.height < editorPreferred) { newEditorSize.height = panelSize.height - minHistorySize; } else if (panelSize.height < editorPreferred + historyPreferred) { newEditorSize.height = editorPreferred; } else { newEditorSize.height = editorPreferred == 0 ? 0 : panelSize.height - historyPreferred; } final Dimension newHistorySize = new Dimension(width, panelSize.height - newEditorSize.height); // apply editor .getComponent() .setBounds(0, newHistorySize.height, panelSize.width, newEditorSize.height); myForceScrollToEnd.compareAndSet(false, shouldScrollHistoryToEnd()); history.getComponent().setBounds(0, 0, panelSize.width, newHistorySize.height); }
@Override public Dimension getPreferredSize() { Dimension dimension = super.getPreferredSize(); if (getText() == null || getText().isEmpty()) { setText("Roots"); dimension.height = super.getPreferredSize().height; setText(""); return dimension; } return dimension; }
public Dimension getPreferredSize() { Dimension basicSize = super.getPreferredSize(); Icon icon = getIcon(); FontMetrics fm = getFontMetrics(getFont()); Rectangle viewRect = new Rectangle(0, 0, Short.MAX_VALUE, Short.MAX_VALUE); Insets insets = getInsets(); int dx = insets.left + insets.right; int dy = insets.top + insets.bottom; Rectangle iconR = new Rectangle(); Rectangle textR = new Rectangle(); SwingUtilities.layoutCompoundLabel( this, fm, getText(), icon, SwingConstants.CENTER, horizontalTextAlignment(), SwingConstants.CENTER, horizontalTextPosition(), viewRect, iconR, textR, iconTextSpace()); int x1 = Math.min(iconR.x, textR.x); int x2 = Math.max(iconR.x + iconR.width, textR.x + textR.width); int y1 = Math.min(iconR.y, textR.y); int y2 = Math.max(iconR.y + iconR.height, textR.y + textR.height); Dimension rv = new Dimension(x2 - x1 + dx, y2 - y1 + dy); rv.width += Math.max(basicSize.height - rv.height, 0); rv.width = Math.max(rv.width, basicSize.width); rv.height = Math.max(rv.height, basicSize.height); return rv; }
public PaletteGroupHeader(PaletteWindow paletteWindow, PaletteGroup group) { myPaletteWindow = paletteWindow; myGroup = group; if (group.getName() == null) { setVisible(false); } else { setText(group.getName()); } setSelected(true); addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (myComponentList != null) { myComponentList.setVisible(isSelected()); } } }); addMouseListener( new PopupHandler() { public void invokePopup(Component comp, int x, int y) { myPaletteWindow.setLastFocusedGroup(PaletteGroupHeader.this); showGroupPopupMenu(comp, x, y); } }); setIcon(UIUtil.getTreeCollapsedIcon()); setSelectedIcon(UIUtil.getTreeExpandedIcon()); setFont(getFont().deriveFont(Font.BOLD)); setFocusPainted(false); setMargin(new Insets(0, 3, 0, 3)); setOpaque(true); if (getBorder() instanceof CompoundBorder) { // from BasicLookAndFeel Dimension pref = getPreferredSize(); pref.height -= 3; setPreferredSize(pref); } DnDManager.getInstance() .registerTarget( new DnDTarget() { public boolean update(DnDEvent aEvent) { setBorderPainted(true); aEvent.setDropPossible(aEvent.getAttachedObject() instanceof PaletteItem); return true; } public void drop(DnDEvent aEvent) { setBorderPainted(false); if (aEvent.getAttachedObject() instanceof PaletteItem) { myGroup.handleDrop( myPaletteWindow.getProject(), (PaletteItem) aEvent.getAttachedObject(), -1); } } public void cleanUpOnLeave() { setBorderPainted(false); } public void updateDraggedImage(Image image, Point dropPoint, Point imageOffset) {} }, this); addFocusListener( new FocusAdapter() { @Override public void focusGained(FocusEvent e) { myPaletteWindow.setLastFocusedGroup(PaletteGroupHeader.this); } }); initActions(); }