Skip to content

Commit fed6409

Browse files
authored
Updated to v1.0.2
+ Optimized code. + TODO Internationalization & Theme.
1 parent 98f107b commit fed6409

File tree

5 files changed

+936
-674
lines changed

5 files changed

+936
-674
lines changed

src/main/java/com/bangmaple/jdbcgenerator/CutCopyPasteActionSupport.java

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,42 @@
2020
*
2121
* @author bangmaple
2222
*/
23-
public class CutCopyPasteActionSupport {
24-
private JMenu jMenu;
25-
JPopupMenu popupMenu = new JPopupMenu();
26-
27-
public CutCopyPasteActionSupport() {
28-
init();
29-
}
30-
31-
private void init() {
32-
jMenu = new JMenu("Edit");
33-
addAction(new DefaultEditorKit.CutAction(), KeyEvent.VK_X, "Cut" );
34-
addAction(new DefaultEditorKit.CopyAction(), KeyEvent.VK_C, "Copy" );
35-
addAction(new DefaultEditorKit.PasteAction(), KeyEvent.VK_V, "Paste" );
36-
}
37-
38-
private void addAction(TextAction action, int key, String text) {
39-
action.putValue(AbstractAction.ACCELERATOR_KEY,
40-
KeyStroke.getKeyStroke(key, InputEvent.CTRL_DOWN_MASK));
41-
action.putValue(AbstractAction.NAME, text);
42-
jMenu.add(new JMenuItem(action));
43-
popupMenu.add(new JMenuItem(action));
44-
}
45-
46-
public void setPopup(JTextComponent... components){
47-
if(components == null){
48-
return;
49-
}
50-
for (JTextComponent tc : components) {
51-
tc.setComponentPopupMenu(popupMenu);
52-
}
53-
}
54-
55-
public JMenu getMenu() {
56-
return jMenu;
57-
}
58-
}
23+
public final class CutCopyPasteActionSupport {
24+
25+
private JMenu jMenu;
26+
private JPopupMenu popupMenu;
27+
28+
public CutCopyPasteActionSupport() {
29+
popupMenu = new JPopupMenu();
30+
init();
31+
}
32+
33+
private void init() {
34+
jMenu = new JMenu("Edit");
35+
addAction(new DefaultEditorKit.CutAction(), KeyEvent.VK_X, "Cut");
36+
addAction(new DefaultEditorKit.CopyAction(), KeyEvent.VK_C, "Copy");
37+
addAction(new DefaultEditorKit.PasteAction(), KeyEvent.VK_V, "Paste");
38+
}
39+
40+
private void addAction(final TextAction action, final int key, final String text) {
41+
action.putValue(AbstractAction.ACCELERATOR_KEY,
42+
KeyStroke.getKeyStroke(key, InputEvent.CTRL_DOWN_MASK));
43+
action.putValue(AbstractAction.NAME, text);
44+
jMenu.add(new JMenuItem(action));
45+
popupMenu.add(new JMenuItem(action));
46+
}
47+
48+
public final void setPopup(final JTextComponent... components) {
49+
if (components == null) {
50+
return;
51+
}
52+
53+
for (JTextComponent tc : components) {
54+
tc.setComponentPopupMenu(popupMenu);
55+
}
56+
}
57+
58+
public JMenu getMenu() {
59+
return jMenu;
60+
}
61+
}

src/main/java/com/bangmaple/jdbcgenerator/DraggableTabbedPane.java

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,68 +18,67 @@
1818
import java.awt.event.MouseEvent;
1919
import java.awt.event.MouseMotionAdapter;
2020
import java.awt.image.BufferedImage;
21-
22-
import javax.swing.JButton;
2321
import javax.swing.JFrame;
2422
import javax.swing.JTabbedPane;
2523

