1/* 2 * Copyright (c) 2011, 2012, 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 23 * questions. 24 */ 25 26package com.apple.laf; 27 28import java.awt.Component; 29import java.awt.Graphics; 30 31import javax.swing.JComponent; 32 33import apple.laf.JRSUIState; 34import apple.laf.JRSUIConstants.Focused; 35import apple.laf.JRSUIConstants.State; 36import apple.laf.JRSUIConstants.Widget; 37 38import com.apple.laf.AquaUtilControlSize.SizeDescriptor; 39import com.apple.laf.AquaUtilControlSize.SizeVariant; 40import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor; 41 42public class AquaScrollRegionBorder extends AquaBorder { 43 private static final RecyclableSingletonFromDefaultConstructor<AquaScrollRegionBorder> instance = new RecyclableSingletonFromDefaultConstructor<AquaScrollRegionBorder>(AquaScrollRegionBorder.class); 44 45 public static AquaScrollRegionBorder getScrollRegionBorder() { 46 return instance.get(); 47 } 48 49 public AquaScrollRegionBorder() { 50 super(new SizeDescriptor(new SizeVariant().alterMargins(2, 2, 2, 2))); 51 } 52 53 @Override 54 protected AquaPainter<? extends JRSUIState> createPainter() { 55 JRSUIState state = JRSUIState.getInstance(); 56 state.set(Widget.FRAME_LIST_BOX); 57 return AquaPainter.<JRSUIState>create(state, 7, 7, 3, 3, 3, 3); 58 } 59 60 public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) { 61 final State state = getState((JComponent)c); 62 painter.state.set(state); 63 painter.state.set(isFocused(c) && state == State.ACTIVE ? Focused.YES : Focused.NO); 64 painter.paint(g, c, x, y, width, height); 65 } 66 67 protected State getState(final JComponent c) { 68 if (!AquaFocusHandler.isActive(c)) return State.INACTIVE; 69 if (!c.isEnabled()) return State.DISABLED; 70 return State.ACTIVE; 71 } 72} 73