() {
81 | @Override
82 | protected void done() {
83 | try {
84 | Boolean result = get();
85 | if (result) {
86 | catDashTemplate.getBFavourite().setIcon(
87 | catDashTemplate.getFavouriteImage(2)
88 | );
89 | catDashTemplate.getBFavourite().setEnabled(false);
90 | homeComponent.updateFavouriteList();
91 | JOptionPane.showMessageDialog(null, "Guardado Exitoso", "Advertencia", 1);
92 | }
93 | } catch (InterruptedException | ExecutionException ex) {
94 | System.out.println(ex);
95 | }
96 | }
97 |
98 | @Override
99 | protected Boolean doInBackground() throws Exception {
100 | return sCat.saveFavourite(cat);
101 | }
102 | };
103 | worker.execute();
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/client/components/catDash/CatDashTemplate.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.client.components.catDash;
2 |
3 | import java.awt.Color;
4 | import java.awt.Image;
5 |
6 | import javax.swing.ImageIcon;
7 | import javax.swing.JButton;
8 | import javax.swing.JLabel;
9 | import javax.swing.JPanel;
10 |
11 | import com.mycompany.catapp.services.graphicServices.ObjGraficosService;
12 | import com.mycompany.catapp.services.graphicServices.RecursosService;
13 |
14 | public class CatDashTemplate extends JPanel{
15 | private static final long serialVersionUID = 1L;
16 |
17 | // Declaracion inyeccion y servicios
18 | private CatDashComponent catDashComponent;
19 | private ObjGraficosService sObjGraphics;
20 | private RecursosService sResources;
21 |
22 | // Declaracion objetos graficos
23 | private JLabel lCatImage, lLoader, lTitle, lSubTitle, lText;
24 | private JButton bFavourite, bNext;
25 |
26 | // Declaracion Objetos Decoradores
27 | private ImageIcon iLoader, iFavouriteD, iFavouriteF, iNext, iDimAux;
28 |
29 | public CatDashTemplate(CatDashComponent catDashComponent) {
30 | this.catDashComponent = catDashComponent;
31 | sObjGraphics = ObjGraficosService.getService();
32 | sResources = RecursosService.getService();
33 |
34 | this.createDecoratorObjects();
35 | this.createJLabels();
36 | this.createJButtons();
37 |
38 | this.setSize(500, 590);
39 | this.setLayout(null);
40 | this.setBackground(Color.WHITE);
41 | this.setVisible(true);
42 | }
43 |
44 | public void createDecoratorObjects() {
45 | iLoader = new ImageIcon("assets/images/loader.gif");
46 | iFavouriteD = new ImageIcon("assets/images/favouriteD.png");
47 | iFavouriteF = new ImageIcon("assets/images/favouriteF.png");
48 | iNext = new ImageIcon("assets/images/next.png");
49 | }
50 |
51 | public void createJLabels() {
52 | lTitle = sObjGraphics.construirJLabel(
53 | "¿Te gusta este Mishi?",
54 | 0, 50, 500, 40,
55 | null, null,
56 | sResources.getFontSubtitulo(),
57 | null, sResources.getColorGrisOscuro(),
58 | null,
59 | "c"
60 | );
61 | this.add(lTitle);
62 |
63 | lCatImage = sObjGraphics.construirJLabel(
64 | null,
65 | (500 - 350) / 2, 100, 350, 250,
66 | null, null, null, null, null,
67 | sResources.getBordeRedondeado(),
68 | "c"
69 | );
70 | lCatImage.setVisible(false);
71 | this.add(lCatImage);
72 |
73 | lLoader = sObjGraphics.construirJLabel(
74 | null,
75 | (500 - 200) / 2, 125, 200, 200,
76 | null,
77 | iLoader,
78 | null, null, null,
79 | sResources.getBordeRedondeado(),
80 | "c"
81 | );
82 | lLoader.setVisible(false);
83 | this.add(lLoader);
84 |
85 | lSubTitle = sObjGraphics.construirJLabel(
86 | "Ayuda a un mishi",
87 | 0, 400, 500, 40,
88 | null, null,
89 | sResources.getFontSubtitulo(),
90 | null, sResources.getColorGrisOscuro(),
91 | null,
92 | "c"
93 | );
94 | this.add(lSubTitle);
95 |
96 | lText = sObjGraphics.construirJLabel(
97 | "" +
98 | "Este es un proyecto creado desde la fundacion Java" +
99 | "el cual pretende ayudar a todos los gatitos sun hogar" +
100 | "para que tengan proteccion, salud y cariño," +
101 | "para mas informacion enrta a www.fudacioncatjava.com" +
102 | "
",
103 | (500 - 400) / 2, 435, 400, 80,
104 | null, null,
105 | sResources.getFontPequeña(),
106 | null, sResources.getColorGrisOscuro(),
107 | null,
108 | "c"
109 | );
110 | this.add(lText);
111 | }
112 |
113 | public void createJButtons() {
114 | iDimAux = new ImageIcon(iFavouriteD.getImage()
115 | .getScaledInstance(40, 40, Image.SCALE_AREA_AVERAGING)
116 | );
117 |
118 | bFavourite = sObjGraphics.construirJButton(
119 | null,
120 | ((500 - 40) / 2) - 50, 350, 40, 40,
121 | sResources.getCMano(),
122 | iDimAux,
123 | null, null, null, null,
124 | "c",
125 | false
126 | );
127 | bFavourite.setEnabled(false);
128 | bFavourite.addActionListener(catDashComponent);
129 | this.add(bFavourite);
130 |
131 | iDimAux = new ImageIcon(iNext.getImage()
132 | .getScaledInstance(40, 40, Image.SCALE_AREA_AVERAGING)
133 | );
134 |
135 | bNext = sObjGraphics.construirJButton(
136 | null,
137 | ((500 - 40) / 2) + 50, 350, 40, 40,
138 | sResources.getCMano(),
139 | iDimAux,
140 | null, null, null, null,
141 | "c",
142 | false
143 | );
144 | bNext.addActionListener(catDashComponent);
145 | this.add(bNext);
146 | }
147 |
148 | public void insertImage(Image image) {
149 | iDimAux = new ImageIcon(
150 | image.getScaledInstance(350, 250, Image.SCALE_AREA_AVERAGING)
151 | );
152 | lCatImage.setIcon(iDimAux);
153 | bFavourite.setIcon(this.getFavouriteImage(1));
154 | bFavourite.setEnabled(true);
155 | lLoader.setVisible(false);
156 | lCatImage.setVisible(true);
157 | }
158 |
159 | public JButton getBFavourite() { return bFavourite; }
160 |
161 | public JButton getBNext() { return bNext; }
162 |
163 | public JLabel getLCatImage() { return lCatImage; }
164 |
165 | public JLabel getLLoader() { return lLoader; }
166 |
167 | public ImageIcon getFavouriteImage (int option) {
168 | if (option == 1) {
169 | iDimAux = new ImageIcon(iFavouriteD.getImage()
170 | .getScaledInstance(40, 40, Image.SCALE_AREA_AVERAGING)
171 | );
172 | }
173 | if (option == 2) {
174 | iDimAux = new ImageIcon(iFavouriteF.getImage()
175 | .getScaledInstance(40, 40, Image.SCALE_AREA_AVERAGING)
176 | );
177 | }
178 | return iDimAux;
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/client/components/catList/CatListComponent.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.client.components.catList;
2 |
3 | import javax.imageio.ImageIO;
4 | import javax.swing.SwingWorker;
5 |
6 | import java.awt.Image;
7 | import java.net.URL;
8 | import java.util.concurrent.ExecutionException;
9 |
10 | import com.mycompany.catapp.models.FavouriteCat;
11 | import com.mycompany.catapp.services.logicServices.CatService;
12 |
13 | public class CatListComponent {
14 | private CatListTemplate catListTemplate;
15 | private CatService sCat;
16 | private FavouriteCat[] favouriteCatList;
17 |
18 | public CatListComponent() {
19 | sCat = CatService.getService();
20 | this.catListTemplate = new CatListTemplate(this);
21 | getFavouriteCatList();
22 | }
23 |
24 | public void getFavouriteCatList() {
25 | SwingWorker worker = new SwingWorker() {
26 | @Override
27 | protected void done() {
28 | try {
29 | favouriteCatList = get();
30 | try {
31 | for(FavouriteCat cat: favouriteCatList) {
32 | Image image = null;
33 | URL url = new URL(cat.getImage().getUrl());
34 | image = ImageIO.read(url);
35 | cat.setCatPicture(image);
36 | }
37 | catListTemplate.createList();
38 | } catch (Exception ex) {
39 | System.out.println(ex);
40 | }
41 | } catch (InterruptedException | ExecutionException ex) {
42 | System.out.println(ex);
43 | }
44 | }
45 |
46 | @Override
47 | protected FavouriteCat[] doInBackground() throws Exception {
48 | return sCat.getFavouriteList();
49 | }
50 | };
51 | worker.execute();
52 | }
53 |
54 | public CatListTemplate getCatListTemplate() {
55 | return catListTemplate;
56 | }
57 |
58 | public FavouriteCat getFavouriteCat(int position) {
59 | try {
60 | return favouriteCatList[position];
61 | } catch (Exception e) {
62 | return null;
63 | }
64 | }
65 |
66 | public int getFavouriteListLen() {
67 | return favouriteCatList.length;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/client/components/catList/CatListTemplate.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.client.components.catList;
2 |
3 | import java.awt.Color;
4 | import java.awt.Image;
5 | import java.awt.GridBagConstraints;
6 | import java.awt.GridBagLayout;
7 |
8 | import javax.swing.ImageIcon;
9 | import javax.swing.JLabel;
10 | import javax.swing.JPanel;
11 | import javax.swing.JScrollPane;
12 | import javax.swing.JTextField;
13 |
14 | import com.mycompany.catapp.client.components.favCat.FavCatComponent;
15 | import com.mycompany.catapp.client.components.favCat.FavCatTemplate;
16 | import com.mycompany.catapp.models.FavouriteCat;
17 | import com.mycompany.catapp.services.graphicServices.GraficosAvanzadosService;
18 | import com.mycompany.catapp.services.graphicServices.ObjGraficosService;
19 | import com.mycompany.catapp.services.graphicServices.RecursosService;
20 |
21 | public class CatListTemplate extends JPanel{
22 | private static final long serialVersionUID = 1L;
23 |
24 | // Declaracion inyeccion y servicios
25 | private CatListComponent catListComponent;
26 | private ObjGraficosService sObjGraphics;
27 | private RecursosService sResources;
28 | private GraficosAvanzadosService sAdvancedGraphics;
29 |
30 | // Declaración LayoutManager
31 | private GridBagLayout lGrid;
32 | private GridBagConstraints gbc;
33 |
34 | // Declaracion objetos graficos
35 | private JPanel pSearch, pContent;
36 | private JTextField tSearch;
37 | private JLabel lSearch;
38 | private JScrollPane pList;
39 |
40 | // Declaracion objetos decoradores
41 | private ImageIcon iSearch, iDimAux;
42 |
43 | public CatListTemplate(CatListComponent catListComponent) {
44 | this.catListComponent = catListComponent;
45 | sObjGraphics = ObjGraficosService.getService();
46 | sResources = RecursosService.getService();
47 | sAdvancedGraphics = GraficosAvanzadosService.getService();
48 | lGrid = new GridBagLayout();
49 | gbc = new GridBagConstraints();
50 |
51 | this.createDecoratorObjects();
52 | this.createSearchContent();
53 |
54 | this.setSize(233, 590);
55 | this.setLayout(null);
56 | this.setBackground(Color.WHITE);
57 | this.setVisible(true);
58 | }
59 |
60 | public void createDecoratorObjects() {
61 | iSearch = new ImageIcon("assets/images/search.png");
62 | }
63 |
64 | public void createSearchContent() {
65 | pSearch = sObjGraphics.construirJPanel(
66 | 9, 10, 215, 40,
67 | sResources.getColorGrisClaro(),
68 | sResources.getBordeRedondeadoLineal()
69 | );
70 | this.add(pSearch);
71 |
72 | tSearch = sObjGraphics.construirJTextField(
73 | "Buscar Favoritos",
74 | 20, 12, 155, 20,
75 | sResources.getFontPequeña(),
76 | sResources.getColorGrisClaro(),
77 | sResources.getColorGrisOscuro(),
78 | sResources.getColorGrisOscuro(),
79 | null,
80 | "l"
81 | );
82 | pSearch.add(tSearch);
83 |
84 | iDimAux = new ImageIcon(iSearch.getImage()
85 | .getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
86 | );
87 | lSearch = sObjGraphics.construirJLabel(
88 | null,
89 | 180, 7, 25, 25,
90 | sResources.getCMano(),
91 | iDimAux,
92 | null, null, null, null,
93 | "c"
94 | );
95 | pSearch.add(lSearch);
96 | }
97 |
98 | public void createList() {
99 | pContent = null;
100 | pList = null;
101 | pContent = sObjGraphics.construirJPanel(0, 0, 0, 0, Color.WHITE, null);
102 | pContent.setLayout(lGrid);
103 |
104 | int numCat = 0;
105 | gbc.anchor = 11;
106 | FavouriteCat cat = catListComponent.getFavouriteCat(numCat);
107 |
108 | while (cat != null) {
109 | FavCatTemplate pFavCat = new FavCatComponent(catListComponent, cat).getFavCatTemplate();
110 | gbc.gridx = 0;
111 | gbc.gridy = numCat;
112 | if (numCat == (catListComponent.getFavouriteListLen() - 1)) gbc.weighty = 1;
113 | lGrid.setConstraints(pFavCat, gbc);
114 | pContent.add(pFavCat);
115 | numCat++;
116 | gbc.weighty = 0;
117 | cat = catListComponent.getFavouriteCat(numCat);
118 | }
119 |
120 | this.pList = sObjGraphics.construirPanelBarra(pContent, 0, 60, 233, 450, Color.WHITE, null);
121 | this.pList.getVerticalScrollBar().setUI(
122 | sAdvancedGraphics.devolverScrollPersonalizado(
123 | 7, 10,
124 | Color.WHITE,
125 | Color.LIGHT_GRAY,
126 | sResources.getColorGrisOscuro()
127 | )
128 | );
129 | this.add(pList);
130 | this.pList.revalidate();
131 | }
132 |
133 | public JPanel getPContent() { return pContent; }
134 |
135 | public JScrollPane getPList() { return pList; }
136 | }
137 |
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/client/components/favCat/FavCatComponent.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.client.components.favCat;
2 |
3 | import com.mycompany.catapp.client.components.catList.CatListComponent;
4 | import com.mycompany.catapp.models.FavouriteCat;
5 | import com.mycompany.catapp.services.logicServices.CatService;
6 |
7 | import java.awt.event.ActionListener;
8 | import java.util.concurrent.ExecutionException;
9 |
10 | import javax.swing.JOptionPane;
11 | import javax.swing.SwingWorker;
12 |
13 | import java.awt.event.ActionEvent;
14 |
15 | public class FavCatComponent implements ActionListener{
16 |
17 | private FavCatTemplate favCatTemplate;
18 | private FavouriteCat cat;
19 | private CatListComponent catListComponent;
20 | private CatService sCat;
21 |
22 | public FavCatComponent(CatListComponent catListComponent, FavouriteCat cat) {
23 | this.catListComponent = catListComponent;
24 | this.cat = cat;
25 | this.sCat = CatService.getService();
26 | this.favCatTemplate = new FavCatTemplate(this, cat);
27 | }
28 |
29 | public FavCatTemplate getFavCatTemplate() {
30 | return favCatTemplate;
31 | }
32 |
33 | @Override
34 | public void actionPerformed(ActionEvent e) {
35 | this.deleteFavouriteCat();
36 | }
37 |
38 | public void deleteFavouriteCat() {
39 | SwingWorker worker = new SwingWorker() {
40 | @Override
41 | protected void done() {
42 | try {
43 | Boolean result = get();
44 | if (result) {
45 | catListComponent.getCatListTemplate().remove(catListComponent.getCatListTemplate().getPList());
46 | catListComponent.getFavouriteCatList();
47 | JOptionPane.showMessageDialog(null, "Eliminación Exitosa", "Advertencia", 1);
48 | }
49 | } catch (InterruptedException | ExecutionException ex) {
50 | System.out.println(ex);
51 | }
52 | }
53 |
54 | @Override
55 | protected Boolean doInBackground() throws Exception {
56 | return sCat.deleteFavourite(cat);
57 | }
58 | };
59 | worker.execute();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/client/components/favCat/FavCatTemplate.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.client.components.favCat;
2 |
3 | import javax.swing.ImageIcon;
4 | import javax.swing.JButton;
5 | import javax.swing.JLabel;
6 | import javax.swing.JPanel;
7 |
8 | import com.mycompany.catapp.models.FavouriteCat;
9 | import com.mycompany.catapp.services.graphicServices.ObjGraficosService;
10 | import com.mycompany.catapp.services.graphicServices.RecursosService;
11 |
12 | import java.awt.Color;
13 | import java.awt.Image;
14 | import java.awt.Dimension;
15 | import java.awt.GridBagConstraints;
16 | import java.awt.GridBagLayout;
17 |
18 | public class FavCatTemplate extends JPanel{
19 | private static final long serialVersionUID = 1L;
20 |
21 | // Declaración Servicios y dependencias
22 | private FavCatComponent favCatComponent;
23 | private ObjGraficosService sObjGraphics;
24 | private RecursosService sResources;
25 | private FavouriteCat cat;
26 |
27 | // Declaración LayoutManager
28 | private GridBagLayout lGrid;
29 | private GridBagConstraints gbc;
30 |
31 | // Declaración Objetos Gráficos
32 | private JLabel lIdUser, lCreateAt;
33 | private JLabel lImage, lIdUserIcon, lCreateAtIcon;
34 | private JButton bClose;
35 |
36 | // Declaración Objetos Decoradores
37 | private ImageIcon iUser, iDate, iDimAux;
38 |
39 | public FavCatTemplate(FavCatComponent favCatComponent, FavouriteCat cat) {
40 | this.favCatComponent = favCatComponent;
41 | this.sObjGraphics = ObjGraficosService.getService();
42 | this.sResources = RecursosService.getService();
43 | this.cat = cat;
44 |
45 | lGrid = new GridBagLayout();
46 | gbc = new GridBagConstraints();
47 | this.setLayout(lGrid);
48 |
49 | createDecoratorObjects();
50 | createJLabels();
51 | createJButtons();
52 |
53 | this.setPreferredSize(new Dimension(215, 80));
54 | this.setBackground(Color.WHITE);
55 | this.setVisible(true);
56 | }
57 |
58 | public void createDecoratorObjects() {
59 | iUser = new ImageIcon("assets/images/user.png");
60 | iDate = new ImageIcon("assets/images/date.png");
61 | }
62 |
63 | public void createJLabels() {
64 | iDimAux = new ImageIcon(cat.getCatPicture().getImage()
65 | .getScaledInstance(55, 55, Image.SCALE_AREA_AVERAGING)
66 | );
67 | // LABEL IMAGE -----------------------------------------------------------
68 | lImage = sObjGraphics.construirJLabel(
69 | null,
70 | 0, 0, 0, 0,
71 | null,
72 | iDimAux,
73 | null, null, null,
74 | sResources.getBordeCircular(),
75 | "c"
76 | );
77 | modificarGbc(0, 0, 1, 2, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0);
78 | this.add(lImage, gbc);
79 |
80 | // LABEL L_ID_USER_ICON -----------------------------------------------------------
81 | iDimAux = new ImageIcon(iUser.getImage()
82 | .getScaledInstance(15, 15, Image.SCALE_AREA_AVERAGING)
83 | );
84 | lIdUserIcon = sObjGraphics.construirJLabel(
85 | null,
86 | 0, 0, 0, 0,
87 | null,
88 | iDimAux,
89 | null, null, null, null,
90 | "c"
91 | );
92 | modificarGbc(1, 0, 1, 1, 0, 10, 10, 0, 0, 0, 0, 0, 1, 0);
93 | this.add(lIdUserIcon, gbc);
94 |
95 | // LABEL L_DATE -----------------------------------------------------------
96 | iDimAux = new ImageIcon(iDate.getImage()
97 | .getScaledInstance(15, 15, Image.SCALE_AREA_AVERAGING)
98 | );
99 | lCreateAtIcon = sObjGraphics.construirJLabel(
100 | null,
101 | 0, 0, 0, 0,
102 | null,
103 | iDimAux,
104 | null, null, null, null,
105 | "c"
106 | );
107 | modificarGbc(1, 1, 1, 1, 0, 10, 0, 0, 0, 0, 0, 0, 1, 0);
108 | this.add(lCreateAtIcon, gbc);
109 |
110 | // LABEL L_ID_USER -----------------------------------------------------------
111 | lIdUser = sObjGraphics.construirJLabel(
112 | cat.getUserId(),
113 | 0, 0, 0, 0,
114 | null, null,
115 | sResources.getFontPequeña(),
116 | null,
117 | sResources.getColorGrisOscuro(),
118 | null,
119 | "l"
120 | );
121 | modificarGbc(2, 0, 1, 1, 0, 17, 10, 0, 0, 0, 0, 0, 1, 0);
122 | this.add(lIdUser, gbc);
123 |
124 | // LABEL L_CREATE_AT -----------------------------------------------------------
125 | lCreateAt = sObjGraphics.construirJLabel(
126 | cat.getCreateAt().substring(0, 10),
127 | 0, 0, 0, 0,
128 | null, null,
129 | sResources.getFontPequeña(),
130 | null,
131 | sResources.getColorGrisOscuro(),
132 | null,
133 | "l"
134 | );
135 | modificarGbc(2, 1, 1, 1, 0, 17, 0, 0, 0, 0, 0, 0, 1, 0);
136 | this.add(lCreateAt, gbc);
137 | }
138 |
139 | public void createJButtons() {
140 | // BUTTON CLOSE -----------------------------------------------------------------
141 | iDimAux = new ImageIcon(sResources.getIClose().getImage()
142 | .getScaledInstance(12, 12, Image.SCALE_AREA_AVERAGING)
143 | );
144 |
145 | bClose = sObjGraphics.construirJButton(
146 | null,
147 | 0, 0, 0, 0,
148 | sResources.getCMano(),
149 | iDimAux,
150 | null, null, null, null,
151 | "c",
152 | false
153 | );
154 | bClose.addActionListener(favCatComponent);
155 | modificarGbc(3, 0, 1, 2, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0);
156 | this.add(bClose, gbc);
157 | }
158 |
159 | public void modificarGbc(
160 | int posColumna, int posFila,
161 | int numColumnas, int numFilas,
162 | int tipoEstirado,
163 | int posicionInterna,
164 | int marginArriba, int marginDerecha, int marginAbajo, int marginIzquierda,
165 | int paddingX, int paddingY,
166 | int estiramientoColumna, int estiramientoFila
167 | ) {
168 | gbc.gridx = posColumna;
169 | gbc.gridy = posFila;
170 | gbc.gridwidth = numColumnas;
171 | gbc.gridheight = numFilas;
172 | gbc.fill = tipoEstirado;
173 | gbc.anchor = posicionInterna;
174 | gbc.insets.top = marginArriba;
175 | gbc.insets.right = marginDerecha;
176 | gbc.insets.bottom = marginAbajo;
177 | gbc.insets.left = marginIzquierda;
178 | gbc.ipadx = paddingX;
179 | gbc.ipady = paddingY;
180 | gbc.weightx = estiramientoColumna;
181 | gbc.weighty = estiramientoFila;
182 | }
183 | }
184 |
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/client/components/home/HomeComponent.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.client.components.home;
2 |
3 | import com.mycompany.catapp.client.components.catDash.CatDashComponent;
4 | import com.mycompany.catapp.client.components.catList.CatListComponent;
5 |
6 | public class HomeComponent {
7 |
8 | private HomeTemplate homeTemplate;
9 | private CatListComponent catListComponent;
10 | private CatDashComponent catDashComponent;
11 |
12 | public HomeComponent() {
13 | this.homeTemplate = new HomeTemplate(this);
14 | this.catListComponent = new CatListComponent();
15 | this.catDashComponent = new CatDashComponent(this);
16 |
17 | this.homeTemplate.addContent(
18 | catListComponent.getCatListTemplate(), 0, 0
19 | );
20 | this.homeTemplate.addContent(
21 | catDashComponent.getCatDashTemplate(), 233, 0
22 | );
23 | this.homeTemplate.setVisible(true);
24 | }
25 |
26 | public void updateFavouriteList() {
27 | catListComponent.getCatListTemplate().remove(catListComponent.getCatListTemplate().getPList());
28 | catListComponent.getFavouriteCatList();
29 | }
30 |
31 | public HomeTemplate getHomeTemplate() {
32 | return homeTemplate;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/client/components/home/HomeTemplate.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.client.components.home;
2 |
3 | import java.awt.Color;
4 | import java.awt.Dimension;
5 |
6 | import javax.swing.JPanel;
7 |
8 | public class HomeTemplate extends JPanel{
9 | private static final long serialVersionUID = 1L;
10 |
11 | private HomeComponent homeComponent;
12 |
13 | public HomeTemplate(HomeComponent homeComponent) {
14 | this.homeComponent = homeComponent;
15 | this.homeComponent.getClass();
16 |
17 | this.setPreferredSize(new Dimension(733, 400));
18 | this.setLayout(null);
19 | this.setBackground(Color.WHITE);
20 | }
21 |
22 | public void addContent(JPanel panel, int posX, int posY) {
23 | panel.setLocation(posX, posY);
24 | this.add(panel);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/client/components/nav/NavComponent.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.client.components.nav;
2 |
3 | import com.mycompany.catapp.client.mainView.MainViewComponent;
4 |
5 | import java.awt.Color;
6 | import java.awt.event.ActionListener;
7 | import java.awt.event.ActionEvent;
8 | import java.awt.event.MouseAdapter;
9 | import java.awt.event.MouseEvent;
10 |
11 | import javax.swing.JButton;
12 |
13 | public class NavComponent extends MouseAdapter implements ActionListener{
14 | private NavTemplate navTemplate;
15 | private MainViewComponent mainViewComponent;
16 |
17 | public NavComponent(MainViewComponent mainViewComponent) {
18 | this.mainViewComponent = mainViewComponent;
19 | this.navTemplate = new NavTemplate(this);
20 | }
21 |
22 | public NavTemplate getNavTemplate() {
23 | return navTemplate;
24 | }
25 |
26 | @Override
27 | public void mouseEntered(MouseEvent e) {
28 | JButton button = (JButton) e.getSource();
29 | button.setContentAreaFilled(true);
30 | button.setForeground(navTemplate.getResourcesService().getColorAzul());
31 | button.setBackground(Color.WHITE);
32 | button.setIcon(navTemplate.getIBlue(button));
33 | }
34 |
35 | @Override
36 | public void mouseExited(MouseEvent e) {
37 | JButton button = (JButton) e.getSource();
38 | button.setContentAreaFilled(false);
39 | button.setForeground(Color.WHITE);
40 | button.setIcon(navTemplate.getIWhite(button));
41 | }
42 |
43 | @Override
44 | public void actionPerformed(ActionEvent e) {
45 | this.mainViewComponent.showComponents(e.getActionCommand().trim());
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/client/components/nav/NavTemplate.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.client.components.nav;
2 |
3 | import java.awt.Color;
4 | import java.awt.Image;
5 |
6 | import javax.swing.ImageIcon;
7 | import javax.swing.JButton;
8 | import javax.swing.JLabel;
9 | import javax.swing.JPanel;
10 |
11 | import com.mycompany.catapp.services.graphicServices.ObjGraficosService;
12 | import com.mycompany.catapp.services.graphicServices.RecursosService;
13 |
14 | public class NavTemplate extends JPanel{
15 | private static final long serialVersionUID = 1L;
16 |
17 | // Declaración inyección y servicios
18 | private NavComponent navComponent;
19 | private ObjGraficosService sObjGraphics;
20 | private RecursosService sResources;
21 |
22 | // Declaración Objetos Gráficos
23 | private JLabel lLogo, lTitle, lCopy;
24 | private JButton bHome, bProfile, bList, bSettings, bSignOut;
25 |
26 | // Declaración Objetos Decoradores
27 | private ImageIcon iLogo, iDimAux;
28 | private ImageIcon iHomeW, iProfileW, iListW, iSettingsW, iSignOutW;
29 | private ImageIcon iHomeB, iProfileB, iListB, iSettingsB, iSignOutB;
30 |
31 |
32 | public NavTemplate(NavComponent navComponent) {
33 | this.navComponent = navComponent;
34 | sObjGraphics = ObjGraficosService.getService();
35 | sResources = RecursosService.getService();
36 |
37 | createDecoratorObjects();
38 | createJLabels();
39 | createJButtons();
40 |
41 | this.setSize(220, 600);
42 | this.setBackground(sResources.getColorAzul());
43 | this.setLayout(null);
44 | this.setVisible(true);
45 | }
46 |
47 | public void createDecoratorObjects() {
48 | iLogo = new ImageIcon("assets/images/logo.png");
49 | iHomeW = new ImageIcon("assets/images/homeW.png");
50 | iProfileW = new ImageIcon("assets/images/profileW.png");
51 | iListW = new ImageIcon("assets/images/listW.png");
52 | iSettingsW = new ImageIcon("assets/images/settingW.png");
53 | iSignOutW = new ImageIcon("assets/images/signoutW.png");
54 | iHomeB = new ImageIcon("assets/images/homeB.png");
55 | iProfileB = new ImageIcon("assets/images/profileB.png");
56 | iListB = new ImageIcon("assets/images/listB.png");
57 | iSettingsB = new ImageIcon("assets/images/settingB.png");
58 | iSignOutB = new ImageIcon("assets/images/signoutB.png");
59 | }
60 |
61 | public void createJLabels() {
62 | iDimAux = new ImageIcon(iLogo.getImage()
63 | .getScaledInstance(40, 40, Image.SCALE_AREA_AVERAGING)
64 | );
65 |
66 | lLogo = sObjGraphics.construirJLabel(
67 | null,
68 | 30, 35, 40, 40,
69 | sResources.getCMano(),
70 | iDimAux,
71 | null, null, null, null,
72 | "c"
73 | );
74 | this.add(lLogo);
75 |
76 | lTitle = sObjGraphics.construirJLabel(
77 | "CatApp",
78 | 80, 30, 120, 50,
79 | sResources.getCMano(),
80 | null,
81 | sResources.getFontTitulo(),
82 | null,
83 | Color.WHITE,
84 | null,
85 | "l"
86 | );
87 | this.add(lTitle);
88 |
89 | lCopy = sObjGraphics.construirJLabel(
90 | " © 2020 - Derechos reservados CrissUD - Cristian Patiño
",
91 | 20, 530, 180, 30,
92 | null, null,
93 | sResources.getFontPequeña(),
94 | null,
95 | Color.WHITE,
96 | null,
97 | "c"
98 | );
99 | this.add(lCopy);
100 | }
101 |
102 | public void createJButtons() {
103 | // BUTTON HOME -----------------------------------------------------------------
104 | iDimAux = new ImageIcon(iHomeW.getImage()
105 | .getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
106 | );
107 |
108 | bHome = sObjGraphics.construirJButton(
109 | " Inicio",
110 | 40, 160, 200, 45,
111 | sResources.getCMano(),
112 | iDimAux,
113 | sResources.getFontBotones(),
114 | null,
115 | Color.WHITE,
116 | sResources.getBordeRedondeadoBoton(),
117 | "l",
118 | false
119 | );
120 | bHome.addActionListener(navComponent);
121 | bHome.addMouseListener(navComponent);
122 | this.add(bHome);
123 |
124 | // BUTTON PROFILE -----------------------------------------------------------------
125 | iDimAux = new ImageIcon(iProfileW.getImage()
126 | .getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
127 | );
128 |
129 | bProfile = sObjGraphics.construirJButton(
130 | " Perfil",
131 | 40, 220, 200, 45,
132 | sResources.getCMano(),
133 | iDimAux,
134 | sResources.getFontBotones(),
135 | null,
136 | Color.WHITE,
137 | sResources.getBordeRedondeadoBoton(),
138 | "l",
139 | false
140 | );
141 | bProfile.addActionListener(navComponent);
142 | bProfile.addMouseListener(navComponent);
143 | this.add(bProfile);
144 |
145 | // BUTTON LISTS -----------------------------------------------------------------
146 | iDimAux = new ImageIcon(iListW.getImage()
147 | .getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
148 | );
149 |
150 | bList = sObjGraphics.construirJButton(
151 | " Listas",
152 | 40, 280, 200, 45,
153 | sResources.getCMano(),
154 | iDimAux,
155 | sResources.getFontBotones(),
156 | null,
157 | Color.WHITE,
158 | sResources.getBordeRedondeadoBoton(),
159 | "l",
160 | false
161 | );
162 | bList.addActionListener(navComponent);
163 | bList.addMouseListener(navComponent);
164 | this.add(bList);
165 |
166 | // BUTTON SETINGS -----------------------------------------------------------------
167 | iDimAux = new ImageIcon(iSettingsW.getImage()
168 | .getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
169 | );
170 |
171 | bSettings = sObjGraphics.construirJButton(
172 | " Ajustes",
173 | 40, 340, 200, 45,
174 | sResources.getCMano(),
175 | iDimAux,
176 | sResources.getFontBotones(),
177 | null,
178 | Color.WHITE,
179 | sResources.getBordeRedondeadoBoton(),
180 | "l",
181 | false
182 | );
183 | bSettings.addActionListener(navComponent);
184 | bSettings.addMouseListener(navComponent);
185 | this.add(bSettings);
186 |
187 | // BUTTON SIGN OUT -----------------------------------------------------------------
188 | iDimAux = new ImageIcon(iSignOutW.getImage()
189 | .getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
190 | );
191 |
192 | bSignOut = sObjGraphics.construirJButton(
193 | " Ajustes",
194 | 40, 400, 200, 45,
195 | sResources.getCMano(),
196 | iDimAux,
197 | sResources.getFontBotones(),
198 | null,
199 | Color.WHITE,
200 | sResources.getBordeRedondeadoBoton(),
201 | "l",
202 | false
203 | );
204 | bSignOut.addActionListener(navComponent);
205 | bSignOut.addMouseListener(navComponent);
206 | this.add(bSignOut);
207 | }
208 |
209 | public RecursosService getResourcesService(){ return sResources; }
210 |
211 | public ImageIcon getIWhite(JButton button) {
212 | if (button == bHome)
213 | iDimAux = new ImageIcon(
214 | iHomeW.getImage().getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
215 | );
216 | if (button == bProfile)
217 | iDimAux = new ImageIcon(
218 | iProfileW.getImage().getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
219 | );
220 | if (button == bList)
221 | iDimAux = new ImageIcon(
222 | iListW.getImage().getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
223 | );
224 | if (button == bSettings)
225 | iDimAux = new ImageIcon(
226 | iSettingsW.getImage().getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
227 | );
228 | if (button == bSignOut)
229 | iDimAux = new ImageIcon(
230 | iSignOutW.getImage().getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
231 | );
232 | return iDimAux;
233 | }
234 |
235 | public ImageIcon getIBlue(JButton button) {
236 | if (button == bHome)
237 | iDimAux = new ImageIcon(
238 | iHomeB.getImage().getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
239 | );
240 | if (button == bProfile)
241 | iDimAux = new ImageIcon(
242 | iProfileB.getImage().getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
243 | );
244 | if (button == bList)
245 | iDimAux = new ImageIcon(
246 | iListB.getImage().getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
247 | );
248 | if (button == bSettings)
249 | iDimAux = new ImageIcon(
250 | iSettingsB.getImage().getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
251 | );
252 | if (button == bSignOut)
253 | iDimAux = new ImageIcon(
254 | iSignOutB.getImage().getScaledInstance(25, 25, Image.SCALE_AREA_AVERAGING)
255 | );
256 | return iDimAux;
257 | }
258 | }
259 |
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/client/mainView/MainViewComponent.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.client.mainView;
2 |
3 | import com.mycompany.catapp.client.components.bar.BarComponent;
4 | import com.mycompany.catapp.client.components.home.HomeComponent;
5 | import com.mycompany.catapp.client.components.nav.NavComponent;
6 |
7 | import java.awt.Frame;
8 |
9 | public class MainViewComponent {
10 |
11 | private MainViewTemplate mainViewTemplate;
12 | private NavComponent navComponent;
13 | private BarComponent barComponent;
14 | private HomeComponent homeComponent;
15 |
16 | public MainViewComponent () {
17 | this.mainViewTemplate = new MainViewTemplate(this);
18 | this.navComponent = new NavComponent(this);
19 | this.barComponent = new BarComponent(this);
20 | this.homeComponent = new HomeComponent();
21 |
22 | mainViewTemplate.getPNav()
23 | .add(navComponent.getNavTemplate());
24 | mainViewTemplate.getPBar()
25 | .add(barComponent.getBarTemplate());
26 | mainViewTemplate.createContent(
27 | homeComponent.getHomeTemplate()
28 | );
29 |
30 | mainViewTemplate.setVisible(true);
31 | }
32 |
33 | public MainViewTemplate getMainViewTemplate () {
34 | return mainViewTemplate;
35 | }
36 |
37 | public void showComponents(String command) {
38 |
39 | }
40 |
41 | public void moveWindow(int posX, int posY) {
42 | this.mainViewTemplate.setLocation(posX, posY);
43 | }
44 |
45 | public void minWindow() {
46 | this.mainViewTemplate.setExtendedState(Frame.ICONIFIED);
47 | }
48 |
49 | public void closeWindow() {
50 | System.exit(0);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/client/mainView/MainViewTemplate.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.client.mainView;
2 |
3 | import java.awt.Color;
4 | // import java.awt.Dimension;
5 |
6 | import javax.swing.JFrame;
7 | import javax.swing.JPanel;
8 | import javax.swing.JScrollPane;
9 |
10 | import com.mycompany.catapp.services.graphicServices.GraficosAvanzadosService;
11 | import com.mycompany.catapp.services.graphicServices.ObjGraficosService;
12 | import com.mycompany.catapp.services.graphicServices.RecursosService;
13 |
14 | public class MainViewTemplate extends JFrame{
15 | private static final long serialVersionUID = 1L;
16 |
17 | //Declaración servicios y objetos
18 | private MainViewComponent mainViewComponent;
19 | private ObjGraficosService sObjGraphics;
20 | private RecursosService sResources;
21 | private GraficosAvanzadosService sAdvancedGraphics;
22 |
23 | //Declaración Objetos Gráficos
24 | private JPanel pNav, pBar, pMain;
25 | private JScrollPane pContent;
26 |
27 | public MainViewTemplate (MainViewComponent mainViewComponent) {
28 | this.mainViewComponent = mainViewComponent;
29 | this.mainViewComponent.getClass();
30 | this.sObjGraphics = ObjGraficosService.getService();
31 | this.sResources = RecursosService.getService();
32 | this.sAdvancedGraphics = GraficosAvanzadosService.getService();
33 |
34 | this.createJPanels();
35 | // JPanel pContenido = sObjGraphics.construirJPanel(0, 0, 0, 0, Color.BLUE, null);
36 | // pContenido.setPreferredSize(new Dimension(733, 1200));
37 | // this.createContent(pContenido);
38 |
39 | this.setDefaultCloseOperation(EXIT_ON_CLOSE);
40 | this.setSize(1000, 600);
41 | this.setLocationRelativeTo(this);
42 | this.setLayout(null);
43 | this.setUndecorated(true);
44 | this.getContentPane().setBackground(sResources.getColorAzul());
45 | }
46 |
47 | private void createJPanels() {
48 | this.pMain = sObjGraphics.construirJPanel(219, 5, 776, 590, Color.WHITE, sResources.getBordeRedondeado());
49 | this.add(pMain);
50 |
51 | this.pNav = sObjGraphics.construirJPanel(0, 0, 220, 600, sResources.getColorAzul(), null);
52 | this.add(pNav);
53 |
54 | this.pBar = sObjGraphics.construirJPanel(10, 5, 750, 50, Color.WHITE, null);
55 | pMain.add(pBar);
56 | }
57 |
58 | public void createContent(JPanel panel) {
59 | this.pContent = sObjGraphics.construirPanelBarra(panel, 10, 60, 750, 510, Color.WHITE, null);
60 | this.pContent.getVerticalScrollBar().setUI(
61 | sAdvancedGraphics.devolverScrollPersonalizado(
62 | 7, 10,
63 | Color.WHITE,
64 | Color.LIGHT_GRAY,
65 | sResources.getColorGrisOscuro()
66 | )
67 | );
68 | this.pMain.add(pContent);
69 | this.pContent.revalidate();
70 | }
71 |
72 | public JPanel getPNav(){ return pNav; }
73 |
74 | public JPanel getPBar(){ return pBar; }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/models/Cat.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.models;
2 |
3 | /**
4 | * @author CrissUD / Cristian Patiño
5 | */
6 | public class Cat {
7 | private String id;
8 | private String url;
9 | private String width;
10 | private String height;
11 |
12 | public String getId() { return id; }
13 |
14 | public String getUrl() { return url; }
15 |
16 | public int getWidth() { return Integer.parseInt(width); }
17 |
18 | public int getHeight() { return Integer.parseInt(height); }
19 |
20 | public void setId(String id) {
21 | this.id = id;
22 | }
23 |
24 | public void setUrl(String url) {
25 | this.url = url;
26 | }
27 |
28 | public void setWidth(String width) {
29 | this.width = width;
30 | }
31 |
32 | public void setHeight(String height) {
33 | this.height = height;
34 | }
35 |
36 |
37 | }
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/models/FavouriteCat.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.models;
2 |
3 | import javax.swing.ImageIcon;
4 | import java.awt.Image;
5 |
6 | public class FavouriteCat {
7 | private String id;
8 | private String user_id;
9 | private String image_id;
10 | private String sub_id;
11 | private String created_at;
12 | private CatImage image;
13 | private ImageIcon catPicture;
14 |
15 | public String getId() { return id; }
16 |
17 | public String getUserId() { return user_id; }
18 |
19 | public String getImageId() { return image_id; }
20 |
21 | public String getSubId() { return sub_id; }
22 |
23 | public String getCreateAt() { return created_at; }
24 |
25 | public CatImage getImage() { return image; }
26 |
27 | public ImageIcon getCatPicture() { return catPicture; }
28 |
29 | public void setId(String id) {
30 | this.id = id;
31 | }
32 |
33 | public void setUserId(String user_id) {
34 | this.user_id = user_id;
35 | }
36 |
37 | public void setImageId(String image_id) {
38 | this.image_id = image_id;
39 | }
40 |
41 | public void setSubId(String sub_id) {
42 | this.sub_id = sub_id;
43 | }
44 |
45 | public void setCreateAt(String created_at) {
46 | this.created_at = created_at;
47 | }
48 |
49 | public void setImage(CatImage image) {
50 | this.image = image;
51 | }
52 |
53 | public void setCatPicture(Image catPicture) {
54 | this.catPicture = new ImageIcon(catPicture);
55 | }
56 |
57 | public class CatImage {
58 | private String id;
59 | private String url;
60 |
61 | public String getId() { return id; }
62 |
63 | public String getUrl() { return url; }
64 |
65 | public void setId(String id) {
66 | this.id = id;
67 | }
68 |
69 | public void setUrl(String url) {
70 | this.url = url;
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/services/graphicServices/GraficosAvanzadosService.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.services.graphicServices;
2 |
3 | import java.awt.Color;
4 | import java.awt.Component;
5 | import java.awt.Dimension;
6 | import java.awt.Font;
7 | import java.awt.Graphics;
8 | import java.awt.Graphics2D;
9 | import java.awt.Image;
10 | import java.awt.Insets;
11 | import java.awt.Point;
12 | import java.awt.Rectangle;
13 | import java.awt.RenderingHints;
14 | import java.awt.geom.Area;
15 | import java.awt.geom.Ellipse2D;
16 | import java.awt.geom.RectangularShape;
17 | import java.awt.geom.RoundRectangle2D;
18 |
19 | import javax.swing.BorderFactory;
20 | import javax.swing.DefaultListCellRenderer;
21 | import javax.swing.JButton;
22 | import javax.swing.JComponent;
23 | import javax.swing.JLabel;
24 | import javax.swing.JList;
25 | import javax.swing.JScrollBar;
26 | import javax.swing.JTable;
27 | import javax.swing.ListCellRenderer;
28 | import javax.swing.SwingConstants;
29 | import javax.swing.border.AbstractBorder;
30 | import javax.swing.border.Border;
31 | import javax.swing.plaf.basic.BasicComboBoxUI;
32 | import javax.swing.plaf.basic.BasicScrollBarUI;
33 | import javax.swing.table.DefaultTableCellRenderer;
34 |
35 | /** @author Cristian Felipe Patiño Cáceres Github: CrissUD*/
36 |
37 | public class GraficosAvanzadosService {
38 | private static GraficosAvanzadosService servicio;
39 |
40 | private GraficosAvanzadosService() {}
41 |
42 | /**
43 | * Descripción: Esta función se encarga de personalizar una tabla, tomando cada celda de la tabla y tratandola como si fuera un JLabel para realizar una personalización completa, el estilo de personalización esta basado en el intercalado de filas.
44 | * Para invocarlo se debe llamar al método: setDefaultRenderer() del objeto gráfico JTable o JTableHeader.
45 | * @param colorPrincipal (Color): Color de fondo de las filas impares (1, 3, 5 ...).
46 | * @param colorSecundario (Color): Color de fondo de las filas pares (2, 4, 6 ...).
47 | * @param colorSeleccion (int): Color de fondo de la fila que sea seleccionada por el usuario.
48 | * @param colorFuente (Color): Color de la letra o Foreground de la tabla.
49 | * @param fuente (Font): Fuente de la letra de la tabla.
50 | * @return DefaultTableCellRenderer: Objeto encargado de la personalización de un objeto JTable.
51 | * @throws null : Si no necesita enviar algun color o la fuente envíe un [null] como parámetro.
52 | */
53 | public DefaultTableCellRenderer devolverTablaPersonalizada(
54 | Color colorPrincipal, Color colorSecundario, Color colorSeleccion, Color colorFuente, Font fuente
55 | ) {
56 | return new DefaultTableCellRenderer() {
57 | private static final long serialVersionUID = -8946942932242371111L;
58 |
59 | @Override
60 | public Component getTableCellRendererComponent(
61 | JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column
62 | ) {
63 | JLabel celda = (JLabel) super.getTableCellRendererComponent(
64 | table, value, isSelected, hasFocus, row, column
65 | );
66 | celda.setOpaque(true);
67 | celda.setFont(fuente);
68 | celda.setForeground(colorFuente);
69 | celda.setHorizontalAlignment(SwingConstants.CENTER);
70 | if (row % 2 != 0) celda.setBackground(colorPrincipal);
71 | else celda.setBackground(colorSecundario);
72 | if (isSelected) {
73 | celda.setBackground(colorSeleccion);
74 | celda.setForeground(Color.WHITE);
75 | }
76 | return celda;
77 | }
78 | };
79 | }
80 |
81 | /**
82 | * Descripción: Esta función se encarga de personalizar un objeto tipo JScrollBar. El modelo que retorna esta basado en un ScrollBar sin botones esquineros y con la posibilidad de devolver un Thumb personalizado.
83 | * Para invocarlo se debe llamar al método: setUI() del objeto gráfico JScrollBar.
84 | * @param grosor (int): Grosor del Thumb o barra de navegación (no se recomiendan valores mayores a 15).
85 | * @param radio (int): Valor del arco en las esquinas del Thumb siendo 0 un arco nulo y con valores mayores se crean bordes redonreados al Thumb (no se recomiendan valores mayores a 15).
86 | * @param colorFondo (Color): Color de fondo (Background) del Track del JScrollBar.
87 | * @param colorBarraNormal (Color): Color de fondo (Background) del Thumb del JScrollBar cuando no se esta usando.
88 | * @param colorBarraArrastrada (Color): Color de fondo (Background) del Thumb del JScrollBar cuando se esta arrastrando a traves del mouse.
89 | * @return BasicScrollBarUI: Objeto encargado de la personalización de un objeto JScrollBar.
90 | * @throws null : Si no necesita enviar algun color envíe un [null] como parámetro.
91 | */
92 | public BasicScrollBarUI devolverScrollPersonalizado(
93 | int grosor, int radio, Color colorFondo, Color colorBarraNormal, Color colorBarraArrastrada
94 | ) {
95 | return new BasicScrollBarUI() {
96 | private Dimension d = new Dimension();
97 |
98 | @Override
99 | protected JButton createDecreaseButton(int orientation) {
100 | JButton boton = new JButton();
101 | boton.setPreferredSize(d);
102 | return boton;
103 | }
104 |
105 | @Override
106 | protected JButton createIncreaseButton(int orientation) {
107 | JButton boton = new JButton();
108 | boton.setPreferredSize(d);
109 | return boton;
110 | }
111 |
112 | @Override
113 | protected void paintTrack(Graphics g, JComponent c, Rectangle r) {
114 | g.setColor(colorFondo);
115 | g.fillRect(r.x, r.y, r.width, r.height);
116 | }
117 |
118 | @Override
119 | protected void paintThumb(Graphics g, JComponent c, Rectangle r) {
120 | Graphics2D g2 = (Graphics2D) g.create();
121 | g2.setRenderingHint(
122 | RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON
123 | );
124 | JScrollBar sb = (JScrollBar) c;
125 | if (!sb.isEnabled()) return;
126 | else if (isDragging) g2.setPaint(colorBarraArrastrada);
127 | else if (isThumbRollover()) g2.setPaint(colorBarraNormal);
128 | else g2.setPaint(colorBarraNormal);
129 |
130 | if (r.width < r.height) g2.fillRoundRect(
131 | (r.width - grosor) / 2, r.y, grosor, r.height, radio, radio
132 | );
133 | else
134 | g2.fillRoundRect(
135 | r.x, (r.height - grosor) / 2, r.width, grosor, radio, radio
136 | );
137 | }
138 | };
139 | }
140 |
141 | /**
142 | * Descripción: Esta función se encarga de personalizar un objeto tipo JComboBox. El modelo que retorna esta basado en un comboBox con boton personalizado, borde personalizado y color de fondo.
143 | * Para invocarlo se debe llamar al método: setUI() del objeto gráfico JComboBox.
144 | * @param boton (JButton): Botón del comboBox situado a la derecha encargado de desplegar la información.
145 | * @param colorBorde (Color): Color de borde en caso de de crear un comboBox sin fondo.
146 | * @param colorFondo (Color): Color de fondo (Background) del valor actual seleccionado del comboBox.
147 | * @param colorSeleccionMenu (Color): Color de fondo de las opciones dentro del popMenu una ves se pasa encima con el cursor.
148 | * @param colorFuenteMenu (Color): Color de fuente (Foreground) las opciones dentro del popMenu del comboBox (es diferente al color de fuente que esta en la selección actual).
149 | * @param esSolido booleano que indica si el comboBox tiene color de Fondo en la selección actual (true) si se deja en (false) obtendra el color de fondo por defecto que tiene el comboBox.
150 | * @return BasicScrollBarUI: Objeto encargado de la personalización de un objeto JScrollBar.
151 | * @throws null : Si no necesita enviar algun color envíe un [null] como parámetro.
152 | */
153 | public BasicComboBoxUI devolverJComboBoxPersonalizado(
154 | JButton boton, Color colorBorde, Color colorFondo, Color colorSeleccionMenu, Color colorFuenteMenu, boolean esSolido
155 | ) {
156 | return new BasicComboBoxUI() {
157 |
158 | @Override
159 | protected JButton createArrowButton() {
160 | return boton;
161 | }
162 |
163 | @Override
164 | public void paintCurrentValueBackground(
165 | Graphics g, Rectangle bounds, boolean hasFocus
166 | ) {
167 | g.setColor(colorBorde);
168 | g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height - 1);
169 | g.drawRect(
170 | bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 3
171 | );
172 | if (esSolido) {
173 | g.setColor(colorFondo);
174 | g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
175 | }
176 | }
177 |
178 | @Override
179 | protected ListCellRenderer createRenderer() {
180 | return new DefaultListCellRenderer() {
181 | private static final long serialVersionUID = 1L;
182 |
183 | @Override
184 | public Component getListCellRendererComponent(
185 | JList> list, Object value, int index, boolean isSelected, boolean cellHasFocus
186 | ) {
187 | super.getListCellRendererComponent(
188 | list, value, index, isSelected, cellHasFocus
189 | );
190 | this.setHorizontalAlignment(SwingConstants.CENTER);
191 | list.setSelectionBackground(colorSeleccionMenu);
192 | list.setSelectionForeground(Color.WHITE);
193 | if (!isSelected) this.setForeground(colorFuenteMenu);
194 | return this;
195 | }
196 | };
197 | }
198 | };
199 | }
200 |
201 | /**
202 | * Descripción: Esta función se encarga de crear un borde difuminado, [version BETA] se recomienda usar colores claros (por encima de 200 en los canales RGB).
203 | * Para invocarlo se debe llamar al método: setBorder() de cualquier objeto Gráfico.
204 | * @param colorBase (Color): Color con el que inicia el borde y con el que empieza la difuminación.
205 | * @param grosor (int): Grosor del borde (no se recomiendan valores superiores a 10) para objetos gráficos pequeños. Tener en cuenta que el grosor del borde se expande de forma interna en el objeto gráfico.
206 | * @return Border: Objeto decorador tipo Border.
207 | */
208 | public Border devolverBordeDifuminado(Color colorBase, int grosor) {
209 | Border bordeFinal = null;
210 | Border bordeInicial = BorderFactory.createLineBorder(colorBase, 1, true);
211 | Color siguienteColor = new Color(
212 | colorBase.getRed() + 5, colorBase.getGreen() + 5, colorBase.getBlue() + 5
213 | );
214 | int contador = 0;
215 | while (
216 | siguienteColor.getRed() < 251 &&
217 | siguienteColor.getGreen() < 251 &&
218 | siguienteColor.getBlue() < 251 &&
219 | contador < grosor
220 | ) {
221 | Border bordeExterno = BorderFactory.createLineBorder(
222 | siguienteColor, 1, true
223 | );
224 | if (contador == 0)
225 | bordeFinal = BorderFactory.createCompoundBorder(bordeExterno, bordeInicial);
226 | else
227 | bordeFinal = BorderFactory.createCompoundBorder(bordeExterno, bordeFinal);
228 | siguienteColor = new Color(
229 | siguienteColor.getRed() + 5, siguienteColor.getGreen() + 5, siguienteColor.getBlue() + 5
230 | );
231 | contador++;
232 | }
233 | return bordeFinal;
234 | }
235 |
236 | /**
237 | * Descripción: Esta función se encarga de crear un borde con esquinas redondeadas.
238 | * Para invocarlo se debe llamar al método: setBorder() de cualquier objeto Gráfico.
239 | * @param colorBorde (Color): Color del contonro del borde en caso de crear el borde lineal.
240 | * @param radio (int): Valor del arco en las esquinas del borde siendo 0 un arco nulo y con valores mayores se crean bordes redonreados.
241 | * @param esLineal (boolean): Si quiere crear un borde con contorno o borde lineal se envia el valor (true), en caso de solo crear la forma del borde sin contorno se envia el valor (false).
242 | * @param imagenFondo (ImageIcon): En caso de que el objeto Gráfico que obtenga el borde este situado encima de una imágen de fondo se debe enviar la imágen con las mismas dimensiones para crear el efecto de transparencia en las esquinas redondeadas.
243 | * @return Border: Objeto decorador tipo Border.
244 | * @throws null : Si no necesita enviar colorBorde o imagenFondo envíe un [null] como parámetro.
245 | */
246 | public Border DibujarBordeRedondeado(
247 | Color colorBorde, int radio, boolean esLineal, Image imagenFondo
248 | ) {
249 | Border bordeRedondeado = new Border() {
250 |
251 | @Override
252 | public void paintBorder(
253 | Component c, Graphics g, int x, int y, int ancho, int alto
254 | ) {
255 | Graphics2D g2 = (Graphics2D) g;
256 | g2.setRenderingHint(
257 | RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON
258 | );
259 | Area area;
260 | Component padreContenedor = c.getParent();
261 | RoundRectangle2D rectanguloBordeado = new RoundRectangle2D.Double();
262 | rectanguloBordeado.setRoundRect(
263 | x, y, ancho - 1, alto - 1, radio, radio
264 | );
265 | if (esLineal) {
266 | dibujarFondo(c, padreContenedor, imagenFondo, g2, ancho, alto);
267 | g2.setColor(c.getBackground());
268 | g2.fill(rectanguloBordeado);
269 | area = dibujarBorde(c, g2, colorBorde, x, y, ancho, alto, rectanguloBordeado);
270 | } else {
271 | area = dibujarBorde(c, g2, colorBorde, x, y, ancho, alto, rectanguloBordeado);
272 | dibujarFondo(c, padreContenedor, imagenFondo, g2, ancho, alto);
273 | }
274 | g2.setClip(null);
275 | g2.draw(area);
276 | }
277 |
278 | @Override
279 | public Insets getBorderInsets(Component c) {
280 | return new Insets(2, 2, 2, 2);
281 | }
282 |
283 | @Override
284 | public boolean isBorderOpaque() {
285 | return false;
286 | }
287 | };
288 | return bordeRedondeado;
289 | }
290 |
291 | /**
292 | * Descripción: Esta función se encarga de crear un borde circular.
293 | * Para invocarlo se debe llamar al método: setBorder() de cualquier objeto Gráfico.
294 | * @param colorBorde (Color): Color del contonro del borde en caso de crear el borde lineal.
295 | * @param esLineal (boolean): Si quiere crear un borde con contorno o borde lineal se envia el valor (true), en caso de solo crear la forma del borde sin contorno se envia el valor (false).
296 | * @param imagenFondo (ImageIcon): En caso de que el objeto Gráfico que obtenga el borde este situado encima de una imágen de fondo se debe enviar la imágen con las mismas dimensiones para crear el efecto de transparencia en las esquinas sobrantes de la circunferencia.
297 | * @return AbstractBorder: Objeto decorador tipo AbstractBorder, compatible con Border.
298 | * @throws null : Si no necesita enviar colorBorde o imagenFondo envíe un [null] como parámetro.
299 | */
300 | public AbstractBorder DibujarBordeCircular(
301 | Color colorBorde, boolean esLineal, Image imagenFondo
302 | ) {
303 | AbstractBorder bordeCircular = new AbstractBorder() {
304 | private static final long serialVersionUID = 2009875951859777681L;
305 |
306 | @Override
307 | public void paintBorder(
308 | Component c, Graphics g, int x, int y, int ancho, int alto
309 | ) {
310 | Graphics2D g2 = (Graphics2D) g;
311 | g2.setRenderingHint(
312 | RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON
313 | );
314 | Area area;
315 | Component padreContenedor = c.getParent();
316 | Ellipse2D circulo = new Ellipse2D.Double();
317 | circulo.setFrameFromCenter(
318 | new Point(x + ancho / 2, y + alto / 2),
319 | new Point(ancho, alto)
320 | );
321 | if (esLineal) {
322 | dibujarFondo(c, padreContenedor, imagenFondo, g2, ancho, alto);
323 | area = dibujarBorde(c, g2, colorBorde, x, y, ancho, alto, circulo);
324 | } else {
325 | area = dibujarBorde(c, g2, colorBorde, x, y, ancho, alto, circulo);
326 | dibujarFondo(c, padreContenedor, imagenFondo, g2, ancho, alto);
327 | }
328 | g2.setClip(null);
329 | g2.draw(area);
330 | }
331 | };
332 | return bordeCircular;
333 | }
334 |
335 | private void dibujarFondo(
336 | Component c, Component padreContenedor, Image imagen, Graphics2D g2, int ancho, int alto
337 | ) {
338 | if (imagen != null)
339 | g2.drawImage(
340 | imagen,
341 | 0, 0,
342 | imagen.getWidth(null), imagen.getHeight(null),
343 | c.getX(), c.getY(),
344 | imagen.getWidth(null) + c.getX(),
345 | imagen.getHeight(null) + c.getY(),
346 | c
347 | );
348 | else {
349 | g2.setColor(padreContenedor.getBackground());
350 | g2.fillRect(0, 0, ancho, alto);
351 | }
352 | }
353 |
354 | private Area dibujarBorde(
355 | Component c, Graphics2D g2, Color color, int x, int y, int ancho, int alto, RectangularShape figura
356 | ) {
357 | if (color == null) g2.setPaint(c.getBackground());
358 | else g2.setPaint(color);
359 | Area area = new Area(figura);
360 | Rectangle rectangulo = new Rectangle(0, 0, ancho, alto);
361 | Area regionBorde = new Area(rectangulo);
362 | regionBorde.subtract(area);
363 | g2.setClip(regionBorde);
364 | return area;
365 | }
366 |
367 | public static GraficosAvanzadosService getService() {
368 | if (servicio == null) servicio = new GraficosAvanzadosService();
369 | return servicio;
370 | }
371 | }
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/services/graphicServices/ObjGraficosService.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.services.graphicServices;
2 |
3 | import java.awt.Color;
4 | import java.awt.Component;
5 | import java.awt.Cursor;
6 | import java.awt.Font;
7 |
8 | import javax.swing.ImageIcon;
9 | import javax.swing.JButton;
10 | import javax.swing.JCheckBox;
11 | import javax.swing.JComboBox;
12 | import javax.swing.JLabel;
13 | import javax.swing.JPanel;
14 | import javax.swing.JPasswordField;
15 | import javax.swing.JRadioButton;
16 | import javax.swing.JScrollPane;
17 | import javax.swing.JTextArea;
18 | import javax.swing.JTextField;
19 | import javax.swing.SwingConstants;
20 | import javax.swing.border.Border;
21 |
22 | /** @author Cristian Felipe Patiño Cáceres Github: CrissUD*/
23 |
24 | public class ObjGraficosService {
25 | private JPanel panel;
26 | private JScrollPane panelScroll;
27 | private JButton button;
28 | private JRadioButton radioButton;
29 | private JCheckBox check;
30 | private JLabel label;
31 | private JTextField textField;
32 | private JPasswordField passwordField;
33 | private JTextArea textArea;
34 | private JComboBox comboBox;
35 |
36 | private static ObjGraficosService servicio;
37 |
38 | private ObjGraficosService() {}
39 |
40 | /**
41 | * Descripción: Esta función se encarga de construir un objeto gráfico tipo JPanel.
42 | * @param x (int): Posición inicial en pixeles sobre el eje X.
43 | * @param y (int): Posición inicial en pixeles sobre el eje Y.
44 | * @param ancho (int): Tamaño sobre el eje X en pixeles del panel.
45 | * @param alto (int): Tamaño sobre el eje Y en pixeles del panel.
46 | * @param colorFondo (Color): Color de fondo o Background del panel.
47 | * @param borde (Border): Borde del panel.
48 | * @return panel (JPanel): Objeto gráfico tipo JPanel.
49 | * @throws null : Si construye un JPanel sin color de fondo o borde envíe un [null] como parámetro.
50 | */
51 | public JPanel construirJPanel(
52 | int x, int y, int ancho, int alto, Color colorFondo, Border borde
53 | ) {
54 | panel = new JPanel();
55 | panel.setLocation(x, y);
56 | panel.setSize(ancho, alto);
57 | panel.setLayout(null);
58 | panel.setBackground(colorFondo);
59 | panel.setBorder(borde);
60 | return panel;
61 | }
62 |
63 | /**
64 | * Descripción: Esta función se encarga de construir un objeto gráfico tipo JScrollPane.
65 | * @param componente (Component): Objeto gráfico que contiene el JScrollPane.
66 | * @param x (int): Posición inicial en pixeles sobre el eje X.
67 | * @param y (int): Posición inicial en pixeles sobre el eje Y.
68 | * @param ancho (int): Tamaño sobre el eje X en pixeles del JScrollPane.
69 | * @param alto (int): Tamaño sobre el eje Y en pixeles del JScrollPane.
70 | * @param colorFondo (Color): Color de fondo o Background del JScrollPane.
71 | * @param borde (Border): Borde del JScrollPane.
72 | * @return panelScroll (JPaneScroll): Objeto gráfico tipo JPaneScroll.
73 | * @throws null : Si construye un JScrollPane sin color de fondo o borde envíe un [null] como parámetro.
74 | */
75 | public JScrollPane construirPanelBarra(
76 | Component componente, int x, int y, int ancho, int alto, Color colorFondo, Border borde
77 | ) {
78 | panelScroll = new JScrollPane(componente);
79 | panelScroll.setLocation(x, y);
80 | panelScroll.setSize(ancho, alto);
81 | panelScroll.getViewport().setBackground(colorFondo);
82 | panelScroll.setBorder(borde);
83 | return panelScroll;
84 | }
85 |
86 | /**
87 | * Descripción: Esta función se encarga de construir un objeto gráfico tipo JButton.
88 | * @param texto (String): Texto que contiene el botón.
89 | * @param x (int): Posición inicial en pixeles sobre el eje X.
90 | * @param y (int): Posición inicial en pixeles sobre el eje Y.
91 | * @param ancho (int): Tamaño sobre el eje X en pixeles del botón.
92 | * @param alto (int): Tamaño sobre el eje Y en pixeles del botón.
93 | * @param cursor (Cursor): Tipo de cursor que se muestra al pasar sobre el botón.
94 | * @param imagen (ImageIcon): Imágen que contiene el Botón.
95 | * @param fuente (Font): Tipo de fuente que tendrá el texto del botón.
96 | * @param colorFondo (Color): Color de fondo o Background del botón.
97 | * @param colorFuente (Color): Color de la letra o ForeGround del botón.
98 | * @param borde (Border): Borde del botón.
99 | * @param direccion (String): Dirección de los elementos dentro del botón siendo:
100 | *
101 | * 'c' (CENTER): Contenido centrado (por defecto).
102 | * 't' (TOP): Contenido centrado con texto arriba de una imágen.
103 | * 'l' (LEFT): Contenido en la izquierda [Si tiene imágen y texto la imágen se posiciona primero].
104 | * 'r' (RIGHT): Contenido en la derecha [Si tiene imágen y texto el texto se posiciona primero].
105 | * 'b' (BOTTOM): Contenido centrado con texto abajo de una imágen.
106 | *
107 | * @param esSolido (boolean): Booleano que indica si el boton tiene color de fondo (true) o tiene fondo transparente (false).
108 | * @return boton (JButton): Objeto gráfico tipo JButton.
109 | * @throws null : Si construye un JButton sin texto, cursor, imagen, fuente, colorFondo, colorFuente o borde envíe un [null] como parámetro.
110 | */
111 | public JButton construirJButton(
112 | String texto, int x, int y, int ancho, int alto, Cursor cursor, ImageIcon imagen, Font fuente,
113 | Color colorFondo, Color colorFuente, Border borde, String direccion, boolean esSolido
114 | ) {
115 | button = new JButton(texto);
116 | button.setLocation(x, y);
117 | button.setSize(ancho, alto);
118 | button.setFocusable(false);
119 | button.setCursor(cursor);
120 | button.setFont(fuente);
121 | button.setBackground(colorFondo);
122 | button.setForeground(colorFuente);
123 | button.setIcon(imagen);
124 | button.setBorder(borde);
125 | button.setContentAreaFilled(esSolido);
126 | switch (direccion) {
127 | case "l":
128 | button.setHorizontalAlignment(SwingConstants.LEFT);
129 | button.setVerticalTextPosition(SwingConstants.BOTTOM);
130 |
131 | break;
132 | case "r":
133 | button.setHorizontalAlignment(SwingConstants.RIGHT);
134 | button.setHorizontalTextPosition(SwingConstants.LEFT);
135 | break;
136 | case "t":
137 | button.setVerticalTextPosition(SwingConstants.TOP);
138 | button.setHorizontalTextPosition(SwingConstants.CENTER);
139 | break;
140 | case "b":
141 | button.setVerticalTextPosition(SwingConstants.BOTTOM);
142 | button.setHorizontalTextPosition(SwingConstants.CENTER);
143 | break;
144 | default:
145 | break;
146 | }
147 | return button;
148 | }
149 |
150 | /**
151 | * Descripción: Esta función se encarga de construir un objeto gráfico tipo JRaddioButton.
152 | * @param texto (String): Texto que contiene el radioButton.
153 | * @param x (int): Posición inicial en pixeles sobre el eje X.
154 | * @param y (int): Posición inicial en pixeles sobre el eje Y.
155 | * @param ancho (int): Tamaño sobre el eje X en pixeles del radioButton.
156 | * @param alto (int): Tamaño sobre el eje Y en pixeles del radioButton.
157 | * @param cursor (Cursor): Tipo de cursor que se muestra al pasar sobre el radioButton.
158 | * @param fuente (Font): Tipo de fuente que tendrá el texto del radioButton.
159 | * @param colorFuente (Color): Color de la letra o ForeGround del radioButton.
160 | * @return radioButton (JButton): Objeto gráfico tipo JRadioButton.
161 | * @throws null : Si construye un JRadioButton sin texto, cursor, fuente, o colorFuente envíe un [null] como parámetro.
162 | */
163 | public JRadioButton construirJRadioButton(
164 | String texto, int x, int y, int ancho, int alto, Cursor cursor, Font fuente, Color colorFuente
165 | ) {
166 | radioButton = new JRadioButton(texto);
167 | radioButton.setLocation(x, y);
168 | radioButton.setSize(ancho, alto);
169 | radioButton.setFocusable(false);
170 | radioButton.setBackground(null);
171 | radioButton.setCursor(cursor);
172 | radioButton.setFont(fuente);
173 | radioButton.setForeground(colorFuente);
174 | return radioButton;
175 | }
176 |
177 | /**
178 | * Descripción: Esta función se encarga de construir un objeto gráfico tipo JCheckBox.
179 | * @param texto (String): Texto que contiene el checkBox.
180 | * @param x (int): Posición inicial en pixeles sobre el eje X.
181 | * @param y (int): Posición inicial en pixeles sobre el eje Y.
182 | * @param ancho (int): Tamaño sobre el eje X en pixeles del checkBox.
183 | * @param alto (int): Tamaño sobre el eje Y en pixeles del checkBox.
184 | * @param cursor (Cursor): Tipo de cursor que se muestra al pasar sobre el checkBox.
185 | * @param fuente (Font): Tipo de fuente que tendrá el texto del checkBox.
186 | * @param colorFuente (Color): Color de la letra o ForeGround del checkBox.
187 | * @return check (JCheckBox): Objeto gráfico tipo JCheckBox.
188 | * @throws null : Si construye un JCheckBox sin texto, cursor, fuente, o colorFuente envíe un [null] como parámetro.
189 | */
190 | public JCheckBox construirJCheckBox(
191 | String texto, int x, int y, int ancho, int alto, Cursor cursor, Font fuente, Color colorFuente
192 | ) {
193 | check = new JCheckBox(texto);
194 | check.setLocation(x, y);
195 | check.setSize(ancho, alto);
196 | check.setFocusable(false);
197 | check.setBackground(null);
198 | check.setCursor(cursor);
199 | check.setFont(fuente);
200 | check.setForeground(colorFuente);
201 | return check;
202 | }
203 |
204 | /**
205 | * Descripción: Esta función se encarga de construir un objeto gráfico tipo JLabel.
206 | * @param texto (String): Texto que contiene el label.
207 | * @param x (int): Posición inicial en pixeles sobre el eje X.
208 | * @param y (int): Posición inicial en pixeles sobre el eje Y.
209 | * @param ancho (int): Tamaño sobre el eje X en pixeles del label.
210 | * @param alto (int): Tamaño sobre el eje Y en pixeles del label.
211 | * @param cursor (Cursor): Tipo de cursor que se muestra al pasar sobre el label.
212 | * @param imagen (ImageIcon): Imagen que contiene el label.
213 | * @param fuente (Font): Tipo de fuente que tendrá el texto del label.
214 | * @param colorFondo (Color): Color de fondo o Background del label.
215 | * @param colorFuente (Color): Color de la letra o ForeGround del label.
216 | * @param borde (Border): Borde del label.
217 | * @param direccion (String): Dirección de los elementos dentro del label siendo:
218 | *
219 | * 'l' (LEFT): Contenido en la izquierda (por defecto).
220 | * 'c' (CENTER): Contenido centrado [Si tiene imágen y texto la imágen se posiciona primero].
221 | * 't' (TOP): Contenido centrado con texto arriba de una imágen.
222 | * 'r' (RIGHT): Contenido en la derecha [Si tiene imágen y texto el texto se posiciona primero].
223 | * 'b' (BOTTOM): Contenido centrado con texto abajo de una imágen.
224 | *
225 | * @return label (JLabel): Objeto gráfico tipo JLabel.
226 | * @throws null : Si construye un JLabel sin texto, cursor, imagen, fuente, colorFondo, colorFuente o borde envíe un [null] como parámetro.
227 | */
228 | public JLabel construirJLabel(
229 | String texto, int x, int y, int ancho, int alto, Cursor cursor, ImageIcon imagen,
230 | Font fuente, Color colorFondo, Color colorFuente, Border borde, String direccion
231 | ) {
232 | label = new JLabel(texto);
233 | label.setLocation(x, y);
234 | label.setSize(ancho, alto);
235 | label.setForeground(colorFuente);
236 | label.setFont(fuente);
237 | label.setCursor(cursor);
238 | label.setIcon(imagen);
239 | label.setBorder(borde);
240 | if (colorFondo != null) {
241 | label.setOpaque(true);
242 | label.setBackground(colorFondo);
243 | }
244 | switch (direccion) {
245 | case "c":
246 | label.setHorizontalAlignment(SwingConstants.CENTER);
247 | break;
248 | case "r":
249 | label.setHorizontalAlignment(SwingConstants.RIGHT);
250 | label.setHorizontalTextPosition(SwingConstants.LEFT);
251 | break;
252 | case "t":
253 | label.setHorizontalAlignment(SwingConstants.CENTER);
254 | label.setVerticalTextPosition(SwingConstants.TOP);
255 | label.setHorizontalTextPosition(SwingConstants.CENTER);
256 | break;
257 | case "b":
258 | label.setHorizontalAlignment(SwingConstants.CENTER);
259 | label.setVerticalTextPosition(SwingConstants.BOTTOM);
260 | label.setHorizontalTextPosition(SwingConstants.CENTER);
261 | break;
262 | default:
263 | break;
264 | }
265 | return label;
266 | }
267 |
268 | /**
269 | * Descripción: Esta función se encarga de construir un objeto gráfico tipo JTextField.
270 | * @param texto (String): Texto que contiene el textField.
271 | * @param x (int): Posición inicial en pixeles sobre el eje X.
272 | * @param y (int): Posición inicial en pixeles sobre el eje Y.
273 | * @param ancho (int): Tamaño sobre el eje X en pixeles del textField.
274 | * @param alto (int): Tamaño sobre el eje Y en pixeles del textField.
275 | * @param fuente (Font): Tipo de fuente que tendrá el texto del textField.
276 | * @param colorFondo (Color): Color de fondo o Background del textField.
277 | * @param colorFuente (Color): Color de la letra o ForeGround del textField.
278 | * @param colorCaret (Color): Color del Caret del textField.
279 | * @param borde (Border): Borde del textField.
280 | * @param direccion (String): Dirección de los elementos dentro del textField siendo:
281 | *
282 | * 'l' (LEFT): Contenido en la izquierda (por defecto).
283 | * 'c' (CENTER): Contenido centrado.
284 | * 'r' (RIGHT): Contenido en la derecha.
285 | *
286 | * @return textField (JTextField): Objeto gráfico tipo JTextField.
287 | * @throws null : Si construye un JTextField sin texto, fuente, colorFondo, colorFuente, colorCaret o borde envíe un [null] como parámetro.
288 | */
289 | public JTextField construirJTextField(
290 | String texto, int x, int y, int ancho, int alto, Font fuente, Color colorFondo,
291 | Color colorFuente, Color colorCaret, Border borde, String direccion
292 | ) {
293 | textField = new JTextField();
294 | textField.setLocation(x, y);
295 | textField.setSize(ancho, alto);
296 | textField.setText(texto);
297 | textField.setForeground(colorFuente);
298 | textField.setBackground(colorFondo);
299 | textField.setCaretColor(colorCaret);
300 | textField.setFont(fuente);
301 | textField.setBorder(borde);
302 | switch (direccion) {
303 | case "c":
304 | textField.setHorizontalAlignment(SwingConstants.CENTER);
305 | break;
306 | case "r":
307 | textField.setHorizontalAlignment(SwingConstants.RIGHT);
308 | break;
309 | default:
310 | break;
311 | }
312 | return textField;
313 | }
314 |
315 | /**
316 | * Descripción: Esta función se encarga de construir un objeto gráfico tipo JPasswordField.
317 | * @param texto (String): Texto que contiene el passwordField.
318 | * @param x (int): Posición inicial en pixeles sobre el eje X.
319 | * @param y (int): Posición inicial en pixeles sobre el eje Y.
320 | * @param ancho (int): Tamaño sobre el eje X en pixeles del passwordField.
321 | * @param alto (int): Tamaño sobre el eje Y en pixeles del passwordField.
322 | * @param fuente (Font): Tipo de fuente que tendrá el texto del passwordField.
323 | * @param colorFondo (Color): Color de fondo o Background del passwordField.
324 | * @param colorFuente (Color): Color de la letra o ForeGround del passwordField.
325 | * @param colorCaret (Color): Color del Caret del passwordField.
326 | * @param borde (Border): Borde del passwordField.
327 | * @param direccion (String): Dirección de los elementos dentro del passwordField siendo:
328 | *
329 | * 'l' (LEFT): Contenido en la izquierda (por defecto).
330 | * 'c' (CENTER): Contenido centrado.
331 | * 'r' (RIGHT): Contenido en la derecha.
332 | *
333 | * @return passwordField (JPasswordField): Objeto gráfico tipo JPasswordField.
334 | * @throws null : Si construye un JPasswordField sin texto, fuente, colorFondo, colorFuente, colorCaret o borde envíe un [null] como parámetro.
335 | */
336 | public JPasswordField construirJPasswordField(
337 | String texto, int x, int y, int ancho, int alto, Font fuente, Color colorFondo,
338 | Color colorFuente, Color colorCaret, Border borde, String direccion
339 | ) {
340 | passwordField = new JPasswordField();
341 | passwordField.setLocation(x, y);
342 | passwordField.setSize(ancho, alto);
343 | passwordField.setText(texto);
344 | passwordField.setForeground(colorFuente);
345 | passwordField.setBackground(colorFondo);
346 | passwordField.setCaretColor(colorCaret);
347 | passwordField.setBorder(borde);
348 | switch (direccion) {
349 | case "c":
350 | passwordField.setHorizontalAlignment(SwingConstants.CENTER);
351 | break;
352 | case "r":
353 | passwordField.setHorizontalAlignment(SwingConstants.RIGHT);
354 | break;
355 | default:
356 | break;
357 | }
358 | return passwordField;
359 | }
360 |
361 | /**
362 | * Descripción: Esta función se encarga de construir un objeto gráfico tipo JTextArea.
363 | * @param texto (String): Texto que contiene el textArea.
364 | * @param x (int): Posición inicial en pixeles sobre el eje X.
365 | * @param y (int): Posición inicial en pixeles sobre el eje Y.
366 | * @param ancho (int): Tamaño sobre el eje X en pixeles del textArea.
367 | * @param alto (int): Tamaño sobre el eje Y en pixeles del textArea.
368 | * @param fuente (Font): Tipo de fuente que tendrá el texto del textArea.
369 | * @param colorFondo (Color): Color de fondo o Background del textArea.
370 | * @param colorFuente (Color): Color de la letra o ForeGround del textArea.
371 | * @param colorCaret (Color): Color del Caret del textArea.
372 | * @param borde (Border): Borde del textArea.
373 | * @return textArea (JTextArea): Objeto gráfico tipo JTextArea.
374 | * @throws null : Si construye un JTextArea sin texto, fuente, colorFondo, colorFuente, colorCaret o borde envíe un [null] como parámetro.
375 | */
376 | public JTextArea construirJTextArea(
377 | String texto, int x, int y, int ancho, int alto, Font fuente,
378 | Color colorFondo, Color colorFuente, Color colorCaret, Border borde
379 | ) {
380 | textArea = new JTextArea();
381 | textArea.setLocation(x, y);
382 | textArea.setSize(ancho, alto);
383 | textArea.setText(texto);
384 | textArea.setFont(fuente);
385 | textArea.setForeground(colorFuente);
386 | textArea.setBackground(colorFondo);
387 | textArea.setCaretColor(colorCaret);
388 | textArea.setBorder(borde);
389 | return textArea;
390 | }
391 |
392 | /**
393 | * Descripción: Esta función se encarga de construir un objeto gráfico tipo JComboBox.
394 | * @param cadena (String): Todas las opciones que tendrá el comboBox, para enviar varias opciones separe cada opcion con un "_".
395 | * @param x (int): Posición inicial en pixeles sobre el eje X.
396 | * @param y (int): Posición inicial en pixeles sobre el eje Y.
397 | * @param ancho (int): Tamaño sobre el eje X en pixeles del comboBox.
398 | * @param alto (int): Tamaño sobre el eje Y en pixeles del comboBox.
399 | * @param fuente (Font): Tipo de fuente que tendrá el texto del comboBox.
400 | * @param colorFondo (Color): Color de fondo o Background del comboBox.
401 | * @param colorFuente (Color): Color de la letra o ForeGround del comboBox.
402 | * @param direccion (String): Dirección de los elementos dentro del comboBox siendo:
403 | *
404 | * 'l' (LEFT): Contenido en la izquierda (por defecto).
405 | * 'c' (CENTER): Contenido centrado.
406 | * 'r' (RIGHT): Contenido en la derecha.
407 | *
408 | * @return comboBox (JComboBox): Objeto gráfico tipo JComboBox.
409 | * @throws null : Si construye un JComboBox sin texto, fuente, colorFondo o colorFuente envíe un [null] como parámetro.
410 | */
411 | public JComboBox construirJComboBox(
412 | String cadena, int x, int y, int ancho, int alto, Font fuente,
413 | Color colorFondo, Color colorFuente, String direccion
414 | ) {
415 | comboBox = new JComboBox();
416 | comboBox.setLocation(x, y);
417 | comboBox.setSize(ancho, alto);
418 | for (String item : cadena.split("_")) {
419 | comboBox.addItem(item);
420 | }
421 | comboBox.setBackground(colorFondo);
422 | comboBox.setForeground(colorFuente);
423 | switch (direccion) {
424 | case "c":
425 | ((JLabel) comboBox.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
426 | break;
427 | case "r":
428 | ((JLabel) comboBox.getRenderer()).setHorizontalAlignment(SwingConstants.RIGHT);
429 | break;
430 | default:
431 | break;
432 | }
433 | return comboBox;
434 | }
435 |
436 | public static ObjGraficosService getService() {
437 | if (servicio == null) servicio = new ObjGraficosService();
438 | return servicio;
439 | }
440 | }
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/services/graphicServices/RecursosService.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.services.graphicServices;
2 |
3 | import java.awt.Color;
4 | import java.awt.Cursor;
5 | import java.awt.Font;
6 | import java.awt.Insets;
7 | import java.awt.FontFormatException;
8 | import java.awt.GraphicsEnvironment;
9 |
10 | import java.io.File;
11 | import java.io.IOException;
12 |
13 | import javax.swing.BorderFactory;
14 | import javax.swing.ImageIcon;
15 | import javax.swing.UIManager;
16 | import javax.swing.border.Border;
17 | import javax.swing.border.EmptyBorder;
18 |
19 | /** @author Cristian Felipe Patiño Cáceres Github: CrissUD*/
20 |
21 | public class RecursosService {
22 | private GraficosAvanzadosService sGraficosAvanzados;
23 | private Color colorAzul, colorAzulOscuro, colorAzulClaro, colorAzulMarino, colorMorado;
24 | private Color colorGrisOscuro, colorGrisClaro, colorTransparente;
25 | private Font fontTPrincipal, fontTitulo, fontSubtitulo;
26 | private Font fontBotones, fontPequeña, fontTProducto;
27 | private Cursor cMano;
28 | private Border borderInferiorAzul, borderInferiorGris, bordeLateralAzul, borderGris, borderAzul;
29 | private Border bordeCircular, bordeRedondeado, bordeRedondeadoLineal, bordeDifuminado, bordeRedondeadoBoton;
30 | private ImageIcon iClose;
31 |
32 | private static RecursosService servicio;
33 |
34 | private RecursosService() {
35 | sGraficosAvanzados = GraficosAvanzadosService.getService();
36 | this.generarFuentes();
37 | this.personalizarJOptionPane();
38 |
39 | this.crearColores();
40 | this.crearFuentes();
41 | this.crearCursores();
42 | this.crearBordes();
43 | this.crearImagenes();
44 | }
45 |
46 | private void crearColores() {
47 | colorMorado = new Color(151, 0, 158);
48 | colorAzul = new Color(0, 112, 218);
49 | colorAzulOscuro = new Color(30, 48, 90);
50 | colorAzulClaro = new Color(231, 244, 253);
51 | colorAzulMarino = new Color(52, 195, 219);
52 | colorGrisOscuro = new Color(102, 102, 102);
53 | colorGrisClaro = new Color(243, 244, 247);
54 | colorTransparente = new Color(0, 0, 0, 0);
55 | }
56 |
57 | private void crearFuentes() {
58 | fontTitulo = new Font("Oswald", Font.PLAIN, 25);
59 | fontSubtitulo = new Font("Oswald", Font.PLAIN, 17);
60 | fontBotones = new Font("LuzSans-Book", Font.PLAIN, 16);
61 | fontPequeña = new Font("LuzSans-Book", Font.PLAIN, 12);
62 | }
63 |
64 | private void crearCursores() { cMano = new Cursor(Cursor.HAND_CURSOR); }
65 |
66 | private void crearBordes() {
67 | borderInferiorAzul = BorderFactory.createMatteBorder(0, 0, 2, 0, colorAzul);
68 | bordeLateralAzul = BorderFactory.createMatteBorder(2, 0, 2, 2, colorAzul);
69 | borderInferiorGris = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY);
70 | borderGris = BorderFactory.createLineBorder(Color.LIGHT_GRAY, 2, true);
71 | borderAzul = BorderFactory.createLineBorder(colorAzul, 2, true);
72 | bordeCircular = sGraficosAvanzados.DibujarBordeCircular(null, false, null);
73 | bordeRedondeado = sGraficosAvanzados.DibujarBordeRedondeado(null, 40, false, null);
74 | bordeRedondeadoLineal = sGraficosAvanzados.DibujarBordeRedondeado(colorAzulMarino, 40, true, null);
75 | bordeDifuminado = sGraficosAvanzados.devolverBordeDifuminado(new Color(215, 215, 215), 8);
76 | bordeRedondeadoBoton = BorderFactory.createCompoundBorder(bordeRedondeado, new EmptyBorder(new Insets(5, 20, 5, 5)));
77 | }
78 |
79 | private void crearImagenes() {
80 | iClose = new ImageIcon("assets/images/close.png");
81 | }
82 |
83 | private void generarFuentes() {
84 | try {
85 | GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
86 | ge.registerFont( Font.createFont(
87 | Font.TRUETYPE_FONT,
88 | new File("assets/fonts/LUZRO.ttf")
89 | ));
90 | ge.registerFont( Font.createFont(
91 | Font.TRUETYPE_FONT,
92 | new File("assets/fonts/Oswald-VariableFont_wght.ttf")
93 | ));
94 | } catch (IOException | FontFormatException e) {
95 | System.out.println(e);
96 | }
97 | }
98 |
99 | private void personalizarJOptionPane() {
100 | UIManager.put("OptionPane.background", Color.WHITE);
101 | UIManager.put("OptionPane.messageForeground", this.colorAzulOscuro);
102 | UIManager.put("Button.background", this.colorAzul);
103 | UIManager.put("Button.foreground", Color.WHITE);
104 | UIManager.put("Panel.background", Color.WHITE);
105 | }
106 |
107 | public Color getColorMorado() { return colorMorado; }
108 |
109 | public Color getColorAzul() { return colorAzul; }
110 |
111 | public Color getColorAzulOscuro() { return colorAzulOscuro; }
112 |
113 | public Color getColorAzulClaro() { return colorAzulClaro; }
114 |
115 | public Color getColorAzulMarino() { return colorAzulMarino; }
116 |
117 | public Color getColorGrisOscuro() { return colorGrisOscuro; }
118 |
119 | public Color getColorGrisClaro() { return colorGrisClaro; }
120 |
121 | public Color getColorTransparente() { return colorTransparente; }
122 |
123 | public Font getFontTProducto() { return fontTProducto; }
124 |
125 | public Font getFontTPrincipal() { return fontTPrincipal; }
126 |
127 | public Font getFontTitulo() { return fontTitulo; }
128 |
129 | public Font getFontSubtitulo() { return fontSubtitulo; }
130 |
131 | public Font getFontBotones() { return fontBotones; }
132 |
133 | public Font getFontPequeña() { return fontPequeña; }
134 |
135 | public Cursor getCMano() { return cMano; }
136 |
137 | public Border getBorderInferiorAzul() { return borderInferiorAzul; }
138 |
139 | public Border getBordeLateralAzul() { return bordeLateralAzul; }
140 |
141 | public Border getBorderInferiorGris() { return borderInferiorGris; }
142 |
143 | public Border getBorderGris() { return borderGris; }
144 |
145 | public Border getBorderAzul() { return borderAzul; }
146 |
147 | public Border getBordeCircular() { return bordeCircular; }
148 |
149 | public Border getBordeRedondeadoBoton() { return bordeRedondeadoBoton; }
150 |
151 | public Border getBordeRedondeado() { return bordeRedondeado; }
152 |
153 | public Border getBordeRedondeadoLineal() { return bordeRedondeadoLineal; }
154 |
155 | public Border getBordeDifuminado() { return bordeDifuminado; }
156 |
157 | public ImageIcon getIClose() { return iClose; }
158 |
159 | public static RecursosService getService() {
160 | if (servicio == null) servicio = new RecursosService();
161 | return servicio;
162 | }
163 | }
--------------------------------------------------------------------------------
/src/main/java/com/mycompany/catapp/services/logicServices/CatService.java:
--------------------------------------------------------------------------------
1 | package com.mycompany.catapp.services.logicServices;
2 |
3 | import com.google.gson.Gson;
4 | import com.squareup.okhttp.MediaType;
5 | import com.squareup.okhttp.OkHttpClient;
6 | import com.squareup.okhttp.Request;
7 | import com.squareup.okhttp.RequestBody;
8 | import com.squareup.okhttp.Response;
9 | import java.io.IOException;
10 |
11 | import com.mycompany.catapp.models.Cat;
12 | import com.mycompany.catapp.models.FavouriteCat;
13 |
14 | /**
15 | * @author CrissUD / Cristian Patiño
16 | */
17 | public class CatService {
18 |
19 | private static CatService servicio;
20 | private FavouriteCat[] favouriteCatList;
21 | private final String API_KEY = "a91bbd76-2104-425f-b02e-5b675babd788";
22 | private final String URL = "https://api.thecatapi.com/v1/";
23 |
24 | public Cat getCat() {
25 | try {
26 | OkHttpClient client = new OkHttpClient();
27 | Request request = new Request.Builder()
28 | .url(URL + "images/search?")
29 | .method("GET", null)
30 | .build();
31 | Response response = client.newCall(request).execute();
32 |
33 | String data = response.body().string();
34 |
35 | data = data.substring(1, data.length());
36 | data = data.substring(0, (data.length() - 1));
37 |
38 | Gson gson = new Gson();
39 | Cat cat = gson.fromJson(data, Cat.class);
40 |
41 | return cat;
42 | } catch (IOException ex) {
43 | System.out.println(ex);
44 | }
45 | return null;
46 | }
47 |
48 | public Boolean saveFavourite(Cat cat) {
49 | try {
50 | OkHttpClient client = new OkHttpClient();
51 | MediaType mediaType = MediaType.parse("application/json");
52 | RequestBody body = RequestBody.create(mediaType, "{\r\n \"image_id\": \""+ cat.getId() +"\"\r\n}");
53 | Request request = new Request.Builder()
54 | .url(URL + "favourites")
55 | .method("POST", body)
56 | .addHeader("Content-Type", "application/json")
57 | .addHeader("x-api-key", API_KEY)
58 | .build();
59 | Response response = client.newCall(request).execute();
60 | if(response.code() == 200)
61 | return true;
62 | } catch (IOException ex) {
63 | System.out.println(ex);
64 | }
65 | return false;
66 | }
67 |
68 | public FavouriteCat[] getFavouriteList() {
69 | try {
70 | OkHttpClient client = new OkHttpClient();
71 | Request request = new Request.Builder()
72 | .url(URL + "favourites")
73 | .method("GET", null)
74 | .addHeader("x-api-key", API_KEY)
75 | .build();
76 | Response response = client.newCall(request).execute();
77 |
78 | String data = response.body().string();
79 |
80 | Gson gson = new Gson();
81 | favouriteCatList = gson.fromJson(data, FavouriteCat[].class);
82 |
83 | if(favouriteCatList.length > 0)
84 | return favouriteCatList;
85 | } catch (IOException ex) {
86 | System.out.println(ex);
87 | }
88 | return null;
89 | }
90 |
91 | public Boolean deleteFavourite (FavouriteCat cat) {
92 | try {
93 | OkHttpClient client = new OkHttpClient();
94 | MediaType mediaType = MediaType.parse("text/plain");
95 | RequestBody body = RequestBody.create(mediaType, "");
96 | Request request = new Request.Builder()
97 | .url(URL + "favourites/" + cat.getId())
98 | .method("DELETE", body)
99 | .addHeader("x-api-key", API_KEY)
100 | .build();
101 | Response response = client.newCall(request).execute();
102 | if(response.code() == 200)
103 | return true;
104 | } catch (IOException ex) {
105 | System.out.println(ex);
106 | }
107 | return false;
108 | }
109 |
110 | public FavouriteCat getFavouriteCat(int position) {
111 | try {
112 | return favouriteCatList[position];
113 | } catch (Exception e) {
114 | return null;
115 | }
116 | }
117 |
118 | public static CatService getService() {
119 | if (servicio == null) servicio = new CatService();
120 | return servicio;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------