Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create RunEDTActionOnFirstRenderHierarchyListener. #53

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions src/main/java/com/blackberry/jwteditor/view/editor/EditorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.blackberry.jwteditor.view.rsta.RstaFactory;
import com.blackberry.jwteditor.view.utils.ErrorLoggingActionListenerFactory;
import com.blackberry.jwteditor.view.utils.MaxLengthStringComboBoxModel;
import com.blackberry.jwteditor.view.utils.RunEDTActionOnFirstRenderHierarchyListener;
import org.exbin.deltahex.EditationAllowed;
import org.exbin.deltahex.swing.CodeArea;
import org.exbin.utils.binary_data.ByteArrayEditableData;
Expand All @@ -38,14 +39,11 @@
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import java.util.List;

import static java.awt.Color.RED;
import static java.awt.EventQueue.invokeLater;
import static java.awt.Font.BOLD;
import static java.awt.event.HierarchyEvent.SHOWING_CHANGED;
import static org.exbin.deltahex.EditationAllowed.ALLOWED;
import static org.exbin.deltahex.EditationAllowed.READ_ONLY;

Expand Down Expand Up @@ -114,7 +112,13 @@ public abstract class EditorView {
this.isProVersion = isProVersion;
this.presenter = new EditorPresenter(this, collaboratorPayloadGenerator, actionListenerFactory, presenters);

panel.addHierarchyListener(new ResizeSplitPanesOnFirstRenderHierarchyListener());
panel.addHierarchyListener(new RunEDTActionOnFirstRenderHierarchyListener(
panel,
() -> {
upperSplitPane.setDividerLocation(0.25);
lowerSplitPane.setDividerLocation(0.75);
}
));

// Event handler for Header / JWS payload change events
DocumentListener documentListener = new DocumentListener() {
Expand Down Expand Up @@ -549,20 +553,4 @@ public void setWarnings(String text) {
labelWarnings.setText(text);
});
}

private class ResizeSplitPanesOnFirstRenderHierarchyListener implements HierarchyListener {
@Override
public void hierarchyChanged(HierarchyEvent e) {
if (e.getChangeFlags() != SHOWING_CHANGED || !e.getComponent().isShowing()) {
return;
}

invokeLater(() -> {
upperSplitPane.setDividerLocation(0.25);
lowerSplitPane.setDividerLocation(0.75);
});

panel.removeHierarchyListener(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@

import javax.swing.*;
import javax.swing.table.TableColumnModel;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;

import static java.awt.event.HierarchyEvent.SHOWING_CHANGED;

public class PercentageBasedColumnWidthTable extends JTable {
private final int[] columnWidthPercentages;

public PercentageBasedColumnWidthTable(int[] columnWidthPercentages) {
this.columnWidthPercentages = columnWidthPercentages;
addHierarchyListener(new ResizeColumnsOnFirstRenderHierarchyListener());
addHierarchyListener(new RunEDTActionOnFirstRenderHierarchyListener(this, this::resizeColumns));

tableHeader.setReorderingAllowed(false);
}
Expand All @@ -49,16 +45,4 @@ private void resizeColumns() {
columnModel.getColumn(i).setPreferredWidth(preferredWidth);
}
}

private class ResizeColumnsOnFirstRenderHierarchyListener implements HierarchyListener {
@Override
public void hierarchyChanged(HierarchyEvent e) {
if (e.getChangeFlags() != SHOWING_CHANGED || !e.getComponent().isShowing()) {
return;
}

resizeColumns();
removeHierarchyListener(this);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Author : Dolph Flynn

Copyright 2024 Dolph Flynn

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package com.blackberry.jwteditor.view.utils;

import java.awt.*;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;

import static java.awt.EventQueue.invokeLater;
import static java.awt.event.HierarchyEvent.SHOWING_CHANGED;

public class RunEDTActionOnFirstRenderHierarchyListener implements HierarchyListener {
private final Component component;
private final Runnable action;

public RunEDTActionOnFirstRenderHierarchyListener(Component component, Runnable action) {
this.component = component;
this.action = action;
}

@Override
public void hierarchyChanged(HierarchyEvent e) {
if (e.getChangeFlags() == SHOWING_CHANGED && e.getComponent().isShowing()) {
invokeLater(action);
component.removeHierarchyListener(this);
}
}
}
Loading