Package: HistogramRenderer
HistogramRenderer
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
HistogramRenderer() |
|
|
|
|
|
||||||||||||||||||||
build() |
|
|
|
|
|
||||||||||||||||||||
clear() |
|
|
|
|
|
||||||||||||||||||||
getHistogram() |
|
|
|
|
|
||||||||||||||||||||
lambda$setHistogram$0(Histogram) |
|
|
|
|
|
||||||||||||||||||||
setHistogram(Histogram) |
|
|
|
|
|
||||||||||||||||||||
showComputing() |
|
|
|
|
|
||||||||||||||||||||
start() |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: /*
2: * *********************************************************************************************************************
3: *
4: * Mistral: open source imaging engine
5: * http://tidalwave.it/projects/mistral
6: *
7: * Copyright (C) 2003 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/mistral-src
23: * git clone https://github.com/tidalwave-it/mistral-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.mistral.example.histogramviewer;
28:
29: import java.awt.CardLayout;
30: import java.awt.Color;
31: import java.awt.Dimension;
32: import javax.swing.JLabel;
33: import javax.swing.JPanel;
34: import javax.swing.SwingUtilities;
35: import it.tidalwave.image.Histogram;
36: import lombok.extern.slf4j.Slf4j;
37:
38: /***********************************************************************************************************************
39: *
40: * @author Fabrizio Giudici
41: *
42: **********************************************************************************************************************/
43: @Slf4j
44: public class HistogramRenderer extends JPanel
45: {
46: private static final String COMPUTING = "COMPUTING";
47:
48: private static final String EMPTY = "EMPTY";
49:
50: private static final String HISTOGRAM = "HISTOGRAM";
51:
52: private final JLabel lbComputing = new JLabel("", JLabel.CENTER);
53:
54: private final JLabel lbEmpty = new JLabel();
55:
56: private final XYPlotter histogramPlotter = new XYPlotter();
57:
58: private final HistogramGrid grid = new HistogramGrid();
59:
60: private Histogram histogram;
61:
62: private final CardLayout cardLayout = new CardLayout();
63:
64: /*******************************************************************************************************************
65: *
66: *
67: *
68: ******************************************************************************************************************/
69: public HistogramRenderer()
70: {
71: build();
72: lbEmpty.setOpaque(false);
73: lbComputing.setOpaque(false);
74: histogramPlotter.setOpaque(false);
75: clear();
76: }
77:
78: /*******************************************************************************************************************
79: *
80: * @return Returns the histogram.
81: *
82: ******************************************************************************************************************/
83: public Histogram getHistogram()
84: {
85: return histogram;
86: }
87:
88: /*******************************************************************************************************************
89: *
90: *
91: *
92: ******************************************************************************************************************/
93: public void start()
94: {
95: lbComputing.setText("Computing histogram...");
96: }
97:
98: /*******************************************************************************************************************
99: *
100: *
101: *
102: ******************************************************************************************************************/
103: public void clear()
104: {
105: cardLayout.show(this, EMPTY);
106: }
107:
108: /*******************************************************************************************************************
109: *
110: *
111: *
112: ******************************************************************************************************************/
113: public void showComputing()
114: {
115: cardLayout.show(this, COMPUTING);
116: }
117:
118: /*******************************************************************************************************************
119: *
120: * @param histogram
121: *
122: ******************************************************************************************************************/
123: public void setHistogram (final Histogram histogram)
124: {
125: this.histogram = histogram;
126:
127: SwingUtilities.invokeLater(() ->
128: {
129: log.trace(">>>> histogram ready...");
130: histogramPlotter.clearData();
131: //histogramPlotter.setXAxisLogarithmic(6);
132: histogramPlotter.setXAxisLinear();
133: grid.setHSteps(6);
134:
135: final var bandCount = histogram.getBandCount();
136:
137:• if (bandCount == 1)
138: {
139: histogramPlotter.addData("GRAY", histogram.getFrequencies(0), Color.WHITE);
140: }
141:
142:• else if (bandCount == 3)
143: {
144: histogramPlotter.addData("RED", histogram.getFrequencies(0), Color.RED);
145: histogramPlotter.addData("GREEN", histogram.getFrequencies(1), Color.GREEN);
146: histogramPlotter.addData("BLUE", histogram.getFrequencies(2), Color.BLUE);
147: }
148:
149: cardLayout.show(HistogramRenderer.this, HISTOGRAM);
150: log.trace(">>>> showing histogram...");
151: });
152: }
153:
154: /*******************************************************************************************************************
155: *
156: *
157: *
158: ******************************************************************************************************************/
159: private void build()
160: {
161: setLayout(cardLayout);
162: setBackground(Color.GRAY);
163: setForeground(Color.LIGHT_GRAY);
164: lbComputing.setBackground(getBackground());
165: lbComputing.setForeground(getForeground());
166: lbComputing.setOpaque(true);
167: lbEmpty.setBackground(getBackground());
168: lbEmpty.setForeground(getForeground());
169: lbEmpty.setOpaque(true);
170: histogramPlotter.setBackground(getBackground());
171: histogramPlotter.setAreaPlot();
172: grid.setColor(Color.DARK_GRAY);
173: //// histogramPlotter.setOverlay(grid);
174: grid.sethistogramPlotter(histogramPlotter);
175: add(lbEmpty, EMPTY);
176: add(lbComputing, COMPUTING);
177: add(histogramPlotter, HISTOGRAM);
178: final var dimension = new Dimension(340, 80);
179: setMinimumSize(dimension);
180: setPreferredSize(dimension);
181: setSize(dimension);
182: }
183: }