this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

render renameField on POPUP_LAYER and size it to the text

+41 -8
+41 -8
src/main/java/app/pane/explorer/Item.java
··· 7 7 import java.awt.Graphics; 8 8 import java.awt.Graphics2D; 9 9 import java.awt.Insets; 10 + import java.awt.Point; 10 11 import java.awt.Rectangle; 11 12 import java.awt.RenderingHints; 12 13 import java.awt.TexturePaint; ··· 22 23 import java.awt.event.MouseEvent; 23 24 import java.awt.image.BufferedImage; 24 25 26 + import javax.swing.event.DocumentEvent; 27 + import javax.swing.event.DocumentListener; 28 + 25 29 import javax.swing.AbstractAction; 26 30 import javax.swing.BorderFactory; 31 + import javax.swing.JLayeredPane; 27 32 import javax.swing.Icon; 28 33 import javax.swing.JMenuItem; 29 34 import javax.swing.JOptionPane; ··· 164 169 { 165 170 if (renameField == null) 166 171 return; 167 - remove(renameField); 172 + var layeredPane = getRootPane().getLayeredPane(); 173 + layeredPane.remove(renameField); 174 + layeredPane.repaint(); 168 175 renameField = null; 169 176 repaint(); 170 177 } ··· 187 194 188 195 renameField = new JTextField(currentName); 189 196 renameField.setHorizontalAlignment(JTextField.CENTER); 190 - renameField.setBounds(x, labelY, w, labelH); 191 197 renameField.selectAll(); 198 + renameField.setFont(renameField.getFont().deriveFont(12f)); 199 + renameField.setBorder(null); 200 + renameField.setMargin(new Insets(0, 0, 0, 0)); 201 + 202 + final JLayeredPane layeredPane = getRootPane().getLayeredPane(); 203 + final int localCenterX = x + w / 2; 204 + final int localY = labelY; 205 + 206 + Runnable resizeRenameField = () -> { 207 + FontMetrics fm = renameField.getFontMetrics(renameField.getFont()); 208 + int textW = fm.stringWidth(renameField.getText()) + fm.charWidth('W'); 209 + int fieldW = Math.max(w, textW); 210 + Point origin = SwingUtilities.convertPoint(Item.this, localCenterX - fieldW / 2, localY, layeredPane); 211 + renameField.setBounds(origin.x, origin.y, fieldW, labelH); 212 + }; 213 + resizeRenameField.run(); 214 + 215 + renameField.getDocument().addDocumentListener(new DocumentListener() { 216 + @Override 217 + public void insertUpdate(DocumentEvent e) { resizeRenameField.run(); } 218 + @Override 219 + public void removeUpdate(DocumentEvent e) { resizeRenameField.run(); } 220 + @Override 221 + public void changedUpdate(DocumentEvent e) { resizeRenameField.run(); } 222 + }); 192 223 193 224 Runnable commit = () -> { 194 225 if (renameField == null) ··· 227 258 } 228 259 }); 229 260 230 - add(renameField); 231 - revalidate(); 261 + layeredPane.add(renameField, JLayeredPane.POPUP_LAYER); 262 + layeredPane.revalidate(); 232 263 renameField.requestFocusInWindow(); 233 264 } 234 265 ··· 279 310 280 311 // Icon 281 312 if (icon != null) { 282 - int iconW = icon.getIconWidth(); 283 - int iconH = icon.getIconHeight(); 313 + int iconW = Math.min(icon.getIconWidth(), AssetHandle.THUMBNAIL_WIDTH); 314 + int iconH = Math.min(icon.getIconHeight(), AssetHandle.THUMBNAIL_HEIGHT); 284 315 int iconX = x + (w - iconW) / 2; 285 316 int iconY = y + (iconAreaH - iconH) / 2; 286 317 287 318 if (checkerboard) 288 319 paintCheckerboard(g2, iconX, iconY, iconW, iconH); 289 320 290 - icon.paintIcon(this, g2, iconX, iconY); 321 + Graphics2D clipped = (Graphics2D) g2.create(iconX, iconY, iconW, iconH); 322 + icon.paintIcon(this, clipped, 0, 0); 323 + clipped.dispose(); 291 324 } 292 325 293 326 // Name label with ellipsis (hidden during inline rename) 294 327 if (renameField == null) { 295 328 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 296 329 g2.setColor(UIManager.getColor("Label.foreground")); 297 - g2.setFont(getFont()); 330 + g2.setFont(getFont().deriveFont(12f)); 298 331 FontMetrics fm = g2.getFontMetrics(); 299 332 300 333 String displayText = name;