Skip to content

Commit 45c45c5

Browse files
authored
add separate log layout and font zoom to hop-gui, resolves #5927 (#5928)
1 parent c27b51c commit 45c45c5

File tree

7 files changed

+244
-5
lines changed

7 files changed

+244
-5
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hop.core.logging;
19+
20+
import java.text.SimpleDateFormat;
21+
import java.util.Arrays;
22+
import java.util.Date;
23+
import org.apache.hop.core.Const;
24+
25+
public class FixedWidthLogLayout {
26+
private static final ThreadLocal<SimpleDateFormat> LOCAL_SIMPLE_DATE_PARSER =
27+
ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"));
28+
29+
private static final int MAX_LOG_LEVEL_LENGTH =
30+
Arrays.stream(LogLevel.getLogLevelCodes()).map(String::length).reduce(0, Integer::max);
31+
32+
private boolean timeAdded;
33+
34+
public FixedWidthLogLayout() {
35+
this(true);
36+
}
37+
38+
public FixedWidthLogLayout(boolean addTime) {
39+
this.timeAdded = addTime;
40+
}
41+
42+
public String format(HopLoggingEvent event) {
43+
StringBuilder line = new StringBuilder();
44+
45+
String dateTimeString = "";
46+
47+
if (timeAdded) {
48+
dateTimeString = LOCAL_SIMPLE_DATE_PARSER.get().format(new Date(event.timeStamp)) + " ";
49+
}
50+
51+
Object object = event.getMessage();
52+
53+
if (object instanceof LogMessage message) {
54+
55+
String logLevel = getLogLevelPadded(message.getLevel());
56+
57+
String[] parts =
58+
message.getMessage() == null ? new String[] {} : message.getMessage().split(Const.CR);
59+
60+
for (int i = 0; i < parts.length; i++) {
61+
if (!message.isSimplified()) {
62+
line.append(dateTimeString);
63+
line.append(logLevel);
64+
65+
// Include the subject too on every line...
66+
if (message.getSubject() != null) {
67+
line.append(message.getSubject());
68+
if (message.getCopy() != null) {
69+
line.append(".").append(message.getCopy());
70+
}
71+
line.append(" - ");
72+
}
73+
}
74+
75+
line.append(parts[i]);
76+
if (i < parts.length - 1) {
77+
line.append(Const.CR); // put the CR's back in there!
78+
}
79+
}
80+
} else {
81+
line.append(dateTimeString);
82+
line.append((object != null ? object.toString() : "<null>"));
83+
}
84+
85+
return line.toString();
86+
}
87+
88+
private String getLogLevelPadded(LogLevel logLevel) {
89+
String code = logLevel.getCode();
90+
return "[" + code + "] " + " ".repeat(Math.max(MAX_LOG_LEVEL_LENGTH - code.length(), 0));
91+
}
92+
}

ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiLogBrowser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.apache.commons.lang3.StringUtils;
2929
import org.apache.hop.core.Const;
3030
import org.apache.hop.core.config.HopConfig;
31-
import org.apache.hop.core.logging.HopLogLayout;
31+
import org.apache.hop.core.logging.FixedWidthLogLayout;
3232
import org.apache.hop.core.logging.HopLogStore;
3333
import org.apache.hop.core.logging.HopLoggingEvent;
3434
import org.apache.hop.core.logging.IHasLogChannel;
@@ -76,7 +76,7 @@ public void installLogSniffer() {
7676
//
7777
final AtomicInteger lastLogId = new AtomicInteger(-1);
7878
final AtomicBoolean busy = new AtomicBoolean(false);
79-
final HopLogLayout logLayout = new HopLogLayout(true);
79+
final FixedWidthLogLayout logLayout = new FixedWidthLogLayout(true);
8080

8181
// Refresh the log every second or so
8282
//

ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/delegates/HopGuiPipelineLogDelegate.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.hop.ui.hopgui.file.IHopFileTypeHandler;
3939
import org.apache.hop.ui.hopgui.file.pipeline.HopGuiLogBrowser;
4040
import org.apache.hop.ui.hopgui.file.pipeline.HopGuiPipelineGraph;
41+
import org.apache.hop.ui.hopgui.file.shared.TextZoom;
4142
import org.eclipse.swt.SWT;
4243
import org.eclipse.swt.custom.CTabItem;
4344
import org.eclipse.swt.layout.FormAttachment;
@@ -58,6 +59,9 @@ public class HopGuiPipelineLogDelegate {
5859
public static final String TOOLBAR_ICON_LOG_COPY_TO_CLIPBOARD =
5960
"ToolbarIcon-10020-LogCopyToClipboard";
6061
public static final String TOOLBAR_ICON_LOG_PAUSE_RESUME = "ToolbarIcon-10030-LogPauseResume";
62+
public static final String TOOLBAR_ICON_LOG_INCREASE_FONT = "ToolbarIcon-10040-LogIncreaseFont";
63+
public static final String TOOLBAR_ICON_LOG_DECREASE_FONT = "ToolbarIcon-10050-LogDecreaseFont";
64+
public static final String TOOLBAR_ICON_LOG_RESET_FONT = "ToolbarIcon-10060-LogResetFont";
6165

6266
private final HopGuiPipelineGraph pipelineGraph;
6367

@@ -66,6 +70,7 @@ public class HopGuiPipelineLogDelegate {
6670
@Getter private CTabItem pipelineLogTab;
6771

6872
private Text pipelineLogText;
73+
private TextZoom textZoom;
6974

7075
private ToolBar toolbar;
7176
private GuiToolbarWidgets toolBarWidgets;
@@ -119,6 +124,10 @@ public void addPipelineLog() {
119124
fdText.top = new FormAttachment(toolbar, 0);
120125
fdText.bottom = new FormAttachment(100, 0);
121126
pipelineLogText.setLayoutData(fdText);
127+
128+
this.textZoom = new TextZoom(pipelineLogText, GuiResource.getInstance().getFontFixed());
129+
this.textZoom.resetFont();
130+
122131
// add a CR to avoid fontStyle from getting lost on macos HOP-2583
123132
if (OsHelper.isMac()) {
124133
pipelineLogText.setText(Const.CR);
@@ -306,6 +315,36 @@ public void pauseLog() {
306315
}
307316
}
308317

318+
@GuiToolbarElement(
319+
root = GUI_PLUGIN_TOOLBAR_PARENT_ID,
320+
id = TOOLBAR_ICON_LOG_INCREASE_FONT,
321+
toolTip = "i18n:org.apache.hop.ui.hopgui:WorkflowLog.Button.IncreaseFont",
322+
image = "ui/images/zoom-in.svg",
323+
separator = true)
324+
public void increaseFont() {
325+
this.textZoom.increaseFont();
326+
}
327+
328+
@GuiToolbarElement(
329+
root = GUI_PLUGIN_TOOLBAR_PARENT_ID,
330+
id = TOOLBAR_ICON_LOG_DECREASE_FONT,
331+
toolTip = "i18n:org.apache.hop.ui.hopgui:WorkflowLog.Button.DecreaseFont",
332+
image = "ui/images/zoom-out.svg",
333+
separator = false)
334+
public void decreaseFont() {
335+
this.textZoom.decreaseFont();
336+
}
337+
338+
@GuiToolbarElement(
339+
root = GUI_PLUGIN_TOOLBAR_PARENT_ID,
340+
id = TOOLBAR_ICON_LOG_RESET_FONT,
341+
toolTip = "i18n:org.apache.hop.ui.hopgui:WorkflowLog.Button.ResetFont",
342+
image = "ui/images/zoom-100.svg",
343+
separator = false)
344+
public void resetFont() {
345+
this.textZoom.resetFont();
346+
}
347+
309348
public boolean hasSelectedText() {
310349
return pipelineLogText != null
311350
&& !pipelineLogText.isDisposed()
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hop.ui.hopgui.file.shared;
19+
20+
import org.eclipse.swt.graphics.Font;
21+
import org.eclipse.swt.graphics.FontData;
22+
import org.eclipse.swt.widgets.Text;
23+
24+
public class TextZoom {
25+
public static final int STEP_DEFAULT = 1;
26+
public static final int MIN_HEIGHT = 4;
27+
28+
private Text widget;
29+
private Font font;
30+
private int step;
31+
private int minHeight;
32+
33+
public TextZoom(Text widget, Font font) {
34+
this(widget, font, TextZoom.STEP_DEFAULT);
35+
}
36+
37+
public TextZoom(Text widget, Font font, int step) {
38+
this(widget, font, step, MIN_HEIGHT);
39+
}
40+
41+
public TextZoom(Text widget, Font font, int step, int minHeight) {
42+
this.widget = widget;
43+
this.font = font;
44+
this.step = step;
45+
this.minHeight = minHeight;
46+
}
47+
48+
public void increaseFont() {
49+
increaseHeightBy(step);
50+
}
51+
52+
public void decreaseFont() {
53+
increaseHeightBy(-step);
54+
}
55+
56+
public void resetFont() {
57+
widget.setFont(font);
58+
}
59+
60+
private void increaseHeightBy(int points) {
61+
FontData fontData = widget.getFont().getFontData()[0];
62+
int newHeight = Math.max(minHeight, fontData.getHeight() + points);
63+
fontData.setHeight(newHeight);
64+
widget.setFont(new Font(widget.getDisplay(), fontData));
65+
}
66+
}

ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/delegates/HopGuiWorkflowLogDelegate.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.hop.ui.hopgui.HopGui;
3434
import org.apache.hop.ui.hopgui.file.IHopFileTypeHandler;
3535
import org.apache.hop.ui.hopgui.file.pipeline.HopGuiLogBrowser;
36+
import org.apache.hop.ui.hopgui.file.shared.TextZoom;
3637
import org.apache.hop.ui.hopgui.file.workflow.HopGuiWorkflowGraph;
3738
import org.apache.hop.workflow.WorkflowMeta;
3839
import org.apache.hop.workflow.action.ActionMeta;
@@ -57,13 +58,17 @@ public class HopGuiWorkflowLogDelegate {
5758
public static final String TOOLBAR_ICON_LOG_COPY_TO_CLIPBOARD =
5859
"ToolbarIcon-10020-LogCopyToClipboard";
5960
public static final String TOOLBAR_ICON_LOG_PAUSE_RESUME = "ToolbarIcon-10030-LogPauseResume";
61+
public static final String TOOLBAR_ICON_LOG_INCREASE_FONT = "ToolbarIcon-10040-LogIncreaseFont";
62+
public static final String TOOLBAR_ICON_LOG_DECREASE_FONT = "ToolbarIcon-10050-LogDecreaseFont";
63+
public static final String TOOLBAR_ICON_LOG_RESET_FONT = "ToolbarIcon-10060-LogResetFont";
6064

6165
private HopGui hopGui;
6266
private HopGuiWorkflowGraph workflowGraph;
6367

6468
private CTabItem workflowLogTab;
6569

6670
private Text workflowLogText;
71+
private TextZoom textZoom;
6772

6873
/** The number of lines in the log tab */
6974
private Composite workflowLogComposite;
@@ -121,6 +126,10 @@ public void addWorkflowLog() {
121126
fdText.top = new FormAttachment((Control) toolbar, 0);
122127
fdText.bottom = new FormAttachment(100, 0);
123128
workflowLogText.setLayoutData(fdText);
129+
130+
this.textZoom = new TextZoom(workflowLogText, GuiResource.getInstance().getFontFixed());
131+
this.textZoom.resetFont();
132+
124133
// add a CR to avoid fontStyle from getting lost on macos HOP-2583
125134
if (OsHelper.isMac()) {
126135
workflowLogText.setText(Const.CR);
@@ -284,6 +293,36 @@ public void pauseLog() {
284293
}
285294
}
286295

296+
@GuiToolbarElement(
297+
root = GUI_PLUGIN_TOOLBAR_PARENT_ID,
298+
id = TOOLBAR_ICON_LOG_INCREASE_FONT,
299+
toolTip = "i18n:org.apache.hop.ui.hopgui:WorkflowLog.Button.IncreaseFont",
300+
image = "ui/images/zoom-in.svg",
301+
separator = true)
302+
public void increaseFont() {
303+
this.textZoom.increaseFont();
304+
}
305+
306+
@GuiToolbarElement(
307+
root = GUI_PLUGIN_TOOLBAR_PARENT_ID,
308+
id = TOOLBAR_ICON_LOG_DECREASE_FONT,
309+
toolTip = "i18n:org.apache.hop.ui.hopgui:WorkflowLog.Button.DecreaseFont",
310+
image = "ui/images/zoom-out.svg",
311+
separator = false)
312+
public void decreaseFont() {
313+
this.textZoom.decreaseFont();
314+
}
315+
316+
@GuiToolbarElement(
317+
root = GUI_PLUGIN_TOOLBAR_PARENT_ID,
318+
id = TOOLBAR_ICON_LOG_RESET_FONT,
319+
toolTip = "i18n:org.apache.hop.ui.hopgui:WorkflowLog.Button.ResetFont",
320+
image = "ui/images/zoom-100.svg",
321+
separator = false)
322+
public void resetFont() {
323+
this.textZoom.resetFont();
324+
}
325+
287326
public boolean hasSelectedText() {
288327
return workflowLogText != null
289328
&& !workflowLogText.isDisposed()

ui/src/main/resources/org/apache/hop/ui/hopgui/messages/messages_de_DE.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
#
17-
1817
HopGui.Application.Name=Hop
1918
HopGui.Dialog.ActionCanNotBeChanged.Message=Die Workflow-Action kann nicht ge\u00E4ndert werden!
2019
HopGui.Dialog.ActionCanNotBeChanged.Title=Sorry...
@@ -241,6 +240,9 @@ WorkflowGraph.Dialog.HopCausesLoop.Message=Dieser Hop verursacht eine unerlaubte
241240
WorkflowGraph.Dialog.HopCausesLoop.Title=Endlosschleife!
242241
WorkflowLog.Button.LogSettings=Log Einstellungen
243242
WorkflowLog.Button.Pause=Workflow Log pausieren
243+
WorkflowLog.Button.IncreaseFont=Schrift vergr\u00F6\u00DFern
244+
WorkflowLog.Button.DecreaseFont=Schrift verkleinern
245+
WorkflowLog.Button.ResetFont=Schriftgr\u00F6\u00DFe zur\u00FCcksetzen
244246
WorkflowLog.Button.ShowErrorLines=Fehlerzeilen anzeigen
245247
WorkflowLog.Dialog.SaveJobBeforeRunning.Message=Den Workflow speichern, bevor er gestartet wird.
246248
WorkflowLog.Dialog.SaveJobBeforeRunning.Title=Workflow speichern

ui/src/main/resources/org/apache/hop/ui/hopgui/messages/messages_en_US.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
#
17-
18-
1917
HopGui.Application.Name=Hop
2018
HopGui.Dialog.ActionCanNotBeChanged.Message=This action can''t be changed\!
2119
HopGui.Dialog.ActionCanNotBeChanged.Title=Sorry...
@@ -271,6 +269,9 @@ WorkflowLog.Button.ClearLog=Clear log
271269
WorkflowLog.Button.LogCopyToClipboard=Copy workflow log to clipboard
272270
WorkflowLog.Button.LogSettings=Log settings
273271
WorkflowLog.Button.Pause=Pause workflow log
272+
WorkflowLog.Button.IncreaseFont=Increase font size
273+
WorkflowLog.Button.DecreaseFont=Decrease font size
274+
WorkflowLog.Button.ResetFont=Reset font size
274275
WorkflowLog.Button.ShowErrorLines=Show error lines
275276
WorkflowLog.Dialog.SaveJobBeforeRunning.Message=Please save the workflow before running it.
276277
WorkflowLog.Dialog.SaveJobBeforeRunning.Title=Save workflow

0 commit comments

Comments
 (0)