Author: rozagh
Date: 2012-08-31 16:12:20 -0700 (Fri, 31 Aug 2012)
New Revision: 30308
Modified:
core3/impl/trunk/welcome-impl/src/main/java/org/cytoscape/welcome/internal/panel/OpenPanel.java
Log:
fixes #1125 truncate the file path in the middle.
Modified:
core3/impl/trunk/welcome-impl/src/main/java/org/cytoscape/welcome/internal/panel/OpenPanel.java
===================================================================
---
core3/impl/trunk/welcome-impl/src/main/java/org/cytoscape/welcome/internal/panel/OpenPanel.java
2012-08-31 22:09:15 UTC (rev 30307)
+++
core3/impl/trunk/welcome-impl/src/main/java/org/cytoscape/welcome/internal/panel/OpenPanel.java
2012-08-31 23:12:20 UTC (rev 30308)
@@ -2,6 +2,7 @@
import java.awt.Cursor;
import java.awt.Dimension;
+import java.awt.FontMetrics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
@@ -83,8 +84,10 @@
continue;
}
final File targetFile = new File(fileURI);
- final JLabel fileLabel = new JLabel(target.toString());
+ final JLabel fileLabel = new JLabel();
+ FontMetrics fm = fileLabel.getFontMetrics(REGULAR_FONT);
fileLabel.setMaximumSize(new Dimension(300, 18));
+ fileLabel.setText(getTruncatedPath(
target.toString(),250, fm ) );
fileLabel.setForeground(REGULAR_FONT_COLOR);
fileLabel.setFont(LINK_FONT);
fileLabel.setBorder(padLine);
@@ -120,4 +123,24 @@
this.add(open);
}
+
+ private String getTruncatedPath(String path, double width, FontMetrics
fm ) {
+
+ String fileName = path.substring(path.lastIndexOf('/'));
+ if (fm.stringWidth("..."+fileName) > width){
+ int startIndex = 4;
+ fileName = "..." + fileName.substring(startIndex);
+ while (fm.stringWidth(fileName) > width){
+ fileName = "..." +
fileName.substring(startIndex);
+ }
+ return fileName;
+ }
+
+ String address = path.substring(0, path.lastIndexOf('/'));
+ while (fm.stringWidth(address + fileName) > width){
+ address = address.substring(0, address.length() - 4) +
"...";
+ }
+
+ return address + fileName;
+ }
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.