1 /*
2 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
726
727 // For focused sliders, we paint focus rect outside the bounds passed.
728 // Need to adjust for that.
729 boolean focused = ((state & SynthConstants.FOCUSED) != 0);
730 int focusSize = 0;
731 if (focused) {
732 GTKStyle style = (GTKStyle)context.getStyle();
733 focusSize = style.getClassSpecificIntValue(
734 context, "focus-line-width", 1) +
735 style.getClassSpecificIntValue(
736 context, "focus-padding", 1);
737 x -= focusSize;
738 y -= focusSize;
739 w += focusSize * 2;
740 h += focusSize * 2;
741 }
742
743 // The ubuntulooks engine paints slider troughs differently depending
744 // on the current slider value and its component orientation.
745 JSlider slider = (JSlider)context.getComponent();
746 double value = slider.getValue();
747 double min = slider.getMinimum();
748 double max = slider.getMaximum();
749 double visible = 20; // not used for sliders; any value will work
750
751 synchronized (UNIXToolkit.GTK_LOCK) {
752 // Note that we don't call paintCachedImage() here. Since some
753 // engines (e.g. ubuntulooks) paint the slider background
754 // differently for any given slider value, it would be wasteful
755 // to try to cache an image for each state, so instead we simply
756 // avoid caching in this case.
757 if (w <= 0 || h <= 0) {
758 return;
759 }
760 ENGINE.startPainting(g, x, y, w, h, id, state, value);
761 int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
762 ENGINE.setRangeValue(context, id, value, min, max, visible);
763 ENGINE.paintBox(g, context, id, gtkState, ShadowType.IN,
764 "trough", x + focusSize, y + focusSize,
765 w - 2 * focusSize, h - 2 * focusSize);
766 if (focused) {
767 ENGINE.paintFocus(g, context, id, SynthConstants.ENABLED,
768 "trough", x, y, w, h);
769 }
770 ENGINE.finishPainting(false); // don't bother caching the image
771 }
772 }
773
774 public void paintSliderThumbBackground(SynthContext context,
775 Graphics g, int x, int y, int w, int h, int dir) {
776 Region id = context.getRegion();
777 int gtkState = GTKLookAndFeel.synthStateToGTKState(
778 id, context.getComponentState());
779 synchronized (UNIXToolkit.GTK_LOCK) {
780 if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState, dir)) {
781 Orientation orientation = (dir == JSlider.HORIZONTAL ?
782 Orientation.HORIZONTAL : Orientation.VERTICAL);
783 String detail = (dir == JSlider.HORIZONTAL ?
784 "hscale" : "vscale");
785 ENGINE.startPainting(g, x, y, w, h, id, gtkState, dir);
786 ENGINE.paintSlider(g, context, id, gtkState,
787 ShadowType.OUT, detail, x, y, w, h, orientation);
788 ENGINE.finishPainting();
789 }
790 }
791 }
792
793 //
794 // SPINNER
795 //
796 public void paintSpinnerBackground(SynthContext context,
797 Graphics g,
798 int x, int y, int w, int h) {
799 // This is handled in paintTextFieldBackground
800 }
801
802 //
803 // SPLIT_PANE_DIVIDER
804 //
805 public void paintSplitPaneDividerBackground(SynthContext context,
806 Graphics g,
807 int x, int y, int w, int h) {
946 }
947
948 int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
949 int focusSize = 0;
950 boolean interiorFocus = style.getClassSpecificBoolValue(
951 context, "interior-focus", true);
952
953 focusSize = style.getClassSpecificIntValue(context,
954 "focus-line-width",1);
955 if (!interiorFocus && (state & SynthConstants.FOCUSED) != 0) {
956 x += focusSize;
957 y += focusSize;
958 w -= 2 * focusSize;
959 h -= 2 * focusSize;
960 }
961
962 int xThickness = style.getXThickness();
963 int yThickness = style.getYThickness();
964
965 ENGINE.startPainting(g, x, y, w, h, id, state);
966 ENGINE.paintShadow(g, context, id, gtkState,
967 ShadowType.IN, "entry", x, y, w, h);
968 ENGINE.paintFlatBox(g, context, id,
969 gtkState, ShadowType.NONE, "entry_bg",
970 x + xThickness,
971 y + yThickness,
972 w - (2 * xThickness),
973 h - (2 * yThickness),
974 ColorType.TEXT_BACKGROUND);
975
976 if (focusSize > 0 && (state & SynthConstants.FOCUSED) != 0) {
977 if (!interiorFocus) {
978 x -= focusSize;
979 y -= focusSize;
980 w += 2 * focusSize;
981 h += 2 * focusSize;
982 } else {
983 if (containerParent instanceof JComboBox) {
984 x += (focusSize + 2);
985 y += (focusSize + 1);
986 w -= (2 * focusSize + 1);
987 h -= (2 * focusSize + 2);
988 } else {
989 x += focusSize;
990 y += focusSize;
991 w -= 2 * focusSize;
992 h -= 2 * focusSize;
993 }
994 }
995 ENGINE.paintFocus(g, context, id, gtkState,
996 "entry", x, y, w, h);
997 }
998 ENGINE.finishPainting();
999 }
1000 }
1001
1002 private void paintTreeCellEditorBackground(SynthContext context, Graphics g,
1003 int x, int y, int w, int h) {
1004 Region id = context.getRegion();
1005 int gtkState = GTKLookAndFeel.synthStateToGTKState(
1006 id, context.getComponentState());
1007 synchronized (UNIXToolkit.GTK_LOCK) {
1008 if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState)) {
1009 ENGINE.startPainting(g, x, y, w, h, id, gtkState);
1010 ENGINE.paintFlatBox(g, context, id, gtkState, ShadowType.NONE,
1011 "entry_bg", x, y, w, h, ColorType.TEXT_BACKGROUND);
1012 ENGINE.finishPainting();
1121 } else if (sb.getValue() == sb.getMinimum()) {
1122 // At minimum
1123 value = rtl ? 100 : 0;
1124 } else if (sb.getValue() >= sb.getMaximum() - sb.getVisibleAmount()) {
1125 // At maximum
1126 value = rtl ? 0 : 100;
1127 } else {
1128 // Somewhere in between
1129 value = 50;
1130 }
1131
1132 synchronized (UNIXToolkit.GTK_LOCK) {
1133 if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState,
1134 dir, value, visible, rtl))
1135 {
1136 ENGINE.startPainting(g, x, y, w, h, id, gtkState,
1137 dir, value, visible, rtl);
1138 Orientation orientation = (dir == JScrollBar.HORIZONTAL ?
1139 Orientation.HORIZONTAL : Orientation.VERTICAL);
1140 ENGINE.setRangeValue(context, id, value, min, max, visible);
1141 ENGINE.paintSlider(g, context, id, gtkState,
1142 ShadowType.OUT, "slider", x, y, w, h, orientation);
1143 ENGINE.finishPainting();
1144 }
1145 }
1146 }
1147
1148 //
1149 // TOOL_TIP
1150 //
1151 public void paintToolTipBackground(SynthContext context, Graphics g,
1152 int x, int y, int w,int h) {
1153 Region id = context.getRegion();
1154 synchronized (UNIXToolkit.GTK_LOCK) {
1155 if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
1156 ENGINE.startPainting(g, x, y, w, h, id);
1157 ENGINE.paintFlatBox(g, context, id, SynthConstants.ENABLED,
1158 ShadowType.OUT, "tooltip", x, y, w, h,
1159 ColorType.BACKGROUND);
1160 ENGINE.finishPainting();
1161 }
1162 }
|
1 /*
2 * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
726
727 // For focused sliders, we paint focus rect outside the bounds passed.
728 // Need to adjust for that.
729 boolean focused = ((state & SynthConstants.FOCUSED) != 0);
730 int focusSize = 0;
731 if (focused) {
732 GTKStyle style = (GTKStyle)context.getStyle();
733 focusSize = style.getClassSpecificIntValue(
734 context, "focus-line-width", 1) +
735 style.getClassSpecificIntValue(
736 context, "focus-padding", 1);
737 x -= focusSize;
738 y -= focusSize;
739 w += focusSize * 2;
740 h += focusSize * 2;
741 }
742
743 // The ubuntulooks engine paints slider troughs differently depending
744 // on the current slider value and its component orientation.
745 JSlider slider = (JSlider)context.getComponent();
746 if (GTKLookAndFeel.is3()) {
747 if (slider.getOrientation() == JSlider.VERTICAL) {
748 y += 1;
749 h -= 2;
750 } else {
751 x += 1;
752 w -= 2;
753 }
754 }
755 double value = slider.getValue();
756 double min = slider.getMinimum();
757 double max = slider.getMaximum();
758 double visible = 20; // not used for sliders; any value will work
759
760 synchronized (UNIXToolkit.GTK_LOCK) {
761 // Note that we don't call paintCachedImage() here. Since some
762 // engines (e.g. ubuntulooks) paint the slider background
763 // differently for any given slider value, it would be wasteful
764 // to try to cache an image for each state, so instead we simply
765 // avoid caching in this case.
766 if (w <= 0 || h <= 0) {
767 return;
768 }
769 ENGINE.startPainting(g, x, y, w, h, id, state, value);
770 int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
771 ENGINE.setRangeValue(context, id, value, min, max, visible);
772 ENGINE.paintBox(g, context, id, gtkState, ShadowType.IN,
773 "trough", x + focusSize, y + focusSize,
774 w - 2 * focusSize, h - 2 * focusSize);
775 if (focused) {
776 ENGINE.paintFocus(g, context, id, SynthConstants.ENABLED,
777 "trough", x, y, w, h);
778 }
779 ENGINE.finishPainting(false); // don't bother caching the image
780 }
781 }
782
783 public void paintSliderThumbBackground(SynthContext context,
784 Graphics g, int x, int y, int w, int h, int dir) {
785 Region id = context.getRegion();
786 int gtkState = GTKLookAndFeel.synthStateToGTKState(
787 id, context.getComponentState());
788 boolean hasFocus = GTKLookAndFeel.is3() &&
789 ((context.getComponentState() & SynthConstants.FOCUSED) != 0);
790 synchronized (UNIXToolkit.GTK_LOCK) {
791 if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState, dir,
792 hasFocus)) {
793 Orientation orientation = (dir == JSlider.HORIZONTAL ?
794 Orientation.HORIZONTAL : Orientation.VERTICAL);
795 String detail = (dir == JSlider.HORIZONTAL ?
796 "hscale" : "vscale");
797 ENGINE.startPainting(g, x, y, w, h, id, gtkState, dir);
798 ENGINE.paintSlider(g, context, id, gtkState,
799 ShadowType.OUT, detail, x, y, w, h, orientation,
800 hasFocus);
801 ENGINE.finishPainting();
802 }
803 }
804 }
805
806 //
807 // SPINNER
808 //
809 public void paintSpinnerBackground(SynthContext context,
810 Graphics g,
811 int x, int y, int w, int h) {
812 // This is handled in paintTextFieldBackground
813 }
814
815 //
816 // SPLIT_PANE_DIVIDER
817 //
818 public void paintSplitPaneDividerBackground(SynthContext context,
819 Graphics g,
820 int x, int y, int w, int h) {
959 }
960
961 int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
962 int focusSize = 0;
963 boolean interiorFocus = style.getClassSpecificBoolValue(
964 context, "interior-focus", true);
965
966 focusSize = style.getClassSpecificIntValue(context,
967 "focus-line-width",1);
968 if (!interiorFocus && (state & SynthConstants.FOCUSED) != 0) {
969 x += focusSize;
970 y += focusSize;
971 w -= 2 * focusSize;
972 h -= 2 * focusSize;
973 }
974
975 int xThickness = style.getXThickness();
976 int yThickness = style.getYThickness();
977
978 ENGINE.startPainting(g, x, y, w, h, id, state);
979 if (GTKLookAndFeel.is3()) {
980 ENGINE.paintBackground(g, context, id, gtkState, null,
981 x, y, w, h);
982 }
983 ENGINE.paintShadow(g, context, id, gtkState,
984 ShadowType.IN, "entry", x, y, w, h);
985 if (!GTKLookAndFeel.is3()) {
986 ENGINE.paintFlatBox(g, context, id,
987 gtkState, ShadowType.NONE, "entry_bg",
988 x + xThickness,
989 y + yThickness,
990 w - (2 * xThickness),
991 h - (2 * yThickness),
992 ColorType.TEXT_BACKGROUND);
993 }
994
995 if (focusSize > 0 && (state & SynthConstants.FOCUSED) != 0) {
996 if (!interiorFocus) {
997 x -= focusSize;
998 y -= focusSize;
999 w += 2 * focusSize;
1000 h += 2 * focusSize;
1001 } else {
1002 if (containerParent instanceof JComboBox) {
1003 x += (focusSize + 2);
1004 y += focusSize + (GTKLookAndFeel.is3() ? 3 : 1);
1005 w -= 2 * focusSize + (GTKLookAndFeel.is3() ? 4 : 1);
1006 h -= 2 * focusSize + (GTKLookAndFeel.is3() ? 6 : 2);
1007 } else {
1008 x += focusSize + (GTKLookAndFeel.is3() ? 2 : 0);
1009 y += focusSize + (GTKLookAndFeel.is3() ? 2 :0 );
1010 w -= 2 * focusSize + (GTKLookAndFeel.is3() ? 4 : 0);
1011 h -= 2 * focusSize + (GTKLookAndFeel.is3() ? 4 : 0);
1012 }
1013 }
1014 ENGINE.paintFocus(g, context, id, gtkState,
1015 "entry", x, y, w, h);
1016 }
1017 ENGINE.finishPainting();
1018 }
1019 }
1020
1021 private void paintTreeCellEditorBackground(SynthContext context, Graphics g,
1022 int x, int y, int w, int h) {
1023 Region id = context.getRegion();
1024 int gtkState = GTKLookAndFeel.synthStateToGTKState(
1025 id, context.getComponentState());
1026 synchronized (UNIXToolkit.GTK_LOCK) {
1027 if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState)) {
1028 ENGINE.startPainting(g, x, y, w, h, id, gtkState);
1029 ENGINE.paintFlatBox(g, context, id, gtkState, ShadowType.NONE,
1030 "entry_bg", x, y, w, h, ColorType.TEXT_BACKGROUND);
1031 ENGINE.finishPainting();
1140 } else if (sb.getValue() == sb.getMinimum()) {
1141 // At minimum
1142 value = rtl ? 100 : 0;
1143 } else if (sb.getValue() >= sb.getMaximum() - sb.getVisibleAmount()) {
1144 // At maximum
1145 value = rtl ? 0 : 100;
1146 } else {
1147 // Somewhere in between
1148 value = 50;
1149 }
1150
1151 synchronized (UNIXToolkit.GTK_LOCK) {
1152 if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState,
1153 dir, value, visible, rtl))
1154 {
1155 ENGINE.startPainting(g, x, y, w, h, id, gtkState,
1156 dir, value, visible, rtl);
1157 Orientation orientation = (dir == JScrollBar.HORIZONTAL ?
1158 Orientation.HORIZONTAL : Orientation.VERTICAL);
1159 ENGINE.setRangeValue(context, id, value, min, max, visible);
1160 ENGINE.paintSlider(g, context, id, gtkState, ShadowType.OUT,
1161 "slider", x, y, w, h, orientation, false);
1162 ENGINE.finishPainting();
1163 }
1164 }
1165 }
1166
1167 //
1168 // TOOL_TIP
1169 //
1170 public void paintToolTipBackground(SynthContext context, Graphics g,
1171 int x, int y, int w,int h) {
1172 Region id = context.getRegion();
1173 synchronized (UNIXToolkit.GTK_LOCK) {
1174 if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
1175 ENGINE.startPainting(g, x, y, w, h, id);
1176 ENGINE.paintFlatBox(g, context, id, SynthConstants.ENABLED,
1177 ShadowType.OUT, "tooltip", x, y, w, h,
1178 ColorType.BACKGROUND);
1179 ENGINE.finishPainting();
1180 }
1181 }
|