2
* Copyright (c) 2014 Jared González
4
* Permission is hereby granted, free of charge, to any
5
* person obtaining a copy of this software and associated
6
* documentation files (the "Software"), to deal in the
7
* Software without restriction, including without limitation
8
* the rights to use, copy, modify, merge, publish,
9
* distribute, sublicense, and/or sell copies of the
10
* Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
13
* The above copyright notice and this permission notice
14
* shall be included in all copies or substantial portions of
17
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
18
* KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
19
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
20
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
21
* OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
package com.jarego.jayatana.swing;
28
import com.jarego.jayatana.Feature;
29
import com.sun.java.swing.plaf.gtk.GTKLookAndFeel;
31
import java.beans.PropertyChangeEvent;
32
import java.beans.PropertyChangeListener;
33
import java.lang.reflect.Field;
34
import java.util.logging.Level;
35
import java.util.logging.Logger;
37
import javax.swing.JComponent;
38
import javax.swing.UIManager;
39
import javax.swing.plaf.synth.Region;
42
* Esta clase es una característica para corregir el borde los menus en GTK los cuales no
43
* se muestran. Esta clase permite incorporar el dibujado de los bordes de estos menús.
45
* @author Jared González
47
@SuppressWarnings("restriction")
48
public class SwingGTKFixed implements Feature, PropertyChangeListener {
50
* Se despliega la correción del borde de los menús en GTK.
53
public void deploy() {
54
UIManager.addPropertyChangeListener(new SwingGTKFixed());
58
* Identifica si el LookAndFeel cambia a GTK.
61
public void propertyChange(PropertyChangeEvent evt) {
62
if ("lookAndFeel".equals(evt.getPropertyName())) {
63
if (evt.getNewValue() != null ?
64
evt.getNewValue().getClass().getName().contains("GTKLookAndFeel") : false)
66
installGtkThikcness();
67
} catch (Exception e) {
68
Logger.getLogger(SwingGTKFixed.class.getName())
69
.log(Level.WARNING, "can't install gtk border fixed", e);
75
* Establece un borde de 1.
79
private static void installGtkThikcness() throws Exception {
80
JComponent comp = new JComponent() {};
81
changeGtkYThikcness(GTKLookAndFeel.getStyle(comp , Region.POPUP_MENU), 1);
82
changeGtkXThikcness(GTKLookAndFeel.getStyle(comp, Region.POPUP_MENU), 1);
83
changeGtkYThikcness(GTKLookAndFeel.getStyle(comp, Region.POPUP_MENU_SEPARATOR), 1);
86
* Cambia el borde vertical de los menús en al menos 1 si es que el valor inicial es 0.
88
* @param style controlador de estilo.
89
* @param border tamaño del borde.
90
* @throws Exception En caso de que falle al acceder al attributo.
92
private static void changeGtkYThikcness(Object style, int border)
94
Field field = style.getClass().getDeclaredField("yThickness");
95
field.setAccessible(true);
96
field.setInt(style, Math.max(border, field.getInt(style)));
97
field.setAccessible(false);
100
* Cambia el borde horizontal de los menús en al menos 1 si es que el valor inicial es 0.
102
* @param style controlador de estilo.
103
* @param border tamaño del borde.
104
* @throws Exception En caso de que falle al acceder al attributo.
106
private static void changeGtkXThikcness(Object style, int border)
108
Field field = style.getClass().getDeclaredField("xThickness");
109
field.setAccessible(true);
110
field.setInt(style, Math.max(border, field.getInt(style)));
111
field.setAccessible(false);