2624
public class DraggableTabbedPane extends JTabbedPane {
2725

28-
private boolean dragging = false;
29-
private Image tabImage = null;
30-
private Point currentMouseLocation = null;
31-
private int draggedTabIndex = 0;
26+
private boolean dragging;
27+
private Image tabImage;
28+
private Point currentMouseLocation;
29+
private int draggedTabIndex;
3230

3331
public DraggableTabbedPane(final JFrame parent) {
3432
super();
33+
initVar();
34+
mouseMotionAdapterActionListener(parent);
35+
mouseAdapterActionListener();
36+
}
37+
38+
private void initVar() {
39+
dragging = false;
40+
tabImage = null;
41+
currentMouseLocation = null;
42+
draggedTabIndex = 0;
43+
}
44+
45+
private void mouseMotionAdapterActionListener(final JFrame parent) {
3546
addMouseMotionListener(new MouseMotionAdapter() {
3647
@Override
3748
public void mouseDragged(MouseEvent e) {
38-
3949
if (!dragging) {
40-
// Gets the tab index based on the mouse position
4150
int tabNumber = getUI().tabForCoordinate(DraggableTabbedPane.this, e.getX(), e.getY());
42-
4351
if (tabNumber >= 0) {
4452
draggedTabIndex = tabNumber;
4553
Rectangle bounds = getUI().getTabBounds(DraggableTabbedPane.this, tabNumber);
46-
47-
// Paint the tabbed pane to a buffer
4854
Image totalImage = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
4955
Graphics totalGraphics = totalImage.getGraphics();
5056
totalGraphics.setClip(bounds);
51-
// Don't be double buffered when painting to a static image.
5257
setDoubleBuffered(false);
5358
paintComponent(totalGraphics);
54-
55-
// Paint just the dragged tab to the buffer
5659
tabImage = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_ARGB);
5760
Graphics graphics = tabImage.getGraphics();
5861
graphics.drawImage(totalImage, 0, 0, bounds.width, bounds.height, bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height, DraggableTabbedPane.this);
59-
6062
dragging = true;
6163
repaint();
6264
}
6365
int thisX = parent.getLocation().x;
6466
int thisY = parent.getLocation().y;
65-
6667
int xMoved = e.getX() - currentMouseLocation.x;
6768
int yMoved = e.getY() - currentMouseLocation.y;
68-
6969
int X = thisX + xMoved;
7070
int Y = thisY + yMoved;
7171
parent.setLocation(X, Y);
7272
} else {
7373
currentMouseLocation = e.getPoint();
74-
75-
// Need to repaint
7674
repaint();
7775
}
78-
7976
super.mouseDragged(e);
8077
}
8178
});
79+
}
8280

