222 static void loadActionMap(LazyActionMap map) {
223 map.put(new Actions(Actions.NEXT));
224 map.put(new Actions(Actions.PREVIOUS));
225 map.put(new Actions(Actions.RIGHT));
226 map.put(new Actions(Actions.LEFT));
227 map.put(new Actions(Actions.UP));
228 map.put(new Actions(Actions.DOWN));
229 map.put(new Actions(Actions.PAGE_UP));
230 map.put(new Actions(Actions.PAGE_DOWN));
231 map.put(new Actions(Actions.REQUEST_FOCUS));
232 map.put(new Actions(Actions.REQUEST_FOCUS_FOR_VISIBLE));
233 map.put(new Actions(Actions.SET_SELECTED));
234 map.put(new Actions(Actions.SELECT_FOCUSED));
235 map.put(new Actions(Actions.SCROLL_FORWARD));
236 map.put(new Actions(Actions.SCROLL_BACKWARD));
237 }
238
239 // UI Installation/De-installation
240
241 public void installUI(JComponent c) {
242 this.tabPane = (JTabbedPane)c;
243
244 calculatedBaseline = false;
245 rolloverTabIndex = -1;
246 focusIndex = -1;
247 c.setLayout(createLayoutManager());
248 installComponents();
249 installDefaults();
250 installListeners();
251 installKeyboardActions();
252 }
253
254 public void uninstallUI(JComponent c) {
255 uninstallKeyboardActions();
256 uninstallListeners();
257 uninstallDefaults();
258 uninstallComponents();
259 c.setLayout(null);
260
261 this.tabPane = null;
925 }
926
927 paintTabBorder(g, tabPlacement, tabIndex, tabRect.x, tabRect.y,
928 tabRect.width, tabRect.height, isSelected);
929
930 String title = tabPane.getTitleAt(tabIndex);
931 Font font = tabPane.getFont();
932 FontMetrics metrics = SwingUtilities2.getFontMetrics(tabPane, g, font);
933 Icon icon = getIconForTab(tabIndex);
934
935 layoutLabel(tabPlacement, metrics, tabIndex, title, icon,
936 tabRect, iconRect, textRect, isSelected);
937
938 if (tabPane.getTabComponentAt(tabIndex) == null) {
939 String clippedTitle = title;
940
941 if (scrollableTabLayoutEnabled() && tabScroller.croppedEdge.isParamsSet() &&
942 tabScroller.croppedEdge.getTabIndex() == tabIndex && isHorizontalTabPlacement()) {
943 int availTextWidth = tabScroller.croppedEdge.getCropline() -
944 (textRect.x - tabRect.x) - tabScroller.croppedEdge.getCroppedSideWidth();
945 clippedTitle = SwingUtilities2.clipStringIfNecessary(null, metrics, title, availTextWidth);
946 } else if (!scrollableTabLayoutEnabled() && isHorizontalTabPlacement()) {
947 clippedTitle = SwingUtilities2.clipStringIfNecessary(null, metrics, title, textRect.width);
948 }
949
950 paintText(g, tabPlacement, font, metrics,
951 tabIndex, clippedTitle, textRect, isSelected);
952
953 paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
954 }
955 paintFocusIndicator(g, tabPlacement, rects, tabIndex,
956 iconRect, textRect, isSelected);
957 }
958
959 private boolean isHorizontalTabPlacement() {
960 return tabPane.getTabPlacement() == TOP || tabPane.getTabPlacement() == BOTTOM;
961 }
962
963 /* This method will create and return a polygon shape for the given tab rectangle
964 * which has been cropped at the specified cropline with a torn edge visual.
965 * e.g. A "File" tab which has cropped been cropped just after the "i":
966 * -------------
967 * | ..... |
1161 g.setFont(font);
1162
1163 View v = getTextViewForTab(tabIndex);
1164 if (v != null) {
1165 // html
1166 v.paint(g, textRect);
1167 } else {
1168 // plain text
1169 int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
1170
1171 if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
1172 Color fg = tabPane.getForegroundAt(tabIndex);
1173 if (isSelected && (fg instanceof UIResource)) {
1174 Color selectedFG = UIManager.getColor(
1175 "TabbedPane.selectedForeground");
1176 if (selectedFG != null) {
1177 fg = selectedFG;
1178 }
1179 }
1180 g.setColor(fg);
1181 SwingUtilities2.drawStringUnderlineCharAt(tabPane, g,
1182 title, mnemIndex,
1183 textRect.x, textRect.y + metrics.getAscent());
1184
1185 } else { // tab disabled
1186 g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
1187 SwingUtilities2.drawStringUnderlineCharAt(tabPane, g,
1188 title, mnemIndex,
1189 textRect.x, textRect.y + metrics.getAscent());
1190 g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
1191 SwingUtilities2.drawStringUnderlineCharAt(tabPane, g,
1192 title, mnemIndex,
1193 textRect.x - 1, textRect.y + metrics.getAscent() - 1);
1194
1195 }
1196 }
1197 }
1198
1199 /**
1200 * Returns the tab label shift x.
1201 * @param tabPlacement the tab placement
1202 * @param tabIndex the tab index
1203 * @param isSelected selection status
1204 * @return the tab label shift x
1205 */
1206 protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected) {
1207 Rectangle tabRect = rects[tabIndex];
1208 String propKey = (isSelected ? "selectedLabelShift" : "labelShift");
1209 int nudge = DefaultLookup.getInt(
1210 tabPane, this, "TabbedPane." + propKey, 1);
1211
2009 * @return the tab width
2010 */
2011 protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) {
2012 Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
2013 int width = tabInsets.left + tabInsets.right + 3;
2014 Component tabComponent = tabPane.getTabComponentAt(tabIndex);
2015 if (tabComponent != null) {
2016 width += tabComponent.getPreferredSize().width;
2017 } else {
2018 Icon icon = getIconForTab(tabIndex);
2019 if (icon != null) {
2020 width += icon.getIconWidth() + textIconGap;
2021 }
2022 View v = getTextViewForTab(tabIndex);
2023 if (v != null) {
2024 // html
2025 width += (int) v.getPreferredSpan(View.X_AXIS);
2026 } else {
2027 // plain text
2028 String title = tabPane.getTitleAt(tabIndex);
2029 width += SwingUtilities2.stringWidth(tabPane, metrics, title);
2030 }
2031 }
2032 return width;
2033 }
2034
2035 /**
2036 * Calculates the maximum tab width.
2037 * @param tabPlacement the placement (left, right, bottom, top) of the tab
2038 * @return the maximum tab width
2039 */
2040 protected int calculateMaxTabWidth(int tabPlacement) {
2041 FontMetrics metrics = getFontMetrics();
2042 int tabCount = tabPane.getTabCount();
2043 int result = 0;
2044 for(int i = 0; i < tabCount; i++) {
2045 result = Math.max(calculateTabWidth(tabPlacement, i, metrics), result);
2046 }
2047 return result;
2048 }
2049
|
222 static void loadActionMap(LazyActionMap map) {
223 map.put(new Actions(Actions.NEXT));
224 map.put(new Actions(Actions.PREVIOUS));
225 map.put(new Actions(Actions.RIGHT));
226 map.put(new Actions(Actions.LEFT));
227 map.put(new Actions(Actions.UP));
228 map.put(new Actions(Actions.DOWN));
229 map.put(new Actions(Actions.PAGE_UP));
230 map.put(new Actions(Actions.PAGE_DOWN));
231 map.put(new Actions(Actions.REQUEST_FOCUS));
232 map.put(new Actions(Actions.REQUEST_FOCUS_FOR_VISIBLE));
233 map.put(new Actions(Actions.SET_SELECTED));
234 map.put(new Actions(Actions.SELECT_FOCUSED));
235 map.put(new Actions(Actions.SCROLL_FORWARD));
236 map.put(new Actions(Actions.SCROLL_BACKWARD));
237 }
238
239 // UI Installation/De-installation
240
241 public void installUI(JComponent c) {
242 super.installUI(c);
243 this.tabPane = (JTabbedPane)c;
244
245 calculatedBaseline = false;
246 rolloverTabIndex = -1;
247 focusIndex = -1;
248 c.setLayout(createLayoutManager());
249 installComponents();
250 installDefaults();
251 installListeners();
252 installKeyboardActions();
253 }
254
255 public void uninstallUI(JComponent c) {
256 uninstallKeyboardActions();
257 uninstallListeners();
258 uninstallDefaults();
259 uninstallComponents();
260 c.setLayout(null);
261
262 this.tabPane = null;
926 }
927
928 paintTabBorder(g, tabPlacement, tabIndex, tabRect.x, tabRect.y,
929 tabRect.width, tabRect.height, isSelected);
930
931 String title = tabPane.getTitleAt(tabIndex);
932 Font font = tabPane.getFont();
933 FontMetrics metrics = SwingUtilities2.getFontMetrics(tabPane, g, font);
934 Icon icon = getIconForTab(tabIndex);
935
936 layoutLabel(tabPlacement, metrics, tabIndex, title, icon,
937 tabRect, iconRect, textRect, isSelected);
938
939 if (tabPane.getTabComponentAt(tabIndex) == null) {
940 String clippedTitle = title;
941
942 if (scrollableTabLayoutEnabled() && tabScroller.croppedEdge.isParamsSet() &&
943 tabScroller.croppedEdge.getTabIndex() == tabIndex && isHorizontalTabPlacement()) {
944 int availTextWidth = tabScroller.croppedEdge.getCropline() -
945 (textRect.x - tabRect.x) - tabScroller.croppedEdge.getCroppedSideWidth();
946 clippedTitle = getTextUIDrawing().getClippedString(null, metrics, title, availTextWidth);
947 } else if (!scrollableTabLayoutEnabled() && isHorizontalTabPlacement()) {
948 clippedTitle = getTextUIDrawing().getClippedString(null, metrics, title, textRect.width);
949 }
950
951 paintText(g, tabPlacement, font, metrics,
952 tabIndex, clippedTitle, textRect, isSelected);
953
954 paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
955 }
956 paintFocusIndicator(g, tabPlacement, rects, tabIndex,
957 iconRect, textRect, isSelected);
958 }
959
960 private boolean isHorizontalTabPlacement() {
961 return tabPane.getTabPlacement() == TOP || tabPane.getTabPlacement() == BOTTOM;
962 }
963
964 /* This method will create and return a polygon shape for the given tab rectangle
965 * which has been cropped at the specified cropline with a torn edge visual.
966 * e.g. A "File" tab which has cropped been cropped just after the "i":
967 * -------------
968 * | ..... |
1162 g.setFont(font);
1163
1164 View v = getTextViewForTab(tabIndex);
1165 if (v != null) {
1166 // html
1167 v.paint(g, textRect);
1168 } else {
1169 // plain text
1170 int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
1171
1172 if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
1173 Color fg = tabPane.getForegroundAt(tabIndex);
1174 if (isSelected && (fg instanceof UIResource)) {
1175 Color selectedFG = UIManager.getColor(
1176 "TabbedPane.selectedForeground");
1177 if (selectedFG != null) {
1178 fg = selectedFG;
1179 }
1180 }
1181 g.setColor(fg);
1182 getTextUIDrawing().drawStringUnderlineCharAt(tabPane, g,
1183 title, mnemIndex,
1184 textRect.x, textRect.y + metrics.getAscent());
1185
1186 } else { // tab disabled
1187 g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
1188 getTextUIDrawing().drawStringUnderlineCharAt(tabPane, g,
1189 title, mnemIndex,
1190 textRect.x, textRect.y + metrics.getAscent());
1191 g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
1192 getTextUIDrawing().drawStringUnderlineCharAt(tabPane, g,
1193 title, mnemIndex,
1194 textRect.x - 1, textRect.y + metrics.getAscent() - 1);
1195
1196 }
1197 }
1198 }
1199
1200 /**
1201 * Returns the tab label shift x.
1202 * @param tabPlacement the tab placement
1203 * @param tabIndex the tab index
1204 * @param isSelected selection status
1205 * @return the tab label shift x
1206 */
1207 protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected) {
1208 Rectangle tabRect = rects[tabIndex];
1209 String propKey = (isSelected ? "selectedLabelShift" : "labelShift");
1210 int nudge = DefaultLookup.getInt(
1211 tabPane, this, "TabbedPane." + propKey, 1);
1212
2010 * @return the tab width
2011 */
2012 protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) {
2013 Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
2014 int width = tabInsets.left + tabInsets.right + 3;
2015 Component tabComponent = tabPane.getTabComponentAt(tabIndex);
2016 if (tabComponent != null) {
2017 width += tabComponent.getPreferredSize().width;
2018 } else {
2019 Icon icon = getIconForTab(tabIndex);
2020 if (icon != null) {
2021 width += icon.getIconWidth() + textIconGap;
2022 }
2023 View v = getTextViewForTab(tabIndex);
2024 if (v != null) {
2025 // html
2026 width += (int) v.getPreferredSpan(View.X_AXIS);
2027 } else {
2028 // plain text
2029 String title = tabPane.getTitleAt(tabIndex);
2030 width += getTextUIDrawing().getStringWidth(tabPane, metrics, title);
2031 }
2032 }
2033 return width;
2034 }
2035
2036 /**
2037 * Calculates the maximum tab width.
2038 * @param tabPlacement the placement (left, right, bottom, top) of the tab
2039 * @return the maximum tab width
2040 */
2041 protected int calculateMaxTabWidth(int tabPlacement) {
2042 FontMetrics metrics = getFontMetrics();
2043 int tabCount = tabPane.getTabCount();
2044 int result = 0;
2045 for(int i = 0; i < tabCount; i++) {
2046 result = Math.max(calculateTabWidth(tabPlacement, i, metrics), result);
2047 }
2048 return result;
2049 }
2050
|