This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git
The following commit(s) were added to refs/heads/master by this push:
new 0a4a3e72c Modeler Cleanup
0a4a3e72c is described below
commit 0a4a3e72ceca81814957bb42d8d3f652b51409ef
Author: Andrus Adamchik <[email protected]>
AuthorDate: Fri Apr 24 19:09:40 2026 -0400
Modeler Cleanup
---
.../org/apache/cayenne/modeler/osx/OSXPanelUI.java | 20 ++++-------
.../org/apache/cayenne/modeler/ui/SearchPanel.java | 2 +-
.../modeler/ui/welcome/RecentFileListModel.java | 19 +++++++---
.../ui/welcome/path/CompoundPathTrimmer.java | 42 ----------------------
.../modeler/ui/welcome/path/HomePathTrimmer.java | 37 -------------------
.../modeler/ui/welcome/path/MaxLengthTrimmer.java | 37 -------------------
.../modeler/ui/welcome/path/PathTrimmer.java | 33 -----------------
.../cayenne/modeler/util/RecentFileMenu.java | 2 +-
8 files changed, 23 insertions(+), 169 deletions(-)
diff --git
a/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXPanelUI.java
b/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXPanelUI.java
index bbf00473d..93f0323f7 100644
---
a/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXPanelUI.java
+++
b/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXPanelUI.java
@@ -19,19 +19,13 @@
package org.apache.cayenne.modeler.osx;
-import java.awt.Color;
-import java.awt.Graphics;
-import javax.swing.JComponent;
-import javax.swing.JPanel;
-import javax.swing.SwingUtilities;
+import org.apache.cayenne.modeler.ui.SearchPanel;
+
+import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicPanelUI;
+import java.awt.*;
-import org.apache.cayenne.modeler.ui.SearchPanel;
-
-/**
- * @since 4.0
- */
public class OSXPanelUI extends BasicPanelUI {
private static final Color BACKGROUND = new Color(0xEEEEEE);
@@ -42,7 +36,7 @@ public class OSXPanelUI extends BasicPanelUI {
BasicPanelUI delegate;
try {
@SuppressWarnings("unchecked")
- Class<? extends BasicPanelUI> delegateClass = (Class<? extends
BasicPanelUI>)
+ Class<? extends BasicPanelUI> delegateClass = (Class<? extends
BasicPanelUI>)
Class.forName("com.apple.laf.AquaPanelUI");
delegate = delegateClass.getDeclaredConstructor().newInstance();
} catch (Exception ex) {
@@ -63,9 +57,9 @@ public class OSXPanelUI extends BasicPanelUI {
}
@Override
- protected void installDefaults(final JPanel p) {
+ protected void installDefaults(JPanel p) {
super.installDefaults(p);
- if(p instanceof SearchPanel) {
+ if (p instanceof SearchPanel) {
SwingUtilities.invokeLater(((SearchPanel) p)::hideSearchLabel);
} else {
p.setBackground(BACKGROUND);
diff --git
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/SearchPanel.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/SearchPanel.java
index 421f3d85b..b78dbd8b3 100644
---
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/SearchPanel.java
+++
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/SearchPanel.java
@@ -7,7 +7,7 @@ import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
-class SearchPanel extends JPanel {
+public class SearchPanel extends JPanel {
private final JLabel searchLabel;
private final JPanel box;
diff --git
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/RecentFileListModel.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/RecentFileListModel.java
index ff90fee30..d63a82085 100644
---
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/RecentFileListModel.java
+++
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/RecentFileListModel.java
@@ -19,8 +19,6 @@
package org.apache.cayenne.modeler.ui.welcome;
-import org.apache.cayenne.modeler.ui.welcome.path.PathTrimmer;
-
import javax.swing.*;
import java.io.File;
import java.util.ArrayList;
@@ -28,16 +26,22 @@ import java.util.List;
class RecentFileListModel extends AbstractListModel<String> {
+ private static final int MAX_LENGTH = 120;
+ private static final String homeDir = System.getProperty("user.home");
+ private final static String replacement;
+
+ static {
+ replacement = homeDir.endsWith(File.separator) ? "~" + File.separator
: "~";
+ }
+
private final List<File> fileListFull;
private final List<String> fileList;
- private static final PathTrimmer pathTrimmer = PathTrimmer.getInstance();
-
RecentFileListModel(List<File> fileList) {
this.fileListFull = fileList;
this.fileList = new ArrayList<>(fileList.size());
for (File next : fileList) {
- this.fileList.add(pathTrimmer.trim(next.getAbsolutePath()));
+ this.fileList.add(trim(next.getAbsolutePath()));
}
}
@@ -54,4 +58,9 @@ class RecentFileListModel extends AbstractListModel<String> {
File getFullElementAt(int index) {
return fileListFull.get(index);
}
+
+ private static String trim(String path) {
+ String t1 = path.replace(homeDir, replacement);
+ return t1.length() <= MAX_LENGTH ? t1 : "..." +
path.substring(path.length() - MAX_LENGTH);
+ }
}
diff --git
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/path/CompoundPathTrimmer.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/path/CompoundPathTrimmer.java
deleted file mode 100644
index 2c38107d2..000000000
---
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/path/CompoundPathTrimmer.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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
- *
- * https://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 org.apache.cayenne.modeler.ui.welcome.path;
-
-class CompoundPathTrimmer implements PathTrimmer {
-
- private final int maxLength;
- private final PathTrimmer[] decorators;
-
- public CompoundPathTrimmer(int maxLength, PathTrimmer... decorators) {
- this.maxLength = maxLength;
- this.decorators = decorators;
- }
-
- @Override
- public String trim(String path) {
- for (PathTrimmer decorator : decorators) {
- path = decorator.trim(path);
- if (path.length() <= maxLength) {
- return path;
- }
- }
- return path;
- }
-}
\ No newline at end of file
diff --git
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/path/HomePathTrimmer.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/path/HomePathTrimmer.java
deleted file mode 100644
index cf5cdc0c2..000000000
---
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/path/HomePathTrimmer.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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
- *
- * https://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 org.apache.cayenne.modeler.ui.welcome.path;
-
-import java.io.File;
-
-class HomePathTrimmer implements PathTrimmer {
-
- private static final String homeDir = System.getProperty("user.home");
- private final static String replacement;
-
- static {
- replacement = homeDir.endsWith(File.separator) ? "~" + File.separator
: "~";
- }
-
- @Override
- public String trim(String path) {
- return path.replace(homeDir, replacement);
- }
-}
\ No newline at end of file
diff --git
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/path/MaxLengthTrimmer.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/path/MaxLengthTrimmer.java
deleted file mode 100644
index 049cab791..000000000
---
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/path/MaxLengthTrimmer.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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
- *
- * https://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 org.apache.cayenne.modeler.ui.welcome.path;
-
-public class MaxLengthTrimmer implements PathTrimmer {
-
- private final int maxLength;
-
- public MaxLengthTrimmer(int maxLength) {
- this.maxLength = maxLength;
- }
-
- @Override
- public String trim(String path) {
- if (path.length() <= maxLength) {
- return path;
- }
- return "..." + path.substring(path.length() - maxLength);
- }
-}
diff --git
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/path/PathTrimmer.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/path/PathTrimmer.java
deleted file mode 100644
index 701172c5c..000000000
---
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/welcome/path/PathTrimmer.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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
- *
- * https://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 org.apache.cayenne.modeler.ui.welcome.path;
-
-public interface PathTrimmer {
- int DEFAULT_MAX_LENGTH = 120;
-
- String trim(String path);
-
- static PathTrimmer getInstance() {
- return new CompoundPathTrimmer(
- DEFAULT_MAX_LENGTH,
- new HomePathTrimmer(),
- new MaxLengthTrimmer(DEFAULT_MAX_LENGTH));
- }
-}
\ No newline at end of file
diff --git
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/RecentFileMenu.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/RecentFileMenu.java
index e2c5eb574..77d2a768d 100644
---
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/RecentFileMenu.java
+++
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/RecentFileMenu.java
@@ -34,7 +34,7 @@ import java.util.List;
* {@link #rebuildFromPreferences()}
*/
public class RecentFileMenu extends JMenu implements RecentFileListListener {
-
+
public RecentFileMenu(String s) {
super(s);
}