81+
private void mouseAdapterActionListener() {
8382
addMouseListener(new MouseAdapter() {
8483
@Override
8584
public void mousePressed(MouseEvent e) {
@@ -89,7 +88,6 @@ public void mousePressed(MouseEvent e) {
8988

9089
@Override
9190
public void mouseReleased(MouseEvent e) {
92-
9391
if (dragging) {
9492
int tabNumber = getUI().tabForCoordinate(DraggableTabbedPane.this, e.getX(), 10);
9593

@@ -100,7 +98,6 @@ public void mouseReleased(MouseEvent e) {
10098
insertTab(title, null, comp, null, tabNumber);
10199
}
102100
}
103-
104101
dragging = false;
105102
tabImage = null;
106103
}
@@ -110,26 +107,8 @@ public void mouseReleased(MouseEvent e) {
110107
@Override
111108
protected void paintComponent(Graphics g) {
112109
super.paintComponent(g);
113-
114-
// Are we dragging?
115110
if (dragging && currentMouseLocation != null && tabImage != null) {
116-
// Draw the dragged tab
117111
g.drawImage(tabImage, currentMouseLocation.x, currentMouseLocation.y, this);
118112
}
119113
}
120-
121-
// public static void main(String[] args) {
122-
// JFrame test = new JFrame("Tab test");
123-
// test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
124-
// test.setSize(400, 400);
125-
//
126-
// DraggableTabbedPane tabs = new DraggableTabbedPane();
127-
// tabs.addTab("One", new JButton("One"));
128-
// tabs.addTab("Two", new JButton("Two"));
129-
// tabs.addTab("Three", new JButton("Three"));
130-
// tabs.addTab("Four", new JButton("Four"));
131-
//
132-
// test.add(tabs);
133-
// test.setVisible(true);
134-
// }
135114
}

src/main/java/com/bangmaple/jdbcgenerator/MainController.form

Lines changed: 106 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949
<Component id="lblLogo" min="-2" pref="265" max="-2" attributes="0"/>
5050
<EmptySpace type="separate" max="-2" attributes="0"/>
5151
<Component id="lblLogoJDBC" min="-2" pref="162" max="-2" attributes="0"/>
52-
<EmptySpace type="separate" max="-2" attributes="0"/>
53-
<Component id="jLabel17" min="-2" max="-2" attributes="0"/>
5452
<EmptySpace max="32767" attributes="0"/>
5553
<Component id="lblMin" min="-2" pref="30" max="-2" attributes="0"/>
5654
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
@@ -98,11 +96,6 @@
9896
<Component id="lblLogoJDBC" max="32767" attributes="0"/>
9997
</Group>
10098
<Component id="lblMin" alignment="0" min="-2" pref="30" max="-2" attributes="0"/>
101-
<Group type="102" alignment="1" attributes="0">
102-
<EmptySpace max="-2" attributes="0"/>
103-
<Component id="jLabel17" min="-2" max="-2" attributes="0"/>
104-
<EmptySpace max="-2" attributes="0"/>
105-
</Group>
10699
</Group>
107100
<Component id="jTabbedPane1" max="32767" attributes="0"/>
108101
<EmptySpace max="-2" attributes="0"/>
@@ -622,21 +615,15 @@
622615
<Component id="txtIP" alignment="0" pref="200" max="32767" attributes="0"/>
623616
<Component id="txtDBName" max="32767" attributes="0"/>
624617
</Group>
625-
<EmptySpace min="-2" pref="46" max="-2" attributes="0"/>
618+
<EmptySpace min="-2" pref="61" max="-2" attributes="0"/>
626619
<Group type="103" groupAlignment="0" attributes="0">
627-
<Component id="jLabel8" alignment="0" min="-2" max="-2" attributes="0"/>
628-
<Group type="102" alignment="0" attributes="0">
629-
<EmptySpace min="-2" pref="15" max="-2" attributes="0"/>
630-
<Group type="103" groupAlignment="0" attributes="0">
631-
<Component id="jLabel6" alignment="0" min="-2" max="-2" attributes="0"/>
632-
<Component id="jLabel4" alignment="0" min="-2" max="-2" attributes="0"/>
633-
</Group>
634-
<EmptySpace type="separate" max="-2" attributes="0"/>
635-
<Group type="103" groupAlignment="0" max="-2" attributes="0">
636-
<Component id="txtPort" pref="155" max="32767" attributes="0"/>
637-
<Component id="txtPassword" max="32767" attributes="0"/>
638-
</Group>
639-
</Group>
620+
<Component id="jLabel6" alignment="0" min="-2" max="-2" attributes="0"/>
621+
<Component id="jLabel4" alignment="0" min="-2" max="-2" attributes="0"/>
622+
</Group>
623+
<EmptySpace type="separate" max="-2" attributes="0"/>
624+
<Group type="103" groupAlignment="0" max="-2" attributes="0">
625+
<Component id="txtPort" pref="155" max="32767" attributes="0"/>
626+
<Component id="txtPassword" max="32767" attributes="0"/>
640627
</Group>
641628
<EmptySpace max="32767" attributes="0"/>
642629
</Group>
@@ -663,7 +650,6 @@
663650
<Group type="103" groupAlignment="3" attributes="0">
664651
<Component id="jLabel7" alignment="3" min="-2" max="-2" attributes="0"/>
665652
<Component id="txtDBName" alignment="3" min="-2" max="-2" attributes="0"/>
666-
<Component id="jLabel8" alignment="3" min="-2" max="-2" attributes="0"/>
667653
</Group>
668654
<EmptySpace max="32767" attributes="0"/>
669655
</Group>
@@ -714,10 +700,8 @@
714700
</Properties>
715701
</Component>
716702
<Component class="javax.swing.JTextField" name="txtDBName">
717-
</Component>
718-
<Component class="javax.swing.JLabel" name="jLabel8">
719703
<Properties>
720-
<Property name="text" type="java.lang.String" value="(Leave blank for &apos;master&apos;)"/>
704+
<Property name="text" type="java.lang.String" value="master"/>
721705
</Properties>
722706
</Component>
723707
</SubComponents>
@@ -1485,6 +1469,103 @@
14851469
</Container>
14861470
</SubComponents>
14871471
</Container>
1472+
<Container class="javax.swing.JPanel" name="jPanel5">
1473+
<Constraints>
1474+
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
1475+
<JTabbedPaneConstraints tabName="Preferences">
1476+
<Property name="tabTitle" type="java.lang.String" value="Preferences"/>
1477+
</JTabbedPaneConstraints>
1478+
</Constraint>
1479+
</Constraints>
1480+
1481+
<Layout>
1482+
<DimensionLayout dim="0">
1483+
<Group type="103" groupAlignment="0" attributes="0">
1484+
<Group type="102" alignment="0" attributes="0">
1485+
<EmptySpace min="-2" pref="15" max="-2" attributes="0"/>
1486+
<Group type="103" groupAlignment="0" attributes="0">
1487+
<Component id="jLabel17" min="-2" max="-2" attributes="0"/>
1488+
<Group type="102" attributes="0">
1489+
<Group type="103" groupAlignment="0" attributes="0">
1490+
<Component id="jLabel19" alignment="0" min="-2" max="-2" attributes="0"/>
1491+
<Component id="jLabel20" alignment="0" min="-2" max="-2" attributes="0"/>
1492+
</Group>
1493+
<EmptySpace type="separate" max="-2" attributes="0"/>
1494+
<Group type="103" groupAlignment="0" max="-2" attributes="0">
1495+
<Component id="jComboBox1" max="32767" attributes="0"/>
1496+
<Component id="jComboBox2" pref="125" max="32767" attributes="0"/>
1497+
</Group>
1498+
</Group>
1499+
</Group>
1500+
<EmptySpace pref="513" max="32767" attributes="0"/>
1501+
</Group>
1502+
</Group>
1503+
</DimensionLayout>
1504+
<DimensionLayout dim="1">
1505+
<Group type="103" groupAlignment="0" attributes="0">
1506+
<Group type="102" alignment="0" attributes="0">
1507+
<EmptySpace min="-2" pref="12" max="-2" attributes="0"/>
1508+
<Group type="103" groupAlignment="3" attributes="0">
1509+
<Component id="jLabel19" alignment="3" min="-2" max="-2" attributes="0"/>
1510+
<Component id="jComboBox1" alignment="3" min="-2" max="-2" attributes="0"/>
1511+
</Group>
1512+
<EmptySpace max="-2" attributes="0"/>
1513+
<Group type="103" groupAlignment="3" attributes="0">
1514+
<Component id="jComboBox2" alignment="3" min="-2" max="-2" attributes="0"/>
1515+
<Component id="jLabel20" alignment="3" min="-2" max="-2" attributes="0"/>
1516+
</Group>
1517+
<EmptySpace type="separate" max="-2" attributes="0"/>
1518+
<Component id="jLabel17" min="-2" max="-2" attributes="0"/>
1519+
<EmptySpace pref="356" max="32767" attributes="0"/>
1520+
</Group>
1521+
</Group>
1522+
</DimensionLayout>
1523+
</Layout>
1524+
<SubComponents>
1525+
<Component class="javax.swing.JLabel" name="jLabel19">
1526+
<Properties>
1527+
<Property name="text" type="java.lang.String" value="Language:"/>
1528+
</Properties>
1529+
</Component>
1530+
<Component class="javax.swing.JComboBox" name="jComboBox1">
1531+
<Properties>
1532+
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
1533+
<StringArray count="2">
1534+
<StringItem index="0" value="en-US"/>
1535+
<StringItem index="1" value="vi-VN"/>
1536+
</StringArray>
1537+
</Property>
1538+
</Properties>
1539+
<AuxValues>
1540+
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
1541+
</AuxValues>
1542+
</Component>
1543+
<Component class="javax.swing.JLabel" name="jLabel20">
1544+
<Properties>
1545+
<Property name="text" type="java.lang.String" value="Theme:"/>
1546+
</Properties>
1547+
</Component>
1548+
<Component class="javax.swing.JComboBox" name="jComboBox2">
1549+
<Properties>
1550+
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
1551+
<StringArray count="3">
1552+
<StringItem index="0" value="Dark Mode"/>
1553+
<StringItem index="1" value="White Mode"/>
1554+
<StringItem index="2" value="Ocean Mode"/>
1555+
</StringArray>
1556+
</Property>
1557+
</Properties>
1558+
<AuxValues>
1559+
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
1560+
</AuxValues>
1561+
</Component>
1562+
<Component class="javax.swing.JLabel" name="jLabel17">
1563+
<Properties>
1564+
<Property name="text" type="java.lang.String" value="&lt;html&gt;fb.com/BangMaple&lt;br/&gt;github.com/BangMaple&lt;/html&gt;"/>
1565+
</Properties>
1566+
</Component>
1567+
</SubComponents>
1568+
</Container>
14881569
</SubComponents>
14891570
</Container>
14901571
<Component class="javax.swing.JLabel" name="lblMaxMin">
@@ -1532,11 +1613,6 @@
15321613
<Property name="text" type="java.lang.String" value="Project path:"/>
15331614
</Properties>
15341615
</Component>
1535-
<Component class="javax.swing.JLabel" name="jLabel17">
1536-
<Properties>
1537-
<Property name="text" type="java.lang.String" value="&lt;html&gt;fb.com/BangMaple&lt;br/&gt;github.com/BangMaple&lt;/html&gt;"/>
1538-
</Properties>
1539-
</Component>
15401616
<Component class="javax.swing.JLabel" name="txtInfo">
15411617
</Component>
15421618
</SubComponents>

0 commit comments

Comments
 (0)