From e3e3c0c819cf1313ead78a30ed78db0daa452ab6 Mon Sep 17 00:00:00 2001 From: hudsonb Date: Thu, 19 Jun 2014 23:37:24 -0400 Subject: [PATCH] JSplitPane now mimics the LAF of intellij splitters --- src/com/bulenkov/darcula/darcula.properties | 1 + src/com/bulenkov/darcula/icons/splitGlueH.png | Bin 0 -> 169 bytes src/com/bulenkov/darcula/icons/splitGlueV.png | Bin 0 -> 174 bytes .../darcula/ui/DarculaSplitPaneDivider.java | 158 ++++++++++++++++++ .../darcula/ui/DarculaSplitPaneUI.java | 34 ++++ 5 files changed, 193 insertions(+) create mode 100644 src/com/bulenkov/darcula/icons/splitGlueH.png create mode 100644 src/com/bulenkov/darcula/icons/splitGlueV.png create mode 100644 src/com/bulenkov/darcula/ui/DarculaSplitPaneDivider.java create mode 100644 src/com/bulenkov/darcula/ui/DarculaSplitPaneUI.java diff --git a/src/com/bulenkov/darcula/darcula.properties b/src/com/bulenkov/darcula/darcula.properties index 8cecdb4..7349398 100755 --- a/src/com/bulenkov/darcula/darcula.properties +++ b/src/com/bulenkov/darcula/darcula.properties @@ -155,6 +155,7 @@ Spinner.background=3c3f41 Spinner.arrowButtonInsets=1,1,1,1 Spinner.editorBorderPainted=false +SplitPaneUI=com.bulenkov.darcula.ui.DarculaSplitPaneUI SplitPane.highlight=3c3f41 TreeUI=com.bulenkov.darcula.ui.DarculaTreeUI diff --git a/src/com/bulenkov/darcula/icons/splitGlueH.png b/src/com/bulenkov/darcula/icons/splitGlueH.png new file mode 100644 index 0000000000000000000000000000000000000000..7e0e99d25ee5c4f1beb505d45ba5aa1f54bf02bf GIT binary patch literal 169 zcmeAS@N?(olHy`uVBq!ia0vp^Y(Ol?0V4m&-^~V61)eUBAr-gwPV^RPP~dU4u45Bn zdsollcbsv-!H(D$*IdPFGmW=&bmXkMn-Qve=#b;mDQRao{Z?GNm3MeGlVeKnkBgiW zEGiBBm>kKx?IQ*>#17J@YwmVd&X`>rA;f#PObdIZ#mgy=VG_qk*5kLEOH&b-6St#_=xM=0jTtbi0VE#YHgoi<)`eqK7s`OEW Ymwk87m-35l20DPj)78&qol`;+0KwZq(*OVf literal 0 HcmV?d00001 diff --git a/src/com/bulenkov/darcula/ui/DarculaSplitPaneDivider.java b/src/com/bulenkov/darcula/ui/DarculaSplitPaneDivider.java new file mode 100644 index 0000000..e8cf583 --- /dev/null +++ b/src/com/bulenkov/darcula/ui/DarculaSplitPaneDivider.java @@ -0,0 +1,158 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.bulenkov.darcula.ui; + +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Graphics; + +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JSplitPane; +import javax.swing.border.Border; +import javax.swing.plaf.basic.BasicSplitPaneDivider; + +import com.bulenkov.iconloader.IconLoader; +import com.bulenkov.iconloader.util.DoubleColor; +import com.bulenkov.iconloader.util.Gray; +import com.bulenkov.iconloader.util.UIUtil; + +public class DarculaSplitPaneDivider extends BasicSplitPaneDivider { + private Icon splitGlueV = IconLoader.findIcon("/com/bulenkov/darcula/icons/splitGlueV.png", DarculaSplitPaneDivider.class, true); + private Icon splitGlueH = IconLoader.findIcon("/com/bulenkov/darcula/icons/splitGlueH.png", DarculaSplitPaneDivider.class, true); + + /** + * Creates an instance of DarculaSplitPaneDivider. Registers this + * instance for mouse events and mouse dragged events. + */ + public DarculaSplitPaneDivider(DarculaSplitPaneUI ui) { + super(ui); + } + + @Override + public void paint(Graphics g) { + super.paint(g); + + if(splitPane.getOrientation() == JSplitPane.VERTICAL_SPLIT) + splitGlueV.paintIcon(this, g, getWidth() / 2, (getHeight() - splitGlueV.getIconHeight()) / 2); + else + splitGlueH.paintIcon(this, g, (getWidth() - splitGlueH.getIconWidth()) / 2, getHeight() / 2); + } + + @Override + protected JButton createLeftOneTouchButton() { + JButton b = new JButton() { + public void setBorder(Border b) { + } + + public void paint(Graphics g) { + if (splitPane != null) { + int[] xs = new int[3]; + int[] ys = new int[3]; + int blockSize; + + // Fill the background first ... + g.setColor(this.getBackground()); + g.fillRect(0, 0, this.getWidth(), + this.getHeight()); + + // ... then draw the arrow. + g.setColor(new DoubleColor(Gray._255, UIUtil.getLabelForeground())); + if (orientation == JSplitPane.VERTICAL_SPLIT) { + blockSize = Math.min(getHeight(), ONE_TOUCH_SIZE); + xs[0] = blockSize; + xs[1] = 0; + xs[2] = blockSize << 1; + ys[0] = 0; + ys[1] = ys[2] = blockSize; + g.drawPolygon(xs, ys, 3); // Little trick to make the + // arrows of equal size + } + else { + blockSize = Math.min(getWidth(), ONE_TOUCH_SIZE); + xs[0] = xs[2] = blockSize; + xs[1] = 0; + ys[0] = 0; + ys[1] = blockSize; + ys[2] = blockSize << 1; + } + g.fillPolygon(xs, ys, 3); + } + } + // Don't want the button to participate in focus traversable. + public boolean isFocusTraversable() { + return false; + } + }; + b.setMinimumSize(new Dimension(ONE_TOUCH_SIZE, ONE_TOUCH_SIZE)); + b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + b.setFocusPainted(false); + b.setBorderPainted(false); + b.setRequestFocusEnabled(false); + return b; + } + + @Override + protected JButton createRightOneTouchButton() { + JButton b = new JButton() { + public void setBorder(Border border) { + } + public void paint(Graphics g) { + if (splitPane != null) { + int[] xs = new int[3]; + int[] ys = new int[3]; + int blockSize; + + // Fill the background first ... + g.setColor(this.getBackground()); + g.fillRect(0, 0, this.getWidth(), + this.getHeight()); + + // ... then draw the arrow. + if (orientation == JSplitPane.VERTICAL_SPLIT) { + blockSize = Math.min(getHeight(), ONE_TOUCH_SIZE); + xs[0] = blockSize; + xs[1] = blockSize << 1; + xs[2] = 0; + ys[0] = blockSize; + ys[1] = ys[2] = 0; + } + else { + blockSize = Math.min(getWidth(), ONE_TOUCH_SIZE); + xs[0] = xs[2] = 0; + xs[1] = blockSize; + ys[0] = 0; + ys[1] = blockSize; + ys[2] = blockSize << 1; + } + g.setColor(new DoubleColor(Gray._255, UIUtil.getLabelForeground())); + g.fillPolygon(xs, ys, 3); + } + } + // Don't want the button to participate in focus traversable. + public boolean isFocusTraversable() { + return false; + } + }; + b.setMinimumSize(new Dimension(ONE_TOUCH_SIZE, ONE_TOUCH_SIZE)); + b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + b.setFocusPainted(false); + b.setBorderPainted(false); + b.setRequestFocusEnabled(false); + return b; + } +} diff --git a/src/com/bulenkov/darcula/ui/DarculaSplitPaneUI.java b/src/com/bulenkov/darcula/ui/DarculaSplitPaneUI.java new file mode 100644 index 0000000..76f16aa --- /dev/null +++ b/src/com/bulenkov/darcula/ui/DarculaSplitPaneUI.java @@ -0,0 +1,34 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.bulenkov.darcula.ui; + +import javax.swing.JComponent; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicSplitPaneDivider; +import javax.swing.plaf.basic.BasicSplitPaneUI; + +public class DarculaSplitPaneUI extends BasicSplitPaneUI { + @SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"}) + public static ComponentUI createUI(JComponent c) { + return new DarculaSplitPaneUI(); + } + + @Override + public BasicSplitPaneDivider createDefaultDivider() { + return new DarculaSplitPaneDivider(this); + } +}